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