includes/clientside/tinymce/plugins/advlink/editor_plugin_src.js
changeset 1 fe660c52c48f
child 335 67bd3121a12e
equal deleted inserted replaced
0:902822492a68 1:fe660c52c48f
       
     1 /**
       
     2  * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
       
     3  *
       
     4  * @author Moxiecode
       
     5  * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
       
     6  */
       
     7 
       
     8 /* Import plugin specific language pack */
       
     9 tinyMCE.importPluginLanguagePack('advlink');
       
    10 
       
    11 var TinyMCE_AdvancedLinkPlugin = {
       
    12 	getInfo : function() {
       
    13 		return {
       
    14 			longname : 'Advanced link',
       
    15 			author : 'Moxiecode Systems AB',
       
    16 			authorurl : 'http://tinymce.moxiecode.com',
       
    17 			infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/advlink',
       
    18 			version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
       
    19 		};
       
    20 	},
       
    21 
       
    22 	initInstance : function(inst) {
       
    23 		inst.addShortcut('ctrl', 'k', 'lang_advlink_desc', 'mceAdvLink');
       
    24 	},
       
    25 
       
    26 	getControlHTML : function(cn) {
       
    27 		switch (cn) {
       
    28 			case "link":
       
    29 				return tinyMCE.getButtonHTML(cn, 'lang_link_desc', '{$themeurl}/images/link.gif', 'mceAdvLink');
       
    30 		}
       
    31 
       
    32 		return "";
       
    33 	},
       
    34 
       
    35 	execCommand : function(editor_id, element, command, user_interface, value) {
       
    36 		switch (command) {
       
    37 			case "mceAdvLink":
       
    38 				var anySelection = false;
       
    39 				var inst = tinyMCE.getInstanceById(editor_id);
       
    40 				var focusElm = inst.getFocusElement();
       
    41 				var selectedText = inst.selection.getSelectedText();
       
    42 
       
    43 				if (tinyMCE.selectedElement)
       
    44 					anySelection = (tinyMCE.selectedElement.nodeName.toLowerCase() == "img") || (selectedText && selectedText.length > 0);
       
    45 
       
    46 				if (anySelection || (focusElm != null && focusElm.nodeName == "A")) {
       
    47 					var template = new Array();
       
    48 
       
    49 					template['file']   = '../../plugins/advlink/link.htm';
       
    50 					template['width']  = 480;
       
    51 					template['height'] = 400;
       
    52 
       
    53 					// Language specific width and height addons
       
    54 					template['width']  += tinyMCE.getLang('lang_advlink_delta_width', 0);
       
    55 					template['height'] += tinyMCE.getLang('lang_advlink_delta_height', 0);
       
    56 
       
    57 					tinyMCE.openWindow(template, {editor_id : editor_id, inline : "yes"});
       
    58 				}
       
    59 
       
    60 				return true;
       
    61 		}
       
    62 
       
    63 		return false;
       
    64 	},
       
    65 
       
    66 	handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
       
    67 		if (node == null)
       
    68 			return;
       
    69 
       
    70 		do {
       
    71 			if (node.nodeName == "A" && tinyMCE.getAttrib(node, 'href') != "") {
       
    72 				tinyMCE.switchClass(editor_id + '_advlink', 'mceButtonSelected');
       
    73 				return true;
       
    74 			}
       
    75 		} while ((node = node.parentNode));
       
    76 
       
    77 		if (any_selection) {
       
    78 			tinyMCE.switchClass(editor_id + '_advlink', 'mceButtonNormal');
       
    79 			return true;
       
    80 		}
       
    81 
       
    82 		tinyMCE.switchClass(editor_id + '_advlink', 'mceButtonDisabled');
       
    83 
       
    84 		return true;
       
    85 	}
       
    86 };
       
    87 
       
    88 tinyMCE.addPlugin("advlink", TinyMCE_AdvancedLinkPlugin);