Guest User

Untitled

a guest
May 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. /**
  2. * $Id: jquery.uri.js 453 2008-10-14 12:24:41Z spocke $
  3. *
  4. * @author Moxiecode
  5. * @copyright Copyright � 2004-2008, Moxiecode Systems AB, All rights reserved.
  6. */
  7.  
  8. (function($) {
  9. var lazyLoading, delayedInits = [];
  10.  
  11. function patch(type, name, patch_func) {
  12. var func;
  13.  
  14. func = $.fn[name];
  15.  
  16. $.fn[name] = function() {
  17. var val;
  18.  
  19. if (type !== 'after') {
  20. val = patch_func.apply(this, arguments);
  21.  
  22. // We got a return value pass out that instead
  23. if (val !== undefined)
  24. return val;
  25. }
  26.  
  27. val = func.apply(this, arguments);
  28.  
  29. if (type !== 'before')
  30. patch_func.apply(this, arguments);
  31.  
  32. return val;
  33. };
  34. };
  35.  
  36. $.fn.tinymce = function(settings) {
  37. var t = this, url, suffix = '', ed;
  38.  
  39. // No match then just ignore the call
  40. if (!t.length)
  41. return;
  42.  
  43. // Get editor instance
  44. if (!settings)
  45. return tinyMCE.get(this[0].id);
  46.  
  47. function init() {
  48. // Apply patches once
  49. if (applyPatch) {
  50. applyPatch();
  51. applyPatch = null;
  52. }
  53.  
  54. // Create an editor instance for each matched node
  55. t.each(function(i, n) {
  56. var ed, id = n.id || tinymce.DOM.uniqueId();
  57.  
  58. n.id = id;
  59. ed = new tinymce.Editor(id, settings);
  60.  
  61. ed.render();
  62. });
  63. };
  64.  
  65. // Load TinyMCE on demand
  66. if (!window['tinymce'] && !lazyLoading && (url = settings.script_url)) {
  67. lazyLoading = 1;
  68.  
  69. if (/_(src|dev)\.js/g.test(url))
  70. suffix = '_src';
  71.  
  72. window.tinyMCEPreInit = {
  73. base : url.substring(0, url.lastIndexOf('/')),
  74. suffix : suffix,
  75. query : ''
  76. };
  77.  
  78. $.getScript(url, function() {
  79. // Script is loaded time to initialize TinyMCE
  80. tinymce.dom.Event.domLoaded = 1;
  81. lazyLoading = 2;
  82. init();
  83.  
  84. $.each(delayedInits, function(i, init) {
  85. init();
  86. });
  87. });
  88. } else {
  89. if (lazyLoading === 1)
  90. delayedInits.push(init);
  91. else
  92. init();
  93. }
  94. };
  95.  
  96. // Add :tinymce psuedo selector
  97. $.extend($.expr[':'], {
  98. tinymce : function(e) {
  99. return e.id && !!tinyMCE.get(e.id);
  100. }
  101. });
  102.  
  103. function applyPatch() {
  104. function removeEditors() {
  105. this.find('span.mceEditor,div.mceEditor').each(function(i, n) {
  106. var ed;
  107.  
  108. if (ed = tinyMCE.get(n.id.replace(/_parent$/, ''))) {
  109. ed.remove();
  110. }
  111. });
  112. };
  113.  
  114. function loadOrSave(value) {
  115. var ed;
  116.  
  117. // Handle set value
  118. if (value !== undefined) {
  119. removeEditors.call(this);
  120.  
  121. // Saves the contents before get/set value of textarea/div
  122. this.each(function(i, node) {
  123. var ed;
  124.  
  125. if (ed = tinyMCE.get(node.id))
  126. ed.setContent(value);
  127. });
  128. } else if (this.length > 0) {
  129. // Handle get value
  130. if (ed = tinyMCE.get(this[0].id))
  131. return ed.getContent();
  132. }
  133. };
  134.  
  135. // Patch various jQuery functions
  136. patch("both", 'text', function(value) {
  137. // Text encode value
  138. if (value !== undefined)
  139. return loadOrSave.call(this, value);
  140.  
  141. // Get contents as plain text
  142. if (this.length > 0) {
  143. // Handle get value
  144. if (ed = tinyMCE.get(this[0].id))
  145. return ed.getContent().replace(/<[^>]+>/g, '');
  146. }
  147. });
  148.  
  149. $.each(['val', 'html'], function(i, name) {
  150. patch("both", name, loadOrSave);
  151. });
  152.  
  153. $.each(['append', 'prepend'], function(i, name) {
  154. patch("before", name, function(value) {
  155. if (value !== undefined) {
  156. this.each(function(i, node) {
  157. var ed;
  158.  
  159. if (ed = tinyMCE.get(node.id)) {
  160. if (name === 'append')
  161. ed.setContent(ed.getContent() + value);
  162. else
  163. ed.setContent(value + ed.getContent());
  164. }
  165. });
  166. }
  167. });
  168. });
  169.  
  170. patch("both", 'attr', function(name, value) {
  171. if (name && name === 'value')
  172. return loadOrSave.call(this, value);
  173. });
  174.  
  175. $.each(['remove', 'replaceWith', 'replaceAll', 'empty'], function(i, name) {
  176. patch("before", name, removeEditors);
  177. });
  178. };
  179. })(jQuery);
Add Comment
Please, Sign In to add comment