]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/js/tinymce/plugins/media/plugin.js
WordPress 4.0
[autoinstalls/wordpress.git] / wp-includes / js / tinymce / plugins / media / plugin.js
index a97d5a067aaabf3a11735a7016f8ccf86e6a8249..3739f7051568a0a81804f965ae08b0cac68d0f03 100644 (file)
@@ -17,9 +17,12 @@ 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) {
                if (url.indexOf('.mp3') != -1) {
                        return 'audio/mpeg';
@@ -62,8 +65,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) {
@@ -117,6 +133,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 +182,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 +241,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 +381,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 +495,7 @@ tinymce.PluginManager.add('media', function(editor, url) {
                                                        width: data.width,
                                                        height: data.height
                                                });
-                                       break;
+                                               break;
                                }
 
                                if (updateAll) {
@@ -420,13 +511,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 +532,7 @@ tinymce.PluginManager.add('media', function(editor, url) {
                                                                        return;
                                                                }
                                                        }
-                                               break;
+                                                       break;
 
                                                case "img":
                                                        if (!data.poster) {
@@ -507,11 +598,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 +617,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 +685,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 +724,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);
                                }