jquery.tinymce.min.js 6.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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;var v=function(){
  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");// Hide textarea to avoid flicker
  21. var n=function(){var a=[],c=0;
  22. // Apply patches to the jQuery object, only once
  23. u||(m(),u=!0),
  24. // Create an editor instance for each matched node
  25. l.each(function(e,t){var n,i=t.id,r=o.oninit;
  26. // Generate unique id for target element if needed
  27. i||(t.id=i=v().DOM.uniqueId()),
  28. // Only init the editor once
  29. v().get(i)||(
  30. // Create editor instance and render it
  31. n=v().createEditor(i,o),a.push(n),n.on("init",function(){var e,t=r;l.css("visibility",""),
  32. // Run this if the oninit setting is defined
  33. // this logic will fire the oninit callback ones each
  34. // matched editor instance is initialized
  35. r&&++c==a.length&&("string"==typeof t&&(e=-1===t.indexOf(".")?null:v().resolve(t.replace(/\.\w+$/,"")),t=v().resolve(t)),
  36. // Call the oninit function with the object
  37. t.apply(e||v(),a))}))}),
  38. // Render the editor instances in a separate loop since we
  39. // need to have the full editors array used in the onInit calls
  40. p.each(a,function(e,t){t.render()})};
  41. // Load TinyMCE on demand, if we need to
  42. if(d.tinymce||c||!(e=o.script_url))
  43. // Delay the init call until tinymce is loaded
  44. 1===c?s.push(n):n();else{c=1,t=e.substring(0,e.lastIndexOf("/")),
  45. // Check if it's a dev/src version they want to load then
  46. // make sure that all plugins, themes etc are loaded in source mode as well
  47. -1!=e.indexOf(".min")&&(r=".min"),
  48. // Setup tinyMCEPreInit object this will later be used by the TinyMCE
  49. // core script to locate other resources like CSS files, dialogs etc
  50. // You can also predefined a tinyMCEPreInit object and then it will use that instead
  51. d.tinymce=d.tinyMCEPreInit||{base:t,suffix:r},
  52. // url contains gzip then we assume it's a compressor
  53. -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||""),
  54. // Check if compressor script is already loaded otherwise setup a basic one
  55. d.tinyMCE_GZ||(d.tinyMCE_GZ={start:function(){var n=function(e){v().ScriptLoader.markDone(v().baseURI.toAbsolute(e))};
  56. // Add core languages
  57. n("langs/"+i+".js"),
  58. // Add themes with languages
  59. n("themes/"+o.theme+"/theme"+r+".js"),n("themes/"+o.theme+"/langs/"+i+".js"),
  60. // Add plugins with languages
  61. 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,
  62. // Execute callback after mainscript has been loaded and before the initialization occurs
  63. o.script_loaded&&o.script_loaded(),n(),p.each(s,function(e,t){t()}))},a.src=e,document.body.appendChild(a)}return l},
  64. // Add :tinymce pseudo selector this will select elements that has been converted into editor instances
  65. // it's now possible to use things like $('*:tinymce') to get all TinyMCE bound elements.
  66. p.extend(p.expr[":"],{tinymce:function(e){var t;return!!(e.id&&"tinymce"in d&&(t=v().get(e.id))&&t.editorManager===v())}});
  67. // This function patches internal jQuery functions so that if
  68. // you for example remove an div element containing an editor it's
  69. // automatically destroyed by the TinyMCE API
  70. var m=function(){
  71. // Removes any child editor instances by looking for editor wrapper elements
  72. var r=function(e){
  73. // If the function is remove
  74. "remove"===e&&this.each(function(e,t){var n=l(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()})},o=function(i){var e,t=this;
  75. // Handle set value
  76. /*jshint eqnull:true */if(null!=i)r.call(t),
  77. // Saves the contents before get/set value of textarea/div
  78. 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()},l=function(e){var t=null;return e&&e.id&&d.tinymce&&(t=v().get(e.id)),t},u=function(e){return!!(e&&e.length&&d.tinymce&&e.is(":tinymce"))},s={};
  79. // Loads or saves contents from/to textarea if the value
  80. // argument is defined it will set the TinyMCE internal contents
  81. // Patch some setter/getter functions these will
  82. // now be able to set/get the contents of editor instances for
  83. // example $('#editorid').html('Content'); will update the TinyMCE iframe instance
  84. 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(!u(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
  85. var i="",r=arguments;return(c?t:t.eq(0)).each(function(e,t){var n=l(t);i+=n?c?n.getContent().replace(/<(?:"[^"]*"|'[^']*'|[^'">])*>/g,""):n.getContent({save:!0}):a.apply(p(t),r)}),i}}),
  86. // Makes it possible to use $('#id').append("content"); to append contents to the TinyMCE editor iframe
  87. 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 u(e)?i!==f?("string"==typeof i&&e.filter(":tinymce").each(function(e,t){var n=l(t);n&&n.setContent(r?i+n.getContent():n.getContent()+i)}),n.apply(e.not(":tinymce"),arguments),e):void 0:n.apply(e,arguments)}}),
  88. // Makes sure that the editor instance gets properly destroyed when the parent element is removed
  89. 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,
  90. // Makes sure that $('#tinymce_id').attr('value') gets the editors current HTML contents
  91. p.fn.attr=function(e,t){var n=this,i=arguments;if(!e||"value"!==e||!u(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
  92. var r=n[0],a=l(r);return a?a.getContent({save:!0}):s.attr.apply(p(r),i)}}}();