Skip to content
This repository was archived by the owner on Nov 15, 2017. It is now read-only.
Open
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
73 changes: 55 additions & 18 deletions source/class/core/ui/Scroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@
/** {Integer} Height to assign to refresh area */
__refreshHeight: null,

/** {Boolean} Whether the refresh process is enabled when the event is released now */
__refreshActive: false,
/** {String} Direction of refresh process that is enabled when the event is released now */
__refreshActive: null,

/** {Function} Callback to execute on activation. This is for signalling the user about a refresh is about to happen when he release */
__refreshActivate: null,
Expand Down Expand Up @@ -271,7 +271,7 @@
self.__computeScrollMax();

// Refresh scroll position
self.scrollTo(self.__scrollLeft, self.__scrollTop, true);
self.scrollTo(self.__scrollLeft, self.__scrollTop, null, null, false);

},

Expand Down Expand Up @@ -329,6 +329,25 @@

},


/**
* Programmatically executes pull to refresh action
* @location {String} executes pull to refresh on "top" or "bottom" of scroller
*/
executePullToRefresh : function(location) {
var self = this;
self.__refreshActive = location;

// Use publish instead of scrollTo to allow scrolling to out of boundary position
// We don't need to normalize scrollLeft, zoomLevel, etc. here because we only y-scrolling when pull-to-refresh is enabled
var posY = (self.__refreshActive=="top") ? (-self.__refreshHeight) : (self.__maxScrollTop+self.__refreshHeight);
self.__publish(self.__scrollLeft, posY , self.__zoomLevel, true);

if (self.__refreshStart) {
self.__refreshStart(self.__refreshActive);
}
},


/**
* Signalizes that pull-to-refresh is finished.
Expand All @@ -337,10 +356,10 @@

var self = this;

self.__refreshActive = false;
if (self.__refreshDeactivate) {
self.__refreshDeactivate();
self.__refreshDeactivate(self.__refreshActive);
}
self.__refreshActive = null;

self.scrollTo(self.__scrollLeft, self.__scrollTop, true);

Expand Down Expand Up @@ -470,8 +489,9 @@
* @param top {Number?null} Vertical scroll position, keeps current if value is <code>null</code>
* @param animate {Boolean?false} Whether the scrolling should happen using an animation
* @param zoom {Number?null} Zoom level to go to
* @param fireEvents {Boolean?true} Whether events should be muted (if parameter is false)
*/
scrollTo: function(left, top, animate, zoom) {
scrollTo: function(left, top, animate, zoom, fireEvents) {

var self = this;

Expand Down Expand Up @@ -540,7 +560,7 @@
}

// Publish new values
self.__publish(left, top, zoom, animate);
self.__publish(left, top, zoom, animate, fireEvents);

},

Expand Down Expand Up @@ -785,18 +805,25 @@
if (!self.__enableScrollX && self.__refreshHeight != null) {

if (!self.__refreshActive && scrollTop <= -self.__refreshHeight) {

self.__refreshActive = true;
self.__refreshActive = "top";
if (self.__refreshActivate) {
self.__refreshActivate();
self.__refreshActivate("top");
}

} else if (self.__refreshActive && scrollTop > -self.__refreshHeight) {
} else if (!self.__refreshActive && scrollTop >= (maxScrollTop + self.__refreshHeight)) {

self.__refreshActive = "bottom";
if (self.__refreshActivate) {
self.__refreshActivate("bottom");
}

self.__refreshActive = false;
} else if (self.__refreshActive && scrollTop > -self.__refreshHeight && scrollTop < (maxScrollTop + self.__refreshHeight)) {

if (self.__refreshDeactivate) {
self.__refreshDeactivate();
self.__refreshDeactivate(self.__refreshActive);
}
self.__refreshActive = null;

}
}
Expand Down Expand Up @@ -942,20 +969,23 @@
self.__publish(self.__scrollLeft, -self.__refreshHeight, self.__zoomLevel, true);

if (self.__refreshStart) {
self.__refreshStart();
self.__refreshStart(self.__refreshActive);
}

} else {

self.scrollTo(self.__scrollLeft, self.__scrollTop, true, self.__zoomLevel);
if (self.__callback) {
self.__callback(self.__scrollLeft, self.__scrollTop, self.__zoomLevel, "stop");
}

// Directly signalize deactivation (nothing todo on refresh?)
if (self.__refreshActive) {

self.__refreshActive = false;
if (self.__refreshDeactivate) {
self.__refreshDeactivate();
self.__refreshDeactivate(self.__refreshActive);
}
self.__refreshActive = null;

}
}
Expand All @@ -980,8 +1010,9 @@
* @param left {Number} Left scroll position
* @param top {Number} Top scroll position
* @param animate {Boolean?false} Whether animation should be used to move to the new coordinates
* @param fireEvents {Boolean?true} Whether events should be muted (if parameter is false)
*/
__publish: function(left, top, zoom, animate) {
__publish: function(left, top, zoom, animate, fireEvents) {

var self = this;

Expand Down Expand Up @@ -1035,6 +1066,9 @@
if (self.options.zooming) {
self.__computeScrollMax();
}
if (self.__callback) {
self.__callback(self.__scrollLeft, self.__scrollTop, self.__zoomLevel, "stop_animation");
}
};

// When continuing based on previous animation we choose an ease-out animation instead of ease-in-out
Expand All @@ -1048,7 +1082,7 @@

// Push values out
if (self.__callback) {
self.__callback(left, top, zoom);
self.__callback(left, top, zoom, (fireEvents===false)?"cleanup":null);
}

// Fix max scroll ranges
Expand Down Expand Up @@ -1127,6 +1161,9 @@
{
// Animate to grid when snapping is active, otherwise just fix out-of-boundary positions
self.scrollTo(self.__scrollLeft, self.__scrollTop, self.options.snapping);
if (self.__callback) {
self.__callback(self.__scrollLeft, self.__scrollTop, self.__zoomLevel, "stop_deceleration");
}
}
};

Expand Down