]> git.wh0rd.org - tt-rss.git/blob - lib/dijit/_editor/plugins/ToggleDir.js.uncompressed.js
upgrade dojo to 1.8.3 (refs #570)
[tt-rss.git] / lib / dijit / _editor / plugins / ToggleDir.js.uncompressed.js
1 define("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 // module:
11 // dijit/_editor/plugins/ToggleDir
12
13 kernel.experimental("dijit._editor.plugins.ToggleDir");
14
15 var ToggleDir = declare("dijit._editor.plugins.ToggleDir", _Plugin, {
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 // Override _Plugin.useDefaultCommand: processing is done in this plugin
21 // rather than by sending commands to the Editor
22 useDefaultCommand: false,
23
24 command: "toggleDir",
25
26 // Override _Plugin.buttonClass to use a ToggleButton for this plugin rather than a vanilla Button
27 buttonClass: ToggleButton,
28
29 _initButton: function(){
30 // Override _Plugin._initButton() to setup handler for button click events.
31 this.inherited(arguments);
32 this.editor.onLoadDeferred.then(lang.hitch(this, function(){
33 var editDoc = this.editor.editorObject.contentWindow.document.documentElement;
34 //IE direction has to toggle on the body, not document itself.
35 //If you toggle just the document, things get very strange in the
36 //view. But, the nice thing is this works for all supported browsers.
37 editDoc = editDoc.getElementsByTagName("body")[0];
38 var isLtr = domStyle.getComputedStyle(editDoc).direction == "ltr";
39 this.button.set("checked", !isLtr);
40 this.connect(this.button, "onChange", "_setRtl");
41 }));
42 },
43
44 updateState: function(){
45 // summary:
46 // Over-ride for button state control for disabled to work.
47 this.button.set("disabled", this.get("disabled"));
48 },
49
50 _setRtl: function(rtl){
51 // summary:
52 // Handler for button click events, to switch the text direction of the editor
53 var dir = "ltr";
54 if(rtl){
55 dir = "rtl";
56 }
57 var editDoc = this.editor.editorObject.contentWindow.document.documentElement;
58 editDoc = editDoc.getElementsByTagName("body")[0];
59 editDoc.dir/*html node*/ = dir;
60 }
61 });
62
63 // Register this plugin.
64 _Plugin.registry["toggleDir"] = function(){
65 return new ToggleDir({command: "toggleDir"});
66 };
67
68 return ToggleDir;
69 });