upload tizen1.0 source
[framework/web/web-ui-fw.git] / src / widgets / progress / js / jquery.mobile.tizen.progress.js
1 /* ***************************************************************************
2  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software" ),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  * ***************************************************************************
22  */
23 // progress
24 (function ( $, window, undefined) {
25         $.widget( "tizen.progress", $.mobile.widget, {
26                 options: {
27                         style: "circle",
28                         running: false
29                 },
30
31                 _show: function () {
32                         if ( !this.init ) {
33                                 $( this.element ).append( this.html );
34                                 this.init = true;
35                         }
36                         var style = this.options.style;
37                         $( this.element ).addClass( "ui-progress-container-" + style + "-bg" );
38                         $( this.element )
39                                 .find( ".ui-progress-" + style )
40                                 .addClass( this.runningClass );
41                 },
42
43                 _hide: function () {
44                         $( this.element )
45                                 .find( ".ui-progress-" + this.options.style )
46                                 .removeClass( this.runningClass );
47                 },
48
49                 running: function ( newRunning ) {
50                         // get value
51                         if ( newRunning === undefined ) {
52                                 return this.options.running;
53                         }
54
55                         // set value
56                         this._setOption( "running", newRunning );
57                         return this;
58                 },
59
60                 _setOption: function ( key, value ) {
61                         if ( key === "running" ) {
62                                 // normalize invalid value
63                                 if ( typeof value !== "boolean" ) {
64                                         window.alert( "running value MUST be boolean type!" );
65                                         return;
66                                 }
67                                 this.options.running = value;
68                                 this._refresh();
69                         }
70                 },
71
72                 _refresh: function () {
73                         if ( this.options.running ) {
74                                 this._show();
75                         } else {
76                                 this._hide();
77                         }
78                 },
79
80                 _create: function () {
81                         var self = this,
82                                 element = this.element,
83                                 style = element.jqmData( "style" ),
84                                 runningClass;
85
86                         if ( style ) {
87                                 this.options.style = style;
88                         }
89
90                         this.html = $( '<div class="ui-progress-container-' + style + '">' +
91                                         '<div class="ui-progress-' + style + '"></div>' +
92                                         '</div>' );
93
94                         runningClass = "ui-progress-" + style + "-running";
95
96                         $.extend( this, {
97                                 init: false,
98                                 runningClass: runningClass
99                         } );
100                         this._refresh();
101                 }
102         } ); /* End of widget */
103
104         // auto self-init widgets
105         $( document ).bind( "pagecreate", function ( e ) {
106                 $( e.target ).find( ":jqmData(role='progress')" ).progress();
107         } );
108 }(jQuery, this));