Revert "Export"
[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.oldValue = this._value();
42                         this._refreshValue();
43                 },
44
45                 _destroy: function () {
46                         this.element
47                                 .removeClass( "ui-progressbar" )
48                                 .removeAttr( "role" )
49                                 .removeAttr( "aria-valuemin" )
50                                 .removeAttr( "aria-valuemax" )
51                                 .removeAttr( "aria-valuenow" );
52
53                         this.valueDiv.remove();
54                 },
55
56                 value: function ( newValue ) {
57                         if ( newValue === undefined ) {
58                                 return this._value();
59                         }
60
61                         this._setOption( "value", newValue );
62                         return this;
63                 },
64
65                 _setOption: function ( key, value ) {
66                         if ( key === "value" ) {
67                                 this.options.value = value;
68                                 this._refreshValue();
69                                 if ( this._value() === this.options.max ) {
70                                         this._trigger( "complete" );
71                                 }
72                         }
73                         // jquery.ui.widget.js MUST be updated to new version!
74                         //this._super( "_setOption", key, value );
75                 },
76
77                 _value: function () {
78                         var val = this.options.value;
79                         // normalize invalid value
80                         if ( typeof val !== "number" ) {
81                                 val = 0;
82                         }
83                         return Math.min( this.options.max, Math.max( this.min, val ) );
84                 },
85
86                 _percentage: function () {
87                         return 100 * this._value() / this.options.max;
88                 },
89
90                 _refreshValue: function () {
91                         var value = this.value(),
92                                 percentage = this._percentage();
93
94                         if ( this.oldValue !== value ) {
95                                 this.oldValue = value;
96                                 this._trigger( "change" );
97                         }
98
99                         this.valueDiv
100                                 .toggle( value > this.min )
101                                 .width( percentage.toFixed(0) + "%" );
102                         this.element.attr( "aria-valuenow", value );
103                 }
104         } );
105
106         // auto self-init widgets
107         $( document ).bind( "pagecreate", function ( e ) {
108                 $( e.target ).find( ":jqmData(role='progressbar')" ).progressbar();
109         } );
110
111 }( jQuery, this ) );