tiny.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. var Tiny = {
  2. button: {}
  3. ,contentBelowAdded: false
  4. ,onLoad: function(ed) {
  5. var el = Ext.get(ed.id+'_ifr');
  6. MODx.load({
  7. xtype: 'modx-treedrop'
  8. ,target: el
  9. ,targetEl: el.dom
  10. ,iframe: true
  11. ,iframeEl: 'tinymce'
  12. ,onInsert: function(v) {
  13. tinyMCE.execCommand('mceInsertContent',false,v);
  14. }
  15. });
  16. }
  17. ,loadedTVs: []
  18. ,onTVLoad: function() {
  19. var els = Ext.query('.modx-richtext');
  20. var ed;
  21. Ext.each(els,function(el) {
  22. el = Ext.get(el);
  23. if (!el) {return;}
  24. if (Ext.isEmpty(Tiny.loadedTVs)) {Tiny.loadedTVs = [];}
  25. if (Tiny.loadedTVs.indexOf(el) != -1) {return;}
  26. tinyMCE.execCommand('mceAddControl', false, el.dom.id);
  27. ed = tinyMCE.get(el.dom.id);
  28. if (ed) {
  29. ed.execCommand('mceResize',false,'60%');
  30. }
  31. Tiny.loadedTVs.push(el);
  32. },this);
  33. }
  34. ,onTVUnload: function() {
  35. var els = Ext.query('.modx-richtext');
  36. Ext.each(els,function(el) {
  37. el = Ext.get(el);
  38. Tiny.loadedTVs.remove(el);
  39. tinyMCE.execCommand('mceRemoveControl', false, el.dom.id);
  40. },this);
  41. }
  42. ,toggle: function(e,t) {
  43. t = t.id.replace(/-toggle/,'');
  44. var ed = tinyMCE.get(t);
  45. if (ed) {
  46. ed.isHidden() ? ed.show() : ed.hide();
  47. }
  48. }
  49. ,onChange: function(ed) {
  50. if (!Ext.isEmpty(tinyMCE)) {
  51. ed.save();
  52. try {
  53. var ta = Ext.get(ed.id);
  54. if (ta) {
  55. ta.dom.value = ed.getContent();
  56. ta.dom.innerHTML = ta.dom.value;
  57. }
  58. } catch (e) {}
  59. }
  60. var pr = Ext.getCmp('modx-panel-resource');
  61. if (pr) pr.markDirty();
  62. }
  63. ,loadBrowser: function(fld, url, type, win) {
  64. var f = Tiny.config.browserUrl+'&ctx='+(MODx.ctx || 'web')+'&wctx='+(MODx.ctx || 'web')+'&source='+MODx.source;
  65. if (MODx.request.id) { f = f+'&id='+MODx.request.id; }
  66. f = f+'&referringAction='+MODx.request.a;
  67. tinyMCE.activeEditor.windowManager.open({
  68. file: f
  69. ,width: screen.width * 0.7
  70. ,height: screen.height * 0.7
  71. ,resizable: 'yes'
  72. ,inline: 'yes'
  73. ,close_previous: 'no'
  74. ,popup_css : false
  75. }, {
  76. window: win
  77. ,input: fld
  78. });
  79. return false;
  80. }
  81. /**
  82. * Prevents MODx tags from becoming &=`value`
  83. */
  84. ,onCleanup: function(type,value) {
  85. switch (type) {
  86. case "get_from_editor":
  87. case "insert_to_editor":
  88. var regexp = /(\[\[[^\]]*)&([^\[]*\]\])/g;
  89. value = value.replace(regexp,'$1&$2');
  90. break;
  91. case "submit_content":
  92. //value.innerHTML = value.innerHTML.replace('&','&');
  93. break;
  94. case "get_from_editor_dom":
  95. case "insert_to_editor_dom":
  96. case "setup_content_dom":
  97. case "submit_content_dom":
  98. //value.innerHTML = value.innerHTML.replace('&','&');
  99. break;
  100. }
  101. return value;
  102. }
  103. ,addContentBelow: function() {
  104. if (Tiny.contentBelowAdded) return false;
  105. var below = Ext.get('modx-content-below');
  106. if (!below) return false;
  107. below.createChild({
  108. tag: 'div'
  109. ,id: 'tiny-content-below'
  110. ,style: 'margin-top: 5px;'
  111. });
  112. var tb = Ext.get('tiny-content-below');
  113. tb.createChild({
  114. tag: 'label'
  115. ,id: 'tiny-toggle-label'
  116. });
  117. var tbl = Ext.get('tiny-toggle-label');
  118. tbl.createChild({
  119. html: Tiny.lang.toggle_editor
  120. ,style: 'float: left; margin-right: 5px;'
  121. });
  122. var z = Ext.state.Manager.get(MODx.siteId+'-tiny');
  123. var chk = !(z === false || z === 'false');
  124. tbl.createChild({
  125. tag: 'input'
  126. ,type: 'checkbox'
  127. ,id: 'tiny-toggle-rte'
  128. ,name: 'tiny_toggle'
  129. ,value: 1
  130. ,checked: chk
  131. });
  132. var cb = Ext.get('tiny-toggle-rte');
  133. cb.dom.checked = chk;
  134. cb.on('click',function(a,b) {
  135. var cb = Ext.get(b);
  136. var id = 'ta';
  137. if (cb.dom.checked) {
  138. tinyMCE.execCommand('mceAddControl',false,id);
  139. Ext.state.Manager.set(MODx.siteId+'-tiny',true);
  140. } else {
  141. tinyMCE.execCommand('mceRemoveControl',false,id);
  142. Ext.state.Manager.set(MODx.siteId+'-tiny',false);
  143. }
  144. },this);
  145. Tiny.contentBelowAdded = true;
  146. return true;
  147. }
  148. ,addContentAbove: function() {
  149. var above = Ext.get('modx-content-above');
  150. above.createChild({
  151. tag: 'div'
  152. ,id: 'tiny-content-above'
  153. ,style: 'margin-bottom: 5px;'
  154. });
  155. MODx.load({
  156. xtype: 'tiny-btn-image'
  157. ,text: 'Insert Image'
  158. ,listeners: {
  159. 'select': function(data) {
  160. if (inRevo20) {
  161. img = '<img src="'+data.relativeUrl+'" alt="" />';
  162. } else {
  163. img = '<img src="'+data.fullRelativeUrl+'" alt="" />';
  164. }
  165. tinyMCE.execCommand('mceInsertContent',false,img);
  166. }
  167. }
  168. ,renderTo: 'tiny-content-above'
  169. });
  170. }
  171. ,onExecCommand: function() {
  172. var pr = Ext.getCmp('modx-panel-resource');
  173. if (pr) { pr.markDirty(); }
  174. return false;
  175. }
  176. };
  177. MODx.loadRTE = function(id) {
  178. if (Tiny.config){
  179. var s = Tiny.config || {};
  180. delete s.assets_path;
  181. delete s.assets_url;
  182. delete s.core_path;
  183. delete s.css_path;
  184. delete s.editor;
  185. delete s.id;
  186. delete s.mode;
  187. delete s.path;
  188. s.cleanup_callback = "Tiny.onCleanup";
  189. var z = Ext.state.Manager.get(MODx.siteId + '-tiny');
  190. if (z !== false) {
  191. delete s.elements;
  192. }
  193. s.dialog_type = 'modal';
  194. s.plugins = Tiny.config.plugins+',inlinepopups';
  195. if (Tiny.config.frontend||Tiny.config.selector){
  196. s.mode = "specific_textareas";
  197. s.editor_selector = Tiny.config.selector||"modx-richtext";
  198. }
  199. tinyMCE.init(s);
  200. }
  201. /*Tiny.addContentAbove();*/
  202. Tiny.addContentBelow();
  203. var ptv = Ext.getCmp('modx-panel-resource-tv');
  204. if (ptv) {ptv.on('load',Tiny.onTVLoad);}
  205. if (z !== false) {
  206. var oid = Ext.get(id);
  207. if (!oid) return;
  208. tinyMCE.execCommand('mceAddControl',false,id);
  209. }
  210. };
  211. MODx.afterTVLoad = function() {
  212. Tiny.onTVLoad();
  213. };
  214. MODx.unloadTVRTE = function() {
  215. Tiny.onTVUnload();
  216. };
  217. /* for future versions */
  218. /*
  219. Tiny.button.Image = function(config) {
  220. config = config || {};
  221. Ext.applyIf(config,{
  222. });
  223. Tiny.button.Image.superclass.constructor.call(this,config);
  224. this.config = config;
  225. this.addEvents({select: true});
  226. };
  227. Ext.extend(Tiny.button.Image,Ext.Button,{
  228. onClick : function(btn){
  229. if (this.disabled){
  230. return false;
  231. }
  232. if (Ext.isEmpty(this.browser)) {
  233. this.browser = MODx.load({
  234. xtype: 'modx-browser'
  235. ,id: Ext.id()
  236. ,multiple: true
  237. ,prependPath: this.config.prependPath || null
  238. ,prependUrl: this.config.prependUrl || null
  239. ,hideFiles: this.config.hideFiles || false
  240. ,rootVisible: this.config.rootVisible || false
  241. ,listeners: {
  242. 'select': {fn: function(data) {
  243. this.fireEvent('select',data);
  244. },scope:this}
  245. }
  246. });
  247. }
  248. this.browser.show(btn);
  249. return true;
  250. }
  251. ,onDestroy: function(){
  252. Tiny.button.Image.superclass.onDestroy.call(this);
  253. }
  254. });
  255. Ext.reg('tiny-btn-image',Tiny.button.Image);
  256. */