/* ! sidr - v3.0.0 - 2017-12-10
http://www.berriart.com/sidr/
Copyright (c) 2013-2017 Alberto Varela; Licensed MIT
*/
! function() {
"use strict";
function e(e) {
return "status" === e ? a : d[e] ? d[e].apply(this, Array.prototype.slice.call(arguments, 1)) : "function" != typeof e && "string" != typeof e && e ? void console.error("Method " + e + " does not exist on sidr") : d.toggle.apply(this, arguments)
}
function t(e, t) {
var n = e.getAttribute(t);
"string" == typeof n && "" !== n && "sidr-inner" !== n && e.setAttribute(t, n.replace(/([A-Za-z0-9_.-]+)/g, "sidr-" + t + "-$1"))
}
function n(e, t, n) {
for (var i = n.split(" "), o = 0; o < i.length; o++) {
var s = i[o].trim();
e.classList[t](s)
}
}
function i(e, t, n) {
e[t] = n
}
function o(e, t, n) {
return e[t]
}
function s(e) {
return "BODY" === e.tagName
}
function r(e) {
var t = "sidr-open";
return "sidr" !== e && (t += " " + e + "-open"), t
}
for (var a = {
moving: !1,
opened: !1
}, l = {}, u = {
add: function(e, t) {
l[e] = t
},
get: function(e) {
return l[e]
}
}, c = function(e) {
return function(t, n) {
"function" == typeof t ? (n = t, t = "sidr") : t || (t = "sidr");
u.get(t)[e](n)
}
}, d = {}, h = ["open", "close", "toggle", "reload"], f = 0; f < h.length; f++) {
var p = h[f];
d[p] = c(p)
}
var m = {
isUrl: function(e) {
return !!new RegExp("^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.?)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(\\#[-a-z\\d_]*)?$", "i").test(e)
},
extend: function(e, t) {
for (var n in t) t.hasOwnProperty(n) && (e[n] = t[n]);
return e
},
fetch: function(e, t) {
var n = new XMLHttpRequest;
n.onreadystatechange = function() {
4 === n.readyState && 200 === n.status && t(n.responseText)
}, n.open("GET", e, !0), n.send()
}
},
v = {
id: function(e) {
return document.getElementById(e)
},
qs: function(e) {
return document.querySelector(e)
},
qsa: function(e) {
return document.querySelectorAll(e)
},
createElement: function(e) {
var t = document.createElement("div");
return t.id = e, document.body.appendChild(t), t
},
getHTMLContent: function(e) {
for (var t = "", n = this.qsa(e), i = 0; i < n.length; i++) t += '
' + n[i].innerHTML + "
";
return t
},
addPrefixes: function(e) {
var n = document.createElement("div");
n.innerHTML = e;
for (var i = n.querySelectorAll("*"), o = 0; o < i.length; o++) t(i[o], "id"), t(i[o], "class"), i[o].removeAttribute("style");
return n.innerHTML
},
transitions: function() {
var e = (document.body || document.documentElement).style,
t = !1,
n = "transition",
i = "transition",
o = "transitionend";
if (n in e) t = !0;
else {
var s = function(e, t) {
for (var n = void 0, i = ["moz", "webkit", "o", "ms"], o = 0; o < i.length; o++)
if ((n = i[o]) + e in t) return n;
return !1
}(n = n.charAt(0).toUpperCase() + n.substr(1), e);
i = (t = !!s) ? s + n : null, n = t ? "-" + s + "-" + n.toLowerCase() : null, "webkit" === s ? o = "webkitTransitionEnd" : "0" === s && (o = "oTransitionEnd")
}
return {
cssProperty: i,
supported: t,
property: n,
event: o
}
}()
},
y = function(e, t) {
if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function")
},
b = function() {
function e(e, t) {
for (var n = 0; n < t.length; n++) {
var i = t[n];
i.enumerable = i.enumerable || !1, i.configurable = !0, "value" in i && (i.writable = !0), Object.defineProperty(e, i.key, i)
}
}
return function(t, n, i) {
return n && e(t.prototype, n), i && e(t, i), t
}
}(),
g = function(e, t) {
if ("function" != typeof t && null !== t) throw new TypeError("Super expression must either be null or a function, not " + typeof t);
e.prototype = Object.create(t && t.prototype, {
constructor: {
value: e,
enumerable: !1,
writable: !0,
configurable: !0
}
}), t && (Object.setPrototypeOf ? Object.setPrototypeOf(e, t) : e.__proto__ = t)
},
C = function(e, t) {
if (!e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
return !t || "object" != typeof t && "function" != typeof t ? e : t
},
k = function() {
function e(t) {
y(this, e), this.element = t
}
return b(e, [{
key: "bind",
value: function(e, t) {
this.element.addEventListener(e, t, !1)
}
}, {
key: "unbind",
value: function(e, t) {
this.element.removeEventListener(e, t, !1)
}
}, {
key: "style",
value: function(e, t) {
if ("string" == typeof e) this.element.style[e] = t;
else
for (var n in e) e.hasOwnProperty(n) && (this.element.style[n] = e[n])
}
}, {
key: "addClass",
value: function(e) {
n(this.element, "add", e)
}
}, {
key: "removeClass",
value: function(e) {
n(this.element, "remove", e)
}
}, {
key: "html",
value: function(e) {
if (!e) return o(this.element, "innerHTML");
i(this.element, "innerHTML", e)
}
}, {
key: "scrollTop",
value: function(e) {
if (!e) return o(this.element, "scrollTop");
i(this.element, "scrollTop", e)
}
}, {
key: "offsetWidth",
value: function() {
return this.element.offsetWidth
}
}]), e
}(),
O = "sidr-animating",
w = function(e) {
function t(e, n) {
y(this, t);
var i = C(this, (t.__proto__ || Object.getPrototypeOf(t)).call(this, v.qs(e.body)));
return i.name = e.name, i.side = e.side, i.speed = e.speed, i.timing = e.timing, i.displace = e.displace, i.menuWidth = n, i
}
return g(t, k), b(t, [{
key: "prepare",
value: function(e) {
var t = "open" === e ? "hidden" : "";
if (s(this.element)) {
var n = new k(v.qs("html")),
i = n.scrollTop();
n.style("overflowX", t), n.scrollTop(i)
}
}
}, {
key: "unprepare",
value: function() {
if (s(this.element)) {
new k(v.qs("html")).style("overflowX", "")
}
}
}, {
key: "move",
value: function(e) {
this.addClass(O), "open" === e ? this.open() : this.close()
}
}, {
key: "open",
value: function() {
var e = this;
if (this.displace) {
var t = v.transitions,
n = {
width: this.offsetWidth() + "px",
position: "absolute"
};
this.style(this.side, "0"), this.style(t.cssProperty, this.side + " " + this.speed / 1e3 + "s " + this.timing), this.style(n), setTimeout(function() {
return e.style(e.side, e.menuWidth + "px")
}, 1)
}
}
}, {
key: "onClose",
value: function() {
var e = v.transitions,
t = {
width: "",
position: "",
right: "",
left: ""
};
t[e.cssProperty] = "", this.style(t), this.unbind(e.event, this.temporalCallback)
}
}, {
key: "close",
value: function() {
if (this.displace) {
var e = v.transitions;
this.style(this.side, 0);
var t = this;
this.temporalCallback = function() {
t.onClose()
}, this.bind(e.event, this.temporalCallback)
}
}
}, {
key: "removeAnimationClass",
value: function() {
this.removeClass(O)
}
}, {
key: "removeOpenClass",
value: function() {
this.removeClass(r(this.name))
}
}, {
key: "addOpenClass",
value: function() {
this.addClass(r(this.name))
}
}]), t
}(),
M = function(e) {
function t(e) {
y(this, t);
var n = C(this, (t.__proto__ || Object.getPrototypeOf(t)).call(this, v.id(e.name)));
return n.name = e.name, n.speed = e.speed, n.side = e.side, n.displace = e.displace, n.source = e.source, n.timing = e.timing, n.method = e.method, n.renaming = e.renaming, n.onOpenCallback = e.onOpen, n.onCloseCallback = e.onClose, n.onOpenEndCallback = e.onOpenEnd, n.onCloseEndCallback = e.onCloseEnd, n.init(e), n
}
return g(t, k), b(t, [{
key: "init",
value: function(e) {
this.element || (this.element = v.createElement(this.name)), this.style(v.transitions.cssProperty, this.side + " " + this.speed / 1e3 + "s " + this.timing), this.addClass("sidr sidr-" + this.side), this.body = new w(e, this.offsetWidth()), this.reload()
}
}, {
key: "reload",
value: function() {
var e = this;
if ("function" == typeof this.source) {
var t = this.source(name);
this.html(t)
} else if ("string" == typeof this.source && m.isUrl(this.source)) m.fetch(this.source, function(t) {
e.html(t)
});
else if ("string" == typeof this.source) {
var n = v.getHTMLContent(this.source);
this.renaming && (n = v.addPrefixes(n)), this.html(n)
} else null !== this.source && console.error("Invalid Sidr Source")
}
}, {
key: "move",
value: function(e, t) {
a.moving = !0, this.body.prepare(e), this.body.move(e), this.moveMenu(e, t)
}
}, {
key: "open",
value: function(e) {
var t = this;
if (a.opened !== this.name && !a.moving)
if (!1 === a.opened) this.move("open", e), this.onOpenCallback();
else {
u.get(a.opened).close(function() {
t.open(e)
})
}
}
}, {
key: "close",
value: function(e) {
a.opened !== this.name || a.moving || (this.move("close", e), this.onCloseCallback())
}
}, {
key: "toggle",
value: function(e) {
a.opened === this.name ? this.close(e) : this.open(e)
}
}, {
key: "onOpenMenu",
value: function(e) {
var t = this.name;
a.moving = !1, a.opened = t, this.unbind(v.transitions.event, this.temporalOpenMenuCallback), this.body.removeAnimationClass(), this.body.addOpenClass(), this.onOpenEndCallback(), "function" == typeof e && e(t)
}
}, {
key: "openMenu",
value: function(e) {
var t = this;
this.style(this.side, 0), this.temporalOpenMenuCallback = function() {
t.onOpenMenu(e)
}, this.bind(v.transitions.event, this.temporalOpenMenuCallback)
}
}, {
key: "onCloseMenu",
value: function(e) {
this.unbind(v.transitions.event, this.temporalCloseMenuCallback), this.style({
left: "",
right: ""
}), this.body.unprepare(), a.moving = !1, a.opened = !1, this.body.removeAnimationClass(), this.body.removeOpenClass(), this.onCloseEndCallback(), "function" == typeof e && e(name)
}
}, {
key: "closeMenu",
value: function(e) {
var t = this;
this.style(this.side, ""), this.temporalCloseMenuCallback = function() {
t.onCloseMenu(e)
}, this.bind(v.transitions.event, this.temporalCloseMenuCallback)
}
}, {
key: "moveMenu",
value: function(e, t) {
"open" === e ? this.openMenu(t) : this.closeMenu(t)
}
}]), t
}(),
E = function(t) {
function n(e, t) {
y(this, n);
var i = C(this, (n.__proto__ || Object.getPrototypeOf(n)).call(this, e));
return i.init(t), i
}
return g(n, k), b(n, [{
key: "init",
value: function(t) {
if (!this.element.getAttribute("data-sidr")) {
var n = t.name,
i = t.method,
o = t.bind;
this.element.setAttribute("data-sidr", n), this.bind(o, function(t) {
t.preventDefault(), e(i, n)
})
}
}
}]), n
}(),
_ = {
name: "sidr",
speed: 200,
side: "left",
source: null,
renaming: !0,
body: "body",
displace: !0,
timing: "ease",
method: "toggle",
bind: "click",
onOpen: function() {},
onClose: function() {},
onOpenEnd: function() {},
onCloseEnd: function() {}
};
jQuery.sidr = e, jQuery.fn.sidr = function(e) {
var t = m.extend(_, e);
return u.add(t.name, new M(t)), this.each(function() {
new E(this, t)
})
}
}();