includes/clientside/tinymce/plugins/directionality/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('directionality');
       
    10 
       
    11 var TinyMCE_DirectionalityPlugin = {
       
    12 	getInfo : function() {
       
    13 		return {
       
    14 			longname : 'Directionality',
       
    15 			author : 'Moxiecode Systems AB',
       
    16 			authorurl : 'http://tinymce.moxiecode.com',
       
    17 			infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/directionality',
       
    18 			version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
       
    19 		};
       
    20 	},
       
    21 
       
    22 	getControlHTML : function(cn) {
       
    23 		switch (cn) {
       
    24 			case "ltr":
       
    25 				return tinyMCE.getButtonHTML(cn, 'lang_directionality_ltr_desc', '{$pluginurl}/images/ltr.gif', 'mceDirectionLTR');
       
    26 
       
    27 			case "rtl":
       
    28 				return tinyMCE.getButtonHTML(cn, 'lang_directionality_rtl_desc', '{$pluginurl}/images/rtl.gif', 'mceDirectionRTL');
       
    29 		}
       
    30 
       
    31 		return "";
       
    32 	},
       
    33 
       
    34 	execCommand : function(editor_id, element, command, user_interface, value) {
       
    35 		// Handle commands
       
    36 		switch (command) {
       
    37 			case "mceDirectionLTR":
       
    38 				var inst = tinyMCE.getInstanceById(editor_id);
       
    39 				var elm = tinyMCE.getParentElement(inst.getFocusElement(), "p,div,td,h1,h2,h3,h4,h5,h6,pre,address");
       
    40 
       
    41 				if (elm)
       
    42 					elm.setAttribute("dir", "ltr");
       
    43 
       
    44 				tinyMCE.triggerNodeChange(false);
       
    45 				return true;
       
    46 
       
    47 			case "mceDirectionRTL":
       
    48 				var inst = tinyMCE.getInstanceById(editor_id);
       
    49 				var elm = tinyMCE.getParentElement(inst.getFocusElement(), "p,div,td,h1,h2,h3,h4,h5,h6,pre,address");
       
    50 
       
    51 				if (elm)
       
    52 					elm.setAttribute("dir", "rtl");
       
    53 
       
    54 				tinyMCE.triggerNodeChange(false);
       
    55 				return true;
       
    56 		}
       
    57 
       
    58 		// Pass to next handler in chain
       
    59 		return false;
       
    60 	},
       
    61 
       
    62 	handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
       
    63 		function getAttrib(elm, name) {
       
    64 			return elm.getAttribute(name) ? elm.getAttribute(name) : "";
       
    65 		}
       
    66 
       
    67 		if (node == null)
       
    68 			return;
       
    69 
       
    70 		var elm = tinyMCE.getParentElement(node, "p,div,td,h1,h2,h3,h4,h5,h6,pre,address");
       
    71 		if (!elm) {
       
    72 			tinyMCE.switchClass(editor_id + '_ltr', 'mceButtonDisabled');
       
    73 			tinyMCE.switchClass(editor_id + '_rtl', 'mceButtonDisabled');
       
    74 			return true;
       
    75 		}
       
    76 
       
    77 		tinyMCE.switchClass(editor_id + '_ltr', 'mceButtonNormal');
       
    78 		tinyMCE.switchClass(editor_id + '_rtl', 'mceButtonNormal');
       
    79 
       
    80 		var dir = getAttrib(elm, "dir");
       
    81 		if (dir == "ltr" || dir == "")
       
    82 			tinyMCE.switchClass(editor_id + '_ltr', 'mceButtonSelected');
       
    83 		else
       
    84 			tinyMCE.switchClass(editor_id + '_rtl', 'mceButtonSelected');
       
    85 
       
    86 		return true;
       
    87 	}
       
    88 };
       
    89 
       
    90 tinyMCE.addPlugin("directionality", TinyMCE_DirectionalityPlugin);