includes/clientside/tinymce/plugins/directionality/editor_plugin_src.js
changeset 335 67bd3121a12e
parent 1 fe660c52c48f
child 395 fa4c5ecb7c9a
--- a/includes/clientside/tinymce/plugins/directionality/editor_plugin_src.js	Wed Dec 26 00:37:26 2007 -0500
+++ b/includes/clientside/tinymce/plugins/directionality/editor_plugin_src.js	Thu Dec 27 22:09:33 2007 -0500
@@ -1,90 +1,79 @@
 /**
- * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
+ * $Id: editor_plugin_src.js 372 2007-11-11 18:38:50Z spocke $
  *
  * @author Moxiecode
  * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
  */
 
-/* Import plugin specific language pack */
-tinyMCE.importPluginLanguagePack('directionality');
+(function() {
+	tinymce.create('tinymce.plugins.Directionality', {
+		init : function(ed, url) {
+			var t = this;
+
+			t.editor = ed;
 
-var TinyMCE_DirectionalityPlugin = {
-	getInfo : function() {
-		return {
-			longname : 'Directionality',
-			author : 'Moxiecode Systems AB',
-			authorurl : 'http://tinymce.moxiecode.com',
-			infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/directionality',
-			version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
-		};
-	},
+			ed.addCommand('mceDirectionLTR', function() {
+				var e = ed.dom.getParent(ed.selection.getNode(), ed.dom.isBlock);
 
-	getControlHTML : function(cn) {
-		switch (cn) {
-			case "ltr":
-				return tinyMCE.getButtonHTML(cn, 'lang_directionality_ltr_desc', '{$pluginurl}/images/ltr.gif', 'mceDirectionLTR');
+				if (e) {
+					if (ed.dom.getAttrib(e, "dir") != "ltr")
+						ed.dom.setAttrib(e, "dir", "ltr");
+					else
+						ed.dom.setAttrib(e, "dir", "");
+				}
 
-			case "rtl":
-				return tinyMCE.getButtonHTML(cn, 'lang_directionality_rtl_desc', '{$pluginurl}/images/rtl.gif', 'mceDirectionRTL');
-		}
+				ed.nodeChanged();
+			});
 
-		return "";
-	},
+			ed.addCommand('mceDirectionRTL', function() {
+				var e = ed.dom.getParent(ed.selection.getNode(), ed.dom.isBlock);
 
-	execCommand : function(editor_id, element, command, user_interface, value) {
-		// Handle commands
-		switch (command) {
-			case "mceDirectionLTR":
-				var inst = tinyMCE.getInstanceById(editor_id);
-				var elm = tinyMCE.getParentElement(inst.getFocusElement(), "p,div,td,h1,h2,h3,h4,h5,h6,pre,address");
+				if (e) {
+					if (ed.dom.getAttrib(e, "dir") != "rtl")
+						ed.dom.setAttrib(e, "dir", "rtl");
+					else
+						ed.dom.setAttrib(e, "dir", "");
+				}
 
-				if (elm)
-					elm.setAttribute("dir", "ltr");
+				ed.nodeChanged();
+			});
 
-				tinyMCE.triggerNodeChange(false);
-				return true;
+			ed.addButton('ltr', {title : 'directionality.ltr_desc', cmd : 'mceDirectionLTR'});
+			ed.addButton('rtl', {title : 'directionality.rtl_desc', cmd : 'mceDirectionRTL'});
 
-			case "mceDirectionRTL":
-				var inst = tinyMCE.getInstanceById(editor_id);
-				var elm = tinyMCE.getParentElement(inst.getFocusElement(), "p,div,td,h1,h2,h3,h4,h5,h6,pre,address");
-
-				if (elm)
-					elm.setAttribute("dir", "rtl");
+			ed.onNodeChange.add(t._nodeChange, t);
+		},
 
-				tinyMCE.triggerNodeChange(false);
-				return true;
-		}
+		getInfo : function() {
+			return {
+				longname : 'Directionality',
+				author : 'Moxiecode Systems AB',
+				authorurl : 'http://tinymce.moxiecode.com',
+				infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/directionality',
+				version : tinymce.majorVersion + "." + tinymce.minorVersion
+			};
+		},
 
-		// Pass to next handler in chain
-		return false;
-	},
+		// Private methods
 
-	handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
-		function getAttrib(elm, name) {
-			return elm.getAttribute(name) ? elm.getAttribute(name) : "";
-		}
+		_nodeChange : function(ed, cm, n) {
+			var dom = ed.dom, dir;
 
-		if (node == null)
-			return;
-
-		var elm = tinyMCE.getParentElement(node, "p,div,td,h1,h2,h3,h4,h5,h6,pre,address");
-		if (!elm) {
-			tinyMCE.switchClass(editor_id + '_ltr', 'mceButtonDisabled');
-			tinyMCE.switchClass(editor_id + '_rtl', 'mceButtonDisabled');
-			return true;
-		}
+			n = dom.getParent(n, dom.isBlock);
+			if (!n) {
+				cm.setDisabled('ltr', 1);
+				cm.setDisabled('rtl', 1);
+				return;
+			}
 
-		tinyMCE.switchClass(editor_id + '_ltr', 'mceButtonNormal');
-		tinyMCE.switchClass(editor_id + '_rtl', 'mceButtonNormal');
+			dir = dom.getAttrib(n, 'dir');
+			cm.setActive('ltr', dir == "ltr");
+			cm.setDisabled('ltr', 0);
+			cm.setActive('rtl', dir == "rtl");
+			cm.setDisabled('rtl', 0);
+		}
+	});
 
-		var dir = getAttrib(elm, "dir");
-		if (dir == "ltr" || dir == "")
-			tinyMCE.switchClass(editor_id + '_ltr', 'mceButtonSelected');
-		else
-			tinyMCE.switchClass(editor_id + '_rtl', 'mceButtonSelected');
-
-		return true;
-	}
-};
-
-tinyMCE.addPlugin("directionality", TinyMCE_DirectionalityPlugin);
+	// Register plugin
+	tinymce.PluginManager.add('directionality', tinymce.plugins.Directionality);
+})();
\ No newline at end of file