Skip to content

Commit

Permalink
Remove global deck interaction methods
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish committed Jun 22, 2014
1 parent 1f77bc5 commit 641308a
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 265 deletions.
154 changes: 69 additions & 85 deletions dist/bespoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,97 +7,81 @@
*/

!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.bespoke=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
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
};

},{}]},{},[1])
Expand Down
2 changes: 1 addition & 1 deletion dist/bespoke.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

154 changes: 69 additions & 85 deletions lib/bespoke.js
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
};
Loading

0 comments on commit 641308a

Please sign in to comment.