Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"doneLoadingEvent": true,
"loadTriggerEvents": true,
"requestErrorCode": true,
"parseResultErrorCode": true
"parseResultErrorCode": true,
"ignoreEvent": true
}
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [2.0.3] - 2018-03-27
### Fixed
- \#5: Fixed an issue that caused the plugin to possibly send an unnecessary request if the `$.mobile.hideUrlBar` JQM setting was set to `true`.
- Fixed incorrect url to the plugin within the `sample.html`.

## [2.0.2] - 2018-03-09
### Fixed
- \#3: Corrected an issue that caused the plugin not to load items on initialization if the `filter` option was set to `true`
Expand Down
25 changes: 21 additions & 4 deletions dist/jquery.mobile.lazyloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ var $window = $( window ),
* The error code that is provided in the event when parsing of a response fails
* @type {number}
*/
parseResultErrorCode = 2;
parseResultErrorCode = 2,

/**
* Indicates the event should be ignored. The value is determined by $.mobile.hideUrlBar and when
* it is true a programmatic scroll is done.
* @type {boolean}
*/
ignoreEvent = $.mobile.hideUrlBar;

// Source: src/filterable.js
var filterableWidget = $.mobile.filterable,
Expand Down Expand Up @@ -103,6 +110,15 @@ if ( filterableWidget ) {
}

// Source: src/lazyloader.js
// Check if the first scroll event should be ignored
if ( ignoreEvent ) {

// It should be ignored so listen to the first scroll event to toggle the boolean
$window.one( "scrollstart", function() {
ignoreEvent = false;
} );
}

$.widget( "mobile." + widgetName, $.mobile.listview, {
options: {

Expand Down Expand Up @@ -256,7 +272,7 @@ $.widget( "mobile." + widgetName, $.mobile.listview, {

// Check if the page scroll location is close to the bottom
if ( self.element.height() - options.threshold <=
$window.scrollTop() + $window.height() ) {
$window.scrollTop() + $window.height() ) {

// Get the progress element
$( options.$progress ).show();
Expand Down Expand Up @@ -405,8 +421,9 @@ $.widget( "mobile." + widgetName, $.mobile.listview, {
_handleEvent: function() {
var self = this;

// Check if the listview is visible and an event has not triggered a load already
if ( !self._eventTriggered && self.element.is( ":visible" ) ) {
// Check if the listview is visible and an event has not triggered a load already or if it
// should be ignored
if ( !self._eventTriggered && !ignoreEvent && self.element.is( ":visible" ) ) {

// Block other events from triggering a load
self._eventTriggered = true;
Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.mobile.lazyloader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion samples/sample.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script src="http://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ICanHaz.js/0.10.3/ICanHaz.min.js"></script>
<script src="../dist/jquery.mobile.lazyloader-2.0.0.js"></script>
<script src="../dist/jquery.mobile.lazyloader.js"></script>
<script src="sample.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script id="user" type="text/html">
Expand Down
9 changes: 8 additions & 1 deletion src/_vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,11 @@ var $window = $( window ),
* The error code that is provided in the event when parsing of a response fails
* @type {number}
*/
parseResultErrorCode = 2;
parseResultErrorCode = 2,

/**
* Indicates the event should be ignored. The value is determined by $.mobile.hideUrlBar and when
* it is true a programmatic scroll is done.
* @type {boolean}
*/
ignoreEvent = $.mobile.hideUrlBar;
16 changes: 13 additions & 3 deletions src/lazyloader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
"use strict";

// Check if the first scroll event should be ignored
if ( ignoreEvent ) {

// It should be ignored so listen to the first scroll event to toggle the boolean
$window.one( "scrollstart", function() {
ignoreEvent = false;
} );
}

$.widget( "mobile." + widgetName, $.mobile.listview, {
options: {

Expand Down Expand Up @@ -153,7 +162,7 @@ $.widget( "mobile." + widgetName, $.mobile.listview, {

// Check if the page scroll location is close to the bottom
if ( self.element.height() - options.threshold <=
$window.scrollTop() + $window.height() ) {
$window.scrollTop() + $window.height() ) {

// Get the progress element
$( options.$progress ).show();
Expand Down Expand Up @@ -302,8 +311,9 @@ $.widget( "mobile." + widgetName, $.mobile.listview, {
_handleEvent: function() {
var self = this;

// Check if the listview is visible and an event has not triggered a load already
if ( !self._eventTriggered && self.element.is( ":visible" ) ) {
// Check if the listview is visible and an event has not triggered a load already or if it
// should be ignored
if ( !self._eventTriggered && !ignoreEvent && self.element.is( ":visible" ) ) {

// Block other events from triggering a load
self._eventTriggered = true;
Expand Down
Loading