/* slinky a light-weight, responsive, mobile-like navigation menu plugin for jquery built by ali zahid published under the mit license */ ;(function($) { $.fn.slinky = function(options) { // setup plugin defaults var settings = $.extend({ label: 'back', title: false, speed: 300, resize: true }, options); // convenience method for navigation animation var move = function(menu, next, callback) { var left = math.round(parseint(menu.get(0).style.left)) || 0; // use multiples of 100% for responsive animation menu.css('left', -math.abs(next ? left - 100 : left + 100) + '%'); // callback after animation is finished if (typeof callback === 'function') { settimeout(callback, settings.speed); } }; // convenience method for resizing menu var resize = function(menu, content) { menu.height(content.outerheight()); }; return this.each(function() { // the root node is where animation happens var menu = $(this), root = menu.children().first(); // set css animation duration menu.css('transition-duration', settings.speed + 'ms'); root.css('transition-duration', settings.speed + 'ms'); // add .next class to links with sub menus $('a + ul', menu).prev().addclass('next'); // add header for back button and title $('li > ul', menu).prepend('
  • '); // add title if (settings.title === true) { // create a label with title from the parent $('li > ul', menu).each(function() { var label = $(this).parent().find('a').first().text(), title = $('

    ').text(label); $('> .header', this).append(title); }); } // add back links with appropriate labels if (!settings.title && settings.label === true) { // create a link with label from parent $('li > ul', menu).each(function() { var label = $(this).parent().find('a').first().text(), backlink = $('').text(label).prop('href', '#').addclass('back'); $('> .header', this).append(backlink); }); } else { // create a link with the label from settings var backlink = $('').text(settings.label).prop('href', '#').addclass('back'); $('.header', menu).append(backlink); } // setup navigation $('a', menu).on('click', function(e) { var a = $(this); // disable navigation if link has hash // else proceed to url if (/#/.test(this.href)) { e.preventdefault(); } // animate forward or backward // resize menu height to match content, if required if (a.hasclass('next')) { a.next().show(); move(root, true); if (settings.resize) { resize(menu, a.next()); } } else if (a.hasclass('back')) { move(root, false, function() { a.parent().parent().hide(); }); if (settings.resize) { resize(menu, a.parent().parent().parents('ul')); } } }); }); return this; }; }(jquery));