Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable user to provide own loading screen #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ There are a few optional parameters you can pass on initialization:
// Number of pixels of dragging down until refresh will fire
distanceToRefresh: 70,

// Callback to toggle loading message
toggleLoadingMsgFunction: false,

// The dragging resistance level, the higher the more you'll need to drag down.
resistance: 2.5
}
Expand Down
30 changes: 21 additions & 9 deletions lib/wptr.1.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ var WebPullToRefresh = (function () {
// Pointer to function that does the loading and returns a promise
loadingFunction: false,

// Pointer to function that toggles loading message
toggleLoadingMsgFunction: false,

// Dragging resistance level
resistance: 2.5
};
Expand Down Expand Up @@ -55,6 +58,7 @@ var WebPullToRefresh = (function () {
ptrEl: params.ptrEl || document.getElementById( defaults.ptrEl ),
distanceToRefresh: params.distanceToRefresh || defaults.distanceToRefresh,
loadingFunction: params.loadingFunction || defaults.loadingFunction,
toggleLoadingMsgFunction: params.toggleLoadingMsgFunction || defaults.toggleLoadingMsgFunction,
resistance: params.resistance || defaults.resistance
};

Expand Down Expand Up @@ -173,7 +177,11 @@ var WebPullToRefresh = (function () {
* Position content and refresh elements to show that loading is taking place.
*/
var _doLoading = function() {
bodyClass.add( 'ptr-loading' );
if ( typeof(options.toggleLoadingMsgFunction) === typeof(Function) ) {
options.toggleLoadingMsgFunction();
} else {
bodyClass.add( 'ptr-loading' );
}

// If no valid loading function exists, just reset elements
if ( ! options.loadingFunction ) {
Expand All @@ -194,16 +202,20 @@ var WebPullToRefresh = (function () {
* Reset all elements to their starting positions before any paning took place.
*/
var _doReset = function() {
bodyClass.remove( 'ptr-loading' );
bodyClass.remove( 'ptr-refresh' );
bodyClass.add( 'ptr-reset' );
if ( typeof(options.toggleLoadingMsgFunction) === typeof(Function) ) {
options.toggleLoadingMsgFunction();
} else {
bodyClass.remove( 'ptr-loading' );
bodyClass.remove( 'ptr-refresh' );
bodyClass.add( 'ptr-reset' );

var bodyClassRemove = function() {
bodyClass.remove( 'ptr-reset' );
document.body.removeEventListener( 'transitionend', bodyClassRemove, false );
};
var bodyClassRemove = function() {
bodyClass.remove( 'ptr-reset' );
document.body.removeEventListener( 'transitionend', bodyClassRemove, false );
};

document.body.addEventListener( 'transitionend', bodyClassRemove, false );
document.body.addEventListener( 'transitionend', bodyClassRemove, false );
}
};

return {
Expand Down