forked from bespokejs/bespoke
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove global deck interaction methods
- Loading branch information
1 parent
1f77bc5
commit 641308a
Showing
4 changed files
with
139 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,76 @@ | ||
var decks = [], | ||
|
||
from = function(selectorOrElement, plugins) { | ||
var parent = selectorOrElement.nodeType === 1 ? selectorOrElement : document.querySelector(selectorOrElement), | ||
slides = [].filter.call(parent.children, function(el) { return el.nodeName !== 'SCRIPT'; }), | ||
activeSlide = slides[0], | ||
listeners = {}, | ||
|
||
activate = function(index, customData) { | ||
if (!slides[index]) { | ||
return; | ||
} | ||
|
||
fire('deactivate', createEventData(activeSlide, customData)); | ||
activeSlide = slides[index]; | ||
fire('activate', createEventData(activeSlide, customData)); | ||
}, | ||
|
||
slide = function(index, customData) { | ||
if (arguments.length) { | ||
fire('slide', createEventData(slides[index], customData)) && activate(index, customData); | ||
} else { | ||
return slides.indexOf(activeSlide); | ||
} | ||
}, | ||
|
||
step = function(offset, customData) { | ||
var slideIndex = slides.indexOf(activeSlide) + offset; | ||
|
||
fire(offset > 0 ? 'next' : 'prev', createEventData(activeSlide, customData)) && activate(slideIndex, customData); | ||
}, | ||
|
||
on = function(eventName, callback) { | ||
(listeners[eventName] || (listeners[eventName] = [])).push(callback); | ||
|
||
return function() { | ||
listeners[eventName] = listeners[eventName].filter(function(listener) { | ||
return listener !== callback; | ||
}); | ||
}; | ||
}, | ||
|
||
fire = function(eventName, eventData) { | ||
return (listeners[eventName] || []) | ||
.reduce(function(notCancelled, callback) { | ||
return notCancelled && callback(eventData) !== false; | ||
}, true); | ||
}, | ||
|
||
createEventData = function(el, eventData) { | ||
eventData = eventData || {}; | ||
eventData.index = slides.indexOf(el); | ||
eventData.slide = el; | ||
return eventData; | ||
}, | ||
|
||
deck = { | ||
on: on, | ||
fire: fire, | ||
slide: slide, | ||
next: step.bind(null, 1), | ||
prev: step.bind(null, -1), | ||
parent: parent, | ||
slides: slides | ||
var from = function(selectorOrElement, plugins) { | ||
var parent = selectorOrElement.nodeType === 1 ? selectorOrElement : document.querySelector(selectorOrElement), | ||
slides = [].filter.call(parent.children, function(el) { return el.nodeName !== 'SCRIPT'; }), | ||
activeSlide = slides[0], | ||
listeners = {}, | ||
|
||
activate = function(index, customData) { | ||
if (!slides[index]) { | ||
return; | ||
} | ||
|
||
fire('deactivate', createEventData(activeSlide, customData)); | ||
activeSlide = slides[index]; | ||
fire('activate', createEventData(activeSlide, customData)); | ||
}, | ||
|
||
slide = function(index, customData) { | ||
if (arguments.length) { | ||
fire('slide', createEventData(slides[index], customData)) && activate(index, customData); | ||
} else { | ||
return slides.indexOf(activeSlide); | ||
} | ||
}, | ||
|
||
step = function(offset, customData) { | ||
var slideIndex = slides.indexOf(activeSlide) + offset; | ||
|
||
fire(offset > 0 ? 'next' : 'prev', createEventData(activeSlide, customData)) && activate(slideIndex, customData); | ||
}, | ||
|
||
on = function(eventName, callback) { | ||
(listeners[eventName] || (listeners[eventName] = [])).push(callback); | ||
|
||
return function() { | ||
listeners[eventName] = listeners[eventName].filter(function(listener) { | ||
return listener !== callback; | ||
}); | ||
}; | ||
}, | ||
|
||
fire = function(eventName, eventData) { | ||
return (listeners[eventName] || []) | ||
.reduce(function(notCancelled, callback) { | ||
return notCancelled && callback(eventData) !== false; | ||
}, true); | ||
}, | ||
|
||
createEventData = function(el, eventData) { | ||
eventData = eventData || {}; | ||
eventData.index = slides.indexOf(el); | ||
eventData.slide = el; | ||
return eventData; | ||
}, | ||
|
||
deck = { | ||
on: on, | ||
fire: fire, | ||
slide: slide, | ||
next: step.bind(null, 1), | ||
prev: step.bind(null, -1), | ||
parent: parent, | ||
slides: slides | ||
}; | ||
|
||
(plugins || []).forEach(function(plugin) { | ||
plugin(deck); | ||
}); | ||
|
||
activate(0); | ||
|
||
decks.push(deck); | ||
(plugins || []).forEach(function(plugin) { | ||
plugin(deck); | ||
}); | ||
|
||
return deck; | ||
}, | ||
activate(0); | ||
|
||
callOnAllDecks = function(method) { | ||
return function() { | ||
var args = arguments; | ||
decks.map(function(deck) { | ||
deck[method].apply(null, args); | ||
}); | ||
}; | ||
}; | ||
return deck; | ||
}; | ||
|
||
module.exports = { | ||
from: from, | ||
slide: callOnAllDecks('slide'), | ||
next: callOnAllDecks('next'), | ||
prev: callOnAllDecks('prev') | ||
from: from | ||
}; |
Oops, something went wrong.