]>
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 var _Plugin = dijit._editor._Plugin;
15 // dijit/_editor/plugins/ToggleDir
17 // This plugin is used to toggle direction of the edited document,
18 // independent of what direction the whole page is.
21 kernel
.experimental("dijit._editor.plugins.ToggleDir");
23 var ToggleDir
= declare("dijit._editor.plugins.ToggleDir", _Plugin
, {
25 // This plugin is used to toggle direction of the edited document,
26 // independent of what direction the whole page is.
28 // Override _Plugin.useDefaultCommand: processing is done in this plugin
29 // rather than by sending commands to the Editor
30 useDefaultCommand
: false,
34 // Override _Plugin.buttonClass to use a ToggleButton for this plugin rather than a vanilla Button
35 buttonClass
: ToggleButton
,
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");
52 updateState: function(){
54 // Over-ride for button state control for disabled to work.
55 this.button
.set("disabled", this.get("disabled"));
58 _setRtl: function(rtl
){
60 // Handler for button click events, to switch the text direction of the editor
65 var editDoc
= this.editor
.editorObject
.contentWindow
.document
.documentElement
;
66 editDoc
= editDoc
.getElementsByTagName("body")[0];
67 editDoc
.dir
/*html node*/ = dir
;
71 // Register this plugin.
72 _Plugin
.registry
["toggleDir"] = function(){
73 return new ToggleDir({command
: "toggleDir"});