UNPKG

bespoke-bullets

Version:
83 lines (68 loc) 3.23 kB
/*! * bespoke-bullets v1.1.0 * * Copyright 2014, Mark Dalgleish * This content is released under the MIT license * http://mit-license.org/markdalgleish */ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;"undefined"!=typeof window?n=window:"undefined"!=typeof global?n=global:"undefined"!=typeof self&&(n=self);var o=n;o=o.bespoke||(o.bespoke={}),o=o.plugins||(o.plugins={}),o.bullets=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){ module.exports = function(options) { return function(deck) { var activeSlideIndex, activeBulletIndex, bullets = deck.slides.map(function(slide) { return [].slice.call(slide.querySelectorAll((typeof options === 'string' ? options : '[data-bespoke-bullet]')), 0); }), next = function() { var nextSlideIndex = activeSlideIndex + 1; if (activeSlideHasBulletByOffset(1)) { activateBullet(activeSlideIndex, activeBulletIndex + 1); return false; } else if (bullets[nextSlideIndex]) { activateBullet(nextSlideIndex, 0); } }, prev = function() { var prevSlideIndex = activeSlideIndex - 1; if (activeSlideHasBulletByOffset(-1)) { activateBullet(activeSlideIndex, activeBulletIndex - 1); return false; } else if (bullets[prevSlideIndex]) { activateBullet(prevSlideIndex, bullets[prevSlideIndex].length - 1); } }, activateBullet = function(slideIndex, bulletIndex) { activeSlideIndex = slideIndex; activeBulletIndex = bulletIndex; bullets.forEach(function(slide, s) { slide.forEach(function(bullet, b) { bullet.classList.add('bespoke-bullet'); if (s < slideIndex || s === slideIndex && b <= bulletIndex) { bullet.classList.add('bespoke-bullet-active'); bullet.classList.remove('bespoke-bullet-inactive'); } else { bullet.classList.add('bespoke-bullet-inactive'); bullet.classList.remove('bespoke-bullet-active'); } if (s === slideIndex && b === bulletIndex) { bullet.classList.add('bespoke-bullet-current'); } else { bullet.classList.remove('bespoke-bullet-current'); } }); }); }, activeSlideHasBulletByOffset = function(offset) { return bullets[activeSlideIndex][activeBulletIndex + offset] !== undefined; }; deck.on('next', next); deck.on('prev', prev); deck.on('slide', function(e) { activateBullet(e.index, 0); }); activateBullet(0, 0); }; }; },{}]},{},[1]) (1) });