1 | define([ |
---|
2 | "dojo/_base/declare", // declare |
---|
3 | "dojo/has", |
---|
4 | "dojo/number", // number.format |
---|
5 | "dojo/query", // query |
---|
6 | "dojo/_base/lang", // lang |
---|
7 | "./HorizontalRule" |
---|
8 | ], function(declare, has, number, query, lang, HorizontalRule){ |
---|
9 | |
---|
10 | // module: |
---|
11 | // dijit/form/HorizontalRuleLabels |
---|
12 | |
---|
13 | var HorizontalRuleLabels = declare("dijit.form.HorizontalRuleLabels", HorizontalRule, { |
---|
14 | // summary: |
---|
15 | // Labels for `dijit/form/HorizontalSlider` |
---|
16 | |
---|
17 | templateString: '<div class="dijitRuleContainer dijitRuleContainerH dijitRuleLabelsContainer dijitRuleLabelsContainerH"></div>', |
---|
18 | |
---|
19 | // labelStyle: String |
---|
20 | // CSS style to apply to individual text labels |
---|
21 | labelStyle: "", |
---|
22 | |
---|
23 | // labels: String[]? |
---|
24 | // Array of text labels to render - evenly spaced from left-to-right or bottom-to-top. |
---|
25 | // Alternately, minimum and maximum can be specified, to get numeric labels. |
---|
26 | labels: [], |
---|
27 | |
---|
28 | // numericMargin: Integer |
---|
29 | // Number of generated numeric labels that should be rendered as '' on the ends when labels[] are not specified |
---|
30 | numericMargin: 0, |
---|
31 | |
---|
32 | // numericMinimum: Integer |
---|
33 | // Leftmost label value for generated numeric labels when labels[] are not specified |
---|
34 | minimum: 0, |
---|
35 | |
---|
36 | // numericMaximum: Integer |
---|
37 | // Rightmost label value for generated numeric labels when labels[] are not specified |
---|
38 | maximum: 1, |
---|
39 | |
---|
40 | // constraints: Object |
---|
41 | // pattern, places, lang, et al (see dojo.number) for generated numeric labels when labels[] are not specified |
---|
42 | constraints: {pattern: "#%"}, |
---|
43 | |
---|
44 | _positionPrefix: '<div class="dijitRuleLabelContainer dijitRuleLabelContainerH" style="left:', |
---|
45 | _labelPrefix: '"><div class="dijitRuleLabel dijitRuleLabelH">', |
---|
46 | _suffix: '</div></div>', |
---|
47 | |
---|
48 | _calcPosition: function(pos){ |
---|
49 | // summary: |
---|
50 | // Returns the value to be used in HTML for the label as part of the left: attribute |
---|
51 | // tags: |
---|
52 | // protected extension |
---|
53 | return pos; |
---|
54 | }, |
---|
55 | |
---|
56 | _genHTML: function(pos, ndx){ |
---|
57 | var label = this.labels[ndx]; |
---|
58 | return this._positionPrefix + this._calcPosition(pos) + this._positionSuffix + this.labelStyle + |
---|
59 | this._genDirectionHTML(label) + |
---|
60 | this._labelPrefix + label + this._suffix; |
---|
61 | }, |
---|
62 | |
---|
63 | _genDirectionHTML: function(label){ |
---|
64 | // extension point for bidi code |
---|
65 | return ""; |
---|
66 | }, |
---|
67 | |
---|
68 | getLabels: function(){ |
---|
69 | // summary: |
---|
70 | // Overridable function to return array of labels to use for this slider. |
---|
71 | // Can specify a getLabels() method instead of a labels[] array, or min/max attributes. |
---|
72 | // tags: |
---|
73 | // protected extension |
---|
74 | |
---|
75 | // if the labels array was not specified directly, then see if <li> children were |
---|
76 | var labels = this.labels; |
---|
77 | if(!labels.length && this.srcNodeRef){ |
---|
78 | // for markup creation, labels are specified as child elements |
---|
79 | labels = query("> li", this.srcNodeRef).map(function(node){ |
---|
80 | return String(node.innerHTML); |
---|
81 | }); |
---|
82 | } |
---|
83 | // if the labels were not specified directly and not as <li> children, then calculate numeric labels |
---|
84 | if(!labels.length && this.count > 1){ |
---|
85 | var start = this.minimum; |
---|
86 | var inc = (this.maximum - start) / (this.count - 1); |
---|
87 | for(var i = 0; i < this.count; i++){ |
---|
88 | labels.push((i < this.numericMargin || i >= (this.count - this.numericMargin)) ? '' : number.format(start, this.constraints)); |
---|
89 | start += inc; |
---|
90 | } |
---|
91 | } |
---|
92 | return labels; |
---|
93 | }, |
---|
94 | |
---|
95 | postMixInProperties: function(){ |
---|
96 | this.inherited(arguments); |
---|
97 | this.labels = this.getLabels(); |
---|
98 | this.count = this.labels.length; |
---|
99 | } |
---|
100 | }); |
---|
101 | |
---|
102 | if(has("dojo-bidi")){ |
---|
103 | HorizontalRuleLabels.extend({ |
---|
104 | _setTextDirAttr: function(textDir){ |
---|
105 | if(this.textDir != textDir){ |
---|
106 | this._set("textDir", textDir); |
---|
107 | query(".dijitRuleLabelContainer", this.domNode).forEach( |
---|
108 | lang.hitch(this, function(labelNode){ |
---|
109 | labelNode.style.direction = this.getTextDir(labelNode.innerText || labelNode.textContent || ""); |
---|
110 | }) |
---|
111 | ); |
---|
112 | } |
---|
113 | }, |
---|
114 | |
---|
115 | _genDirectionHTML: function(label){ |
---|
116 | return (this.textDir ? ("direction:" + this.getTextDir(label) + ";") : "") |
---|
117 | } |
---|
118 | }); |
---|
119 | } |
---|
120 | |
---|
121 | return HorizontalRuleLabels; |
---|
122 | }); |
---|