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