-
Notifications
You must be signed in to change notification settings - Fork 75
/
jquery.fs.naver.min.js
9 lines (8 loc) · 3.4 KB
/
jquery.fs.naver.min.js
1
2
3
4
5
6
7
8
9
/*
* Naver v3.1.2 - 2015-04-04
* A jQuery plugin for responsive navigation. Part of the Formstone Library.
* http://formstone.it/naver/
*
* Copyright 2015 Ben Plum; MIT Licensed
*/
!function(a,b){"use strict";function c(b){b=a.extend(!0,{},j,b);for(var c=a(this),e=0,f=c.length;f>e;e++)d(c.eq(e),b);return c}function d(c,d){if(!c.data("naver")){d=a.extend(!0,{},d,c.data("naver-options"));var f=c.find(".naver-handle").length?c.find(".naver-handle").detach():a('<span class="naver-handle"></span>');c.addClass("naver "+d.customClass).wrapInner('<div class="naver-container"></div>').wrapInner('<div class="naver-wrapper"></div>').prepend(f);var g=a.extend(!0,{$nav:c,$container:c.find(".naver-container"),$wrapper:c.find(".naver-wrapper"),$handle:c.find(".naver-handle")},d);g.$handle.text(d.label?d.labels.closed:""),g.$nav.on("touchstart.naver",".naver-handle",g,e).on("click.naver",".naver-handle",g,h).data("naver",g),void 0!==b.matchMedia&&(g.mediaQuery=b.matchMedia("(max-width:"+(g.maxWidth===1/0?"100000px":g.maxWidth)+")"),g.mediaQuery.addListener(function(){i.apply(g.$nav)}),i.apply(g.$nav))}}function e(a){a.stopPropagation();var b=a.data;b.touchStartEvent=a.originalEvent,b.touchStartX=b.touchStartEvent.touches[0].clientX,b.touchStartY=b.touchStartEvent.touches[0].clientY,b.$nav.on("touchmove.naver",".naver-handle",b,f).on("touchend.naver",".naver-handle",b,g)}function f(a){var b=a.data,c=a.originalEvent;(Math.abs(c.touches[0].clientX-b.touchStartX)>10||Math.abs(c.touches[0].clientY-b.touchStartY)>10)&&b.$nav.off("touchmove.naver touchend.naver")}function g(a){a.preventDefault(),a.stopPropagation();var b=a.data;b.touchStartEvent.preventDefault(),b.$nav.off("touchmove.naver touchend.naver click.naver"),h(a)}function h(b){b.preventDefault(),b.stopPropagation();var c=(a(b.currentTarget),b.data);a(".naver").not(c.$nav).naver("close"),c.$nav.hasClass("open")?k.close.apply(c.$nav):k.open.apply(c.$nav)}function i(){var b=a(this).data("naver");b.mediaQuery.matches?k.enable.apply(b.$nav):k.disable.apply(b.$nav)}var j={customClass:"",label:!0,labels:{closed:"Navigation",open:"Close"},maxWidth:"980px"},k={close:function(b){return a(this).each(function(b,c){var d=a(c).data("naver");d&&d.$nav.hasClass("enabled")&&(d.$wrapper.css({height:0}),d.label&&d.$handle.html(d.labels.closed),d.$nav.removeClass("open").trigger("close.naver"))})},defaults:function(b){return j=a.extend(!0,j,b||{}),"object"==typeof this?a(this):!0},disable:function(){return a(this).each(function(b,c){var d=a(c).data("naver");d&&(d.$nav.removeClass("enabled"),d.$wrapper.css({height:""}))})},destroy:function(){return a(this).each(function(b,c){var d=a(c).data("naver");d&&(d.$handle.remove(),d.$container.contents().unwrap().unwrap(),d.$nav.removeClass("enabled disabled naver "+d.customClass).off(".naver").removeData("naver"))})},enable:function(){return a(this).each(function(b,c){var d=a(c).data("naver");d&&(d.$nav.addClass("enabled"),k.close.apply(d.$nav))})},open:function(){return a(this).each(function(b,c){var d=a(c).data("naver");d&&d.$nav.hasClass("enabled")&&(d.$wrapper.css({height:d.$container.outerHeight(!0)}),d.label&&d.$handle.html(d.labels.open),d.$nav.addClass("open").trigger("open.naver"))})}};a.fn.naver=function(a){return k[a]?k[a].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof a&&a?this:c.apply(this,arguments)},a.naver=function(a){"defaults"===a&&k.defaults.apply(this,Array.prototype.slice.call(arguments,1))}}(jQuery,window);