assets/javascripts/semantic_ui/definitions/behaviors/visibility.js in less-rails-semantic_ui-1.2.0.0 vs assets/javascripts/semantic_ui/definitions/behaviors/visibility.js in less-rails-semantic_ui-1.3.1.0

- old
+ new

@@ -60,21 +60,22 @@ initialize: function() { module.verbose('Initializing visibility', settings); module.setup.cache(); module.save.position(); - module.bindEvents(); - module.instantiate(); - if(settings.type == 'image') { - module.setup.image(); + if( module.should.trackChanges() ) { + module.bindEvents(); + if(settings.type == 'image') { + module.setup.image(); + } + if(settings.type == 'fixed') { + module.setup.fixed(); + } } - if(settings.type == 'fixed') { - module.setup.fixed(); - } - - requestAnimationFrame(module.checkVisibility); + module.checkVisibility(); + module.instantiate(); }, instantiate: function() { module.verbose('Storing instance of module', module); instance = module; @@ -142,10 +143,23 @@ cacheImage.src = images[imagesLength]; cache.push(cacheImage); } }, + should: { + + trackChanges: function() { + if(methodInvoked && queryArguments.length > 0) { + module.debug('One time query, no need to bind events'); + return false; + } + module.debug('Query is attaching callbacks, watching for changes with scroll'); + return true; + } + + }, + setup: { cache: function() { module.cache = { occurred : {}, screen : {}, @@ -206,11 +220,11 @@ ; $module .attr('src', src) ; if(offScreen) { - module.verbose('Image outside browser, avoiding animation') + module.verbose('Image outside browser, no show animation'); $module.show(); } else { if(settings.transition && $.fn.transition !== undefined) { $module.transition(settings.transition, settings.duration); @@ -238,14 +252,11 @@ } }, checkVisibility: function() { module.verbose('Checking visibility of element', module.cache.element); - module.save.scroll(); - module.save.direction(); - module.save.screenCalculations(); - module.save.elementCalculations(); + module.save.calculations(); // percentage module.passed(); // reverse (must be first) @@ -366,11 +377,11 @@ } else if(!settings.once) { module.remove.occurred(callbackName); } if(newCallback === undefined) { - return calculations.onTopPassed; + return calculations.topPassed; } }, bottomPassed: function(newCallback) { var @@ -541,10 +552,17 @@ } } }, save: { + calculations: function() { + module.verbose('Saving all calculations necessary to determine positioning'); + module.save.scroll(); + module.save.direction(); + module.save.screenCalculations(); + module.save.elementCalculations(); + }, occurred: function(callback) { if(callback) { if(module.cache.occurred[callback] === undefined || (module.cache.occurred[callback] !== true)) { module.verbose('Saving callback occurred', callback); module.cache.occurred[callback] = true; @@ -844,10 +862,11 @@ else if( object[value] !== undefined ) { found = object[value]; return false; } else { + module.error(error.method, query); return false; } }); } if ( $.isFunction( found ) ) { @@ -912,11 +931,11 @@ throttle : false, // special visibility type (image, fixed) type : false, - // image only settings + // image only animation settings transition : false, duration : 500, // array of callbacks for percentage onPassed : {}, @@ -941,10 +960,10 @@ // utility callbacks onRefresh : function(){}, onScroll : function(){}, error : { - method : 'The method you called is not defined.' + method : 'The method you called is not defined.' } }; })( jQuery, window , document );