username@email.com
2025-04-27 15eb82df2d6ec539e9d4245bfe08d531e8eb6379
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
/**
 * jQuery EasyUI 1.5.2
 * 
 * Copyright (c) 2009-2017 www.jeasyui.com. All rights reserved.
 *
 * Licensed under the freeware license: http://www.jeasyui.com/license_freeware.php
 * To use it on other terms please contact us: info@jeasyui.com
 *
 */
/**
 * progressbar - jQuery EasyUI
 * 
 * Dependencies:
 *      none
 * 
 */
(function($){
    function init(target){
        $(target).addClass('progressbar');
        $(target).html('<div class="progressbar-text"></div><div class="progressbar-value"><div class="progressbar-text"></div></div>');
        $(target).bind('_resize', function(e,force){
            if ($(this).hasClass('easyui-fluid') || force){
                setSize(target);
            }
            return false;
        });
        return $(target);
    }
    
    function setSize(target,width){
        var opts = $.data(target, 'progressbar').options;
        var bar = $.data(target, 'progressbar').bar;
        if (width) opts.width = width;
        bar._size(opts);
        
        bar.find('div.progressbar-text').css('width', bar.width());
        bar.find('div.progressbar-text,div.progressbar-value').css({
            height: bar.height()+'px',
            lineHeight: bar.height()+'px'
        });
    }
    
    $.fn.progressbar = function(options, param){
        if (typeof options == 'string'){
            var method = $.fn.progressbar.methods[options];
            if (method){
                return method(this, param);
            }
        }
        
        options = options || {};
        return this.each(function(){
            var state = $.data(this, 'progressbar');
            if (state){
                $.extend(state.options, options);
            } else {
                state = $.data(this, 'progressbar', {
                    options: $.extend({}, $.fn.progressbar.defaults, $.fn.progressbar.parseOptions(this), options),
                    bar: init(this)
                });
            }
            $(this).progressbar('setValue', state.options.value);
            setSize(this);
        });
    };
    
    $.fn.progressbar.methods = {
        options: function(jq){
            return $.data(jq[0], 'progressbar').options;
        },
        resize: function(jq, width){
            return jq.each(function(){
                setSize(this, width);
            });
        },
        getValue: function(jq){
            return $.data(jq[0], 'progressbar').options.value;
        },
        setValue: function(jq, value){
            if (value < 0) value = 0;
            if (value > 100) value = 100;
            return jq.each(function(){
                var opts = $.data(this, 'progressbar').options;
                var text = opts.text.replace(/{value}/, value);
                var oldValue = opts.value;
                opts.value = value;
                $(this).find('div.progressbar-value').width(value+'%');
                $(this).find('div.progressbar-text').html(text);
                if (oldValue != value){
                    opts.onChange.call(this, value, oldValue);
                }
            });
        }
    };
    
    $.fn.progressbar.parseOptions = function(target){
        return $.extend({}, $.parser.parseOptions(target, ['width','height','text',{value:'number'}]));
    };
    
    $.fn.progressbar.defaults = {
        width: 'auto',
        height: 22,
        value: 0,    // percentage value
        text: '{value}%',
        onChange:function(newValue,oldValue){}
    };
})(jQuery);