plugin.js 0000644 00000240664 15021307423 0006411 0 ustar 00 (function () {
var paste = (function (domGlobals) {
'use strict';
var Cell = function (initial) {
var value = initial;
var get = function () {
return value;
};
var set = function (v) {
value = v;
};
var clone = function () {
return Cell(get());
};
return {
get: get,
set: set,
clone: clone
};
};
var global$1 = tinymce.util.Tools.resolve('tinymce.PluginManager');
var hasProPlugin = function (editor) {
if (/(^|[ ,])powerpaste([, ]|$)/.test(editor.settings.plugins) && global$1.get('powerpaste')) {
if (typeof domGlobals.window.console !== 'undefined' && domGlobals.window.console.log) {
domGlobals.window.console.log('PowerPaste is incompatible with Paste plugin! Remove \'paste\' from the \'plugins\' option.');
}
return true;
} else {
return false;
}
};
var DetectProPlugin = { hasProPlugin: hasProPlugin };
var get = function (clipboard, quirks) {
return {
clipboard: clipboard,
quirks: quirks
};
};
var Api = { get: get };
var firePastePreProcess = function (editor, html, internal, isWordHtml) {
return editor.fire('PastePreProcess', {
content: html,
internal: internal,
wordContent: isWordHtml
});
};
var firePastePostProcess = function (editor, node, internal, isWordHtml) {
return editor.fire('PastePostProcess', {
node: node,
internal: internal,
wordContent: isWordHtml
});
};
var firePastePlainTextToggle = function (editor, state) {
return editor.fire('PastePlainTextToggle', { state: state });
};
var firePaste = function (editor, ieFake) {
return editor.fire('paste', { ieFake: ieFake });
};
var Events = {
firePastePreProcess: firePastePreProcess,
firePastePostProcess: firePastePostProcess,
firePastePlainTextToggle: firePastePlainTextToggle,
firePaste: firePaste
};
var shouldPlainTextInform = function (editor) {
return editor.getParam('paste_plaintext_inform', true);
};
var shouldBlockDrop = function (editor) {
return editor.getParam('paste_block_drop', false);
};
var shouldPasteDataImages = function (editor) {
return editor.getParam('paste_data_images', false);
};
var shouldFilterDrop = function (editor) {
return editor.getParam('paste_filter_drop', true);
};
var getPreProcess = function (editor) {
return editor.getParam('paste_preprocess');
};
var getPostProcess = function (editor) {
return editor.getParam('paste_postprocess');
};
var getWebkitStyles = function (editor) {
return editor.getParam('paste_webkit_styles');
};
var shouldRemoveWebKitStyles = function (editor) {
return editor.getParam('paste_remove_styles_if_webkit', true);
};
var shouldMergeFormats = function (editor) {
return editor.getParam('paste_merge_formats', true);
};
var isSmartPasteEnabled = function (editor) {
return editor.getParam('smart_paste', true);
};
var isPasteAsTextEnabled = function (editor) {
return editor.getParam('paste_as_text', false);
};
var getRetainStyleProps = function (editor) {
return editor.getParam('paste_retain_style_properties');
};
var getWordValidElements = function (editor) {
var defaultValidElements = '-strong/b,-em/i,-u,-span,-p,-ol,-ul,-li,-h1,-h2,-h3,-h4,-h5,-h6,' + '-p/div,-a[href|name],sub,sup,strike,br,del,table[width],tr,' + 'td[colspan|rowspan|width],th[colspan|rowspan|width],thead,tfoot,tbody';
return editor.getParam('paste_word_valid_elements', defaultValidElements);
};
var shouldConvertWordFakeLists = function (editor) {
return editor.getParam('paste_convert_word_fake_lists', true);
};
var shouldUseDefaultFilters = function (editor) {
return editor.getParam('paste_enable_default_filters', true);
};
var Settings = {
shouldPlainTextInform: shouldPlainTextInform,
shouldBlockDrop: shouldBlockDrop,
shouldPasteDataImages: shouldPasteDataImages,
shouldFilterDrop: shouldFilterDrop,
getPreProcess: getPreProcess,
getPostProcess: getPostProcess,
getWebkitStyles: getWebkitStyles,
shouldRemoveWebKitStyles: shouldRemoveWebKitStyles,
shouldMergeFormats: shouldMergeFormats,
isSmartPasteEnabled: isSmartPasteEnabled,
isPasteAsTextEnabled: isPasteAsTextEnabled,
getRetainStyleProps: getRetainStyleProps,
getWordValidElements: getWordValidElements,
shouldConvertWordFakeLists: shouldConvertWordFakeLists,
shouldUseDefaultFilters: shouldUseDefaultFilters
};
var shouldInformUserAboutPlainText = function (editor, userIsInformedState) {
return userIsInformedState.get() === false && Settings.shouldPlainTextInform(editor);
};
var displayNotification = function (editor, message) {
editor.notificationManager.open({
text: editor.translate(message),
type: 'info'
});
};
var togglePlainTextPaste = function (editor, clipboard, userIsInformedState) {
if (clipboard.pasteFormat.get() === 'text') {
clipboard.pasteFormat.set('html');
Events.firePastePlainTextToggle(editor, false);
} else {
clipboard.pasteFormat.set('text');
Events.firePastePlainTextToggle(editor, true);
if (shouldInformUserAboutPlainText(editor, userIsInformedState)) {
displayNotification(editor, 'Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off.');
userIsInformedState.set(true);
}
}
editor.focus();
};
var Actions = { togglePlainTextPaste: togglePlainTextPaste };
var register = function (editor, clipboard, userIsInformedState) {
editor.addCommand('mceTogglePlainTextPaste', function () {
Actions.togglePlainTextPaste(editor, clipboard, userIsInformedState);
});
editor.addCommand('mceInsertClipboardContent', function (ui, value) {
if (value.content) {
clipboard.pasteHtml(value.content, value.internal);
}
if (value.text) {
clipboard.pasteText(value.text);
}
});
};
var Commands = { register: register };
var global$2 = tinymce.util.Tools.resolve('tinymce.Env');
var global$3 = tinymce.util.Tools.resolve('tinymce.util.Delay');
var global$4 = tinymce.util.Tools.resolve('tinymce.util.Tools');
var global$5 = tinymce.util.Tools.resolve('tinymce.util.VK');
var internalMimeType = 'x-tinymce/html';
var internalMark = '';
var mark = function (html) {
return internalMark + html;
};
var unmark = function (html) {
return html.replace(internalMark, '');
};
var isMarked = function (html) {
return html.indexOf(internalMark) !== -1;
};
var InternalHtml = {
mark: mark,
unmark: unmark,
isMarked: isMarked,
internalHtmlMime: function () {
return internalMimeType;
}
};
var global$6 = tinymce.util.Tools.resolve('tinymce.html.Entities');
var isPlainText = function (text) {
return !/<(?:\/?(?!(?:div|p|br|span)>)\w+|(?:(?!(?:span style="white-space:\s?pre;?">)|br\s?\/>))\w+\s[^>]+)>/i.test(text);
};
var toBRs = function (text) {
return text.replace(/\r?\n/g, '
');
};
var openContainer = function (rootTag, rootAttrs) {
var key;
var attrs = [];
var tag = '<' + rootTag;
if (typeof rootAttrs === 'object') {
for (key in rootAttrs) {
if (rootAttrs.hasOwnProperty(key)) {
attrs.push(key + '="' + global$6.encodeAllRaw(rootAttrs[key]) + '"');
}
}
if (attrs.length) {
tag += ' ' + attrs.join(' ');
}
}
return tag + '>';
};
var toBlockElements = function (text, rootTag, rootAttrs) {
var blocks = text.split(/\n\n/);
var tagOpen = openContainer(rootTag, rootAttrs);
var tagClose = '' + rootTag + '>';
var paragraphs = global$4.map(blocks, function (p) {
return p.split(/\n/).join('
');
});
var stitch = function (p) {
return tagOpen + p + tagClose;
};
return paragraphs.length === 1 ? paragraphs[0] : global$4.map(paragraphs, stitch).join('');
};
var convert = function (text, rootTag, rootAttrs) {
return rootTag ? toBlockElements(text, rootTag, rootAttrs) : toBRs(text);
};
var Newlines = {
isPlainText: isPlainText,
convert: convert,
toBRs: toBRs,
toBlockElements: toBlockElements
};
var global$7 = tinymce.util.Tools.resolve('tinymce.html.DomParser');
var global$8 = tinymce.util.Tools.resolve('tinymce.html.Serializer');
var global$9 = tinymce.util.Tools.resolve('tinymce.html.Node');
var global$a = tinymce.util.Tools.resolve('tinymce.html.Schema');
function filter(content, items) {
global$4.each(items, function (v) {
if (v.constructor === RegExp) {
content = content.replace(v, '');
} else {
content = content.replace(v[0], v[1]);
}
});
return content;
}
function innerText(html) {
var schema = global$a();
var domParser = global$7({}, schema);
var text = '';
var shortEndedElements = schema.getShortEndedElements();
var ignoreElements = global$4.makeMap('script noscript style textarea video audio iframe object', ' ');
var blockElements = schema.getBlockElements();
function walk(node) {
var name = node.name, currentNode = node;
if (name === 'br') {
text += '\n';
return;
}
if (name === 'wbr') {
return;
}
if (shortEndedElements[name]) {
text += ' ';
}
if (ignoreElements[name]) {
text += ' ';
return;
}
if (node.type === 3) {
text += node.value;
}
if (!node.shortEnded) {
if (node = node.firstChild) {
do {
walk(node);
} while (node = node.next);
}
}
if (blockElements[name] && currentNode.next) {
text += '\n';
if (name === 'p') {
text += '\n';
}
}
}
html = filter(html, [//g]);
walk(domParser.parse(html));
return text;
}
function trimHtml(html) {
function trimSpaces(all, s1, s2) {
if (!s1 && !s2) {
return ' ';
}
return '\xA0';
}
html = filter(html, [
/^[\s\S]*