plugin.js 0000666 00000147130 15214116547 0006420 0 ustar 00 /** * Compiled inline version. (Library mode) */ /*jshint smarttabs:true, undef:true, latedef:true, curly:true, bitwise:true, camelcase:true */ /*globals $code */ (function(exports, undefined) { "use strict"; var modules = {}; function require(ids, callback) { var module, defs = []; for (var i = 0; i < ids.length; ++i) { module = modules[ids[i]] || resolve(ids[i]); if (!module) { throw 'module definition dependecy not found: ' + ids[i]; } defs.push(module); } callback.apply(null, defs); } function define(id, dependencies, definition) { if (typeof id !== 'string') { throw 'invalid module definition, module id must be defined and be a string'; } if (dependencies === undefined) { throw 'invalid module definition, dependencies must be specified'; } if (definition === undefined) { throw 'invalid module definition, definition function must be specified'; } require(dependencies, function() { modules[id] = definition.apply(null, arguments); }); } function defined(id) { return !!modules[id]; } function resolve(id) { var target = exports; var fragments = id.split(/[.\/]/); for (var fi = 0; fi < fragments.length; ++fi) { if (!target[fragments[fi]]) { return; } target = target[fragments[fi]]; } return target; } function expose(ids) { var i, target, id, fragments, privateModules; for (i = 0; i < ids.length; i++) { target = exports; id = ids[i]; fragments = id.split(/[.\/]/); for (var fi = 0; fi < fragments.length - 1; ++fi) { if (target[fragments[fi]] === undefined) { target[fragments[fi]] = {}; } target = target[fragments[fi]]; } target[fragments[fragments.length - 1]] = modules[id]; } // Expose private modules for unit tests if (exports.AMDLC_TESTS) { privateModules = exports.privateModules || {}; for (id in modules) { privateModules[id] = modules[id]; } for (i = 0; i < ids.length; i++) { delete privateModules[ids[i]]; } exports.privateModules = privateModules; } } // Included from: js/tinymce/plugins/paste/classes/Utils.js /** * Utils.js * * 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 */ /** * This class contails various utility functions for the paste plugin. * * @class tinymce.pasteplugin.Utils */ define("tinymce/pasteplugin/Utils", [ "tinymce/util/Tools", "tinymce/html/DomParser", "tinymce/html/Schema" ], function(Tools, DomParser, Schema) { function filter(content, items) { Tools.each(items, function(v) { if (v.constructor == RegExp) { content = content.replace(v, ''); } else { content = content.replace(v[0], v[1]); } }); return content; } /** * Gets the innerText of the specified element. It will handle edge cases * and works better than textContent on Gecko. * * @param {String} html HTML string to get text from. * @return {String} String of text with line feeds. */ function innerText(html) { var schema = new Schema(), domParser = new DomParser({}, schema), text = ''; var shortEndedElements = schema.getShortEndedElements(); var ignoreElements = Tools.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; } // img/input/hr if (shortEndedElements[name]) { text += ' '; } // Ingore script, video contents if (ignoreElements[name]) { text += ' '; return; } if (node.type == 3) { text += node.value; } // Walk all children if (!node.shortEnded) { if ((node = node.firstChild)) { do { walk(node); } while ((node = node.next)); } } // Add \n or \n\n for blocks or P if (blockElements[name] && currentNode.next) { text += '\n'; if (name == 'p') { text += '\n'; } } } html = filter(html, [ //g // Conditional comments ]); walk(domParser.parse(html)); return text; } /** * Trims the specified HTML by removing all WebKit fragments, all elements wrapping the body trailing BR elements etc. * * @param {String} html Html string to trim contents on. * @return {String} Html contents that got trimmed. */ function trimHtml(html) { function trimSpaces(all, s1, s2) { // WebKit meant to preserve multiple spaces but instead inserted around all inline tags, // including the spans with inline styles created on paste if (!s1 && !s2) { return ' '; } return '\u00a0'; } html = filter(html, [ /^[\s\S]*
]*>\s*|\s*<\/body[^>]*>[\s\S]*$/g, // Remove anything but the contents within the BODY element /|/g, // Inner fragments (tables from excel on mac) [/( ?)\u00a0<\/span>( ?)/g, trimSpaces], /
var forcedRootBlockName = editor.settings.forced_root_block;
var forcedRootBlockStartHtml;
if (forcedRootBlockName) {
forcedRootBlockStartHtml = editor.dom.createHTML(forcedRootBlockName, editor.settings.forced_root_block_attrs);
forcedRootBlockStartHtml = forcedRootBlockStartHtml.substr(0, forcedRootBlockStartHtml.length - 3) + '>';
}
if ((startBlock && /^(PRE|DIV)$/.test(startBlock.nodeName)) || !forcedRootBlockName) {
text = Utils.filter(text, [
[/\n/g, "
"]
]);
} else {
text = Utils.filter(text, [
[/\n\n/g, "
)$/, forcedRootBlockStartHtml + '$1'],
[/\n/g, "
"]
]);
if (text.indexOf('
') != -1) {
text = forcedRootBlockStartHtml + text;
}
}
pasteHtml(text);
}
/**
* Creates a paste bin element as close as possible to the current caret location and places the focus inside that element
* so that when the real paste event occurs the contents gets inserted into this element
* instead of the current editor selection element.
*/
function createPasteBin() {
var dom = editor.dom, body = editor.getBody();
var viewport = editor.dom.getViewPort(editor.getWin()), scrollTop = viewport.y, top = 20;
var scrollContainer;
lastRng = editor.selection.getRng();
if (editor.inline) {
scrollContainer = editor.selection.getScrollContainer();
// Can't always rely on scrollTop returning a useful value.
// It returns 0 if the browser doesn't support scrollTop for the element or is non-scrollable
if (scrollContainer && scrollContainer.scrollTop > 0) {
scrollTop = scrollContainer.scrollTop;
}
}
/**
* Returns the rect of the current caret if the caret is in an empty block before a
* BR we insert a temporary invisible character that we get the rect this way we always get a proper rect.
*
* TODO: This might be useful in core.
*/
function getCaretRect(rng) {
var rects, textNode, node, container = rng.startContainer;
rects = rng.getClientRects();
if (rects.length) {
return rects[0];
}
if (!rng.collapsed || container.nodeType != 1) {
return;
}
node = container.childNodes[lastRng.startOffset];
// Skip empty whitespace nodes
while (node && node.nodeType == 3 && !node.data.length) {
node = node.nextSibling;
}
if (!node) {
return;
}
// Check if the location is |
// TODO: Might need to expand this to say |