Debian Codegraph @

dijit/_editor/plugins/ToggleDir.js

raw symbols SCIP
1 define([
2 "dojo/_base/declare", // declare
3 "dojo/dom-style", // domStyle.getComputedStyle
4 "dojo/_base/kernel", // kernel.experimental
5 "dojo/_base/lang", // lang.hitch
6 "dojo/on",
7 "../_Plugin",
8 "../../form/ToggleButton"
9 ], function(declare, domStyle, kernel, lang, on, _Plugin, ToggleButton){
10
11 // module:
12 // dijit/_editor/plugins/ToggleDir
13
14 var ToggleDir = declare("dijit._editor.plugins.ToggleDir", _Plugin, {
15 // summary:
16 // This plugin is used to toggle direction of the edited document,
17 // independent of what direction the whole page is.
18
19 // Override _Plugin.useDefaultCommand: processing is done in this plugin
20 // rather than by sending commands to the Editor
21 useDefaultCommand: false,
22
23 command: "toggleDir",
24
25 // Override _Plugin.buttonClass to use a ToggleButton for this plugin rather than a vanilla Button
26 buttonClass: ToggleButton,
27
28 _initButton: function(){
29 this.inherited(arguments);
30
31 var button = this.button,
32 editorLtr = this.editor.isLeftToRight();
33
34 this.own(this.button.on("change", lang.hitch(this, function(checked){
35 this.editor.set("textDir", editorLtr ^ checked ? "ltr" : "rtl");
36 })));
37
38 // Button should be checked if the editor's textDir is opposite of the editor's dir.
39 // Note that the arrow in the icon points in opposite directions depending on the editor's dir.
40 var editorDir = editorLtr ? "ltr" : "rtl";
41 function setButtonChecked(textDir){
42 button.set("checked", textDir && textDir !== editorDir, false);
43 }
44 setButtonChecked(this.editor.get("textDir"));
45 this.editor.watch("textDir", function(name, oval, nval){
46 setButtonChecked(nval);
47 });
48 },
49
50 updateState: function(){
51 // summary:
52 // Over-ride for button state control for disabled to work.
53 this.button.set("disabled", this.get("disabled"));
54 }
55 });
56
57 // Register this plugin.
58 _Plugin.registry["toggleDir"] = function(){
59 return new ToggleDir({command: "toggleDir"});
60 };
61
62 return ToggleDir;
63 });