982f59515cf60a87e0ca3805959444f018e32e8a
[platform/framework/web/web-ui-fw.git] / src / widgets / progressbar / js / jquery.mobile.tizen.progressbar.js
1 /* TBD */
2 /*
3  * jQuery UI Progressbar @VERSION
4  *
5  * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
6  * Dual licensed under the MIT or GPL Version 2 licenses.
7  * http://jquery.org/license
8  *
9  * http://docs.jquery.com/UI/Progressbar
10  *
11  * Depends:
12  *   jquery.ui.core.js
13  *   jquery.ui.widget.js
14  * Original file:
15  *   jquery.ui.progressbar.js
16  */
17 /* This is from jquery ui plugin - progressbar 11/16/2011 */
18
19 (function( $, window, undefined ) {
20
21 $.widget( "tizen.progressbar", $.mobile.widget, {
22         options: {
23                 value: 0,
24                 max: 100
25         },
26
27         min: 0,
28
29         _create: function() {
30                 this.element
31                         .addClass( "ui-progressbar" )
32                         .attr({
33                                 role: "progressbar",
34                                 "aria-valuemin": this.min,
35                                 "aria-valuemax": this.options.max,
36                                 "aria-valuenow": this._value()
37                         });
38
39                 this.valueDiv = $( "<div class='ui-progressbar-value'></div>" )
40                         .appendTo( this.element );
41
42                 this.oldValue = this._value();
43                 this._refreshValue();
44         },
45
46         _destroy: function() {
47                 this.element
48                         .removeClass( "ui-progressbar" )
49                         .removeAttr( "role" )
50                         .removeAttr( "aria-valuemin" )
51                         .removeAttr( "aria-valuemax" )
52                         .removeAttr( "aria-valuenow" );
53
54                 this.valueDiv.remove();
55         },
56
57         value: function( newValue ) {
58                 if ( newValue === undefined ) {
59                         return this._value();
60                 }
61
62                 this._setOption( "value", newValue );
63                 return this;
64         },
65
66         _setOption: function( key, value ) {
67                 if ( key === "value" ) {
68                         this.options.value = value;
69                         this._refreshValue();
70                         if ( this._value() === this.options.max ) {
71                                 this._trigger( "complete" );
72                         }
73                 }
74                 // jquery.ui.widget.js MUST be updated to new version!
75                 //this._super( "_setOption", key, value );
76         },
77
78         _value: function() {
79                 var val = this.options.value;
80                 // normalize invalid value
81                 if ( typeof val !== "number" ) {
82                         val = 0;
83                 }
84                 return Math.min( this.options.max, Math.max( this.min, val ) );
85         },
86
87         _percentage: function() {
88                 return 100 * this._value() / this.options.max;
89         },
90
91         _refreshValue: function() {
92                 var value = this.value();
93                 var percentage = this._percentage();
94
95                 if ( this.oldValue !== value ) {
96                         this.oldValue = value;
97                         this._trigger( "change" );
98                 }
99
100                 this.valueDiv
101                         .toggle( value > this.min )
102                         .width( percentage.toFixed(0) + "%" );
103                 this.element.attr( "aria-valuenow", value );
104         }
105 });
106
107 // auto self-init widgets
108 $(document).bind("pagecreate", function (e) {
109         $(e.target).find(":jqmData(role='progressbar')").progressbar();
110 });
111
112 })( jQuery, this );