123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- (function($) {
- var undef,
- lazyLoading,
- patchApplied,
- delayedInits = [],
- win = window;
- $.fn.tinymce = function(settings) {
- var self = this, url, base, lang, suffix = "";
-
- if (!self.length) {
- return self;
- }
-
- if (!settings) {
- return window.tinymce ? tinymce.get(self[0].id) : null;
- }
- self.css('visibility', 'hidden');
- function init() {
- var editors = [], initCount = 0;
-
- if (!patchApplied) {
- applyPatch();
- patchApplied = true;
- }
-
- self.each(function(i, node) {
- var ed, id = node.id, oninit = settings.oninit;
-
- if (!id) {
- node.id = id = tinymce.DOM.uniqueId();
- }
-
- if (tinymce.get(id)) {
- return;
- }
-
- ed = new tinymce.Editor(id, settings, tinymce.EditorManager);
- editors.push(ed);
- ed.on('init', function() {
- var scope, func = oninit;
- self.css('visibility', '');
-
-
-
- if (oninit) {
-
- if (++initCount == editors.length) {
- if (typeof func === "string") {
- scope = (func.indexOf(".") === -1) ? null : tinymce.resolve(func.replace(/\.\w+$/, ""));
- func = tinymce.resolve(func);
- }
-
- func.apply(scope || tinymce, editors);
- }
- }
- });
- });
-
-
- $.each(editors, function(i, ed) {
- ed.render();
- });
- }
-
- if (!win.tinymce && !lazyLoading && (url = settings.script_url)) {
- lazyLoading = 1;
- base = url.substring(0, url.lastIndexOf("/"));
-
-
- if (url.indexOf('.min') != -1) {
- suffix = ".min";
- }
-
-
-
- win.tinymce = win.tinyMCEPreInit || {
- base: base,
- suffix: suffix
- };
-
- if (url.indexOf('gzip') != -1) {
- lang = settings.language || "en";
- url = url + (/\?/.test(url) ? '&' : '?') + "js=true&core=true&suffix=" + escape(suffix) +
- "&themes=" + escape(settings.theme || 'modern') + "&plugins=" +
- escape(settings.plugins || '') + "&languages=" + (lang || '');
-
- if (!win.tinyMCE_GZ) {
- win.tinyMCE_GZ = {
- start: function() {
- function load(url) {
- tinymce.ScriptLoader.markDone(tinymce.baseURI.toAbsolute(url));
- }
-
- load("langs/" + lang + ".js");
-
- load("themes/" + settings.theme + "/theme" + suffix + ".js");
- load("themes/" + settings.theme + "/langs/" + lang + ".js");
-
- $.each(settings.plugins.split(","), function(i, name) {
- if (name) {
- load("plugins/" + name + "/plugin" + suffix + ".js");
- load("plugins/" + name + "/langs/" + lang + ".js");
- }
- });
- },
- end: function() {
- }
- };
- }
- }
- var script = document.createElement('script');
- script.type = 'text/javascript';
- script.onload = script.onreadystatechange = function(e) {
- e = e || window.event;
- if (lazyLoading !== 2 && (e.type == 'load' || /complete|loaded/.test(script.readyState))) {
- tinymce.dom.Event.domLoaded = 1;
- lazyLoading = 2;
-
- if (settings.script_loaded) {
- settings.script_loaded();
- }
- init();
- $.each(delayedInits, function(i, init) {
- init();
- });
- }
- };
- script.src = url;
- document.body.appendChild(script);
- } else {
-
- if (lazyLoading === 1) {
- delayedInits.push(init);
- } else {
- init();
- }
- }
- return self;
- };
-
-
- $.extend($.expr[":"], {
- tinymce: function(e) {
- var editor;
- if (e.id && "tinymce" in window) {
- editor = tinymce.get(e.id);
- if (editor && editor.editorManager === tinymce) {
- return true;
- }
- }
- return false;
- }
- });
-
-
-
- function applyPatch() {
-
- function removeEditors(name) {
-
- if (name === "remove") {
- this.each(function(i, node) {
- var ed = tinyMCEInstance(node);
- if (ed) {
- ed.remove();
- }
- });
- }
- this.find("span.mceEditor,div.mceEditor").each(function(i, node) {
- var ed = tinymce.get(node.id.replace(/_parent$/, ""));
- if (ed) {
- ed.remove();
- }
- });
- }
-
-
- function loadOrSave(value) {
- var self = this, ed;
-
-
- if (value != null) {
- removeEditors.call(self);
-
- self.each(function(i, node) {
- var ed;
- if ((ed = tinymce.get(node.id))) {
- ed.setContent(value);
- }
- });
- } else if (self.length > 0) {
-
- if ((ed = tinymce.get(self[0].id))) {
- return ed.getContent();
- }
- }
- }
-
- function tinyMCEInstance(element) {
- var ed = null;
- if (element && element.id && win.tinymce) {
- ed = tinymce.get(element.id);
- }
- return ed;
- }
-
- function containsTinyMCE(matchedSet) {
- return !!((matchedSet) && (matchedSet.length) && (win.tinymce) && (matchedSet.is(":tinymce")));
- }
-
- var jQueryFn = {};
-
-
-
- $.each(["text", "html", "val"], function(i, name) {
- var origFn = jQueryFn[name] = $.fn[name],
- textProc = (name === "text");
- $.fn[name] = function(value) {
- var self = this;
- if (!containsTinyMCE(self)) {
- return origFn.apply(self, arguments);
- }
- if (value !== undef) {
- loadOrSave.call(self.filter(":tinymce"), value);
- origFn.apply(self.not(":tinymce"), arguments);
- return self;
- }
- var ret = "";
- var args = arguments;
- (textProc ? self : self.eq(0)).each(function(i, node) {
- var ed = tinyMCEInstance(node);
- if (ed) {
- ret += textProc ? ed.getContent().replace(/<(?:"[^"]*"|'[^']*'|[^'">])*>/g, "") : ed.getContent({save: true});
- } else {
- ret += origFn.apply($(node), args);
- }
- });
- return ret;
- };
- });
-
- $.each(["append", "prepend"], function(i, name) {
- var origFn = jQueryFn[name] = $.fn[name],
- prepend = (name === "prepend");
- $.fn[name] = function(value) {
- var self = this;
- if (!containsTinyMCE(self)) {
- return origFn.apply(self, arguments);
- }
- if (value !== undef) {
- if (typeof value === "string") {
- self.filter(":tinymce").each(function(i, node) {
- var ed = tinyMCEInstance(node);
- if (ed) {
- ed.setContent(prepend ? value + ed.getContent() : ed.getContent() + value);
- }
- });
- }
- origFn.apply(self.not(":tinymce"), arguments);
- return self;
- }
- };
- });
-
- $.each(["remove", "replaceWith", "replaceAll", "empty"], function(i, name) {
- var origFn = jQueryFn[name] = $.fn[name];
- $.fn[name] = function() {
- removeEditors.call(this, name);
- return origFn.apply(this, arguments);
- };
- });
- jQueryFn.attr = $.fn.attr;
-
- $.fn.attr = function(name, value) {
- var self = this, args = arguments;
- if ((!name) || (name !== "value") || (!containsTinyMCE(self))) {
- if (value !== undef) {
- return jQueryFn.attr.apply(self, args);
- }
- return jQueryFn.attr.apply(self, args);
- }
- if (value !== undef) {
- loadOrSave.call(self.filter(":tinymce"), value);
- jQueryFn.attr.apply(self.not(":tinymce"), args);
- return self;
- }
- var node = self[0], ed = tinyMCEInstance(node);
- return ed ? ed.getContent({save: true}) : jQueryFn.attr.apply($(node), args);
- };
- }
- })(jQuery);
|