]>
git.wh0rd.org - tt-rss.git/blob - 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
7 "../../form/ToggleButton"
8 ], function(declare
, domStyle
, kernel
, lang
, _Plugin
, ToggleButton
){
11 // dijit/_editor/plugins/ToggleDir
13 kernel
.experimental("dijit._editor.plugins.ToggleDir");
15 var ToggleDir
= declare("dijit._editor.plugins.ToggleDir", _Plugin
, {
17 // This plugin is used to toggle direction of the edited document,
18 // independent of what direction the whole page is.
20 // Override _Plugin.useDefaultCommand: processing is done in this plugin
21 // rather than by sending commands to the Editor
22 useDefaultCommand
: false,
26 // Override _Plugin.buttonClass to use a ToggleButton for this plugin rather than a vanilla Button
27 buttonClass
: ToggleButton
,
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");
44 updateState: function(){
46 // Over-ride for button state control for disabled to work.
47 this.button
.set("disabled", this.get("disabled"));
50 _setRtl: function(rtl
){
52 // Handler for button click events, to switch the text direction of the editor
57 var editDoc
= this.editor
.editorObject
.contentWindow
.document
.documentElement
;
58 editDoc
= editDoc
.getElementsByTagName("body")[0];
59 editDoc
.dir
/*html node*/ = dir
;
63 // Register this plugin.
64 _Plugin
.registry
["toggleDir"] = function(){
65 return new ToggleDir({command
: "toggleDir"});