X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/41578db67d72562346e4dbb2a14889b23d522813..refs/tags/wordpress-4.2:/wp-includes/js/tinymce/plugins/media/plugin.js diff --git a/wp-includes/js/tinymce/plugins/media/plugin.js b/wp-includes/js/tinymce/plugins/media/plugin.js index a97d5a06..4507e6bf 100644 --- a/wp-includes/js/tinymce/plugins/media/plugin.js +++ b/wp-includes/js/tinymce/plugins/media/plugin.js @@ -17,10 +17,15 @@ tinymce.PluginManager.add('media', function(editor, url) { {regex: /youtu\.be\/([\w\-.]+)/, type: 'iframe', w: 425, h: 350, url: '//www.youtube.com/embed/$1'}, {regex: /youtube\.com(.+)v=([^&]+)/, type: 'iframe', w: 425, h: 350, url: '//www.youtube.com/embed/$2'}, {regex: /vimeo\.com\/([0-9]+)/, type: 'iframe', w: 425, h: 350, url: '//player.vimeo.com/video/$1?title=0&byline=0&portrait=0&color=8dc7dc'}, + {regex: /vimeo\.com\/(.*)\/([0-9]+)/, type: "iframe", w: 425, h: 350, url: "//player.vimeo.com/video/$2?title=0&byline=0"}, {regex: /maps\.google\.([a-z]{2,3})\/maps\/(.+)msid=(.+)/, type: 'iframe', w: 425, h: 350, url: '//maps.google.com/maps/ms?msid=$2&output=embed"'} ]; + var embedChange = (tinymce.Env.ie && tinymce.Env.ie <= 8) ? 'onChange' : 'onInput'; + function guessMime(url) { + url = url.toLowerCase(); + if (url.indexOf('.mp3') != -1) { return 'audio/mpeg'; } @@ -62,8 +67,21 @@ tinymce.PluginManager.add('media', function(editor, url) { function showDialog() { var win, width, height, data; + var generalFormItems = [ - {name: 'source1', type: 'filepicker', filetype: 'media', size: 40, autofocus: true, label: 'Source'} + { + name: 'source1', + type: 'filepicker', + filetype: 'media', + size: 40, + autofocus: true, + label: 'Source', + onchange: function(e) { + tinymce.each(e.meta, function(value, key) { + win.find('#' + key).value(value); + }); + } + } ]; function recalcSize(e) { @@ -78,10 +96,16 @@ tinymce.PluginManager.add('media', function(editor, url) { if (win.find('#constrain')[0].checked() && width && height && newWidth && newHeight) { if (e.control == widthCtrl) { newHeight = Math.round((newWidth / width) * newHeight); - heightCtrl.value(newHeight); + + if (!isNaN(newHeight)) { + heightCtrl.value(newHeight); + } } else { newWidth = Math.round((newHeight / height) * newWidth); - widthCtrl.value(newWidth); + + if (!isNaN(newWidth)) { + widthCtrl.value(newWidth); + } } } @@ -105,9 +129,9 @@ tinymce.PluginManager.add('media', function(editor, url) { align: 'center', spacing: 5, items: [ - {name: 'width', type: 'textbox', maxLength: 3, size: 3, onchange: recalcSize}, + {name: 'width', type: 'textbox', maxLength: 5, size: 3, onchange: recalcSize, ariaLabel: 'Width'}, {type: 'label', text: 'x'}, - {name: 'height', type: 'textbox', maxLength: 3, size: 3, onchange: recalcSize}, + {name: 'height', type: 'textbox', maxLength: 5, size: 3, onchange: recalcSize, ariaLabel: 'Height'}, {name: 'constrain', type: 'checkbox', checked: true, text: 'Constrain proportions'} ] }); @@ -117,6 +141,23 @@ tinymce.PluginManager.add('media', function(editor, url) { width = data.width; height = data.height; + var embedTextBox = { + id: 'mcemediasource', + type: 'textbox', + flex: 1, + name: 'embed', + value: getSource(), + multiline: true, + label: 'Source' + }; + + function updateValueOnChange() { + data = htmlToData(this.value()); + this.parent().parent().fromJSON(data); + } + + embedTextBox[embedChange] = updateValueOnChange; + win = editor.windowManager.open({ title: 'Insert/edit video', data: data, @@ -149,20 +190,28 @@ tinymce.PluginManager.add('media', function(editor, url) { text: 'Paste your embed code below:', forId: 'mcemediasource' }, - { - id: 'mcemediasource', - type: 'textbox', - flex: 1, - name: 'embed', - value: getSource(), - multiline: true, - label: 'Source' - } + embedTextBox ] } ], onSubmit: function() { + var beforeObjects, afterObjects, i, y; + + beforeObjects = editor.dom.select('img[data-mce-object]'); editor.insertContent(dataToHtml(this.toJSON())); + afterObjects = editor.dom.select('img[data-mce-object]'); + + // Find new image placeholder so we can select it + for (i = 0; i < beforeObjects.length; i++) { + for (y = afterObjects.length - 1; y >= 0; y--) { + if (beforeObjects[i] == afterObjects[y]) { + afterObjects.splice(y, 1); + } + } + } + + editor.selection.select(afterObjects[0]); + editor.nodeChanged(); } }); } @@ -200,30 +249,30 @@ tinymce.PluginManager.add('media', function(editor, url) { data.poster = editor.convertURL(data.poster, "poster"); data.flashPlayerUrl = editor.convertURL(url + '/moxieplayer.swf', "movie"); - if (data.embed) { - html = updateHtml(data.embed, data, true); - } else { - tinymce.each(urlPatterns, function(pattern) { - var match, i, url; - - if ((match = pattern.regex.exec(data.source1))) { - url = pattern.url; + tinymce.each(urlPatterns, function(pattern) { + var match, i, url; - for (i = 0; match[i]; i++) { - /*jshint loopfunc:true*/ - /*eslint no-loop-func:0 */ - url = url.replace('$' + i, function() { - return match[i]; - }); - } + if ((match = pattern.regex.exec(data.source1))) { + url = pattern.url; - data.source1 = url; - data.type = pattern.type; - data.width = data.width || pattern.w; - data.height = data.height || pattern.h; + for (i = 0; match[i]; i++) { + /*jshint loopfunc:true*/ + /*eslint no-loop-func:0 */ + url = url.replace('$' + i, function() { + return match[i]; + }); } - }); + data.source1 = url; + data.type = pattern.type; + data.width = data.width || pattern.w; + data.height = data.height || pattern.h; + } + }); + + if (data.embed) { + html = updateHtml(data.embed, data, true); + } else { var videoScript = getVideoScriptMatch(data.source1); if (videoScript) { data.type = 'script'; @@ -340,6 +389,56 @@ tinymce.PluginManager.add('media', function(editor, url) { return {}; } + function sanitize(html) { + if (editor.settings.media_filter_html === false) { + return html; + } + + var writer = new tinymce.html.Writer(); + + new tinymce.html.SaxParser({ + validate: false, + allow_conditional_comments: false, + special: 'script,noscript', + + comment: function(text) { + writer.comment(text); + }, + + cdata: function(text) { + writer.cdata(text); + }, + + text: function(text, raw) { + writer.text(text, raw); + }, + + start: function(name, attrs, empty) { + if (name == 'script' || name == 'noscript') { + return; + } + + for (var i = 0; i < attrs.length; i++) { + if (attrs[i].name.indexOf('on') === 0) { + return; + } + } + + writer.start(name, attrs, empty); + }, + + end: function(name) { + if (name == 'script' || name == 'noscript') { + return; + } + + writer.end(name); + } + }, new tinymce.html.Schema({})).parse(html); + + return writer.getContent(); + } + function updateHtml(html, data, updateAll) { var writer = new tinymce.html.Writer(); var sourceCount = 0, hasImage; @@ -404,7 +503,7 @@ tinymce.PluginManager.add('media', function(editor, url) { width: data.width, height: data.height }); - break; + break; } if (updateAll) { @@ -420,13 +519,13 @@ tinymce.PluginManager.add('media', function(editor, url) { src: "" }); } - break; + break; case "iframe": setAttributes(attrs, { src: data.source1 }); - break; + break; case "source": sourceCount++; @@ -441,7 +540,7 @@ tinymce.PluginManager.add('media', function(editor, url) { return; } } - break; + break; case "img": if (!data.poster) { @@ -507,11 +606,11 @@ tinymce.PluginManager.add('media', function(editor, url) { // Make sure that any messy HTML is retained inside these var specialElements = editor.schema.getSpecialElements(); tinymce.each('video audio iframe object'.split(' '), function(name) { - specialElements[name] = new RegExp('<\/' + name + '[^>]*>','gi'); + specialElements[name] = new RegExp('<\/' + name + '[^>]*>', 'gi'); }); // Allow elements - editor.schema.addValidElements('object[id|style|width|height|classid|codebase|*],embed[id|style|width|height|type|src|*],video[*],audio[*]'); + //editor.schema.addValidElements('object[id|style|width|height|classid|codebase|*],embed[id|style|width|height|type|src|*],video[*],audio[*]'); // Set allowFullscreen attribs as boolean var boolAttrs = editor.schema.getBoolAttrs(); @@ -526,6 +625,9 @@ tinymce.PluginManager.add('media', function(editor, url) { while (i--) { node = nodes[i]; + if (!node.parent) { + continue; + } if (node.name == 'script') { videoScript = getVideoScriptMatch(node.attr('src')); @@ -591,6 +693,10 @@ tinymce.PluginManager.add('media', function(editor, url) { while (i--) { node = nodes[i]; + if (!node.parent) { + continue; + } + realElmName = node.attr(name); realElm = new tinymce.html.Node(realElmName, 1); @@ -626,7 +732,7 @@ tinymce.PluginManager.add('media', function(editor, url) { if (innerHtml) { innerNode = new tinymce.html.Node('#text', 3); innerNode.raw = true; - innerNode.value = unescape(innerHtml); + innerNode.value = sanitize(unescape(innerHtml)); realElm.append(innerNode); } @@ -668,7 +774,7 @@ tinymce.PluginManager.add('media', function(editor, url) { editor.addMenuItem('media', { icon: 'media', - text: 'Insert video', + text: 'Insert/edit video', onclick: showDialog, context: 'insert', prependToContext: true