提交 | 用户 | 时间
|
71e81e
|
1 |
/** |
懒 |
2 |
* Copyright (c) Tiny Technologies, Inc. All rights reserved. |
|
3 |
* Licensed under the LGPL or a commercial license. |
|
4 |
* For LGPL see License.txt in the project root for license information. |
|
5 |
* For commercial licenses see https://www.tiny.cloud/ |
|
6 |
*/ |
|
7 |
/** |
|
8 |
* Jquery integration plugin. |
|
9 |
* |
|
10 |
* @class tinymce.core.JqueryIntegration |
|
11 |
* @private |
|
12 |
*/ |
|
13 |
!function(){var f,c,u,p,d,s=[];d="undefined"!=typeof global?global:window,p=d.jQuery;function v(){ |
|
14 |
// Reference to tinymce needs to be lazily evaluated since tinymce |
|
15 |
// might be loaded through the compressor or other means |
|
16 |
return d.tinymce}p.fn.tinymce=function(o){var e,t,i,l=this,r=""; |
|
17 |
// No match then just ignore the call |
|
18 |
if(!l.length)return l; |
|
19 |
// Get editor instance |
|
20 |
if(!o)return v()?v().get(l[0].id):null;l.css("visibility","hidden");function n(){var a=[],c=0; |
|
21 |
// Apply patches to the jQuery object, only once |
|
22 |
u||(m(),u=!0), |
|
23 |
// Create an editor instance for each matched node |
|
24 |
l.each(function(e,t){var n,i=t.id,r=o.oninit; |
|
25 |
// Generate unique id for target element if needed |
|
26 |
i||(t.id=i=v().DOM.uniqueId()), |
|
27 |
// Only init the editor once |
|
28 |
v().get(i)||( |
|
29 |
// Create editor instance and render it |
|
30 |
n=v().createEditor(i,o),a.push(n),n.on("init",function(){var e,t=r;l.css("visibility",""), |
|
31 |
// Run this if the oninit setting is defined |
|
32 |
// this logic will fire the oninit callback ones each |
|
33 |
// matched editor instance is initialized |
|
34 |
r&&++c==a.length&&("string"==typeof t&&(e=-1===t.indexOf(".")?null:v().resolve(t.replace(/\.\w+$/,"")),t=v().resolve(t)), |
|
35 |
// Call the oninit function with the object |
|
36 |
t.apply(e||v(),a))}))}), |
|
37 |
// Render the editor instances in a separate loop since we |
|
38 |
// need to have the full editors array used in the onInit calls |
|
39 |
p.each(a,function(e,t){t.render()})} |
|
40 |
// Load TinyMCE on demand, if we need to |
|
41 |
if(d.tinymce||c||!(e=o.script_url)) |
|
42 |
// Delay the init call until tinymce is loaded |
|
43 |
1===c?s.push(n):n();else{c=1,t=e.substring(0,e.lastIndexOf("/")), |
|
44 |
// Check if it's a dev/src version they want to load then |
|
45 |
// make sure that all plugins, themes etc are loaded in source mode as well |
|
46 |
-1!=e.indexOf(".min")&&(r=".min"), |
|
47 |
// Setup tinyMCEPreInit object this will later be used by the TinyMCE |
|
48 |
// core script to locate other resources like CSS files, dialogs etc |
|
49 |
// You can also predefined a tinyMCEPreInit object and then it will use that instead |
|
50 |
d.tinymce=d.tinyMCEPreInit||{base:t,suffix:r}, |
|
51 |
// url contains gzip then we assume it's a compressor |
|
52 |
-1!=e.indexOf("gzip")&&(i=o.language||"en",e=e+(/\?/.test(e)?"&":"?")+"js=true&core=true&suffix="+escape(r)+"&themes="+escape(o.theme||"modern")+"&plugins="+escape(o.plugins||"")+"&languages="+(i||""), |
|
53 |
// Check if compressor script is already loaded otherwise setup a basic one |
|
54 |
d.tinyMCE_GZ||(d.tinyMCE_GZ={start:function(){function n(e){v().ScriptLoader.markDone(v().baseURI.toAbsolute(e))} |
|
55 |
// Add core languages |
|
56 |
n("langs/"+i+".js"), |
|
57 |
// Add themes with languages |
|
58 |
n("themes/"+o.theme+"/theme"+r+".js"),n("themes/"+o.theme+"/langs/"+i+".js"), |
|
59 |
// Add plugins with languages |
|
60 |
p.each(o.plugins.split(","),function(e,t){t&&(n("plugins/"+t+"/plugin"+r+".js"),n("plugins/"+t+"/langs/"+i+".js"))})},end:function(){}}));var a=document.createElement("script");a.type="text/javascript",a.onload=a.onreadystatechange=function(e){e=e||window.event,2===c||"load"!=e.type&&!/complete|loaded/.test(a.readyState)||(v().dom.Event.domLoaded=1,c=2, |
|
61 |
// Execute callback after mainscript has been loaded and before the initialization occurs |
|
62 |
o.script_loaded&&o.script_loaded(),n(),p.each(s,function(e,t){t()}))},a.src=e,document.body.appendChild(a)}return l}, |
|
63 |
// Add :tinymce pseudo selector this will select elements that has been converted into editor instances |
|
64 |
// it's now possible to use things like $('*:tinymce') to get all TinyMCE bound elements. |
|
65 |
p.extend(p.expr[":"],{tinymce:function(e){var t;return!!(e.id&&"tinymce"in d&&(t=v().get(e.id))&&t.editorManager===v())}}); |
|
66 |
// This function patches internal jQuery functions so that if |
|
67 |
// you for example remove an div element containing an editor it's |
|
68 |
// automatically destroyed by the TinyMCE API |
|
69 |
var m=function(){function r(e){ |
|
70 |
// If the function is remove |
|
71 |
"remove"===e&&this.each(function(e,t){var n=u(t);n&&n.remove()}),this.find("span.mceEditor,div.mceEditor").each(function(e,t){var n=v().get(t.id.replace(/_parent$/,""));n&&n.remove()})}function o(i){var e,t=this; |
|
72 |
// Handle set value |
|
73 |
/*jshint eqnull:true */if(null!=i)r.call(t), |
|
74 |
// Saves the contents before get/set value of textarea/div |
|
75 |
t.each(function(e,t){var n;(n=v().get(t.id))&&n.setContent(i)});else if(0<t.length&&(e=v().get(t[0].id)))return e.getContent()}function l(e){return!!(e&&e.length&&d.tinymce&&e.is(":tinymce"))} |
|
76 |
// Removes any child editor instances by looking for editor wrapper elements |
|
77 |
var u=function(e){var t=null;return e&&e.id&&d.tinymce&&(t=v().get(e.id)),t},s={}; |
|
78 |
// Loads or saves contents from/to textarea if the value |
|
79 |
// argument is defined it will set the TinyMCE internal contents |
|
80 |
// Patch some setter/getter functions these will |
|
81 |
// now be able to set/get the contents of editor instances for |
|
82 |
// example $('#editorid').html('Content'); will update the TinyMCE iframe instance |
|
83 |
p.each(["text","html","val"],function(e,t){var a=s[t]=p.fn[t],c="text"===t;p.fn[t]=function(e){var t=this;if(!l(t))return a.apply(t,arguments);if(e!==f)return o.call(t.filter(":tinymce"),e),a.apply(t.not(":tinymce"),arguments),t;// return original set for chaining |
|
84 |
var i="",r=arguments;return(c?t:t.eq(0)).each(function(e,t){var n=u(t);i+=n?c?n.getContent().replace(/<(?:"[^"]*"|'[^']*'|[^'">])*>/g,""):n.getContent({save:!0}):a.apply(p(t),r)}),i}}), |
|
85 |
// Makes it possible to use $('#id').append("content"); to append contents to the TinyMCE editor iframe |
|
86 |
p.each(["append","prepend"],function(e,t){var n=s[t]=p.fn[t],r="prepend"===t;p.fn[t]=function(i){var e=this;return l(e)?i!==f?("string"==typeof i&&e.filter(":tinymce").each(function(e,t){var n=u(t);n&&n.setContent(r?i+n.getContent():n.getContent()+i)}),n.apply(e.not(":tinymce"),arguments),e):void 0:n.apply(e,arguments)}}), |
|
87 |
// Makes sure that the editor instance gets properly destroyed when the parent element is removed |
|
88 |
p.each(["remove","replaceWith","replaceAll","empty"],function(e,t){var n=s[t]=p.fn[t];p.fn[t]=function(){return r.call(this,t),n.apply(this,arguments)}}),s.attr=p.fn.attr, |
|
89 |
// Makes sure that $('#tinymce_id').attr('value') gets the editors current HTML contents |
|
90 |
p.fn.attr=function(e,t){var n=this,i=arguments;if(!e||"value"!==e||!l(n))return s.attr.apply(n,i);if(t!==f)return o.call(n.filter(":tinymce"),t),s.attr.apply(n.not(":tinymce"),i),n;// return original set for chaining |
|
91 |
var r=n[0],a=u(r);return a?a.getContent({save:!0}):s.attr.apply(p(r),i)}}}(); |