{"version":3,"sources":["slinky.js"],"names":["Slinky","element","options","arguments","length","undefined","_classCallCheck","this","settings","_extends","resize","_init","speed","theme","title","menu","jQuery","base","children","first","addClass","_transition","prev","wrapInner","prepend","header","back","prop","each","index","parent","find","text","label","append","_addListeners","_jumpToInitial","_this","e","_clicked","Date","now","link","currentTarget","attr","indexOf","hasClass","preventDefault","next","_move","removeClass","hide","parentsUntil","_resize","active","jump","setTimeout","height","outerHeight","callback","depth","left","Math","round","parseInt","get","style","css","content","target","animate","to","count","menus","show","parents","not","remove","off","transition-duration","contents","unwrap","split","forEach","field","_this2","fn","slinky"],"mappings":"wiBAOMA,kBAWJ,SAAAA,EAAYC,GAAuB,IAAdC,EAAcC,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,MAAAG,gBAAAC,KAAAP,GAEjCO,KAAKC,SAALC,YAVAF,KAAOL,QACLQ,GADKH,KAAPI,MAAAV,wDAAA,OACES,QAAQ,EACRE,MAAO,IACPC,MAAO,uBACPC,OAAO,mDAIXb,GAcEM,KAAKQ,KAAOC,OAAOf,GAdcM,KAAAU,KAAAV,KAAAQ,KAAAG,WAAAC,QACjCZ,KAAAU,KADF,IACEF,EAAAR,KAAAQ,KAAAP,EAAAD,KAAAC,SAMAO,EAAAK,SAAA,eAAAA,SAAAZ,EAAAK,OAgBAN,KAAKc,YAAYb,EAASI,OAG1BI,OAAO,SAAUD,GACdO,OACAF,SAAS,QAbZJ,OAAKC,SAAOF,GAAAQ,UAAA,UAHC,IAKCR,EAAmBC,OALpB,QAAAI,SAAA,UAObJ,OAAA,UAAAD,GAAAS,QAAAC,GAsBA,IAAMC,EAAOV,OAAO,OAnBpBW,KAAA,OAAA,KACAP,SAAKC,QAGLL,OAAAA,UAAAD,GAAAS,QAEGJ,GAGHZ,EAAAM,OAoBEE,OAAO,UAAWD,GAAMa,KAAK,SAACC,EAAO5B,GAhBvC,IAAMwB,EAAST,OAAOf,GAmBf6B,SAjBPC,KAAA,KACAf,QAmBOg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R,KAAAQ,KAAAP,EAAAD,KAAAC,SAGA8D,GACAC,KAAGG,YAAOtD,GAIR,IAAAkC,EAAKjC,EAALU,KAAA,WAGF4C,EAAArB,EAAAF,aAAArC,EAAA,MAGAR,KAAA0C,OAAA0B,EAAAvE,OAAA,WAEEkD,EAAKD,YAAL,UAAAF,OAGFwB,EAAAC,IAAA3D,GAAAkC,SAID3C,EAAAE,QA6BGH,KAAK8C,QAAQpC,IAIC,IAAZqD,GACF/D,KAAKc,YAAYb,EAASI,yCA7BRJ,IAAAA,EAAAA,KAmCZS,EAAeV,KAAfU,KAAMF,EAASR,KAATQ,KAhCdC,OAAKsD,UAASvD,GAAA8D,SAId7D,OAAA,IAAAD,GACAmC,YAAenC,QAoCZ+D,IAAI,SAGP/D,EAAKoD,KAlCLV,OAAA,GACAsB,sBAAoB3E,KAsCpBa,EAAKkD,KAlCHN,KAAA,GACAc,sBAAkBxB,KAIpBnC,OAAIR,gBAAiBO,GACnBiE,WACDC,SAGDlE,EAAAgB,KAAIuC,WAAYpB,YAAO,UAGxBnC,EAAA6B,KAAA,SAAAsC,MAAA,KAEDC,QAAA,SAAAjB,GAoCoC,IAA5BA,EAAMrB,QAAQ,WAChB9B,EAAKmC,YAAYgB,MAnCE,WADf,OAAA,QA2CDiB,QAAQ,SAAAC,GAAA,cAAgBC,EAAKD,cA7BlC3B,OAPF6B,GAAAC,OAAA,SAAArF,GAKA,OAJA,IAAYa,OACTmC,KAAAA","file":"slinky.min.js","sourcesContent":["/*\n * Slinky\n * Rather sweetmenus\n * @author Ali Zahid \n * @license MIT\n */\n\nclass Slinky {\n // default options\n get options() {\n return {\n resize: true,\n speed: 300,\n theme: 'slinky-theme-default',\n title: false\n }\n }\n\n constructor(element, options = {}) {\n // save settings\n this.settings = {\n ...this.options,\n ...options\n }\n\n // let's go!\n this._init(element)\n }\n\n // setup the DOM just for us\n _init(element) {\n // the two elements of water and moisture\n this.menu = jQuery(element)\n this.base = this.menu.children().first()\n\n const { base, menu, settings } = this\n\n // set theme\n menu.addClass('slinky-menu').addClass(settings.theme)\n\n // set transition speed\n this._transition(settings.speed)\n\n // add arrows to links with children\n jQuery('a + ul', menu)\n .prev()\n .addClass('next')\n\n // wrap link text with \n // mostly for styling\n jQuery('li > a', menu).wrapInner('')\n\n // create header item\n const header = jQuery('
  • ').addClass('header')\n\n // prepend it to the list\n jQuery('li > ul', menu).prepend(header)\n\n // create back buttons\n const back = jQuery('')\n .prop('href', '#')\n .addClass('back')\n\n // prepend them to the headers\n jQuery('.header', menu).prepend(back)\n\n // do we need to add titles?\n if (settings.title) {\n // loop through each child list\n jQuery('li > ul', menu).each((index, element) => {\n // get the label from the parent link\n const label = jQuery(element)\n .parent()\n .find('a')\n .first()\n .text()\n\n // if it's not empty, create the title\n if (label) {\n const title = jQuery('
    ')\n .addClass('title')\n .text(label)\n\n // append it to the immediate header\n jQuery('> .header', element).append(title)\n }\n })\n }\n\n // add click listeners\n this._addListeners()\n\n // jump to initial active\n this._jumpToInitial()\n }\n\n // click listeners\n _addListeners() {\n const { menu, settings } = this\n\n jQuery('a', menu).on('click', e => {\n // prevent broken/half transitions\n if (this._clicked + settings.speed > Date.now()) {\n return false\n }\n\n // cache click time to check on next click\n this._clicked = Date.now()\n\n // get the link\n const link = jQuery(e.currentTarget)\n\n // prevent default if it's a hash\n // or a Slinky button\n if (\n link.attr('href').indexOf('#') === 0 ||\n link.hasClass('next') ||\n link.hasClass('back')\n ) {\n e.preventDefault()\n }\n\n // time to move\n if (link.hasClass('next')) {\n // one step forward\n\n // remove the current active\n menu.find('.active').removeClass('active')\n\n // set the new active\n link\n .next()\n .show()\n .addClass('active')\n\n // make the chess move\n this._move(1)\n\n // resize the menu if need be\n if (settings.resize) {\n this._resize(link.next())\n }\n } else if (link.hasClass('back')) {\n // and two steps back\n // just one step back, actually\n\n // make the move\n this._move(-1, () => {\n // remove the current active\n menu.find('.active').removeClass('active')\n\n // set the new active\n link\n .parent()\n .parent()\n .hide()\n .parentsUntil(menu, 'ul')\n .first()\n .addClass('active')\n })\n\n // resize the menu if need be\n if (settings.resize) {\n this._resize(\n link\n .parent()\n .parent()\n .parentsUntil(menu, 'ul')\n )\n }\n }\n })\n }\n\n // jump to initial active on init\n _jumpToInitial() {\n const { menu, settings } = this\n\n // get initial active\n const active = menu.find('.active')\n\n if (active.length > 0) {\n // remove initial active\n active.removeClass('active')\n\n // jump without animation\n this.jump(active, false)\n }\n\n // set initial height on the menu\n // to fix the first transition resize bug\n setTimeout(() => menu.height(menu.outerHeight()), settings.speed)\n }\n\n // slide the menu\n _move(depth = 0, callback = () => {}) {\n // don't bother packing if we're not going anywhere\n if (depth === 0) {\n return\n }\n\n const { settings, base } = this\n\n // get current position from the left\n const left = Math.round(parseInt(base.get(0).style.left)) || 0\n\n // set the new position from the left\n base.css('left', `${left - depth * 100}%`)\n\n // callback after the animation\n if (typeof callback === 'function') {\n setTimeout(callback, settings.speed)\n }\n }\n\n // resize the menu\n // to match content height\n _resize(content) {\n const { menu } = this\n\n menu.height(content.outerHeight())\n }\n\n // set the transition speed\n _transition(speed = 300) {\n const { menu, base } = this\n\n menu.css('transition-duration', `${speed}ms`)\n base.css('transition-duration', `${speed}ms`)\n }\n\n // jump to an element\n jump(target, animate = true) {\n if (!target) {\n return\n }\n\n const { menu, settings } = this\n\n const to = jQuery(target)\n\n // get all current active\n const active = menu.find('.active')\n\n // how many moves must we jump?\n let count = 0\n\n // this many\n // until we reach the parent list\n if (active.length > 0) {\n count = active.parentsUntil(menu, 'ul').length\n }\n\n // remove current active\n // hide all lists\n menu\n .find('ul')\n .removeClass('active')\n .hide()\n\n // get parent list\n const menus = to.parentsUntil(menu, 'ul')\n\n // show parent list\n menus.show()\n\n //\n to.show().addClass('active')\n\n // set transition speed to 0 if no animation\n if (!animate) {\n this._transition(0)\n }\n\n // make the checkers move\n this._move(menus.length - count)\n\n // resize menu if need be\n if (settings.resize) {\n this._resize(to)\n }\n\n // set transition speed to default after transition\n if (!animate) {\n this._transition(settings.speed)\n }\n }\n\n // go big or go home\n // just go home\n home(animate = true) {\n const { base, menu, settings } = this\n\n // set transition speed to 0 if no animation\n if (!animate) {\n this._transition(0)\n }\n\n // get current active\n const active = menu.find('.active')\n\n // get all parent lists\n const parents = active.parentsUntil(menu, 'ul')\n\n // make the move\n this._move(-parents.length, () => {\n // remove the current active\n active.removeClass('active').hide()\n\n // hide all parents except base\n parents.not(base).hide()\n })\n\n // resize if need be\n if (settings.resize) {\n this._resize(base)\n }\n\n // set transition speed back to default\n if (animate === false) {\n this._transition(settings.speed)\n }\n }\n\n // crush, kill, destroy\n destroy() {\n const { base, menu } = this\n\n // remove all headers\n jQuery('.header', menu).remove()\n\n // remove Slinky links\n // and click listeners\n jQuery('a', menu)\n .removeClass('next')\n .off('click')\n\n // remove inline styles\n menu.css({\n height: '',\n 'transition-duration': ''\n })\n\n base.css({\n left: '',\n 'transition-duration': ''\n })\n\n // remove Slinky HTML\n jQuery('li > a > span', menu)\n .contents()\n .unwrap()\n\n // remove any current active\n menu.find('.active').removeClass('active')\n\n // remove any Slinky style classes\n const styles = menu.attr('class').split(' ')\n\n styles.forEach(style => {\n if (style.indexOf('slinky') === 0) {\n menu.removeClass(style)\n }\n })\n\n // reset fields\n const fields = ['settings', 'menu', 'base']\n\n fields.forEach(field => delete this[field])\n }\n}\n\n// jQuery plugin\n;($ => {\n $.fn.slinky = function(options) {\n const menu = new Slinky(this, options)\n\n return menu\n }\n})(jQuery)\n"]}