[TemporaryStorage] add files required for SDK build
[samples/web/TemporaryStorage.git] / tizen-web-ui-fw / latest / js / src / widgets / loader.js
1
2 (function( $, window ) {
3         // DEPRECATED
4         // NOTE global mobile object settings
5         $.extend( $.mobile, {
6                 // DEPRECATED Should the text be visble in the loading message?
7                 loadingMessageTextVisible: undefined,
8
9                 // DEPRECATED When the text is visible, what theme does the loading box use?
10                 loadingMessageTheme: undefined,
11
12                 // DEPRECATED default message setting
13                 loadingMessage: undefined,
14
15                 // DEPRECATED
16                 // Turn on/off page loading message. Theme doubles as an object argument
17                 // with the following shape: { theme: '', text: '', html: '', textVisible: '' }
18                 // NOTE that the $.mobile.loading* settings and params past the first are deprecated
19                 showPageLoadingMsg: function( theme, msgText, textonly ) {
20                         $.mobile.loading( 'show', theme, msgText, textonly );
21                 },
22
23                 // DEPRECATED
24                 hidePageLoadingMsg: function() {
25                         $.mobile.loading( 'hide' );
26                 },
27
28                 loading: function() {
29                         this.loaderWidget.loader.apply( this.loaderWidget, arguments );
30                 }
31         });
32
33         // TODO move loader class down into the widget settings
34         var loaderClass = "ui-loader", $html = $( "html" ), $window = $.mobile.$window;
35
36         $.widget( "mobile.loader", {
37                 // NOTE if the global config settings are defined they will override these
38                 //      options
39                 options: {
40                         // the theme for the loading message
41                         theme: "a",
42
43                         // whether the text in the loading message is shown
44                         textVisible: false,
45
46                         // custom html for the inner content of the loading message
47                         html: "",
48
49                         // the text to be displayed when the popup is shown
50                         text: "loading"
51                 },
52
53                 defaultHtml: "<div class='" + loaderClass + "'>" +
54                         "<span class='ui-icon ui-icon-loading'></span>" +
55                         "<h1></h1>" +
56                         "</div>",
57
58                 // For non-fixed supportin browsers. Position at y center (if scrollTop supported), above the activeBtn (if defined), or just 100px from top
59                 fakeFixLoader: function() {
60                         var activeBtn = $( "." + $.mobile.activeBtnClass ).first();
61
62                         this.element
63                                 .css({
64                                         top: $.support.scrollTop && $window.scrollTop() + $window.height() / 2 ||
65                                                 activeBtn.length && activeBtn.offset().top || 100
66                                 });
67                 },
68
69                 // check position of loader to see if it appears to be "fixed" to center
70                 // if not, use abs positioning
71                 checkLoaderPosition: function() {
72                         var offset = this.element.offset(),
73                                 scrollTop = $window.scrollTop(),
74                                 screenHeight = $.mobile.getScreenHeight();
75
76                         if ( offset.top < scrollTop || ( offset.top - scrollTop ) > screenHeight ) {
77                                 this.element.addClass( "ui-loader-fakefix" );
78                                 this.fakeFixLoader();
79                                 $window
80                                         .unbind( "scroll", this.checkLoaderPosition )
81                                         .bind( "scroll", this.fakeFixLoader );
82                         }
83                 },
84
85                 resetHtml: function() {
86                         this.element.html( $( this.defaultHtml ).html() );
87                 },
88
89                 // Turn on/off page loading message. Theme doubles as an object argument
90                 // with the following shape: { theme: '', text: '', html: '', textVisible: '' }
91                 // NOTE that the $.mobile.loading* settings and params past the first are deprecated
92                 // TODO sweet jesus we need to break some of this out
93                 show: function( theme, msgText, textonly ) {
94                         var textVisible, message, $header, loadSettings;
95
96                         this.resetHtml();
97
98                         // use the prototype options so that people can set them globally at
99                         // mobile init. Consistency, it's what's for dinner
100                         if ( $.type(theme) === "object" ) {
101                                 loadSettings = $.extend( {}, this.options, theme );
102
103                                 // prefer object property from the param then the old theme setting
104                                 theme = loadSettings.theme || $.mobile.loadingMessageTheme;
105                         } else {
106                                 loadSettings = this.options;
107
108                                 // here we prefer the them value passed as a string argument, then
109                                 // we prefer the global option because we can't use undefined default
110                                 // prototype options, then the prototype option
111                                 theme = theme || $.mobile.loadingMessageTheme || loadSettings.theme;
112                         }
113
114                         // set the message text, prefer the param, then the settings object
115                         // then loading message
116                         message = msgText || $.mobile.loadingMessage || loadSettings.text;
117
118                         // prepare the dom
119                         $html.addClass( "ui-loading" );
120
121                         if ( $.mobile.loadingMessage !== false || loadSettings.html ) {
122                                 // boolean values require a bit more work :P, supports object properties
123                                 // and old settings
124                                 if ( $.mobile.loadingMessageTextVisible !== undefined ) {
125                                         textVisible = $.mobile.loadingMessageTextVisible;
126                                 } else {
127                                         textVisible = loadSettings.textVisible;
128                                 }
129
130                                 // add the proper css given the options (theme, text, etc)
131                                 // Force text visibility if the second argument was supplied, or
132                                 // if the text was explicitly set in the object args
133                                 this.element.attr("class", loaderClass +
134                                         " ui-corner-all ui-body-" + theme +
135                                         " ui-loader-" + ( textVisible || msgText || theme.text ? "verbose" : "default" ) +
136                                         ( loadSettings.textonly || textonly ? " ui-loader-textonly" : "" ) );
137
138                                 // TODO verify that jquery.fn.html is ok to use in both cases here
139                                 //      this might be overly defensive in preventing unknowing xss
140                                 // if the html attribute is defined on the loading settings, use that
141                                 // otherwise use the fallbacks from above
142                                 if ( loadSettings.html ) {
143                                         this.element.html( loadSettings.html );
144                                 } else {
145                                         this.element.find( "h1" ).text( message );
146                                 }
147
148                                 // attach the loader to the DOM
149                                 this.element.appendTo( $.mobile.pageContainer );
150
151                                 // check that the loader is visible
152                                 this.checkLoaderPosition();
153
154                                 // on scroll check the loader position
155                                 $window.bind( "scroll", $.proxy( this.checkLoaderPosition, this ) );
156                         }
157                 },
158
159                 hide: function() {
160                         $html.removeClass( "ui-loading" );
161
162                         if ( $.mobile.loadingMessage ) {
163                                 this.element.removeClass( "ui-loader-fakefix" );
164                         }
165
166                         $.mobile.$window.unbind( "scroll", $.proxy( this.fakeFixLoader, this) );
167                         $.mobile.$window.unbind( "scroll", $.proxy( this.checkLoaderPosition, this ) );
168                 }
169         });
170
171         $window.bind( 'pagecontainercreate', function() {
172                 $.mobile.loaderWidget = $.mobile.loaderWidget || $( $.mobile.loader.prototype.defaultHtml ).loader();
173         });
174 })(jQuery, this);
175