1 | define([ |
---|
2 | "dojo/_base/declare", |
---|
3 | "./common", |
---|
4 | "dojo/dom-class" |
---|
5 | ], function(declare, common, domClass){ |
---|
6 | |
---|
7 | // module: |
---|
8 | // dojox/mobile/bidi/Switch |
---|
9 | |
---|
10 | return declare(null, { |
---|
11 | // summary: |
---|
12 | // Bidi support for mobile Switch widget, using Unicode Control Characters to control text direction. |
---|
13 | // description: |
---|
14 | // Implementation for text direction support for LeftLabel and RightLabel. |
---|
15 | // This class should not be used directly. |
---|
16 | // Mobile Switch widget loads this module when user sets "has: {'dojo-bidi': true }" in data-dojo-config. |
---|
17 | postCreate: function(){ |
---|
18 | this.inherited(arguments); |
---|
19 | if(!this.textDir && this.getParent() && this.getParent().get("textDir")){ |
---|
20 | this.set("textDir", this.getParent().get("textDir")); |
---|
21 | } |
---|
22 | }, |
---|
23 | buildRendering: function(){ |
---|
24 | this.inherited(arguments); |
---|
25 | // dojox.mobile mirroring support |
---|
26 | if(!this.isLeftToRight()){ |
---|
27 | domClass.add(this.left, "mblSwitchBgLeftRtl"); |
---|
28 | domClass.add(this.left.firstChild, "mblSwitchTextLeftRtl"); |
---|
29 | domClass.add(this.right, "mblSwitchBgRightRtl"); |
---|
30 | domClass.add(this.right.firstChild, "mblSwitchTextRightRtl"); |
---|
31 | } |
---|
32 | }, |
---|
33 | _newState: function(newState){ |
---|
34 | if(this.isLeftToRight()){ |
---|
35 | return this.inherited(arguments); |
---|
36 | } |
---|
37 | return (this.inner.offsetLeft < -(this._width/2)) ? "on" : "off"; |
---|
38 | }, |
---|
39 | _setLeftLabelAttr: function(label){ |
---|
40 | this.inherited(arguments); |
---|
41 | this.left.firstChild.innerHTML = common.enforceTextDirWithUcc(this.left.firstChild.innerHTML, this.textDir); |
---|
42 | }, |
---|
43 | |
---|
44 | _setRightLabelAttr: function(label){ |
---|
45 | this.inherited(arguments); |
---|
46 | this.right.firstChild.innerHTML = common.enforceTextDirWithUcc(this.right.firstChild.innerHTML, this.textDir); |
---|
47 | }, |
---|
48 | |
---|
49 | _setTextDirAttr: function(textDir){ |
---|
50 | if(textDir && (!this._created || this.textDir !== textDir)){ |
---|
51 | this.textDir = textDir; |
---|
52 | this.left.firstChild.innerHTML = common.removeUCCFromText(this.left.firstChild.innerHTML); |
---|
53 | this.left.firstChild.innerHTML = common.enforceTextDirWithUcc(this.left.firstChild.innerHTML, this.textDir); |
---|
54 | this.right.firstChild.innerHTML = common.removeUCCFromText(this.right.firstChild.innerHTML); |
---|
55 | this.right.firstChild.innerHTML = common.enforceTextDirWithUcc(this.right.firstChild.innerHTML, this.textDir); |
---|
56 | } |
---|
57 | } |
---|
58 | }); |
---|
59 | }); |
---|