/*! sidr - v2.2.1 - 2016-02-17 * http://www.berriart.com/sidr/ * copyright (c) 2013-2016 alberto varela; licensed mit */ (function () { 'use strict'; var babelhelpers = {}; babelhelpers.classcallcheck = function (instance, constructor) { if (!(instance instanceof constructor)) { throw new typeerror("cannot call a class as a function"); } }; babelhelpers.createclass = function () { function defineproperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; object.defineproperty(target, descriptor.key, descriptor); } } return function (constructor, protoprops, staticprops) { if (protoprops) defineproperties(constructor.prototype, protoprops); if (staticprops) defineproperties(constructor, staticprops); return constructor; }; }(); babelhelpers; var sidrstatus = { moving: false, opened: false }; var helper = { // check for valids urls // from : http://stackoverflow.com/questions/5717093/check-if-a-javascript-string-is-an-url isurl: function isurl(str) { var pattern = new regexp('^(https?:\\/\\/)?' + // protocol '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.?)+[a-z]{2,}|' + // domain name '((\\d{1,3}\\.){3}\\d{1,3}))' + // or ip (v4) address '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string '(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator if (pattern.test(str)) { return true; } else { return false; } }, // add sidr prefixes addprefixes: function addprefixes($element) { this.addprefix($element, 'id'); this.addprefix($element, 'class'); $element.removeattr('style'); }, addprefix: function addprefix($element, attribute) { var toreplace = $element.attr(attribute); if (typeof toreplace === 'string' && toreplace !== '' && toreplace !== 'sidr-inner') { $element.attr(attribute, toreplace.replace(/([a-za-z0-9_.\-]+)/g, 'sidr-' + attribute + '-$1')); } }, // check if transitions is supported transitions: function () { var body = document.body || document.documentelement, style = body.style, supported = false, property = 'transition'; if (property in style) { supported = true; } else { (function () { var prefixes = ['moz', 'webkit', 'o', 'ms'], prefix = undefined, i = undefined; property = property.charat(0).touppercase() + property.substr(1); supported = function () { for (i = 0; i < prefixes.length; i++) { prefix = prefixes[i]; if (prefix + property in style) { return true; } } return false; }(); property = supported ? '-' + prefix.tolowercase() + '-' + property.tolowercase() : null; })(); } return { supported: supported, property: property }; }() }; var $$2 = jquery; var bodyanimationclass = 'sidr-animating'; var openaction = 'open'; var closeaction = 'close'; var transitionendevent = 'webkittransitionend otransitionend otransitionend mstransitionend transitionend'; var menu = function () { function menu(name) { babelhelpers.classcallcheck(this, menu); this.name = name; this.item = $$2('#' + name); this.openclass = name === 'sidr' ? 'sidr-open' : 'sidr-open ' + name + '-open'; this.menuwidth = this.item.outerwidth(true); this.speed = this.item.data('speed'); this.side = this.item.data('side'); this.displace = this.item.data('displace'); this.timing = this.item.data('timing'); this.method = this.item.data('method'); this.onopencallback = this.item.data('onopen'); this.onclosecallback = this.item.data('onclose'); this.onopenendcallback = this.item.data('onopenend'); this.oncloseendcallback = this.item.data('oncloseend'); this.body = $$2(this.item.data('body')); } babelhelpers.createclass(menu, [{ key: 'getanimation', value: function getanimation(action, element) { var animation = {}, prop = this.side; if (action === 'open' && element === 'body') { animation[prop] = this.menuwidth + 'px'; } else if (action === 'close' && element === 'menu') { animation[prop] = '-' + this.menuwidth + 'px'; } else { animation[prop] = 0; } return animation; } }, { key: 'preparebody', value: function preparebody(action) { var prop = action === 'open' ? 'hidden' : ''; // prepare page if container is body if (this.body.is('body')) { var $html = $$2('html'), scrolltop = $html.scrolltop(); $html.css('overflow-x', prop).scrolltop(scrolltop); } } }, { key: 'openbody', value: function openbody() { if (this.displace) { var transitions = helper.transitions, $body = this.body; if (transitions.supported) { $body.css(transitions.property, this.side + ' ' + this.speed / 1000 + 's ' + this.timing).css(this.side, 0).css({ width: $body.width(), position: 'absolute' }); $body.css(this.side, this.menuwidth + 'px'); } else { var bodyanimation = this.getanimation(openaction, 'body'); $body.css({ width: $body.width(), position: 'absolute' }).animate(bodyanimation, { queue: false, duration: this.speed }); } } } }, { key: 'onclosebody', value: function onclosebody() { var transitions = helper.transitions, resetstyles = { width: '', position: '', right: '', left: '' }; if (transitions.supported) { resetstyles[transitions.property] = ''; } this.body.css(resetstyles).unbind(transitionendevent); } }, { key: 'closebody', value: function closebody() { var _this = this; if (this.displace) { if (helper.transitions.supported) { this.body.css(this.side, 0).one(transitionendevent, function () { _this.onclosebody(); }); } else { var bodyanimation = this.getanimation(closeaction, 'body'); this.body.animate(bodyanimation, { queue: false, duration: this.speed, complete: function complete() { _this.onclosebody(); } }); } } } }, { key: 'movebody', value: function movebody(action) { if (action === openaction) { this.openbody(); } else { this.closebody(); } } }, { key: 'onopenmenu', value: function onopenmenu(callback) { var name = this.name; sidrstatus.moving = false; sidrstatus.opened = name; this.item.unbind(transitionendevent); this.body.removeclass(bodyanimationclass).addclass(this.openclass); this.onopenendcallback(); if (typeof callback === 'function') { callback(name); } } }, { key: 'openmenu', value: function openmenu(callback) { var _this2 = this; var $item = this.item; if (helper.transitions.supported) { $item.css(this.side, 0).one(transitionendevent, function () { _this2.onopenmenu(callback); }); } else { var menuanimation = this.getanimation(openaction, 'menu'); $item.css('display', 'block').animate(menuanimation, { queue: false, duration: this.speed, complete: function complete() { _this2.onopenmenu(callback); } }); } } }, { key: 'onclosemenu', value: function onclosemenu(callback) { this.item.css({ left: '', right: '' }).unbind(transitionendevent); $$2('html').css('overflow-x', ''); sidrstatus.moving = false; sidrstatus.opened = false; this.body.removeclass(bodyanimationclass).removeclass(this.openclass); this.oncloseendcallback(); // callback if (typeof callback === 'function') { callback(name); } } }, { key: 'closemenu', value: function closemenu(callback) { var _this3 = this; var item = this.item; if (helper.transitions.supported) { item.css(this.side, '').one(transitionendevent, function () { _this3.onclosemenu(callback); }); } else { var menuanimation = this.getanimation(closeaction, 'menu'); item.animate(menuanimation, { queue: false, duration: this.speed, complete: function complete() { _this3.onclosemenu(); } }); } } }, { key: 'movemenu', value: function movemenu(action, callback) { this.body.addclass(bodyanimationclass); if (action === openaction) { this.openmenu(callback); } else { this.closemenu(callback); } } }, { key: 'move', value: function move(action, callback) { // lock sidr sidrstatus.moving = true; this.preparebody(action); this.movebody(action); this.movemenu(action, callback); } }, { key: 'open', value: function open(callback) { var _this4 = this; // check if is already opened or moving if (sidrstatus.opened === this.name || sidrstatus.moving) { return; } // if another menu opened close first if (sidrstatus.opened !== false) { var alreadyopenedmenu = new menu(sidrstatus.opened); alreadyopenedmenu.close(function () { _this4.open(callback); }); return; } this.move('open', callback); // onopen callback this.onopencallback(); } }, { key: 'close', value: function close(callback) { // check if is already closed or moving if (sidrstatus.opened !== this.name || sidrstatus.moving) { return; } this.move('close', callback); // onclose callback this.onclosecallback(); } }, { key: 'toggle', value: function toggle(callback) { if (sidrstatus.opened === this.name) { this.close(callback); } else { this.open(callback); } } }]); return menu; }(); var $$1 = jquery; function execute(action, name, callback) { var sidr = new menu(name); switch (action) { case 'open': sidr.open(callback); break; case 'close': sidr.close(callback); break; case 'toggle': sidr.toggle(callback); break; default: $$1.error('method ' + action + ' does not exist on jquery.sidr'); break; } } var i; var $ = jquery; var publicmethods = ['open', 'close', 'toggle']; var methodname; var methods = {}; var getmethod = function getmethod(methodname) { return function (name, callback) { // check arguments if (typeof name === 'function') { callback = name; name = 'sidr'; } else if (!name) { name = 'sidr'; } execute(methodname, name, callback); }; }; for (i = 0; i < publicmethods.length; i++) { methodname = publicmethods[i]; methods[methodname] = getmethod(methodname); } function sidr(method) { if (method === 'status') { return sidrstatus; } else if (methods[method]) { return methods[method].apply(this, array.prototype.slice.call(arguments, 1)); } else if (typeof method === 'function' || typeof method === 'string' || !method) { return methods.toggle.apply(this, arguments); } else { $.error('method ' + method + ' does not exist on jquery.sidr'); } } var $$3 = jquery; function fillcontent($sidemenu, settings) { // the menu content if (typeof settings.source === 'function') { var newcontent = settings.source(name); $sidemenu.html(newcontent); } else if (typeof settings.source === 'string' && helper.isurl(settings.source)) { $$3.get(settings.source, function (data) { $sidemenu.html(data); }); } else if (typeof settings.source === 'string') { var htmlcontent = '', selectors = settings.source.split(','); $$3.each(selectors, function (index, element) { htmlcontent += '
' + $$3(element).html() + '
'; }); // renaming ids and classes if (settings.renaming) { var $htmlcontent = $$3('
').html(htmlcontent); $htmlcontent.find('*').each(function (index, element) { var $element = $$3(element); helper.addprefixes($element); }); htmlcontent = $htmlcontent.html(); } $sidemenu.html(htmlcontent); } else if (settings.source !== null) { $$3.error('invalid sidr source'); } return $sidemenu; } function fnsidr(options) { var transitions = helper.transitions, settings = $$3.extend({ name: 'sidr', // name for the 'sidr' speed: 200, // accepts standard jquery effects speeds (i.e. fast, normal or milliseconds) side: 'left', // accepts 'left' or 'right' source: null, // override the source of the content. renaming: true, // the ids and classes will be prepended with a prefix when loading existent content body: 'body', // page container selector, displace: true, // displace the body content or not timing: 'ease', // timing function for css transitions method: 'toggle', // the method to call when element is clicked bind: 'touchstart click', // the event(s) to trigger the menu onopen: function onopen() {}, // callback when sidr start opening onclose: function onclose() {}, // callback when sidr start closing onopenend: function onopenend() {}, // callback when sidr end opening oncloseend: function oncloseend() {} // callback when sidr end closing }, options), name = settings.name, $sidemenu = $$3('#' + name); // if the side menu do not exist create it if ($sidemenu.length === 0) { $sidemenu = $$3('
').attr('id', name).appendto($$3('body')); } // add transition to menu if are supported if (transitions.supported) { $sidemenu.css(transitions.property, settings.side + ' ' + settings.speed / 1000 + 's ' + settings.timing); } // adding styles and options $sidemenu.addclass('sidr').addclass(settings.side).data({ speed: settings.speed, side: settings.side, body: settings.body, displace: settings.displace, timing: settings.timing, method: settings.method, onopen: settings.onopen, onclose: settings.onclose, onopenend: settings.onopenend, oncloseend: settings.oncloseend }); $sidemenu = fillcontent($sidemenu, settings); return this.each(function () { var $this = $$3(this), data = $this.data('sidr'), flag = false; // if the plugin hasn't been initialized yet if (!data) { sidrstatus.moving = false; sidrstatus.opened = false; $this.data('sidr', name); $this.bind(settings.bind, function (event) { event.preventdefault(); if (!flag) { flag = true; sidr(settings.method, name); settimeout(function () { flag = false; }, 100); } }); } }); } jquery.sidr = sidr; jquery.fn.sidr = fnsidr; }());