]> git.wh0rd.org - tt-rss.git/blame - lib/dijit/_editor/plugins/ToggleDir.js.uncompressed.js
make precache_headlines_idle() start slower
[tt-rss.git] / lib / dijit / _editor / plugins / ToggleDir.js.uncompressed.js
CommitLineData
1354d172
AD
1define("dijit/_editor/plugins/ToggleDir", [
2 "dojo/_base/declare", // declare
3 "dojo/dom-style", // domStyle.getComputedStyle
4 "dojo/_base/kernel", // kernel.experimental
5 "dojo/_base/lang", // lang.hitch
6 "../_Plugin",
7 "../../form/ToggleButton"
8], function(declare, domStyle, kernel, lang, _Plugin, ToggleButton){
9
10/*=====
11 var _Plugin = dijit._editor._Plugin;
12=====*/
13
14 // module:
15 // dijit/_editor/plugins/ToggleDir
16 // summary:
17 // This plugin is used to toggle direction of the edited document,
18 // independent of what direction the whole page is.
19
20
21 kernel.experimental("dijit._editor.plugins.ToggleDir");
22
23 var ToggleDir = declare("dijit._editor.plugins.ToggleDir", _Plugin, {
24 // summary:
25 // This plugin is used to toggle direction of the edited document,
26 // independent of what direction the whole page is.
27
28 // Override _Plugin.useDefaultCommand: processing is done in this plugin
29 // rather than by sending commands to the Editor
30 useDefaultCommand: false,
31
32 command: "toggleDir",
33
34 // Override _Plugin.buttonClass to use a ToggleButton for this plugin rather than a vanilla Button
35 buttonClass: ToggleButton,
36
37 _initButton: function(){
38 // Override _Plugin._initButton() to setup handler for button click events.
39 this.inherited(arguments);
40 this.editor.onLoadDeferred.addCallback(lang.hitch(this, function(){
41 var editDoc = this.editor.editorObject.contentWindow.document.documentElement;
42 //IE direction has to toggle on the body, not document itself.
43 //If you toggle just the document, things get very strange in the
44 //view. But, the nice thing is this works for all supported browsers.
45 editDoc = editDoc.getElementsByTagName("body")[0];
46 var isLtr = domStyle.getComputedStyle(editDoc).direction == "ltr";
47 this.button.set("checked", !isLtr);
48 this.connect(this.button, "onChange", "_setRtl");
49 }));
50 },
51
52 updateState: function(){
53 // summary:
54 // Over-ride for button state control for disabled to work.
55 this.button.set("disabled", this.get("disabled"));
56 },
57
58 _setRtl: function(rtl){
59 // summary:
60 // Handler for button click events, to switch the text direction of the editor
61 var dir = "ltr";
62 if(rtl){
63 dir = "rtl";
64 }
65 var editDoc = this.editor.editorObject.contentWindow.document.documentElement;
66 editDoc = editDoc.getElementsByTagName("body")[0];
67 editDoc.dir/*html node*/ = dir;
68 }
69 });
70
71 // Register this plugin.
72 _Plugin.registry["toggleDir"] = function(){
73 return new ToggleDir({command: "toggleDir"});
74 };
75
76 return ToggleDir;
77});