fckplugin.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. // ================================================
  2. // Image Manager FCKeditor interface (IE & Gecko)
  3. // ================================================
  4. // Plugin Interface: Brent Kelly - Zeald.com
  5. // (c)2005 All rights reserved.
  6. // ================================================
  7. // Integrates FCKeditor with:
  8. // PHP image manager http://www.zhuo.org/htmlarea/
  9. // ================================================
  10. // Revision: 1.0 Date: 06/03/2005
  11. // $Id: fckplugin.js,v 1.4 2006/12/21 20:47:55 thierrybo Exp $
  12. // ================================================
  13. // ============== config settings ===========
  14. // This is for supporting old javascript versions.
  15. if ( !Array.indexOf )
  16. {
  17. Array.prototype.indexOf = function( value )
  18. {
  19. for ( var i = 0 ; i < this.length ; i++ )
  20. {
  21. if ( this[i] == value )
  22. return i ;
  23. }
  24. return -1 ;
  25. }
  26. }
  27. // plugin's language
  28. var _editor_lang = "en" ;
  29. // We have to determine which language file to be loaded
  30. // using information that is provided by the FCKEditor.
  31. var _available_langs = 'en,af,ar,ast,bg,bn,bs,ca,cs,da,de,el,en-au,en-ca,en-uk,eo,es,et,eu,fa,fi,fo,fr-ca,fr,fur,gl,gu,he,hi,hr,hu,id,is,it,ja,ka,km,ko,lt,lv,mk,mn,ms,nb,nl,no,oc,pl,prs,ps,pt-br,pt,qu,ro,ru,sk,sl,sr-latn,sr,sv,sw,th,tr,uk,vi,yo,zh-cn,zh' ;
  32. _available_langs = _available_langs.split( ',' ) ;
  33. if ( FCKConfig.DefaultLanguage )
  34. {
  35. if ( _available_langs.indexOf( FCKConfig.DefaultLanguage ) >= 0 )
  36. {
  37. _editor_lang = FCKConfig.DefaultLanguage ;
  38. }
  39. }
  40. // show image manager or show immediately the image editor
  41. // false = use manager, standard behavior
  42. // true = no manager, only editing the image
  43. var IM_directEdit = false;
  44. // ================================================
  45. var FCKImageManager = function(name) {
  46. this.Name = name;
  47. }
  48. // manage the plugins' button behavior
  49. FCKImageManager.prototype.GetState = function() {
  50. return FCK_TRISTATE_OFF;
  51. }
  52. FCKCommands.RegisterCommand('ImageManager', new FCKImageManager('ImageManager')) ;
  53. // Create the toolbar button.
  54. var oImageManagerItem = new FCKToolbarButton( 'ImageManager', "ImageManager", null, null, false, true ) ;
  55. //oImageManagerItem.IconPath = FCKConfig.PluginsPath + 'ImageManager/icon.gif' ;
  56. oImageManagerItem.IconPath = FCKConfig.ImagesIcon ; // Use a custom icon.
  57. FCKToolbarItems.RegisterItem( 'ImageManager', oImageManagerItem ) ;
  58. FCKImageManager.prototype.Execute = function() {
  59. ImageManager_click(FCK, null);
  60. }
  61. function ImageManager_click(editor, sender) {
  62. // If an existing image has been selected let us use the original Image Properties dialog.
  63. var image = FCK.Selection.GetSelectedElement() ;
  64. if ( image )
  65. {
  66. // Checking whether the selected object is a real image.
  67. if ( FCK.IsRealImage( image ) )
  68. {
  69. var command = new FCKDialogCommand( 'Image', FCKLang.DlgImgTitle, 'dialog/fck_image.html', 600, 455 ) ;
  70. command.Execute() ;
  71. return ;
  72. }
  73. // For other kinds of objects Image Manager should be activated to replace them.
  74. }
  75. // Starting ImageManager.
  76. var wArgs = {};
  77. if(FCKSelection.GetType() == 'Control') {
  78. var sElm = FCK.Selection.GetSelectedElement();
  79. } if(FCKSelection.GetType() == 'Text') {
  80. var sElm = FCKSelection.GetParentElement();
  81. }
  82. if (sElm != null && sElm.nodeName.toLowerCase() == 'img')
  83. var im = sElm; // is current cell a image ?
  84. if (im)
  85. { // selected object is image
  86. wArgs.f_url = im.src ? im.src : '';
  87. wArgs.f_alt = im.alt ? im.alt : '';
  88. wArgs.f_title = im.title ? im.title : '';
  89. wArgs.f_width = im.style.width ? im.style.width : im.width;
  90. wArgs.f_height = im.style.height ? im.style.height : im.height;
  91. wArgs.f_border = im.border ? im.border : '';
  92. wArgs.f_align = im.align ? im.align : '';
  93. wArgs.f_className = im.className ? im.className : '';
  94. // (-1 when not set under gecko for some reason)
  95. if ( im.hspace )
  96. {
  97. wArgs.f_horiz = (im.hspace >= 0) ? im.attributes['hspace'].nodeValue : '';
  98. }
  99. if ( im.vspace )
  100. {
  101. wArgs.f_vert = (im.vspace >= 0) ? wArgs.f_vert = im.attributes['vspace'].nodeValue : '';
  102. }
  103. } else {
  104. wArgs = null;
  105. }
  106. //-------------------------------------------------------------------------
  107. var manager = new ImageManager();
  108. manager.insert(wArgs);
  109. }
  110. //-------------------------------------------------------------------------
  111. function setAttrib(element, name, value, fixval) { // set element attributes
  112. if (!fixval && value != null) {
  113. var re = new RegExp('[^0-9%]', 'g');
  114. value = value.replace(re, '');
  115. }
  116. if (value != null && value != '') {
  117. element.setAttribute(name, value);
  118. } else {
  119. element.removeAttribute(name);
  120. }
  121. }
  122. /* IMAGE MANAGER OBJECT - A CROSS BETWEEN THE STANDALONE & HTMLAREA PLUGIN VERSIONS */
  123. function ImageManager()
  124. {
  125. //var tt = ImageManager.I18N;
  126. };
  127. // Open up the plugin's dialog with manager or editor.
  128. ImageManager.prototype.insert = function(outparam)
  129. {
  130. // show image editor
  131. if (IM_directEdit)
  132. {
  133. // image selected?
  134. var sElm = FCK.Selection.GetSelectedElement();
  135. if (sElm != null && sElm.nodeName.toLowerCase() == 'img')
  136. {
  137. // opening a dialog with the image editor - editor.php must receive the path to the image relative to your 'base_url' defined in 'config.inc.php'
  138. // for direct Editing, we assume that there are no subdirectories in 'base_url' so our path is just '/'
  139. lastSlashPosition = sElm.src.lastIndexOf('/') + 1;
  140. imgFileName = sElm.src.substring(lastSlashPosition);
  141. var url = FCKConfig.PluginsPath + 'ImageManager/editor.php?img=' + "/" + imgFileName;
  142. //Dialog(url, null, outparam);
  143. OpenDialog( url, null, outparam, 'FCKDialog_ImageEditor', 'Edit image', 713, 596 );
  144. }
  145. // no image selected - stop
  146. else
  147. {
  148. alert("no image selected");
  149. return false;
  150. }
  151. }
  152. // show image manager
  153. else
  154. {
  155. var manager = FCKConfig.PluginsPath+'ImageManager/manager.php?base_url_alt='+FCKConfig.CreateDocumentDir;
  156. //Dialog(manager, function(param) {
  157. OpenDialog( manager, function(param) {
  158. if (!param) return false; // user must have pressed cancel
  159. var sElm = FCK.Selection.GetSelectedElement();
  160. if (sElm != null && sElm.nodeName.toLowerCase() == 'img') var im = sElm;
  161. if (!im) { // new image// no image - create new image
  162. im = FCK.CreateElement('IMG');
  163. }
  164. // set image attributes
  165. setAttrib(im, "_fcksavedurl", param.f_url_alt , true);
  166. //setAttrib(im, 'src', param.f_url_alt, true);
  167. setAttrib(im, 'src', param.f_url_alt, true);
  168. setAttrib(im, 'alt', param.f_alt, true);
  169. setAttrib(im, 'title', param.f_title, true);
  170. setAttrib(im, 'align', param.f_align, true);
  171. setAttrib(im, 'border', param.f_border);
  172. setAttrib(im, 'hspace', param.f_horiz);
  173. setAttrib(im, 'vspace', param.f_vert);
  174. setAttrib(im, 'width', param.f_width);
  175. setAttrib(im, 'height', param.f_height);
  176. setAttrib(im, 'className', param.f_className, true);
  177. return;
  178. //}, outparam);
  179. }, outparam, 'FCKDialog_ImageManager', 'Insert Image', 900, 535 );
  180. }
  181. };
  182. // Added by Ivan Tcholakov, 23-JUL-2009.
  183. function OpenDialog( url, action, init, dialogName, dialogTitle, width, height )
  184. {
  185. if ( FCKConfig.OpenImageManagerInANewWindow && FCKConfig.OpenImageManagerInANewWindow.toString() == 'true' ) {
  186. Dialog(url, action, init);
  187. } else {
  188. if (typeof init == "undefined") {
  189. init = window; // pass this window object by default
  190. }
  191. FCKDialog.OpenDialog( dialogName, dialogTitle, url, width, height ) ;
  192. Dialog._arguments = init;
  193. Dialog._return = function (val) {
  194. if (val && action) {
  195. action(val);
  196. }
  197. };
  198. }
  199. }
  200. // Dialog v3.0 - Copyright (c) 2003-2004 interactivetools.com, inc.
  201. // This copyright notice MUST stay intact for use (see license.txt).
  202. //
  203. // Portions (c) dynarch.com, 2003-2004
  204. //
  205. // A free WYSIWYG editor replacement for <textarea> fields.
  206. // For full source code and docs, visit http://www.interactivetools.com/
  207. //
  208. // Version 3.0 developed by Mihai Bazon.
  209. // http://dynarch.com/mishoo
  210. //
  211. // Id: dialog.js 26 2004-03-31 02:35:21Z Wei Zhuo
  212. // Though "Dialog" looks like an object, it isn't really an object. Instead
  213. // it's just namespace for protecting global symbols.
  214. function Dialog(url, action, init) {
  215. if (typeof init == "undefined") {
  216. init = window; // pass this window object by default
  217. }
  218. Dialog._geckoOpenModal(url, action, init);
  219. };
  220. Dialog._parentEvent = function(ev) {
  221. setTimeout( function() { if (Dialog._modal && !Dialog._modal.closed) { Dialog._modal.focus() } }, 50);
  222. if (Dialog._modal && !Dialog._modal.closed) {
  223. Dialog._stopEvent(ev);
  224. }
  225. };
  226. // should be a function, the return handler of the currently opened dialog.
  227. Dialog._return = null;
  228. // constant, the currently opened dialog
  229. Dialog._modal = null;
  230. // the dialog will read it's args from this variable
  231. Dialog._arguments = null;
  232. Dialog._geckoOpenModal = function(url, action, init) {
  233. //var urlLink = "hadialog"+url.toString();
  234. var myURL = "hadialog"+url;
  235. var regObj = /\W/g;
  236. myURL = myURL.replace(regObj,'_');
  237. var dlg = window.open(url, myURL,
  238. "toolbar=no,menubar=no,personalbar=no,width=10,height=10," +
  239. "scrollbars=no,resizable=yes,modal=yes,dependable=yes");
  240. Dialog._modal = dlg;
  241. Dialog._arguments = init;
  242. // capture some window's events
  243. function capwin(w) {
  244. Dialog._addEvent(w, "click", Dialog._parentEvent);
  245. Dialog._addEvent(w, "mousedown", Dialog._parentEvent);
  246. Dialog._addEvent(w, "focus", Dialog._parentEvent);
  247. };
  248. // release the captured events
  249. function relwin(w) {
  250. Dialog._removeEvent(w, "click", Dialog._parentEvent);
  251. Dialog._removeEvent(w, "mousedown", Dialog._parentEvent);
  252. Dialog._removeEvent(w, "focus", Dialog._parentEvent);
  253. };
  254. capwin(window.document);
  255. // capture other frames
  256. for (var i = 0; i < window.frames.length; capwin(window.frames[i++].document));
  257. // make up a function to be called when the Dialog ends.
  258. Dialog._return = function (val) {
  259. if (val && action) {
  260. action(val);
  261. }
  262. relwin(window.document);
  263. // capture other frames
  264. for (var i = 0; i < window.frames.length; relwin(window.frames[i++].document));
  265. Dialog._modal = null;
  266. };
  267. };
  268. // event handling
  269. Dialog._addEvent = function(el, evname, func) {
  270. if (Dialog.is_ie) {
  271. el.attachEvent("on" + evname, func);
  272. } else {
  273. el.addEventListener(evname, func, true);
  274. }
  275. };
  276. Dialog._removeEvent = function(el, evname, func) {
  277. if (Dialog.is_ie) {
  278. el.detachEvent("on" + evname, func);
  279. } else {
  280. el.removeEventListener(evname, func, true);
  281. }
  282. };
  283. Dialog._stopEvent = function(ev) {
  284. if (Dialog.is_ie) {
  285. ev.cancelBubble = true;
  286. ev.returnValue = false;
  287. } else {
  288. ev.preventDefault();
  289. ev.stopPropagation();
  290. }
  291. };
  292. Dialog.agt = navigator.userAgent.toLowerCase();
  293. Dialog.is_ie = ((Dialog.agt.indexOf("msie") != -1) && (Dialog.agt.indexOf("opera") == -1));