From 0b8fe0ac0b81ac61e79772d29eea8d97a00e24d5 Mon Sep 17 00:00:00 2001 From: DanielApt Date: Mon, 28 Sep 2015 11:08:59 +0100 Subject: [PATCH] Dispatch events when reaching start / end of axes --- src/js/plugin/update-scroll.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/js/plugin/update-scroll.js b/src/js/plugin/update-scroll.js index 02e7455..90a4177 100644 --- a/src/js/plugin/update-scroll.js +++ b/src/js/plugin/update-scroll.js @@ -11,6 +11,10 @@ var upEvent = document.createEvent('Event') , rightEvent = document.createEvent('Event') , yEvent = document.createEvent('Event') , xEvent = document.createEvent('Event') + , xStartEvent = document.createEvent('Event') + , xEndEvent = document.createEvent('Event') + , yStartEvent = document.createEvent('Event') + , yEndEvent = document.createEvent('Event') , lastTop , lastLeft; @@ -20,6 +24,10 @@ leftEvent.initEvent('ps-scroll-left', true, true); rightEvent.initEvent('ps-scroll-right', true, true); yEvent.initEvent('ps-scroll-y', true, true); xEvent.initEvent('ps-scroll-x', true, true); +xStartEvent.initEvent('ps-x-reach-start', true, true); +xEndEvent.initEvent('ps-x-reach-end', true, true); +yStartEvent.initEvent('ps-y-reach-start', true, true); +yEndEvent.initEvent('ps-y-reach-end', true, true); module.exports = function (element, axis, value) { if (typeof element === 'undefined' ) { @@ -34,17 +42,25 @@ module.exports = function (element, axis, value) { throw 'You must provide a value to the update-scroll function' } - if (value < 0) { + if (axis === 'top' && value <= 0) { + element.dispatchEvent(yStartEvent); + return; // don't allow negative scroll + } + + if (axis === 'left' && value <= 0) { + element.dispatchEvent(xStartEvent); return; // don't allow negative scroll } var i = instances.get(element); if (axis === 'top' && value > i.contentHeight - i.containerHeight) { + element.dispatchEvent(yEndEvent); return; // don't allow scroll past container } if (axis === 'left' && value > i.contentWidth - i.containerWidth) { + element.dispatchEvent(xEndEvent); return; // don't allow scroll past container }