Skip to content

Commit

Permalink
Added event listener
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Feb 18, 2015
1 parent 7cd2fe0 commit 0cbf859
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 32 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ Recalc height of all decks. Need to update when content added
- `anchor` - `#id` of deck, `up` or `down`
- `noAnimation` - prevents animation

###skrollr.decks.on(event, callback)

- `change(activeElement)` - calls when active deck is changed
- `render(e)` - skrollr render event

##License

[The MIT License (MIT)](LICENSE)
Expand Down
53 changes: 38 additions & 15 deletions dist/skrollr.decks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* skrollr-decks 1.0.0
* skrollr-decks 1.0.1
* Fullpage presentation decks with scrolling
* https://github.com/TrySound/skrollr-decks
*
Expand All @@ -26,8 +26,10 @@
duration: 600,
easing: 'quadratic',
delay: 500,
autoscroll: true,
onRender: null
autoscroll: true
}, callbacks = {
render: null,
change: null
};


Expand All @@ -38,7 +40,8 @@
settings = {},
segments = {},
segmentsList = [],
nav = document.createElement('ul');
nav = document.createElement('ul'),
currentDeck;


// Stop animating on scroll keys
Expand Down Expand Up @@ -71,10 +74,21 @@
return {
init: init,
animateTo: animateTo,
refresh: resizeDecks
refresh: resizeDecks,
on: on
};


function on(name, cb) {
if(name in callbacks) {
callbacks[name] = cb;
}
}

function trigger(name, data) {
var fn = callbacks[name];
typeof fn === 'function' && fn.apply({}, data);
}


// Initialize
Expand All @@ -92,6 +106,9 @@
settings[key] = user[key] || defaults[key];
}

var onRender = settings.onRender,
onChange = settings.onChange,

inst = skrollr.init({
forceHeight: false
});
Expand All @@ -105,15 +122,17 @@

inst.refresh(nav.children);

if(settings.autoscroll) {
window.addEventListener('resize', update, false);
inst.on('render', function (e) {
clearTimeout(renderTimer);
renderTimer = setTimeout(function () {
update(e);
}, settings.delay);
});
}
window.addEventListener('resize', update, false);
inst.on('render', function (e) {
var el = update(e);

clearTimeout(renderTimer);
renderTimer = setTimeout(function () {
settings.autoscroll && el && inst.animateTo(inst.relativeToAbsolute(el, 'top', 'top') + 1, settings);
}, settings.delay);

trigger('render', [e]);
});
}


Expand Down Expand Up @@ -184,7 +203,11 @@
if( ! isVol(el)) {
el = segments[active[after].getAttribute('data-anchor-target')];
}
inst.animateTo(inst.relativeToAbsolute(el, 'top', 'top') + 1, settings);

currentDeck !== el && trigger('change', [el])
currentDeck = el;

return el;
}
}

Expand Down
4 changes: 2 additions & 2 deletions dist/skrollr.decks.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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "skrollr-decks",
"version": "1.0.0",
"version": "1.0.1",
"description": "Fullpage presentation decks with scrolling",
"main": "gulpfile.js",
"scripts": {
Expand Down
51 changes: 37 additions & 14 deletions src/skrollr.decks.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
duration: 600,
easing: 'quadratic',
delay: 500,
autoscroll: true,
onRender: null
autoscroll: true
}, callbacks = {
render: null,
change: null
};


Expand All @@ -29,7 +31,8 @@
settings = {},
segments = {},
segmentsList = [],
nav = document.createElement('ul');
nav = document.createElement('ul'),
currentDeck;


// Stop animating on scroll keys
Expand Down Expand Up @@ -62,10 +65,21 @@
return {
init: init,
animateTo: animateTo,
refresh: resizeDecks
refresh: resizeDecks,
on: on
};


function on(name, cb) {
if(name in callbacks) {
callbacks[name] = cb;
}
}

function trigger(name, data) {
var fn = callbacks[name];
typeof fn === 'function' && fn.apply({}, data);
}


// Initialize
Expand All @@ -83,6 +97,9 @@
settings[key] = user[key] || defaults[key];
}

var onRender = settings.onRender,
onChange = settings.onChange,

inst = skrollr.init({
forceHeight: false
});
Expand All @@ -96,15 +113,17 @@

inst.refresh(nav.children);

if(settings.autoscroll) {
window.addEventListener('resize', update, false);
inst.on('render', function (e) {
clearTimeout(renderTimer);
renderTimer = setTimeout(function () {
update(e);
}, settings.delay);
});
}
window.addEventListener('resize', update, false);
inst.on('render', function (e) {
var el = update(e);

clearTimeout(renderTimer);
renderTimer = setTimeout(function () {
settings.autoscroll && el && inst.animateTo(inst.relativeToAbsolute(el, 'top', 'top') + 1, settings);
}, settings.delay);

trigger('render', [e]);
});
}


Expand Down Expand Up @@ -175,7 +194,11 @@
if( ! isVol(el)) {
el = segments[active[after].getAttribute('data-anchor-target')];
}
inst.animateTo(inst.relativeToAbsolute(el, 'top', 'top') + 1, settings);

currentDeck !== el && trigger('change', [el])
currentDeck = el;

return el;
}
}

Expand Down

0 comments on commit 0cbf859

Please sign in to comment.