A QCodo powered CMS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

294 lines
7.5 KiB

  1. // Some global instances
  2. var tinymce = null, tinyMCEPopup, tinyMCE;
  3. tinyMCEPopup = {
  4. init : function() {
  5. var t = this, w, ti, li, q, i, it;
  6. li = ('' + document.location.search).replace(/^\?/, '').split('&');
  7. q = {};
  8. for (i=0; i<li.length; i++) {
  9. it = li[i].split('=');
  10. q[unescape(it[0])] = unescape(it[1]);
  11. }
  12. if (q.mce_rdomain)
  13. document.domain = q.mce_rdomain;
  14. // Find window & API
  15. w = t.getWin();
  16. tinymce = w.tinymce;
  17. tinyMCE = w.tinyMCE;
  18. t.editor = tinymce.EditorManager.activeEditor;
  19. t.params = t.editor.windowManager.params;
  20. t.features = t.editor.windowManager.features;
  21. // Setup local DOM
  22. t.dom = t.editor.windowManager.createInstance('tinymce.dom.DOMUtils', document);
  23. // Enables you to skip loading the default css
  24. if (t.features.popup_css !== false)
  25. t.dom.loadCSS(t.features.popup_css || t.editor.settings.popup_css);
  26. // Setup on init listeners
  27. t.listeners = [];
  28. t.onInit = {
  29. add : function(f, s) {
  30. t.listeners.push({func : f, scope : s});
  31. }
  32. };
  33. t.isWindow = !t.getWindowArg('mce_inline');
  34. t.id = t.getWindowArg('mce_window_id');
  35. t.editor.windowManager.onOpen.dispatch(t.editor.windowManager, window);
  36. },
  37. getWin : function() {
  38. return window.dialogArguments || opener || parent || top;
  39. },
  40. getWindowArg : function(n, dv) {
  41. var v = this.params[n];
  42. return tinymce.is(v) ? v : dv;
  43. },
  44. getParam : function(n, dv) {
  45. return this.editor.getParam(n, dv);
  46. },
  47. getLang : function(n, dv) {
  48. return this.editor.getLang(n, dv);
  49. },
  50. execCommand : function(cmd, ui, val, a) {
  51. a = a || {};
  52. a.skip_focus = 1;
  53. this.restoreSelection();
  54. return this.editor.execCommand(cmd, ui, val, a);
  55. },
  56. resizeToInnerSize : function() {
  57. var t = this, n, b = document.body, vp = t.dom.getViewPort(window), dw, dh;
  58. dw = t.getWindowArg('mce_width') - vp.w;
  59. dh = t.getWindowArg('mce_height') - vp.h;
  60. if (t.isWindow)
  61. window.resizeBy(dw, dh);
  62. else
  63. t.editor.windowManager.resizeBy(dw, dh, t.id);
  64. },
  65. executeOnLoad : function(s) {
  66. this.onInit.add(function() {
  67. eval(s);
  68. });
  69. },
  70. storeSelection : function() {
  71. this.editor.windowManager.bookmark = tinyMCEPopup.editor.selection.getBookmark('simple');
  72. },
  73. restoreSelection : function() {
  74. var t = tinyMCEPopup;
  75. if (!t.isWindow && tinymce.isIE)
  76. t.editor.selection.moveToBookmark(t.editor.windowManager.bookmark);
  77. },
  78. requireLangPack : function() {
  79. var u = this.getWindowArg('plugin_url') || this.getWindowArg('theme_url');
  80. if (u && this.editor.settings.language) {
  81. u += '/langs/' + this.editor.settings.language + '_dlg.js';
  82. if (!tinymce.ScriptLoader.isDone(u)) {
  83. document.write('<script type="text/javascript" src="' + tinymce._addVer(u) + '"></script>');
  84. tinymce.ScriptLoader.markDone(u);
  85. }
  86. }
  87. },
  88. pickColor : function(e, element_id) {
  89. this.execCommand('mceColorPicker', true, {
  90. color : document.getElementById(element_id).value,
  91. func : function(c) {
  92. document.getElementById(element_id).value = c;
  93. try {
  94. document.getElementById(element_id).onchange();
  95. } catch (ex) {
  96. // Try fire event, ignore errors
  97. }
  98. }
  99. });
  100. },
  101. openBrowser : function(element_id, type, option) {
  102. tinyMCEPopup.restoreSelection();
  103. this.editor.execCallback('file_browser_callback', element_id, document.getElementById(element_id).value, type, window);
  104. },
  105. confirm : function(t, cb, s) {
  106. this.editor.windowManager.confirm(t, cb, s, window);
  107. },
  108. alert : function(tx, cb, s) {
  109. this.editor.windowManager.alert(tx, cb, s, window);
  110. },
  111. close : function() {
  112. var t = this;
  113. // To avoid domain relaxing issue in Opera
  114. function close() {
  115. t.editor.windowManager.close(window);
  116. tinymce = tinyMCE = t.editor = t.params = t.dom = t.dom.doc = null; // Cleanup
  117. };
  118. if (tinymce.isOpera)
  119. t.getWin().setTimeout(close, 0);
  120. else
  121. close();
  122. },
  123. // Internal functions
  124. _restoreSelection : function() {
  125. var e = window.event.srcElement;
  126. if (e.nodeName == 'INPUT' && (e.type == 'submit' || e.type == 'button'))
  127. tinyMCEPopup.restoreSelection();
  128. },
  129. /* _restoreSelection : function() {
  130. var e = window.event.srcElement;
  131. // If user focus a non text input or textarea
  132. if ((e.nodeName != 'INPUT' && e.nodeName != 'TEXTAREA') || e.type != 'text')
  133. tinyMCEPopup.restoreSelection();
  134. },*/
  135. _onDOMLoaded : function() {
  136. var t = this, ti = document.title, bm, h, nv;
  137. // Translate page
  138. if (t.features.translate_i18n !== false) {
  139. h = document.body.innerHTML;
  140. // Replace a=x with a="x" in IE
  141. if (tinymce.isIE)
  142. h = h.replace(/ (value|title|alt)=([^"][^\s>]+)/gi, ' $1="$2"')
  143. document.dir = t.editor.getParam('directionality','');
  144. if ((nv = t.editor.translate(h)) && nv != h)
  145. document.body.innerHTML = nv;
  146. if ((nv = t.editor.translate(ti)) && nv != ti)
  147. document.title = ti = nv;
  148. }
  149. document.body.style.display = '';
  150. // Restore selection in IE when focus is placed on a non textarea or input element of the type text
  151. if (tinymce.isIE)
  152. document.attachEvent('onmouseup', tinyMCEPopup._restoreSelection);
  153. t.restoreSelection();
  154. t.resizeToInnerSize();
  155. // Set inline title
  156. if (!t.isWindow)
  157. t.editor.windowManager.setTitle(window, ti);
  158. else
  159. window.focus();
  160. if (!tinymce.isIE && !t.isWindow) {
  161. tinymce.dom.Event._add(document, 'focus', function() {
  162. t.editor.windowManager.focus(t.id)
  163. });
  164. }
  165. // Patch for accessibility
  166. tinymce.each(t.dom.select('select'), function(e) {
  167. e.onkeydown = tinyMCEPopup._accessHandler;
  168. });
  169. // Call onInit
  170. // Init must be called before focus so the selection won't get lost by the focus call
  171. tinymce.each(t.listeners, function(o) {
  172. o.func.call(o.scope, t.editor);
  173. });
  174. // Move focus to window
  175. if (t.getWindowArg('mce_auto_focus', true)) {
  176. window.focus();
  177. // Focus element with mceFocus class
  178. tinymce.each(document.forms, function(f) {
  179. tinymce.each(f.elements, function(e) {
  180. if (t.dom.hasClass(e, 'mceFocus') && !e.disabled) {
  181. e.focus();
  182. return false; // Break loop
  183. }
  184. });
  185. });
  186. }
  187. document.onkeyup = tinyMCEPopup._closeWinKeyHandler;
  188. },
  189. _accessHandler : function(e) {
  190. e = e || window.event;
  191. if (e.keyCode == 13 || e.keyCode == 32) {
  192. e = e.target || e.srcElement;
  193. if (e.onchange)
  194. e.onchange();
  195. return tinymce.dom.Event.cancel(e);
  196. }
  197. },
  198. _closeWinKeyHandler : function(e) {
  199. e = e || window.event;
  200. if (e.keyCode == 27)
  201. tinyMCEPopup.close();
  202. },
  203. _wait : function() {
  204. var t = this, ti;
  205. if (tinymce.isIE && document.location.protocol != 'https:') {
  206. // Fake DOMContentLoaded on IE
  207. document.write('<script id=__ie_onload defer src=\'javascript:""\';><\/script>');
  208. document.getElementById("__ie_onload").onreadystatechange = function() {
  209. if (this.readyState == "complete") {
  210. t._onDOMLoaded();
  211. document.getElementById("__ie_onload").onreadystatechange = null; // Prevent leak
  212. }
  213. };
  214. } else {
  215. if (tinymce.isIE || tinymce.isWebKit) {
  216. ti = setInterval(function() {
  217. if (/loaded|complete/.test(document.readyState)) {
  218. clearInterval(ti);
  219. t._onDOMLoaded();
  220. }
  221. }, 10);
  222. } else {
  223. window.addEventListener('DOMContentLoaded', function() {
  224. t._onDOMLoaded();
  225. }, false);
  226. }
  227. }
  228. }
  229. };
  230. tinyMCEPopup.init();
  231. tinyMCEPopup._wait(); // Wait for DOM Content Loaded