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