/**
* plugin.js
*
- * Copyright, Moxiecode Systems AB
* Released under LGPL License.
+ * Copyright (c) 1999-2015 Ephox Corp. All rights reserved
*
* License: http://www.tinymce.com/license
* Contributing: http://www.tinymce.com/contributing
{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';
}
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) {
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);
+ }
}
}
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'}
]
});
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,
{
title: 'Embed',
- type: "panel",
+ type: "container",
layout: 'flex',
direction: 'column',
align: 'stretch',
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();
}
});
}
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';
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;
width: data.width,
height: data.height
});
- break;
+ break;
}
if (updateAll) {
src: ""
});
}
- break;
+ break;
case "iframe":
setAttributes(attrs, {
src: data.source1
});
- break;
+ break;
case "source":
sourceCount++;
return;
}
}
- break;
+ break;
case "img":
if (!data.poster) {
// 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();
while (i--) {
node = nodes[i];
+ if (!node.parent) {
+ continue;
+ }
if (node.name == 'script') {
videoScript = getVideoScriptMatch(node.attr('src'));
while (i--) {
node = nodes[i];
+ if (!node.parent) {
+ continue;
+ }
+
realElmName = node.attr(name);
realElm = new tinymce.html.Node(realElmName, 1);
if (innerHtml) {
innerNode = new tinymce.html.Node('#text', 3);
innerNode.raw = true;
- innerNode.value = unescape(innerHtml);
+ innerNode.value = sanitize(unescape(innerHtml));
realElm.append(innerNode);
}
editor.addMenuItem('media', {
icon: 'media',
- text: 'Insert video',
+ text: 'Insert/edit video',
onclick: showDialog,
context: 'insert',
prependToContext: true