includes/clientside/tinymce/plugins/advimage/editor_plugin_src.js
changeset 335 67bd3121a12e
parent 1 fe660c52c48f
child 395 fa4c5ecb7c9a
equal deleted inserted replaced
334:c72b545f1304 335:67bd3121a12e
     1 /**
     1 /**
     2  * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
     2  * $Id: editor_plugin_src.js 373 2007-11-12 17:57:47Z spocke $
     3  *
     3  *
     4  * @author Moxiecode
     4  * @author Moxiecode
     5  * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
     5  * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
     6  */
     6  */
     7 
     7 
     8 /* Import plugin specific language pack */
     8 (function() {
     9 tinyMCE.importPluginLanguagePack('advimage');
     9 	tinymce.create('tinymce.plugins.AdvancedImagePlugin', {
       
    10 		init : function(ed, url) {
       
    11 			// Register commands
       
    12 			ed.addCommand('mceAdvImage', function() {
       
    13 				var e = ed.selection.getNode();
    10 
    14 
    11 var TinyMCE_AdvancedImagePlugin = {
    15 				// Internal image object like a flash placeholder
    12 	getInfo : function() {
    16 				if (ed.dom.getAttrib(e, 'class').indexOf('mceItem') != -1)
    13 		return {
    17 					return;
    14 			longname : 'Advanced image',
       
    15 			author : 'Moxiecode Systems AB',
       
    16 			authorurl : 'http://tinymce.moxiecode.com',
       
    17 			infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/advimage',
       
    18 			version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
       
    19 		};
       
    20 	},
       
    21 
    18 
    22 	getControlHTML : function(cn) {
    19 				ed.windowManager.open({
    23 		switch (cn) {
    20 					file : url + '/image.htm',
    24 			case "image":
    21 					width : 480 + ed.getLang('advimage.delta_width', 0),
    25 				return tinyMCE.getButtonHTML(cn, 'lang_image_desc', '{$themeurl}/images/image.gif', 'mceAdvImage');
    22 					height : 385 + ed.getLang('advimage.delta_height', 0),
       
    23 					inline : 1
       
    24 				}, {
       
    25 					plugin_url : url
       
    26 				});
       
    27 			});
       
    28 
       
    29 			// Register buttons
       
    30 			ed.addButton('image', {
       
    31 				title : 'advimage.image_desc',
       
    32 				cmd : 'mceAdvImage'
       
    33 			});
       
    34 		},
       
    35 
       
    36 		getInfo : function() {
       
    37 			return {
       
    38 				longname : 'Advanced image',
       
    39 				author : 'Moxiecode Systems AB',
       
    40 				authorurl : 'http://tinymce.moxiecode.com',
       
    41 				infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/advimage',
       
    42 				version : tinymce.majorVersion + "." + tinymce.minorVersion
       
    43 			};
    26 		}
    44 		}
       
    45 	});
    27 
    46 
    28 		return "";
    47 	// Register plugin
    29 	},
    48 	tinymce.PluginManager.add('advimage', tinymce.plugins.AdvancedImagePlugin);
    30 
    49 })();
    31 	execCommand : function(editor_id, element, command, user_interface, value) {
       
    32 		switch (command) {
       
    33 			case "mceAdvImage":
       
    34 				var template = new Array();
       
    35 
       
    36 				template['file']   = '../../plugins/advimage/image.htm';
       
    37 				template['width']  = 480;
       
    38 				template['height'] = 380;
       
    39 
       
    40 				// Language specific width and height addons
       
    41 				template['width']  += tinyMCE.getLang('lang_advimage_delta_width', 0);
       
    42 				template['height'] += tinyMCE.getLang('lang_advimage_delta_height', 0);
       
    43 
       
    44 				var inst = tinyMCE.getInstanceById(editor_id);
       
    45 				var elm = inst.getFocusElement();
       
    46 
       
    47 				if (elm != null && tinyMCE.getAttrib(elm, 'class').indexOf('mceItem') != -1)
       
    48 					return true;
       
    49 
       
    50 				tinyMCE.openWindow(template, {editor_id : editor_id, inline : "yes"});
       
    51 
       
    52 				return true;
       
    53 		}
       
    54 
       
    55 		return false;
       
    56 	},
       
    57 
       
    58 	cleanup : function(type, content) {
       
    59 		switch (type) {
       
    60 			case "insert_to_editor_dom":
       
    61 				var imgs = content.getElementsByTagName("img"), src, i;
       
    62 				for (i=0; i<imgs.length; i++) {
       
    63 					var onmouseover = tinyMCE.cleanupEventStr(tinyMCE.getAttrib(imgs[i], 'onmouseover'));
       
    64 					var onmouseout = tinyMCE.cleanupEventStr(tinyMCE.getAttrib(imgs[i], 'onmouseout'));
       
    65 
       
    66 					if ((src = this._getImageSrc(onmouseover)) != "") {
       
    67 						if (tinyMCE.getParam('convert_urls'))
       
    68 							src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], src);
       
    69 
       
    70 						imgs[i].setAttribute('onmouseover', "this.src='" + src + "';");
       
    71 					}
       
    72 
       
    73 					if ((src = this._getImageSrc(onmouseout)) != "") {
       
    74 						if (tinyMCE.getParam('convert_urls'))
       
    75 							src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], src);
       
    76 
       
    77 						imgs[i].setAttribute('onmouseout', "this.src='" + src + "';");
       
    78 					}
       
    79 				}
       
    80 				break;
       
    81 
       
    82 			case "get_from_editor_dom":
       
    83 				var imgs = content.getElementsByTagName("img");
       
    84 				for (var i=0; i<imgs.length; i++) {
       
    85 					var onmouseover = tinyMCE.cleanupEventStr(tinyMCE.getAttrib(imgs[i], 'onmouseover'));
       
    86 					var onmouseout = tinyMCE.cleanupEventStr(tinyMCE.getAttrib(imgs[i], 'onmouseout'));
       
    87 
       
    88 					if ((src = this._getImageSrc(onmouseover)) != "") {
       
    89 						if (tinyMCE.getParam('convert_urls'))
       
    90 							src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, null, true);");
       
    91 
       
    92 						imgs[i].setAttribute('onmouseover', "this.src='" + src + "';");
       
    93 					}
       
    94 
       
    95 					if ((src = this._getImageSrc(onmouseout)) != "") {
       
    96 						if (tinyMCE.getParam('convert_urls'))
       
    97 							src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, null, true);");
       
    98 
       
    99 						imgs[i].setAttribute('onmouseout', "this.src='" + src + "';");
       
   100 					}
       
   101 				}
       
   102 				break;
       
   103 		}
       
   104 
       
   105 		return content;
       
   106 	},
       
   107 
       
   108 	handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
       
   109 		if (node == null)
       
   110 			return;
       
   111 
       
   112 		do {
       
   113 			if (node.nodeName == "IMG" && tinyMCE.getAttrib(node, 'class').indexOf('mceItem') == -1) {
       
   114 				tinyMCE.switchClass(editor_id + '_advimage', 'mceButtonSelected');
       
   115 				return true;
       
   116 			}
       
   117 		} while ((node = node.parentNode));
       
   118 
       
   119 		tinyMCE.switchClass(editor_id + '_advimage', 'mceButtonNormal');
       
   120 
       
   121 		return true;
       
   122 	},
       
   123 
       
   124 	/**
       
   125 	 * Returns the image src from a scripted mouse over image str.
       
   126 	 *
       
   127 	 * @param {string} s String to get real src from.
       
   128 	 * @return Image src from a scripted mouse over image str.
       
   129 	 * @type string
       
   130 	 */
       
   131 	_getImageSrc : function(s) {
       
   132 		var sr, p = -1;
       
   133 
       
   134 		if (!s)
       
   135 			return "";
       
   136 
       
   137 		if ((p = s.indexOf('this.src=')) != -1) {
       
   138 			sr = s.substring(p + 10);
       
   139 			sr = sr.substring(0, sr.indexOf('\''));
       
   140 
       
   141 			return sr;
       
   142 		}
       
   143 
       
   144 		return "";
       
   145 	}
       
   146 };
       
   147 
       
   148 tinyMCE.addPlugin("advimage", TinyMCE_AdvancedImagePlugin);