人人商城

plugin.min.js 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. /**
  2. * plugin.js
  3. *
  4. * Copyright, Moxiecode Systems AB
  5. * Released under LGPL License.
  6. *
  7. * License: http://www.tinymce.com/license
  8. * Contributing: http://www.tinymce.com/contributing
  9. */
  10. /*jshint maxlen:255 */
  11. /*eslint max-len:0 */
  12. /*global tinymce:true */
  13. tinymce.PluginManager.add('media', function(editor, url) {
  14. var urlPatterns = [
  15. {regex: /youtu\.be\/([\w\-.]+)/, type: 'iframe', w: '100%', h: '250px', url: '//www.youtube.com/embed/$1'},
  16. {regex: /youtube\.com(.+)v=([^&]+)/, type: 'iframe', w: '100%', h: '250px', url: '//www.youtube.com/embed/$2'},
  17. {regex: /vimeo\.com\/([0-9]+)/, type: 'iframe', w: '100%', h: '250px', url: '//player.vimeo.com/video/$1?title=0&byline=0&portrait=0&color=8dc7dc'},
  18. {regex: /vimeo\.com\/(.*)\/([0-9]+)/, type: "iframe", w: '100%', h: '250px', url: "//player.vimeo.com/video/$2?title=0&byline=0"},
  19. {regex: /maps\.google\.([a-z]{2,3})\/maps\/(.+)msid=(.+)/, type: 'iframe', w: '100%', h: '250px', url: '//maps.google.com/maps/ms?msid=$2&output=embed"'},
  20. {regex: /v\.youku\.com\/v_show\/id_([\w\-=]+)\.html/, type: 'iframe', w: '100%', h: '250px', url: '//player.youku.com/embed/$1'},
  21. {regex: /tudou\.com\/(listplay|albumplay)\/([\w\-=]+)\/([\w\-=]+)\.html/, type: 'iframe', w: '100%', h: '250px', url: '//www.tudou.com/programs/view/html5embed.action?type=0&code=$3&lcode='},
  22. {regex: /tudou\.com\/programs\/view\/([\w\-=]+)\//, type: 'iframe', w: '100%', h: '250px', url: '//www.tudou.com/programs/view/html5embed.action?type=0&code=$1&lcode='},
  23. {regex: /56\.com\/([\w\-=]+)\/v_([\w\-=]+)\.html/, type: 'iframe', w: '100%', h: '250px', url: '//www.56.com/iframe/$2"'},
  24. {regex: /v\.ku6\.com\/.+\/([\w\-=._]+)\.html.*$/, type: 'iframe', w: '100%', h: '250px', url: '//player.ku6.com/refer/$1/v.swf'}
  25. ];
  26. var embedChange = (tinymce.Env.ie && tinymce.Env.ie <= 8) ? 'onChange' : 'onInput';
  27. function guessMime(url) {
  28. if (url.indexOf('.mp3') != -1) {
  29. return 'audio/mpeg';
  30. }
  31. if (url.indexOf('.wav') != -1) {
  32. return 'audio/wav';
  33. }
  34. if (url.indexOf('.mp4') != -1) {
  35. return 'video/mp4';
  36. }
  37. if (url.indexOf('.webm') != -1) {
  38. return 'video/webm';
  39. }
  40. if (url.indexOf('.ogg') != -1) {
  41. return 'video/ogg';
  42. }
  43. if (url.indexOf('.swf') != -1) {
  44. return 'application/x-shockwave-flash';
  45. }
  46. return '';
  47. }
  48. function getVideoScriptMatch(src) {
  49. var prefixes = editor.settings.media_scripts;
  50. if (prefixes) {
  51. for (var i = 0; i < prefixes.length; i++) {
  52. if (src.indexOf(prefixes[i].filter) !== -1) {
  53. return prefixes[i];
  54. }
  55. }
  56. }
  57. }
  58. function showDialog() {
  59. var win, width, height, data;
  60. var generalFormItems = [
  61. {
  62. name: 'source1',
  63. type: 'filepicker',
  64. filetype: 'media',
  65. size: 40,
  66. autofocus: true,
  67. label: 'Source',
  68. onchange: function(e) {
  69. tinymce.each(e.meta, function(value, key) {
  70. win.find('#' + key).value(value);
  71. });
  72. }
  73. }
  74. ];
  75. function recalcSize(e) {
  76. var widthCtrl, heightCtrl, newWidth, newHeight;
  77. widthCtrl = win.find('#width')[0];
  78. heightCtrl = win.find('#height')[0];
  79. newWidth = widthCtrl.value();
  80. newHeight = heightCtrl.value();
  81. if (win.find('#constrain')[0].checked() && width && height && newWidth && newHeight) {
  82. if (e.control == widthCtrl) {
  83. newHeight = Math.round((newWidth / width) * newHeight);
  84. heightCtrl.value(newHeight);
  85. } else {
  86. newWidth = Math.round((newHeight / height) * newWidth);
  87. widthCtrl.value(newWidth);
  88. }
  89. }
  90. width = newWidth;
  91. height = newHeight;
  92. }
  93. generalFormItems.push({type: 'label',text: '支持优酷、56、土豆、酷六',forId: ''});
  94. generalFormItems.push({type: 'label',text: '直接填写页面地址即可',forId: ''});
  95. generalFormItems.push({type: 'label',text: '其它视频请复制“通用代码”到内嵌中',forId: ''});
  96. if (editor.settings.media_alt_source !== false) {
  97. generalFormItems.push({name: 'source2', type: 'filepicker', filetype: 'media', size: 40, label: 'Alternative source'});
  98. }
  99. if (editor.settings.media_poster !== false) {
  100. generalFormItems.push({name: 'poster', type: 'filepicker', filetype: 'image', size: 40, label: 'Poster'});
  101. }
  102. if (editor.settings.media_dimensions !== false) {
  103. generalFormItems.push({
  104. type: 'container',
  105. label: 'Dimensions',
  106. layout: 'flex',
  107. align: 'center',
  108. spacing: 5,
  109. items: [
  110. {name: 'width', type: 'textbox', maxLength: 3, size: 3, onchange: recalcSize},
  111. {type: 'label', text: 'x'},
  112. {name: 'height', type: 'textbox', maxLength: 3, size: 3, onchange: recalcSize},
  113. {name: 'constrain', type: 'checkbox', checked: true, text: 'Constrain proportions'}
  114. ]
  115. });
  116. }
  117. data = getData(editor.selection.getNode());
  118. width = data.width;
  119. height = data.height;
  120. var embedTextBox = {
  121. id: 'mcemediasource',
  122. type: 'textbox',
  123. flex: 1,
  124. name: 'embed',
  125. value: getSource(),
  126. multiline: true,
  127. label: 'Source'
  128. };
  129. function updateValueOnChange() {
  130. data = htmlToData(this.value());
  131. this.parent().parent().fromJSON(data);
  132. }
  133. embedTextBox[embedChange] = updateValueOnChange;
  134. win = editor.windowManager.open({
  135. title: 'Insert/edit video',
  136. data: data,
  137. bodyType: 'tabpanel',
  138. body: [
  139. {
  140. title: 'General',
  141. type: "form",
  142. onShowTab: function() {
  143. data = htmlToData(this.next().find('#embed').value());
  144. this.fromJSON(data);
  145. },
  146. items: generalFormItems
  147. },
  148. {
  149. title: 'Embed',
  150. type: "panel",
  151. layout: 'flex',
  152. direction: 'column',
  153. align: 'stretch',
  154. padding: 10,
  155. spacing: 10,
  156. onShowTab: function() {
  157. this.find('#embed').value(dataToHtml(this.parent().toJSON()));
  158. },
  159. items: [
  160. {
  161. type: 'label',
  162. text: 'Paste your embed code below:',
  163. forId: 'mcemediasource'
  164. },
  165. embedTextBox
  166. ]
  167. }
  168. ],
  169. onSubmit: function() {
  170. var beforeObjects, afterObjects, i, y;
  171. beforeObjects = editor.dom.select('img[data-mce-object]');
  172. editor.insertContent(dataToHtml(this.toJSON()));
  173. afterObjects = editor.dom.select('img[data-mce-object]');
  174. // Find new image placeholder so we can select it
  175. for (i = 0; i < beforeObjects.length; i++) {
  176. for (y = afterObjects.length - 1; y >= 0; y--) {
  177. if (beforeObjects[i] == afterObjects[y]) {
  178. afterObjects.splice(y, 1);
  179. }
  180. }
  181. }
  182. editor.selection.select(afterObjects[0]);
  183. editor.nodeChanged();
  184. }
  185. });
  186. }
  187. function getSource() {
  188. var elm = editor.selection.getNode();
  189. if (elm.getAttribute('data-mce-object')) {
  190. return editor.selection.getContent();
  191. }
  192. }
  193. function dataToHtml(data) {
  194. var html = '';
  195. if (!data.source1) {
  196. tinymce.extend(data, htmlToData(data.embed));
  197. if (!data.source1) {
  198. return '';
  199. }
  200. }
  201. if (!data.source2) {
  202. data.source2 = '';
  203. }
  204. if (!data.poster) {
  205. data.poster = '';
  206. }
  207. data.source1 = editor.convertURL(data.source1, "source");
  208. data.source2 = editor.convertURL(data.source2, "source");
  209. data.source1mime = guessMime(data.source1);
  210. data.source2mime = guessMime(data.source2);
  211. data.poster = editor.convertURL(data.poster, "poster");
  212. data.flashPlayerUrl = editor.convertURL(url + '/moxieplayer.swf', "movie");
  213. tinymce.each(urlPatterns, function(pattern) {
  214. var match, i, url;
  215. if ((match = pattern.regex.exec(data.source1))) {
  216. url = pattern.url;
  217. for (i = 0; match[i]; i++) {
  218. /*jshint loopfunc:true*/
  219. /*eslint no-loop-func:0 */
  220. url = url.replace('$' + i, function() {
  221. return match[i];
  222. });
  223. }
  224. data.source1 = url;
  225. data.type = pattern.type;
  226. data.width = data.width || pattern.w;
  227. data.height = data.height || pattern.h;
  228. }
  229. });
  230. if (data.embed) {
  231. html = updateHtml(data.embed, data, true);
  232. } else {
  233. var videoScript = getVideoScriptMatch(data.source1);
  234. if (videoScript) {
  235. data.type = 'script';
  236. data.width = videoScript.width;
  237. data.height = videoScript.height;
  238. }
  239. data.width = data.width || 300;
  240. data.height = data.height || 150;
  241. tinymce.each(data, function(value, key) {
  242. data[key] = editor.dom.encode(value);
  243. });
  244. if (data.type == "iframe") {
  245. html += '<iframe src="' + data.source1 + '" style="width:' + data.width + '; height:' + data.height + ';" frameborder="0"></iframe>';
  246. } else if (data.source1mime == "application/x-shockwave-flash") {
  247. html += '<object data="' + data.source1 + '" width="' + data.width + '" height="' + data.height + '" type="application/x-shockwave-flash">';
  248. if (data.poster) {
  249. html += '<img src="' + data.poster + '" width="' + data.width + '" height="' + data.height + '" />';
  250. }
  251. html += '</object>';
  252. } else if (data.source1mime.indexOf('audio') != -1) {
  253. if (editor.settings.audio_template_callback) {
  254. html = editor.settings.audio_template_callback(data);
  255. } else {
  256. html += (
  257. '<audio controls="controls" src="' + data.source1 + '">' +
  258. (data.source2 ? '\n<source src="' + data.source2 + '"' + (data.source2mime ? ' type="' + data.source2mime + '"' : '') + ' />\n' : '') +
  259. '</audio>'
  260. );
  261. }
  262. } else if (data.type == "script") {
  263. html += '<script src="' + data.source1 + '"></script>';
  264. } else {
  265. if (editor.settings.video_template_callback) {
  266. html = editor.settings.video_template_callback(data);
  267. } else {
  268. html = (
  269. '<video width="' + data.width + '" height="' + data.height + '"' + (data.poster ? ' poster="' + data.poster + '"' : '') + ' controls="controls">\n' +
  270. '<source src="' + data.source1 + '"' + (data.source1mime ? ' type="' + data.source1mime + '"' : '') + ' />\n' +
  271. (data.source2 ? '<source src="' + data.source2 + '"' + (data.source2mime ? ' type="' + data.source2mime + '"' : '') + ' />\n' : '') +
  272. '</video>'
  273. );
  274. }
  275. }
  276. }
  277. return html;
  278. }
  279. function htmlToData(html) {
  280. var data = {};
  281. new tinymce.html.SaxParser({
  282. validate: false,
  283. allow_conditional_comments: true,
  284. special: 'script,noscript',
  285. start: function(name, attrs) {
  286. if (!data.source1 && name == "param") {
  287. data.source1 = attrs.map.movie;
  288. }
  289. if (name == "iframe" || name == "object" || name == "embed" || name == "video" || name == "audio") {
  290. if (!data.type) {
  291. data.type = name;
  292. }
  293. data = tinymce.extend(attrs.map, data);
  294. }
  295. if (name == "script") {
  296. var videoScript = getVideoScriptMatch(attrs.map.src);
  297. if (!videoScript) {
  298. return;
  299. }
  300. data = {
  301. type: "script",
  302. source1: attrs.map.src,
  303. width: videoScript.width,
  304. height: videoScript.height
  305. };
  306. }
  307. if (name == "source") {
  308. if (!data.source1) {
  309. data.source1 = attrs.map.src;
  310. } else if (!data.source2) {
  311. data.source2 = attrs.map.src;
  312. }
  313. }
  314. if (name == "img" && !data.poster) {
  315. data.poster = attrs.map.src;
  316. }
  317. }
  318. }).parse(html);
  319. data.source1 = data.source1 || data.src || data.data;
  320. data.source2 = data.source2 || '';
  321. data.poster = data.poster || '';
  322. return data;
  323. }
  324. function getData(element) {
  325. if (element.getAttribute('data-mce-object')) {
  326. return htmlToData(editor.serializer.serialize(element, {selection: true}));
  327. }
  328. return {};
  329. }
  330. function sanitize(html) {
  331. if (editor.settings.media_filter_html === false) {
  332. return html;
  333. }
  334. var writer = new tinymce.html.Writer();
  335. new tinymce.html.SaxParser({
  336. validate: false,
  337. allow_conditional_comments: false,
  338. special: 'script,noscript',
  339. comment: function(text) {
  340. writer.comment(text);
  341. },
  342. cdata: function(text) {
  343. writer.cdata(text);
  344. },
  345. text: function(text, raw) {
  346. writer.text(text, raw);
  347. },
  348. start: function(name, attrs, empty) {
  349. if (name == 'script' || name == 'noscript') {
  350. return;
  351. }
  352. for (var i = 0; i < attrs.length; i++) {
  353. if (attrs[i].name.indexOf('on') === 0) {
  354. return;
  355. }
  356. }
  357. writer.start(name, attrs, empty);
  358. },
  359. end: function(name) {
  360. if (name == 'script' || name == 'noscript') {
  361. return;
  362. }
  363. writer.end(name);
  364. }
  365. }, new tinymce.html.Schema({})).parse(html);
  366. return writer.getContent();
  367. }
  368. function updateHtml(html, data, updateAll) {
  369. var writer = new tinymce.html.Writer();
  370. var sourceCount = 0, hasImage;
  371. function setAttributes(attrs, updatedAttrs) {
  372. var name, i, value, attr;
  373. for (name in updatedAttrs) {
  374. value = "" + updatedAttrs[name];
  375. if (attrs.map[name]) {
  376. i = attrs.length;
  377. while (i--) {
  378. attr = attrs[i];
  379. if (attr.name == name) {
  380. if (value) {
  381. attrs.map[name] = value;
  382. attr.value = value;
  383. } else {
  384. delete attrs.map[name];
  385. attrs.splice(i, 1);
  386. }
  387. }
  388. }
  389. } else if (value) {
  390. attrs.push({
  391. name: name,
  392. value: value
  393. });
  394. attrs.map[name] = value;
  395. }
  396. }
  397. }
  398. new tinymce.html.SaxParser({
  399. validate: false,
  400. allow_conditional_comments: true,
  401. special: 'script,noscript',
  402. comment: function(text) {
  403. writer.comment(text);
  404. },
  405. cdata: function(text) {
  406. writer.cdata(text);
  407. },
  408. text: function(text, raw) {
  409. writer.text(text, raw);
  410. },
  411. start: function(name, attrs, empty) {
  412. switch (name) {
  413. case "video":
  414. case "object":
  415. case "embed":
  416. case "img":
  417. case "iframe":
  418. setAttributes(attrs, {
  419. style: 'width:'+data.width+'; height:'+data.height+';'
  420. });
  421. break;
  422. }
  423. if (updateAll) {
  424. switch (name) {
  425. case "video":
  426. setAttributes(attrs, {
  427. poster: data.poster,
  428. src: ""
  429. });
  430. if (data.source2) {
  431. setAttributes(attrs, {
  432. src: ""
  433. });
  434. }
  435. break;
  436. case "iframe":
  437. setAttributes(attrs, {
  438. src: data.source1
  439. });
  440. break;
  441. case "source":
  442. sourceCount++;
  443. if (sourceCount <= 2) {
  444. setAttributes(attrs, {
  445. src: data["source" + sourceCount],
  446. type: data["source" + sourceCount + "mime"]
  447. });
  448. if (!data["source" + sourceCount]) {
  449. return;
  450. }
  451. }
  452. break;
  453. case "img":
  454. if (!data.poster) {
  455. return;
  456. }
  457. hasImage = true;
  458. break;
  459. }
  460. }
  461. writer.start(name, attrs, empty);
  462. },
  463. end: function(name) {
  464. if (name == "video" && updateAll) {
  465. for (var index = 1; index <= 2; index++) {
  466. if (data["source" + index]) {
  467. var attrs = [];
  468. attrs.map = {};
  469. if (sourceCount < index) {
  470. setAttributes(attrs, {
  471. src: data["source" + index],
  472. type: data["source" + index + "mime"]
  473. });
  474. writer.start("source", attrs, true);
  475. }
  476. }
  477. }
  478. }
  479. if (data.poster && name == "object" && updateAll && !hasImage) {
  480. var imgAttrs = [];
  481. imgAttrs.map = {};
  482. setAttributes(imgAttrs, {
  483. src: data.poster,
  484. width: data.width,
  485. height: data.height
  486. });
  487. writer.start("img", imgAttrs, true);
  488. }
  489. writer.end(name);
  490. }
  491. }, new tinymce.html.Schema({})).parse(html);
  492. return writer.getContent();
  493. }
  494. editor.on('ResolveName', function(e) {
  495. var name;
  496. if (e.target.nodeType == 1 && (name = e.target.getAttribute("data-mce-object"))) {
  497. e.name = name;
  498. }
  499. });
  500. editor.on('preInit', function() {
  501. // Make sure that any messy HTML is retained inside these
  502. var specialElements = editor.schema.getSpecialElements();
  503. tinymce.each('video audio iframe object'.split(' '), function(name) {
  504. specialElements[name] = new RegExp('<\/' + name + '[^>]*>', 'gi');
  505. });
  506. // Allow elements
  507. //editor.schema.addValidElements('object[id|style|width|height|classid|codebase|*],embed[id|style|width|height|type|src|*],video[*],audio[*]');
  508. // Set allowFullscreen attribs as boolean
  509. var boolAttrs = editor.schema.getBoolAttrs();
  510. tinymce.each('webkitallowfullscreen mozallowfullscreen allowfullscreen'.split(' '), function(name) {
  511. boolAttrs[name] = {};
  512. });
  513. // Converts iframe, video etc into placeholder images
  514. editor.parser.addNodeFilter('iframe,video,audio,object,embed,script', function(nodes, name) {
  515. var i = nodes.length, ai, node, placeHolder, attrName, attrValue, attribs, innerHtml;
  516. var videoScript;
  517. while (i--) {
  518. node = nodes[i];
  519. if (!node.parent) {
  520. continue;
  521. }
  522. if (node.name == 'script') {
  523. videoScript = getVideoScriptMatch(node.attr('src'));
  524. if (!videoScript) {
  525. continue;
  526. }
  527. }
  528. placeHolder = new tinymce.html.Node('img', 1);
  529. placeHolder.shortEnded = true;
  530. if (videoScript) {
  531. if (videoScript.width) {
  532. node.attr('width', videoScript.width.toString());
  533. }
  534. if (videoScript.height) {
  535. node.attr('height', videoScript.height.toString());
  536. }
  537. }
  538. // Prefix all attributes except width, height and style since we
  539. // will add these to the placeholder
  540. attribs = node.attributes;
  541. ai = attribs.length;
  542. while (ai--) {
  543. attrName = attribs[ai].name;
  544. attrValue = attribs[ai].value;
  545. if (attrName !== "width" && attrName !== "height" && attrName !== "style") {
  546. if (attrName == "data" || attrName == "src") {
  547. attrValue = editor.convertURL(attrValue, attrName);
  548. }
  549. placeHolder.attr('data-mce-p-' + attrName, attrValue);
  550. }
  551. }
  552. // Place the inner HTML contents inside an escaped attribute
  553. // This enables us to copy/paste the fake object
  554. innerHtml = node.firstChild && node.firstChild.value;
  555. if (innerHtml) {
  556. placeHolder.attr("data-mce-html", escape(innerHtml));
  557. placeHolder.firstChild = null;
  558. }
  559. placeHolder.attr({
  560. width: node.attr('width') || "300",
  561. height: node.attr('height') || (name == "audio" ? "30" : "150"),
  562. style: node.attr('style'),
  563. src: tinymce.Env.transparentSrc,
  564. "data-mce-object": name,
  565. "class": "mce-object mce-object-" + name
  566. });
  567. node.replace(placeHolder);
  568. }
  569. });
  570. // Replaces placeholder images with real elements for video, object, iframe etc
  571. editor.serializer.addAttributeFilter('data-mce-object', function(nodes, name) {
  572. var i = nodes.length, node, realElm, ai, attribs, innerHtml, innerNode, realElmName;
  573. while (i--) {
  574. node = nodes[i];
  575. if (!node.parent) {
  576. continue;
  577. }
  578. realElmName = node.attr(name);
  579. realElm = new tinymce.html.Node(realElmName, 1);
  580. // Add width/height to everything but audio
  581. if (realElmName != "audio" && realElmName != "script") {
  582. realElm.attr({
  583. width: node.attr('width'),
  584. height: node.attr('height')
  585. });
  586. }
  587. realElm.attr({
  588. style: node.attr('style')
  589. });
  590. // Unprefix all placeholder attributes
  591. attribs = node.attributes;
  592. ai = attribs.length;
  593. while (ai--) {
  594. var attrName = attribs[ai].name;
  595. if (attrName.indexOf('data-mce-p-') === 0) {
  596. realElm.attr(attrName.substr(11), attribs[ai].value);
  597. }
  598. }
  599. if (realElmName == "script") {
  600. realElm.attr('type', 'text/javascript');
  601. }
  602. // Inject innerhtml
  603. innerHtml = node.attr('data-mce-html');
  604. if (innerHtml) {
  605. innerNode = new tinymce.html.Node('#text', 3);
  606. innerNode.raw = true;
  607. innerNode.value = sanitize(unescape(innerHtml));
  608. realElm.append(innerNode);
  609. }
  610. node.replace(realElm);
  611. }
  612. });
  613. });
  614. editor.on('ObjectSelected', function(e) {
  615. var objectType = e.target.getAttribute('data-mce-object');
  616. if (objectType == "audio" || objectType == "script") {
  617. e.preventDefault();
  618. }
  619. });
  620. editor.on('objectResized', function(e) {
  621. var target = e.target, html;
  622. if (target.getAttribute('data-mce-object')) {
  623. html = target.getAttribute('data-mce-html');
  624. if (html) {
  625. html = unescape(html);
  626. target.setAttribute('data-mce-html', escape(
  627. updateHtml(html, {
  628. width: e.width,
  629. height: e.height
  630. })
  631. ));
  632. }
  633. }
  634. });
  635. editor.addButton('media', {
  636. tooltip: 'Insert/edit video',
  637. onclick: showDialog,
  638. stateSelector: ['img[data-mce-object=video]', 'img[data-mce-object=iframe]']
  639. });
  640. editor.addMenuItem('media', {
  641. icon: 'media',
  642. text: 'Insert video',
  643. onclick: showDialog,
  644. context: 'insert',
  645. prependToContext: true
  646. });
  647. });