app/assets/javascripts/plugins/loading.js in sports_db-0.2 vs app/assets/javascripts/plugins/loading.js in sports_db-0.2.1
- old
+ new
@@ -1,47 +1,48 @@
-(function($){
+;(function($){
var load_timer;
var LOADING_TEXT = 'Loading…';
- function prevent(e) {
- e.preventDefault();
- }
- function freeze() {
- $(document.body).bind("touchmove", prevent);
- }
- function thaw() {
- $(document.body).unbind('touchmove', prevent);
- }
- function showLoaderNow() {
- $('#app_load_loader').remove();
- freeze();
- loading_text = LOADING_TEXT;
- if (Application.currentView && Application.currentView.params.loading_text) {
- loading_text = Application.currentView.params.loading_text;
- }
- $('#loading_text').html(loading_text);
+ var $loading = $('#loading');
+ var v = parseFloat($.os.version);
+ var deviceHasNativeSupport = ($.os.ios && v >= 5) || ($.os.android && v >= 2.2);
- $('#loading').css({'height': document.documentElement.clientHeight + 'px'});
- $.alignLoader();
-
- $('#loading').show();
+ function alignLoader() {
+ if (!deviceHasNativeSupport && $loading.css('display') === 'block') {
+ $loading
+ .css('position', 'absolute')
+ .find('.loading_text')
+ .css('margin-top', (window.pageYOffset + 80) + 'px');
+ }
}
- $.alignLoader = function() {
- $('#loading').css({'top': window.scrollY + 'px'});
- };
- $.showLoader = function(loader_text) {
+ $.showLoader = function() {
if (load_timer) {
- load_timer.stop();
- load_timer = undefined;
+ window.clearTimeout(load_timer);
}
- load_timer = new Timer(showLoaderNow, 222);
- load_timer.start();
+ load_timer = setTimeout(function() {
+ var txt = LOADING_TEXT;
+ if (Application.currentView && Application.currentView.params.loading_text) {
+ txt = Application.currentView.params.loading_text;
+ }
+ $('#loading_text').html(txt);
+ $loading
+ .freeze()
+ .show();
+ alignLoader();
+ }, 333);
};
$.hideLoader = function() {
- load_timer.stop();
- thaw();
- $('#loading').hide();
- $('#app_load_loader').remove();
- if (Application.currentView && Application.currentView.params.loading_text) {
- Application.currentView.params.loading_text = LOADING_TEXT;
+ if (load_timer) {
+ window.clearTimeout(load_timer);
}
+
+ $loading
+ .freeze({'unfreeze':true})
+ .hide();
+
+ $('#app_load_loader').remove();
+
+ Application.currentView.params.loading_text = LOADING_TEXT;
};
+
+ $(window).on('scroll', alignLoader);
+
})(Zepto);