mirror of
https://github.com/wahyd4/cdnjs.git
synced 2026-08-09 04:46:00 +10:00
Updated bespoke to 0.3.1
This commit is contained in:
@@ -0,0 +1,187 @@
|
||||
/*!
|
||||
* Bespoke.js v0.3.1
|
||||
*
|
||||
* Copyright 2013, Mark Dalgleish
|
||||
* This content is released under the MIT license
|
||||
* http://mit-license.org/markdalgleish
|
||||
*/
|
||||
|
||||
(function(moduleName, window) {
|
||||
var from = function(selectorOrElement, selectedPlugins) {
|
||||
var parent = selectorOrElement.blur ? selectorOrElement : document.querySelector(selectorOrElement),
|
||||
slides = [].slice.call(parent.children, 0),
|
||||
activeSlide = slides[0],
|
||||
listeners = {},
|
||||
|
||||
activate = function(index, customData) {
|
||||
if (!slides[index]) {
|
||||
return;
|
||||
}
|
||||
|
||||
fire('deactivate', createEventData(activeSlide, customData));
|
||||
|
||||
activeSlide = slides[index];
|
||||
|
||||
slides.map(deactivate);
|
||||
|
||||
fire('activate', createEventData(activeSlide, customData));
|
||||
|
||||
addClass(activeSlide, 'active');
|
||||
removeClass(activeSlide, 'inactive');
|
||||
},
|
||||
|
||||
deactivate = function(slide, index) {
|
||||
var offset = index - slides.indexOf(activeSlide),
|
||||
offsetClass = offset > 0 ? 'after' : 'before';
|
||||
|
||||
['before(-\\d+)?', 'after(-\\d+)?', 'active', 'inactive'].map(removeClass.bind(0, slide));
|
||||
|
||||
slide != activeSlide &&
|
||||
['inactive', offsetClass, offsetClass + '-' + Math.abs(offset)].map(addClass.bind(0, slide));
|
||||
},
|
||||
|
||||
slide = function(index, customData) {
|
||||
fire('slide', createEventData(slides[index], customData)) && activate(index, customData);
|
||||
},
|
||||
|
||||
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(slide, eventData) {
|
||||
eventData = eventData || {};
|
||||
eventData.index = slides.indexOf(slide);
|
||||
eventData.slide = slide;
|
||||
return eventData;
|
||||
},
|
||||
|
||||
deck = {
|
||||
on: on,
|
||||
fire: fire,
|
||||
slide: slide,
|
||||
next: step.bind(0, 1),
|
||||
prev: step.bind(0, -1),
|
||||
parent: parent,
|
||||
slides: slides
|
||||
};
|
||||
|
||||
addClass(parent, 'parent');
|
||||
|
||||
slides.map(function(slide) {
|
||||
addClass(slide, 'slide');
|
||||
});
|
||||
|
||||
for (var pluginName in selectedPlugins) {
|
||||
plugins[pluginName](deck, selectedPlugins[pluginName]);
|
||||
}
|
||||
|
||||
activate(0);
|
||||
|
||||
decks.push(deck);
|
||||
|
||||
return deck;
|
||||
},
|
||||
|
||||
decks = [],
|
||||
|
||||
addClass = function(el, cls) {
|
||||
el.classList.add(moduleName + '-' + cls);
|
||||
},
|
||||
|
||||
removeClass = function(el, cls) {
|
||||
el.className = el.className
|
||||
.replace(RegExp(moduleName + '-' + cls +'(\\s|$)', 'g'), ' ')
|
||||
.trim();
|
||||
},
|
||||
|
||||
callOnAllDecks = function(method) {
|
||||
return function(arg) {
|
||||
decks.map(function(deck) {
|
||||
deck[method](arg);
|
||||
});
|
||||
};
|
||||
},
|
||||
|
||||
bindPlugin = function(pluginName) {
|
||||
return {
|
||||
from: function(selectorOrElement, selectedPlugins) {
|
||||
(selectedPlugins = selectedPlugins || {})[pluginName] = true;
|
||||
return from(selectorOrElement, selectedPlugins);
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
makePluginForAxis = function(axis) {
|
||||
return function(deck) {
|
||||
var startPosition,
|
||||
delta;
|
||||
|
||||
document.addEventListener('keydown', function(e) {
|
||||
(
|
||||
e.which == 34 || // PAGE DOWN
|
||||
e.which == 32 || // SPACE
|
||||
axis == 'X' && e.which == 39 || // RIGHT
|
||||
axis == 'Y' && e.which == 40 // BOTTOM
|
||||
) && deck.next();
|
||||
(
|
||||
e.which == 33 || // PAGE UP
|
||||
axis == 'X' && e.which == 37 || // LEFT
|
||||
axis == 'Y' && e.which == 38 // TOP
|
||||
) && deck.prev();
|
||||
});
|
||||
|
||||
deck.parent.addEventListener('touchstart', function(e) {
|
||||
if (e.touches.length == 1) {
|
||||
startPosition = e.touches[0]['page' + axis];
|
||||
delta = 0;
|
||||
}
|
||||
});
|
||||
|
||||
deck.parent.addEventListener('touchmove', function(e) {
|
||||
if (e.touches.length == 1) {
|
||||
e.preventDefault();
|
||||
delta = e.touches[0]['page' + axis] - startPosition;
|
||||
}
|
||||
});
|
||||
|
||||
deck.parent.addEventListener('touchend', function() {
|
||||
Math.abs(delta) > 50 && (delta > 0 ? deck.prev() : deck.next());
|
||||
});
|
||||
};
|
||||
},
|
||||
|
||||
plugins = {
|
||||
horizontal: makePluginForAxis('X'),
|
||||
vertical: makePluginForAxis('Y')
|
||||
};
|
||||
|
||||
window[moduleName] = {
|
||||
from: from,
|
||||
slide: callOnAllDecks('slide'),
|
||||
next: callOnAllDecks('next'),
|
||||
prev: callOnAllDecks('prev'),
|
||||
horizontal: bindPlugin('horizontal'),
|
||||
vertical: bindPlugin('vertical'),
|
||||
plugins: plugins
|
||||
};
|
||||
|
||||
}('bespoke', window));
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
/*! Bespoke.js v0.3.1 © 2013 Mark Dalgleish, Licensed MIT */
|
||||
!function(a,b){var c=function(a,b){var c=a.blur?a:document.querySelector(a),g=[].slice.call(c.children,0),h=g[0],i={},k=function(a,b){g[a]&&(p("deactivate",q(h,b)),h=g[a],g.map(l),p("activate",q(h,b)),e(h,"active"),f(h,"inactive"))},l=function(a,b){var c=b-g.indexOf(h),d=c>0?"after":"before";["before(-\\d+)?","after(-\\d+)?","active","inactive"].map(f.bind(0,a)),a!=h&&["inactive",d,d+"-"+Math.abs(c)].map(e.bind(0,a))},m=function(a,b){p("slide",q(g[a],b))&&k(a,b)},n=function(a,b){var c=g.indexOf(h)+a;p(a>0?"next":"prev",q(h,b))&&k(c,b)},o=function(a,b){return(i[a]||(i[a]=[])).push(b),function(){i[a]=i[a].filter(function(a){return a!=b})}},p=function(a,b){return(i[a]||[]).reduce(function(a,c){return a&&c(b)!==!1},!0)},q=function(a,b){return b=b||{},b.index=g.indexOf(a),b.slide=a,b},r={on:o,fire:p,slide:m,next:n.bind(0,1),prev:n.bind(0,-1),parent:c,slides:g};e(c,"parent"),g.map(function(a){e(a,"slide")});for(var s in b)j[s](r,b[s]);return k(0),d.push(r),r},d=[],e=function(b,c){b.classList.add(a+"-"+c)},f=function(b,c){b.className=b.className.replace(RegExp(a+"-"+c+"(\\s|$)","g")," ").trim()},g=function(a){return function(b){d.map(function(c){c[a](b)})}},h=function(a){return{from:function(b,d){return(d=d||{})[a]=!0,c(b,d)}}},i=function(a){return function(b){var c,d;document.addEventListener("keydown",function(c){(34==c.which||32==c.which||"X"==a&&39==c.which||"Y"==a&&40==c.which)&&b.next(),(33==c.which||"X"==a&&37==c.which||"Y"==a&&38==c.which)&&b.prev()}),b.parent.addEventListener("touchstart",function(b){1==b.touches.length&&(c=b.touches[0]["page"+a],d=0)}),b.parent.addEventListener("touchmove",function(b){1==b.touches.length&&(b.preventDefault(),d=b.touches[0]["page"+a]-c)}),b.parent.addEventListener("touchend",function(){Math.abs(d)>50&&(d>0?b.prev():b.next())})}},j={horizontal:i("X"),vertical:i("Y")};b[a]={from:c,slide:g("slide"),next:g("next"),prev:g("prev"),horizontal:h("horizontal"),vertical:h("vertical"),plugins:j}}("bespoke",window);
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "bespoke.js",
|
||||
"filename": "bespoke.min.js",
|
||||
"version": "0.2.1",
|
||||
"version": "0.3.1",
|
||||
"description": "DIY Presentation Micro-Framework",
|
||||
"homepage": "https://github.com/markdalgleish/bespoke.js",
|
||||
"keywords": [
|
||||
|
||||
Reference in New Issue
Block a user