I'm using a version of the Insert Video snippet from another forum post that makes use of the Editor's "insertHtml" function to embed videos. It works great in most browsers. However, in IE9, the video is always inserted at the beginning of the text instead of where the cursor is. Is there anything I can do about this?
Here's the relevant code snippet
Here's the relevant code snippet
<script type=
"text/x-kendo-template"
id=
"insertVideo-template"
>
<div>
<label
for
=
"videoUrl"
>Enter a Share URL from YouTube:</label>
<input type=
"text"
id=
"videoUrl"
name=
"videoUrl"
/>
<div class=
"insertVideo-actions"
>
<button class=
"k-button insertVideo-insert"
>Insert</button>
<button class=
"k-button insertVideo-cancel"
>Cancel</button>
</div>
</div>
</script>
<script type=
"text/x-kendo-template"
id=
"youTube-template"
>
<iframe width=
"458"
height=
"315"
src=
"http://www.youtube.com/embed/#= source #?wmode=opaque&rel=0"
frameborder=
"0"
></iframe>
</script>
function
insertVideo(e) {
var
editor = $(
this
).data(
"kendoEditor"
);
var
dialog = $($(
"#insertVideo-template"
).html())
.find(
".insertVideo-insert"
)
.click(
function
() {
var
media = testUrlForMedia(dialog.element.find(
"input"
).val());
if
(media) {
var
template = kendo.template($(
"#youTube-template"
).html());
editor.exec(
"insertHtml"
, { value: template({ source: media.id }) });
}
dialog.close();
})
.end()
.find(
".insertVideo-cancel"
)
.click(
function
() {
dialog.close();
})
.end()
.kendoWindow({
modal:
true
,
title:
"Insert Video"
,
animation:
false
,
deactivate:
function
() {
dialog.destroy();
}
}).data(
"kendoWindow"
);
dialog.center().open();
}
// Check inserted URL for valid Media Link
function
testUrlForMedia(pastedData) {
var
success =
false
;
var
media = {};
if
(pastedData.match(
'http://(www.)?youtube|youtu\.be'
)) {
if
(pastedData.match(
'embed'
)) {
youtube_id = pastedData.split(/embed\
//)[1].split('"')[0];
}
else
{
youtube_id = pastedData.split(/v\/|v=|youtu\.be\
//)[1].split(/[?&]/)[0];
}
media.type =
"youtube"
;
media.id = youtube_id;
success =
true
;
}
if
(success) {
return
media;
}
else
{
alert(
"No valid media id detected.\nBe sure to use the \"Share\" url, located in the menu under the video on the youtube page."
);
}
return
false
;
}
$(
".fnRichTextField"
).kendoEditor({
encoded:
false
,
tools: [
"bold"
,
"italic"
,
"underline"
,
"separator"
,
"fontName"
,
"fontSize"
,
"foreColor"
,
"backColor"
,
"separator"
,
"insertUnorderedList"
,
"insertOrderedList"
,
"separator"
,
"justifyLeft"
,
"justifyCenter"
,
"justifyRight"
,
"justifyFull"
,
"separator"
,
"createLink"
,
"unlink"
,
"separator"
,
{ name:
"insertVideo"
, tooltip:
"Embed Youtube Video"
, exec: insertVideo },
"viewHtml"
]
});