-
-
Save jmbauguess/733b062f1d65abd876a61e5796259fad to your computer and use it in GitHub Desktop.
Enabling Video Tags in the TinyMCE HTML Fields in ServiceNow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MySNTinyMCEMedia = function SNTinyMCEMedia(ed) { | |
var data; | |
var el = ed.selection.getNode(); | |
data = getData(el); | |
var allowFullScr = ""; | |
var allowScptAcs = ""; | |
if (!data.allowscriptaccess){ | |
var htmlStr = decodeURIComponent(el.getAttribute('data-mce-html')); | |
var nodeList = ed.dom.createFragment(htmlStr).childNodes; | |
if (nodeList != null){ | |
for (i=0; i<nodeList.length; i++){ | |
if (nodeList[i].name == "allowfullscreen"){ | |
allowFullScr = nodeList[i].value; | |
}else if (nodeList[i].name == "allowscriptaccess"){ | |
allowScptAcs = nodeList[i].value; | |
} | |
} | |
} | |
} | |
var outparam = []; | |
if (isMediaImg(el, ed)) { | |
if (data.data){ | |
outparam['f_url'] = data.data; | |
} else if (data.src){ | |
outparam['f_url'] = data.src; | |
} | |
if (data.allowfullscreen) { | |
outparam['f_allowfullscreen'] = data.allowfullscreen; | |
outparam['f_allowscriptaccess'] = data.allowscriptaccess; | |
} else { | |
outparam['f_allowfullscreen'] = allowFullScr; | |
outparam['f_allowscriptaccess'] = allowScptAcs; | |
} | |
outparam['f_width'] = el.width; | |
outparam['f_height'] = el.height; | |
} else | |
outparam['textArea'] = ed._textArea; | |
ed.windowManager.bookmark = ed.selection.getBookmark(1) | |
var dialog = GlideModal ? GlideModal : GlideDialogWindow; | |
g_dialog = new dialog('html_insert_video_dialog'); | |
g_dialog.setTitle('Insert/Modify Video'); | |
if (tinyMCE.isInMainWindow) { | |
g_dialog.setPreference('target_table', g_form.getTableName()); | |
g_dialog.setPreference('target_sys_id', g_form.getUniqueValue()); | |
} | |
g_dialog.setPreference('outparam', outparam); | |
g_dialog.setPreference('action', | |
function(param) { | |
g_dialog.destroy(); | |
if (!param) { | |
return false; | |
} | |
var videoText = createVideoText(param); | |
ed.execCommand('mceInsertContent', false, videoText); | |
}); | |
g_dialog.render(); | |
function createVideoText (param) { | |
return '<video controls="controls" width="100%" height="150">' + | |
'<source src="/' + param.f_url + '" type="video/mp4" />' + | |
'</video>'; | |
} | |
function isMediaImg(node, ed) { | |
return node && node.nodeName === 'IMG' && ed.dom.hasClass(node, 'mce-object'); | |
} | |
function getVideoScriptMatch(src) { | |
var prefixes = editor.settings.media_scripts; | |
if (prefixes) { | |
for (var i = 0; i < prefixes.length; i++) { | |
if (src.indexOf(prefixes[i].filter) !== -1) { | |
return prefixes[i]; | |
} | |
} | |
} | |
} | |
function htmlToData(html) { | |
var data = {}; | |
new tinymce.html.SaxParser({ | |
validate: false, | |
allow_conditional_comments: true, | |
special: 'script,noscript', | |
start: function(name, attrs) { | |
if (!data.source1 && name == "param") { | |
data.source1 = attrs.map.movie; | |
} | |
if (name == "iframe" || name == "object" || name == "embed" || name == "video" || name == "audio") { | |
if (!data.type) { | |
data.type = name; | |
} | |
data = tinymce.extend(attrs.map, data); | |
} | |
if (name == "script") { | |
var videoScript = getVideoScriptMatch(attrs.map.src); | |
if (!videoScript) { | |
return; | |
} | |
data = { | |
type: "script", | |
source1: attrs.map.src, | |
width: videoScript.width, | |
height: videoScript.height | |
}; | |
} | |
if (name == "source") { | |
if (!data.source1) { | |
data.source1 = attrs.map.src; | |
} else if (!data.source2) { | |
data.source2 = attrs.map.src; | |
} | |
} | |
if (name == "img" && !data.poster) { | |
data.poster = attrs.map.src; | |
} | |
} | |
}).parse(html); | |
data.source1 = data.source1 || data.src || data.data; | |
data.source2 = data.source2 || ''; | |
data.poster = data.poster || ''; | |
return data; | |
} | |
function getData(element) { | |
if (element.getAttribute('data-mce-object')) { | |
return htmlToData(ed.serializer.serialize(element, {selection: true})); | |
} | |
return {}; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<unload unload_date="2017-05-25 02:32:57"> | |
<sys_script_client action="INSERT_OR_UPDATE"> | |
<active>true</active> | |
<applies_extended>false</applies_extended> | |
<condition/> | |
<description/> | |
<field>active</field> | |
<global>true</global> | |
<messages/> | |
<name>Swapout TinyMCEMedia</name> | |
<order/> | |
<script><![CDATA[function onLoad() { | |
window.SNTinyMCEMedia = MySNTinyMCEMedia; | |
}]]></script> | |
<sys_class_name>sys_script_client</sys_class_name> | |
<sys_created_by>admin</sys_created_by> | |
<sys_created_on>2017-05-25 01:51:49</sys_created_on> | |
<sys_customer_update>true</sys_customer_update> | |
<sys_domain>global</sys_domain> | |
<sys_domain_path>/</sys_domain_path> | |
<sys_id>c65b96b34f363200bc63a7d18110c791</sys_id> | |
<sys_mod_count>2</sys_mod_count> | |
<sys_name>Swapout TinyMCEMedia</sys_name> | |
<sys_overrides display_value=""/> | |
<sys_package display_value="Global">global</sys_package> | |
<sys_policy/> | |
<sys_replace_on_upgrade>false</sys_replace_on_upgrade> | |
<sys_scope display_value="Global">global</sys_scope> | |
<sys_update_name>sys_script_client_c65b96b34f363200bc63a7d18110c791</sys_update_name> | |
<sys_updated_by>admin</sys_updated_by> | |
<sys_updated_on>2017-05-25 02:32:47</sys_updated_on> | |
<table>kb_knowledge</table> | |
<type>onLoad</type> | |
<ui_type>0</ui_type> | |
<view/> | |
</sys_script_client> | |
</unload> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<unload unload_date="2017-05-25 02:33:54"> | |
<sys_embed_object action="INSERT_OR_UPDATE"> | |
<active>true</active> | |
<clsid>22D6F312-B0F6-11D0-94AB-0080C74C7E95</clsid> | |
<codebase>https://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab</codebase> | |
<embed_type>video/mp4</embed_type> | |
<extension>mp4</extension> | |
<pluginspage>https://www.microsoft.com/Windows/MediaPlayer/</pluginspage> | |
<sys_class_name>sys_embed_object</sys_class_name> | |
<sys_created_by>admin</sys_created_by> | |
<sys_created_on>2016-12-06 15:19:18</sys_created_on> | |
<sys_customer_update>true</sys_customer_update> | |
<sys_id>d1e5f99913af2640881c73076144b055</sys_id> | |
<sys_mod_count>1</sys_mod_count> | |
<sys_name>mp4</sys_name> | |
<sys_package display_value="Global">global</sys_package> | |
<sys_policy/> | |
<sys_replace_on_upgrade>false</sys_replace_on_upgrade> | |
<sys_scope display_value="Global">global</sys_scope> | |
<sys_update_name>sys_embed_object_d1e5f99913af2640881c73076144b055</sys_update_name> | |
<sys_updated_by>admin</sys_updated_by> | |
<sys_updated_on>2017-05-23 23:34:52</sys_updated_on> | |
</sys_embed_object> | |
</unload> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<unload unload_date="2017-05-25 02:34:55"> | |
<sys_embed_object action="INSERT_OR_UPDATE"> | |
<active>true</active> | |
<clsid>22D6F312-B0F6-11D0-94AB-0080C74C7E95</clsid> | |
<codebase>http://www.apple.com/qtactivex/qtplugin.cab</codebase> | |
<embed_type>video/quicktime</embed_type> | |
<extension>mp4</extension> | |
<pluginspage>http://www.apple.com/quicktime/download</pluginspage> | |
<sys_class_name>sys_embed_object</sys_class_name> | |
<sys_created_by>admin</sys_created_by> | |
<sys_created_on>2016-12-06 15:19:18</sys_created_on> | |
<sys_customer_update>true</sys_customer_update> | |
<sys_id>d1e5f99913af2640881c73076144b055</sys_id> | |
<sys_mod_count>2</sys_mod_count> | |
<sys_name>mp4</sys_name> | |
<sys_package display_value="Global">global</sys_package> | |
<sys_policy/> | |
<sys_replace_on_upgrade>false</sys_replace_on_upgrade> | |
<sys_scope display_value="Global">global</sys_scope> | |
<sys_update_name>sys_embed_object_d1e5f99913af2640881c73076144b055</sys_update_name> | |
<sys_updated_by>admin</sys_updated_by> | |
<sys_updated_on>2017-05-25 02:34:18</sys_updated_on> | |
</sys_embed_object> | |
</unload> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment