source: Dev/trunk/src/client/dijit/_editor/plugins/ToggleDir.js

Last change on this file was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 2.3 KB
Line 
1define([
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        kernel.experimental("dijit._editor.plugins.ToggleDir");
15
16        var ToggleDir = declare("dijit._editor.plugins.ToggleDir", _Plugin, {
17                // summary:
18                //              This plugin is used to toggle direction of the edited document,
19                //              independent of what direction the whole page is.
20
21                // Override _Plugin.useDefaultCommand: processing is done in this plugin
22                // rather than by sending commands to the Editor
23                useDefaultCommand: false,
24
25                command: "toggleDir",
26
27                // Override _Plugin.buttonClass to use a ToggleButton for this plugin rather than a vanilla Button
28                buttonClass: ToggleButton,
29
30                _initButton: function(){
31                        // Override _Plugin._initButton() to setup handler for button click events.
32                        this.inherited(arguments);
33                        this.editor.onLoadDeferred.then(lang.hitch(this, function(){
34                                var editDoc = this.editor.editorObject.contentWindow.document.documentElement;
35                                //IE direction has to toggle on the body, not document itself.
36                                //If you toggle just the document, things get very strange in the
37                                //view.  But, the nice thing is this works for all supported browsers.
38                                editDoc = editDoc.getElementsByTagName("body")[0];
39                                var isLtr = domStyle.getComputedStyle(editDoc).direction == "ltr";
40                                this.button.set("checked", !isLtr);
41                                this.own(this.button.on("change", lang.hitch(this, "_setRtl")));
42                        }));
43                },
44
45                updateState: function(){
46                        // summary:
47                        //              Over-ride for button state control for disabled to work.
48                        this.button.set("disabled", this.get("disabled"));
49                },
50
51                _setRtl: function(rtl){
52                        // summary:
53                        //              Handler for button click events, to switch the text direction of the editor
54                        var dir = "ltr";
55                        if(rtl){
56                                dir = "rtl";
57                        }
58                        var editDoc = this.editor.editorObject.contentWindow.document.documentElement;
59                        editDoc = editDoc.getElementsByTagName("body")[0];
60                        editDoc.dir/*html node*/ = dir;
61                }
62        });
63
64        // Register this plugin.
65        _Plugin.registry["toggleDir"] = function(){
66                return new ToggleDir({command: "toggleDir"});
67        };
68
69        return ToggleDir;
70});
Note: See TracBrowser for help on using the repository browser.