]> git.wh0rd.org Git - tt-rss.git/blob - lib/dijit/_editor/plugins/ToggleDir.js
upgrade Dojo to 1.6.1
[tt-rss.git] / lib / dijit / _editor / plugins / ToggleDir.js
1 /*
2         Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
3         Available via Academic Free License >= 2.1 OR the modified BSD license.
4         see: http://dojotoolkit.org/license for details
5 */
6
7
8 if(!dojo._hasResource["dijit._editor.plugins.ToggleDir"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
9 dojo._hasResource["dijit._editor.plugins.ToggleDir"] = true;
10 dojo.provide("dijit._editor.plugins.ToggleDir");
11 dojo.require("dijit._editor._Plugin");
12 dojo.require("dijit.form.ToggleButton");
13
14
15 dojo.experimental("dijit._editor.plugins.ToggleDir");
16
17 dojo.require("dijit._editor._Plugin");
18 dojo.require("dijit.form.ToggleButton");
19
20 dojo.declare("dijit._editor.plugins.ToggleDir",
21         dijit._editor._Plugin,
22         {
23                 // summary:
24                 //              This plugin is used to toggle direction of the edited document,
25                 //              independent of what direction the whole page is.
26
27                 // Override _Plugin.useDefaultCommand: processing is done in this plugin
28                 // rather than by sending commands to the Editor
29                 useDefaultCommand: false,
30
31                 command: "toggleDir",
32
33                 // Override _Plugin.buttonClass to use a ToggleButton for this plugin rather than a vanilla Button
34                 buttonClass: dijit.form.ToggleButton,
35
36                 _initButton: function(){
37                         // Override _Plugin._initButton() to setup handler for button click events.
38                         this.inherited(arguments);
39                         this.editor.onLoadDeferred.addCallback(dojo.hitch(this, function(){
40                                 var editDoc = this.editor.editorObject.contentWindow.document.documentElement;
41                                 //IE direction has to toggle on the body, not document itself.
42                                 //If you toggle just the document, things get very strange in the
43                                 //view.  But, the nice thing is this works for all supported browsers.
44                                 editDoc = editDoc.getElementsByTagName("body")[0];
45                                 var isLtr = dojo.getComputedStyle(editDoc).direction == "ltr";
46                                 this.button.set("checked", !isLtr);
47                                 this.connect(this.button, "onChange", "_setRtl");
48                         }));
49                 },
50
51                 updateState: function(){
52                         // summary:
53                         //              Over-ride for button state control for disabled to work.
54                         this.button.set("disabled", this.get("disabled"));
55                 },
56
57                 _setRtl: function(rtl){
58                         // summary:
59                         //              Handler for button click events, to switch the text direction of the editor
60                         var dir = "ltr";
61                         if(rtl){
62                                 dir = "rtl";
63                         }
64                         var editDoc = this.editor.editorObject.contentWindow.document.documentElement;
65                         editDoc = editDoc.getElementsByTagName("body")[0];
66                         editDoc.dir/*html node*/ = dir;
67                 }
68         }
69 );
70
71 // Register this plugin.
72 dojo.subscribe(dijit._scopeName + ".Editor.getPlugin",null,function(o){
73         if(o.plugin){ return; }
74         switch(o.args.name){
75         case "toggleDir":
76                 o.plugin = new dijit._editor.plugins.ToggleDir({command: o.args.name});
77         }
78 });
79
80 }