github.com/mithrandie/csvq@v1.18.1/docs/assets/js/materialize.js (about) 1 /*! 2 * Materialize v0.100.2 (http://materializecss.com) 3 * Copyright 2014-2017 Materialize 4 * MIT License (https://raw.githubusercontent.com/Dogfalo/materialize/master/LICENSE) 5 */ 6 var _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; }; }(); 7 8 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 9 10 // Check for jQuery. 11 if (typeof jQuery === 'undefined') { 12 // Check if require is a defined function. 13 if (typeof require === 'function') { 14 jQuery = $ = require('jquery'); 15 // Else use the dollar sign alias. 16 } else { 17 jQuery = $; 18 } 19 } 20 ; /* 21 * jQuery Easing v1.4.0 - http://gsgd.co.uk/sandbox/jquery/easing/ 22 * Open source under the BSD License. 23 * Copyright © 2008 George McGinley Smith 24 * All rights reserved. 25 * https://raw.github.com/gdsmith/jquery-easing/master/LICENSE 26 */ 27 28 (function (factory) { 29 if (typeof define === "function" && define.amd) { 30 define(['jquery'], function ($) { 31 return factory($); 32 }); 33 } else if (typeof module === "object" && typeof module.exports === "object") { 34 exports = factory(require('jquery')); 35 } else { 36 factory(jQuery); 37 } 38 })(function ($) { 39 40 // Preserve the original jQuery "swing" easing as "jswing" 41 $.easing['jswing'] = $.easing['swing']; 42 43 var pow = Math.pow, 44 sqrt = Math.sqrt, 45 sin = Math.sin, 46 cos = Math.cos, 47 PI = Math.PI, 48 c1 = 1.70158, 49 c2 = c1 * 1.525, 50 c3 = c1 + 1, 51 c4 = 2 * PI / 3, 52 c5 = 2 * PI / 4.5; 53 54 // x is the fraction of animation progress, in the range 0..1 55 function bounceOut(x) { 56 var n1 = 7.5625, 57 d1 = 2.75; 58 if (x < 1 / d1) { 59 return n1 * x * x; 60 } else if (x < 2 / d1) { 61 return n1 * (x -= 1.5 / d1) * x + .75; 62 } else if (x < 2.5 / d1) { 63 return n1 * (x -= 2.25 / d1) * x + .9375; 64 } else { 65 return n1 * (x -= 2.625 / d1) * x + .984375; 66 } 67 } 68 69 $.extend($.easing, { 70 def: 'easeOutQuad', 71 swing: function (x) { 72 return $.easing[$.easing.def](x); 73 }, 74 easeInQuad: function (x) { 75 return x * x; 76 }, 77 easeOutQuad: function (x) { 78 return 1 - (1 - x) * (1 - x); 79 }, 80 easeInOutQuad: function (x) { 81 return x < 0.5 ? 2 * x * x : 1 - pow(-2 * x + 2, 2) / 2; 82 }, 83 easeInCubic: function (x) { 84 return x * x * x; 85 }, 86 easeOutCubic: function (x) { 87 return 1 - pow(1 - x, 3); 88 }, 89 easeInOutCubic: function (x) { 90 return x < 0.5 ? 4 * x * x * x : 1 - pow(-2 * x + 2, 3) / 2; 91 }, 92 easeInQuart: function (x) { 93 return x * x * x * x; 94 }, 95 easeOutQuart: function (x) { 96 return 1 - pow(1 - x, 4); 97 }, 98 easeInOutQuart: function (x) { 99 return x < 0.5 ? 8 * x * x * x * x : 1 - pow(-2 * x + 2, 4) / 2; 100 }, 101 easeInQuint: function (x) { 102 return x * x * x * x * x; 103 }, 104 easeOutQuint: function (x) { 105 return 1 - pow(1 - x, 5); 106 }, 107 easeInOutQuint: function (x) { 108 return x < 0.5 ? 16 * x * x * x * x * x : 1 - pow(-2 * x + 2, 5) / 2; 109 }, 110 easeInSine: function (x) { 111 return 1 - cos(x * PI / 2); 112 }, 113 easeOutSine: function (x) { 114 return sin(x * PI / 2); 115 }, 116 easeInOutSine: function (x) { 117 return -(cos(PI * x) - 1) / 2; 118 }, 119 easeInExpo: function (x) { 120 return x === 0 ? 0 : pow(2, 10 * x - 10); 121 }, 122 easeOutExpo: function (x) { 123 return x === 1 ? 1 : 1 - pow(2, -10 * x); 124 }, 125 easeInOutExpo: function (x) { 126 return x === 0 ? 0 : x === 1 ? 1 : x < 0.5 ? pow(2, 20 * x - 10) / 2 : (2 - pow(2, -20 * x + 10)) / 2; 127 }, 128 easeInCirc: function (x) { 129 return 1 - sqrt(1 - pow(x, 2)); 130 }, 131 easeOutCirc: function (x) { 132 return sqrt(1 - pow(x - 1, 2)); 133 }, 134 easeInOutCirc: function (x) { 135 return x < 0.5 ? (1 - sqrt(1 - pow(2 * x, 2))) / 2 : (sqrt(1 - pow(-2 * x + 2, 2)) + 1) / 2; 136 }, 137 easeInElastic: function (x) { 138 return x === 0 ? 0 : x === 1 ? 1 : -pow(2, 10 * x - 10) * sin((x * 10 - 10.75) * c4); 139 }, 140 easeOutElastic: function (x) { 141 return x === 0 ? 0 : x === 1 ? 1 : pow(2, -10 * x) * sin((x * 10 - 0.75) * c4) + 1; 142 }, 143 easeInOutElastic: function (x) { 144 return x === 0 ? 0 : x === 1 ? 1 : x < 0.5 ? -(pow(2, 20 * x - 10) * sin((20 * x - 11.125) * c5)) / 2 : pow(2, -20 * x + 10) * sin((20 * x - 11.125) * c5) / 2 + 1; 145 }, 146 easeInBack: function (x) { 147 return c3 * x * x * x - c1 * x * x; 148 }, 149 easeOutBack: function (x) { 150 return 1 + c3 * pow(x - 1, 3) + c1 * pow(x - 1, 2); 151 }, 152 easeInOutBack: function (x) { 153 return x < 0.5 ? pow(2 * x, 2) * ((c2 + 1) * 2 * x - c2) / 2 : (pow(2 * x - 2, 2) * ((c2 + 1) * (x * 2 - 2) + c2) + 2) / 2; 154 }, 155 easeInBounce: function (x) { 156 return 1 - bounceOut(1 - x); 157 }, 158 easeOutBounce: bounceOut, 159 easeInOutBounce: function (x) { 160 return x < 0.5 ? (1 - bounceOut(1 - 2 * x)) / 2 : (1 + bounceOut(2 * x - 1)) / 2; 161 } 162 }); 163 });; // Custom Easing 164 jQuery.extend(jQuery.easing, { 165 easeInOutMaterial: function (x, t, b, c, d) { 166 if ((t /= d / 2) < 1) return c / 2 * t * t + b; 167 return c / 4 * ((t -= 2) * t * t + 2) + b; 168 } 169 });; /*! VelocityJS.org (1.2.3). (C) 2014 Julian Shapiro. MIT @license: en.wikipedia.org/wiki/MIT_License */ 170 /*! VelocityJS.org jQuery Shim (1.0.1). (C) 2014 The jQuery Foundation. MIT @license: en.wikipedia.org/wiki/MIT_License. */ 171 /*! Note that this has been modified by Materialize to confirm that Velocity is not already being imported. */ 172 jQuery.Velocity ? console.log("Velocity is already loaded. You may be needlessly importing Velocity again; note that Materialize includes Velocity.") : (!function (e) { 173 function t(e) { 174 var t = e.length, 175 a = r.type(e);return "function" === a || r.isWindow(e) ? !1 : 1 === e.nodeType && t ? !0 : "array" === a || 0 === t || "number" == typeof t && t > 0 && t - 1 in e; 176 }if (!e.jQuery) { 177 var r = function (e, t) { 178 return new r.fn.init(e, t); 179 };r.isWindow = function (e) { 180 return null != e && e == e.window; 181 }, r.type = function (e) { 182 return null == e ? e + "" : "object" == typeof e || "function" == typeof e ? n[i.call(e)] || "object" : typeof e; 183 }, r.isArray = Array.isArray || function (e) { 184 return "array" === r.type(e); 185 }, r.isPlainObject = function (e) { 186 var t;if (!e || "object" !== r.type(e) || e.nodeType || r.isWindow(e)) return !1;try { 187 if (e.constructor && !o.call(e, "constructor") && !o.call(e.constructor.prototype, "isPrototypeOf")) return !1; 188 } catch (a) { 189 return !1; 190 }for (t in e) {}return void 0 === t || o.call(e, t); 191 }, r.each = function (e, r, a) { 192 var n, 193 o = 0, 194 i = e.length, 195 s = t(e);if (a) { 196 if (s) for (; i > o && (n = r.apply(e[o], a), n !== !1); o++) {} else for (o in e) { 197 if (n = r.apply(e[o], a), n === !1) break; 198 } 199 } else if (s) for (; i > o && (n = r.call(e[o], o, e[o]), n !== !1); o++) {} else for (o in e) { 200 if (n = r.call(e[o], o, e[o]), n === !1) break; 201 }return e; 202 }, r.data = function (e, t, n) { 203 if (void 0 === n) { 204 var o = e[r.expando], 205 i = o && a[o];if (void 0 === t) return i;if (i && t in i) return i[t]; 206 } else if (void 0 !== t) { 207 var o = e[r.expando] || (e[r.expando] = ++r.uuid);return a[o] = a[o] || {}, a[o][t] = n, n; 208 } 209 }, r.removeData = function (e, t) { 210 var n = e[r.expando], 211 o = n && a[n];o && r.each(t, function (e, t) { 212 delete o[t]; 213 }); 214 }, r.extend = function () { 215 var e, 216 t, 217 a, 218 n, 219 o, 220 i, 221 s = arguments[0] || {}, 222 l = 1, 223 u = arguments.length, 224 c = !1;for ("boolean" == typeof s && (c = s, s = arguments[l] || {}, l++), "object" != typeof s && "function" !== r.type(s) && (s = {}), l === u && (s = this, l--); u > l; l++) { 225 if (null != (o = arguments[l])) for (n in o) { 226 e = s[n], a = o[n], s !== a && (c && a && (r.isPlainObject(a) || (t = r.isArray(a))) ? (t ? (t = !1, i = e && r.isArray(e) ? e : []) : i = e && r.isPlainObject(e) ? e : {}, s[n] = r.extend(c, i, a)) : void 0 !== a && (s[n] = a)); 227 } 228 }return s; 229 }, r.queue = function (e, a, n) { 230 function o(e, r) { 231 var a = r || [];return null != e && (t(Object(e)) ? !function (e, t) { 232 for (var r = +t.length, a = 0, n = e.length; r > a;) { 233 e[n++] = t[a++]; 234 }if (r !== r) for (; void 0 !== t[a];) { 235 e[n++] = t[a++]; 236 }return e.length = n, e; 237 }(a, "string" == typeof e ? [e] : e) : [].push.call(a, e)), a; 238 }if (e) { 239 a = (a || "fx") + "queue";var i = r.data(e, a);return n ? (!i || r.isArray(n) ? i = r.data(e, a, o(n)) : i.push(n), i) : i || []; 240 } 241 }, r.dequeue = function (e, t) { 242 r.each(e.nodeType ? [e] : e, function (e, a) { 243 t = t || "fx";var n = r.queue(a, t), 244 o = n.shift();"inprogress" === o && (o = n.shift()), o && ("fx" === t && n.unshift("inprogress"), o.call(a, function () { 245 r.dequeue(a, t); 246 })); 247 }); 248 }, r.fn = r.prototype = { init: function (e) { 249 if (e.nodeType) return this[0] = e, this;throw new Error("Not a DOM node."); 250 }, offset: function () { 251 var t = this[0].getBoundingClientRect ? this[0].getBoundingClientRect() : { top: 0, left: 0 };return { top: t.top + (e.pageYOffset || document.scrollTop || 0) - (document.clientTop || 0), left: t.left + (e.pageXOffset || document.scrollLeft || 0) - (document.clientLeft || 0) }; 252 }, position: function () { 253 function e() { 254 for (var e = this.offsetParent || document; e && "html" === !e.nodeType.toLowerCase && "static" === e.style.position;) { 255 e = e.offsetParent; 256 }return e || document; 257 }var t = this[0], 258 e = e.apply(t), 259 a = this.offset(), 260 n = /^(?:body|html)$/i.test(e.nodeName) ? { top: 0, left: 0 } : r(e).offset();return a.top -= parseFloat(t.style.marginTop) || 0, a.left -= parseFloat(t.style.marginLeft) || 0, e.style && (n.top += parseFloat(e.style.borderTopWidth) || 0, n.left += parseFloat(e.style.borderLeftWidth) || 0), { top: a.top - n.top, left: a.left - n.left }; 261 } };var a = {};r.expando = "velocity" + new Date().getTime(), r.uuid = 0;for (var n = {}, o = n.hasOwnProperty, i = n.toString, s = "Boolean Number String Function Array Date RegExp Object Error".split(" "), l = 0; l < s.length; l++) { 262 n["[object " + s[l] + "]"] = s[l].toLowerCase(); 263 }r.fn.init.prototype = r.fn, e.Velocity = { Utilities: r }; 264 } 265 }(window), function (e) { 266 "object" == typeof module && "object" == typeof module.exports ? module.exports = e() : "function" == typeof define && define.amd ? define(e) : e(); 267 }(function () { 268 return function (e, t, r, a) { 269 function n(e) { 270 for (var t = -1, r = e ? e.length : 0, a = []; ++t < r;) { 271 var n = e[t];n && a.push(n); 272 }return a; 273 }function o(e) { 274 return m.isWrapped(e) ? e = [].slice.call(e) : m.isNode(e) && (e = [e]), e; 275 }function i(e) { 276 var t = f.data(e, "velocity");return null === t ? a : t; 277 }function s(e) { 278 return function (t) { 279 return Math.round(t * e) * (1 / e); 280 }; 281 }function l(e, r, a, n) { 282 function o(e, t) { 283 return 1 - 3 * t + 3 * e; 284 }function i(e, t) { 285 return 3 * t - 6 * e; 286 }function s(e) { 287 return 3 * e; 288 }function l(e, t, r) { 289 return ((o(t, r) * e + i(t, r)) * e + s(t)) * e; 290 }function u(e, t, r) { 291 return 3 * o(t, r) * e * e + 2 * i(t, r) * e + s(t); 292 }function c(t, r) { 293 for (var n = 0; m > n; ++n) { 294 var o = u(r, e, a);if (0 === o) return r;var i = l(r, e, a) - t;r -= i / o; 295 }return r; 296 }function p() { 297 for (var t = 0; b > t; ++t) { 298 w[t] = l(t * x, e, a); 299 } 300 }function f(t, r, n) { 301 var o, 302 i, 303 s = 0;do { 304 i = r + (n - r) / 2, o = l(i, e, a) - t, o > 0 ? n = i : r = i; 305 } while (Math.abs(o) > h && ++s < v);return i; 306 }function d(t) { 307 for (var r = 0, n = 1, o = b - 1; n != o && w[n] <= t; ++n) { 308 r += x; 309 }--n;var i = (t - w[n]) / (w[n + 1] - w[n]), 310 s = r + i * x, 311 l = u(s, e, a);return l >= y ? c(t, s) : 0 == l ? s : f(t, r, r + x); 312 }function g() { 313 V = !0, (e != r || a != n) && p(); 314 }var m = 4, 315 y = .001, 316 h = 1e-7, 317 v = 10, 318 b = 11, 319 x = 1 / (b - 1), 320 S = "Float32Array" in t;if (4 !== arguments.length) return !1;for (var P = 0; 4 > P; ++P) { 321 if ("number" != typeof arguments[P] || isNaN(arguments[P]) || !isFinite(arguments[P])) return !1; 322 }e = Math.min(e, 1), a = Math.min(a, 1), e = Math.max(e, 0), a = Math.max(a, 0);var w = S ? new Float32Array(b) : new Array(b), 323 V = !1, 324 C = function (t) { 325 return V || g(), e === r && a === n ? t : 0 === t ? 0 : 1 === t ? 1 : l(d(t), r, n); 326 };C.getControlPoints = function () { 327 return [{ x: e, y: r }, { x: a, y: n }]; 328 };var T = "generateBezier(" + [e, r, a, n] + ")";return C.toString = function () { 329 return T; 330 }, C; 331 }function u(e, t) { 332 var r = e;return m.isString(e) ? b.Easings[e] || (r = !1) : r = m.isArray(e) && 1 === e.length ? s.apply(null, e) : m.isArray(e) && 2 === e.length ? x.apply(null, e.concat([t])) : m.isArray(e) && 4 === e.length ? l.apply(null, e) : !1, r === !1 && (r = b.Easings[b.defaults.easing] ? b.defaults.easing : v), r; 333 }function c(e) { 334 if (e) { 335 var t = new Date().getTime(), 336 r = b.State.calls.length;r > 1e4 && (b.State.calls = n(b.State.calls));for (var o = 0; r > o; o++) { 337 if (b.State.calls[o]) { 338 var s = b.State.calls[o], 339 l = s[0], 340 u = s[2], 341 d = s[3], 342 g = !!d, 343 y = null;d || (d = b.State.calls[o][3] = t - 16);for (var h = Math.min((t - d) / u.duration, 1), v = 0, x = l.length; x > v; v++) { 344 var P = l[v], 345 V = P.element;if (i(V)) { 346 var C = !1;if (u.display !== a && null !== u.display && "none" !== u.display) { 347 if ("flex" === u.display) { 348 var T = ["-webkit-box", "-moz-box", "-ms-flexbox", "-webkit-flex"];f.each(T, function (e, t) { 349 S.setPropertyValue(V, "display", t); 350 }); 351 }S.setPropertyValue(V, "display", u.display); 352 }u.visibility !== a && "hidden" !== u.visibility && S.setPropertyValue(V, "visibility", u.visibility);for (var k in P) { 353 if ("element" !== k) { 354 var A, 355 F = P[k], 356 j = m.isString(F.easing) ? b.Easings[F.easing] : F.easing;if (1 === h) A = F.endValue;else { 357 var E = F.endValue - F.startValue;if (A = F.startValue + E * j(h, u, E), !g && A === F.currentValue) continue; 358 }if (F.currentValue = A, "tween" === k) y = A;else { 359 if (S.Hooks.registered[k]) { 360 var H = S.Hooks.getRoot(k), 361 N = i(V).rootPropertyValueCache[H];N && (F.rootPropertyValue = N); 362 }var L = S.setPropertyValue(V, k, F.currentValue + (0 === parseFloat(A) ? "" : F.unitType), F.rootPropertyValue, F.scrollData);S.Hooks.registered[k] && (i(V).rootPropertyValueCache[H] = S.Normalizations.registered[H] ? S.Normalizations.registered[H]("extract", null, L[1]) : L[1]), "transform" === L[0] && (C = !0); 363 } 364 } 365 }u.mobileHA && i(V).transformCache.translate3d === a && (i(V).transformCache.translate3d = "(0px, 0px, 0px)", C = !0), C && S.flushTransformCache(V); 366 } 367 }u.display !== a && "none" !== u.display && (b.State.calls[o][2].display = !1), u.visibility !== a && "hidden" !== u.visibility && (b.State.calls[o][2].visibility = !1), u.progress && u.progress.call(s[1], s[1], h, Math.max(0, d + u.duration - t), d, y), 1 === h && p(o); 368 } 369 } 370 }b.State.isTicking && w(c); 371 }function p(e, t) { 372 if (!b.State.calls[e]) return !1;for (var r = b.State.calls[e][0], n = b.State.calls[e][1], o = b.State.calls[e][2], s = b.State.calls[e][4], l = !1, u = 0, c = r.length; c > u; u++) { 373 var p = r[u].element;if (t || o.loop || ("none" === o.display && S.setPropertyValue(p, "display", o.display), "hidden" === o.visibility && S.setPropertyValue(p, "visibility", o.visibility)), o.loop !== !0 && (f.queue(p)[1] === a || !/\.velocityQueueEntryFlag/i.test(f.queue(p)[1])) && i(p)) { 374 i(p).isAnimating = !1, i(p).rootPropertyValueCache = {};var d = !1;f.each(S.Lists.transforms3D, function (e, t) { 375 var r = /^scale/.test(t) ? 1 : 0, 376 n = i(p).transformCache[t];i(p).transformCache[t] !== a && new RegExp("^\\(" + r + "[^.]").test(n) && (d = !0, delete i(p).transformCache[t]); 377 }), o.mobileHA && (d = !0, delete i(p).transformCache.translate3d), d && S.flushTransformCache(p), S.Values.removeClass(p, "velocity-animating"); 378 }if (!t && o.complete && !o.loop && u === c - 1) try { 379 o.complete.call(n, n); 380 } catch (g) { 381 setTimeout(function () { 382 throw g; 383 }, 1); 384 }s && o.loop !== !0 && s(n), i(p) && o.loop === !0 && !t && (f.each(i(p).tweensContainer, function (e, t) { 385 /^rotate/.test(e) && 360 === parseFloat(t.endValue) && (t.endValue = 0, t.startValue = 360), /^backgroundPosition/.test(e) && 100 === parseFloat(t.endValue) && "%" === t.unitType && (t.endValue = 0, t.startValue = 100); 386 }), b(p, "reverse", { loop: !0, delay: o.delay })), o.queue !== !1 && f.dequeue(p, o.queue); 387 }b.State.calls[e] = !1;for (var m = 0, y = b.State.calls.length; y > m; m++) { 388 if (b.State.calls[m] !== !1) { 389 l = !0;break; 390 } 391 }l === !1 && (b.State.isTicking = !1, delete b.State.calls, b.State.calls = []); 392 }var f, 393 d = function () { 394 if (r.documentMode) return r.documentMode;for (var e = 7; e > 4; e--) { 395 var t = r.createElement("div");if (t.innerHTML = "<!--[if IE " + e + "]><span></span><![endif]-->", t.getElementsByTagName("span").length) return t = null, e; 396 }return a; 397 }(), 398 g = function () { 399 var e = 0;return t.webkitRequestAnimationFrame || t.mozRequestAnimationFrame || function (t) { 400 var r, 401 a = new Date().getTime();return r = Math.max(0, 16 - (a - e)), e = a + r, setTimeout(function () { 402 t(a + r); 403 }, r); 404 }; 405 }(), 406 m = { isString: function (e) { 407 return "string" == typeof e; 408 }, isArray: Array.isArray || function (e) { 409 return "[object Array]" === Object.prototype.toString.call(e); 410 }, isFunction: function (e) { 411 return "[object Function]" === Object.prototype.toString.call(e); 412 }, isNode: function (e) { 413 return e && e.nodeType; 414 }, isNodeList: function (e) { 415 return "object" == typeof e && /^\[object (HTMLCollection|NodeList|Object)\]$/.test(Object.prototype.toString.call(e)) && e.length !== a && (0 === e.length || "object" == typeof e[0] && e[0].nodeType > 0); 416 }, isWrapped: function (e) { 417 return e && (e.jquery || t.Zepto && t.Zepto.zepto.isZ(e)); 418 }, isSVG: function (e) { 419 return t.SVGElement && e instanceof t.SVGElement; 420 }, isEmptyObject: function (e) { 421 for (var t in e) { 422 return !1; 423 }return !0; 424 } }, 425 y = !1;if (e.fn && e.fn.jquery ? (f = e, y = !0) : f = t.Velocity.Utilities, 8 >= d && !y) throw new Error("Velocity: IE8 and below require jQuery to be loaded before Velocity.");if (7 >= d) return void (jQuery.fn.velocity = jQuery.fn.animate);var h = 400, 426 v = "swing", 427 b = { State: { isMobile: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent), isAndroid: /Android/i.test(navigator.userAgent), isGingerbread: /Android 2\.3\.[3-7]/i.test(navigator.userAgent), isChrome: t.chrome, isFirefox: /Firefox/i.test(navigator.userAgent), prefixElement: r.createElement("div"), prefixMatches: {}, scrollAnchor: null, scrollPropertyLeft: null, scrollPropertyTop: null, isTicking: !1, calls: [] }, CSS: {}, Utilities: f, Redirects: {}, Easings: {}, Promise: t.Promise, defaults: { queue: "", duration: h, easing: v, begin: a, complete: a, progress: a, display: a, visibility: a, loop: !1, delay: !1, mobileHA: !0, _cacheValues: !0 }, init: function (e) { 428 f.data(e, "velocity", { isSVG: m.isSVG(e), isAnimating: !1, computedStyle: null, tweensContainer: null, rootPropertyValueCache: {}, transformCache: {} }); 429 }, hook: null, mock: !1, version: { major: 1, minor: 2, patch: 2 }, debug: !1 };t.pageYOffset !== a ? (b.State.scrollAnchor = t, b.State.scrollPropertyLeft = "pageXOffset", b.State.scrollPropertyTop = "pageYOffset") : (b.State.scrollAnchor = r.documentElement || r.body.parentNode || r.body, b.State.scrollPropertyLeft = "scrollLeft", b.State.scrollPropertyTop = "scrollTop");var x = function () { 430 function e(e) { 431 return -e.tension * e.x - e.friction * e.v; 432 }function t(t, r, a) { 433 var n = { x: t.x + a.dx * r, v: t.v + a.dv * r, tension: t.tension, friction: t.friction };return { dx: n.v, dv: e(n) }; 434 }function r(r, a) { 435 var n = { dx: r.v, dv: e(r) }, 436 o = t(r, .5 * a, n), 437 i = t(r, .5 * a, o), 438 s = t(r, a, i), 439 l = 1 / 6 * (n.dx + 2 * (o.dx + i.dx) + s.dx), 440 u = 1 / 6 * (n.dv + 2 * (o.dv + i.dv) + s.dv);return r.x = r.x + l * a, r.v = r.v + u * a, r; 441 }return function a(e, t, n) { 442 var o, 443 i, 444 s, 445 l = { x: -1, v: 0, tension: null, friction: null }, 446 u = [0], 447 c = 0, 448 p = 1e-4, 449 f = .016;for (e = parseFloat(e) || 500, t = parseFloat(t) || 20, n = n || null, l.tension = e, l.friction = t, o = null !== n, o ? (c = a(e, t), i = c / n * f) : i = f; s = r(s || l, i), u.push(1 + s.x), c += 16, Math.abs(s.x) > p && Math.abs(s.v) > p;) {}return o ? function (e) { 450 return u[e * (u.length - 1) | 0]; 451 } : c; 452 }; 453 }();b.Easings = { linear: function (e) { 454 return e; 455 }, swing: function (e) { 456 return .5 - Math.cos(e * Math.PI) / 2; 457 }, spring: function (e) { 458 return 1 - Math.cos(4.5 * e * Math.PI) * Math.exp(6 * -e); 459 } }, f.each([["ease", [.25, .1, .25, 1]], ["ease-in", [.42, 0, 1, 1]], ["ease-out", [0, 0, .58, 1]], ["ease-in-out", [.42, 0, .58, 1]], ["easeInSine", [.47, 0, .745, .715]], ["easeOutSine", [.39, .575, .565, 1]], ["easeInOutSine", [.445, .05, .55, .95]], ["easeInQuad", [.55, .085, .68, .53]], ["easeOutQuad", [.25, .46, .45, .94]], ["easeInOutQuad", [.455, .03, .515, .955]], ["easeInCubic", [.55, .055, .675, .19]], ["easeOutCubic", [.215, .61, .355, 1]], ["easeInOutCubic", [.645, .045, .355, 1]], ["easeInQuart", [.895, .03, .685, .22]], ["easeOutQuart", [.165, .84, .44, 1]], ["easeInOutQuart", [.77, 0, .175, 1]], ["easeInQuint", [.755, .05, .855, .06]], ["easeOutQuint", [.23, 1, .32, 1]], ["easeInOutQuint", [.86, 0, .07, 1]], ["easeInExpo", [.95, .05, .795, .035]], ["easeOutExpo", [.19, 1, .22, 1]], ["easeInOutExpo", [1, 0, 0, 1]], ["easeInCirc", [.6, .04, .98, .335]], ["easeOutCirc", [.075, .82, .165, 1]], ["easeInOutCirc", [.785, .135, .15, .86]]], function (e, t) { 460 b.Easings[t[0]] = l.apply(null, t[1]); 461 });var S = b.CSS = { RegEx: { isHex: /^#([A-f\d]{3}){1,2}$/i, valueUnwrap: /^[A-z]+\((.*)\)$/i, wrappedValueAlreadyExtracted: /[0-9.]+ [0-9.]+ [0-9.]+( [0-9.]+)?/, valueSplit: /([A-z]+\(.+\))|(([A-z0-9#-.]+?)(?=\s|$))/gi }, Lists: { colors: ["fill", "stroke", "stopColor", "color", "backgroundColor", "borderColor", "borderTopColor", "borderRightColor", "borderBottomColor", "borderLeftColor", "outlineColor"], transformsBase: ["translateX", "translateY", "scale", "scaleX", "scaleY", "skewX", "skewY", "rotateZ"], transforms3D: ["transformPerspective", "translateZ", "scaleZ", "rotateX", "rotateY"] }, Hooks: { templates: { textShadow: ["Color X Y Blur", "black 0px 0px 0px"], boxShadow: ["Color X Y Blur Spread", "black 0px 0px 0px 0px"], clip: ["Top Right Bottom Left", "0px 0px 0px 0px"], backgroundPosition: ["X Y", "0% 0%"], transformOrigin: ["X Y Z", "50% 50% 0px"], perspectiveOrigin: ["X Y", "50% 50%"] }, registered: {}, register: function () { 462 for (var e = 0; e < S.Lists.colors.length; e++) { 463 var t = "color" === S.Lists.colors[e] ? "0 0 0 1" : "255 255 255 1";S.Hooks.templates[S.Lists.colors[e]] = ["Red Green Blue Alpha", t]; 464 }var r, a, n;if (d) for (r in S.Hooks.templates) { 465 a = S.Hooks.templates[r], n = a[0].split(" ");var o = a[1].match(S.RegEx.valueSplit);"Color" === n[0] && (n.push(n.shift()), o.push(o.shift()), S.Hooks.templates[r] = [n.join(" "), o.join(" ")]); 466 }for (r in S.Hooks.templates) { 467 a = S.Hooks.templates[r], n = a[0].split(" ");for (var e in n) { 468 var i = r + n[e], 469 s = e;S.Hooks.registered[i] = [r, s]; 470 } 471 } 472 }, getRoot: function (e) { 473 var t = S.Hooks.registered[e];return t ? t[0] : e; 474 }, cleanRootPropertyValue: function (e, t) { 475 return S.RegEx.valueUnwrap.test(t) && (t = t.match(S.RegEx.valueUnwrap)[1]), S.Values.isCSSNullValue(t) && (t = S.Hooks.templates[e][1]), t; 476 }, extractValue: function (e, t) { 477 var r = S.Hooks.registered[e];if (r) { 478 var a = r[0], 479 n = r[1];return t = S.Hooks.cleanRootPropertyValue(a, t), t.toString().match(S.RegEx.valueSplit)[n]; 480 }return t; 481 }, injectValue: function (e, t, r) { 482 var a = S.Hooks.registered[e];if (a) { 483 var n, 484 o, 485 i = a[0], 486 s = a[1];return r = S.Hooks.cleanRootPropertyValue(i, r), n = r.toString().match(S.RegEx.valueSplit), n[s] = t, o = n.join(" "); 487 }return r; 488 } }, Normalizations: { registered: { clip: function (e, t, r) { 489 switch (e) {case "name": 490 return "clip";case "extract": 491 var a;return S.RegEx.wrappedValueAlreadyExtracted.test(r) ? a = r : (a = r.toString().match(S.RegEx.valueUnwrap), a = a ? a[1].replace(/,(\s+)?/g, " ") : r), a;case "inject": 492 return "rect(" + r + ")";} 493 }, blur: function (e, t, r) { 494 switch (e) {case "name": 495 return b.State.isFirefox ? "filter" : "-webkit-filter";case "extract": 496 var a = parseFloat(r);if (!a && 0 !== a) { 497 var n = r.toString().match(/blur\(([0-9]+[A-z]+)\)/i);a = n ? n[1] : 0; 498 }return a;case "inject": 499 return parseFloat(r) ? "blur(" + r + ")" : "none";} 500 }, opacity: function (e, t, r) { 501 if (8 >= d) switch (e) {case "name": 502 return "filter";case "extract": 503 var a = r.toString().match(/alpha\(opacity=(.*)\)/i);return r = a ? a[1] / 100 : 1;case "inject": 504 return t.style.zoom = 1, parseFloat(r) >= 1 ? "" : "alpha(opacity=" + parseInt(100 * parseFloat(r), 10) + ")";} else switch (e) {case "name": 505 return "opacity";case "extract": 506 return r;case "inject": 507 return r;} 508 } }, register: function () { 509 9 >= d || b.State.isGingerbread || (S.Lists.transformsBase = S.Lists.transformsBase.concat(S.Lists.transforms3D));for (var e = 0; e < S.Lists.transformsBase.length; e++) { 510 !function () { 511 var t = S.Lists.transformsBase[e];S.Normalizations.registered[t] = function (e, r, n) { 512 switch (e) {case "name": 513 return "transform";case "extract": 514 return i(r) === a || i(r).transformCache[t] === a ? /^scale/i.test(t) ? 1 : 0 : i(r).transformCache[t].replace(/[()]/g, "");case "inject": 515 var o = !1;switch (t.substr(0, t.length - 1)) {case "translate": 516 o = !/(%|px|em|rem|vw|vh|\d)$/i.test(n);break;case "scal":case "scale": 517 b.State.isAndroid && i(r).transformCache[t] === a && 1 > n && (n = 1), o = !/(\d)$/i.test(n);break;case "skew": 518 o = !/(deg|\d)$/i.test(n);break;case "rotate": 519 o = !/(deg|\d)$/i.test(n);}return o || (i(r).transformCache[t] = "(" + n + ")"), i(r).transformCache[t];} 520 }; 521 }(); 522 }for (var e = 0; e < S.Lists.colors.length; e++) { 523 !function () { 524 var t = S.Lists.colors[e];S.Normalizations.registered[t] = function (e, r, n) { 525 switch (e) {case "name": 526 return t;case "extract": 527 var o;if (S.RegEx.wrappedValueAlreadyExtracted.test(n)) o = n;else { 528 var i, 529 s = { black: "rgb(0, 0, 0)", blue: "rgb(0, 0, 255)", gray: "rgb(128, 128, 128)", green: "rgb(0, 128, 0)", red: "rgb(255, 0, 0)", white: "rgb(255, 255, 255)" };/^[A-z]+$/i.test(n) ? i = s[n] !== a ? s[n] : s.black : S.RegEx.isHex.test(n) ? i = "rgb(" + S.Values.hexToRgb(n).join(" ") + ")" : /^rgba?\(/i.test(n) || (i = s.black), o = (i || n).toString().match(S.RegEx.valueUnwrap)[1].replace(/,(\s+)?/g, " "); 530 }return 8 >= d || 3 !== o.split(" ").length || (o += " 1"), o;case "inject": 531 return 8 >= d ? 4 === n.split(" ").length && (n = n.split(/\s+/).slice(0, 3).join(" ")) : 3 === n.split(" ").length && (n += " 1"), (8 >= d ? "rgb" : "rgba") + "(" + n.replace(/\s+/g, ",").replace(/\.(\d)+(?=,)/g, "") + ")";} 532 }; 533 }(); 534 } 535 } }, Names: { camelCase: function (e) { 536 return e.replace(/-(\w)/g, function (e, t) { 537 return t.toUpperCase(); 538 }); 539 }, SVGAttribute: function (e) { 540 var t = "width|height|x|y|cx|cy|r|rx|ry|x1|x2|y1|y2";return (d || b.State.isAndroid && !b.State.isChrome) && (t += "|transform"), new RegExp("^(" + t + ")$", "i").test(e); 541 }, prefixCheck: function (e) { 542 if (b.State.prefixMatches[e]) return [b.State.prefixMatches[e], !0];for (var t = ["", "Webkit", "Moz", "ms", "O"], r = 0, a = t.length; a > r; r++) { 543 var n;if (n = 0 === r ? e : t[r] + e.replace(/^\w/, function (e) { 544 return e.toUpperCase(); 545 }), m.isString(b.State.prefixElement.style[n])) return b.State.prefixMatches[e] = n, [n, !0]; 546 }return [e, !1]; 547 } }, Values: { hexToRgb: function (e) { 548 var t, 549 r = /^#?([a-f\d])([a-f\d])([a-f\d])$/i, 550 a = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i;return e = e.replace(r, function (e, t, r, a) { 551 return t + t + r + r + a + a; 552 }), t = a.exec(e), t ? [parseInt(t[1], 16), parseInt(t[2], 16), parseInt(t[3], 16)] : [0, 0, 0]; 553 }, isCSSNullValue: function (e) { 554 return 0 == e || /^(none|auto|transparent|(rgba\(0, ?0, ?0, ?0\)))$/i.test(e); 555 }, getUnitType: function (e) { 556 return (/^(rotate|skew)/i.test(e) ? "deg" : /(^(scale|scaleX|scaleY|scaleZ|alpha|flexGrow|flexHeight|zIndex|fontWeight)$)|((opacity|red|green|blue|alpha)$)/i.test(e) ? "" : "px" 557 ); 558 }, getDisplayType: function (e) { 559 var t = e && e.tagName.toString().toLowerCase();return (/^(b|big|i|small|tt|abbr|acronym|cite|code|dfn|em|kbd|strong|samp|var|a|bdo|br|img|map|object|q|script|span|sub|sup|button|input|label|select|textarea)$/i.test(t) ? "inline" : /^(li)$/i.test(t) ? "list-item" : /^(tr)$/i.test(t) ? "table-row" : /^(table)$/i.test(t) ? "table" : /^(tbody)$/i.test(t) ? "table-row-group" : "block" 560 ); 561 }, addClass: function (e, t) { 562 e.classList ? e.classList.add(t) : e.className += (e.className.length ? " " : "") + t; 563 }, removeClass: function (e, t) { 564 e.classList ? e.classList.remove(t) : e.className = e.className.toString().replace(new RegExp("(^|\\s)" + t.split(" ").join("|") + "(\\s|$)", "gi"), " "); 565 } }, getPropertyValue: function (e, r, n, o) { 566 function s(e, r) { 567 function n() { 568 u && S.setPropertyValue(e, "display", "none"); 569 }var l = 0;if (8 >= d) l = f.css(e, r);else { 570 var u = !1;if (/^(width|height)$/.test(r) && 0 === S.getPropertyValue(e, "display") && (u = !0, S.setPropertyValue(e, "display", S.Values.getDisplayType(e))), !o) { 571 if ("height" === r && "border-box" !== S.getPropertyValue(e, "boxSizing").toString().toLowerCase()) { 572 var c = e.offsetHeight - (parseFloat(S.getPropertyValue(e, "borderTopWidth")) || 0) - (parseFloat(S.getPropertyValue(e, "borderBottomWidth")) || 0) - (parseFloat(S.getPropertyValue(e, "paddingTop")) || 0) - (parseFloat(S.getPropertyValue(e, "paddingBottom")) || 0);return n(), c; 573 }if ("width" === r && "border-box" !== S.getPropertyValue(e, "boxSizing").toString().toLowerCase()) { 574 var p = e.offsetWidth - (parseFloat(S.getPropertyValue(e, "borderLeftWidth")) || 0) - (parseFloat(S.getPropertyValue(e, "borderRightWidth")) || 0) - (parseFloat(S.getPropertyValue(e, "paddingLeft")) || 0) - (parseFloat(S.getPropertyValue(e, "paddingRight")) || 0);return n(), p; 575 } 576 }var g;g = i(e) === a ? t.getComputedStyle(e, null) : i(e).computedStyle ? i(e).computedStyle : i(e).computedStyle = t.getComputedStyle(e, null), "borderColor" === r && (r = "borderTopColor"), l = 9 === d && "filter" === r ? g.getPropertyValue(r) : g[r], ("" === l || null === l) && (l = e.style[r]), n(); 577 }if ("auto" === l && /^(top|right|bottom|left)$/i.test(r)) { 578 var m = s(e, "position");("fixed" === m || "absolute" === m && /top|left/i.test(r)) && (l = f(e).position()[r] + "px"); 579 }return l; 580 }var l;if (S.Hooks.registered[r]) { 581 var u = r, 582 c = S.Hooks.getRoot(u);n === a && (n = S.getPropertyValue(e, S.Names.prefixCheck(c)[0])), S.Normalizations.registered[c] && (n = S.Normalizations.registered[c]("extract", e, n)), l = S.Hooks.extractValue(u, n); 583 } else if (S.Normalizations.registered[r]) { 584 var p, g;p = S.Normalizations.registered[r]("name", e), "transform" !== p && (g = s(e, S.Names.prefixCheck(p)[0]), S.Values.isCSSNullValue(g) && S.Hooks.templates[r] && (g = S.Hooks.templates[r][1])), l = S.Normalizations.registered[r]("extract", e, g); 585 }if (!/^[\d-]/.test(l)) if (i(e) && i(e).isSVG && S.Names.SVGAttribute(r)) { 586 if (/^(height|width)$/i.test(r)) try { 587 l = e.getBBox()[r]; 588 } catch (m) { 589 l = 0; 590 } else l = e.getAttribute(r); 591 } else l = s(e, S.Names.prefixCheck(r)[0]);return S.Values.isCSSNullValue(l) && (l = 0), b.debug >= 2 && console.log("Get " + r + ": " + l), l; 592 }, setPropertyValue: function (e, r, a, n, o) { 593 var s = r;if ("scroll" === r) o.container ? o.container["scroll" + o.direction] = a : "Left" === o.direction ? t.scrollTo(a, o.alternateValue) : t.scrollTo(o.alternateValue, a);else if (S.Normalizations.registered[r] && "transform" === S.Normalizations.registered[r]("name", e)) S.Normalizations.registered[r]("inject", e, a), s = "transform", a = i(e).transformCache[r];else { 594 if (S.Hooks.registered[r]) { 595 var l = r, 596 u = S.Hooks.getRoot(r);n = n || S.getPropertyValue(e, u), a = S.Hooks.injectValue(l, a, n), r = u; 597 }if (S.Normalizations.registered[r] && (a = S.Normalizations.registered[r]("inject", e, a), r = S.Normalizations.registered[r]("name", e)), s = S.Names.prefixCheck(r)[0], 8 >= d) try { 598 e.style[s] = a; 599 } catch (c) { 600 b.debug && console.log("Browser does not support [" + a + "] for [" + s + "]"); 601 } else i(e) && i(e).isSVG && S.Names.SVGAttribute(r) ? e.setAttribute(r, a) : e.style[s] = a;b.debug >= 2 && console.log("Set " + r + " (" + s + "): " + a); 602 }return [s, a]; 603 }, flushTransformCache: function (e) { 604 function t(t) { 605 return parseFloat(S.getPropertyValue(e, t)); 606 }var r = "";if ((d || b.State.isAndroid && !b.State.isChrome) && i(e).isSVG) { 607 var a = { translate: [t("translateX"), t("translateY")], skewX: [t("skewX")], skewY: [t("skewY")], scale: 1 !== t("scale") ? [t("scale"), t("scale")] : [t("scaleX"), t("scaleY")], rotate: [t("rotateZ"), 0, 0] };f.each(i(e).transformCache, function (e) { 608 /^translate/i.test(e) ? e = "translate" : /^scale/i.test(e) ? e = "scale" : /^rotate/i.test(e) && (e = "rotate"), a[e] && (r += e + "(" + a[e].join(" ") + ") ", delete a[e]); 609 }); 610 } else { 611 var n, o;f.each(i(e).transformCache, function (t) { 612 return n = i(e).transformCache[t], "transformPerspective" === t ? (o = n, !0) : (9 === d && "rotateZ" === t && (t = "rotate"), void (r += t + n + " ")); 613 }), o && (r = "perspective" + o + " " + r); 614 }S.setPropertyValue(e, "transform", r); 615 } };S.Hooks.register(), S.Normalizations.register(), b.hook = function (e, t, r) { 616 var n = a;return e = o(e), f.each(e, function (e, o) { 617 if (i(o) === a && b.init(o), r === a) n === a && (n = b.CSS.getPropertyValue(o, t));else { 618 var s = b.CSS.setPropertyValue(o, t, r);"transform" === s[0] && b.CSS.flushTransformCache(o), n = s; 619 } 620 }), n; 621 };var P = function () { 622 function e() { 623 return s ? k.promise || null : l; 624 }function n() { 625 function e(e) { 626 function p(e, t) { 627 var r = a, 628 n = a, 629 i = a;return m.isArray(e) ? (r = e[0], !m.isArray(e[1]) && /^[\d-]/.test(e[1]) || m.isFunction(e[1]) || S.RegEx.isHex.test(e[1]) ? i = e[1] : (m.isString(e[1]) && !S.RegEx.isHex.test(e[1]) || m.isArray(e[1])) && (n = t ? e[1] : u(e[1], s.duration), e[2] !== a && (i = e[2]))) : r = e, t || (n = n || s.easing), m.isFunction(r) && (r = r.call(o, V, w)), m.isFunction(i) && (i = i.call(o, V, w)), [r || 0, n, i]; 630 }function d(e, t) { 631 var r, a;return a = (t || "0").toString().toLowerCase().replace(/[%A-z]+$/, function (e) { 632 return r = e, ""; 633 }), r || (r = S.Values.getUnitType(e)), [a, r]; 634 }function h() { 635 var e = { myParent: o.parentNode || r.body, position: S.getPropertyValue(o, "position"), fontSize: S.getPropertyValue(o, "fontSize") }, 636 a = e.position === L.lastPosition && e.myParent === L.lastParent, 637 n = e.fontSize === L.lastFontSize;L.lastParent = e.myParent, L.lastPosition = e.position, L.lastFontSize = e.fontSize;var s = 100, 638 l = {};if (n && a) l.emToPx = L.lastEmToPx, l.percentToPxWidth = L.lastPercentToPxWidth, l.percentToPxHeight = L.lastPercentToPxHeight;else { 639 var u = i(o).isSVG ? r.createElementNS("http://www.w3.org/2000/svg", "rect") : r.createElement("div");b.init(u), e.myParent.appendChild(u), f.each(["overflow", "overflowX", "overflowY"], function (e, t) { 640 b.CSS.setPropertyValue(u, t, "hidden"); 641 }), b.CSS.setPropertyValue(u, "position", e.position), b.CSS.setPropertyValue(u, "fontSize", e.fontSize), b.CSS.setPropertyValue(u, "boxSizing", "content-box"), f.each(["minWidth", "maxWidth", "width", "minHeight", "maxHeight", "height"], function (e, t) { 642 b.CSS.setPropertyValue(u, t, s + "%"); 643 }), b.CSS.setPropertyValue(u, "paddingLeft", s + "em"), l.percentToPxWidth = L.lastPercentToPxWidth = (parseFloat(S.getPropertyValue(u, "width", null, !0)) || 1) / s, l.percentToPxHeight = L.lastPercentToPxHeight = (parseFloat(S.getPropertyValue(u, "height", null, !0)) || 1) / s, l.emToPx = L.lastEmToPx = (parseFloat(S.getPropertyValue(u, "paddingLeft")) || 1) / s, e.myParent.removeChild(u); 644 }return null === L.remToPx && (L.remToPx = parseFloat(S.getPropertyValue(r.body, "fontSize")) || 16), null === L.vwToPx && (L.vwToPx = parseFloat(t.innerWidth) / 100, L.vhToPx = parseFloat(t.innerHeight) / 100), l.remToPx = L.remToPx, l.vwToPx = L.vwToPx, l.vhToPx = L.vhToPx, b.debug >= 1 && console.log("Unit ratios: " + JSON.stringify(l), o), l; 645 }if (s.begin && 0 === V) try { 646 s.begin.call(g, g); 647 } catch (x) { 648 setTimeout(function () { 649 throw x; 650 }, 1); 651 }if ("scroll" === A) { 652 var P, 653 C, 654 T, 655 F = /^x$/i.test(s.axis) ? "Left" : "Top", 656 j = parseFloat(s.offset) || 0;s.container ? m.isWrapped(s.container) || m.isNode(s.container) ? (s.container = s.container[0] || s.container, P = s.container["scroll" + F], T = P + f(o).position()[F.toLowerCase()] + j) : s.container = null : (P = b.State.scrollAnchor[b.State["scrollProperty" + F]], C = b.State.scrollAnchor[b.State["scrollProperty" + ("Left" === F ? "Top" : "Left")]], T = f(o).offset()[F.toLowerCase()] + j), l = { scroll: { rootPropertyValue: !1, startValue: P, currentValue: P, endValue: T, unitType: "", easing: s.easing, scrollData: { container: s.container, direction: F, alternateValue: C } }, element: o }, b.debug && console.log("tweensContainer (scroll): ", l.scroll, o); 657 } else if ("reverse" === A) { 658 if (!i(o).tweensContainer) return void f.dequeue(o, s.queue);"none" === i(o).opts.display && (i(o).opts.display = "auto"), "hidden" === i(o).opts.visibility && (i(o).opts.visibility = "visible"), i(o).opts.loop = !1, i(o).opts.begin = null, i(o).opts.complete = null, v.easing || delete s.easing, v.duration || delete s.duration, s = f.extend({}, i(o).opts, s);var E = f.extend(!0, {}, i(o).tweensContainer);for (var H in E) { 659 if ("element" !== H) { 660 var N = E[H].startValue;E[H].startValue = E[H].currentValue = E[H].endValue, E[H].endValue = N, m.isEmptyObject(v) || (E[H].easing = s.easing), b.debug && console.log("reverse tweensContainer (" + H + "): " + JSON.stringify(E[H]), o); 661 } 662 }l = E; 663 } else if ("start" === A) { 664 var E;i(o).tweensContainer && i(o).isAnimating === !0 && (E = i(o).tweensContainer), f.each(y, function (e, t) { 665 if (RegExp("^" + S.Lists.colors.join("$|^") + "$").test(e)) { 666 var r = p(t, !0), 667 n = r[0], 668 o = r[1], 669 i = r[2];if (S.RegEx.isHex.test(n)) { 670 for (var s = ["Red", "Green", "Blue"], l = S.Values.hexToRgb(n), u = i ? S.Values.hexToRgb(i) : a, c = 0; c < s.length; c++) { 671 var f = [l[c]];o && f.push(o), u !== a && f.push(u[c]), y[e + s[c]] = f; 672 }delete y[e]; 673 } 674 } 675 });for (var z in y) { 676 var O = p(y[z]), 677 q = O[0], 678 $ = O[1], 679 M = O[2];z = S.Names.camelCase(z);var I = S.Hooks.getRoot(z), 680 B = !1;if (i(o).isSVG || "tween" === I || S.Names.prefixCheck(I)[1] !== !1 || S.Normalizations.registered[I] !== a) { 681 (s.display !== a && null !== s.display && "none" !== s.display || s.visibility !== a && "hidden" !== s.visibility) && /opacity|filter/.test(z) && !M && 0 !== q && (M = 0), s._cacheValues && E && E[z] ? (M === a && (M = E[z].endValue + E[z].unitType), B = i(o).rootPropertyValueCache[I]) : S.Hooks.registered[z] ? M === a ? (B = S.getPropertyValue(o, I), M = S.getPropertyValue(o, z, B)) : B = S.Hooks.templates[I][1] : M === a && (M = S.getPropertyValue(o, z));var W, 682 G, 683 Y, 684 D = !1;if (W = d(z, M), M = W[0], Y = W[1], W = d(z, q), q = W[0].replace(/^([+-\/*])=/, function (e, t) { 685 return D = t, ""; 686 }), G = W[1], M = parseFloat(M) || 0, q = parseFloat(q) || 0, "%" === G && (/^(fontSize|lineHeight)$/.test(z) ? (q /= 100, G = "em") : /^scale/.test(z) ? (q /= 100, G = "") : /(Red|Green|Blue)$/i.test(z) && (q = q / 100 * 255, G = "")), /[\/*]/.test(D)) G = Y;else if (Y !== G && 0 !== M) if (0 === q) G = Y;else { 687 n = n || h();var Q = /margin|padding|left|right|width|text|word|letter/i.test(z) || /X$/.test(z) || "x" === z ? "x" : "y";switch (Y) {case "%": 688 M *= "x" === Q ? n.percentToPxWidth : n.percentToPxHeight;break;case "px": 689 break;default: 690 M *= n[Y + "ToPx"];}switch (G) {case "%": 691 M *= 1 / ("x" === Q ? n.percentToPxWidth : n.percentToPxHeight);break;case "px": 692 break;default: 693 M *= 1 / n[G + "ToPx"];} 694 }switch (D) {case "+": 695 q = M + q;break;case "-": 696 q = M - q;break;case "*": 697 q = M * q;break;case "/": 698 q = M / q;}l[z] = { rootPropertyValue: B, startValue: M, currentValue: M, endValue: q, unitType: G, easing: $ }, b.debug && console.log("tweensContainer (" + z + "): " + JSON.stringify(l[z]), o); 699 } else b.debug && console.log("Skipping [" + I + "] due to a lack of browser support."); 700 }l.element = o; 701 }l.element && (S.Values.addClass(o, "velocity-animating"), R.push(l), "" === s.queue && (i(o).tweensContainer = l, i(o).opts = s), i(o).isAnimating = !0, V === w - 1 ? (b.State.calls.push([R, g, s, null, k.resolver]), b.State.isTicking === !1 && (b.State.isTicking = !0, c())) : V++); 702 }var n, 703 o = this, 704 s = f.extend({}, b.defaults, v), 705 l = {};switch (i(o) === a && b.init(o), parseFloat(s.delay) && s.queue !== !1 && f.queue(o, s.queue, function (e) { 706 b.velocityQueueEntryFlag = !0, i(o).delayTimer = { setTimeout: setTimeout(e, parseFloat(s.delay)), next: e }; 707 }), s.duration.toString().toLowerCase()) {case "fast": 708 s.duration = 200;break;case "normal": 709 s.duration = h;break;case "slow": 710 s.duration = 600;break;default: 711 s.duration = parseFloat(s.duration) || 1;}b.mock !== !1 && (b.mock === !0 ? s.duration = s.delay = 1 : (s.duration *= parseFloat(b.mock) || 1, s.delay *= parseFloat(b.mock) || 1)), s.easing = u(s.easing, s.duration), s.begin && !m.isFunction(s.begin) && (s.begin = null), s.progress && !m.isFunction(s.progress) && (s.progress = null), s.complete && !m.isFunction(s.complete) && (s.complete = null), s.display !== a && null !== s.display && (s.display = s.display.toString().toLowerCase(), "auto" === s.display && (s.display = b.CSS.Values.getDisplayType(o))), s.visibility !== a && null !== s.visibility && (s.visibility = s.visibility.toString().toLowerCase()), s.mobileHA = s.mobileHA && b.State.isMobile && !b.State.isGingerbread, s.queue === !1 ? s.delay ? setTimeout(e, s.delay) : e() : f.queue(o, s.queue, function (t, r) { 712 return r === !0 ? (k.promise && k.resolver(g), !0) : (b.velocityQueueEntryFlag = !0, void e(t)); 713 }), "" !== s.queue && "fx" !== s.queue || "inprogress" === f.queue(o)[0] || f.dequeue(o); 714 }var s, 715 l, 716 d, 717 g, 718 y, 719 v, 720 x = arguments[0] && (arguments[0].p || f.isPlainObject(arguments[0].properties) && !arguments[0].properties.names || m.isString(arguments[0].properties));if (m.isWrapped(this) ? (s = !1, d = 0, g = this, l = this) : (s = !0, d = 1, g = x ? arguments[0].elements || arguments[0].e : arguments[0]), g = o(g)) { 721 x ? (y = arguments[0].properties || arguments[0].p, v = arguments[0].options || arguments[0].o) : (y = arguments[d], v = arguments[d + 1]);var w = g.length, 722 V = 0;if (!/^(stop|finish)$/i.test(y) && !f.isPlainObject(v)) { 723 var C = d + 1;v = {};for (var T = C; T < arguments.length; T++) { 724 m.isArray(arguments[T]) || !/^(fast|normal|slow)$/i.test(arguments[T]) && !/^\d/.test(arguments[T]) ? m.isString(arguments[T]) || m.isArray(arguments[T]) ? v.easing = arguments[T] : m.isFunction(arguments[T]) && (v.complete = arguments[T]) : v.duration = arguments[T]; 725 } 726 }var k = { promise: null, resolver: null, rejecter: null };s && b.Promise && (k.promise = new b.Promise(function (e, t) { 727 k.resolver = e, k.rejecter = t; 728 }));var A;switch (y) {case "scroll": 729 A = "scroll";break;case "reverse": 730 A = "reverse";break;case "finish":case "stop": 731 f.each(g, function (e, t) { 732 i(t) && i(t).delayTimer && (clearTimeout(i(t).delayTimer.setTimeout), i(t).delayTimer.next && i(t).delayTimer.next(), delete i(t).delayTimer); 733 });var F = [];return f.each(b.State.calls, function (e, t) { 734 t && f.each(t[1], function (r, n) { 735 var o = v === a ? "" : v;return o === !0 || t[2].queue === o || v === a && t[2].queue === !1 ? void f.each(g, function (r, a) { 736 a === n && ((v === !0 || m.isString(v)) && (f.each(f.queue(a, m.isString(v) ? v : ""), function (e, t) { 737 m.isFunction(t) && t(null, !0); 738 }), f.queue(a, m.isString(v) ? v : "", [])), "stop" === y ? (i(a) && i(a).tweensContainer && o !== !1 && f.each(i(a).tweensContainer, function (e, t) { 739 t.endValue = t.currentValue; 740 }), F.push(e)) : "finish" === y && (t[2].duration = 1)); 741 }) : !0; 742 }); 743 }), "stop" === y && (f.each(F, function (e, t) { 744 p(t, !0); 745 }), k.promise && k.resolver(g)), e();default: 746 if (!f.isPlainObject(y) || m.isEmptyObject(y)) { 747 if (m.isString(y) && b.Redirects[y]) { 748 var j = f.extend({}, v), 749 E = j.duration, 750 H = j.delay || 0;return j.backwards === !0 && (g = f.extend(!0, [], g).reverse()), f.each(g, function (e, t) { 751 parseFloat(j.stagger) ? j.delay = H + parseFloat(j.stagger) * e : m.isFunction(j.stagger) && (j.delay = H + j.stagger.call(t, e, w)), j.drag && (j.duration = parseFloat(E) || (/^(callout|transition)/.test(y) ? 1e3 : h), j.duration = Math.max(j.duration * (j.backwards ? 1 - e / w : (e + 1) / w), .75 * j.duration, 200)), b.Redirects[y].call(t, t, j || {}, e, w, g, k.promise ? k : a); 752 }), e(); 753 }var N = "Velocity: First argument (" + y + ") was not a property map, a known action, or a registered redirect. Aborting.";return k.promise ? k.rejecter(new Error(N)) : console.log(N), e(); 754 }A = "start";}var L = { lastParent: null, lastPosition: null, lastFontSize: null, lastPercentToPxWidth: null, lastPercentToPxHeight: null, lastEmToPx: null, remToPx: null, vwToPx: null, vhToPx: null }, 755 R = [];f.each(g, function (e, t) { 756 m.isNode(t) && n.call(t); 757 });var z, 758 j = f.extend({}, b.defaults, v);if (j.loop = parseInt(j.loop), z = 2 * j.loop - 1, j.loop) for (var O = 0; z > O; O++) { 759 var q = { delay: j.delay, progress: j.progress };O === z - 1 && (q.display = j.display, q.visibility = j.visibility, q.complete = j.complete), P(g, "reverse", q); 760 }return e(); 761 } 762 };b = f.extend(P, b), b.animate = P;var w = t.requestAnimationFrame || g;return b.State.isMobile || r.hidden === a || r.addEventListener("visibilitychange", function () { 763 r.hidden ? (w = function (e) { 764 return setTimeout(function () { 765 e(!0); 766 }, 16); 767 }, c()) : w = t.requestAnimationFrame || g; 768 }), e.Velocity = b, e !== t && (e.fn.velocity = P, e.fn.velocity.defaults = b.defaults), f.each(["Down", "Up"], function (e, t) { 769 b.Redirects["slide" + t] = function (e, r, n, o, i, s) { 770 var l = f.extend({}, r), 771 u = l.begin, 772 c = l.complete, 773 p = { height: "", marginTop: "", marginBottom: "", paddingTop: "", paddingBottom: "" }, 774 d = {};l.display === a && (l.display = "Down" === t ? "inline" === b.CSS.Values.getDisplayType(e) ? "inline-block" : "block" : "none"), l.begin = function () { 775 u && u.call(i, i);for (var r in p) { 776 d[r] = e.style[r];var a = b.CSS.getPropertyValue(e, r);p[r] = "Down" === t ? [a, 0] : [0, a]; 777 }d.overflow = e.style.overflow, e.style.overflow = "hidden"; 778 }, l.complete = function () { 779 for (var t in d) { 780 e.style[t] = d[t]; 781 }c && c.call(i, i), s && s.resolver(i); 782 }, b(e, p, l); 783 }; 784 }), f.each(["In", "Out"], function (e, t) { 785 b.Redirects["fade" + t] = function (e, r, n, o, i, s) { 786 var l = f.extend({}, r), 787 u = { opacity: "In" === t ? 1 : 0 }, 788 c = l.complete;l.complete = n !== o - 1 ? l.begin = null : function () { 789 c && c.call(i, i), s && s.resolver(i); 790 }, l.display === a && (l.display = "In" === t ? "auto" : "none"), b(this, u, l); 791 }; 792 }), b; 793 }(window.jQuery || window.Zepto || window, window, document); 794 })); 795 ;!function (a, b, c, d) { 796 "use strict"; 797 function k(a, b, c) { 798 return setTimeout(q(a, c), b); 799 }function l(a, b, c) { 800 return Array.isArray(a) ? (m(a, c[b], c), !0) : !1; 801 }function m(a, b, c) { 802 var e;if (a) if (a.forEach) a.forEach(b, c);else if (a.length !== d) for (e = 0; e < a.length;) { 803 b.call(c, a[e], e, a), e++; 804 } else for (e in a) { 805 a.hasOwnProperty(e) && b.call(c, a[e], e, a); 806 } 807 }function n(a, b, c) { 808 for (var e = Object.keys(b), f = 0; f < e.length;) { 809 (!c || c && a[e[f]] === d) && (a[e[f]] = b[e[f]]), f++; 810 }return a; 811 }function o(a, b) { 812 return n(a, b, !0); 813 }function p(a, b, c) { 814 var e, 815 d = b.prototype;e = a.prototype = Object.create(d), e.constructor = a, e._super = d, c && n(e, c); 816 }function q(a, b) { 817 return function () { 818 return a.apply(b, arguments); 819 }; 820 }function r(a, b) { 821 return typeof a == g ? a.apply(b ? b[0] || d : d, b) : a; 822 }function s(a, b) { 823 return a === d ? b : a; 824 }function t(a, b, c) { 825 m(x(b), function (b) { 826 a.addEventListener(b, c, !1); 827 }); 828 }function u(a, b, c) { 829 m(x(b), function (b) { 830 a.removeEventListener(b, c, !1); 831 }); 832 }function v(a, b) { 833 for (; a;) { 834 if (a == b) return !0;a = a.parentNode; 835 }return !1; 836 }function w(a, b) { 837 return a.indexOf(b) > -1; 838 }function x(a) { 839 return a.trim().split(/\s+/g); 840 }function y(a, b, c) { 841 if (a.indexOf && !c) return a.indexOf(b);for (var d = 0; d < a.length;) { 842 if (c && a[d][c] == b || !c && a[d] === b) return d;d++; 843 }return -1; 844 }function z(a) { 845 return Array.prototype.slice.call(a, 0); 846 }function A(a, b, c) { 847 for (var d = [], e = [], f = 0; f < a.length;) { 848 var g = b ? a[f][b] : a[f];y(e, g) < 0 && d.push(a[f]), e[f] = g, f++; 849 }return c && (d = b ? d.sort(function (a, c) { 850 return a[b] > c[b]; 851 }) : d.sort()), d; 852 }function B(a, b) { 853 for (var c, f, g = b[0].toUpperCase() + b.slice(1), h = 0; h < e.length;) { 854 if (c = e[h], f = c ? c + g : b, f in a) return f;h++; 855 }return d; 856 }function D() { 857 return C++; 858 }function E(a) { 859 var b = a.ownerDocument;return b.defaultView || b.parentWindow; 860 }function ab(a, b) { 861 var c = this;this.manager = a, this.callback = b, this.element = a.element, this.target = a.options.inputTarget, this.domHandler = function (b) { 862 r(a.options.enable, [a]) && c.handler(b); 863 }, this.init(); 864 }function bb(a) { 865 var b, 866 c = a.options.inputClass;return b = c ? c : H ? wb : I ? Eb : G ? Gb : rb, new b(a, cb); 867 }function cb(a, b, c) { 868 var d = c.pointers.length, 869 e = c.changedPointers.length, 870 f = b & O && 0 === d - e, 871 g = b & (Q | R) && 0 === d - e;c.isFirst = !!f, c.isFinal = !!g, f && (a.session = {}), c.eventType = b, db(a, c), a.emit("hammer.input", c), a.recognize(c), a.session.prevInput = c; 872 }function db(a, b) { 873 var c = a.session, 874 d = b.pointers, 875 e = d.length;c.firstInput || (c.firstInput = gb(b)), e > 1 && !c.firstMultiple ? c.firstMultiple = gb(b) : 1 === e && (c.firstMultiple = !1);var f = c.firstInput, 876 g = c.firstMultiple, 877 h = g ? g.center : f.center, 878 i = b.center = hb(d);b.timeStamp = j(), b.deltaTime = b.timeStamp - f.timeStamp, b.angle = lb(h, i), b.distance = kb(h, i), eb(c, b), b.offsetDirection = jb(b.deltaX, b.deltaY), b.scale = g ? nb(g.pointers, d) : 1, b.rotation = g ? mb(g.pointers, d) : 0, fb(c, b);var k = a.element;v(b.srcEvent.target, k) && (k = b.srcEvent.target), b.target = k; 879 }function eb(a, b) { 880 var c = b.center, 881 d = a.offsetDelta || {}, 882 e = a.prevDelta || {}, 883 f = a.prevInput || {};(b.eventType === O || f.eventType === Q) && (e = a.prevDelta = { x: f.deltaX || 0, y: f.deltaY || 0 }, d = a.offsetDelta = { x: c.x, y: c.y }), b.deltaX = e.x + (c.x - d.x), b.deltaY = e.y + (c.y - d.y); 884 }function fb(a, b) { 885 var f, 886 g, 887 h, 888 j, 889 c = a.lastInterval || b, 890 e = b.timeStamp - c.timeStamp;if (b.eventType != R && (e > N || c.velocity === d)) { 891 var k = c.deltaX - b.deltaX, 892 l = c.deltaY - b.deltaY, 893 m = ib(e, k, l);g = m.x, h = m.y, f = i(m.x) > i(m.y) ? m.x : m.y, j = jb(k, l), a.lastInterval = b; 894 } else f = c.velocity, g = c.velocityX, h = c.velocityY, j = c.direction;b.velocity = f, b.velocityX = g, b.velocityY = h, b.direction = j; 895 }function gb(a) { 896 for (var b = [], c = 0; c < a.pointers.length;) { 897 b[c] = { clientX: h(a.pointers[c].clientX), clientY: h(a.pointers[c].clientY) }, c++; 898 }return { timeStamp: j(), pointers: b, center: hb(b), deltaX: a.deltaX, deltaY: a.deltaY }; 899 }function hb(a) { 900 var b = a.length;if (1 === b) return { x: h(a[0].clientX), y: h(a[0].clientY) };for (var c = 0, d = 0, e = 0; b > e;) { 901 c += a[e].clientX, d += a[e].clientY, e++; 902 }return { x: h(c / b), y: h(d / b) }; 903 }function ib(a, b, c) { 904 return { x: b / a || 0, y: c / a || 0 }; 905 }function jb(a, b) { 906 return a === b ? S : i(a) >= i(b) ? a > 0 ? T : U : b > 0 ? V : W; 907 }function kb(a, b, c) { 908 c || (c = $);var d = b[c[0]] - a[c[0]], 909 e = b[c[1]] - a[c[1]];return Math.sqrt(d * d + e * e); 910 }function lb(a, b, c) { 911 c || (c = $);var d = b[c[0]] - a[c[0]], 912 e = b[c[1]] - a[c[1]];return 180 * Math.atan2(e, d) / Math.PI; 913 }function mb(a, b) { 914 return lb(b[1], b[0], _) - lb(a[1], a[0], _); 915 }function nb(a, b) { 916 return kb(b[0], b[1], _) / kb(a[0], a[1], _); 917 }function rb() { 918 this.evEl = pb, this.evWin = qb, this.allow = !0, this.pressed = !1, ab.apply(this, arguments); 919 }function wb() { 920 this.evEl = ub, this.evWin = vb, ab.apply(this, arguments), this.store = this.manager.session.pointerEvents = []; 921 }function Ab() { 922 this.evTarget = yb, this.evWin = zb, this.started = !1, ab.apply(this, arguments); 923 }function Bb(a, b) { 924 var c = z(a.touches), 925 d = z(a.changedTouches);return b & (Q | R) && (c = A(c.concat(d), "identifier", !0)), [c, d]; 926 }function Eb() { 927 this.evTarget = Db, this.targetIds = {}, ab.apply(this, arguments); 928 }function Fb(a, b) { 929 var c = z(a.touches), 930 d = this.targetIds;if (b & (O | P) && 1 === c.length) return d[c[0].identifier] = !0, [c, c];var e, 931 f, 932 g = z(a.changedTouches), 933 h = [], 934 i = this.target;if (f = c.filter(function (a) { 935 return v(a.target, i); 936 }), b === O) for (e = 0; e < f.length;) { 937 d[f[e].identifier] = !0, e++; 938 }for (e = 0; e < g.length;) { 939 d[g[e].identifier] && h.push(g[e]), b & (Q | R) && delete d[g[e].identifier], e++; 940 }return h.length ? [A(f.concat(h), "identifier", !0), h] : void 0; 941 }function Gb() { 942 ab.apply(this, arguments);var a = q(this.handler, this);this.touch = new Eb(this.manager, a), this.mouse = new rb(this.manager, a); 943 }function Pb(a, b) { 944 this.manager = a, this.set(b); 945 }function Qb(a) { 946 if (w(a, Mb)) return Mb;var b = w(a, Nb), 947 c = w(a, Ob);return b && c ? Nb + " " + Ob : b || c ? b ? Nb : Ob : w(a, Lb) ? Lb : Kb; 948 }function Yb(a) { 949 this.id = D(), this.manager = null, this.options = o(a || {}, this.defaults), this.options.enable = s(this.options.enable, !0), this.state = Rb, this.simultaneous = {}, this.requireFail = []; 950 }function Zb(a) { 951 return a & Wb ? "cancel" : a & Ub ? "end" : a & Tb ? "move" : a & Sb ? "start" : ""; 952 }function $b(a) { 953 return a == W ? "down" : a == V ? "up" : a == T ? "left" : a == U ? "right" : ""; 954 }function _b(a, b) { 955 var c = b.manager;return c ? c.get(a) : a; 956 }function ac() { 957 Yb.apply(this, arguments); 958 }function bc() { 959 ac.apply(this, arguments), this.pX = null, this.pY = null; 960 }function cc() { 961 ac.apply(this, arguments); 962 }function dc() { 963 Yb.apply(this, arguments), this._timer = null, this._input = null; 964 }function ec() { 965 ac.apply(this, arguments); 966 }function fc() { 967 ac.apply(this, arguments); 968 }function gc() { 969 Yb.apply(this, arguments), this.pTime = !1, this.pCenter = !1, this._timer = null, this._input = null, this.count = 0; 970 }function hc(a, b) { 971 return b = b || {}, b.recognizers = s(b.recognizers, hc.defaults.preset), new kc(a, b); 972 }function kc(a, b) { 973 b = b || {}, this.options = o(b, hc.defaults), this.options.inputTarget = this.options.inputTarget || a, this.handlers = {}, this.session = {}, this.recognizers = [], this.element = a, this.input = bb(this), this.touchAction = new Pb(this, this.options.touchAction), lc(this, !0), m(b.recognizers, function (a) { 974 var b = this.add(new a[0](a[1]));a[2] && b.recognizeWith(a[2]), a[3] && b.requireFailure(a[3]); 975 }, this); 976 }function lc(a, b) { 977 var c = a.element;m(a.options.cssProps, function (a, d) { 978 c.style[B(c.style, d)] = b ? a : ""; 979 }); 980 }function mc(a, c) { 981 var d = b.createEvent("Event");d.initEvent(a, !0, !0), d.gesture = c, c.target.dispatchEvent(d); 982 }var e = ["", "webkit", "moz", "MS", "ms", "o"], 983 f = b.createElement("div"), 984 g = "function", 985 h = Math.round, 986 i = Math.abs, 987 j = Date.now, 988 C = 1, 989 F = /mobile|tablet|ip(ad|hone|od)|android/i, 990 G = "ontouchstart" in a, 991 H = B(a, "PointerEvent") !== d, 992 I = G && F.test(navigator.userAgent), 993 J = "touch", 994 K = "pen", 995 L = "mouse", 996 M = "kinect", 997 N = 25, 998 O = 1, 999 P = 2, 1000 Q = 4, 1001 R = 8, 1002 S = 1, 1003 T = 2, 1004 U = 4, 1005 V = 8, 1006 W = 16, 1007 X = T | U, 1008 Y = V | W, 1009 Z = X | Y, 1010 $ = ["x", "y"], 1011 _ = ["clientX", "clientY"];ab.prototype = { handler: function () {}, init: function () { 1012 this.evEl && t(this.element, this.evEl, this.domHandler), this.evTarget && t(this.target, this.evTarget, this.domHandler), this.evWin && t(E(this.element), this.evWin, this.domHandler); 1013 }, destroy: function () { 1014 this.evEl && u(this.element, this.evEl, this.domHandler), this.evTarget && u(this.target, this.evTarget, this.domHandler), this.evWin && u(E(this.element), this.evWin, this.domHandler); 1015 } };var ob = { mousedown: O, mousemove: P, mouseup: Q }, 1016 pb = "mousedown", 1017 qb = "mousemove mouseup";p(rb, ab, { handler: function (a) { 1018 var b = ob[a.type];b & O && 0 === a.button && (this.pressed = !0), b & P && 1 !== a.which && (b = Q), this.pressed && this.allow && (b & Q && (this.pressed = !1), this.callback(this.manager, b, { pointers: [a], changedPointers: [a], pointerType: L, srcEvent: a })); 1019 } });var sb = { pointerdown: O, pointermove: P, pointerup: Q, pointercancel: R, pointerout: R }, 1020 tb = { 2: J, 3: K, 4: L, 5: M }, 1021 ub = "pointerdown", 1022 vb = "pointermove pointerup pointercancel";a.MSPointerEvent && (ub = "MSPointerDown", vb = "MSPointerMove MSPointerUp MSPointerCancel"), p(wb, ab, { handler: function (a) { 1023 var b = this.store, 1024 c = !1, 1025 d = a.type.toLowerCase().replace("ms", ""), 1026 e = sb[d], 1027 f = tb[a.pointerType] || a.pointerType, 1028 g = f == J, 1029 h = y(b, a.pointerId, "pointerId");e & O && (0 === a.button || g) ? 0 > h && (b.push(a), h = b.length - 1) : e & (Q | R) && (c = !0), 0 > h || (b[h] = a, this.callback(this.manager, e, { pointers: b, changedPointers: [a], pointerType: f, srcEvent: a }), c && b.splice(h, 1)); 1030 } });var xb = { touchstart: O, touchmove: P, touchend: Q, touchcancel: R }, 1031 yb = "touchstart", 1032 zb = "touchstart touchmove touchend touchcancel";p(Ab, ab, { handler: function (a) { 1033 var b = xb[a.type];if (b === O && (this.started = !0), this.started) { 1034 var c = Bb.call(this, a, b);b & (Q | R) && 0 === c[0].length - c[1].length && (this.started = !1), this.callback(this.manager, b, { pointers: c[0], changedPointers: c[1], pointerType: J, srcEvent: a }); 1035 } 1036 } });var Cb = { touchstart: O, touchmove: P, touchend: Q, touchcancel: R }, 1037 Db = "touchstart touchmove touchend touchcancel";p(Eb, ab, { handler: function (a) { 1038 var b = Cb[a.type], 1039 c = Fb.call(this, a, b);c && this.callback(this.manager, b, { pointers: c[0], changedPointers: c[1], pointerType: J, srcEvent: a }); 1040 } }), p(Gb, ab, { handler: function (a, b, c) { 1041 var d = c.pointerType == J, 1042 e = c.pointerType == L;if (d) this.mouse.allow = !1;else if (e && !this.mouse.allow) return;b & (Q | R) && (this.mouse.allow = !0), this.callback(a, b, c); 1043 }, destroy: function () { 1044 this.touch.destroy(), this.mouse.destroy(); 1045 } });var Hb = B(f.style, "touchAction"), 1046 Ib = Hb !== d, 1047 Jb = "compute", 1048 Kb = "auto", 1049 Lb = "manipulation", 1050 Mb = "none", 1051 Nb = "pan-x", 1052 Ob = "pan-y";Pb.prototype = { set: function (a) { 1053 a == Jb && (a = this.compute()), Ib && (this.manager.element.style[Hb] = a), this.actions = a.toLowerCase().trim(); 1054 }, update: function () { 1055 this.set(this.manager.options.touchAction); 1056 }, compute: function () { 1057 var a = [];return m(this.manager.recognizers, function (b) { 1058 r(b.options.enable, [b]) && (a = a.concat(b.getTouchAction())); 1059 }), Qb(a.join(" ")); 1060 }, preventDefaults: function (a) { 1061 if (!Ib) { 1062 var b = a.srcEvent, 1063 c = a.offsetDirection;if (this.manager.session.prevented) return b.preventDefault(), void 0;var d = this.actions, 1064 e = w(d, Mb), 1065 f = w(d, Ob), 1066 g = w(d, Nb);return e || f && c & X || g && c & Y ? this.preventSrc(b) : void 0; 1067 } 1068 }, preventSrc: function (a) { 1069 this.manager.session.prevented = !0, a.preventDefault(); 1070 } };var Rb = 1, 1071 Sb = 2, 1072 Tb = 4, 1073 Ub = 8, 1074 Vb = Ub, 1075 Wb = 16, 1076 Xb = 32;Yb.prototype = { defaults: {}, set: function (a) { 1077 return n(this.options, a), this.manager && this.manager.touchAction.update(), this; 1078 }, recognizeWith: function (a) { 1079 if (l(a, "recognizeWith", this)) return this;var b = this.simultaneous;return a = _b(a, this), b[a.id] || (b[a.id] = a, a.recognizeWith(this)), this; 1080 }, dropRecognizeWith: function (a) { 1081 return l(a, "dropRecognizeWith", this) ? this : (a = _b(a, this), delete this.simultaneous[a.id], this); 1082 }, requireFailure: function (a) { 1083 if (l(a, "requireFailure", this)) return this;var b = this.requireFail;return a = _b(a, this), -1 === y(b, a) && (b.push(a), a.requireFailure(this)), this; 1084 }, dropRequireFailure: function (a) { 1085 if (l(a, "dropRequireFailure", this)) return this;a = _b(a, this);var b = y(this.requireFail, a);return b > -1 && this.requireFail.splice(b, 1), this; 1086 }, hasRequireFailures: function () { 1087 return this.requireFail.length > 0; 1088 }, canRecognizeWith: function (a) { 1089 return !!this.simultaneous[a.id]; 1090 }, emit: function (a) { 1091 function d(d) { 1092 b.manager.emit(b.options.event + (d ? Zb(c) : ""), a); 1093 }var b = this, 1094 c = this.state;Ub > c && d(!0), d(), c >= Ub && d(!0); 1095 }, tryEmit: function (a) { 1096 return this.canEmit() ? this.emit(a) : (this.state = Xb, void 0); 1097 }, canEmit: function () { 1098 for (var a = 0; a < this.requireFail.length;) { 1099 if (!(this.requireFail[a].state & (Xb | Rb))) return !1;a++; 1100 }return !0; 1101 }, recognize: function (a) { 1102 var b = n({}, a);return r(this.options.enable, [this, b]) ? (this.state & (Vb | Wb | Xb) && (this.state = Rb), this.state = this.process(b), this.state & (Sb | Tb | Ub | Wb) && this.tryEmit(b), void 0) : (this.reset(), this.state = Xb, void 0); 1103 }, process: function () {}, getTouchAction: function () {}, reset: function () {} }, p(ac, Yb, { defaults: { pointers: 1 }, attrTest: function (a) { 1104 var b = this.options.pointers;return 0 === b || a.pointers.length === b; 1105 }, process: function (a) { 1106 var b = this.state, 1107 c = a.eventType, 1108 d = b & (Sb | Tb), 1109 e = this.attrTest(a);return d && (c & R || !e) ? b | Wb : d || e ? c & Q ? b | Ub : b & Sb ? b | Tb : Sb : Xb; 1110 } }), p(bc, ac, { defaults: { event: "pan", threshold: 10, pointers: 1, direction: Z }, getTouchAction: function () { 1111 var a = this.options.direction, 1112 b = [];return a & X && b.push(Ob), a & Y && b.push(Nb), b; 1113 }, directionTest: function (a) { 1114 var b = this.options, 1115 c = !0, 1116 d = a.distance, 1117 e = a.direction, 1118 f = a.deltaX, 1119 g = a.deltaY;return e & b.direction || (b.direction & X ? (e = 0 === f ? S : 0 > f ? T : U, c = f != this.pX, d = Math.abs(a.deltaX)) : (e = 0 === g ? S : 0 > g ? V : W, c = g != this.pY, d = Math.abs(a.deltaY))), a.direction = e, c && d > b.threshold && e & b.direction; 1120 }, attrTest: function (a) { 1121 return ac.prototype.attrTest.call(this, a) && (this.state & Sb || !(this.state & Sb) && this.directionTest(a)); 1122 }, emit: function (a) { 1123 this.pX = a.deltaX, this.pY = a.deltaY;var b = $b(a.direction);b && this.manager.emit(this.options.event + b, a), this._super.emit.call(this, a); 1124 } }), p(cc, ac, { defaults: { event: "pinch", threshold: 0, pointers: 2 }, getTouchAction: function () { 1125 return [Mb]; 1126 }, attrTest: function (a) { 1127 return this._super.attrTest.call(this, a) && (Math.abs(a.scale - 1) > this.options.threshold || this.state & Sb); 1128 }, emit: function (a) { 1129 if (this._super.emit.call(this, a), 1 !== a.scale) { 1130 var b = a.scale < 1 ? "in" : "out";this.manager.emit(this.options.event + b, a); 1131 } 1132 } }), p(dc, Yb, { defaults: { event: "press", pointers: 1, time: 500, threshold: 5 }, getTouchAction: function () { 1133 return [Kb]; 1134 }, process: function (a) { 1135 var b = this.options, 1136 c = a.pointers.length === b.pointers, 1137 d = a.distance < b.threshold, 1138 e = a.deltaTime > b.time;if (this._input = a, !d || !c || a.eventType & (Q | R) && !e) this.reset();else if (a.eventType & O) this.reset(), this._timer = k(function () { 1139 this.state = Vb, this.tryEmit(); 1140 }, b.time, this);else if (a.eventType & Q) return Vb;return Xb; 1141 }, reset: function () { 1142 clearTimeout(this._timer); 1143 }, emit: function (a) { 1144 this.state === Vb && (a && a.eventType & Q ? this.manager.emit(this.options.event + "up", a) : (this._input.timeStamp = j(), this.manager.emit(this.options.event, this._input))); 1145 } }), p(ec, ac, { defaults: { event: "rotate", threshold: 0, pointers: 2 }, getTouchAction: function () { 1146 return [Mb]; 1147 }, attrTest: function (a) { 1148 return this._super.attrTest.call(this, a) && (Math.abs(a.rotation) > this.options.threshold || this.state & Sb); 1149 } }), p(fc, ac, { defaults: { event: "swipe", threshold: 10, velocity: .65, direction: X | Y, pointers: 1 }, getTouchAction: function () { 1150 return bc.prototype.getTouchAction.call(this); 1151 }, attrTest: function (a) { 1152 var c, 1153 b = this.options.direction;return b & (X | Y) ? c = a.velocity : b & X ? c = a.velocityX : b & Y && (c = a.velocityY), this._super.attrTest.call(this, a) && b & a.direction && a.distance > this.options.threshold && i(c) > this.options.velocity && a.eventType & Q; 1154 }, emit: function (a) { 1155 var b = $b(a.direction);b && this.manager.emit(this.options.event + b, a), this.manager.emit(this.options.event, a); 1156 } }), p(gc, Yb, { defaults: { event: "tap", pointers: 1, taps: 1, interval: 300, time: 250, threshold: 2, posThreshold: 10 }, getTouchAction: function () { 1157 return [Lb]; 1158 }, process: function (a) { 1159 var b = this.options, 1160 c = a.pointers.length === b.pointers, 1161 d = a.distance < b.threshold, 1162 e = a.deltaTime < b.time;if (this.reset(), a.eventType & O && 0 === this.count) return this.failTimeout();if (d && e && c) { 1163 if (a.eventType != Q) return this.failTimeout();var f = this.pTime ? a.timeStamp - this.pTime < b.interval : !0, 1164 g = !this.pCenter || kb(this.pCenter, a.center) < b.posThreshold;this.pTime = a.timeStamp, this.pCenter = a.center, g && f ? this.count += 1 : this.count = 1, this._input = a;var h = this.count % b.taps;if (0 === h) return this.hasRequireFailures() ? (this._timer = k(function () { 1165 this.state = Vb, this.tryEmit(); 1166 }, b.interval, this), Sb) : Vb; 1167 }return Xb; 1168 }, failTimeout: function () { 1169 return this._timer = k(function () { 1170 this.state = Xb; 1171 }, this.options.interval, this), Xb; 1172 }, reset: function () { 1173 clearTimeout(this._timer); 1174 }, emit: function () { 1175 this.state == Vb && (this._input.tapCount = this.count, this.manager.emit(this.options.event, this._input)); 1176 } }), hc.VERSION = "2.0.4", hc.defaults = { domEvents: !1, touchAction: Jb, enable: !0, inputTarget: null, inputClass: null, preset: [[ec, { enable: !1 }], [cc, { enable: !1 }, ["rotate"]], [fc, { direction: X }], [bc, { direction: X }, ["swipe"]], [gc], [gc, { event: "doubletap", taps: 2 }, ["tap"]], [dc]], cssProps: { userSelect: "default", touchSelect: "none", touchCallout: "none", contentZooming: "none", userDrag: "none", tapHighlightColor: "rgba(0,0,0,0)" } };var ic = 1, 1177 jc = 2;kc.prototype = { set: function (a) { 1178 return n(this.options, a), a.touchAction && this.touchAction.update(), a.inputTarget && (this.input.destroy(), this.input.target = a.inputTarget, this.input.init()), this; 1179 }, stop: function (a) { 1180 this.session.stopped = a ? jc : ic; 1181 }, recognize: function (a) { 1182 var b = this.session;if (!b.stopped) { 1183 this.touchAction.preventDefaults(a);var c, 1184 d = this.recognizers, 1185 e = b.curRecognizer;(!e || e && e.state & Vb) && (e = b.curRecognizer = null);for (var f = 0; f < d.length;) { 1186 c = d[f], b.stopped === jc || e && c != e && !c.canRecognizeWith(e) ? c.reset() : c.recognize(a), !e && c.state & (Sb | Tb | Ub) && (e = b.curRecognizer = c), f++; 1187 } 1188 } 1189 }, get: function (a) { 1190 if (a instanceof Yb) return a;for (var b = this.recognizers, c = 0; c < b.length; c++) { 1191 if (b[c].options.event == a) return b[c]; 1192 }return null; 1193 }, add: function (a) { 1194 if (l(a, "add", this)) return this;var b = this.get(a.options.event);return b && this.remove(b), this.recognizers.push(a), a.manager = this, this.touchAction.update(), a; 1195 }, remove: function (a) { 1196 if (l(a, "remove", this)) return this;var b = this.recognizers;return a = this.get(a), b.splice(y(b, a), 1), this.touchAction.update(), this; 1197 }, on: function (a, b) { 1198 var c = this.handlers;return m(x(a), function (a) { 1199 c[a] = c[a] || [], c[a].push(b); 1200 }), this; 1201 }, off: function (a, b) { 1202 var c = this.handlers;return m(x(a), function (a) { 1203 b ? c[a].splice(y(c[a], b), 1) : delete c[a]; 1204 }), this; 1205 }, emit: function (a, b) { 1206 this.options.domEvents && mc(a, b);var c = this.handlers[a] && this.handlers[a].slice();if (c && c.length) { 1207 b.type = a, b.preventDefault = function () { 1208 b.srcEvent.preventDefault(); 1209 };for (var d = 0; d < c.length;) { 1210 c[d](b), d++; 1211 } 1212 } 1213 }, destroy: function () { 1214 this.element && lc(this, !1), this.handlers = {}, this.session = {}, this.input.destroy(), this.element = null; 1215 } }, n(hc, { INPUT_START: O, INPUT_MOVE: P, INPUT_END: Q, INPUT_CANCEL: R, STATE_POSSIBLE: Rb, STATE_BEGAN: Sb, STATE_CHANGED: Tb, STATE_ENDED: Ub, STATE_RECOGNIZED: Vb, STATE_CANCELLED: Wb, STATE_FAILED: Xb, DIRECTION_NONE: S, DIRECTION_LEFT: T, DIRECTION_RIGHT: U, DIRECTION_UP: V, DIRECTION_DOWN: W, DIRECTION_HORIZONTAL: X, DIRECTION_VERTICAL: Y, DIRECTION_ALL: Z, Manager: kc, Input: ab, TouchAction: Pb, TouchInput: Eb, MouseInput: rb, PointerEventInput: wb, TouchMouseInput: Gb, SingleTouchInput: Ab, Recognizer: Yb, AttrRecognizer: ac, Tap: gc, Pan: bc, Swipe: fc, Pinch: cc, Rotate: ec, Press: dc, on: t, off: u, each: m, merge: o, extend: n, inherit: p, bindFn: q, prefixed: B }), typeof define == g && define.amd ? define(function () { 1216 return hc; 1217 }) : "undefined" != typeof module && module.exports ? module.exports = hc : a[c] = hc; 1218 }(window, document, "Hammer");;(function (factory) { 1219 if (typeof define === 'function' && define.amd) { 1220 define(['jquery', 'hammerjs'], factory); 1221 } else if (typeof exports === 'object') { 1222 factory(require('jquery'), require('hammerjs')); 1223 } else { 1224 factory(jQuery, Hammer); 1225 } 1226 })(function ($, Hammer) { 1227 function hammerify(el, options) { 1228 var $el = $(el); 1229 if (!$el.data("hammer")) { 1230 $el.data("hammer", new Hammer($el[0], options)); 1231 } 1232 } 1233 1234 $.fn.hammer = function (options) { 1235 return this.each(function () { 1236 hammerify(this, options); 1237 }); 1238 }; 1239 1240 // extend the emit method to also trigger jQuery events 1241 Hammer.Manager.prototype.emit = function (originalEmit) { 1242 return function (type, data) { 1243 originalEmit.call(this, type, data); 1244 $(this.element).trigger({ 1245 type: type, 1246 gesture: data 1247 }); 1248 }; 1249 }(Hammer.Manager.prototype.emit); 1250 }); 1251 ; // Required for Meteor package, the use of window prevents export by Meteor 1252 (function (window) { 1253 if (window.Package) { 1254 Materialize = {}; 1255 } else { 1256 window.Materialize = {}; 1257 } 1258 })(window); 1259 1260 if (typeof exports !== 'undefined' && !exports.nodeType) { 1261 if (typeof module !== 'undefined' && !module.nodeType && module.exports) { 1262 exports = module.exports = Materialize; 1263 } 1264 exports.default = Materialize; 1265 } 1266 1267 /* 1268 * raf.js 1269 * https://github.com/ngryman/raf.js 1270 * 1271 * original requestAnimationFrame polyfill by Erik Möller 1272 * inspired from paul_irish gist and post 1273 * 1274 * Copyright (c) 2013 ngryman 1275 * Licensed under the MIT license. 1276 */ 1277 (function (window) { 1278 var lastTime = 0, 1279 vendors = ['webkit', 'moz'], 1280 requestAnimationFrame = window.requestAnimationFrame, 1281 cancelAnimationFrame = window.cancelAnimationFrame, 1282 i = vendors.length; 1283 1284 // try to un-prefix existing raf 1285 while (--i >= 0 && !requestAnimationFrame) { 1286 requestAnimationFrame = window[vendors[i] + 'RequestAnimationFrame']; 1287 cancelAnimationFrame = window[vendors[i] + 'CancelRequestAnimationFrame']; 1288 } 1289 1290 // polyfill with setTimeout fallback 1291 // heavily inspired from @darius gist mod: https://gist.github.com/paulirish/1579671#comment-837945 1292 if (!requestAnimationFrame || !cancelAnimationFrame) { 1293 requestAnimationFrame = function (callback) { 1294 var now = +Date.now(), 1295 nextTime = Math.max(lastTime + 16, now); 1296 return setTimeout(function () { 1297 callback(lastTime = nextTime); 1298 }, nextTime - now); 1299 }; 1300 1301 cancelAnimationFrame = clearTimeout; 1302 } 1303 1304 // export to window 1305 window.requestAnimationFrame = requestAnimationFrame; 1306 window.cancelAnimationFrame = cancelAnimationFrame; 1307 })(window); 1308 1309 /** 1310 * Generate approximated selector string for a jQuery object 1311 * @param {jQuery} obj jQuery object to be parsed 1312 * @returns {string} 1313 */ 1314 Materialize.objectSelectorString = function (obj) { 1315 var tagStr = obj.prop('tagName') || ''; 1316 var idStr = obj.attr('id') || ''; 1317 var classStr = obj.attr('class') || ''; 1318 return (tagStr + idStr + classStr).replace(/\s/g, ''); 1319 }; 1320 1321 // Unique Random ID 1322 Materialize.guid = function () { 1323 function s4() { 1324 return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1); 1325 } 1326 return function () { 1327 return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); 1328 }; 1329 }(); 1330 1331 /** 1332 * Escapes hash from special characters 1333 * @param {string} hash String returned from this.hash 1334 * @returns {string} 1335 */ 1336 Materialize.escapeHash = function (hash) { 1337 return hash.replace(/(:|\.|\[|\]|,|=)/g, "\\$1"); 1338 }; 1339 1340 Materialize.elementOrParentIsFixed = function (element) { 1341 var $element = $(element); 1342 var $checkElements = $element.add($element.parents()); 1343 var isFixed = false; 1344 $checkElements.each(function () { 1345 if ($(this).css("position") === "fixed") { 1346 isFixed = true; 1347 return false; 1348 } 1349 }); 1350 return isFixed; 1351 }; 1352 1353 /** 1354 * Get time in ms 1355 * @license https://raw.github.com/jashkenas/underscore/master/LICENSE 1356 * @type {function} 1357 * @return {number} 1358 */ 1359 var getTime = Date.now || function () { 1360 return new Date().getTime(); 1361 }; 1362 1363 /** 1364 * Returns a function, that, when invoked, will only be triggered at most once 1365 * during a given window of time. Normally, the throttled function will run 1366 * as much as it can, without ever going more than once per `wait` duration; 1367 * but if you'd like to disable the execution on the leading edge, pass 1368 * `{leading: false}`. To disable execution on the trailing edge, ditto. 1369 * @license https://raw.github.com/jashkenas/underscore/master/LICENSE 1370 * @param {function} func 1371 * @param {number} wait 1372 * @param {Object=} options 1373 * @returns {Function} 1374 */ 1375 Materialize.throttle = function (func, wait, options) { 1376 var context, args, result; 1377 var timeout = null; 1378 var previous = 0; 1379 options || (options = {}); 1380 var later = function () { 1381 previous = options.leading === false ? 0 : getTime(); 1382 timeout = null; 1383 result = func.apply(context, args); 1384 context = args = null; 1385 }; 1386 return function () { 1387 var now = getTime(); 1388 if (!previous && options.leading === false) previous = now; 1389 var remaining = wait - (now - previous); 1390 context = this; 1391 args = arguments; 1392 if (remaining <= 0) { 1393 clearTimeout(timeout); 1394 timeout = null; 1395 previous = now; 1396 result = func.apply(context, args); 1397 context = args = null; 1398 } else if (!timeout && options.trailing !== false) { 1399 timeout = setTimeout(later, remaining); 1400 } 1401 return result; 1402 }; 1403 }; 1404 1405 // Velocity has conflicts when loaded with jQuery, this will check for it 1406 // First, check if in noConflict mode 1407 var Vel; 1408 if (jQuery) { 1409 Vel = jQuery.Velocity; 1410 } else if ($) { 1411 Vel = $.Velocity; 1412 } else { 1413 Vel = Velocity; 1414 } 1415 1416 if (Vel) { 1417 Materialize.Vel = Vel; 1418 } else { 1419 Materialize.Vel = Velocity; 1420 } 1421 ;(function ($) { 1422 $.fn.collapsible = function (options, methodParam) { 1423 var defaults = { 1424 accordion: undefined, 1425 onOpen: undefined, 1426 onClose: undefined 1427 }; 1428 1429 var methodName = options; 1430 options = $.extend(defaults, options); 1431 1432 return this.each(function () { 1433 1434 var $this = $(this); 1435 1436 var $panel_headers = $(this).find('> li > .collapsible-header'); 1437 1438 var collapsible_type = $this.data("collapsible"); 1439 1440 /**************** 1441 Helper Functions 1442 ****************/ 1443 1444 // Accordion Open 1445 function accordionOpen(object) { 1446 $panel_headers = $this.find('> li > .collapsible-header'); 1447 if (object.hasClass('active')) { 1448 object.parent().addClass('active'); 1449 } else { 1450 object.parent().removeClass('active'); 1451 } 1452 if (object.parent().hasClass('active')) { 1453 object.siblings('.collapsible-body').stop(true, false).slideDown({ duration: 350, easing: "easeOutQuart", queue: false, complete: function () { 1454 $(this).css('height', ''); 1455 } }); 1456 } else { 1457 object.siblings('.collapsible-body').stop(true, false).slideUp({ duration: 350, easing: "easeOutQuart", queue: false, complete: function () { 1458 $(this).css('height', ''); 1459 } }); 1460 } 1461 1462 $panel_headers.not(object).removeClass('active').parent().removeClass('active'); 1463 1464 // Close previously open accordion elements. 1465 $panel_headers.not(object).parent().children('.collapsible-body').stop(true, false).each(function () { 1466 if ($(this).is(':visible')) { 1467 $(this).slideUp({ 1468 duration: 350, 1469 easing: "easeOutQuart", 1470 queue: false, 1471 complete: function () { 1472 $(this).css('height', ''); 1473 execCallbacks($(this).siblings('.collapsible-header')); 1474 } 1475 }); 1476 } 1477 }); 1478 } 1479 1480 // Expandable Open 1481 function expandableOpen(object) { 1482 if (object.hasClass('active')) { 1483 object.parent().addClass('active'); 1484 } else { 1485 object.parent().removeClass('active'); 1486 } 1487 if (object.parent().hasClass('active')) { 1488 object.siblings('.collapsible-body').stop(true, false).slideDown({ duration: 350, easing: "easeOutQuart", queue: false, complete: function () { 1489 $(this).css('height', ''); 1490 } }); 1491 } else { 1492 object.siblings('.collapsible-body').stop(true, false).slideUp({ duration: 350, easing: "easeOutQuart", queue: false, complete: function () { 1493 $(this).css('height', ''); 1494 } }); 1495 } 1496 } 1497 1498 // Open collapsible. object: .collapsible-header 1499 function collapsibleOpen(object, noToggle) { 1500 if (!noToggle) { 1501 object.toggleClass('active'); 1502 } 1503 1504 if (options.accordion || collapsible_type === "accordion" || collapsible_type === undefined) { 1505 // Handle Accordion 1506 accordionOpen(object); 1507 } else { 1508 // Handle Expandables 1509 expandableOpen(object); 1510 } 1511 1512 execCallbacks(object); 1513 } 1514 1515 // Handle callbacks 1516 function execCallbacks(object) { 1517 if (object.hasClass('active')) { 1518 if (typeof options.onOpen === "function") { 1519 options.onOpen.call(this, object.parent()); 1520 } 1521 } else { 1522 if (typeof options.onClose === "function") { 1523 options.onClose.call(this, object.parent()); 1524 } 1525 } 1526 } 1527 1528 /** 1529 * Check if object is children of panel header 1530 * @param {Object} object Jquery object 1531 * @return {Boolean} true if it is children 1532 */ 1533 function isChildrenOfPanelHeader(object) { 1534 1535 var panelHeader = getPanelHeader(object); 1536 1537 return panelHeader.length > 0; 1538 } 1539 1540 /** 1541 * Get panel header from a children element 1542 * @param {Object} object Jquery object 1543 * @return {Object} panel header object 1544 */ 1545 function getPanelHeader(object) { 1546 1547 return object.closest('li > .collapsible-header'); 1548 } 1549 1550 // Turn off any existing event handlers 1551 function removeEventHandlers() { 1552 $this.off('click.collapse', '> li > .collapsible-header'); 1553 } 1554 1555 /***** End Helper Functions *****/ 1556 1557 // Methods 1558 if (methodName === 'destroy') { 1559 removeEventHandlers(); 1560 return; 1561 } else if (methodParam >= 0 && methodParam < $panel_headers.length) { 1562 var $curr_header = $panel_headers.eq(methodParam); 1563 if ($curr_header.length && (methodName === 'open' || methodName === 'close' && $curr_header.hasClass('active'))) { 1564 collapsibleOpen($curr_header); 1565 } 1566 return; 1567 } 1568 1569 removeEventHandlers(); 1570 1571 // Add click handler to only direct collapsible header children 1572 $this.on('click.collapse', '> li > .collapsible-header', function (e) { 1573 var element = $(e.target); 1574 1575 if (isChildrenOfPanelHeader(element)) { 1576 element = getPanelHeader(element); 1577 } 1578 1579 collapsibleOpen(element); 1580 }); 1581 1582 // Open first active 1583 if (options.accordion || collapsible_type === "accordion" || collapsible_type === undefined) { 1584 // Handle Accordion 1585 collapsibleOpen($panel_headers.filter('.active').first(), true); 1586 } else { 1587 // Handle Expandables 1588 $panel_headers.filter('.active').each(function () { 1589 collapsibleOpen($(this), true); 1590 }); 1591 } 1592 }); 1593 }; 1594 1595 $(document).ready(function () { 1596 $('.collapsible').collapsible(); 1597 }); 1598 })(jQuery);;(function ($) { 1599 1600 // Add posibility to scroll to selected option 1601 // usefull for select for example 1602 $.fn.scrollTo = function (elem) { 1603 $(this).scrollTop($(this).scrollTop() - $(this).offset().top + $(elem).offset().top); 1604 return this; 1605 }; 1606 1607 $.fn.dropdown = function (options) { 1608 var defaults = { 1609 inDuration: 300, 1610 outDuration: 225, 1611 constrainWidth: true, // Constrains width of dropdown to the activator 1612 hover: false, 1613 gutter: 0, // Spacing from edge 1614 belowOrigin: false, 1615 alignment: 'left', 1616 stopPropagation: false 1617 }; 1618 1619 // Open dropdown. 1620 if (options === "open") { 1621 this.each(function () { 1622 $(this).trigger('open'); 1623 }); 1624 return false; 1625 } 1626 1627 // Close dropdown. 1628 if (options === "close") { 1629 this.each(function () { 1630 $(this).trigger('close'); 1631 }); 1632 return false; 1633 } 1634 1635 this.each(function () { 1636 var origin = $(this); 1637 var curr_options = $.extend({}, defaults, options); 1638 var isFocused = false; 1639 1640 // Dropdown menu 1641 var activates = $("#" + origin.attr('data-activates')); 1642 1643 function updateOptions() { 1644 if (origin.data('induration') !== undefined) curr_options.inDuration = origin.data('induration'); 1645 if (origin.data('outduration') !== undefined) curr_options.outDuration = origin.data('outduration'); 1646 if (origin.data('constrainwidth') !== undefined) curr_options.constrainWidth = origin.data('constrainwidth'); 1647 if (origin.data('hover') !== undefined) curr_options.hover = origin.data('hover'); 1648 if (origin.data('gutter') !== undefined) curr_options.gutter = origin.data('gutter'); 1649 if (origin.data('beloworigin') !== undefined) curr_options.belowOrigin = origin.data('beloworigin'); 1650 if (origin.data('alignment') !== undefined) curr_options.alignment = origin.data('alignment'); 1651 if (origin.data('stoppropagation') !== undefined) curr_options.stopPropagation = origin.data('stoppropagation'); 1652 } 1653 1654 updateOptions(); 1655 1656 // Attach dropdown to its activator 1657 origin.after(activates); 1658 1659 /* 1660 Helper function to position and resize dropdown. 1661 Used in hover and click handler. 1662 */ 1663 function placeDropdown(eventType) { 1664 // Check for simultaneous focus and click events. 1665 if (eventType === 'focus') { 1666 isFocused = true; 1667 } 1668 1669 // Check html data attributes 1670 updateOptions(); 1671 1672 // Set Dropdown state 1673 activates.addClass('active'); 1674 origin.addClass('active'); 1675 1676 var originWidth = origin[0].getBoundingClientRect().width; 1677 1678 // Constrain width 1679 if (curr_options.constrainWidth === true) { 1680 activates.css('width', originWidth); 1681 } else { 1682 activates.css('white-space', 'nowrap'); 1683 } 1684 1685 // Offscreen detection 1686 var windowHeight = window.innerHeight; 1687 var originHeight = origin.innerHeight(); 1688 var offsetLeft = origin.offset().left; 1689 var offsetTop = origin.offset().top - $(window).scrollTop(); 1690 var currAlignment = curr_options.alignment; 1691 var gutterSpacing = 0; 1692 var leftPosition = 0; 1693 1694 // Below Origin 1695 var verticalOffset = 0; 1696 if (curr_options.belowOrigin === true) { 1697 verticalOffset = originHeight; 1698 } 1699 1700 // Check for scrolling positioned container. 1701 var scrollYOffset = 0; 1702 var scrollXOffset = 0; 1703 var wrapper = origin.parent(); 1704 if (!wrapper.is('body')) { 1705 if (wrapper[0].scrollHeight > wrapper[0].clientHeight) { 1706 scrollYOffset = wrapper[0].scrollTop; 1707 } 1708 if (wrapper[0].scrollWidth > wrapper[0].clientWidth) { 1709 scrollXOffset = wrapper[0].scrollLeft; 1710 } 1711 } 1712 1713 if (offsetLeft + activates.innerWidth() > $(window).width()) { 1714 // Dropdown goes past screen on right, force right alignment 1715 currAlignment = 'right'; 1716 } else if (offsetLeft - activates.innerWidth() + origin.innerWidth() < 0) { 1717 // Dropdown goes past screen on left, force left alignment 1718 currAlignment = 'left'; 1719 } 1720 // Vertical bottom offscreen detection 1721 if (offsetTop + activates.innerHeight() > windowHeight) { 1722 // If going upwards still goes offscreen, just crop height of dropdown. 1723 if (offsetTop + originHeight - activates.innerHeight() < 0) { 1724 var adjustedHeight = windowHeight - offsetTop - verticalOffset; 1725 activates.css('max-height', adjustedHeight); 1726 } else { 1727 // Flow upwards. 1728 if (!verticalOffset) { 1729 verticalOffset += originHeight; 1730 } 1731 verticalOffset -= activates.innerHeight(); 1732 } 1733 } 1734 1735 // Handle edge alignment 1736 if (currAlignment === 'left') { 1737 gutterSpacing = curr_options.gutter; 1738 leftPosition = origin.position().left + gutterSpacing; 1739 } else if (currAlignment === 'right') { 1740 // Material icons fix 1741 activates.stop(true, true).css({ 1742 opacity: 0, 1743 left: 0 1744 }); 1745 1746 var offsetRight = origin.position().left + originWidth - activates.width(); 1747 gutterSpacing = -curr_options.gutter; 1748 leftPosition = offsetRight + gutterSpacing; 1749 } 1750 1751 // Position dropdown 1752 activates.css({ 1753 position: 'absolute', 1754 top: origin.position().top + verticalOffset + scrollYOffset, 1755 left: leftPosition + scrollXOffset 1756 }); 1757 1758 // Show dropdown 1759 activates.slideDown({ 1760 queue: false, 1761 duration: curr_options.inDuration, 1762 easing: 'easeOutCubic', 1763 complete: function () { 1764 $(this).css('height', ''); 1765 } 1766 }).animate({ opacity: 1 }, { queue: false, duration: curr_options.inDuration, easing: 'easeOutSine' }); 1767 1768 // Add click close handler to document 1769 setTimeout(function () { 1770 $(document).on('click.' + activates.attr('id'), function (e) { 1771 hideDropdown(); 1772 $(document).off('click.' + activates.attr('id')); 1773 }); 1774 }, 0); 1775 } 1776 1777 function hideDropdown() { 1778 // Check for simultaneous focus and click events. 1779 isFocused = false; 1780 activates.fadeOut(curr_options.outDuration); 1781 activates.removeClass('active'); 1782 origin.removeClass('active'); 1783 $(document).off('click.' + activates.attr('id')); 1784 setTimeout(function () { 1785 activates.css('max-height', ''); 1786 }, curr_options.outDuration); 1787 } 1788 1789 // Hover 1790 if (curr_options.hover) { 1791 var open = false; 1792 origin.off('click.' + origin.attr('id')); 1793 // Hover handler to show dropdown 1794 origin.on('mouseenter', function (e) { 1795 // Mouse over 1796 if (open === false) { 1797 placeDropdown(); 1798 open = true; 1799 } 1800 }); 1801 origin.on('mouseleave', function (e) { 1802 // If hover on origin then to something other than dropdown content, then close 1803 var toEl = e.toElement || e.relatedTarget; // added browser compatibility for target element 1804 if (!$(toEl).closest('.dropdown-content').is(activates)) { 1805 activates.stop(true, true); 1806 hideDropdown(); 1807 open = false; 1808 } 1809 }); 1810 1811 activates.on('mouseleave', function (e) { 1812 // Mouse out 1813 var toEl = e.toElement || e.relatedTarget; 1814 if (!$(toEl).closest('.dropdown-button').is(origin)) { 1815 activates.stop(true, true); 1816 hideDropdown(); 1817 open = false; 1818 } 1819 }); 1820 1821 // Click 1822 } else { 1823 // Click handler to show dropdown 1824 origin.off('click.' + origin.attr('id')); 1825 origin.on('click.' + origin.attr('id'), function (e) { 1826 if (!isFocused) { 1827 if (origin[0] == e.currentTarget && !origin.hasClass('active') && $(e.target).closest('.dropdown-content').length === 0) { 1828 e.preventDefault(); // Prevents button click from moving window 1829 if (curr_options.stopPropagation) { 1830 e.stopPropagation(); 1831 } 1832 placeDropdown('click'); 1833 } 1834 // If origin is clicked and menu is open, close menu 1835 else if (origin.hasClass('active')) { 1836 hideDropdown(); 1837 $(document).off('click.' + activates.attr('id')); 1838 } 1839 } 1840 }); 1841 } // End else 1842 1843 // Listen to open and close event - useful for select component 1844 origin.on('open', function (e, eventType) { 1845 placeDropdown(eventType); 1846 }); 1847 origin.on('close', hideDropdown); 1848 }); 1849 }; // End dropdown plugin 1850 1851 $(document).ready(function () { 1852 $('.dropdown-button').dropdown(); 1853 }); 1854 })(jQuery); 1855 ;(function ($, Vel) { 1856 'use strict'; 1857 1858 var _defaults = { 1859 opacity: 0.5, 1860 inDuration: 250, 1861 outDuration: 250, 1862 ready: undefined, 1863 complete: undefined, 1864 dismissible: true, 1865 startingTop: '4%', 1866 endingTop: '10%' 1867 }; 1868 1869 /** 1870 * @class 1871 * 1872 */ 1873 1874 var Modal = function () { 1875 /** 1876 * Construct Modal instance and set up overlay 1877 * @constructor 1878 * @param {jQuery} $el 1879 * @param {Object} options 1880 */ 1881 function Modal($el, options) { 1882 _classCallCheck(this, Modal); 1883 1884 // If exists, destroy and reinitialize 1885 if (!!$el[0].M_Modal) { 1886 $el[0].M_Modal.destroy(); 1887 } 1888 1889 /** 1890 * The jQuery element 1891 * @type {jQuery} 1892 */ 1893 this.$el = $el; 1894 1895 /** 1896 * Options for the modal 1897 * @member Modal#options 1898 * @prop {Number} [opacity=0.5] - Opacity of the modal overlay 1899 * @prop {Number} [inDuration=250] - Length in ms of enter transition 1900 * @prop {Number} [outDuration=250] - Length in ms of exit transition 1901 * @prop {Function} ready - Callback function called when modal is finished entering 1902 * @prop {Function} complete - Callback function called when modal is finished exiting 1903 * @prop {Boolean} [dismissible=true] - Allow modal to be dismissed by keyboard or overlay click 1904 * @prop {String} [startingTop='4%'] - startingTop 1905 * @prop {String} [endingTop='10%'] - endingTop 1906 */ 1907 this.options = $.extend({}, Modal.defaults, options); 1908 1909 /** 1910 * Describes open/close state of modal 1911 * @type {Boolean} 1912 */ 1913 this.isOpen = false; 1914 1915 this.$el[0].M_Modal = this; 1916 this.id = $el.attr('id'); 1917 this.openingTrigger = undefined; 1918 this.$overlay = $('<div class="modal-overlay"></div>'); 1919 1920 Modal._increment++; 1921 Modal._count++; 1922 this.$overlay[0].style.zIndex = 1000 + Modal._increment * 2; 1923 this.$el[0].style.zIndex = 1000 + Modal._increment * 2 + 1; 1924 this.setupEventHandlers(); 1925 } 1926 1927 _createClass(Modal, [{ 1928 key: 'getInstance', 1929 1930 1931 /** 1932 * Get Instance 1933 */ 1934 value: function getInstance() { 1935 return this; 1936 } 1937 1938 /** 1939 * Teardown component 1940 */ 1941 1942 }, { 1943 key: 'destroy', 1944 value: function destroy() { 1945 this.removeEventHandlers(); 1946 this.$el[0].removeAttribute('style'); 1947 if (!!this.$overlay[0].parentNode) { 1948 this.$overlay[0].parentNode.removeChild(this.$overlay[0]); 1949 } 1950 this.$el[0].M_Modal = undefined; 1951 Modal._count--; 1952 } 1953 1954 /** 1955 * Setup Event Handlers 1956 */ 1957 1958 }, { 1959 key: 'setupEventHandlers', 1960 value: function setupEventHandlers() { 1961 this.handleOverlayClickBound = this.handleOverlayClick.bind(this); 1962 this.handleModalCloseClickBound = this.handleModalCloseClick.bind(this); 1963 1964 if (Modal._count === 1) { 1965 document.body.addEventListener('click', this.handleTriggerClick); 1966 } 1967 this.$overlay[0].addEventListener('click', this.handleOverlayClickBound); 1968 this.$el[0].addEventListener('click', this.handleModalCloseClickBound); 1969 } 1970 1971 /** 1972 * Remove Event Handlers 1973 */ 1974 1975 }, { 1976 key: 'removeEventHandlers', 1977 value: function removeEventHandlers() { 1978 if (Modal._count === 0) { 1979 document.body.removeEventListener('click', this.handleTriggerClick); 1980 } 1981 this.$overlay[0].removeEventListener('click', this.handleOverlayClickBound); 1982 this.$el[0].removeEventListener('click', this.handleModalCloseClickBound); 1983 } 1984 1985 /** 1986 * Handle Trigger Click 1987 * @param {Event} e 1988 */ 1989 1990 }, { 1991 key: 'handleTriggerClick', 1992 value: function handleTriggerClick(e) { 1993 var $trigger = $(e.target).closest('.modal-trigger'); 1994 if (e.target && $trigger.length) { 1995 var modalId = $trigger[0].getAttribute('href'); 1996 if (modalId) { 1997 modalId = modalId.slice(1); 1998 } else { 1999 modalId = $trigger[0].getAttribute('data-target'); 2000 } 2001 var modalInstance = document.getElementById(modalId).M_Modal; 2002 if (modalInstance) { 2003 modalInstance.open($trigger); 2004 } 2005 e.preventDefault(); 2006 } 2007 } 2008 2009 /** 2010 * Handle Overlay Click 2011 */ 2012 2013 }, { 2014 key: 'handleOverlayClick', 2015 value: function handleOverlayClick() { 2016 if (this.options.dismissible) { 2017 this.close(); 2018 } 2019 } 2020 2021 /** 2022 * Handle Modal Close Click 2023 * @param {Event} e 2024 */ 2025 2026 }, { 2027 key: 'handleModalCloseClick', 2028 value: function handleModalCloseClick(e) { 2029 var $closeTrigger = $(e.target).closest('.modal-close'); 2030 if (e.target && $closeTrigger.length) { 2031 this.close(); 2032 } 2033 } 2034 2035 /** 2036 * Handle Keydown 2037 * @param {Event} e 2038 */ 2039 2040 }, { 2041 key: 'handleKeydown', 2042 value: function handleKeydown(e) { 2043 // ESC key 2044 if (e.keyCode === 27 && this.options.dismissible) { 2045 this.close(); 2046 } 2047 } 2048 2049 /** 2050 * Animate in modal 2051 */ 2052 2053 }, { 2054 key: 'animateIn', 2055 value: function animateIn() { 2056 var _this = this; 2057 2058 // Set initial styles 2059 $.extend(this.$el[0].style, { 2060 display: 'block', 2061 opacity: 0 2062 }); 2063 $.extend(this.$overlay[0].style, { 2064 display: 'block', 2065 opacity: 0 2066 }); 2067 2068 // Animate overlay 2069 Vel(this.$overlay[0], { opacity: this.options.opacity }, { duration: this.options.inDuration, queue: false, ease: 'easeOutCubic' }); 2070 2071 // Define modal animation options 2072 var enterVelocityOptions = { 2073 duration: this.options.inDuration, 2074 queue: false, 2075 ease: 'easeOutCubic', 2076 // Handle modal ready callback 2077 complete: function () { 2078 if (typeof _this.options.ready === 'function') { 2079 _this.options.ready.call(_this, _this.$el, _this.openingTrigger); 2080 } 2081 } 2082 }; 2083 2084 // Bottom sheet animation 2085 if (this.$el[0].classList.contains('bottom-sheet')) { 2086 Vel(this.$el[0], { bottom: 0, opacity: 1 }, enterVelocityOptions); 2087 2088 // Normal modal animation 2089 } else { 2090 Vel.hook(this.$el[0], 'scaleX', 0.7); 2091 this.$el[0].style.top = this.options.startingTop; 2092 Vel(this.$el[0], { top: this.options.endingTop, opacity: 1, scaleX: 1 }, enterVelocityOptions); 2093 } 2094 } 2095 2096 /** 2097 * Animate out modal 2098 */ 2099 2100 }, { 2101 key: 'animateOut', 2102 value: function animateOut() { 2103 var _this2 = this; 2104 2105 // Animate overlay 2106 Vel(this.$overlay[0], { opacity: 0 }, { duration: this.options.outDuration, queue: false, ease: 'easeOutQuart' }); 2107 2108 // Define modal animation options 2109 var exitVelocityOptions = { 2110 duration: this.options.outDuration, 2111 queue: false, 2112 ease: 'easeOutCubic', 2113 // Handle modal ready callback 2114 complete: function () { 2115 _this2.$el[0].style.display = 'none'; 2116 // Call complete callback 2117 if (typeof _this2.options.complete === 'function') { 2118 _this2.options.complete.call(_this2, _this2.$el); 2119 } 2120 _this2.$overlay[0].parentNode.removeChild(_this2.$overlay[0]); 2121 } 2122 }; 2123 2124 // Bottom sheet animation 2125 if (this.$el[0].classList.contains('bottom-sheet')) { 2126 Vel(this.$el[0], { bottom: '-100%', opacity: 0 }, exitVelocityOptions); 2127 2128 // Normal modal animation 2129 } else { 2130 Vel(this.$el[0], { top: this.options.startingTop, opacity: 0, scaleX: 0.7 }, exitVelocityOptions); 2131 } 2132 } 2133 2134 /** 2135 * Open Modal 2136 * @param {jQuery} [$trigger] 2137 */ 2138 2139 }, { 2140 key: 'open', 2141 value: function open($trigger) { 2142 if (this.isOpen) { 2143 return; 2144 } 2145 2146 this.isOpen = true; 2147 var body = document.body; 2148 body.style.overflow = 'hidden'; 2149 this.$el[0].classList.add('open'); 2150 body.appendChild(this.$overlay[0]); 2151 2152 // Set opening trigger, undefined indicates modal was opened by javascript 2153 this.openingTrigger = !!$trigger ? $trigger : undefined; 2154 2155 if (this.options.dismissible) { 2156 this.handleKeydownBound = this.handleKeydown.bind(this); 2157 document.addEventListener('keydown', this.handleKeydownBound); 2158 } 2159 2160 this.animateIn(); 2161 2162 return this; 2163 } 2164 2165 /** 2166 * Close Modal 2167 */ 2168 2169 }, { 2170 key: 'close', 2171 value: function close() { 2172 if (!this.isOpen) { 2173 return; 2174 } 2175 2176 this.isOpen = false; 2177 this.$el[0].classList.remove('open'); 2178 document.body.style.overflow = ''; 2179 2180 if (this.options.dismissible) { 2181 document.removeEventListener('keydown', this.handleKeydownBound); 2182 } 2183 2184 this.animateOut(); 2185 2186 return this; 2187 } 2188 }], [{ 2189 key: 'init', 2190 value: function init($els, options) { 2191 var arr = []; 2192 $els.each(function () { 2193 arr.push(new Modal($(this), options)); 2194 }); 2195 return arr; 2196 } 2197 }, { 2198 key: 'defaults', 2199 get: function () { 2200 return _defaults; 2201 } 2202 }]); 2203 2204 return Modal; 2205 }(); 2206 2207 /** 2208 * @static 2209 * @memberof Modal 2210 */ 2211 2212 2213 Modal._increment = 0; 2214 2215 /** 2216 * @static 2217 * @memberof Modal 2218 */ 2219 Modal._count = 0; 2220 2221 Materialize.Modal = Modal; 2222 2223 $.fn.modal = function (methodOrOptions) { 2224 // Call plugin method if valid method name is passed in 2225 if (Modal.prototype[methodOrOptions]) { 2226 // Getter methods 2227 if (methodOrOptions.slice(0, 3) === 'get') { 2228 return this.first()[0].M_Modal[methodOrOptions](); 2229 2230 // Void methods 2231 } else { 2232 return this.each(function () { 2233 this.M_Modal[methodOrOptions](); 2234 }); 2235 } 2236 2237 // Initialize plugin if options or no argument is passed in 2238 } else if (typeof methodOrOptions === 'object' || !methodOrOptions) { 2239 Modal.init(this, arguments[0]); 2240 return this; 2241 2242 // Return error if an unrecognized method name is passed in 2243 } else { 2244 $.error('Method ' + methodOrOptions + ' does not exist on jQuery.modal'); 2245 } 2246 }; 2247 })(jQuery, Materialize.Vel); 2248 ;(function ($) { 2249 2250 $.fn.materialbox = function () { 2251 2252 return this.each(function () { 2253 2254 if ($(this).hasClass('initialized')) { 2255 return; 2256 } 2257 2258 $(this).addClass('initialized'); 2259 2260 var overlayActive = false; 2261 var doneAnimating = true; 2262 var inDuration = 275; 2263 var outDuration = 200; 2264 var origin = $(this); 2265 var placeholder = $('<div></div>').addClass('material-placeholder'); 2266 var originalWidth = 0; 2267 var originalHeight = 0; 2268 var ancestorsChanged; 2269 var ancestor; 2270 var originInlineStyles = origin.attr('style'); 2271 origin.wrap(placeholder); 2272 2273 // Start click handler 2274 origin.on('click', function () { 2275 var placeholder = origin.parent('.material-placeholder'); 2276 var windowWidth = window.innerWidth; 2277 var windowHeight = window.innerHeight; 2278 var originalWidth = origin.width(); 2279 var originalHeight = origin.height(); 2280 2281 // If already modal, return to original 2282 if (doneAnimating === false) { 2283 returnToOriginal(); 2284 return false; 2285 } else if (overlayActive && doneAnimating === true) { 2286 returnToOriginal(); 2287 return false; 2288 } 2289 2290 // Set states 2291 doneAnimating = false; 2292 origin.addClass('active'); 2293 overlayActive = true; 2294 2295 // Set positioning for placeholder 2296 placeholder.css({ 2297 width: placeholder[0].getBoundingClientRect().width, 2298 height: placeholder[0].getBoundingClientRect().height, 2299 position: 'relative', 2300 top: 0, 2301 left: 0 2302 }); 2303 2304 // Find ancestor with overflow: hidden; and remove it 2305 ancestorsChanged = undefined; 2306 ancestor = placeholder[0].parentNode; 2307 var count = 0; 2308 while (ancestor !== null && !$(ancestor).is(document)) { 2309 var curr = $(ancestor); 2310 if (curr.css('overflow') !== 'visible') { 2311 curr.css('overflow', 'visible'); 2312 if (ancestorsChanged === undefined) { 2313 ancestorsChanged = curr; 2314 } else { 2315 ancestorsChanged = ancestorsChanged.add(curr); 2316 } 2317 } 2318 ancestor = ancestor.parentNode; 2319 } 2320 2321 // Set css on origin 2322 origin.css({ 2323 position: 'absolute', 2324 'z-index': 1000, 2325 'will-change': 'left, top, width, height' 2326 }).data('width', originalWidth).data('height', originalHeight); 2327 2328 // Add overlay 2329 var overlay = $('<div id="materialbox-overlay"></div>').css({ 2330 opacity: 0 2331 }).click(function () { 2332 if (doneAnimating === true) returnToOriginal(); 2333 }); 2334 2335 // Put before in origin image to preserve z-index layering. 2336 origin.before(overlay); 2337 2338 // Set dimensions if needed 2339 var overlayOffset = overlay[0].getBoundingClientRect(); 2340 overlay.css({ 2341 width: windowWidth, 2342 height: windowHeight, 2343 left: -1 * overlayOffset.left, 2344 top: -1 * overlayOffset.top 2345 }); 2346 2347 // Animate Overlay 2348 overlay.velocity({ opacity: 1 }, { duration: inDuration, queue: false, easing: 'easeOutQuad' }); 2349 2350 // Add and animate caption if it exists 2351 if (origin.data('caption') !== "") { 2352 var $photo_caption = $('<div class="materialbox-caption"></div>'); 2353 $photo_caption.text(origin.data('caption')); 2354 $('body').append($photo_caption); 2355 $photo_caption.css({ "display": "inline" }); 2356 $photo_caption.velocity({ opacity: 1 }, { duration: inDuration, queue: false, easing: 'easeOutQuad' }); 2357 } 2358 2359 // Resize Image 2360 var ratio = 0; 2361 var widthPercent = originalWidth / windowWidth; 2362 var heightPercent = originalHeight / windowHeight; 2363 var newWidth = 0; 2364 var newHeight = 0; 2365 2366 if (widthPercent > heightPercent) { 2367 ratio = originalHeight / originalWidth; 2368 newWidth = windowWidth * 0.9; 2369 newHeight = windowWidth * 0.9 * ratio; 2370 } else { 2371 ratio = originalWidth / originalHeight; 2372 newWidth = windowHeight * 0.9 * ratio; 2373 newHeight = windowHeight * 0.9; 2374 } 2375 2376 // Animate image + set z-index 2377 if (origin.hasClass('responsive-img')) { 2378 origin.velocity({ 'max-width': newWidth, 'width': originalWidth }, { duration: 0, queue: false, 2379 complete: function () { 2380 origin.css({ left: 0, top: 0 }).velocity({ 2381 height: newHeight, 2382 width: newWidth, 2383 left: $(document).scrollLeft() + windowWidth / 2 - origin.parent('.material-placeholder').offset().left - newWidth / 2, 2384 top: $(document).scrollTop() + windowHeight / 2 - origin.parent('.material-placeholder').offset().top - newHeight / 2 2385 }, { 2386 duration: inDuration, 2387 queue: false, 2388 easing: 'easeOutQuad', 2389 complete: function () { 2390 doneAnimating = true; 2391 } 2392 }); 2393 } // End Complete 2394 }); // End Velocity 2395 } else { 2396 origin.css('left', 0).css('top', 0).velocity({ 2397 height: newHeight, 2398 width: newWidth, 2399 left: $(document).scrollLeft() + windowWidth / 2 - origin.parent('.material-placeholder').offset().left - newWidth / 2, 2400 top: $(document).scrollTop() + windowHeight / 2 - origin.parent('.material-placeholder').offset().top - newHeight / 2 2401 }, { 2402 duration: inDuration, 2403 queue: false, 2404 easing: 'easeOutQuad', 2405 complete: function () { 2406 doneAnimating = true; 2407 } 2408 }); // End Velocity 2409 } 2410 2411 // Handle Exit triggers 2412 $(window).on('scroll.materialbox', function () { 2413 if (overlayActive) { 2414 returnToOriginal(); 2415 } 2416 }); 2417 2418 $(window).on('resize.materialbox', function () { 2419 if (overlayActive) { 2420 returnToOriginal(); 2421 } 2422 }); 2423 2424 $(document).on('keyup.materialbox', function (e) { 2425 // ESC key 2426 if (e.keyCode === 27 && doneAnimating === true && overlayActive) { 2427 returnToOriginal(); 2428 } 2429 }); 2430 }); // End click handler 2431 2432 2433 // This function returns the modaled image to the original spot 2434 function returnToOriginal() { 2435 2436 doneAnimating = false; 2437 2438 var placeholder = origin.parent('.material-placeholder'); 2439 var windowWidth = window.innerWidth; 2440 var windowHeight = window.innerHeight; 2441 var originalWidth = origin.data('width'); 2442 var originalHeight = origin.data('height'); 2443 2444 origin.velocity("stop", true); 2445 $('#materialbox-overlay').velocity("stop", true); 2446 $('.materialbox-caption').velocity("stop", true); 2447 2448 // disable exit handlers 2449 $(window).off('scroll.materialbox'); 2450 $(document).off('keyup.materialbox'); 2451 $(window).off('resize.materialbox'); 2452 2453 $('#materialbox-overlay').velocity({ opacity: 0 }, { 2454 duration: outDuration, // Delay prevents animation overlapping 2455 queue: false, easing: 'easeOutQuad', 2456 complete: function () { 2457 // Remove Overlay 2458 overlayActive = false; 2459 $(this).remove(); 2460 } 2461 }); 2462 2463 // Resize Image 2464 origin.velocity({ 2465 width: originalWidth, 2466 height: originalHeight, 2467 left: 0, 2468 top: 0 2469 }, { 2470 duration: outDuration, 2471 queue: false, easing: 'easeOutQuad', 2472 complete: function () { 2473 placeholder.css({ 2474 height: '', 2475 width: '', 2476 position: '', 2477 top: '', 2478 left: '' 2479 }); 2480 2481 origin.removeAttr('style'); 2482 origin.attr('style', originInlineStyles); 2483 2484 // Remove class 2485 origin.removeClass('active'); 2486 doneAnimating = true; 2487 2488 // Remove overflow overrides on ancestors 2489 if (ancestorsChanged) { 2490 ancestorsChanged.css('overflow', ''); 2491 } 2492 } 2493 }); 2494 2495 // Remove Caption + reset css settings on image 2496 $('.materialbox-caption').velocity({ opacity: 0 }, { 2497 duration: outDuration, // Delay prevents animation overlapping 2498 queue: false, easing: 'easeOutQuad', 2499 complete: function () { 2500 $(this).remove(); 2501 } 2502 }); 2503 } 2504 }); 2505 }; 2506 2507 $(document).ready(function () { 2508 $('.materialboxed').materialbox(); 2509 }); 2510 })(jQuery); 2511 ;(function ($) { 2512 2513 $.fn.parallax = function () { 2514 var window_width = $(window).width(); 2515 // Parallax Scripts 2516 return this.each(function (i) { 2517 var $this = $(this); 2518 $this.addClass('parallax'); 2519 2520 function updateParallax(initial) { 2521 var container_height; 2522 if (window_width < 601) { 2523 container_height = $this.height() > 0 ? $this.height() : $this.children("img").height(); 2524 } else { 2525 container_height = $this.height() > 0 ? $this.height() : 500; 2526 } 2527 var $img = $this.children("img").first(); 2528 var img_height = $img.height(); 2529 var parallax_dist = img_height - container_height; 2530 var bottom = $this.offset().top + container_height; 2531 var top = $this.offset().top; 2532 var scrollTop = $(window).scrollTop(); 2533 var windowHeight = window.innerHeight; 2534 var windowBottom = scrollTop + windowHeight; 2535 var percentScrolled = (windowBottom - top) / (container_height + windowHeight); 2536 var parallax = Math.round(parallax_dist * percentScrolled); 2537 2538 if (initial) { 2539 $img.css('display', 'block'); 2540 } 2541 if (bottom > scrollTop && top < scrollTop + windowHeight) { 2542 $img.css('transform', "translate3D(-50%," + parallax + "px, 0)"); 2543 } 2544 } 2545 2546 // Wait for image load 2547 $this.children("img").one("load", function () { 2548 updateParallax(true); 2549 }).each(function () { 2550 if (this.complete) $(this).trigger("load"); 2551 }); 2552 2553 $(window).scroll(function () { 2554 window_width = $(window).width(); 2555 updateParallax(false); 2556 }); 2557 2558 $(window).resize(function () { 2559 window_width = $(window).width(); 2560 updateParallax(false); 2561 }); 2562 }); 2563 }; 2564 })(jQuery); 2565 ;(function ($) { 2566 2567 var methods = { 2568 init: function (options) { 2569 var defaults = { 2570 onShow: null, 2571 swipeable: false, 2572 responsiveThreshold: Infinity // breakpoint for swipeable 2573 }; 2574 options = $.extend(defaults, options); 2575 var namespace = Materialize.objectSelectorString($(this)); 2576 2577 return this.each(function (i) { 2578 2579 var uniqueNamespace = namespace + i; 2580 2581 // For each set of tabs, we want to keep track of 2582 // which tab is active and its associated content 2583 var $this = $(this), 2584 window_width = $(window).width(); 2585 2586 var $active, 2587 $content, 2588 $links = $this.find('li.tab a'), 2589 $tabs_width = $this.width(), 2590 $tabs_content = $(), 2591 $tabs_wrapper, 2592 $tab_width = Math.max($tabs_width, $this[0].scrollWidth) / $links.length, 2593 $indicator, 2594 index = 0, 2595 prev_index = 0, 2596 clicked = false, 2597 clickedTimeout, 2598 transition = 300; 2599 2600 // Finds right attribute for indicator based on active tab. 2601 // el: jQuery Object 2602 var calcRightPos = function (el) { 2603 return Math.ceil($tabs_width - el.position().left - el[0].getBoundingClientRect().width - $this.scrollLeft()); 2604 }; 2605 2606 // Finds left attribute for indicator based on active tab. 2607 // el: jQuery Object 2608 var calcLeftPos = function (el) { 2609 return Math.floor(el.position().left + $this.scrollLeft()); 2610 }; 2611 2612 // Animates Indicator to active tab. 2613 // prev_index: Number 2614 var animateIndicator = function (prev_index) { 2615 if (index - prev_index >= 0) { 2616 $indicator.velocity({ "right": calcRightPos($active) }, { duration: transition, queue: false, easing: 'easeOutQuad' }); 2617 $indicator.velocity({ "left": calcLeftPos($active) }, { duration: transition, queue: false, easing: 'easeOutQuad', delay: 90 }); 2618 } else { 2619 $indicator.velocity({ "left": calcLeftPos($active) }, { duration: transition, queue: false, easing: 'easeOutQuad' }); 2620 $indicator.velocity({ "right": calcRightPos($active) }, { duration: transition, queue: false, easing: 'easeOutQuad', delay: 90 }); 2621 } 2622 }; 2623 2624 // Change swipeable according to responsive threshold 2625 if (options.swipeable) { 2626 if (window_width > options.responsiveThreshold) { 2627 options.swipeable = false; 2628 } 2629 } 2630 2631 // If the location.hash matches one of the links, use that as the active tab. 2632 $active = $($links.filter('[href="' + location.hash + '"]')); 2633 2634 // If no match is found, use the first link or any with class 'active' as the initial active tab. 2635 if ($active.length === 0) { 2636 $active = $(this).find('li.tab a.active').first(); 2637 } 2638 if ($active.length === 0) { 2639 $active = $(this).find('li.tab a').first(); 2640 } 2641 2642 $active.addClass('active'); 2643 index = $links.index($active); 2644 if (index < 0) { 2645 index = 0; 2646 } 2647 2648 if ($active[0] !== undefined) { 2649 $content = $($active[0].hash); 2650 $content.addClass('active'); 2651 } 2652 2653 // append indicator then set indicator width to tab width 2654 if (!$this.find('.indicator').length) { 2655 $this.append('<li class="indicator"></li>'); 2656 } 2657 $indicator = $this.find('.indicator'); 2658 2659 // we make sure that the indicator is at the end of the tabs 2660 $this.append($indicator); 2661 2662 if ($this.is(":visible")) { 2663 // $indicator.css({"right": $tabs_width - ((index + 1) * $tab_width)}); 2664 // $indicator.css({"left": index * $tab_width}); 2665 setTimeout(function () { 2666 $indicator.css({ "right": calcRightPos($active) }); 2667 $indicator.css({ "left": calcLeftPos($active) }); 2668 }, 0); 2669 } 2670 $(window).off('resize.tabs-' + uniqueNamespace).on('resize.tabs-' + uniqueNamespace, function () { 2671 $tabs_width = $this.width(); 2672 $tab_width = Math.max($tabs_width, $this[0].scrollWidth) / $links.length; 2673 if (index < 0) { 2674 index = 0; 2675 } 2676 if ($tab_width !== 0 && $tabs_width !== 0) { 2677 $indicator.css({ "right": calcRightPos($active) }); 2678 $indicator.css({ "left": calcLeftPos($active) }); 2679 } 2680 }); 2681 2682 // Initialize Tabs Content. 2683 if (options.swipeable) { 2684 // TODO: Duplicate calls with swipeable? handle multiple div wrapping. 2685 $links.each(function () { 2686 var $curr_content = $(Materialize.escapeHash(this.hash)); 2687 $curr_content.addClass('carousel-item'); 2688 $tabs_content = $tabs_content.add($curr_content); 2689 }); 2690 $tabs_wrapper = $tabs_content.wrapAll('<div class="tabs-content carousel"></div>'); 2691 $tabs_content.css('display', ''); 2692 $('.tabs-content.carousel').carousel({ 2693 fullWidth: true, 2694 noWrap: true, 2695 onCycleTo: function (item) { 2696 if (!clicked) { 2697 var prev_index = index; 2698 index = $tabs_wrapper.index(item); 2699 $active.removeClass('active'); 2700 $active = $links.eq(index); 2701 $active.addClass('active'); 2702 animateIndicator(prev_index); 2703 if (typeof options.onShow === "function") { 2704 options.onShow.call($this[0], $content); 2705 } 2706 } 2707 } 2708 }); 2709 } else { 2710 // Hide the remaining content 2711 $links.not($active).each(function () { 2712 $(Materialize.escapeHash(this.hash)).hide(); 2713 }); 2714 } 2715 2716 // Bind the click event handler 2717 $this.off('click.tabs').on('click.tabs', 'a', function (e) { 2718 if ($(this).parent().hasClass('disabled')) { 2719 e.preventDefault(); 2720 return; 2721 } 2722 2723 // Act as regular link if target attribute is specified. 2724 if (!!$(this).attr("target")) { 2725 return; 2726 } 2727 2728 clicked = true; 2729 $tabs_width = $this.width(); 2730 $tab_width = Math.max($tabs_width, $this[0].scrollWidth) / $links.length; 2731 2732 // Make the old tab inactive. 2733 $active.removeClass('active'); 2734 var $oldContent = $content; 2735 2736 // Update the variables with the new link and content 2737 $active = $(this); 2738 $content = $(Materialize.escapeHash(this.hash)); 2739 $links = $this.find('li.tab a'); 2740 var activeRect = $active.position(); 2741 2742 // Make the tab active. 2743 $active.addClass('active'); 2744 prev_index = index; 2745 index = $links.index($(this)); 2746 if (index < 0) { 2747 index = 0; 2748 } 2749 // Change url to current tab 2750 // window.location.hash = $active.attr('href'); 2751 2752 // Swap content 2753 if (options.swipeable) { 2754 if ($tabs_content.length) { 2755 $tabs_content.carousel('set', index, function () { 2756 if (typeof options.onShow === "function") { 2757 options.onShow.call($this[0], $content); 2758 } 2759 }); 2760 } 2761 } else { 2762 if ($content !== undefined) { 2763 $content.show(); 2764 $content.addClass('active'); 2765 if (typeof options.onShow === "function") { 2766 options.onShow.call(this, $content); 2767 } 2768 } 2769 2770 if ($oldContent !== undefined && !$oldContent.is($content)) { 2771 $oldContent.hide(); 2772 $oldContent.removeClass('active'); 2773 } 2774 } 2775 2776 // Reset clicked state 2777 clickedTimeout = setTimeout(function () { 2778 clicked = false; 2779 }, transition); 2780 2781 // Update indicator 2782 animateIndicator(prev_index); 2783 2784 // Prevent the anchor's default click action 2785 e.preventDefault(); 2786 }); 2787 }); 2788 }, 2789 select_tab: function (id) { 2790 this.find('a[href="#' + id + '"]').trigger('click'); 2791 } 2792 }; 2793 2794 $.fn.tabs = function (methodOrOptions) { 2795 if (methods[methodOrOptions]) { 2796 return methods[methodOrOptions].apply(this, Array.prototype.slice.call(arguments, 1)); 2797 } else if (typeof methodOrOptions === 'object' || !methodOrOptions) { 2798 // Default to "init" 2799 return methods.init.apply(this, arguments); 2800 } else { 2801 $.error('Method ' + methodOrOptions + ' does not exist on jQuery.tabs'); 2802 } 2803 }; 2804 2805 $(document).ready(function () { 2806 $('ul.tabs').tabs(); 2807 }); 2808 })(jQuery); 2809 ;(function ($) { 2810 $.fn.tooltip = function (options) { 2811 var timeout = null, 2812 margin = 5; 2813 2814 // Defaults 2815 var defaults = { 2816 delay: 350, 2817 tooltip: '', 2818 position: 'bottom', 2819 html: false 2820 }; 2821 2822 // Remove tooltip from the activator 2823 if (options === "remove") { 2824 this.each(function () { 2825 $('#' + $(this).attr('data-tooltip-id')).remove(); 2826 $(this).removeAttr('data-tooltip-id'); 2827 $(this).off('mouseenter.tooltip mouseleave.tooltip'); 2828 }); 2829 return false; 2830 } 2831 2832 options = $.extend(defaults, options); 2833 2834 return this.each(function () { 2835 var tooltipId = Materialize.guid(); 2836 var origin = $(this); 2837 2838 // Destroy old tooltip 2839 if (origin.attr('data-tooltip-id')) { 2840 $('#' + origin.attr('data-tooltip-id')).remove(); 2841 } 2842 2843 origin.attr('data-tooltip-id', tooltipId); 2844 2845 // Get attributes. 2846 var allowHtml, tooltipDelay, tooltipPosition, tooltipText, tooltipEl, backdrop; 2847 var setAttributes = function () { 2848 allowHtml = origin.attr('data-html') ? origin.attr('data-html') === 'true' : options.html; 2849 tooltipDelay = origin.attr('data-delay'); 2850 tooltipDelay = tooltipDelay === undefined || tooltipDelay === '' ? options.delay : tooltipDelay; 2851 tooltipPosition = origin.attr('data-position'); 2852 tooltipPosition = tooltipPosition === undefined || tooltipPosition === '' ? options.position : tooltipPosition; 2853 tooltipText = origin.attr('data-tooltip'); 2854 tooltipText = tooltipText === undefined || tooltipText === '' ? options.tooltip : tooltipText; 2855 }; 2856 setAttributes(); 2857 2858 var renderTooltipEl = function () { 2859 var tooltip = $('<div class="material-tooltip"></div>'); 2860 2861 // Create Text span 2862 if (allowHtml) { 2863 tooltipText = $('<span></span>').html(tooltipText); 2864 } else { 2865 tooltipText = $('<span></span>').text(tooltipText); 2866 } 2867 2868 // Create tooltip 2869 tooltip.append(tooltipText).appendTo($('body')).attr('id', tooltipId); 2870 2871 // Create backdrop 2872 backdrop = $('<div class="backdrop"></div>'); 2873 backdrop.appendTo(tooltip); 2874 return tooltip; 2875 }; 2876 tooltipEl = renderTooltipEl(); 2877 2878 // Destroy previously binded events 2879 origin.off('mouseenter.tooltip mouseleave.tooltip'); 2880 // Mouse In 2881 var started = false, 2882 timeoutRef; 2883 origin.on({ 'mouseenter.tooltip': function (e) { 2884 var showTooltip = function () { 2885 setAttributes(); 2886 started = true; 2887 tooltipEl.velocity('stop'); 2888 backdrop.velocity('stop'); 2889 tooltipEl.css({ visibility: 'visible', left: '0px', top: '0px' }); 2890 2891 // Tooltip positioning 2892 var originWidth = origin.outerWidth(); 2893 var originHeight = origin.outerHeight(); 2894 var tooltipHeight = tooltipEl.outerHeight(); 2895 var tooltipWidth = tooltipEl.outerWidth(); 2896 var tooltipVerticalMovement = '0px'; 2897 var tooltipHorizontalMovement = '0px'; 2898 var backdropOffsetWidth = backdrop[0].offsetWidth; 2899 var backdropOffsetHeight = backdrop[0].offsetHeight; 2900 var scaleXFactor = 8; 2901 var scaleYFactor = 8; 2902 var scaleFactor = 0; 2903 var targetTop, targetLeft, newCoordinates; 2904 2905 if (tooltipPosition === "top") { 2906 // Top Position 2907 targetTop = origin.offset().top - tooltipHeight - margin; 2908 targetLeft = origin.offset().left + originWidth / 2 - tooltipWidth / 2; 2909 newCoordinates = repositionWithinScreen(targetLeft, targetTop, tooltipWidth, tooltipHeight); 2910 tooltipVerticalMovement = '-10px'; 2911 backdrop.css({ 2912 bottom: 0, 2913 left: 0, 2914 borderRadius: '14px 14px 0 0', 2915 transformOrigin: '50% 100%', 2916 marginTop: tooltipHeight, 2917 marginLeft: tooltipWidth / 2 - backdropOffsetWidth / 2 2918 }); 2919 } 2920 // Left Position 2921 else if (tooltipPosition === "left") { 2922 targetTop = origin.offset().top + originHeight / 2 - tooltipHeight / 2; 2923 targetLeft = origin.offset().left - tooltipWidth - margin; 2924 newCoordinates = repositionWithinScreen(targetLeft, targetTop, tooltipWidth, tooltipHeight); 2925 2926 tooltipHorizontalMovement = '-10px'; 2927 backdrop.css({ 2928 top: '-7px', 2929 right: 0, 2930 width: '14px', 2931 height: '14px', 2932 borderRadius: '14px 0 0 14px', 2933 transformOrigin: '95% 50%', 2934 marginTop: tooltipHeight / 2, 2935 marginLeft: tooltipWidth 2936 }); 2937 } 2938 // Right Position 2939 else if (tooltipPosition === "right") { 2940 targetTop = origin.offset().top + originHeight / 2 - tooltipHeight / 2; 2941 targetLeft = origin.offset().left + originWidth + margin; 2942 newCoordinates = repositionWithinScreen(targetLeft, targetTop, tooltipWidth, tooltipHeight); 2943 2944 tooltipHorizontalMovement = '+10px'; 2945 backdrop.css({ 2946 top: '-7px', 2947 left: 0, 2948 width: '14px', 2949 height: '14px', 2950 borderRadius: '0 14px 14px 0', 2951 transformOrigin: '5% 50%', 2952 marginTop: tooltipHeight / 2, 2953 marginLeft: '0px' 2954 }); 2955 } else { 2956 // Bottom Position 2957 targetTop = origin.offset().top + origin.outerHeight() + margin; 2958 targetLeft = origin.offset().left + originWidth / 2 - tooltipWidth / 2; 2959 newCoordinates = repositionWithinScreen(targetLeft, targetTop, tooltipWidth, tooltipHeight); 2960 tooltipVerticalMovement = '+10px'; 2961 backdrop.css({ 2962 top: 0, 2963 left: 0, 2964 marginLeft: tooltipWidth / 2 - backdropOffsetWidth / 2 2965 }); 2966 } 2967 2968 // Set tooptip css placement 2969 tooltipEl.css({ 2970 top: newCoordinates.y, 2971 left: newCoordinates.x 2972 }); 2973 2974 // Calculate Scale to fill 2975 scaleXFactor = Math.SQRT2 * tooltipWidth / parseInt(backdropOffsetWidth); 2976 scaleYFactor = Math.SQRT2 * tooltipHeight / parseInt(backdropOffsetHeight); 2977 scaleFactor = Math.max(scaleXFactor, scaleYFactor); 2978 2979 tooltipEl.velocity({ translateY: tooltipVerticalMovement, translateX: tooltipHorizontalMovement }, { duration: 350, queue: false }).velocity({ opacity: 1 }, { duration: 300, delay: 50, queue: false }); 2980 backdrop.css({ visibility: 'visible' }).velocity({ opacity: 1 }, { duration: 55, delay: 0, queue: false }).velocity({ scaleX: scaleFactor, scaleY: scaleFactor }, { duration: 300, delay: 0, queue: false, easing: 'easeInOutQuad' }); 2981 }; 2982 2983 timeoutRef = setTimeout(showTooltip, tooltipDelay); // End Interval 2984 2985 // Mouse Out 2986 }, 2987 'mouseleave.tooltip': function () { 2988 // Reset State 2989 started = false; 2990 clearTimeout(timeoutRef); 2991 2992 // Animate back 2993 setTimeout(function () { 2994 if (started !== true) { 2995 tooltipEl.velocity({ 2996 opacity: 0, translateY: 0, translateX: 0 }, { duration: 225, queue: false }); 2997 backdrop.velocity({ opacity: 0, scaleX: 1, scaleY: 1 }, { 2998 duration: 225, 2999 queue: false, 3000 complete: function () { 3001 backdrop.css({ visibility: 'hidden' }); 3002 tooltipEl.css({ visibility: 'hidden' }); 3003 started = false; 3004 } 3005 }); 3006 } 3007 }, 225); 3008 } 3009 }); 3010 }); 3011 }; 3012 3013 var repositionWithinScreen = function (x, y, width, height) { 3014 var newX = x; 3015 var newY = y; 3016 3017 if (newX < 0) { 3018 newX = 4; 3019 } else if (newX + width > window.innerWidth) { 3020 newX -= newX + width - window.innerWidth; 3021 } 3022 3023 if (newY < 0) { 3024 newY = 4; 3025 } else if (newY + height > window.innerHeight + $(window).scrollTop) { 3026 newY -= newY + height - window.innerHeight; 3027 } 3028 3029 return { x: newX, y: newY }; 3030 }; 3031 3032 $(document).ready(function () { 3033 $('.tooltipped').tooltip(); 3034 }); 3035 })(jQuery); 3036 ; /*! 3037 * Waves v0.6.4 3038 * http://fian.my.id/Waves 3039 * 3040 * Copyright 2014 Alfiana E. Sibuea and other contributors 3041 * Released under the MIT license 3042 * https://github.com/fians/Waves/blob/master/LICENSE 3043 */ 3044 3045 ;(function (window) { 3046 'use strict'; 3047 3048 var Waves = Waves || {}; 3049 var $$ = document.querySelectorAll.bind(document); 3050 3051 // Find exact position of element 3052 function isWindow(obj) { 3053 return obj !== null && obj === obj.window; 3054 } 3055 3056 function getWindow(elem) { 3057 return isWindow(elem) ? elem : elem.nodeType === 9 && elem.defaultView; 3058 } 3059 3060 function offset(elem) { 3061 var docElem, 3062 win, 3063 box = { top: 0, left: 0 }, 3064 doc = elem && elem.ownerDocument; 3065 3066 docElem = doc.documentElement; 3067 3068 if (typeof elem.getBoundingClientRect !== typeof undefined) { 3069 box = elem.getBoundingClientRect(); 3070 } 3071 win = getWindow(doc); 3072 return { 3073 top: box.top + win.pageYOffset - docElem.clientTop, 3074 left: box.left + win.pageXOffset - docElem.clientLeft 3075 }; 3076 } 3077 3078 function convertStyle(obj) { 3079 var style = ''; 3080 3081 for (var a in obj) { 3082 if (obj.hasOwnProperty(a)) { 3083 style += a + ':' + obj[a] + ';'; 3084 } 3085 } 3086 3087 return style; 3088 } 3089 3090 var Effect = { 3091 3092 // Effect delay 3093 duration: 750, 3094 3095 show: function (e, element) { 3096 3097 // Disable right click 3098 if (e.button === 2) { 3099 return false; 3100 } 3101 3102 var el = element || this; 3103 3104 // Create ripple 3105 var ripple = document.createElement('div'); 3106 ripple.className = 'waves-ripple'; 3107 el.appendChild(ripple); 3108 3109 // Get click coordinate and element witdh 3110 var pos = offset(el); 3111 var relativeY = e.pageY - pos.top; 3112 var relativeX = e.pageX - pos.left; 3113 var scale = 'scale(' + el.clientWidth / 100 * 10 + ')'; 3114 3115 // Support for touch devices 3116 if ('touches' in e) { 3117 relativeY = e.touches[0].pageY - pos.top; 3118 relativeX = e.touches[0].pageX - pos.left; 3119 } 3120 3121 // Attach data to element 3122 ripple.setAttribute('data-hold', Date.now()); 3123 ripple.setAttribute('data-scale', scale); 3124 ripple.setAttribute('data-x', relativeX); 3125 ripple.setAttribute('data-y', relativeY); 3126 3127 // Set ripple position 3128 var rippleStyle = { 3129 'top': relativeY + 'px', 3130 'left': relativeX + 'px' 3131 }; 3132 3133 ripple.className = ripple.className + ' waves-notransition'; 3134 ripple.setAttribute('style', convertStyle(rippleStyle)); 3135 ripple.className = ripple.className.replace('waves-notransition', ''); 3136 3137 // Scale the ripple 3138 rippleStyle['-webkit-transform'] = scale; 3139 rippleStyle['-moz-transform'] = scale; 3140 rippleStyle['-ms-transform'] = scale; 3141 rippleStyle['-o-transform'] = scale; 3142 rippleStyle.transform = scale; 3143 rippleStyle.opacity = '1'; 3144 3145 rippleStyle['-webkit-transition-duration'] = Effect.duration + 'ms'; 3146 rippleStyle['-moz-transition-duration'] = Effect.duration + 'ms'; 3147 rippleStyle['-o-transition-duration'] = Effect.duration + 'ms'; 3148 rippleStyle['transition-duration'] = Effect.duration + 'ms'; 3149 3150 rippleStyle['-webkit-transition-timing-function'] = 'cubic-bezier(0.250, 0.460, 0.450, 0.940)'; 3151 rippleStyle['-moz-transition-timing-function'] = 'cubic-bezier(0.250, 0.460, 0.450, 0.940)'; 3152 rippleStyle['-o-transition-timing-function'] = 'cubic-bezier(0.250, 0.460, 0.450, 0.940)'; 3153 rippleStyle['transition-timing-function'] = 'cubic-bezier(0.250, 0.460, 0.450, 0.940)'; 3154 3155 ripple.setAttribute('style', convertStyle(rippleStyle)); 3156 }, 3157 3158 hide: function (e) { 3159 TouchHandler.touchup(e); 3160 3161 var el = this; 3162 var width = el.clientWidth * 1.4; 3163 3164 // Get first ripple 3165 var ripple = null; 3166 var ripples = el.getElementsByClassName('waves-ripple'); 3167 if (ripples.length > 0) { 3168 ripple = ripples[ripples.length - 1]; 3169 } else { 3170 return false; 3171 } 3172 3173 var relativeX = ripple.getAttribute('data-x'); 3174 var relativeY = ripple.getAttribute('data-y'); 3175 var scale = ripple.getAttribute('data-scale'); 3176 3177 // Get delay beetween mousedown and mouse leave 3178 var diff = Date.now() - Number(ripple.getAttribute('data-hold')); 3179 var delay = 350 - diff; 3180 3181 if (delay < 0) { 3182 delay = 0; 3183 } 3184 3185 // Fade out ripple after delay 3186 setTimeout(function () { 3187 var style = { 3188 'top': relativeY + 'px', 3189 'left': relativeX + 'px', 3190 'opacity': '0', 3191 3192 // Duration 3193 '-webkit-transition-duration': Effect.duration + 'ms', 3194 '-moz-transition-duration': Effect.duration + 'ms', 3195 '-o-transition-duration': Effect.duration + 'ms', 3196 'transition-duration': Effect.duration + 'ms', 3197 '-webkit-transform': scale, 3198 '-moz-transform': scale, 3199 '-ms-transform': scale, 3200 '-o-transform': scale, 3201 'transform': scale 3202 }; 3203 3204 ripple.setAttribute('style', convertStyle(style)); 3205 3206 setTimeout(function () { 3207 try { 3208 el.removeChild(ripple); 3209 } catch (e) { 3210 return false; 3211 } 3212 }, Effect.duration); 3213 }, delay); 3214 }, 3215 3216 // Little hack to make <input> can perform waves effect 3217 wrapInput: function (elements) { 3218 for (var a = 0; a < elements.length; a++) { 3219 var el = elements[a]; 3220 3221 if (el.tagName.toLowerCase() === 'input') { 3222 var parent = el.parentNode; 3223 3224 // If input already have parent just pass through 3225 if (parent.tagName.toLowerCase() === 'i' && parent.className.indexOf('waves-effect') !== -1) { 3226 continue; 3227 } 3228 3229 // Put element class and style to the specified parent 3230 var wrapper = document.createElement('i'); 3231 wrapper.className = el.className + ' waves-input-wrapper'; 3232 3233 var elementStyle = el.getAttribute('style'); 3234 3235 if (!elementStyle) { 3236 elementStyle = ''; 3237 } 3238 3239 wrapper.setAttribute('style', elementStyle); 3240 3241 el.className = 'waves-button-input'; 3242 el.removeAttribute('style'); 3243 3244 // Put element as child 3245 parent.replaceChild(wrapper, el); 3246 wrapper.appendChild(el); 3247 } 3248 } 3249 } 3250 }; 3251 3252 /** 3253 * Disable mousedown event for 500ms during and after touch 3254 */ 3255 var TouchHandler = { 3256 /* uses an integer rather than bool so there's no issues with 3257 * needing to clear timeouts if another touch event occurred 3258 * within the 500ms. Cannot mouseup between touchstart and 3259 * touchend, nor in the 500ms after touchend. */ 3260 touches: 0, 3261 allowEvent: function (e) { 3262 var allow = true; 3263 3264 if (e.type === 'touchstart') { 3265 TouchHandler.touches += 1; //push 3266 } else if (e.type === 'touchend' || e.type === 'touchcancel') { 3267 setTimeout(function () { 3268 if (TouchHandler.touches > 0) { 3269 TouchHandler.touches -= 1; //pop after 500ms 3270 } 3271 }, 500); 3272 } else if (e.type === 'mousedown' && TouchHandler.touches > 0) { 3273 allow = false; 3274 } 3275 3276 return allow; 3277 }, 3278 touchup: function (e) { 3279 TouchHandler.allowEvent(e); 3280 } 3281 }; 3282 3283 /** 3284 * Delegated click handler for .waves-effect element. 3285 * returns null when .waves-effect element not in "click tree" 3286 */ 3287 function getWavesEffectElement(e) { 3288 if (TouchHandler.allowEvent(e) === false) { 3289 return null; 3290 } 3291 3292 var element = null; 3293 var target = e.target || e.srcElement; 3294 3295 while (target.parentNode !== null) { 3296 if (!(target instanceof SVGElement) && target.className.indexOf('waves-effect') !== -1) { 3297 element = target; 3298 break; 3299 } 3300 target = target.parentNode; 3301 } 3302 return element; 3303 } 3304 3305 /** 3306 * Bubble the click and show effect if .waves-effect elem was found 3307 */ 3308 function showEffect(e) { 3309 var element = getWavesEffectElement(e); 3310 3311 if (element !== null) { 3312 Effect.show(e, element); 3313 3314 if ('ontouchstart' in window) { 3315 element.addEventListener('touchend', Effect.hide, false); 3316 element.addEventListener('touchcancel', Effect.hide, false); 3317 } 3318 3319 element.addEventListener('mouseup', Effect.hide, false); 3320 element.addEventListener('mouseleave', Effect.hide, false); 3321 element.addEventListener('dragend', Effect.hide, false); 3322 } 3323 } 3324 3325 Waves.displayEffect = function (options) { 3326 options = options || {}; 3327 3328 if ('duration' in options) { 3329 Effect.duration = options.duration; 3330 } 3331 3332 //Wrap input inside <i> tag 3333 Effect.wrapInput($$('.waves-effect')); 3334 3335 if ('ontouchstart' in window) { 3336 document.body.addEventListener('touchstart', showEffect, false); 3337 } 3338 3339 document.body.addEventListener('mousedown', showEffect, false); 3340 }; 3341 3342 /** 3343 * Attach Waves to an input element (or any element which doesn't 3344 * bubble mouseup/mousedown events). 3345 * Intended to be used with dynamically loaded forms/inputs, or 3346 * where the user doesn't want a delegated click handler. 3347 */ 3348 Waves.attach = function (element) { 3349 //FUTURE: automatically add waves classes and allow users 3350 // to specify them with an options param? Eg. light/classic/button 3351 if (element.tagName.toLowerCase() === 'input') { 3352 Effect.wrapInput([element]); 3353 element = element.parentNode; 3354 } 3355 3356 if ('ontouchstart' in window) { 3357 element.addEventListener('touchstart', showEffect, false); 3358 } 3359 3360 element.addEventListener('mousedown', showEffect, false); 3361 }; 3362 3363 window.Waves = Waves; 3364 3365 document.addEventListener('DOMContentLoaded', function () { 3366 Waves.displayEffect(); 3367 }, false); 3368 })(window); 3369 ;(function ($, Vel) { 3370 'use strict'; 3371 3372 var _defaults = { 3373 displayLength: Infinity, 3374 inDuration: 300, 3375 outDuration: 375, 3376 className: undefined, 3377 completeCallback: undefined, 3378 activationPercent: 0.8 3379 }; 3380 3381 var Toast = function () { 3382 function Toast(message, displayLength, className, completeCallback) { 3383 _classCallCheck(this, Toast); 3384 3385 if (!message) { 3386 return; 3387 } 3388 3389 /** 3390 * Options for the toast 3391 * @member Toast#options 3392 */ 3393 this.options = { 3394 displayLength: displayLength, 3395 className: className, 3396 completeCallback: completeCallback 3397 }; 3398 3399 this.options = $.extend({}, Toast.defaults, this.options); 3400 this.message = message; 3401 3402 /** 3403 * Describes current pan state toast 3404 * @type {Boolean} 3405 */ 3406 this.panning = false; 3407 3408 /** 3409 * Time remaining until toast is removed 3410 */ 3411 this.timeRemaining = this.options.displayLength; 3412 3413 if (Toast._toasts.length === 0) { 3414 Toast._createContainer(); 3415 } 3416 3417 // Create new toast 3418 Toast._toasts.push(this); 3419 var toastElement = this.createToast(); 3420 toastElement.M_Toast = this; 3421 this.el = toastElement; 3422 this._animateIn(); 3423 this.setTimer(); 3424 } 3425 3426 _createClass(Toast, [{ 3427 key: 'createToast', 3428 3429 3430 /** 3431 * Create toast and append it to toast container 3432 */ 3433 value: function createToast() { 3434 var toast = document.createElement('div'); 3435 toast.classList.add('toast'); 3436 3437 // Add custom classes onto toast 3438 if (this.options.className) { 3439 var classes = this.options.className.split(' '); 3440 var i = void 0, 3441 count = void 0; 3442 for (i = 0, count = classes.length; i < count; i++) { 3443 toast.classList.add(classes[i]); 3444 } 3445 } 3446 3447 // Set content 3448 if (typeof HTMLElement === 'object' ? this.message instanceof HTMLElement : this.message && typeof this.message === 'object' && this.message !== null && this.message.nodeType === 1 && typeof this.message.nodeName === 'string') { 3449 toast.appendChild(this.message); 3450 3451 // Check if it is jQuery object 3452 } else if (this.message instanceof jQuery) { 3453 $(toast).append(this.message); 3454 3455 // Insert as text; 3456 } else { 3457 toast.innerHTML = this.message; 3458 } 3459 3460 // Append toasft 3461 Toast._container.appendChild(toast); 3462 return toast; 3463 } 3464 3465 /** 3466 * Animate in toast 3467 */ 3468 3469 }, { 3470 key: '_animateIn', 3471 value: function _animateIn() { 3472 // Animate toast in 3473 Vel(this.el, { top: 0, opacity: 1 }, { 3474 duration: 300, 3475 easing: 'easeOutCubic', 3476 queue: false 3477 }); 3478 } 3479 3480 /** 3481 * Create setInterval which automatically removes toast when timeRemaining >= 0 3482 * has been reached 3483 */ 3484 3485 }, { 3486 key: 'setTimer', 3487 value: function setTimer() { 3488 var _this3 = this; 3489 3490 if (this.timeRemaining !== Infinity) { 3491 this.counterInterval = setInterval(function () { 3492 // If toast is not being dragged, decrease its time remaining 3493 if (!_this3.panning) { 3494 _this3.timeRemaining -= 20; 3495 } 3496 3497 // Animate toast out 3498 if (_this3.timeRemaining <= 0) { 3499 _this3.remove(); 3500 } 3501 }, 20); 3502 } 3503 } 3504 3505 /** 3506 * Dismiss toast with animation 3507 */ 3508 3509 }, { 3510 key: 'remove', 3511 value: function remove() { 3512 var _this4 = this; 3513 3514 window.clearInterval(this.counterInterval); 3515 var activationDistance = this.el.offsetWidth * this.options.activationPercent; 3516 3517 if (this.wasSwiped) { 3518 this.el.style.transition = 'transform .05s, opacity .05s'; 3519 this.el.style.transform = 'translateX(' + activationDistance + 'px)'; 3520 this.el.style.opacity = 0; 3521 } 3522 3523 Vel(this.el, { opacity: 0, marginTop: '-40px' }, { 3524 duration: this.options.outDuration, 3525 easing: 'easeOutExpo', 3526 queue: false, 3527 complete: function () { 3528 // Call the optional callback 3529 if (typeof _this4.options.completeCallback === 'function') { 3530 _this4.options.completeCallback(); 3531 } 3532 // Remove toast from DOM 3533 _this4.el.parentNode.removeChild(_this4.el); 3534 Toast._toasts.splice(Toast._toasts.indexOf(_this4), 1); 3535 if (Toast._toasts.length === 0) { 3536 Toast._removeContainer(); 3537 } 3538 } 3539 }); 3540 } 3541 }], [{ 3542 key: '_createContainer', 3543 3544 3545 /** 3546 * Append toast container and add event handlers 3547 */ 3548 value: function _createContainer() { 3549 var container = document.createElement('div'); 3550 container.setAttribute('id', 'toast-container'); 3551 3552 // Add event handler 3553 container.addEventListener('touchstart', Toast._onDragStart); 3554 container.addEventListener('touchmove', Toast._onDragMove); 3555 container.addEventListener('touchend', Toast._onDragEnd); 3556 3557 container.addEventListener('mousedown', Toast._onDragStart); 3558 document.addEventListener('mousemove', Toast._onDragMove); 3559 document.addEventListener('mouseup', Toast._onDragEnd); 3560 3561 document.body.appendChild(container); 3562 Toast._container = container; 3563 } 3564 3565 /** 3566 * Remove toast container and event handlers 3567 */ 3568 3569 }, { 3570 key: '_removeContainer', 3571 value: function _removeContainer() { 3572 // Add event handler 3573 document.removeEventListener('mousemove', Toast._onDragMove); 3574 document.removeEventListener('mouseup', Toast._onDragEnd); 3575 3576 Toast._container.parentNode.removeChild(Toast._container); 3577 Toast._container = null; 3578 } 3579 3580 /** 3581 * Begin drag handler 3582 * @param {Event} e 3583 */ 3584 3585 }, { 3586 key: '_onDragStart', 3587 value: function _onDragStart(e) { 3588 if (e.target && $(e.target).closest('.toast').length) { 3589 var $toast = $(e.target).closest('.toast'); 3590 var toast = $toast[0].M_Toast; 3591 toast.panning = true; 3592 Toast._draggedToast = toast; 3593 toast.el.classList.add('panning'); 3594 toast.el.style.transition = ''; 3595 toast.startingXPos = Toast._xPos(e); 3596 toast.time = Date.now(); 3597 toast.xPos = Toast._xPos(e); 3598 } 3599 } 3600 3601 /** 3602 * Drag move handler 3603 * @param {Event} e 3604 */ 3605 3606 }, { 3607 key: '_onDragMove', 3608 value: function _onDragMove(e) { 3609 if (!!Toast._draggedToast) { 3610 e.preventDefault(); 3611 var toast = Toast._draggedToast; 3612 toast.deltaX = Math.abs(toast.xPos - Toast._xPos(e)); 3613 toast.xPos = Toast._xPos(e); 3614 toast.velocityX = toast.deltaX / (Date.now() - toast.time); 3615 toast.time = Date.now(); 3616 3617 var totalDeltaX = toast.xPos - toast.startingXPos; 3618 var activationDistance = toast.el.offsetWidth * toast.options.activationPercent; 3619 toast.el.style.transform = 'translateX(' + totalDeltaX + 'px)'; 3620 toast.el.style.opacity = 1 - Math.abs(totalDeltaX / activationDistance); 3621 } 3622 } 3623 3624 /** 3625 * End drag handler 3626 * @param {Event} e 3627 */ 3628 3629 }, { 3630 key: '_onDragEnd', 3631 value: function _onDragEnd(e) { 3632 if (!!Toast._draggedToast) { 3633 var toast = Toast._draggedToast; 3634 toast.panning = false; 3635 toast.el.classList.remove('panning'); 3636 3637 var totalDeltaX = toast.xPos - toast.startingXPos; 3638 var activationDistance = toast.el.offsetWidth * toast.options.activationPercent; 3639 var shouldBeDismissed = Math.abs(totalDeltaX) > activationDistance || toast.velocityX > 1; 3640 3641 // Remove toast 3642 if (shouldBeDismissed) { 3643 toast.wasSwiped = true; 3644 toast.remove(); 3645 3646 // Animate toast back to original position 3647 } else { 3648 toast.el.style.transition = 'transform .2s, opacity .2s'; 3649 toast.el.style.transform = ''; 3650 toast.el.style.opacity = ''; 3651 } 3652 Toast._draggedToast = null; 3653 } 3654 } 3655 3656 /** 3657 * Get x position of mouse or touch event 3658 * @param {Event} e 3659 */ 3660 3661 }, { 3662 key: '_xPos', 3663 value: function _xPos(e) { 3664 if (e.targetTouches && e.targetTouches.length >= 1) { 3665 return e.targetTouches[0].clientX; 3666 } 3667 // mouse event 3668 return e.clientX; 3669 } 3670 3671 /** 3672 * Remove all toasts 3673 */ 3674 3675 }, { 3676 key: 'removeAll', 3677 value: function removeAll() { 3678 for (var toastIndex in Toast._toasts) { 3679 Toast._toasts[toastIndex].remove(); 3680 } 3681 } 3682 }, { 3683 key: 'defaults', 3684 get: function () { 3685 return _defaults; 3686 } 3687 }]); 3688 3689 return Toast; 3690 }(); 3691 3692 /** 3693 * @static 3694 * @memberof Toast 3695 * @type {Array.<Toast>} 3696 */ 3697 3698 3699 Toast._toasts = []; 3700 3701 /** 3702 * @static 3703 * @memberof Toast 3704 */ 3705 Toast._container = null; 3706 3707 /** 3708 * @static 3709 * @memberof Toast 3710 * @type {Toast} 3711 */ 3712 Toast._draggedToast = null; 3713 3714 Materialize.Toast = Toast; 3715 Materialize.toast = function (message, displayLength, className, completeCallback) { 3716 return new Toast(message, displayLength, className, completeCallback); 3717 }; 3718 })(jQuery, Materialize.Vel); 3719 ;(function ($) { 3720 3721 var methods = { 3722 init: function (options) { 3723 var defaults = { 3724 menuWidth: 300, 3725 edge: 'left', 3726 closeOnClick: false, 3727 draggable: true, 3728 onOpen: null, 3729 onClose: null 3730 }; 3731 options = $.extend(defaults, options); 3732 3733 $(this).each(function () { 3734 var $this = $(this); 3735 var menuId = $this.attr('data-activates'); 3736 var menu = $("#" + menuId); 3737 3738 // Set to width 3739 if (options.menuWidth != 300) { 3740 menu.css('width', options.menuWidth); 3741 } 3742 3743 // Add Touch Area 3744 var $dragTarget = $('.drag-target[data-sidenav="' + menuId + '"]'); 3745 if (options.draggable) { 3746 // Regenerate dragTarget 3747 if ($dragTarget.length) { 3748 $dragTarget.remove(); 3749 } 3750 3751 $dragTarget = $('<div class="drag-target"></div>').attr('data-sidenav', menuId); 3752 $('body').append($dragTarget); 3753 } else { 3754 $dragTarget = $(); 3755 } 3756 3757 if (options.edge == 'left') { 3758 menu.css('transform', 'translateX(-100%)'); 3759 $dragTarget.css({ 'left': 0 }); // Add Touch Area 3760 } else { 3761 menu.addClass('right-aligned') // Change text-alignment to right 3762 .css('transform', 'translateX(100%)'); 3763 $dragTarget.css({ 'right': 0 }); // Add Touch Area 3764 } 3765 3766 // If fixed sidenav, bring menu out 3767 if (menu.hasClass('fixed')) { 3768 if (window.innerWidth > 992) { 3769 menu.css('transform', 'translateX(0)'); 3770 } 3771 } 3772 3773 // Window resize to reset on large screens fixed 3774 if (menu.hasClass('fixed')) { 3775 $(window).resize(function () { 3776 if (window.innerWidth > 992) { 3777 // Close menu if window is resized bigger than 992 and user has fixed sidenav 3778 if ($('#sidenav-overlay').length !== 0 && menuOut) { 3779 removeMenu(true); 3780 } else { 3781 // menu.removeAttr('style'); 3782 menu.css('transform', 'translateX(0%)'); 3783 // menu.css('width', options.menuWidth); 3784 } 3785 } else if (menuOut === false) { 3786 if (options.edge === 'left') { 3787 menu.css('transform', 'translateX(-100%)'); 3788 } else { 3789 menu.css('transform', 'translateX(100%)'); 3790 } 3791 } 3792 }); 3793 } 3794 3795 // if closeOnClick, then add close event for all a tags in side sideNav 3796 if (options.closeOnClick === true) { 3797 menu.on("click.itemclick", "a:not(.collapsible-header)", function () { 3798 if (!(window.innerWidth > 992 && menu.hasClass('fixed'))) { 3799 removeMenu(); 3800 } 3801 }); 3802 } 3803 3804 var removeMenu = function (restoreNav) { 3805 panning = false; 3806 menuOut = false; 3807 // Reenable scrolling 3808 $('body').css({ 3809 overflow: '', 3810 width: '' 3811 }); 3812 3813 $('#sidenav-overlay').velocity({ opacity: 0 }, { duration: 200, 3814 queue: false, easing: 'easeOutQuad', 3815 complete: function () { 3816 $(this).remove(); 3817 } }); 3818 if (options.edge === 'left') { 3819 // Reset phantom div 3820 $dragTarget.css({ width: '', right: '', left: '0' }); 3821 menu.velocity({ 'translateX': '-100%' }, { duration: 200, 3822 queue: false, 3823 easing: 'easeOutCubic', 3824 complete: function () { 3825 if (restoreNav === true) { 3826 // Restore Fixed sidenav 3827 menu.removeAttr('style'); 3828 menu.css('width', options.menuWidth); 3829 } 3830 } 3831 3832 }); 3833 } else { 3834 // Reset phantom div 3835 $dragTarget.css({ width: '', right: '0', left: '' }); 3836 menu.velocity({ 'translateX': '100%' }, { duration: 200, 3837 queue: false, 3838 easing: 'easeOutCubic', 3839 complete: function () { 3840 if (restoreNav === true) { 3841 // Restore Fixed sidenav 3842 menu.removeAttr('style'); 3843 menu.css('width', options.menuWidth); 3844 } 3845 } 3846 }); 3847 } 3848 3849 // Callback 3850 if (typeof options.onClose === 'function') { 3851 options.onClose.call(this, menu); 3852 } 3853 }; 3854 3855 // Touch Event 3856 var panning = false; 3857 var menuOut = false; 3858 3859 if (options.draggable) { 3860 $dragTarget.on('click', function () { 3861 if (menuOut) { 3862 removeMenu(); 3863 } 3864 }); 3865 3866 $dragTarget.hammer({ 3867 prevent_default: false 3868 }).on('pan', function (e) { 3869 3870 if (e.gesture.pointerType == "touch") { 3871 3872 var direction = e.gesture.direction; 3873 var x = e.gesture.center.x; 3874 var y = e.gesture.center.y; 3875 var velocityX = e.gesture.velocityX; 3876 3877 // Vertical scroll bugfix 3878 if (x === 0 && y === 0) { 3879 return; 3880 } 3881 3882 // Disable Scrolling 3883 var $body = $('body'); 3884 var $overlay = $('#sidenav-overlay'); 3885 var oldWidth = $body.innerWidth(); 3886 $body.css('overflow', 'hidden'); 3887 $body.width(oldWidth); 3888 3889 // If overlay does not exist, create one and if it is clicked, close menu 3890 if ($overlay.length === 0) { 3891 $overlay = $('<div id="sidenav-overlay"></div>'); 3892 $overlay.css('opacity', 0).click(function () { 3893 removeMenu(); 3894 }); 3895 3896 // Run 'onOpen' when sidenav is opened via touch/swipe if applicable 3897 if (typeof options.onOpen === 'function') { 3898 options.onOpen.call(this, menu); 3899 } 3900 3901 $('body').append($overlay); 3902 } 3903 3904 // Keep within boundaries 3905 if (options.edge === 'left') { 3906 if (x > options.menuWidth) { 3907 x = options.menuWidth; 3908 } else if (x < 0) { 3909 x = 0; 3910 } 3911 } 3912 3913 if (options.edge === 'left') { 3914 // Left Direction 3915 if (x < options.menuWidth / 2) { 3916 menuOut = false; 3917 } 3918 // Right Direction 3919 else if (x >= options.menuWidth / 2) { 3920 menuOut = true; 3921 } 3922 menu.css('transform', 'translateX(' + (x - options.menuWidth) + 'px)'); 3923 } else { 3924 // Left Direction 3925 if (x < window.innerWidth - options.menuWidth / 2) { 3926 menuOut = true; 3927 } 3928 // Right Direction 3929 else if (x >= window.innerWidth - options.menuWidth / 2) { 3930 menuOut = false; 3931 } 3932 var rightPos = x - options.menuWidth / 2; 3933 if (rightPos < 0) { 3934 rightPos = 0; 3935 } 3936 3937 menu.css('transform', 'translateX(' + rightPos + 'px)'); 3938 } 3939 3940 // Percentage overlay 3941 var overlayPerc; 3942 if (options.edge === 'left') { 3943 overlayPerc = x / options.menuWidth; 3944 $overlay.velocity({ opacity: overlayPerc }, { duration: 10, queue: false, easing: 'easeOutQuad' }); 3945 } else { 3946 overlayPerc = Math.abs((x - window.innerWidth) / options.menuWidth); 3947 $overlay.velocity({ opacity: overlayPerc }, { duration: 10, queue: false, easing: 'easeOutQuad' }); 3948 } 3949 } 3950 }).on('panend', function (e) { 3951 3952 if (e.gesture.pointerType == "touch") { 3953 var $overlay = $('#sidenav-overlay'); 3954 var velocityX = e.gesture.velocityX; 3955 var x = e.gesture.center.x; 3956 var leftPos = x - options.menuWidth; 3957 var rightPos = x - options.menuWidth / 2; 3958 if (leftPos > 0) { 3959 leftPos = 0; 3960 } 3961 if (rightPos < 0) { 3962 rightPos = 0; 3963 } 3964 panning = false; 3965 3966 if (options.edge === 'left') { 3967 // If velocityX <= 0.3 then the user is flinging the menu closed so ignore menuOut 3968 if (menuOut && velocityX <= 0.3 || velocityX < -0.5) { 3969 // Return menu to open 3970 if (leftPos !== 0) { 3971 menu.velocity({ 'translateX': [0, leftPos] }, { duration: 300, queue: false, easing: 'easeOutQuad' }); 3972 } 3973 3974 $overlay.velocity({ opacity: 1 }, { duration: 50, queue: false, easing: 'easeOutQuad' }); 3975 $dragTarget.css({ width: '50%', right: 0, left: '' }); 3976 menuOut = true; 3977 } else if (!menuOut || velocityX > 0.3) { 3978 // Enable Scrolling 3979 $('body').css({ 3980 overflow: '', 3981 width: '' 3982 }); 3983 // Slide menu closed 3984 menu.velocity({ 'translateX': [-1 * options.menuWidth - 10, leftPos] }, { duration: 200, queue: false, easing: 'easeOutQuad' }); 3985 $overlay.velocity({ opacity: 0 }, { duration: 200, queue: false, easing: 'easeOutQuad', 3986 complete: function () { 3987 // Run 'onClose' when sidenav is closed via touch/swipe if applicable 3988 if (typeof options.onClose === 'function') { 3989 options.onClose.call(this, menu); 3990 } 3991 3992 $(this).remove(); 3993 } }); 3994 $dragTarget.css({ width: '10px', right: '', left: 0 }); 3995 } 3996 } else { 3997 if (menuOut && velocityX >= -0.3 || velocityX > 0.5) { 3998 // Return menu to open 3999 if (rightPos !== 0) { 4000 menu.velocity({ 'translateX': [0, rightPos] }, { duration: 300, queue: false, easing: 'easeOutQuad' }); 4001 } 4002 4003 $overlay.velocity({ opacity: 1 }, { duration: 50, queue: false, easing: 'easeOutQuad' }); 4004 $dragTarget.css({ width: '50%', right: '', left: 0 }); 4005 menuOut = true; 4006 } else if (!menuOut || velocityX < -0.3) { 4007 // Enable Scrolling 4008 $('body').css({ 4009 overflow: '', 4010 width: '' 4011 }); 4012 4013 // Slide menu closed 4014 menu.velocity({ 'translateX': [options.menuWidth + 10, rightPos] }, { duration: 200, queue: false, easing: 'easeOutQuad' }); 4015 $overlay.velocity({ opacity: 0 }, { duration: 200, queue: false, easing: 'easeOutQuad', 4016 complete: function () { 4017 // Run 'onClose' when sidenav is closed via touch/swipe if applicable 4018 if (typeof options.onClose === 'function') { 4019 options.onClose.call(this, menu); 4020 } 4021 4022 $(this).remove(); 4023 } }); 4024 $dragTarget.css({ width: '10px', right: 0, left: '' }); 4025 } 4026 } 4027 } 4028 }); 4029 } 4030 4031 $this.off('click.sidenav').on('click.sidenav', function () { 4032 if (menuOut === true) { 4033 menuOut = false; 4034 panning = false; 4035 removeMenu(); 4036 } else { 4037 4038 // Disable Scrolling 4039 var $body = $('body'); 4040 var $overlay = $('<div id="sidenav-overlay"></div>'); 4041 var oldWidth = $body.innerWidth(); 4042 $body.css('overflow', 'hidden'); 4043 $body.width(oldWidth); 4044 4045 // Push current drag target on top of DOM tree 4046 $('body').append($dragTarget); 4047 4048 if (options.edge === 'left') { 4049 $dragTarget.css({ width: '50%', right: 0, left: '' }); 4050 menu.velocity({ 'translateX': [0, -1 * options.menuWidth] }, { duration: 300, queue: false, easing: 'easeOutQuad' }); 4051 } else { 4052 $dragTarget.css({ width: '50%', right: '', left: 0 }); 4053 menu.velocity({ 'translateX': [0, options.menuWidth] }, { duration: 300, queue: false, easing: 'easeOutQuad' }); 4054 } 4055 4056 // Overlay close on click 4057 $overlay.css('opacity', 0).click(function () { 4058 menuOut = false; 4059 panning = false; 4060 removeMenu(); 4061 $overlay.velocity({ opacity: 0 }, { duration: 300, queue: false, easing: 'easeOutQuad', 4062 complete: function () { 4063 $(this).remove(); 4064 } 4065 }); 4066 }); 4067 4068 // Append body 4069 $('body').append($overlay); 4070 $overlay.velocity({ opacity: 1 }, { duration: 300, queue: false, easing: 'easeOutQuad', 4071 complete: function () { 4072 menuOut = true; 4073 panning = false; 4074 } 4075 }); 4076 4077 // Callback 4078 if (typeof options.onOpen === 'function') { 4079 options.onOpen.call(this, menu); 4080 } 4081 } 4082 4083 return false; 4084 }); 4085 }); 4086 }, 4087 destroy: function () { 4088 var $overlay = $('#sidenav-overlay'); 4089 var $dragTarget = $('.drag-target[data-sidenav="' + $(this).attr('data-activates') + '"]'); 4090 $overlay.trigger('click'); 4091 $dragTarget.remove(); 4092 $(this).off('click'); 4093 $overlay.remove(); 4094 }, 4095 show: function () { 4096 this.trigger('click'); 4097 }, 4098 hide: function () { 4099 $('#sidenav-overlay').trigger('click'); 4100 } 4101 }; 4102 4103 $.fn.sideNav = function (methodOrOptions) { 4104 if (methods[methodOrOptions]) { 4105 return methods[methodOrOptions].apply(this, Array.prototype.slice.call(arguments, 1)); 4106 } else if (typeof methodOrOptions === 'object' || !methodOrOptions) { 4107 // Default to "init" 4108 return methods.init.apply(this, arguments); 4109 } else { 4110 $.error('Method ' + methodOrOptions + ' does not exist on jQuery.sideNav'); 4111 } 4112 }; // Plugin end 4113 })(jQuery); 4114 ; /** 4115 * Extend jquery with a scrollspy plugin. 4116 * This watches the window scroll and fires events when elements are scrolled into viewport. 4117 * 4118 * throttle() and getTime() taken from Underscore.js 4119 * https://github.com/jashkenas/underscore 4120 * 4121 * @author Copyright 2013 John Smart 4122 * @license https://raw.github.com/thesmart/jquery-scrollspy/master/LICENSE 4123 * @see https://github.com/thesmart 4124 * @version 0.1.2 4125 */ 4126 (function ($) { 4127 4128 var jWindow = $(window); 4129 var elements = []; 4130 var elementsInView = []; 4131 var isSpying = false; 4132 var ticks = 0; 4133 var unique_id = 1; 4134 var offset = { 4135 top: 0, 4136 right: 0, 4137 bottom: 0, 4138 left: 0 4139 4140 /** 4141 * Find elements that are within the boundary 4142 * @param {number} top 4143 * @param {number} right 4144 * @param {number} bottom 4145 * @param {number} left 4146 * @return {jQuery} A collection of elements 4147 */ 4148 };function findElements(top, right, bottom, left) { 4149 var hits = $(); 4150 $.each(elements, function (i, element) { 4151 if (element.height() > 0) { 4152 var elTop = element.offset().top, 4153 elLeft = element.offset().left, 4154 elRight = elLeft + element.width(), 4155 elBottom = elTop + element.height(); 4156 4157 var isIntersect = !(elLeft > right || elRight < left || elTop > bottom || elBottom < top); 4158 4159 if (isIntersect) { 4160 hits.push(element); 4161 } 4162 } 4163 }); 4164 4165 return hits; 4166 } 4167 4168 /** 4169 * Called when the user scrolls the window 4170 */ 4171 function onScroll(scrollOffset) { 4172 // unique tick id 4173 ++ticks; 4174 4175 // viewport rectangle 4176 var top = jWindow.scrollTop(), 4177 left = jWindow.scrollLeft(), 4178 right = left + jWindow.width(), 4179 bottom = top + jWindow.height(); 4180 4181 // determine which elements are in view 4182 var intersections = findElements(top + offset.top + scrollOffset || 200, right + offset.right, bottom + offset.bottom, left + offset.left); 4183 $.each(intersections, function (i, element) { 4184 4185 var lastTick = element.data('scrollSpy:ticks'); 4186 if (typeof lastTick != 'number') { 4187 // entered into view 4188 element.triggerHandler('scrollSpy:enter'); 4189 } 4190 4191 // update tick id 4192 element.data('scrollSpy:ticks', ticks); 4193 }); 4194 4195 // determine which elements are no longer in view 4196 $.each(elementsInView, function (i, element) { 4197 var lastTick = element.data('scrollSpy:ticks'); 4198 if (typeof lastTick == 'number' && lastTick !== ticks) { 4199 // exited from view 4200 element.triggerHandler('scrollSpy:exit'); 4201 element.data('scrollSpy:ticks', null); 4202 } 4203 }); 4204 4205 // remember elements in view for next tick 4206 elementsInView = intersections; 4207 } 4208 4209 /** 4210 * Called when window is resized 4211 */ 4212 function onWinSize() { 4213 jWindow.trigger('scrollSpy:winSize'); 4214 } 4215 4216 /** 4217 * Enables ScrollSpy using a selector 4218 * @param {jQuery|string} selector The elements collection, or a selector 4219 * @param {Object=} options Optional. 4220 throttle : number -> scrollspy throttling. Default: 100 ms 4221 offsetTop : number -> offset from top. Default: 0 4222 offsetRight : number -> offset from right. Default: 0 4223 offsetBottom : number -> offset from bottom. Default: 0 4224 offsetLeft : number -> offset from left. Default: 0 4225 activeClass : string -> Class name to be added to the active link. Default: active 4226 * @returns {jQuery} 4227 */ 4228 $.scrollSpy = function (selector, options) { 4229 var defaults = { 4230 throttle: 100, 4231 scrollOffset: 200, // offset - 200 allows elements near bottom of page to scroll 4232 activeClass: 'active', 4233 getActiveElement: function (id) { 4234 return 'a[href="#' + id + '"]'; 4235 } 4236 }; 4237 options = $.extend(defaults, options); 4238 4239 var visible = []; 4240 selector = $(selector); 4241 selector.each(function (i, element) { 4242 elements.push($(element)); 4243 $(element).data("scrollSpy:id", i); 4244 // Smooth scroll to section 4245 $('a[href="#' + $(element).attr('id') + '"]').click(function (e) { 4246 e.preventDefault(); 4247 var offset = $(Materialize.escapeHash(this.hash)).offset().top + 1; 4248 $('html, body').animate({ scrollTop: offset - options.scrollOffset }, { duration: 400, queue: false, easing: 'easeOutCubic' }); 4249 }); 4250 }); 4251 4252 offset.top = options.offsetTop || 0; 4253 offset.right = options.offsetRight || 0; 4254 offset.bottom = options.offsetBottom || 0; 4255 offset.left = options.offsetLeft || 0; 4256 4257 var throttledScroll = Materialize.throttle(function () { 4258 onScroll(options.scrollOffset); 4259 }, options.throttle || 100); 4260 var readyScroll = function () { 4261 $(document).ready(throttledScroll); 4262 }; 4263 4264 if (!isSpying) { 4265 jWindow.on('scroll', readyScroll); 4266 jWindow.on('resize', readyScroll); 4267 isSpying = true; 4268 } 4269 4270 // perform a scan once, after current execution context, and after dom is ready 4271 setTimeout(readyScroll, 0); 4272 4273 selector.on('scrollSpy:enter', function () { 4274 visible = $.grep(visible, function (value) { 4275 return value.height() != 0; 4276 }); 4277 4278 var $this = $(this); 4279 4280 if (visible[0]) { 4281 $(options.getActiveElement(visible[0].attr('id'))).removeClass(options.activeClass); 4282 if ($this.data('scrollSpy:id') < visible[0].data('scrollSpy:id')) { 4283 visible.unshift($(this)); 4284 } else { 4285 visible.push($(this)); 4286 } 4287 } else { 4288 visible.push($(this)); 4289 } 4290 4291 $(options.getActiveElement(visible[0].attr('id'))).addClass(options.activeClass); 4292 }); 4293 selector.on('scrollSpy:exit', function () { 4294 visible = $.grep(visible, function (value) { 4295 return value.height() != 0; 4296 }); 4297 4298 if (visible[0]) { 4299 $(options.getActiveElement(visible[0].attr('id'))).removeClass(options.activeClass); 4300 var $this = $(this); 4301 visible = $.grep(visible, function (value) { 4302 return value.attr('id') != $this.attr('id'); 4303 }); 4304 if (visible[0]) { 4305 // Check if empty 4306 $(options.getActiveElement(visible[0].attr('id'))).addClass(options.activeClass); 4307 } 4308 } 4309 }); 4310 4311 return selector; 4312 }; 4313 4314 /** 4315 * Listen for window resize events 4316 * @param {Object=} options Optional. Set { throttle: number } to change throttling. Default: 100 ms 4317 * @returns {jQuery} $(window) 4318 */ 4319 $.winSizeSpy = function (options) { 4320 $.winSizeSpy = function () { 4321 return jWindow; 4322 }; // lock from multiple calls 4323 options = options || { 4324 throttle: 100 4325 }; 4326 return jWindow.on('resize', Materialize.throttle(onWinSize, options.throttle || 100)); 4327 }; 4328 4329 /** 4330 * Enables ScrollSpy on a collection of elements 4331 * e.g. $('.scrollSpy').scrollSpy() 4332 * @param {Object=} options Optional. 4333 throttle : number -> scrollspy throttling. Default: 100 ms 4334 offsetTop : number -> offset from top. Default: 0 4335 offsetRight : number -> offset from right. Default: 0 4336 offsetBottom : number -> offset from bottom. Default: 0 4337 offsetLeft : number -> offset from left. Default: 0 4338 * @returns {jQuery} 4339 */ 4340 $.fn.scrollSpy = function (options) { 4341 return $.scrollSpy($(this), options); 4342 }; 4343 })(jQuery); 4344 ;(function ($) { 4345 $(document).ready(function () { 4346 4347 // Function to update labels of text fields 4348 Materialize.updateTextFields = function () { 4349 var input_selector = 'input[type=text], input[type=password], input[type=email], input[type=url], input[type=tel], input[type=number], input[type=search], textarea'; 4350 $(input_selector).each(function (index, element) { 4351 var $this = $(this); 4352 if ($(element).val().length > 0 || $(element).is(':focus') || element.autofocus || $this.attr('placeholder') !== undefined) { 4353 $this.siblings('label').addClass('active'); 4354 } else if ($(element)[0].validity) { 4355 $this.siblings('label').toggleClass('active', $(element)[0].validity.badInput === true); 4356 } else { 4357 $this.siblings('label').removeClass('active'); 4358 } 4359 }); 4360 }; 4361 4362 // Text based inputs 4363 var input_selector = 'input[type=text], input[type=password], input[type=email], input[type=url], input[type=tel], input[type=number], input[type=search], textarea'; 4364 4365 // Add active if form auto complete 4366 $(document).on('change', input_selector, function () { 4367 if ($(this).val().length !== 0 || $(this).attr('placeholder') !== undefined) { 4368 $(this).siblings('label').addClass('active'); 4369 } 4370 validate_field($(this)); 4371 }); 4372 4373 // Add active if input element has been pre-populated on document ready 4374 $(document).ready(function () { 4375 Materialize.updateTextFields(); 4376 }); 4377 4378 // HTML DOM FORM RESET handling 4379 $(document).on('reset', function (e) { 4380 var formReset = $(e.target); 4381 if (formReset.is('form')) { 4382 formReset.find(input_selector).removeClass('valid').removeClass('invalid'); 4383 formReset.find(input_selector).each(function () { 4384 if ($(this).attr('value') === '') { 4385 $(this).siblings('label').removeClass('active'); 4386 } 4387 }); 4388 4389 // Reset select 4390 formReset.find('select.initialized').each(function () { 4391 var reset_text = formReset.find('option[selected]').text(); 4392 formReset.siblings('input.select-dropdown').val(reset_text); 4393 }); 4394 } 4395 }); 4396 4397 // Add active when element has focus 4398 $(document).on('focus', input_selector, function () { 4399 $(this).siblings('label, .prefix').addClass('active'); 4400 }); 4401 4402 $(document).on('blur', input_selector, function () { 4403 var $inputElement = $(this); 4404 var selector = ".prefix"; 4405 4406 if ($inputElement.val().length === 0 && $inputElement[0].validity.badInput !== true && $inputElement.attr('placeholder') === undefined) { 4407 selector += ", label"; 4408 } 4409 4410 $inputElement.siblings(selector).removeClass('active'); 4411 4412 validate_field($inputElement); 4413 }); 4414 4415 window.validate_field = function (object) { 4416 var hasLength = object.attr('data-length') !== undefined; 4417 var lenAttr = parseInt(object.attr('data-length')); 4418 var len = object.val().length; 4419 4420 if (object.val().length === 0 && object[0].validity.badInput === false && !object.is(':required')) { 4421 if (object.hasClass('validate')) { 4422 object.removeClass('valid'); 4423 object.removeClass('invalid'); 4424 } 4425 } else { 4426 if (object.hasClass('validate')) { 4427 // Check for character counter attributes 4428 if (object.is(':valid') && hasLength && len <= lenAttr || object.is(':valid') && !hasLength) { 4429 object.removeClass('invalid'); 4430 object.addClass('valid'); 4431 } else { 4432 object.removeClass('valid'); 4433 object.addClass('invalid'); 4434 } 4435 } 4436 } 4437 }; 4438 4439 // Radio and Checkbox focus class 4440 var radio_checkbox = 'input[type=radio], input[type=checkbox]'; 4441 $(document).on('keyup.radio', radio_checkbox, function (e) { 4442 // TAB, check if tabbing to radio or checkbox. 4443 if (e.which === 9) { 4444 $(this).addClass('tabbed'); 4445 var $this = $(this); 4446 $this.one('blur', function (e) { 4447 4448 $(this).removeClass('tabbed'); 4449 }); 4450 return; 4451 } 4452 }); 4453 4454 // Textarea Auto Resize 4455 var hiddenDiv = $('.hiddendiv').first(); 4456 if (!hiddenDiv.length) { 4457 hiddenDiv = $('<div class="hiddendiv common"></div>'); 4458 $('body').append(hiddenDiv); 4459 } 4460 var text_area_selector = '.materialize-textarea'; 4461 4462 function textareaAutoResize($textarea) { 4463 // Set font properties of hiddenDiv 4464 4465 var fontFamily = $textarea.css('font-family'); 4466 var fontSize = $textarea.css('font-size'); 4467 var lineHeight = $textarea.css('line-height'); 4468 var padding = $textarea.css('padding'); 4469 4470 if (fontSize) { 4471 hiddenDiv.css('font-size', fontSize); 4472 } 4473 if (fontFamily) { 4474 hiddenDiv.css('font-family', fontFamily); 4475 } 4476 if (lineHeight) { 4477 hiddenDiv.css('line-height', lineHeight); 4478 } 4479 if (padding) { 4480 hiddenDiv.css('padding', padding); 4481 } 4482 4483 // Set original-height, if none 4484 if (!$textarea.data('original-height')) { 4485 $textarea.data('original-height', $textarea.height()); 4486 } 4487 4488 if ($textarea.attr('wrap') === 'off') { 4489 hiddenDiv.css('overflow-wrap', 'normal').css('white-space', 'pre'); 4490 } 4491 4492 hiddenDiv.text($textarea.val() + '\n'); 4493 var content = hiddenDiv.html().replace(/\n/g, '<br>'); 4494 hiddenDiv.html(content); 4495 4496 // When textarea is hidden, width goes crazy. 4497 // Approximate with half of window size 4498 4499 if ($textarea.is(':visible')) { 4500 hiddenDiv.css('width', $textarea.width()); 4501 } else { 4502 hiddenDiv.css('width', $(window).width() / 2); 4503 } 4504 4505 /** 4506 * Resize if the new height is greater than the 4507 * original height of the textarea 4508 */ 4509 if ($textarea.data('original-height') <= hiddenDiv.height()) { 4510 $textarea.css('height', hiddenDiv.height()); 4511 } else if ($textarea.val().length < $textarea.data('previous-length')) { 4512 /** 4513 * In case the new height is less than original height, it 4514 * means the textarea has less text than before 4515 * So we set the height to the original one 4516 */ 4517 $textarea.css('height', $textarea.data('original-height')); 4518 } 4519 $textarea.data('previous-length', $textarea.val().length); 4520 } 4521 4522 $(text_area_selector).each(function () { 4523 var $textarea = $(this); 4524 /** 4525 * Instead of resizing textarea on document load, 4526 * store the original height and the original length 4527 */ 4528 $textarea.data('original-height', $textarea.height()); 4529 $textarea.data('previous-length', $textarea.val().length); 4530 }); 4531 4532 $('body').on('keyup keydown autoresize', text_area_selector, function () { 4533 textareaAutoResize($(this)); 4534 }); 4535 4536 // File Input Path 4537 $(document).on('change', '.file-field input[type="file"]', function () { 4538 var file_field = $(this).closest('.file-field'); 4539 var path_input = file_field.find('input.file-path'); 4540 var files = $(this)[0].files; 4541 var file_names = []; 4542 for (var i = 0; i < files.length; i++) { 4543 file_names.push(files[i].name); 4544 } 4545 path_input.val(file_names.join(", ")); 4546 path_input.trigger('change'); 4547 }); 4548 4549 /**************** 4550 * Range Input * 4551 ****************/ 4552 4553 var range_type = 'input[type=range]'; 4554 var range_mousedown = false; 4555 var left; 4556 4557 $(range_type).each(function () { 4558 var thumb = $('<span class="thumb"><span class="value"></span></span>'); 4559 $(this).after(thumb); 4560 }); 4561 4562 var showRangeBubble = function (thumb) { 4563 var paddingLeft = parseInt(thumb.parent().css('padding-left')); 4564 var marginLeft = -7 + paddingLeft + 'px'; 4565 thumb.velocity({ height: "30px", width: "30px", top: "-30px", marginLeft: marginLeft }, { duration: 300, easing: 'easeOutExpo' }); 4566 }; 4567 4568 var calcRangeOffset = function (range) { 4569 var width = range.width() - 15; 4570 var max = parseFloat(range.attr('max')); 4571 var min = parseFloat(range.attr('min')); 4572 var percent = (parseFloat(range.val()) - min) / (max - min); 4573 return percent * width; 4574 }; 4575 4576 var range_wrapper = '.range-field'; 4577 $(document).on('change', range_type, function (e) { 4578 var thumb = $(this).siblings('.thumb'); 4579 thumb.find('.value').html($(this).val()); 4580 4581 if (!thumb.hasClass('active')) { 4582 showRangeBubble(thumb); 4583 } 4584 4585 var offsetLeft = calcRangeOffset($(this)); 4586 thumb.addClass('active').css('left', offsetLeft); 4587 }); 4588 4589 $(document).on('mousedown touchstart', range_type, function (e) { 4590 var thumb = $(this).siblings('.thumb'); 4591 4592 // If thumb indicator does not exist yet, create it 4593 if (thumb.length <= 0) { 4594 thumb = $('<span class="thumb"><span class="value"></span></span>'); 4595 $(this).after(thumb); 4596 } 4597 4598 // Set indicator value 4599 thumb.find('.value').html($(this).val()); 4600 4601 range_mousedown = true; 4602 $(this).addClass('active'); 4603 4604 if (!thumb.hasClass('active')) { 4605 showRangeBubble(thumb); 4606 } 4607 4608 if (e.type !== 'input') { 4609 var offsetLeft = calcRangeOffset($(this)); 4610 thumb.addClass('active').css('left', offsetLeft); 4611 } 4612 }); 4613 4614 $(document).on('mouseup touchend', range_wrapper, function () { 4615 range_mousedown = false; 4616 $(this).removeClass('active'); 4617 }); 4618 4619 $(document).on('input mousemove touchmove', range_wrapper, function (e) { 4620 var thumb = $(this).children('.thumb'); 4621 var left; 4622 var input = $(this).find(range_type); 4623 4624 if (range_mousedown) { 4625 if (!thumb.hasClass('active')) { 4626 showRangeBubble(thumb); 4627 } 4628 4629 var offsetLeft = calcRangeOffset(input); 4630 thumb.addClass('active').css('left', offsetLeft); 4631 thumb.find('.value').html(thumb.siblings(range_type).val()); 4632 } 4633 }); 4634 4635 $(document).on('mouseout touchleave', range_wrapper, function () { 4636 if (!range_mousedown) { 4637 4638 var thumb = $(this).children('.thumb'); 4639 var paddingLeft = parseInt($(this).css('padding-left')); 4640 var marginLeft = 7 + paddingLeft + 'px'; 4641 4642 if (thumb.hasClass('active')) { 4643 thumb.velocity({ height: '0', width: '0', top: '10px', marginLeft: marginLeft }, { duration: 100 }); 4644 } 4645 thumb.removeClass('active'); 4646 } 4647 }); 4648 4649 /************************** 4650 * Auto complete plugin * 4651 *************************/ 4652 $.fn.autocomplete = function (options) { 4653 // Defaults 4654 var defaults = { 4655 data: {}, 4656 limit: Infinity, 4657 onAutocomplete: null, 4658 minLength: 1 4659 }; 4660 4661 options = $.extend(defaults, options); 4662 4663 return this.each(function () { 4664 var $input = $(this); 4665 var data = options.data, 4666 count = 0, 4667 activeIndex = -1, 4668 oldVal, 4669 $inputDiv = $input.closest('.input-field'); // Div to append on 4670 4671 // Check if data isn't empty 4672 if (!$.isEmptyObject(data)) { 4673 var $autocomplete = $('<ul class="autocomplete-content dropdown-content"></ul>'); 4674 var $oldAutocomplete; 4675 4676 // Append autocomplete element. 4677 // Prevent double structure init. 4678 if ($inputDiv.length) { 4679 $oldAutocomplete = $inputDiv.children('.autocomplete-content.dropdown-content').first(); 4680 if (!$oldAutocomplete.length) { 4681 $inputDiv.append($autocomplete); // Set ul in body 4682 } 4683 } else { 4684 $oldAutocomplete = $input.next('.autocomplete-content.dropdown-content'); 4685 if (!$oldAutocomplete.length) { 4686 $input.after($autocomplete); 4687 } 4688 } 4689 if ($oldAutocomplete.length) { 4690 $autocomplete = $oldAutocomplete; 4691 } 4692 4693 // Highlight partial match. 4694 var highlight = function (string, $el) { 4695 var img = $el.find('img'); 4696 var matchStart = $el.text().toLowerCase().indexOf("" + string.toLowerCase() + ""), 4697 matchEnd = matchStart + string.length - 1, 4698 beforeMatch = $el.text().slice(0, matchStart), 4699 matchText = $el.text().slice(matchStart, matchEnd + 1), 4700 afterMatch = $el.text().slice(matchEnd + 1); 4701 $el.html("<span>" + beforeMatch + "<span class='highlight'>" + matchText + "</span>" + afterMatch + "</span>"); 4702 if (img.length) { 4703 $el.prepend(img); 4704 } 4705 }; 4706 4707 // Reset current element position 4708 var resetCurrentElement = function () { 4709 activeIndex = -1; 4710 $autocomplete.find('.active').removeClass('active'); 4711 }; 4712 4713 // Remove autocomplete elements 4714 var removeAutocomplete = function () { 4715 $autocomplete.empty(); 4716 resetCurrentElement(); 4717 oldVal = undefined; 4718 }; 4719 4720 $input.off('blur.autocomplete').on('blur.autocomplete', function () { 4721 removeAutocomplete(); 4722 }); 4723 4724 // Perform search 4725 $input.off('keyup.autocomplete focus.autocomplete').on('keyup.autocomplete focus.autocomplete', function (e) { 4726 // Reset count. 4727 count = 0; 4728 var val = $input.val().toLowerCase(); 4729 4730 // Don't capture enter or arrow key usage. 4731 if (e.which === 13 || e.which === 38 || e.which === 40) { 4732 return; 4733 } 4734 4735 // Check if the input isn't empty 4736 if (oldVal !== val) { 4737 removeAutocomplete(); 4738 4739 if (val.length >= options.minLength) { 4740 for (var key in data) { 4741 if (data.hasOwnProperty(key) && key.toLowerCase().indexOf(val) !== -1) { 4742 // Break if past limit 4743 if (count >= options.limit) { 4744 break; 4745 } 4746 4747 var autocompleteOption = $('<li></li>'); 4748 if (!!data[key]) { 4749 autocompleteOption.append('<img src="' + data[key] + '" class="right circle"><span>' + key + '</span>'); 4750 } else { 4751 autocompleteOption.append('<span>' + key + '</span>'); 4752 } 4753 4754 $autocomplete.append(autocompleteOption); 4755 highlight(val, autocompleteOption); 4756 count++; 4757 } 4758 } 4759 } 4760 } 4761 4762 // Update oldVal 4763 oldVal = val; 4764 }); 4765 4766 $input.off('keydown.autocomplete').on('keydown.autocomplete', function (e) { 4767 // Arrow keys and enter key usage 4768 var keyCode = e.which, 4769 liElement, 4770 numItems = $autocomplete.children('li').length, 4771 $active = $autocomplete.children('.active').first(); 4772 4773 // select element on Enter 4774 if (keyCode === 13 && activeIndex >= 0) { 4775 liElement = $autocomplete.children('li').eq(activeIndex); 4776 if (liElement.length) { 4777 liElement.trigger('mousedown.autocomplete'); 4778 e.preventDefault(); 4779 } 4780 return; 4781 } 4782 4783 // Capture up and down key 4784 if (keyCode === 38 || keyCode === 40) { 4785 e.preventDefault(); 4786 4787 if (keyCode === 38 && activeIndex > 0) { 4788 activeIndex--; 4789 } 4790 4791 if (keyCode === 40 && activeIndex < numItems - 1) { 4792 activeIndex++; 4793 } 4794 4795 $active.removeClass('active'); 4796 if (activeIndex >= 0) { 4797 $autocomplete.children('li').eq(activeIndex).addClass('active'); 4798 } 4799 } 4800 }); 4801 4802 // Set input value 4803 $autocomplete.off('mousedown.autocomplete touchstart.autocomplete').on('mousedown.autocomplete touchstart.autocomplete', 'li', function () { 4804 var text = $(this).text().trim(); 4805 $input.val(text); 4806 $input.trigger('change'); 4807 removeAutocomplete(); 4808 4809 // Handle onAutocomplete callback. 4810 if (typeof options.onAutocomplete === "function") { 4811 options.onAutocomplete.call(this, text); 4812 } 4813 }); 4814 4815 // Empty data 4816 } else { 4817 $input.off('keyup.autocomplete focus.autocomplete'); 4818 } 4819 }); 4820 }; 4821 }); // End of $(document).ready 4822 4823 /******************* 4824 * Select Plugin * 4825 ******************/ 4826 $.fn.material_select = function (callback) { 4827 $(this).each(function () { 4828 var $select = $(this); 4829 4830 if ($select.hasClass('browser-default')) { 4831 return; // Continue to next (return false breaks out of entire loop) 4832 } 4833 4834 var multiple = $select.attr('multiple') ? true : false, 4835 lastID = $select.attr('data-select-id'); // Tear down structure if Select needs to be rebuilt 4836 4837 if (lastID) { 4838 $select.parent().find('span.caret').remove(); 4839 $select.parent().find('input').remove(); 4840 4841 $select.unwrap(); 4842 $('ul#select-options-' + lastID).remove(); 4843 } 4844 4845 // If destroying the select, remove the selelct-id and reset it to it's uninitialized state. 4846 if (callback === 'destroy') { 4847 $select.removeAttr('data-select-id').removeClass('initialized'); 4848 $(window).off('click.select'); 4849 return; 4850 } 4851 4852 var uniqueID = Materialize.guid(); 4853 $select.attr('data-select-id', uniqueID); 4854 var wrapper = $('<div class="select-wrapper"></div>'); 4855 wrapper.addClass($select.attr('class')); 4856 if ($select.is(':disabled')) wrapper.addClass('disabled'); 4857 var options = $('<ul id="select-options-' + uniqueID + '" class="dropdown-content select-dropdown ' + (multiple ? 'multiple-select-dropdown' : '') + '"></ul>'), 4858 selectChildren = $select.children('option, optgroup'), 4859 valuesSelected = [], 4860 optionsHover = false; 4861 4862 var label = $select.find('option:selected').html() || $select.find('option:first').html() || ""; 4863 4864 // Function that renders and appends the option taking into 4865 // account type and possible image icon. 4866 var appendOptionWithIcon = function (select, option, type) { 4867 // Add disabled attr if disabled 4868 var disabledClass = option.is(':disabled') ? 'disabled ' : ''; 4869 var optgroupClass = type === 'optgroup-option' ? 'optgroup-option ' : ''; 4870 var multipleCheckbox = multiple ? '<input type="checkbox"' + disabledClass + '/><label></label>' : ''; 4871 4872 // add icons 4873 var icon_url = option.data('icon'); 4874 var classes = option.attr('class'); 4875 if (!!icon_url) { 4876 var classString = ''; 4877 if (!!classes) classString = ' class="' + classes + '"'; 4878 4879 // Check for multiple type. 4880 options.append($('<li class="' + disabledClass + optgroupClass + '"><img alt="" src="' + icon_url + '"' + classString + '><span>' + multipleCheckbox + option.html() + '</span></li>')); 4881 return true; 4882 } 4883 4884 // Check for multiple type. 4885 options.append($('<li class="' + disabledClass + optgroupClass + '"><span>' + multipleCheckbox + option.html() + '</span></li>')); 4886 }; 4887 4888 /* Create dropdown structure. */ 4889 if (selectChildren.length) { 4890 selectChildren.each(function () { 4891 if ($(this).is('option')) { 4892 // Direct descendant option. 4893 if (multiple) { 4894 appendOptionWithIcon($select, $(this), 'multiple'); 4895 } else { 4896 appendOptionWithIcon($select, $(this)); 4897 } 4898 } else if ($(this).is('optgroup')) { 4899 // Optgroup. 4900 var selectOptions = $(this).children('option'); 4901 options.append($('<li class="optgroup"><span>' + $(this).attr('label') + '</span></li>')); 4902 4903 selectOptions.each(function () { 4904 appendOptionWithIcon($select, $(this), 'optgroup-option'); 4905 }); 4906 } 4907 }); 4908 } 4909 4910 options.find('li:not(.optgroup)').each(function (i) { 4911 $(this).click(function (e) { 4912 // Check if option element is disabled 4913 if (!$(this).hasClass('disabled') && !$(this).hasClass('optgroup')) { 4914 var selected = true; 4915 4916 if (multiple) { 4917 $('input[type="checkbox"]', this).prop('checked', function (i, v) { 4918 return !v; 4919 }); 4920 selected = toggleEntryFromArray(valuesSelected, i, $select); 4921 $newSelect.trigger('focus'); 4922 } else { 4923 options.find('li').removeClass('active'); 4924 $(this).toggleClass('active'); 4925 $newSelect.val($(this).text()); 4926 } 4927 4928 activateOption(options, $(this)); 4929 $select.find('option').eq(i).prop('selected', selected); 4930 // Trigger onchange() event 4931 $select.trigger('change'); 4932 if (typeof callback !== 'undefined') callback(); 4933 } 4934 4935 e.stopPropagation(); 4936 }); 4937 }); 4938 4939 // Wrap Elements 4940 $select.wrap(wrapper); 4941 // Add Select Display Element 4942 var dropdownIcon = $('<span class="caret">▼</span>'); 4943 4944 // escape double quotes 4945 var sanitizedLabelHtml = label.replace(/"/g, '"'); 4946 4947 var $newSelect = $('<input type="text" class="select-dropdown" readonly="true" ' + ($select.is(':disabled') ? 'disabled' : '') + ' data-activates="select-options-' + uniqueID + '" value="' + sanitizedLabelHtml + '"/>'); 4948 $select.before($newSelect); 4949 $newSelect.before(dropdownIcon); 4950 4951 $newSelect.after(options); 4952 // Check if section element is disabled 4953 if (!$select.is(':disabled')) { 4954 $newSelect.dropdown({ 'hover': false }); 4955 } 4956 4957 // Copy tabindex 4958 if ($select.attr('tabindex')) { 4959 $($newSelect[0]).attr('tabindex', $select.attr('tabindex')); 4960 } 4961 4962 $select.addClass('initialized'); 4963 4964 $newSelect.on({ 4965 'focus': function () { 4966 if ($('ul.select-dropdown').not(options[0]).is(':visible')) { 4967 $('input.select-dropdown').trigger('close'); 4968 $(window).off('click.select'); 4969 } 4970 if (!options.is(':visible')) { 4971 $(this).trigger('open', ['focus']); 4972 var label = $(this).val(); 4973 if (multiple && label.indexOf(',') >= 0) { 4974 label = label.split(',')[0]; 4975 } 4976 4977 var selectedOption = options.find('li').filter(function () { 4978 return $(this).text().toLowerCase() === label.toLowerCase(); 4979 })[0]; 4980 activateOption(options, selectedOption, true); 4981 4982 $(window).off('click.select').on('click.select', function () { 4983 multiple && (optionsHover || $newSelect.trigger('close')); 4984 $(window).off('click.select'); 4985 }); 4986 } 4987 }, 4988 'click': function (e) { 4989 e.stopPropagation(); 4990 } 4991 }); 4992 4993 $newSelect.on('blur', function () { 4994 if (!multiple) { 4995 $(this).trigger('close'); 4996 $(window).off('click.select'); 4997 } 4998 options.find('li.selected').removeClass('selected'); 4999 }); 5000 5001 options.hover(function () { 5002 optionsHover = true; 5003 }, function () { 5004 optionsHover = false; 5005 }); 5006 5007 // Add initial multiple selections. 5008 if (multiple) { 5009 $select.find("option:selected:not(:disabled)").each(function () { 5010 var index = this.index; 5011 5012 toggleEntryFromArray(valuesSelected, index, $select); 5013 options.find("li:not(.optgroup)").eq(index).find(":checkbox").prop("checked", true); 5014 }); 5015 } 5016 5017 /** 5018 * Make option as selected and scroll to selected position 5019 * @param {jQuery} collection Select options jQuery element 5020 * @param {Element} newOption element of the new option 5021 * @param {Boolean} firstActivation If on first activation of select 5022 */ 5023 var activateOption = function (collection, newOption, firstActivation) { 5024 if (newOption) { 5025 collection.find('li.selected').removeClass('selected'); 5026 var option = $(newOption); 5027 option.addClass('selected'); 5028 if (!multiple || !!firstActivation) { 5029 options.scrollTo(option); 5030 } 5031 } 5032 }; 5033 5034 // Allow user to search by typing 5035 // this array is cleared after 1 second 5036 var filterQuery = [], 5037 onKeyDown = function (e) { 5038 // TAB - switch to another input 5039 if (e.which == 9) { 5040 $newSelect.trigger('close'); 5041 return; 5042 } 5043 5044 // ARROW DOWN WHEN SELECT IS CLOSED - open select options 5045 if (e.which == 40 && !options.is(':visible')) { 5046 $newSelect.trigger('open'); 5047 return; 5048 } 5049 5050 // ENTER WHEN SELECT IS CLOSED - submit form 5051 if (e.which == 13 && !options.is(':visible')) { 5052 return; 5053 } 5054 5055 e.preventDefault(); 5056 5057 // CASE WHEN USER TYPE LETTERS 5058 var letter = String.fromCharCode(e.which).toLowerCase(), 5059 nonLetters = [9, 13, 27, 38, 40]; 5060 if (letter && nonLetters.indexOf(e.which) === -1) { 5061 filterQuery.push(letter); 5062 5063 var string = filterQuery.join(''), 5064 newOption = options.find('li').filter(function () { 5065 return $(this).text().toLowerCase().indexOf(string) === 0; 5066 })[0]; 5067 5068 if (newOption) { 5069 activateOption(options, newOption); 5070 } 5071 } 5072 5073 // ENTER - select option and close when select options are opened 5074 if (e.which == 13) { 5075 var activeOption = options.find('li.selected:not(.disabled)')[0]; 5076 if (activeOption) { 5077 $(activeOption).trigger('click'); 5078 if (!multiple) { 5079 $newSelect.trigger('close'); 5080 } 5081 } 5082 } 5083 5084 // ARROW DOWN - move to next not disabled option 5085 if (e.which == 40) { 5086 if (options.find('li.selected').length) { 5087 newOption = options.find('li.selected').next('li:not(.disabled)')[0]; 5088 } else { 5089 newOption = options.find('li:not(.disabled)')[0]; 5090 } 5091 activateOption(options, newOption); 5092 } 5093 5094 // ESC - close options 5095 if (e.which == 27) { 5096 $newSelect.trigger('close'); 5097 } 5098 5099 // ARROW UP - move to previous not disabled option 5100 if (e.which == 38) { 5101 newOption = options.find('li.selected').prev('li:not(.disabled)')[0]; 5102 if (newOption) activateOption(options, newOption); 5103 } 5104 5105 // Automaticaly clean filter query so user can search again by starting letters 5106 setTimeout(function () { 5107 filterQuery = []; 5108 }, 1000); 5109 }; 5110 5111 $newSelect.on('keydown', onKeyDown); 5112 }); 5113 5114 function toggleEntryFromArray(entriesArray, entryIndex, select) { 5115 var index = entriesArray.indexOf(entryIndex), 5116 notAdded = index === -1; 5117 5118 if (notAdded) { 5119 entriesArray.push(entryIndex); 5120 } else { 5121 entriesArray.splice(index, 1); 5122 } 5123 5124 select.siblings('ul.dropdown-content').find('li:not(.optgroup)').eq(entryIndex).toggleClass('active'); 5125 5126 // use notAdded instead of true (to detect if the option is selected or not) 5127 select.find('option').eq(entryIndex).prop('selected', notAdded); 5128 setValueToInput(entriesArray, select); 5129 5130 return notAdded; 5131 } 5132 5133 function setValueToInput(entriesArray, select) { 5134 var value = ''; 5135 5136 for (var i = 0, count = entriesArray.length; i < count; i++) { 5137 var text = select.find('option').eq(entriesArray[i]).text(); 5138 5139 i === 0 ? value += text : value += ', ' + text; 5140 } 5141 5142 if (value === '') { 5143 value = select.find('option:disabled').eq(0).text(); 5144 } 5145 5146 select.siblings('input.select-dropdown').val(value); 5147 } 5148 }; 5149 })(jQuery); 5150 ;(function ($) { 5151 5152 var methods = { 5153 5154 init: function (options) { 5155 var defaults = { 5156 indicators: true, 5157 height: 400, 5158 transition: 500, 5159 interval: 6000 5160 }; 5161 options = $.extend(defaults, options); 5162 5163 return this.each(function () { 5164 5165 // For each slider, we want to keep track of 5166 // which slide is active and its associated content 5167 var $this = $(this); 5168 var $slider = $this.find('ul.slides').first(); 5169 var $slides = $slider.find('> li'); 5170 var $active_index = $slider.find('.active').index(); 5171 var $active, $indicators, $interval; 5172 if ($active_index != -1) { 5173 $active = $slides.eq($active_index); 5174 } 5175 5176 // Transitions the caption depending on alignment 5177 function captionTransition(caption, duration) { 5178 if (caption.hasClass("center-align")) { 5179 caption.velocity({ opacity: 0, translateY: -100 }, { duration: duration, queue: false }); 5180 } else if (caption.hasClass("right-align")) { 5181 caption.velocity({ opacity: 0, translateX: 100 }, { duration: duration, queue: false }); 5182 } else if (caption.hasClass("left-align")) { 5183 caption.velocity({ opacity: 0, translateX: -100 }, { duration: duration, queue: false }); 5184 } 5185 } 5186 5187 // This function will transition the slide to any index of the next slide 5188 function moveToSlide(index) { 5189 // Wrap around indices. 5190 if (index >= $slides.length) index = 0;else if (index < 0) index = $slides.length - 1; 5191 5192 $active_index = $slider.find('.active').index(); 5193 5194 // Only do if index changes 5195 if ($active_index != index) { 5196 $active = $slides.eq($active_index); 5197 $caption = $active.find('.caption'); 5198 5199 $active.removeClass('active'); 5200 $active.velocity({ opacity: 0 }, { duration: options.transition, queue: false, easing: 'easeOutQuad', 5201 complete: function () { 5202 $slides.not('.active').velocity({ opacity: 0, translateX: 0, translateY: 0 }, { duration: 0, queue: false }); 5203 } }); 5204 captionTransition($caption, options.transition); 5205 5206 // Update indicators 5207 if (options.indicators) { 5208 $indicators.eq($active_index).removeClass('active'); 5209 } 5210 5211 $slides.eq(index).velocity({ opacity: 1 }, { duration: options.transition, queue: false, easing: 'easeOutQuad' }); 5212 $slides.eq(index).find('.caption').velocity({ opacity: 1, translateX: 0, translateY: 0 }, { duration: options.transition, delay: options.transition, queue: false, easing: 'easeOutQuad' }); 5213 $slides.eq(index).addClass('active'); 5214 5215 // Update indicators 5216 if (options.indicators) { 5217 $indicators.eq(index).addClass('active'); 5218 } 5219 } 5220 } 5221 5222 // Set height of slider 5223 // If fullscreen, do nothing 5224 if (!$this.hasClass('fullscreen')) { 5225 if (options.indicators) { 5226 // Add height if indicators are present 5227 $this.height(options.height + 40); 5228 } else { 5229 $this.height(options.height); 5230 } 5231 $slider.height(options.height); 5232 } 5233 5234 // Set initial positions of captions 5235 $slides.find('.caption').each(function () { 5236 captionTransition($(this), 0); 5237 }); 5238 5239 // Move img src into background-image 5240 $slides.find('img').each(function () { 5241 var placeholderBase64 = 'data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='; 5242 if ($(this).attr('src') !== placeholderBase64) { 5243 $(this).css('background-image', 'url("' + $(this).attr('src') + '")'); 5244 $(this).attr('src', placeholderBase64); 5245 } 5246 }); 5247 5248 // dynamically add indicators 5249 if (options.indicators) { 5250 $indicators = $('<ul class="indicators"></ul>'); 5251 $slides.each(function (index) { 5252 var $indicator = $('<li class="indicator-item"></li>'); 5253 5254 // Handle clicks on indicators 5255 $indicator.click(function () { 5256 var $parent = $slider.parent(); 5257 var curr_index = $parent.find($(this)).index(); 5258 moveToSlide(curr_index); 5259 5260 // reset interval 5261 clearInterval($interval); 5262 $interval = setInterval(function () { 5263 $active_index = $slider.find('.active').index(); 5264 if ($slides.length == $active_index + 1) $active_index = 0; // loop to start 5265 else $active_index += 1; 5266 5267 moveToSlide($active_index); 5268 }, options.transition + options.interval); 5269 }); 5270 $indicators.append($indicator); 5271 }); 5272 $this.append($indicators); 5273 $indicators = $this.find('ul.indicators').find('li.indicator-item'); 5274 } 5275 5276 if ($active) { 5277 $active.show(); 5278 } else { 5279 $slides.first().addClass('active').velocity({ opacity: 1 }, { duration: options.transition, queue: false, easing: 'easeOutQuad' }); 5280 5281 $active_index = 0; 5282 $active = $slides.eq($active_index); 5283 5284 // Update indicators 5285 if (options.indicators) { 5286 $indicators.eq($active_index).addClass('active'); 5287 } 5288 } 5289 5290 // Adjust height to current slide 5291 $active.find('img').each(function () { 5292 $active.find('.caption').velocity({ opacity: 1, translateX: 0, translateY: 0 }, { duration: options.transition, queue: false, easing: 'easeOutQuad' }); 5293 }); 5294 5295 // auto scroll 5296 $interval = setInterval(function () { 5297 $active_index = $slider.find('.active').index(); 5298 moveToSlide($active_index + 1); 5299 }, options.transition + options.interval); 5300 5301 // HammerJS, Swipe navigation 5302 5303 // Touch Event 5304 var panning = false; 5305 var swipeLeft = false; 5306 var swipeRight = false; 5307 5308 $this.hammer({ 5309 prevent_default: false 5310 }).on('pan', function (e) { 5311 if (e.gesture.pointerType === "touch") { 5312 5313 // reset interval 5314 clearInterval($interval); 5315 5316 var direction = e.gesture.direction; 5317 var x = e.gesture.deltaX; 5318 var velocityX = e.gesture.velocityX; 5319 var velocityY = e.gesture.velocityY; 5320 5321 $curr_slide = $slider.find('.active'); 5322 if (Math.abs(velocityX) > Math.abs(velocityY)) { 5323 $curr_slide.velocity({ translateX: x 5324 }, { duration: 50, queue: false, easing: 'easeOutQuad' }); 5325 } 5326 5327 // Swipe Left 5328 if (direction === 4 && (x > $this.innerWidth() / 2 || velocityX < -0.65)) { 5329 swipeRight = true; 5330 } 5331 // Swipe Right 5332 else if (direction === 2 && (x < -1 * $this.innerWidth() / 2 || velocityX > 0.65)) { 5333 swipeLeft = true; 5334 } 5335 5336 // Make Slide Behind active slide visible 5337 var next_slide; 5338 if (swipeLeft) { 5339 next_slide = $curr_slide.next(); 5340 if (next_slide.length === 0) { 5341 next_slide = $slides.first(); 5342 } 5343 next_slide.velocity({ opacity: 1 5344 }, { duration: 300, queue: false, easing: 'easeOutQuad' }); 5345 } 5346 if (swipeRight) { 5347 next_slide = $curr_slide.prev(); 5348 if (next_slide.length === 0) { 5349 next_slide = $slides.last(); 5350 } 5351 next_slide.velocity({ opacity: 1 5352 }, { duration: 300, queue: false, easing: 'easeOutQuad' }); 5353 } 5354 } 5355 }).on('panend', function (e) { 5356 if (e.gesture.pointerType === "touch") { 5357 5358 $curr_slide = $slider.find('.active'); 5359 panning = false; 5360 curr_index = $slider.find('.active').index(); 5361 5362 if (!swipeRight && !swipeLeft || $slides.length <= 1) { 5363 // Return to original spot 5364 $curr_slide.velocity({ translateX: 0 5365 }, { duration: 300, queue: false, easing: 'easeOutQuad' }); 5366 } else if (swipeLeft) { 5367 moveToSlide(curr_index + 1); 5368 $curr_slide.velocity({ translateX: -1 * $this.innerWidth() }, { duration: 300, queue: false, easing: 'easeOutQuad', 5369 complete: function () { 5370 $curr_slide.velocity({ opacity: 0, translateX: 0 }, { duration: 0, queue: false }); 5371 } }); 5372 } else if (swipeRight) { 5373 moveToSlide(curr_index - 1); 5374 $curr_slide.velocity({ translateX: $this.innerWidth() }, { duration: 300, queue: false, easing: 'easeOutQuad', 5375 complete: function () { 5376 $curr_slide.velocity({ opacity: 0, translateX: 0 }, { duration: 0, queue: false }); 5377 } }); 5378 } 5379 swipeLeft = false; 5380 swipeRight = false; 5381 5382 // Restart interval 5383 clearInterval($interval); 5384 $interval = setInterval(function () { 5385 $active_index = $slider.find('.active').index(); 5386 if ($slides.length == $active_index + 1) $active_index = 0; // loop to start 5387 else $active_index += 1; 5388 5389 moveToSlide($active_index); 5390 }, options.transition + options.interval); 5391 } 5392 }); 5393 5394 $this.on('sliderPause', function () { 5395 clearInterval($interval); 5396 }); 5397 5398 $this.on('sliderStart', function () { 5399 clearInterval($interval); 5400 $interval = setInterval(function () { 5401 $active_index = $slider.find('.active').index(); 5402 if ($slides.length == $active_index + 1) $active_index = 0; // loop to start 5403 else $active_index += 1; 5404 5405 moveToSlide($active_index); 5406 }, options.transition + options.interval); 5407 }); 5408 5409 $this.on('sliderNext', function () { 5410 $active_index = $slider.find('.active').index(); 5411 moveToSlide($active_index + 1); 5412 }); 5413 5414 $this.on('sliderPrev', function () { 5415 $active_index = $slider.find('.active').index(); 5416 moveToSlide($active_index - 1); 5417 }); 5418 }); 5419 }, 5420 pause: function () { 5421 $(this).trigger('sliderPause'); 5422 }, 5423 start: function () { 5424 $(this).trigger('sliderStart'); 5425 }, 5426 next: function () { 5427 $(this).trigger('sliderNext'); 5428 }, 5429 prev: function () { 5430 $(this).trigger('sliderPrev'); 5431 } 5432 }; 5433 5434 $.fn.slider = function (methodOrOptions) { 5435 if (methods[methodOrOptions]) { 5436 return methods[methodOrOptions].apply(this, Array.prototype.slice.call(arguments, 1)); 5437 } else if (typeof methodOrOptions === 'object' || !methodOrOptions) { 5438 // Default to "init" 5439 return methods.init.apply(this, arguments); 5440 } else { 5441 $.error('Method ' + methodOrOptions + ' does not exist on jQuery.tooltip'); 5442 } 5443 }; // Plugin end 5444 })(jQuery); 5445 ;(function ($) { 5446 $(document).ready(function () { 5447 5448 $(document).on('click.card', '.card', function (e) { 5449 if ($(this).find('> .card-reveal').length) { 5450 var $card = $(e.target).closest('.card'); 5451 if ($card.data('initialOverflow') === undefined) { 5452 $card.data('initialOverflow', $card.css('overflow') === undefined ? '' : $card.css('overflow')); 5453 } 5454 if ($(e.target).is($('.card-reveal .card-title')) || $(e.target).is($('.card-reveal .card-title i'))) { 5455 // Make Reveal animate down and display none 5456 $(this).find('.card-reveal').velocity({ translateY: 0 }, { 5457 duration: 225, 5458 queue: false, 5459 easing: 'easeInOutQuad', 5460 complete: function () { 5461 $(this).css({ display: 'none' }); 5462 $card.css('overflow', $card.data('initialOverflow')); 5463 } 5464 }); 5465 } else if ($(e.target).is($('.card .activator')) || $(e.target).is($('.card .activator i'))) { 5466 $card.css('overflow', 'hidden'); 5467 $(this).find('.card-reveal').css({ display: 'block' }).velocity("stop", false).velocity({ translateY: '-100%' }, { duration: 300, queue: false, easing: 'easeInOutQuad' }); 5468 } 5469 } 5470 }); 5471 }); 5472 })(jQuery); 5473 ;(function ($) { 5474 var materialChipsDefaults = { 5475 data: [], 5476 placeholder: '', 5477 secondaryPlaceholder: '', 5478 autocompleteOptions: {} 5479 }; 5480 5481 $(document).ready(function () { 5482 // Handle removal of static chips. 5483 $(document).on('click', '.chip .close', function (e) { 5484 var $chips = $(this).closest('.chips'); 5485 if ($chips.attr('data-initialized')) { 5486 return; 5487 } 5488 $(this).closest('.chip').remove(); 5489 }); 5490 }); 5491 5492 $.fn.material_chip = function (options) { 5493 var self = this; 5494 this.$el = $(this); 5495 this.$document = $(document); 5496 this.SELS = { 5497 CHIPS: '.chips', 5498 CHIP: '.chip', 5499 INPUT: 'input', 5500 DELETE: '.material-icons', 5501 SELECTED_CHIP: '.selected' 5502 }; 5503 5504 if ('data' === options) { 5505 return this.$el.data('chips'); 5506 } 5507 5508 var curr_options = $.extend({}, materialChipsDefaults, options); 5509 self.hasAutocomplete = !$.isEmptyObject(curr_options.autocompleteOptions.data); 5510 5511 // Initialize 5512 this.init = function () { 5513 var i = 0; 5514 var chips; 5515 self.$el.each(function () { 5516 var $chips = $(this); 5517 var chipId = Materialize.guid(); 5518 self.chipId = chipId; 5519 5520 if (!curr_options.data || !(curr_options.data instanceof Array)) { 5521 curr_options.data = []; 5522 } 5523 $chips.data('chips', curr_options.data); 5524 $chips.attr('data-index', i); 5525 $chips.attr('data-initialized', true); 5526 5527 if (!$chips.hasClass(self.SELS.CHIPS)) { 5528 $chips.addClass('chips'); 5529 } 5530 5531 self.chips($chips, chipId); 5532 i++; 5533 }); 5534 }; 5535 5536 this.handleEvents = function () { 5537 var SELS = self.SELS; 5538 5539 self.$document.off('click.chips-focus', SELS.CHIPS).on('click.chips-focus', SELS.CHIPS, function (e) { 5540 $(e.target).find(SELS.INPUT).focus(); 5541 }); 5542 5543 self.$document.off('click.chips-select', SELS.CHIP).on('click.chips-select', SELS.CHIP, function (e) { 5544 var $chip = $(e.target); 5545 if ($chip.length) { 5546 var wasSelected = $chip.hasClass('selected'); 5547 var $chips = $chip.closest(SELS.CHIPS); 5548 $(SELS.CHIP).removeClass('selected'); 5549 5550 if (!wasSelected) { 5551 self.selectChip($chip.index(), $chips); 5552 } 5553 } 5554 }); 5555 5556 self.$document.off('keydown.chips').on('keydown.chips', function (e) { 5557 if ($(e.target).is('input, textarea')) { 5558 return; 5559 } 5560 5561 // delete 5562 var $chip = self.$document.find(SELS.CHIP + SELS.SELECTED_CHIP); 5563 var $chips = $chip.closest(SELS.CHIPS); 5564 var length = $chip.siblings(SELS.CHIP).length; 5565 var index; 5566 5567 if (!$chip.length) { 5568 return; 5569 } 5570 5571 if (e.which === 8 || e.which === 46) { 5572 e.preventDefault(); 5573 5574 index = $chip.index(); 5575 self.deleteChip(index, $chips); 5576 5577 var selectIndex = null; 5578 if (index + 1 < length) { 5579 selectIndex = index; 5580 } else if (index === length || index + 1 === length) { 5581 selectIndex = length - 1; 5582 } 5583 5584 if (selectIndex < 0) selectIndex = null; 5585 5586 if (null !== selectIndex) { 5587 self.selectChip(selectIndex, $chips); 5588 } 5589 if (!length) $chips.find('input').focus(); 5590 5591 // left 5592 } else if (e.which === 37) { 5593 index = $chip.index() - 1; 5594 if (index < 0) { 5595 return; 5596 } 5597 $(SELS.CHIP).removeClass('selected'); 5598 self.selectChip(index, $chips); 5599 5600 // right 5601 } else if (e.which === 39) { 5602 index = $chip.index() + 1; 5603 $(SELS.CHIP).removeClass('selected'); 5604 if (index > length) { 5605 $chips.find('input').focus(); 5606 return; 5607 } 5608 self.selectChip(index, $chips); 5609 } 5610 }); 5611 5612 self.$document.off('focusin.chips', SELS.CHIPS + ' ' + SELS.INPUT).on('focusin.chips', SELS.CHIPS + ' ' + SELS.INPUT, function (e) { 5613 var $currChips = $(e.target).closest(SELS.CHIPS); 5614 $currChips.addClass('focus'); 5615 $currChips.siblings('label, .prefix').addClass('active'); 5616 $(SELS.CHIP).removeClass('selected'); 5617 }); 5618 5619 self.$document.off('focusout.chips', SELS.CHIPS + ' ' + SELS.INPUT).on('focusout.chips', SELS.CHIPS + ' ' + SELS.INPUT, function (e) { 5620 var $currChips = $(e.target).closest(SELS.CHIPS); 5621 $currChips.removeClass('focus'); 5622 5623 // Remove active if empty 5624 if ($currChips.data('chips') === undefined || !$currChips.data('chips').length) { 5625 $currChips.siblings('label').removeClass('active'); 5626 } 5627 $currChips.siblings('.prefix').removeClass('active'); 5628 }); 5629 5630 self.$document.off('keydown.chips-add', SELS.CHIPS + ' ' + SELS.INPUT).on('keydown.chips-add', SELS.CHIPS + ' ' + SELS.INPUT, function (e) { 5631 var $target = $(e.target); 5632 var $chips = $target.closest(SELS.CHIPS); 5633 var chipsLength = $chips.children(SELS.CHIP).length; 5634 5635 // enter 5636 if (13 === e.which) { 5637 // Override enter if autocompleting. 5638 if (self.hasAutocomplete && $chips.find('.autocomplete-content.dropdown-content').length && $chips.find('.autocomplete-content.dropdown-content').children().length) { 5639 return; 5640 } 5641 5642 e.preventDefault(); 5643 self.addChip({ tag: $target.val() }, $chips); 5644 $target.val(''); 5645 return; 5646 } 5647 5648 // delete or left 5649 if ((8 === e.keyCode || 37 === e.keyCode) && '' === $target.val() && chipsLength) { 5650 e.preventDefault(); 5651 self.selectChip(chipsLength - 1, $chips); 5652 $target.blur(); 5653 return; 5654 } 5655 }); 5656 5657 // Click on delete icon in chip. 5658 self.$document.off('click.chips-delete', SELS.CHIPS + ' ' + SELS.DELETE).on('click.chips-delete', SELS.CHIPS + ' ' + SELS.DELETE, function (e) { 5659 var $target = $(e.target); 5660 var $chips = $target.closest(SELS.CHIPS); 5661 var $chip = $target.closest(SELS.CHIP); 5662 e.stopPropagation(); 5663 self.deleteChip($chip.index(), $chips); 5664 $chips.find('input').focus(); 5665 }); 5666 }; 5667 5668 this.chips = function ($chips, chipId) { 5669 $chips.empty(); 5670 $chips.data('chips').forEach(function (elem) { 5671 $chips.append(self.renderChip(elem)); 5672 }); 5673 $chips.append($('<input id="' + chipId + '" class="input" placeholder="">')); 5674 self.setPlaceholder($chips); 5675 5676 // Set for attribute for label 5677 var label = $chips.next('label'); 5678 if (label.length) { 5679 label.attr('for', chipId); 5680 5681 if ($chips.data('chips') !== undefined && $chips.data('chips').length) { 5682 label.addClass('active'); 5683 } 5684 } 5685 5686 // Setup autocomplete if needed. 5687 var input = $('#' + chipId); 5688 if (self.hasAutocomplete) { 5689 curr_options.autocompleteOptions.onAutocomplete = function (val) { 5690 self.addChip({ tag: val }, $chips); 5691 input.val(''); 5692 input.focus(); 5693 }; 5694 input.autocomplete(curr_options.autocompleteOptions); 5695 } 5696 }; 5697 5698 /** 5699 * Render chip jQuery element. 5700 * @param {Object} elem 5701 * @return {jQuery} 5702 */ 5703 this.renderChip = function (elem) { 5704 if (!elem.tag) return; 5705 5706 var $renderedChip = $('<div class="chip"></div>'); 5707 $renderedChip.text(elem.tag); 5708 if (elem.image) { 5709 $renderedChip.prepend($('<img />').attr('src', elem.image)); 5710 } 5711 $renderedChip.append($('<i class="material-icons close">close</i>')); 5712 return $renderedChip; 5713 }; 5714 5715 this.setPlaceholder = function ($chips) { 5716 if ($chips.data('chips') !== undefined && !$chips.data('chips').length && curr_options.placeholder) { 5717 $chips.find('input').prop('placeholder', curr_options.placeholder); 5718 } else if (($chips.data('chips') === undefined || !!$chips.data('chips').length) && curr_options.secondaryPlaceholder) { 5719 $chips.find('input').prop('placeholder', curr_options.secondaryPlaceholder); 5720 } 5721 }; 5722 5723 this.isValid = function ($chips, elem) { 5724 var chips = $chips.data('chips'); 5725 var exists = false; 5726 for (var i = 0; i < chips.length; i++) { 5727 if (chips[i].tag === elem.tag) { 5728 exists = true; 5729 return; 5730 } 5731 } 5732 return '' !== elem.tag && !exists; 5733 }; 5734 5735 this.addChip = function (elem, $chips) { 5736 if (!self.isValid($chips, elem)) { 5737 return; 5738 } 5739 var $renderedChip = self.renderChip(elem); 5740 var newData = []; 5741 var oldData = $chips.data('chips'); 5742 for (var i = 0; i < oldData.length; i++) { 5743 newData.push(oldData[i]); 5744 } 5745 newData.push(elem); 5746 5747 $chips.data('chips', newData); 5748 $renderedChip.insertBefore($chips.find('input')); 5749 $chips.trigger('chip.add', elem); 5750 self.setPlaceholder($chips); 5751 }; 5752 5753 this.deleteChip = function (chipIndex, $chips) { 5754 var chip = $chips.data('chips')[chipIndex]; 5755 $chips.find('.chip').eq(chipIndex).remove(); 5756 5757 var newData = []; 5758 var oldData = $chips.data('chips'); 5759 for (var i = 0; i < oldData.length; i++) { 5760 if (i !== chipIndex) { 5761 newData.push(oldData[i]); 5762 } 5763 } 5764 5765 $chips.data('chips', newData); 5766 $chips.trigger('chip.delete', chip); 5767 self.setPlaceholder($chips); 5768 }; 5769 5770 this.selectChip = function (chipIndex, $chips) { 5771 var $chip = $chips.find('.chip').eq(chipIndex); 5772 if ($chip && false === $chip.hasClass('selected')) { 5773 $chip.addClass('selected'); 5774 $chips.trigger('chip.select', $chips.data('chips')[chipIndex]); 5775 } 5776 }; 5777 5778 this.getChipsElement = function (index, $chips) { 5779 return $chips.eq(index); 5780 }; 5781 5782 // init 5783 this.init(); 5784 5785 this.handleEvents(); 5786 }; 5787 })(jQuery); 5788 ;(function ($) { 5789 $.fn.pushpin = function (options) { 5790 // Defaults 5791 var defaults = { 5792 top: 0, 5793 bottom: Infinity, 5794 offset: 0 5795 }; 5796 5797 // Remove pushpin event and classes 5798 if (options === "remove") { 5799 this.each(function () { 5800 if (id = $(this).data('pushpin-id')) { 5801 $(window).off('scroll.' + id); 5802 $(this).removeData('pushpin-id').removeClass('pin-top pinned pin-bottom').removeAttr('style'); 5803 } 5804 }); 5805 return false; 5806 } 5807 5808 options = $.extend(defaults, options); 5809 5810 $index = 0; 5811 return this.each(function () { 5812 var $uniqueId = Materialize.guid(), 5813 $this = $(this), 5814 $original_offset = $(this).offset().top; 5815 5816 function removePinClasses(object) { 5817 object.removeClass('pin-top'); 5818 object.removeClass('pinned'); 5819 object.removeClass('pin-bottom'); 5820 } 5821 5822 function updateElements(objects, scrolled) { 5823 objects.each(function () { 5824 // Add position fixed (because its between top and bottom) 5825 if (options.top <= scrolled && options.bottom >= scrolled && !$(this).hasClass('pinned')) { 5826 removePinClasses($(this)); 5827 $(this).css('top', options.offset); 5828 $(this).addClass('pinned'); 5829 } 5830 5831 // Add pin-top (when scrolled position is above top) 5832 if (scrolled < options.top && !$(this).hasClass('pin-top')) { 5833 removePinClasses($(this)); 5834 $(this).css('top', 0); 5835 $(this).addClass('pin-top'); 5836 } 5837 5838 // Add pin-bottom (when scrolled position is below bottom) 5839 if (scrolled > options.bottom && !$(this).hasClass('pin-bottom')) { 5840 removePinClasses($(this)); 5841 $(this).addClass('pin-bottom'); 5842 $(this).css('top', options.bottom - $original_offset); 5843 } 5844 }); 5845 } 5846 5847 $(this).data('pushpin-id', $uniqueId); 5848 updateElements($this, $(window).scrollTop()); 5849 $(window).on('scroll.' + $uniqueId, function () { 5850 var $scrolled = $(window).scrollTop() + options.offset; 5851 updateElements($this, $scrolled); 5852 }); 5853 }); 5854 }; 5855 })(jQuery);;(function ($) { 5856 $(document).ready(function () { 5857 5858 // jQuery reverse 5859 $.fn.reverse = [].reverse; 5860 5861 // Hover behaviour: make sure this doesn't work on .click-to-toggle FABs! 5862 $(document).on('mouseenter.fixedActionBtn', '.fixed-action-btn:not(.click-to-toggle):not(.toolbar)', function (e) { 5863 var $this = $(this); 5864 openFABMenu($this); 5865 }); 5866 $(document).on('mouseleave.fixedActionBtn', '.fixed-action-btn:not(.click-to-toggle):not(.toolbar)', function (e) { 5867 var $this = $(this); 5868 closeFABMenu($this); 5869 }); 5870 5871 // Toggle-on-click behaviour. 5872 $(document).on('click.fabClickToggle', '.fixed-action-btn.click-to-toggle > a', function (e) { 5873 var $this = $(this); 5874 var $menu = $this.parent(); 5875 if ($menu.hasClass('active')) { 5876 closeFABMenu($menu); 5877 } else { 5878 openFABMenu($menu); 5879 } 5880 }); 5881 5882 // Toolbar transition behaviour. 5883 $(document).on('click.fabToolbar', '.fixed-action-btn.toolbar > a', function (e) { 5884 var $this = $(this); 5885 var $menu = $this.parent(); 5886 FABtoToolbar($menu); 5887 }); 5888 }); 5889 5890 $.fn.extend({ 5891 openFAB: function () { 5892 openFABMenu($(this)); 5893 }, 5894 closeFAB: function () { 5895 closeFABMenu($(this)); 5896 }, 5897 openToolbar: function () { 5898 FABtoToolbar($(this)); 5899 }, 5900 closeToolbar: function () { 5901 toolbarToFAB($(this)); 5902 } 5903 }); 5904 5905 var openFABMenu = function (btn) { 5906 var $this = btn; 5907 if ($this.hasClass('active') === false) { 5908 5909 // Get direction option 5910 var horizontal = $this.hasClass('horizontal'); 5911 var offsetY, offsetX; 5912 5913 if (horizontal === true) { 5914 offsetX = 40; 5915 } else { 5916 offsetY = 40; 5917 } 5918 5919 $this.addClass('active'); 5920 $this.find('ul .btn-floating').velocity({ scaleY: ".4", scaleX: ".4", translateY: offsetY + 'px', translateX: offsetX + 'px' }, { duration: 0 }); 5921 5922 var time = 0; 5923 $this.find('ul .btn-floating').reverse().each(function () { 5924 $(this).velocity({ opacity: "1", scaleX: "1", scaleY: "1", translateY: "0", translateX: '0' }, { duration: 80, delay: time }); 5925 time += 40; 5926 }); 5927 } 5928 }; 5929 5930 var closeFABMenu = function (btn) { 5931 var $this = btn; 5932 // Get direction option 5933 var horizontal = $this.hasClass('horizontal'); 5934 var offsetY, offsetX; 5935 5936 if (horizontal === true) { 5937 offsetX = 40; 5938 } else { 5939 offsetY = 40; 5940 } 5941 5942 $this.removeClass('active'); 5943 var time = 0; 5944 $this.find('ul .btn-floating').velocity("stop", true); 5945 $this.find('ul .btn-floating').velocity({ opacity: "0", scaleX: ".4", scaleY: ".4", translateY: offsetY + 'px', translateX: offsetX + 'px' }, { duration: 80 }); 5946 }; 5947 5948 /** 5949 * Transform FAB into toolbar 5950 * @param {Object} object jQuery object 5951 */ 5952 var FABtoToolbar = function (btn) { 5953 if (btn.attr('data-open') === "true") { 5954 return; 5955 } 5956 5957 var offsetX, offsetY, scaleFactor; 5958 var windowWidth = window.innerWidth; 5959 var windowHeight = window.innerHeight; 5960 var btnRect = btn[0].getBoundingClientRect(); 5961 var anchor = btn.find('> a').first(); 5962 var menu = btn.find('> ul').first(); 5963 var backdrop = $('<div class="fab-backdrop"></div>'); 5964 var fabColor = anchor.css('background-color'); 5965 anchor.append(backdrop); 5966 5967 offsetX = btnRect.left - windowWidth / 2 + btnRect.width / 2; 5968 offsetY = windowHeight - btnRect.bottom; 5969 scaleFactor = windowWidth / backdrop.width(); 5970 btn.attr('data-origin-bottom', btnRect.bottom); 5971 btn.attr('data-origin-left', btnRect.left); 5972 btn.attr('data-origin-width', btnRect.width); 5973 5974 // Set initial state 5975 btn.addClass('active'); 5976 btn.attr('data-open', true); 5977 btn.css({ 5978 'text-align': 'center', 5979 width: '100%', 5980 bottom: 0, 5981 left: 0, 5982 transform: 'translateX(' + offsetX + 'px)', 5983 transition: 'none' 5984 }); 5985 anchor.css({ 5986 transform: 'translateY(' + -offsetY + 'px)', 5987 transition: 'none' 5988 }); 5989 backdrop.css({ 5990 'background-color': fabColor 5991 }); 5992 5993 setTimeout(function () { 5994 btn.css({ 5995 transform: '', 5996 transition: 'transform .2s cubic-bezier(0.550, 0.085, 0.680, 0.530), background-color 0s linear .2s' 5997 }); 5998 anchor.css({ 5999 overflow: 'visible', 6000 transform: '', 6001 transition: 'transform .2s' 6002 }); 6003 6004 setTimeout(function () { 6005 btn.css({ 6006 overflow: 'hidden', 6007 'background-color': fabColor 6008 }); 6009 backdrop.css({ 6010 transform: 'scale(' + scaleFactor + ')', 6011 transition: 'transform .2s cubic-bezier(0.550, 0.055, 0.675, 0.190)' 6012 }); 6013 menu.find('> li > a').css({ 6014 opacity: 1 6015 }); 6016 6017 // Scroll to close. 6018 $(window).on('scroll.fabToolbarClose', function () { 6019 toolbarToFAB(btn); 6020 $(window).off('scroll.fabToolbarClose'); 6021 $(document).off('click.fabToolbarClose'); 6022 }); 6023 6024 $(document).on('click.fabToolbarClose', function (e) { 6025 if (!$(e.target).closest(menu).length) { 6026 toolbarToFAB(btn); 6027 $(window).off('scroll.fabToolbarClose'); 6028 $(document).off('click.fabToolbarClose'); 6029 } 6030 }); 6031 }, 100); 6032 }, 0); 6033 }; 6034 6035 /** 6036 * Transform toolbar back into FAB 6037 * @param {Object} object jQuery object 6038 */ 6039 var toolbarToFAB = function (btn) { 6040 if (btn.attr('data-open') !== "true") { 6041 return; 6042 } 6043 6044 var offsetX, offsetY, scaleFactor; 6045 var windowWidth = window.innerWidth; 6046 var windowHeight = window.innerHeight; 6047 var btnWidth = btn.attr('data-origin-width'); 6048 var btnBottom = btn.attr('data-origin-bottom'); 6049 var btnLeft = btn.attr('data-origin-left'); 6050 var anchor = btn.find('> .btn-floating').first(); 6051 var menu = btn.find('> ul').first(); 6052 var backdrop = btn.find('.fab-backdrop'); 6053 var fabColor = anchor.css('background-color'); 6054 6055 offsetX = btnLeft - windowWidth / 2 + btnWidth / 2; 6056 offsetY = windowHeight - btnBottom; 6057 scaleFactor = windowWidth / backdrop.width(); 6058 6059 // Hide backdrop 6060 btn.removeClass('active'); 6061 btn.attr('data-open', false); 6062 btn.css({ 6063 'background-color': 'transparent', 6064 transition: 'none' 6065 }); 6066 anchor.css({ 6067 transition: 'none' 6068 }); 6069 backdrop.css({ 6070 transform: 'scale(0)', 6071 'background-color': fabColor 6072 }); 6073 menu.find('> li > a').css({ 6074 opacity: '' 6075 }); 6076 6077 setTimeout(function () { 6078 backdrop.remove(); 6079 6080 // Set initial state. 6081 btn.css({ 6082 'text-align': '', 6083 width: '', 6084 bottom: '', 6085 left: '', 6086 overflow: '', 6087 'background-color': '', 6088 transform: 'translate3d(' + -offsetX + 'px,0,0)' 6089 }); 6090 anchor.css({ 6091 overflow: '', 6092 transform: 'translate3d(0,' + offsetY + 'px,0)' 6093 }); 6094 6095 setTimeout(function () { 6096 btn.css({ 6097 transform: 'translate3d(0,0,0)', 6098 transition: 'transform .2s' 6099 }); 6100 anchor.css({ 6101 transform: 'translate3d(0,0,0)', 6102 transition: 'transform .2s cubic-bezier(0.550, 0.055, 0.675, 0.190)' 6103 }); 6104 }, 20); 6105 }, 200); 6106 }; 6107 })(jQuery); 6108 ;(function ($) { 6109 // Image transition function 6110 Materialize.fadeInImage = function (selectorOrEl) { 6111 var element; 6112 if (typeof selectorOrEl === 'string') { 6113 element = $(selectorOrEl); 6114 } else if (typeof selectorOrEl === 'object') { 6115 element = selectorOrEl; 6116 } else { 6117 return; 6118 } 6119 element.css({ opacity: 0 }); 6120 $(element).velocity({ opacity: 1 }, { 6121 duration: 650, 6122 queue: false, 6123 easing: 'easeOutSine' 6124 }); 6125 $(element).velocity({ opacity: 1 }, { 6126 duration: 1300, 6127 queue: false, 6128 easing: 'swing', 6129 step: function (now, fx) { 6130 fx.start = 100; 6131 var grayscale_setting = now / 100; 6132 var brightness_setting = 150 - (100 - now) / 1.75; 6133 6134 if (brightness_setting < 100) { 6135 brightness_setting = 100; 6136 } 6137 if (now >= 0) { 6138 $(this).css({ 6139 "-webkit-filter": "grayscale(" + grayscale_setting + ")" + "brightness(" + brightness_setting + "%)", 6140 "filter": "grayscale(" + grayscale_setting + ")" + "brightness(" + brightness_setting + "%)" 6141 }); 6142 } 6143 } 6144 }); 6145 }; 6146 6147 // Horizontal staggered list 6148 Materialize.showStaggeredList = function (selectorOrEl) { 6149 var element; 6150 if (typeof selectorOrEl === 'string') { 6151 element = $(selectorOrEl); 6152 } else if (typeof selectorOrEl === 'object') { 6153 element = selectorOrEl; 6154 } else { 6155 return; 6156 } 6157 var time = 0; 6158 element.find('li').velocity({ translateX: "-100px" }, { duration: 0 }); 6159 6160 element.find('li').each(function () { 6161 $(this).velocity({ opacity: "1", translateX: "0" }, { duration: 800, delay: time, easing: [60, 10] }); 6162 time += 120; 6163 }); 6164 }; 6165 6166 $(document).ready(function () { 6167 // Hardcoded .staggered-list scrollFire 6168 // var staggeredListOptions = []; 6169 // $('ul.staggered-list').each(function (i) { 6170 6171 // var label = 'scrollFire-' + i; 6172 // $(this).addClass(label); 6173 // staggeredListOptions.push( 6174 // {selector: 'ul.staggered-list.' + label, 6175 // offset: 200, 6176 // callback: 'showStaggeredList("ul.staggered-list.' + label + '")'}); 6177 // }); 6178 // scrollFire(staggeredListOptions); 6179 6180 // HammerJS, Swipe navigation 6181 6182 // Touch Event 6183 var swipeLeft = false; 6184 var swipeRight = false; 6185 6186 // Dismissible Collections 6187 $('.dismissable').each(function () { 6188 $(this).hammer({ 6189 prevent_default: false 6190 }).on('pan', function (e) { 6191 if (e.gesture.pointerType === "touch") { 6192 var $this = $(this); 6193 var direction = e.gesture.direction; 6194 var x = e.gesture.deltaX; 6195 var velocityX = e.gesture.velocityX; 6196 6197 $this.velocity({ translateX: x 6198 }, { duration: 50, queue: false, easing: 'easeOutQuad' }); 6199 6200 // Swipe Left 6201 if (direction === 4 && (x > $this.innerWidth() / 2 || velocityX < -0.75)) { 6202 swipeLeft = true; 6203 } 6204 6205 // Swipe Right 6206 if (direction === 2 && (x < -1 * $this.innerWidth() / 2 || velocityX > 0.75)) { 6207 swipeRight = true; 6208 } 6209 } 6210 }).on('panend', function (e) { 6211 // Reset if collection is moved back into original position 6212 if (Math.abs(e.gesture.deltaX) < $(this).innerWidth() / 2) { 6213 swipeRight = false; 6214 swipeLeft = false; 6215 } 6216 6217 if (e.gesture.pointerType === "touch") { 6218 var $this = $(this); 6219 if (swipeLeft || swipeRight) { 6220 var fullWidth; 6221 if (swipeLeft) { 6222 fullWidth = $this.innerWidth(); 6223 } else { 6224 fullWidth = -1 * $this.innerWidth(); 6225 } 6226 6227 $this.velocity({ translateX: fullWidth 6228 }, { duration: 100, queue: false, easing: 'easeOutQuad', complete: function () { 6229 $this.css('border', 'none'); 6230 $this.velocity({ height: 0, padding: 0 6231 }, { duration: 200, queue: false, easing: 'easeOutQuad', complete: function () { 6232 $this.remove(); 6233 } 6234 }); 6235 } 6236 }); 6237 } else { 6238 $this.velocity({ translateX: 0 6239 }, { duration: 100, queue: false, easing: 'easeOutQuad' }); 6240 } 6241 swipeLeft = false; 6242 swipeRight = false; 6243 } 6244 }); 6245 }); 6246 6247 // time = 0 6248 // // Vertical Staggered list 6249 // $('ul.staggered-list.vertical li').velocity( 6250 // { translateY: "100px"}, 6251 // { duration: 0 }); 6252 6253 // $('ul.staggered-list.vertical li').each(function() { 6254 // $(this).velocity( 6255 // { opacity: "1", translateY: "0"}, 6256 // { duration: 800, delay: time, easing: [60, 25] }); 6257 // time += 120; 6258 // }); 6259 6260 // // Fade in and Scale 6261 // $('.fade-in.scale').velocity( 6262 // { scaleX: .4, scaleY: .4, translateX: -600}, 6263 // { duration: 0}); 6264 // $('.fade-in').each(function() { 6265 // $(this).velocity( 6266 // { opacity: "1", scaleX: 1, scaleY: 1, translateX: 0}, 6267 // { duration: 800, easing: [60, 10] }); 6268 // }); 6269 }); 6270 })(jQuery); 6271 ;(function ($) { 6272 6273 var scrollFireEventsHandled = false; 6274 6275 // Input: Array of JSON objects {selector, offset, callback} 6276 Materialize.scrollFire = function (options) { 6277 var onScroll = function () { 6278 var windowScroll = window.pageYOffset + window.innerHeight; 6279 6280 for (var i = 0; i < options.length; i++) { 6281 // Get options from each line 6282 var value = options[i]; 6283 var selector = value.selector, 6284 offset = value.offset, 6285 callback = value.callback; 6286 6287 var currentElement = document.querySelector(selector); 6288 if (currentElement !== null) { 6289 var elementOffset = currentElement.getBoundingClientRect().top + window.pageYOffset; 6290 6291 if (windowScroll > elementOffset + offset) { 6292 if (value.done !== true) { 6293 if (typeof callback === 'function') { 6294 callback.call(this, currentElement); 6295 } else if (typeof callback === 'string') { 6296 var callbackFunc = new Function(callback); 6297 callbackFunc(currentElement); 6298 } 6299 value.done = true; 6300 } 6301 } 6302 } 6303 } 6304 }; 6305 6306 var throttledScroll = Materialize.throttle(function () { 6307 onScroll(); 6308 }, options.throttle || 100); 6309 6310 if (!scrollFireEventsHandled) { 6311 window.addEventListener("scroll", throttledScroll); 6312 window.addEventListener("resize", throttledScroll); 6313 scrollFireEventsHandled = true; 6314 } 6315 6316 // perform a scan once, after current execution context, and after dom is ready 6317 setTimeout(throttledScroll, 0); 6318 }; 6319 })(jQuery); 6320 ; /*! 6321 * pickadate.js v3.5.0, 2014/04/13 6322 * By Amsul, http://amsul.ca 6323 * Hosted on http://amsul.github.io/pickadate.js 6324 * Licensed under MIT 6325 */ 6326 6327 (function (factory) { 6328 6329 Materialize.Picker = factory(jQuery); 6330 })(function ($) { 6331 6332 var $window = $(window); 6333 var $document = $(document); 6334 var $html = $(document.documentElement); 6335 6336 /** 6337 * The picker constructor that creates a blank picker. 6338 */ 6339 function PickerConstructor(ELEMENT, NAME, COMPONENT, OPTIONS) { 6340 6341 // If there’s no element, return the picker constructor. 6342 if (!ELEMENT) return PickerConstructor; 6343 6344 var IS_DEFAULT_THEME = false, 6345 6346 6347 // The state of the picker. 6348 STATE = { 6349 id: ELEMENT.id || 'P' + Math.abs(~~(Math.random() * new Date())) 6350 }, 6351 6352 6353 // Merge the defaults and options passed. 6354 SETTINGS = COMPONENT ? $.extend(true, {}, COMPONENT.defaults, OPTIONS) : OPTIONS || {}, 6355 6356 6357 // Merge the default classes with the settings classes. 6358 CLASSES = $.extend({}, PickerConstructor.klasses(), SETTINGS.klass), 6359 6360 6361 // The element node wrapper into a jQuery object. 6362 $ELEMENT = $(ELEMENT), 6363 6364 6365 // Pseudo picker constructor. 6366 PickerInstance = function () { 6367 return this.start(); 6368 }, 6369 6370 6371 // The picker prototype. 6372 P = PickerInstance.prototype = { 6373 6374 constructor: PickerInstance, 6375 6376 $node: $ELEMENT, 6377 6378 /** 6379 * Initialize everything 6380 */ 6381 start: function () { 6382 6383 // If it’s already started, do nothing. 6384 if (STATE && STATE.start) return P; 6385 6386 // Update the picker states. 6387 STATE.methods = {}; 6388 STATE.start = true; 6389 STATE.open = false; 6390 STATE.type = ELEMENT.type; 6391 6392 // Confirm focus state, convert into text input to remove UA stylings, 6393 // and set as readonly to prevent keyboard popup. 6394 ELEMENT.autofocus = ELEMENT == getActiveElement(); 6395 ELEMENT.readOnly = !SETTINGS.editable; 6396 ELEMENT.id = ELEMENT.id || STATE.id; 6397 if (ELEMENT.type != 'text') { 6398 ELEMENT.type = 'text'; 6399 } 6400 6401 // Create a new picker component with the settings. 6402 P.component = new COMPONENT(P, SETTINGS); 6403 6404 // Create the picker root with a holder and then prepare it. 6405 P.$root = $(PickerConstructor._.node('div', createWrappedComponent(), CLASSES.picker, 'id="' + ELEMENT.id + '_root" tabindex="0"')); 6406 prepareElementRoot(); 6407 6408 // If there’s a format for the hidden input element, create the element. 6409 if (SETTINGS.formatSubmit) { 6410 prepareElementHidden(); 6411 } 6412 6413 // Prepare the input element. 6414 prepareElement(); 6415 6416 // Insert the root as specified in the settings. 6417 if (SETTINGS.container) $(SETTINGS.container).append(P.$root);else $ELEMENT.before(P.$root); 6418 6419 // Bind the default component and settings events. 6420 P.on({ 6421 start: P.component.onStart, 6422 render: P.component.onRender, 6423 stop: P.component.onStop, 6424 open: P.component.onOpen, 6425 close: P.component.onClose, 6426 set: P.component.onSet 6427 }).on({ 6428 start: SETTINGS.onStart, 6429 render: SETTINGS.onRender, 6430 stop: SETTINGS.onStop, 6431 open: SETTINGS.onOpen, 6432 close: SETTINGS.onClose, 6433 set: SETTINGS.onSet 6434 }); 6435 6436 // Once we’re all set, check the theme in use. 6437 IS_DEFAULT_THEME = isUsingDefaultTheme(P.$root.children()[0]); 6438 6439 // If the element has autofocus, open the picker. 6440 if (ELEMENT.autofocus) { 6441 P.open(); 6442 } 6443 6444 // Trigger queued the “start” and “render” events. 6445 return P.trigger('start').trigger('render'); 6446 }, //start 6447 6448 6449 /** 6450 * Render a new picker 6451 */ 6452 render: function (entireComponent) { 6453 6454 // Insert a new component holder in the root or box. 6455 if (entireComponent) P.$root.html(createWrappedComponent());else P.$root.find('.' + CLASSES.box).html(P.component.nodes(STATE.open)); 6456 6457 // Trigger the queued “render” events. 6458 return P.trigger('render'); 6459 }, //render 6460 6461 6462 /** 6463 * Destroy everything 6464 */ 6465 stop: function () { 6466 6467 // If it’s already stopped, do nothing. 6468 if (!STATE.start) return P; 6469 6470 // Then close the picker. 6471 P.close(); 6472 6473 // Remove the hidden field. 6474 if (P._hidden) { 6475 P._hidden.parentNode.removeChild(P._hidden); 6476 } 6477 6478 // Remove the root. 6479 P.$root.remove(); 6480 6481 // Remove the input class, remove the stored data, and unbind 6482 // the events (after a tick for IE - see `P.close`). 6483 $ELEMENT.removeClass(CLASSES.input).removeData(NAME); 6484 setTimeout(function () { 6485 $ELEMENT.off('.' + STATE.id); 6486 }, 0); 6487 6488 // Restore the element state 6489 ELEMENT.type = STATE.type; 6490 ELEMENT.readOnly = false; 6491 6492 // Trigger the queued “stop” events. 6493 P.trigger('stop'); 6494 6495 // Reset the picker states. 6496 STATE.methods = {}; 6497 STATE.start = false; 6498 6499 return P; 6500 }, //stop 6501 6502 6503 /** 6504 * Open up the picker 6505 */ 6506 open: function (dontGiveFocus) { 6507 6508 // If it’s already open, do nothing. 6509 if (STATE.open) return P; 6510 6511 // Add the “active” class. 6512 $ELEMENT.addClass(CLASSES.active); 6513 aria(ELEMENT, 'expanded', true); 6514 6515 // * A Firefox bug, when `html` has `overflow:hidden`, results in 6516 // killing transitions :(. So add the “opened” state on the next tick. 6517 // Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=625289 6518 setTimeout(function () { 6519 6520 // Add the “opened” class to the picker root. 6521 P.$root.addClass(CLASSES.opened); 6522 aria(P.$root[0], 'hidden', false); 6523 }, 0); 6524 6525 // If we have to give focus, bind the element and doc events. 6526 if (dontGiveFocus !== false) { 6527 6528 // Set it as open. 6529 STATE.open = true; 6530 6531 // Prevent the page from scrolling. 6532 if (IS_DEFAULT_THEME) { 6533 $html.css('overflow', 'hidden').css('padding-right', '+=' + getScrollbarWidth()); 6534 } 6535 6536 // Pass focus to the root element’s jQuery object. 6537 // * Workaround for iOS8 to bring the picker’s root into view. 6538 P.$root.eq(0).focus(); 6539 6540 // Bind the document events. 6541 $document.on('click.' + STATE.id + ' focusin.' + STATE.id, function (event) { 6542 6543 var target = event.target; 6544 6545 // If the target of the event is not the element, close the picker picker. 6546 // * Don’t worry about clicks or focusins on the root because those don’t bubble up. 6547 // Also, for Firefox, a click on an `option` element bubbles up directly 6548 // to the doc. So make sure the target wasn't the doc. 6549 // * In Firefox stopPropagation() doesn’t prevent right-click events from bubbling, 6550 // which causes the picker to unexpectedly close when right-clicking it. So make 6551 // sure the event wasn’t a right-click. 6552 if (target != ELEMENT && target != document && event.which != 3) { 6553 6554 // If the target was the holder that covers the screen, 6555 // keep the element focused to maintain tabindex. 6556 P.close(target === P.$root.children()[0]); 6557 } 6558 }).on('keydown.' + STATE.id, function (event) { 6559 6560 var 6561 // Get the keycode. 6562 keycode = event.keyCode, 6563 6564 6565 // Translate that to a selection change. 6566 keycodeToMove = P.component.key[keycode], 6567 6568 6569 // Grab the target. 6570 target = event.target; 6571 6572 // On escape, close the picker and give focus. 6573 if (keycode == 27) { 6574 P.close(true); 6575 } 6576 6577 // Check if there is a key movement or “enter” keypress on the element. 6578 else if (target == P.$root[0] && (keycodeToMove || keycode == 13)) { 6579 6580 // Prevent the default action to stop page movement. 6581 event.preventDefault(); 6582 6583 // Trigger the key movement action. 6584 if (keycodeToMove) { 6585 PickerConstructor._.trigger(P.component.key.go, P, [PickerConstructor._.trigger(keycodeToMove)]); 6586 } 6587 6588 // On “enter”, if the highlighted item isn’t disabled, set the value and close. 6589 else if (!P.$root.find('.' + CLASSES.highlighted).hasClass(CLASSES.disabled)) { 6590 P.set('select', P.component.item.highlight); 6591 if (SETTINGS.closeOnSelect) { 6592 P.close(true); 6593 } 6594 } 6595 } 6596 6597 // If the target is within the root and “enter” is pressed, 6598 // prevent the default action and trigger a click on the target instead. 6599 else if ($.contains(P.$root[0], target) && keycode == 13) { 6600 event.preventDefault(); 6601 target.click(); 6602 } 6603 }); 6604 } 6605 6606 // Trigger the queued “open” events. 6607 return P.trigger('open'); 6608 }, //open 6609 6610 6611 /** 6612 * Close the picker 6613 */ 6614 close: function (giveFocus) { 6615 6616 // If we need to give focus, do it before changing states. 6617 if (giveFocus) { 6618 // ....ah yes! It would’ve been incomplete without a crazy workaround for IE :| 6619 // The focus is triggered *after* the close has completed - causing it 6620 // to open again. So unbind and rebind the event at the next tick. 6621 P.$root.off('focus.toOpen').eq(0).focus(); 6622 setTimeout(function () { 6623 P.$root.on('focus.toOpen', handleFocusToOpenEvent); 6624 }, 0); 6625 } 6626 6627 // Remove the “active” class. 6628 $ELEMENT.removeClass(CLASSES.active); 6629 aria(ELEMENT, 'expanded', false); 6630 6631 // * A Firefox bug, when `html` has `overflow:hidden`, results in 6632 // killing transitions :(. So remove the “opened” state on the next tick. 6633 // Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=625289 6634 setTimeout(function () { 6635 6636 // Remove the “opened” and “focused” class from the picker root. 6637 P.$root.removeClass(CLASSES.opened + ' ' + CLASSES.focused); 6638 aria(P.$root[0], 'hidden', true); 6639 }, 0); 6640 6641 // If it’s already closed, do nothing more. 6642 if (!STATE.open) return P; 6643 6644 // Set it as closed. 6645 STATE.open = false; 6646 6647 // Allow the page to scroll. 6648 if (IS_DEFAULT_THEME) { 6649 $html.css('overflow', '').css('padding-right', '-=' + getScrollbarWidth()); 6650 } 6651 6652 // Unbind the document events. 6653 $document.off('.' + STATE.id); 6654 6655 // Trigger the queued “close” events. 6656 return P.trigger('close'); 6657 }, //close 6658 6659 6660 /** 6661 * Clear the values 6662 */ 6663 clear: function (options) { 6664 return P.set('clear', null, options); 6665 }, //clear 6666 6667 6668 /** 6669 * Set something 6670 */ 6671 set: function (thing, value, options) { 6672 6673 var thingItem, 6674 thingValue, 6675 thingIsObject = $.isPlainObject(thing), 6676 thingObject = thingIsObject ? thing : {}; 6677 6678 // Make sure we have usable options. 6679 options = thingIsObject && $.isPlainObject(value) ? value : options || {}; 6680 6681 if (thing) { 6682 6683 // If the thing isn’t an object, make it one. 6684 if (!thingIsObject) { 6685 thingObject[thing] = value; 6686 } 6687 6688 // Go through the things of items to set. 6689 for (thingItem in thingObject) { 6690 6691 // Grab the value of the thing. 6692 thingValue = thingObject[thingItem]; 6693 6694 // First, if the item exists and there’s a value, set it. 6695 if (thingItem in P.component.item) { 6696 if (thingValue === undefined) thingValue = null; 6697 P.component.set(thingItem, thingValue, options); 6698 } 6699 6700 // Then, check to update the element value and broadcast a change. 6701 if (thingItem == 'select' || thingItem == 'clear') { 6702 $ELEMENT.val(thingItem == 'clear' ? '' : P.get(thingItem, SETTINGS.format)).trigger('change'); 6703 } 6704 } 6705 6706 // Render a new picker. 6707 P.render(); 6708 } 6709 6710 // When the method isn’t muted, trigger queued “set” events and pass the `thingObject`. 6711 return options.muted ? P : P.trigger('set', thingObject); 6712 }, //set 6713 6714 6715 /** 6716 * Get something 6717 */ 6718 get: function (thing, format) { 6719 6720 // Make sure there’s something to get. 6721 thing = thing || 'value'; 6722 6723 // If a picker state exists, return that. 6724 if (STATE[thing] != null) { 6725 return STATE[thing]; 6726 } 6727 6728 // Return the submission value, if that. 6729 if (thing == 'valueSubmit') { 6730 if (P._hidden) { 6731 return P._hidden.value; 6732 } 6733 thing = 'value'; 6734 } 6735 6736 // Return the value, if that. 6737 if (thing == 'value') { 6738 return ELEMENT.value; 6739 } 6740 6741 // Check if a component item exists, return that. 6742 if (thing in P.component.item) { 6743 if (typeof format == 'string') { 6744 var thingValue = P.component.get(thing); 6745 return thingValue ? PickerConstructor._.trigger(P.component.formats.toString, P.component, [format, thingValue]) : ''; 6746 } 6747 return P.component.get(thing); 6748 } 6749 }, //get 6750 6751 6752 /** 6753 * Bind events on the things. 6754 */ 6755 on: function (thing, method, internal) { 6756 6757 var thingName, 6758 thingMethod, 6759 thingIsObject = $.isPlainObject(thing), 6760 thingObject = thingIsObject ? thing : {}; 6761 6762 if (thing) { 6763 6764 // If the thing isn’t an object, make it one. 6765 if (!thingIsObject) { 6766 thingObject[thing] = method; 6767 } 6768 6769 // Go through the things to bind to. 6770 for (thingName in thingObject) { 6771 6772 // Grab the method of the thing. 6773 thingMethod = thingObject[thingName]; 6774 6775 // If it was an internal binding, prefix it. 6776 if (internal) { 6777 thingName = '_' + thingName; 6778 } 6779 6780 // Make sure the thing methods collection exists. 6781 STATE.methods[thingName] = STATE.methods[thingName] || []; 6782 6783 // Add the method to the relative method collection. 6784 STATE.methods[thingName].push(thingMethod); 6785 } 6786 } 6787 6788 return P; 6789 }, //on 6790 6791 6792 /** 6793 * Unbind events on the things. 6794 */ 6795 off: function () { 6796 var i, 6797 thingName, 6798 names = arguments; 6799 for (i = 0, namesCount = names.length; i < namesCount; i += 1) { 6800 thingName = names[i]; 6801 if (thingName in STATE.methods) { 6802 delete STATE.methods[thingName]; 6803 } 6804 } 6805 return P; 6806 }, 6807 6808 /** 6809 * Fire off method events. 6810 */ 6811 trigger: function (name, data) { 6812 var _trigger = function (name) { 6813 var methodList = STATE.methods[name]; 6814 if (methodList) { 6815 methodList.map(function (method) { 6816 PickerConstructor._.trigger(method, P, [data]); 6817 }); 6818 } 6819 }; 6820 _trigger('_' + name); 6821 _trigger(name); 6822 return P; 6823 } //trigger 6824 //PickerInstance.prototype 6825 6826 6827 /** 6828 * Wrap the picker holder components together. 6829 */ 6830 };function createWrappedComponent() { 6831 6832 // Create a picker wrapper holder 6833 return PickerConstructor._.node('div', 6834 6835 // Create a picker wrapper node 6836 PickerConstructor._.node('div', 6837 6838 // Create a picker frame 6839 PickerConstructor._.node('div', 6840 6841 // Create a picker box node 6842 PickerConstructor._.node('div', 6843 6844 // Create the components nodes. 6845 P.component.nodes(STATE.open), 6846 6847 // The picker box class 6848 CLASSES.box), 6849 6850 // Picker wrap class 6851 CLASSES.wrap), 6852 6853 // Picker frame class 6854 CLASSES.frame), 6855 6856 // Picker holder class 6857 CLASSES.holder); //endreturn 6858 } //createWrappedComponent 6859 6860 6861 /** 6862 * Prepare the input element with all bindings. 6863 */ 6864 function prepareElement() { 6865 6866 $ELEMENT. 6867 6868 // Store the picker data by component name. 6869 data(NAME, P). 6870 6871 // Add the “input” class name. 6872 addClass(CLASSES.input). 6873 6874 // Remove the tabindex. 6875 attr('tabindex', -1). 6876 6877 // If there’s a `data-value`, update the value of the element. 6878 val($ELEMENT.data('value') ? P.get('select', SETTINGS.format) : ELEMENT.value); 6879 6880 // Only bind keydown events if the element isn’t editable. 6881 if (!SETTINGS.editable) { 6882 6883 $ELEMENT. 6884 6885 // On focus/click, focus onto the root to open it up. 6886 on('focus.' + STATE.id + ' click.' + STATE.id, function (event) { 6887 event.preventDefault(); 6888 P.$root.eq(0).focus(); 6889 }). 6890 6891 // Handle keyboard event based on the picker being opened or not. 6892 on('keydown.' + STATE.id, handleKeydownEvent); 6893 } 6894 6895 // Update the aria attributes. 6896 aria(ELEMENT, { 6897 haspopup: true, 6898 expanded: false, 6899 readonly: false, 6900 owns: ELEMENT.id + '_root' 6901 }); 6902 } 6903 6904 /** 6905 * Prepare the root picker element with all bindings. 6906 */ 6907 function prepareElementRoot() { 6908 6909 P.$root.on({ 6910 6911 // For iOS8. 6912 keydown: handleKeydownEvent, 6913 6914 // When something within the root is focused, stop from bubbling 6915 // to the doc and remove the “focused” state from the root. 6916 focusin: function (event) { 6917 P.$root.removeClass(CLASSES.focused); 6918 event.stopPropagation(); 6919 }, 6920 6921 // When something within the root holder is clicked, stop it 6922 // from bubbling to the doc. 6923 'mousedown click': function (event) { 6924 6925 var target = event.target; 6926 6927 // Make sure the target isn’t the root holder so it can bubble up. 6928 if (target != P.$root.children()[0]) { 6929 6930 event.stopPropagation(); 6931 6932 // * For mousedown events, cancel the default action in order to 6933 // prevent cases where focus is shifted onto external elements 6934 // when using things like jQuery mobile or MagnificPopup (ref: #249 & #120). 6935 // Also, for Firefox, don’t prevent action on the `option` element. 6936 if (event.type == 'mousedown' && !$(target).is('input, select, textarea, button, option')) { 6937 6938 event.preventDefault(); 6939 6940 // Re-focus onto the root so that users can click away 6941 // from elements focused within the picker. 6942 P.$root.eq(0).focus(); 6943 } 6944 } 6945 } 6946 }). 6947 6948 // Add/remove the “target” class on focus and blur. 6949 on({ 6950 focus: function () { 6951 $ELEMENT.addClass(CLASSES.target); 6952 }, 6953 blur: function () { 6954 $ELEMENT.removeClass(CLASSES.target); 6955 } 6956 }). 6957 6958 // Open the picker and adjust the root “focused” state 6959 on('focus.toOpen', handleFocusToOpenEvent). 6960 6961 // If there’s a click on an actionable element, carry out the actions. 6962 on('click', '[data-pick], [data-nav], [data-clear], [data-close]', function () { 6963 6964 var $target = $(this), 6965 targetData = $target.data(), 6966 targetDisabled = $target.hasClass(CLASSES.navDisabled) || $target.hasClass(CLASSES.disabled), 6967 6968 6969 // * For IE, non-focusable elements can be active elements as well 6970 // (http://stackoverflow.com/a/2684561). 6971 activeElement = getActiveElement(); 6972 activeElement = activeElement && (activeElement.type || activeElement.href) && activeElement; 6973 6974 // If it’s disabled or nothing inside is actively focused, re-focus the element. 6975 if (targetDisabled || activeElement && !$.contains(P.$root[0], activeElement)) { 6976 P.$root.eq(0).focus(); 6977 } 6978 6979 // If something is superficially changed, update the `highlight` based on the `nav`. 6980 if (!targetDisabled && targetData.nav) { 6981 P.set('highlight', P.component.item.highlight, { nav: targetData.nav }); 6982 } 6983 6984 // If something is picked, set `select` then close with focus. 6985 else if (!targetDisabled && 'pick' in targetData) { 6986 P.set('select', targetData.pick); 6987 if (SETTINGS.closeOnSelect) { 6988 P.close(true); 6989 } 6990 } 6991 6992 // If a “clear” button is pressed, empty the values and close with focus. 6993 else if (targetData.clear) { 6994 P.clear(); 6995 if (SETTINGS.closeOnSelect) { 6996 P.close(true); 6997 } 6998 } else if (targetData.close) { 6999 P.close(true); 7000 } 7001 }); //P.$root 7002 7003 aria(P.$root[0], 'hidden', true); 7004 } 7005 7006 /** 7007 * Prepare the hidden input element along with all bindings. 7008 */ 7009 function prepareElementHidden() { 7010 7011 var name; 7012 7013 if (SETTINGS.hiddenName === true) { 7014 name = ELEMENT.name; 7015 ELEMENT.name = ''; 7016 } else { 7017 name = [typeof SETTINGS.hiddenPrefix == 'string' ? SETTINGS.hiddenPrefix : '', typeof SETTINGS.hiddenSuffix == 'string' ? SETTINGS.hiddenSuffix : '_submit']; 7018 name = name[0] + ELEMENT.name + name[1]; 7019 } 7020 7021 P._hidden = $('<input ' + 'type=hidden ' + 7022 7023 // Create the name using the original input’s with a prefix and suffix. 7024 'name="' + name + '"' + ( 7025 7026 // If the element has a value, set the hidden value as well. 7027 $ELEMENT.data('value') || ELEMENT.value ? ' value="' + P.get('select', SETTINGS.formatSubmit) + '"' : '') + '>')[0]; 7028 7029 $ELEMENT. 7030 7031 // If the value changes, update the hidden input with the correct format. 7032 on('change.' + STATE.id, function () { 7033 P._hidden.value = ELEMENT.value ? P.get('select', SETTINGS.formatSubmit) : ''; 7034 }); 7035 7036 // Insert the hidden input as specified in the settings. 7037 if (SETTINGS.container) $(SETTINGS.container).append(P._hidden);else $ELEMENT.before(P._hidden); 7038 } 7039 7040 // For iOS8. 7041 function handleKeydownEvent(event) { 7042 7043 var keycode = event.keyCode, 7044 7045 7046 // Check if one of the delete keys was pressed. 7047 isKeycodeDelete = /^(8|46)$/.test(keycode); 7048 7049 // For some reason IE clears the input value on “escape”. 7050 if (keycode == 27) { 7051 P.close(); 7052 return false; 7053 } 7054 7055 // Check if `space` or `delete` was pressed or the picker is closed with a key movement. 7056 if (keycode == 32 || isKeycodeDelete || !STATE.open && P.component.key[keycode]) { 7057 7058 // Prevent it from moving the page and bubbling to doc. 7059 event.preventDefault(); 7060 event.stopPropagation(); 7061 7062 // If `delete` was pressed, clear the values and close the picker. 7063 // Otherwise open the picker. 7064 if (isKeycodeDelete) { 7065 P.clear().close(); 7066 } else { 7067 P.open(); 7068 } 7069 } 7070 } 7071 7072 // Separated for IE 7073 function handleFocusToOpenEvent(event) { 7074 7075 // Stop the event from propagating to the doc. 7076 event.stopPropagation(); 7077 7078 // If it’s a focus event, add the “focused” class to the root. 7079 if (event.type == 'focus') { 7080 P.$root.addClass(CLASSES.focused); 7081 } 7082 7083 // And then finally open the picker. 7084 P.open(); 7085 } 7086 7087 // Return a new picker instance. 7088 return new PickerInstance(); 7089 } //PickerConstructor 7090 7091 7092 /** 7093 * The default classes and prefix to use for the HTML classes. 7094 */ 7095 PickerConstructor.klasses = function (prefix) { 7096 prefix = prefix || 'picker'; 7097 return { 7098 7099 picker: prefix, 7100 opened: prefix + '--opened', 7101 focused: prefix + '--focused', 7102 7103 input: prefix + '__input', 7104 active: prefix + '__input--active', 7105 target: prefix + '__input--target', 7106 7107 holder: prefix + '__holder', 7108 7109 frame: prefix + '__frame', 7110 wrap: prefix + '__wrap', 7111 7112 box: prefix + '__box' 7113 }; 7114 }; //PickerConstructor.klasses 7115 7116 7117 /** 7118 * Check if the default theme is being used. 7119 */ 7120 function isUsingDefaultTheme(element) { 7121 7122 var theme, 7123 prop = 'position'; 7124 7125 // For IE. 7126 if (element.currentStyle) { 7127 theme = element.currentStyle[prop]; 7128 } 7129 7130 // For normal browsers. 7131 else if (window.getComputedStyle) { 7132 theme = getComputedStyle(element)[prop]; 7133 } 7134 7135 return theme == 'fixed'; 7136 } 7137 7138 /** 7139 * Get the width of the browser’s scrollbar. 7140 * Taken from: https://github.com/VodkaBears/Remodal/blob/master/src/jquery.remodal.js 7141 */ 7142 function getScrollbarWidth() { 7143 7144 if ($html.height() <= $window.height()) { 7145 return 0; 7146 } 7147 7148 var $outer = $('<div style="visibility:hidden;width:100px" />').appendTo('body'); 7149 7150 // Get the width without scrollbars. 7151 var widthWithoutScroll = $outer[0].offsetWidth; 7152 7153 // Force adding scrollbars. 7154 $outer.css('overflow', 'scroll'); 7155 7156 // Add the inner div. 7157 var $inner = $('<div style="width:100%" />').appendTo($outer); 7158 7159 // Get the width with scrollbars. 7160 var widthWithScroll = $inner[0].offsetWidth; 7161 7162 // Remove the divs. 7163 $outer.remove(); 7164 7165 // Return the difference between the widths. 7166 return widthWithoutScroll - widthWithScroll; 7167 } 7168 7169 /** 7170 * PickerConstructor helper methods. 7171 */ 7172 PickerConstructor._ = { 7173 7174 /** 7175 * Create a group of nodes. Expects: 7176 * ` 7177 { 7178 min: {Integer}, 7179 max: {Integer}, 7180 i: {Integer}, 7181 node: {String}, 7182 item: {Function} 7183 } 7184 * ` 7185 */ 7186 group: function (groupObject) { 7187 7188 var 7189 // Scope for the looped object 7190 loopObjectScope, 7191 7192 7193 // Create the nodes list 7194 nodesList = '', 7195 7196 7197 // The counter starts from the `min` 7198 counter = PickerConstructor._.trigger(groupObject.min, groupObject); 7199 7200 // Loop from the `min` to `max`, incrementing by `i` 7201 for (; counter <= PickerConstructor._.trigger(groupObject.max, groupObject, [counter]); counter += groupObject.i) { 7202 7203 // Trigger the `item` function within scope of the object 7204 loopObjectScope = PickerConstructor._.trigger(groupObject.item, groupObject, [counter]); 7205 7206 // Splice the subgroup and create nodes out of the sub nodes 7207 nodesList += PickerConstructor._.node(groupObject.node, loopObjectScope[0], // the node 7208 loopObjectScope[1], // the classes 7209 loopObjectScope[2] // the attributes 7210 ); 7211 } 7212 7213 // Return the list of nodes 7214 return nodesList; 7215 }, //group 7216 7217 7218 /** 7219 * Create a dom node string 7220 */ 7221 node: function (wrapper, item, klass, attribute) { 7222 7223 // If the item is false-y, just return an empty string 7224 if (!item) return ''; 7225 7226 // If the item is an array, do a join 7227 item = $.isArray(item) ? item.join('') : item; 7228 7229 // Check for the class 7230 klass = klass ? ' class="' + klass + '"' : ''; 7231 7232 // Check for any attributes 7233 attribute = attribute ? ' ' + attribute : ''; 7234 7235 // Return the wrapped item 7236 return '<' + wrapper + klass + attribute + '>' + item + '</' + wrapper + '>'; 7237 }, //node 7238 7239 7240 /** 7241 * Lead numbers below 10 with a zero. 7242 */ 7243 lead: function (number) { 7244 return (number < 10 ? '0' : '') + number; 7245 }, 7246 7247 /** 7248 * Trigger a function otherwise return the value. 7249 */ 7250 trigger: function (callback, scope, args) { 7251 return typeof callback == 'function' ? callback.apply(scope, args || []) : callback; 7252 }, 7253 7254 /** 7255 * If the second character is a digit, length is 2 otherwise 1. 7256 */ 7257 digits: function (string) { 7258 return (/\d/.test(string[1]) ? 2 : 1 7259 ); 7260 }, 7261 7262 /** 7263 * Tell if something is a date object. 7264 */ 7265 isDate: function (value) { 7266 return {}.toString.call(value).indexOf('Date') > -1 && this.isInteger(value.getDate()); 7267 }, 7268 7269 /** 7270 * Tell if something is an integer. 7271 */ 7272 isInteger: function (value) { 7273 return {}.toString.call(value).indexOf('Number') > -1 && value % 1 === 0; 7274 }, 7275 7276 /** 7277 * Create ARIA attribute strings. 7278 */ 7279 ariaAttr: ariaAttr //PickerConstructor._ 7280 7281 7282 /** 7283 * Extend the picker with a component and defaults. 7284 */ 7285 };PickerConstructor.extend = function (name, Component) { 7286 7287 // Extend jQuery. 7288 $.fn[name] = function (options, action) { 7289 7290 // Grab the component data. 7291 var componentData = this.data(name); 7292 7293 // If the picker is requested, return the data object. 7294 if (options == 'picker') { 7295 return componentData; 7296 } 7297 7298 // If the component data exists and `options` is a string, carry out the action. 7299 if (componentData && typeof options == 'string') { 7300 return PickerConstructor._.trigger(componentData[options], componentData, [action]); 7301 } 7302 7303 // Otherwise go through each matched element and if the component 7304 // doesn’t exist, create a new picker using `this` element 7305 // and merging the defaults and options with a deep copy. 7306 return this.each(function () { 7307 var $this = $(this); 7308 if (!$this.data(name)) { 7309 new PickerConstructor(this, name, Component, options); 7310 } 7311 }); 7312 }; 7313 7314 // Set the defaults. 7315 $.fn[name].defaults = Component.defaults; 7316 }; //PickerConstructor.extend 7317 7318 7319 function aria(element, attribute, value) { 7320 if ($.isPlainObject(attribute)) { 7321 for (var key in attribute) { 7322 ariaSet(element, key, attribute[key]); 7323 } 7324 } else { 7325 ariaSet(element, attribute, value); 7326 } 7327 } 7328 function ariaSet(element, attribute, value) { 7329 element.setAttribute((attribute == 'role' ? '' : 'aria-') + attribute, value); 7330 } 7331 function ariaAttr(attribute, data) { 7332 if (!$.isPlainObject(attribute)) { 7333 attribute = { attribute: data }; 7334 } 7335 data = ''; 7336 for (var key in attribute) { 7337 var attr = (key == 'role' ? '' : 'aria-') + key, 7338 attrVal = attribute[key]; 7339 data += attrVal == null ? '' : attr + '="' + attribute[key] + '"'; 7340 } 7341 return data; 7342 } 7343 7344 // IE8 bug throws an error for activeElements within iframes. 7345 function getActiveElement() { 7346 try { 7347 return document.activeElement; 7348 } catch (err) {} 7349 } 7350 7351 // Expose the picker constructor. 7352 return PickerConstructor; 7353 }); 7354 ; /*! 7355 * Date picker for pickadate.js v3.5.0 7356 * http://amsul.github.io/pickadate.js/date.htm 7357 */ 7358 7359 (function (factory) { 7360 factory(Materialize.Picker, jQuery); 7361 })(function (Picker, $) { 7362 7363 /** 7364 * Globals and constants 7365 */ 7366 var DAYS_IN_WEEK = 7, 7367 WEEKS_IN_CALENDAR = 6, 7368 _ = Picker._; 7369 7370 /** 7371 * The date picker constructor 7372 */ 7373 function DatePicker(picker, settings) { 7374 7375 var calendar = this, 7376 element = picker.$node[0], 7377 elementValue = element.value, 7378 elementDataValue = picker.$node.data('value'), 7379 valueString = elementDataValue || elementValue, 7380 formatString = elementDataValue ? settings.formatSubmit : settings.format, 7381 isRTL = function () { 7382 7383 return element.currentStyle ? 7384 7385 // For IE. 7386 element.currentStyle.direction == 'rtl' : 7387 7388 // For normal browsers. 7389 getComputedStyle(picker.$root[0]).direction == 'rtl'; 7390 }; 7391 7392 calendar.settings = settings; 7393 calendar.$node = picker.$node; 7394 7395 // The queue of methods that will be used to build item objects. 7396 calendar.queue = { 7397 min: 'measure create', 7398 max: 'measure create', 7399 now: 'now create', 7400 select: 'parse create validate', 7401 highlight: 'parse navigate create validate', 7402 view: 'parse create validate viewset', 7403 disable: 'deactivate', 7404 enable: 'activate' 7405 7406 // The component's item object. 7407 };calendar.item = {}; 7408 7409 calendar.item.clear = null; 7410 calendar.item.disable = (settings.disable || []).slice(0); 7411 calendar.item.enable = -function (collectionDisabled) { 7412 return collectionDisabled[0] === true ? collectionDisabled.shift() : -1; 7413 }(calendar.item.disable); 7414 7415 calendar.set('min', settings.min).set('max', settings.max).set('now'); 7416 7417 // When there’s a value, set the `select`, which in turn 7418 // also sets the `highlight` and `view`. 7419 if (valueString) { 7420 calendar.set('select', valueString, { format: formatString }); 7421 } 7422 7423 // If there’s no value, default to highlighting “today”. 7424 else { 7425 calendar.set('select', null).set('highlight', calendar.item.now); 7426 } 7427 7428 // The keycode to movement mapping. 7429 calendar.key = { 7430 40: 7, // Down 7431 38: -7, // Up 7432 39: function () { 7433 return isRTL() ? -1 : 1; 7434 }, // Right 7435 37: function () { 7436 return isRTL() ? 1 : -1; 7437 }, // Left 7438 go: function (timeChange) { 7439 var highlightedObject = calendar.item.highlight, 7440 targetDate = new Date(highlightedObject.year, highlightedObject.month, highlightedObject.date + timeChange); 7441 calendar.set('highlight', targetDate, { interval: timeChange }); 7442 this.render(); 7443 } 7444 7445 // Bind some picker events. 7446 };picker.on('render', function () { 7447 picker.$root.find('.' + settings.klass.selectMonth).on('change', function () { 7448 var value = this.value; 7449 if (value) { 7450 picker.set('highlight', [picker.get('view').year, value, picker.get('highlight').date]); 7451 picker.$root.find('.' + settings.klass.selectMonth).trigger('focus'); 7452 } 7453 }); 7454 picker.$root.find('.' + settings.klass.selectYear).on('change', function () { 7455 var value = this.value; 7456 if (value) { 7457 picker.set('highlight', [value, picker.get('view').month, picker.get('highlight').date]); 7458 picker.$root.find('.' + settings.klass.selectYear).trigger('focus'); 7459 } 7460 }); 7461 }, 1).on('open', function () { 7462 var includeToday = ''; 7463 if (calendar.disabled(calendar.get('now'))) { 7464 includeToday = ':not(.' + settings.klass.buttonToday + ')'; 7465 } 7466 picker.$root.find('button' + includeToday + ', select').attr('disabled', false); 7467 }, 1).on('close', function () { 7468 picker.$root.find('button, select').attr('disabled', true); 7469 }, 1); 7470 } //DatePicker 7471 7472 7473 /** 7474 * Set a datepicker item object. 7475 */ 7476 DatePicker.prototype.set = function (type, value, options) { 7477 7478 var calendar = this, 7479 calendarItem = calendar.item; 7480 7481 // If the value is `null` just set it immediately. 7482 if (value === null) { 7483 if (type == 'clear') type = 'select'; 7484 calendarItem[type] = value; 7485 return calendar; 7486 } 7487 7488 // Otherwise go through the queue of methods, and invoke the functions. 7489 // Update this as the time unit, and set the final value as this item. 7490 // * In the case of `enable`, keep the queue but set `disable` instead. 7491 // And in the case of `flip`, keep the queue but set `enable` instead. 7492 calendarItem[type == 'enable' ? 'disable' : type == 'flip' ? 'enable' : type] = calendar.queue[type].split(' ').map(function (method) { 7493 value = calendar[method](type, value, options); 7494 return value; 7495 }).pop(); 7496 7497 // Check if we need to cascade through more updates. 7498 if (type == 'select') { 7499 calendar.set('highlight', calendarItem.select, options); 7500 } else if (type == 'highlight') { 7501 calendar.set('view', calendarItem.highlight, options); 7502 } else if (type.match(/^(flip|min|max|disable|enable)$/)) { 7503 if (calendarItem.select && calendar.disabled(calendarItem.select)) { 7504 calendar.set('select', calendarItem.select, options); 7505 } 7506 if (calendarItem.highlight && calendar.disabled(calendarItem.highlight)) { 7507 calendar.set('highlight', calendarItem.highlight, options); 7508 } 7509 } 7510 7511 return calendar; 7512 }; //DatePicker.prototype.set 7513 7514 7515 /** 7516 * Get a datepicker item object. 7517 */ 7518 DatePicker.prototype.get = function (type) { 7519 return this.item[type]; 7520 }; //DatePicker.prototype.get 7521 7522 7523 /** 7524 * Create a picker date object. 7525 */ 7526 DatePicker.prototype.create = function (type, value, options) { 7527 7528 var isInfiniteValue, 7529 calendar = this; 7530 7531 // If there’s no value, use the type as the value. 7532 value = value === undefined ? type : value; 7533 7534 // If it’s infinity, update the value. 7535 if (value == -Infinity || value == Infinity) { 7536 isInfiniteValue = value; 7537 } 7538 7539 // If it’s an object, use the native date object. 7540 else if ($.isPlainObject(value) && _.isInteger(value.pick)) { 7541 value = value.obj; 7542 } 7543 7544 // If it’s an array, convert it into a date and make sure 7545 // that it’s a valid date – otherwise default to today. 7546 else if ($.isArray(value)) { 7547 value = new Date(value[0], value[1], value[2]); 7548 value = _.isDate(value) ? value : calendar.create().obj; 7549 } 7550 7551 // If it’s a number or date object, make a normalized date. 7552 else if (_.isInteger(value) || _.isDate(value)) { 7553 value = calendar.normalize(new Date(value), options); 7554 } 7555 7556 // If it’s a literal true or any other case, set it to now. 7557 else /*if ( value === true )*/{ 7558 value = calendar.now(type, value, options); 7559 } 7560 7561 // Return the compiled object. 7562 return { 7563 year: isInfiniteValue || value.getFullYear(), 7564 month: isInfiniteValue || value.getMonth(), 7565 date: isInfiniteValue || value.getDate(), 7566 day: isInfiniteValue || value.getDay(), 7567 obj: isInfiniteValue || value, 7568 pick: isInfiniteValue || value.getTime() 7569 }; 7570 }; //DatePicker.prototype.create 7571 7572 7573 /** 7574 * Create a range limit object using an array, date object, 7575 * literal “true”, or integer relative to another time. 7576 */ 7577 DatePicker.prototype.createRange = function (from, to) { 7578 7579 var calendar = this, 7580 createDate = function (date) { 7581 if (date === true || $.isArray(date) || _.isDate(date)) { 7582 return calendar.create(date); 7583 } 7584 return date; 7585 }; 7586 7587 // Create objects if possible. 7588 if (!_.isInteger(from)) { 7589 from = createDate(from); 7590 } 7591 if (!_.isInteger(to)) { 7592 to = createDate(to); 7593 } 7594 7595 // Create relative dates. 7596 if (_.isInteger(from) && $.isPlainObject(to)) { 7597 from = [to.year, to.month, to.date + from]; 7598 } else if (_.isInteger(to) && $.isPlainObject(from)) { 7599 to = [from.year, from.month, from.date + to]; 7600 } 7601 7602 return { 7603 from: createDate(from), 7604 to: createDate(to) 7605 }; 7606 }; //DatePicker.prototype.createRange 7607 7608 7609 /** 7610 * Check if a date unit falls within a date range object. 7611 */ 7612 DatePicker.prototype.withinRange = function (range, dateUnit) { 7613 range = this.createRange(range.from, range.to); 7614 return dateUnit.pick >= range.from.pick && dateUnit.pick <= range.to.pick; 7615 }; 7616 7617 /** 7618 * Check if two date range objects overlap. 7619 */ 7620 DatePicker.prototype.overlapRanges = function (one, two) { 7621 7622 var calendar = this; 7623 7624 // Convert the ranges into comparable dates. 7625 one = calendar.createRange(one.from, one.to); 7626 two = calendar.createRange(two.from, two.to); 7627 7628 return calendar.withinRange(one, two.from) || calendar.withinRange(one, two.to) || calendar.withinRange(two, one.from) || calendar.withinRange(two, one.to); 7629 }; 7630 7631 /** 7632 * Get the date today. 7633 */ 7634 DatePicker.prototype.now = function (type, value, options) { 7635 value = new Date(); 7636 if (options && options.rel) { 7637 value.setDate(value.getDate() + options.rel); 7638 } 7639 return this.normalize(value, options); 7640 }; 7641 7642 /** 7643 * Navigate to next/prev month. 7644 */ 7645 DatePicker.prototype.navigate = function (type, value, options) { 7646 7647 var targetDateObject, 7648 targetYear, 7649 targetMonth, 7650 targetDate, 7651 isTargetArray = $.isArray(value), 7652 isTargetObject = $.isPlainObject(value), 7653 viewsetObject = this.item.view; /*, 7654 safety = 100*/ 7655 7656 if (isTargetArray || isTargetObject) { 7657 7658 if (isTargetObject) { 7659 targetYear = value.year; 7660 targetMonth = value.month; 7661 targetDate = value.date; 7662 } else { 7663 targetYear = +value[0]; 7664 targetMonth = +value[1]; 7665 targetDate = +value[2]; 7666 } 7667 7668 // If we’re navigating months but the view is in a different 7669 // month, navigate to the view’s year and month. 7670 if (options && options.nav && viewsetObject && viewsetObject.month !== targetMonth) { 7671 targetYear = viewsetObject.year; 7672 targetMonth = viewsetObject.month; 7673 } 7674 7675 // Figure out the expected target year and month. 7676 targetDateObject = new Date(targetYear, targetMonth + (options && options.nav ? options.nav : 0), 1); 7677 targetYear = targetDateObject.getFullYear(); 7678 targetMonth = targetDateObject.getMonth(); 7679 7680 // If the month we’re going to doesn’t have enough days, 7681 // keep decreasing the date until we reach the month’s last date. 7682 while ( /*safety &&*/new Date(targetYear, targetMonth, targetDate).getMonth() !== targetMonth) { 7683 targetDate -= 1; 7684 /*safety -= 1 7685 if ( !safety ) { 7686 throw 'Fell into an infinite loop while navigating to ' + new Date( targetYear, targetMonth, targetDate ) + '.' 7687 }*/ 7688 } 7689 7690 value = [targetYear, targetMonth, targetDate]; 7691 } 7692 7693 return value; 7694 }; //DatePicker.prototype.navigate 7695 7696 7697 /** 7698 * Normalize a date by setting the hours to midnight. 7699 */ 7700 DatePicker.prototype.normalize = function (value /*, options*/) { 7701 value.setHours(0, 0, 0, 0); 7702 return value; 7703 }; 7704 7705 /** 7706 * Measure the range of dates. 7707 */ 7708 DatePicker.prototype.measure = function (type, value /*, options*/) { 7709 7710 var calendar = this; 7711 7712 // If it’s anything false-y, remove the limits. 7713 if (!value) { 7714 value = type == 'min' ? -Infinity : Infinity; 7715 } 7716 7717 // If it’s a string, parse it. 7718 else if (typeof value == 'string') { 7719 value = calendar.parse(type, value); 7720 } 7721 7722 // If it's an integer, get a date relative to today. 7723 else if (_.isInteger(value)) { 7724 value = calendar.now(type, value, { rel: value }); 7725 } 7726 7727 return value; 7728 }; ///DatePicker.prototype.measure 7729 7730 7731 /** 7732 * Create a viewset object based on navigation. 7733 */ 7734 DatePicker.prototype.viewset = function (type, dateObject /*, options*/) { 7735 return this.create([dateObject.year, dateObject.month, 1]); 7736 }; 7737 7738 /** 7739 * Validate a date as enabled and shift if needed. 7740 */ 7741 DatePicker.prototype.validate = function (type, dateObject, options) { 7742 7743 var calendar = this, 7744 7745 7746 // Keep a reference to the original date. 7747 originalDateObject = dateObject, 7748 7749 7750 // Make sure we have an interval. 7751 interval = options && options.interval ? options.interval : 1, 7752 7753 7754 // Check if the calendar enabled dates are inverted. 7755 isFlippedBase = calendar.item.enable === -1, 7756 7757 7758 // Check if we have any enabled dates after/before now. 7759 hasEnabledBeforeTarget, 7760 hasEnabledAfterTarget, 7761 7762 7763 // The min & max limits. 7764 minLimitObject = calendar.item.min, 7765 maxLimitObject = calendar.item.max, 7766 7767 7768 // Check if we’ve reached the limit during shifting. 7769 reachedMin, 7770 reachedMax, 7771 7772 7773 // Check if the calendar is inverted and at least one weekday is enabled. 7774 hasEnabledWeekdays = isFlippedBase && calendar.item.disable.filter(function (value) { 7775 7776 // If there’s a date, check where it is relative to the target. 7777 if ($.isArray(value)) { 7778 var dateTime = calendar.create(value).pick; 7779 if (dateTime < dateObject.pick) hasEnabledBeforeTarget = true;else if (dateTime > dateObject.pick) hasEnabledAfterTarget = true; 7780 } 7781 7782 // Return only integers for enabled weekdays. 7783 return _.isInteger(value); 7784 }).length; /*, 7785 safety = 100*/ 7786 7787 // Cases to validate for: 7788 // [1] Not inverted and date disabled. 7789 // [2] Inverted and some dates enabled. 7790 // [3] Not inverted and out of range. 7791 // 7792 // Cases to **not** validate for: 7793 // • Navigating months. 7794 // • Not inverted and date enabled. 7795 // • Inverted and all dates disabled. 7796 // • ..and anything else. 7797 if (!options || !options.nav) if ( 7798 /* 1 */!isFlippedBase && calendar.disabled(dateObject) || 7799 /* 2 */isFlippedBase && calendar.disabled(dateObject) && (hasEnabledWeekdays || hasEnabledBeforeTarget || hasEnabledAfterTarget) || 7800 /* 3 */!isFlippedBase && (dateObject.pick <= minLimitObject.pick || dateObject.pick >= maxLimitObject.pick)) { 7801 7802 // When inverted, flip the direction if there aren’t any enabled weekdays 7803 // and there are no enabled dates in the direction of the interval. 7804 if (isFlippedBase && !hasEnabledWeekdays && (!hasEnabledAfterTarget && interval > 0 || !hasEnabledBeforeTarget && interval < 0)) { 7805 interval *= -1; 7806 } 7807 7808 // Keep looping until we reach an enabled date. 7809 while ( /*safety &&*/calendar.disabled(dateObject)) { 7810 7811 /*safety -= 1 7812 if ( !safety ) { 7813 throw 'Fell into an infinite loop while validating ' + dateObject.obj + '.' 7814 }*/ 7815 7816 // If we’ve looped into the next/prev month with a large interval, return to the original date and flatten the interval. 7817 if (Math.abs(interval) > 1 && (dateObject.month < originalDateObject.month || dateObject.month > originalDateObject.month)) { 7818 dateObject = originalDateObject; 7819 interval = interval > 0 ? 1 : -1; 7820 } 7821 7822 // If we’ve reached the min/max limit, reverse the direction, flatten the interval and set it to the limit. 7823 if (dateObject.pick <= minLimitObject.pick) { 7824 reachedMin = true; 7825 interval = 1; 7826 dateObject = calendar.create([minLimitObject.year, minLimitObject.month, minLimitObject.date + (dateObject.pick === minLimitObject.pick ? 0 : -1)]); 7827 } else if (dateObject.pick >= maxLimitObject.pick) { 7828 reachedMax = true; 7829 interval = -1; 7830 dateObject = calendar.create([maxLimitObject.year, maxLimitObject.month, maxLimitObject.date + (dateObject.pick === maxLimitObject.pick ? 0 : 1)]); 7831 } 7832 7833 // If we’ve reached both limits, just break out of the loop. 7834 if (reachedMin && reachedMax) { 7835 break; 7836 } 7837 7838 // Finally, create the shifted date using the interval and keep looping. 7839 dateObject = calendar.create([dateObject.year, dateObject.month, dateObject.date + interval]); 7840 } 7841 } //endif 7842 7843 7844 // Return the date object settled on. 7845 return dateObject; 7846 }; //DatePicker.prototype.validate 7847 7848 7849 /** 7850 * Check if a date is disabled. 7851 */ 7852 DatePicker.prototype.disabled = function (dateToVerify) { 7853 7854 var calendar = this, 7855 7856 7857 // Filter through the disabled dates to check if this is one. 7858 isDisabledMatch = calendar.item.disable.filter(function (dateToDisable) { 7859 7860 // If the date is a number, match the weekday with 0index and `firstDay` check. 7861 if (_.isInteger(dateToDisable)) { 7862 return dateToVerify.day === (calendar.settings.firstDay ? dateToDisable : dateToDisable - 1) % 7; 7863 } 7864 7865 // If it’s an array or a native JS date, create and match the exact date. 7866 if ($.isArray(dateToDisable) || _.isDate(dateToDisable)) { 7867 return dateToVerify.pick === calendar.create(dateToDisable).pick; 7868 } 7869 7870 // If it’s an object, match a date within the “from” and “to” range. 7871 if ($.isPlainObject(dateToDisable)) { 7872 return calendar.withinRange(dateToDisable, dateToVerify); 7873 } 7874 }); 7875 7876 // If this date matches a disabled date, confirm it’s not inverted. 7877 isDisabledMatch = isDisabledMatch.length && !isDisabledMatch.filter(function (dateToDisable) { 7878 return $.isArray(dateToDisable) && dateToDisable[3] == 'inverted' || $.isPlainObject(dateToDisable) && dateToDisable.inverted; 7879 }).length; 7880 7881 // Check the calendar “enabled” flag and respectively flip the 7882 // disabled state. Then also check if it’s beyond the min/max limits. 7883 return calendar.item.enable === -1 ? !isDisabledMatch : isDisabledMatch || dateToVerify.pick < calendar.item.min.pick || dateToVerify.pick > calendar.item.max.pick; 7884 }; //DatePicker.prototype.disabled 7885 7886 7887 /** 7888 * Parse a string into a usable type. 7889 */ 7890 DatePicker.prototype.parse = function (type, value, options) { 7891 7892 var calendar = this, 7893 parsingObject = {}; 7894 7895 // If it’s already parsed, we’re good. 7896 if (!value || typeof value != 'string') { 7897 return value; 7898 } 7899 7900 // We need a `.format` to parse the value with. 7901 if (!(options && options.format)) { 7902 options = options || {}; 7903 options.format = calendar.settings.format; 7904 } 7905 7906 // Convert the format into an array and then map through it. 7907 calendar.formats.toArray(options.format).map(function (label) { 7908 7909 var 7910 // Grab the formatting label. 7911 formattingLabel = calendar.formats[label], 7912 7913 7914 // The format length is from the formatting label function or the 7915 // label length without the escaping exclamation (!) mark. 7916 formatLength = formattingLabel ? _.trigger(formattingLabel, calendar, [value, parsingObject]) : label.replace(/^!/, '').length; 7917 7918 // If there's a format label, split the value up to the format length. 7919 // Then add it to the parsing object with appropriate label. 7920 if (formattingLabel) { 7921 parsingObject[label] = value.substr(0, formatLength); 7922 } 7923 7924 // Update the value as the substring from format length to end. 7925 value = value.substr(formatLength); 7926 }); 7927 7928 // Compensate for month 0index. 7929 return [parsingObject.yyyy || parsingObject.yy, +(parsingObject.mm || parsingObject.m) - 1, parsingObject.dd || parsingObject.d]; 7930 }; //DatePicker.prototype.parse 7931 7932 7933 /** 7934 * Various formats to display the object in. 7935 */ 7936 DatePicker.prototype.formats = function () { 7937 7938 // Return the length of the first word in a collection. 7939 function getWordLengthFromCollection(string, collection, dateObject) { 7940 7941 // Grab the first word from the string. 7942 var word = string.match(/\w+/)[0]; 7943 7944 // If there's no month index, add it to the date object 7945 if (!dateObject.mm && !dateObject.m) { 7946 dateObject.m = collection.indexOf(word) + 1; 7947 } 7948 7949 // Return the length of the word. 7950 return word.length; 7951 } 7952 7953 // Get the length of the first word in a string. 7954 function getFirstWordLength(string) { 7955 return string.match(/\w+/)[0].length; 7956 } 7957 7958 return { 7959 7960 d: function (string, dateObject) { 7961 7962 // If there's string, then get the digits length. 7963 // Otherwise return the selected date. 7964 return string ? _.digits(string) : dateObject.date; 7965 }, 7966 dd: function (string, dateObject) { 7967 7968 // If there's a string, then the length is always 2. 7969 // Otherwise return the selected date with a leading zero. 7970 return string ? 2 : _.lead(dateObject.date); 7971 }, 7972 ddd: function (string, dateObject) { 7973 7974 // If there's a string, then get the length of the first word. 7975 // Otherwise return the short selected weekday. 7976 return string ? getFirstWordLength(string) : this.settings.weekdaysShort[dateObject.day]; 7977 }, 7978 dddd: function (string, dateObject) { 7979 7980 // If there's a string, then get the length of the first word. 7981 // Otherwise return the full selected weekday. 7982 return string ? getFirstWordLength(string) : this.settings.weekdaysFull[dateObject.day]; 7983 }, 7984 m: function (string, dateObject) { 7985 7986 // If there's a string, then get the length of the digits 7987 // Otherwise return the selected month with 0index compensation. 7988 return string ? _.digits(string) : dateObject.month + 1; 7989 }, 7990 mm: function (string, dateObject) { 7991 7992 // If there's a string, then the length is always 2. 7993 // Otherwise return the selected month with 0index and leading zero. 7994 return string ? 2 : _.lead(dateObject.month + 1); 7995 }, 7996 mmm: function (string, dateObject) { 7997 7998 var collection = this.settings.monthsShort; 7999 8000 // If there's a string, get length of the relevant month from the short 8001 // months collection. Otherwise return the selected month from that collection. 8002 return string ? getWordLengthFromCollection(string, collection, dateObject) : collection[dateObject.month]; 8003 }, 8004 mmmm: function (string, dateObject) { 8005 8006 var collection = this.settings.monthsFull; 8007 8008 // If there's a string, get length of the relevant month from the full 8009 // months collection. Otherwise return the selected month from that collection. 8010 return string ? getWordLengthFromCollection(string, collection, dateObject) : collection[dateObject.month]; 8011 }, 8012 yy: function (string, dateObject) { 8013 8014 // If there's a string, then the length is always 2. 8015 // Otherwise return the selected year by slicing out the first 2 digits. 8016 return string ? 2 : ('' + dateObject.year).slice(2); 8017 }, 8018 yyyy: function (string, dateObject) { 8019 8020 // If there's a string, then the length is always 4. 8021 // Otherwise return the selected year. 8022 return string ? 4 : dateObject.year; 8023 }, 8024 8025 // Create an array by splitting the formatting string passed. 8026 toArray: function (formatString) { 8027 return formatString.split(/(d{1,4}|m{1,4}|y{4}|yy|!.)/g); 8028 }, 8029 8030 // Format an object into a string using the formatting options. 8031 toString: function (formatString, itemObject) { 8032 var calendar = this; 8033 return calendar.formats.toArray(formatString).map(function (label) { 8034 return _.trigger(calendar.formats[label], calendar, [0, itemObject]) || label.replace(/^!/, ''); 8035 }).join(''); 8036 } 8037 }; 8038 }(); //DatePicker.prototype.formats 8039 8040 8041 /** 8042 * Check if two date units are the exact. 8043 */ 8044 DatePicker.prototype.isDateExact = function (one, two) { 8045 8046 var calendar = this; 8047 8048 // When we’re working with weekdays, do a direct comparison. 8049 if (_.isInteger(one) && _.isInteger(two) || typeof one == 'boolean' && typeof two == 'boolean') { 8050 return one === two; 8051 } 8052 8053 // When we’re working with date representations, compare the “pick” value. 8054 if ((_.isDate(one) || $.isArray(one)) && (_.isDate(two) || $.isArray(two))) { 8055 return calendar.create(one).pick === calendar.create(two).pick; 8056 } 8057 8058 // When we’re working with range objects, compare the “from” and “to”. 8059 if ($.isPlainObject(one) && $.isPlainObject(two)) { 8060 return calendar.isDateExact(one.from, two.from) && calendar.isDateExact(one.to, two.to); 8061 } 8062 8063 return false; 8064 }; 8065 8066 /** 8067 * Check if two date units overlap. 8068 */ 8069 DatePicker.prototype.isDateOverlap = function (one, two) { 8070 8071 var calendar = this, 8072 firstDay = calendar.settings.firstDay ? 1 : 0; 8073 8074 // When we’re working with a weekday index, compare the days. 8075 if (_.isInteger(one) && (_.isDate(two) || $.isArray(two))) { 8076 one = one % 7 + firstDay; 8077 return one === calendar.create(two).day + 1; 8078 } 8079 if (_.isInteger(two) && (_.isDate(one) || $.isArray(one))) { 8080 two = two % 7 + firstDay; 8081 return two === calendar.create(one).day + 1; 8082 } 8083 8084 // When we’re working with range objects, check if the ranges overlap. 8085 if ($.isPlainObject(one) && $.isPlainObject(two)) { 8086 return calendar.overlapRanges(one, two); 8087 } 8088 8089 return false; 8090 }; 8091 8092 /** 8093 * Flip the “enabled” state. 8094 */ 8095 DatePicker.prototype.flipEnable = function (val) { 8096 var itemObject = this.item; 8097 itemObject.enable = val || (itemObject.enable == -1 ? 1 : -1); 8098 }; 8099 8100 /** 8101 * Mark a collection of dates as “disabled”. 8102 */ 8103 DatePicker.prototype.deactivate = function (type, datesToDisable) { 8104 8105 var calendar = this, 8106 disabledItems = calendar.item.disable.slice(0); 8107 8108 // If we’re flipping, that’s all we need to do. 8109 if (datesToDisable == 'flip') { 8110 calendar.flipEnable(); 8111 } else if (datesToDisable === false) { 8112 calendar.flipEnable(1); 8113 disabledItems = []; 8114 } else if (datesToDisable === true) { 8115 calendar.flipEnable(-1); 8116 disabledItems = []; 8117 } 8118 8119 // Otherwise go through the dates to disable. 8120 else { 8121 8122 datesToDisable.map(function (unitToDisable) { 8123 8124 var matchFound; 8125 8126 // When we have disabled items, check for matches. 8127 // If something is matched, immediately break out. 8128 for (var index = 0; index < disabledItems.length; index += 1) { 8129 if (calendar.isDateExact(unitToDisable, disabledItems[index])) { 8130 matchFound = true; 8131 break; 8132 } 8133 } 8134 8135 // If nothing was found, add the validated unit to the collection. 8136 if (!matchFound) { 8137 if (_.isInteger(unitToDisable) || _.isDate(unitToDisable) || $.isArray(unitToDisable) || $.isPlainObject(unitToDisable) && unitToDisable.from && unitToDisable.to) { 8138 disabledItems.push(unitToDisable); 8139 } 8140 } 8141 }); 8142 } 8143 8144 // Return the updated collection. 8145 return disabledItems; 8146 }; //DatePicker.prototype.deactivate 8147 8148 8149 /** 8150 * Mark a collection of dates as “enabled”. 8151 */ 8152 DatePicker.prototype.activate = function (type, datesToEnable) { 8153 8154 var calendar = this, 8155 disabledItems = calendar.item.disable, 8156 disabledItemsCount = disabledItems.length; 8157 8158 // If we’re flipping, that’s all we need to do. 8159 if (datesToEnable == 'flip') { 8160 calendar.flipEnable(); 8161 } else if (datesToEnable === true) { 8162 calendar.flipEnable(1); 8163 disabledItems = []; 8164 } else if (datesToEnable === false) { 8165 calendar.flipEnable(-1); 8166 disabledItems = []; 8167 } 8168 8169 // Otherwise go through the disabled dates. 8170 else { 8171 8172 datesToEnable.map(function (unitToEnable) { 8173 8174 var matchFound, disabledUnit, index, isExactRange; 8175 8176 // Go through the disabled items and try to find a match. 8177 for (index = 0; index < disabledItemsCount; index += 1) { 8178 8179 disabledUnit = disabledItems[index]; 8180 8181 // When an exact match is found, remove it from the collection. 8182 if (calendar.isDateExact(disabledUnit, unitToEnable)) { 8183 matchFound = disabledItems[index] = null; 8184 isExactRange = true; 8185 break; 8186 } 8187 8188 // When an overlapped match is found, add the “inverted” state to it. 8189 else if (calendar.isDateOverlap(disabledUnit, unitToEnable)) { 8190 if ($.isPlainObject(unitToEnable)) { 8191 unitToEnable.inverted = true; 8192 matchFound = unitToEnable; 8193 } else if ($.isArray(unitToEnable)) { 8194 matchFound = unitToEnable; 8195 if (!matchFound[3]) matchFound.push('inverted'); 8196 } else if (_.isDate(unitToEnable)) { 8197 matchFound = [unitToEnable.getFullYear(), unitToEnable.getMonth(), unitToEnable.getDate(), 'inverted']; 8198 } 8199 break; 8200 } 8201 } 8202 8203 // If a match was found, remove a previous duplicate entry. 8204 if (matchFound) for (index = 0; index < disabledItemsCount; index += 1) { 8205 if (calendar.isDateExact(disabledItems[index], unitToEnable)) { 8206 disabledItems[index] = null; 8207 break; 8208 } 8209 } 8210 8211 // In the event that we’re dealing with an exact range of dates, 8212 // make sure there are no “inverted” dates because of it. 8213 if (isExactRange) for (index = 0; index < disabledItemsCount; index += 1) { 8214 if (calendar.isDateOverlap(disabledItems[index], unitToEnable)) { 8215 disabledItems[index] = null; 8216 break; 8217 } 8218 } 8219 8220 // If something is still matched, add it into the collection. 8221 if (matchFound) { 8222 disabledItems.push(matchFound); 8223 } 8224 }); 8225 } 8226 8227 // Return the updated collection. 8228 return disabledItems.filter(function (val) { 8229 return val != null; 8230 }); 8231 }; //DatePicker.prototype.activate 8232 8233 8234 /** 8235 * Create a string for the nodes in the picker. 8236 */ 8237 DatePicker.prototype.nodes = function (isOpen) { 8238 8239 var calendar = this, 8240 settings = calendar.settings, 8241 calendarItem = calendar.item, 8242 nowObject = calendarItem.now, 8243 selectedObject = calendarItem.select, 8244 highlightedObject = calendarItem.highlight, 8245 viewsetObject = calendarItem.view, 8246 disabledCollection = calendarItem.disable, 8247 minLimitObject = calendarItem.min, 8248 maxLimitObject = calendarItem.max, 8249 8250 8251 // Create the calendar table head using a copy of weekday labels collection. 8252 // * We do a copy so we don't mutate the original array. 8253 tableHead = function (collection, fullCollection) { 8254 8255 // If the first day should be Monday, move Sunday to the end. 8256 if (settings.firstDay) { 8257 collection.push(collection.shift()); 8258 fullCollection.push(fullCollection.shift()); 8259 } 8260 8261 // Create and return the table head group. 8262 return _.node('thead', _.node('tr', _.group({ 8263 min: 0, 8264 max: DAYS_IN_WEEK - 1, 8265 i: 1, 8266 node: 'th', 8267 item: function (counter) { 8268 return [collection[counter], settings.klass.weekdays, 'scope=col title="' + fullCollection[counter] + '"']; 8269 } 8270 }))); //endreturn 8271 8272 // Materialize modified 8273 }((settings.showWeekdaysFull ? settings.weekdaysFull : settings.weekdaysLetter).slice(0), settings.weekdaysFull.slice(0)), 8274 //tableHead 8275 8276 8277 // Create the nav for next/prev month. 8278 createMonthNav = function (next) { 8279 8280 // Otherwise, return the created month tag. 8281 return _.node('div', ' ', settings.klass['nav' + (next ? 'Next' : 'Prev')] + ( 8282 8283 // If the focused month is outside the range, disabled the button. 8284 next && viewsetObject.year >= maxLimitObject.year && viewsetObject.month >= maxLimitObject.month || !next && viewsetObject.year <= minLimitObject.year && viewsetObject.month <= minLimitObject.month ? ' ' + settings.klass.navDisabled : ''), 'data-nav=' + (next || -1) + ' ' + _.ariaAttr({ 8285 role: 'button', 8286 controls: calendar.$node[0].id + '_table' 8287 }) + ' ' + 'title="' + (next ? settings.labelMonthNext : settings.labelMonthPrev) + '"'); //endreturn 8288 }, 8289 //createMonthNav 8290 8291 8292 // Create the month label. 8293 //Materialize modified 8294 createMonthLabel = function (override) { 8295 8296 var monthsCollection = settings.showMonthsShort ? settings.monthsShort : settings.monthsFull; 8297 8298 // Materialize modified 8299 if (override == "short_months") { 8300 monthsCollection = settings.monthsShort; 8301 } 8302 8303 // If there are months to select, add a dropdown menu. 8304 if (settings.selectMonths && override == undefined) { 8305 8306 return _.node('select', _.group({ 8307 min: 0, 8308 max: 11, 8309 i: 1, 8310 node: 'option', 8311 item: function (loopedMonth) { 8312 8313 return [ 8314 8315 // The looped month and no classes. 8316 monthsCollection[loopedMonth], 0, 8317 8318 // Set the value and selected index. 8319 'value=' + loopedMonth + (viewsetObject.month == loopedMonth ? ' selected' : '') + (viewsetObject.year == minLimitObject.year && loopedMonth < minLimitObject.month || viewsetObject.year == maxLimitObject.year && loopedMonth > maxLimitObject.month ? ' disabled' : '')]; 8320 } 8321 }), settings.klass.selectMonth + ' browser-default', (isOpen ? '' : 'disabled') + ' ' + _.ariaAttr({ controls: calendar.$node[0].id + '_table' }) + ' ' + 'title="' + settings.labelMonthSelect + '"'); 8322 } 8323 8324 // Materialize modified 8325 if (override == "short_months") if (selectedObject != null) return monthsCollection[selectedObject.month];else return monthsCollection[viewsetObject.month]; 8326 8327 // If there's a need for a month selector 8328 return _.node('div', monthsCollection[viewsetObject.month], settings.klass.month); 8329 }, 8330 //createMonthLabel 8331 8332 8333 // Create the year label. 8334 // Materialize modified 8335 createYearLabel = function (override) { 8336 8337 var focusedYear = viewsetObject.year, 8338 8339 8340 // If years selector is set to a literal "true", set it to 5. Otherwise 8341 // divide in half to get half before and half after focused year. 8342 numberYears = settings.selectYears === true ? 5 : ~~(settings.selectYears / 2); 8343 8344 // If there are years to select, add a dropdown menu. 8345 if (numberYears) { 8346 8347 var minYear = minLimitObject.year, 8348 maxYear = maxLimitObject.year, 8349 lowestYear = focusedYear - numberYears, 8350 highestYear = focusedYear + numberYears; 8351 8352 // If the min year is greater than the lowest year, increase the highest year 8353 // by the difference and set the lowest year to the min year. 8354 if (minYear > lowestYear) { 8355 highestYear += minYear - lowestYear; 8356 lowestYear = minYear; 8357 } 8358 8359 // If the max year is less than the highest year, decrease the lowest year 8360 // by the lower of the two: available and needed years. Then set the 8361 // highest year to the max year. 8362 if (maxYear < highestYear) { 8363 8364 var availableYears = lowestYear - minYear, 8365 neededYears = highestYear - maxYear; 8366 8367 lowestYear -= availableYears > neededYears ? neededYears : availableYears; 8368 highestYear = maxYear; 8369 } 8370 8371 if (settings.selectYears && override == undefined) { 8372 return _.node('select', _.group({ 8373 min: lowestYear, 8374 max: highestYear, 8375 i: 1, 8376 node: 'option', 8377 item: function (loopedYear) { 8378 return [ 8379 8380 // The looped year and no classes. 8381 loopedYear, 0, 8382 8383 // Set the value and selected index. 8384 'value=' + loopedYear + (focusedYear == loopedYear ? ' selected' : '')]; 8385 } 8386 }), settings.klass.selectYear + ' browser-default', (isOpen ? '' : 'disabled') + ' ' + _.ariaAttr({ controls: calendar.$node[0].id + '_table' }) + ' ' + 'title="' + settings.labelYearSelect + '"'); 8387 } 8388 } 8389 8390 // Materialize modified 8391 if (override === 'raw' && selectedObject != null) { 8392 return _.node('div', selectedObject.year); 8393 } 8394 8395 // Otherwise just return the year focused 8396 return _.node('div', focusedYear, settings.klass.year); 8397 }; //createYearLabel 8398 8399 8400 // Materialize modified 8401 createDayLabel = function () { 8402 if (selectedObject != null) return selectedObject.date;else return nowObject.date; 8403 }; 8404 createWeekdayLabel = function () { 8405 var display_day; 8406 8407 if (selectedObject != null) display_day = selectedObject.day;else display_day = nowObject.day; 8408 var weekday = settings.weekdaysShort[display_day]; 8409 return weekday; 8410 }; 8411 8412 // Create and return the entire calendar. 8413 8414 return _.node( 8415 // Date presentation View 8416 'div', _.node( 8417 // Div for Year 8418 'div', createYearLabel("raw"), settings.klass.year_display) + _.node('span', createWeekdayLabel() + ', ', "picker__weekday-display") + _.node( 8419 // Div for short Month 8420 'span', createMonthLabel("short_months") + ' ', settings.klass.month_display) + _.node( 8421 // Div for Day 8422 'span', createDayLabel(), settings.klass.day_display), settings.klass.date_display) + 8423 // Calendar container 8424 _.node('div', _.node('div', _.node('div', (settings.selectYears ? createMonthLabel() + createYearLabel() : createMonthLabel() + createYearLabel()) + createMonthNav() + createMonthNav(1), settings.klass.header) + _.node('table', tableHead + _.node('tbody', _.group({ 8425 min: 0, 8426 max: WEEKS_IN_CALENDAR - 1, 8427 i: 1, 8428 node: 'tr', 8429 item: function (rowCounter) { 8430 8431 // If Monday is the first day and the month starts on Sunday, shift the date back a week. 8432 var shiftDateBy = settings.firstDay && calendar.create([viewsetObject.year, viewsetObject.month, 1]).day === 0 ? -7 : 0; 8433 8434 return [_.group({ 8435 min: DAYS_IN_WEEK * rowCounter - viewsetObject.day + shiftDateBy + 1, // Add 1 for weekday 0index 8436 max: function () { 8437 return this.min + DAYS_IN_WEEK - 1; 8438 }, 8439 i: 1, 8440 node: 'td', 8441 item: function (targetDate) { 8442 8443 // Convert the time date from a relative date to a target date. 8444 targetDate = calendar.create([viewsetObject.year, viewsetObject.month, targetDate + (settings.firstDay ? 1 : 0)]); 8445 8446 var isSelected = selectedObject && selectedObject.pick == targetDate.pick, 8447 isHighlighted = highlightedObject && highlightedObject.pick == targetDate.pick, 8448 isDisabled = disabledCollection && calendar.disabled(targetDate) || targetDate.pick < minLimitObject.pick || targetDate.pick > maxLimitObject.pick, 8449 formattedDate = _.trigger(calendar.formats.toString, calendar, [settings.format, targetDate]); 8450 8451 return [_.node('div', targetDate.date, function (klasses) { 8452 8453 // Add the `infocus` or `outfocus` classes based on month in view. 8454 klasses.push(viewsetObject.month == targetDate.month ? settings.klass.infocus : settings.klass.outfocus); 8455 8456 // Add the `today` class if needed. 8457 if (nowObject.pick == targetDate.pick) { 8458 klasses.push(settings.klass.now); 8459 } 8460 8461 // Add the `selected` class if something's selected and the time matches. 8462 if (isSelected) { 8463 klasses.push(settings.klass.selected); 8464 } 8465 8466 // Add the `highlighted` class if something's highlighted and the time matches. 8467 if (isHighlighted) { 8468 klasses.push(settings.klass.highlighted); 8469 } 8470 8471 // Add the `disabled` class if something's disabled and the object matches. 8472 if (isDisabled) { 8473 klasses.push(settings.klass.disabled); 8474 } 8475 8476 return klasses.join(' '); 8477 }([settings.klass.day]), 'data-pick=' + targetDate.pick + ' ' + _.ariaAttr({ 8478 role: 'gridcell', 8479 label: formattedDate, 8480 selected: isSelected && calendar.$node.val() === formattedDate ? true : null, 8481 activedescendant: isHighlighted ? true : null, 8482 disabled: isDisabled ? true : null 8483 }) + ' ' + (isDisabled ? '' : 'tabindex="0"')), '', _.ariaAttr({ role: 'presentation' })]; //endreturn 8484 } 8485 })]; //endreturn 8486 } 8487 })), settings.klass.table, 'id="' + calendar.$node[0].id + '_table' + '" ' + _.ariaAttr({ 8488 role: 'grid', 8489 controls: calendar.$node[0].id, 8490 readonly: true 8491 })), settings.klass.calendar_container) // end calendar 8492 8493 + 8494 8495 // * For Firefox forms to submit, make sure to set the buttons’ `type` attributes as “button”. 8496 _.node('div', _.node('button', settings.today, "btn-flat picker__today waves-effect", 'type=button data-pick=' + nowObject.pick + (isOpen && !calendar.disabled(nowObject) ? '' : ' disabled') + ' ' + _.ariaAttr({ controls: calendar.$node[0].id })) + _.node('button', settings.clear, "btn-flat picker__clear waves-effect", 'type=button data-clear=1' + (isOpen ? '' : ' disabled') + ' ' + _.ariaAttr({ controls: calendar.$node[0].id })) + _.node('button', settings.close, "btn-flat picker__close waves-effect", 'type=button data-close=true ' + (isOpen ? '' : ' disabled') + ' ' + _.ariaAttr({ controls: calendar.$node[0].id })), settings.klass.footer), 'picker__container__wrapper'); //endreturn 8497 }; //DatePicker.prototype.nodes 8498 8499 8500 /** 8501 * The date picker defaults. 8502 */ 8503 DatePicker.defaults = function (prefix) { 8504 8505 return { 8506 8507 // The title label to use for the month nav buttons 8508 labelMonthNext: 'Next month', 8509 labelMonthPrev: 'Previous month', 8510 8511 // The title label to use for the dropdown selectors 8512 labelMonthSelect: 'Select a month', 8513 labelYearSelect: 'Select a year', 8514 8515 // Months and weekdays 8516 monthsFull: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], 8517 monthsShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], 8518 weekdaysFull: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], 8519 weekdaysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], 8520 8521 // Materialize modified 8522 weekdaysLetter: ['S', 'M', 'T', 'W', 'T', 'F', 'S'], 8523 8524 // Today and clear 8525 today: 'Today', 8526 clear: 'Clear', 8527 close: 'Ok', 8528 8529 // Picker close behavior (Prevent a change in behaviour for backwards compatibility) 8530 closeOnSelect: false, 8531 8532 // The format to show on the `input` element 8533 format: 'd mmmm, yyyy', 8534 8535 // Classes 8536 klass: { 8537 8538 table: prefix + 'table', 8539 8540 header: prefix + 'header', 8541 8542 // Materialize Added klasses 8543 date_display: prefix + 'date-display', 8544 day_display: prefix + 'day-display', 8545 month_display: prefix + 'month-display', 8546 year_display: prefix + 'year-display', 8547 calendar_container: prefix + 'calendar-container', 8548 // end 8549 8550 8551 navPrev: prefix + 'nav--prev', 8552 navNext: prefix + 'nav--next', 8553 navDisabled: prefix + 'nav--disabled', 8554 8555 month: prefix + 'month', 8556 year: prefix + 'year', 8557 8558 selectMonth: prefix + 'select--month', 8559 selectYear: prefix + 'select--year', 8560 8561 weekdays: prefix + 'weekday', 8562 8563 day: prefix + 'day', 8564 disabled: prefix + 'day--disabled', 8565 selected: prefix + 'day--selected', 8566 highlighted: prefix + 'day--highlighted', 8567 now: prefix + 'day--today', 8568 infocus: prefix + 'day--infocus', 8569 outfocus: prefix + 'day--outfocus', 8570 8571 footer: prefix + 'footer', 8572 8573 buttonClear: prefix + 'button--clear', 8574 buttonToday: prefix + 'button--today', 8575 buttonClose: prefix + 'button--close' 8576 } 8577 }; 8578 }(Picker.klasses().picker + '__'); 8579 8580 /** 8581 * Extend the picker to add the date picker. 8582 */ 8583 Picker.extend('pickadate', DatePicker); 8584 }); 8585 ; /*! 8586 * ClockPicker v0.0.7 (http://weareoutman.github.io/clockpicker/) 8587 * Copyright 2014 Wang Shenwei. 8588 * Licensed under MIT (https://github.com/weareoutman/clockpicker/blob/gh-pages/LICENSE) 8589 * 8590 * Further modified 8591 * Copyright 2015 Ching Yaw Hao. 8592 */ 8593 8594 (function ($) { 8595 var $win = $(window), 8596 $doc = $(document); 8597 8598 // Can I use inline svg ? 8599 var svgNS = 'http://www.w3.org/2000/svg', 8600 svgSupported = 'SVGAngle' in window && function () { 8601 var supported, 8602 el = document.createElement('div'); 8603 el.innerHTML = '<svg/>'; 8604 supported = (el.firstChild && el.firstChild.namespaceURI) == svgNS; 8605 el.innerHTML = ''; 8606 return supported; 8607 }(); 8608 8609 // Can I use transition ? 8610 var transitionSupported = function () { 8611 var style = document.createElement('div').style; 8612 return 'transition' in style || 'WebkitTransition' in style || 'MozTransition' in style || 'msTransition' in style || 'OTransition' in style; 8613 }(); 8614 8615 // Listen touch events in touch screen device, instead of mouse events in desktop. 8616 var touchSupported = 'ontouchstart' in window, 8617 mousedownEvent = 'mousedown' + (touchSupported ? ' touchstart' : ''), 8618 mousemoveEvent = 'mousemove.clockpicker' + (touchSupported ? ' touchmove.clockpicker' : ''), 8619 mouseupEvent = 'mouseup.clockpicker' + (touchSupported ? ' touchend.clockpicker' : ''); 8620 8621 // Vibrate the device if supported 8622 var vibrate = navigator.vibrate ? 'vibrate' : navigator.webkitVibrate ? 'webkitVibrate' : null; 8623 8624 function createSvgElement(name) { 8625 return document.createElementNS(svgNS, name); 8626 } 8627 8628 function leadingZero(num) { 8629 return (num < 10 ? '0' : '') + num; 8630 } 8631 8632 // Get a unique id 8633 var idCounter = 0; 8634 function uniqueId(prefix) { 8635 var id = ++idCounter + ''; 8636 return prefix ? prefix + id : id; 8637 } 8638 8639 // Clock size 8640 var dialRadius = 135, 8641 outerRadius = 105, 8642 8643 // innerRadius = 80 on 12 hour clock 8644 innerRadius = 70, 8645 tickRadius = 20, 8646 diameter = dialRadius * 2, 8647 duration = transitionSupported ? 350 : 1; 8648 8649 // Popover template 8650 var tpl = ['<div class="clockpicker picker">', '<div class="picker__holder">', '<div class="picker__frame">', '<div class="picker__wrap">', '<div class="picker__box">', '<div class="picker__date-display">', '<div class="clockpicker-display">', '<div class="clockpicker-display-column">', '<span class="clockpicker-span-hours text-primary"></span>', ':', '<span class="clockpicker-span-minutes"></span>', '</div>', '<div class="clockpicker-display-column clockpicker-display-am-pm">', '<div class="clockpicker-span-am-pm"></div>', '</div>', '</div>', '</div>', '<div class="picker__container__wrapper">', '<div class="picker__calendar-container">', '<div class="clockpicker-plate">', '<div class="clockpicker-canvas"></div>', '<div class="clockpicker-dial clockpicker-hours"></div>', '<div class="clockpicker-dial clockpicker-minutes clockpicker-dial-out"></div>', '</div>', '<div class="clockpicker-am-pm-block">', '</div>', '</div>', '<div class="picker__footer">', '</div>', '</div>', '</div>', '</div>', '</div>', '</div>', '</div>'].join(''); 8651 8652 // ClockPicker 8653 function ClockPicker(element, options) { 8654 var popover = $(tpl), 8655 plate = popover.find('.clockpicker-plate'), 8656 holder = popover.find('.picker__holder'), 8657 hoursView = popover.find('.clockpicker-hours'), 8658 minutesView = popover.find('.clockpicker-minutes'), 8659 amPmBlock = popover.find('.clockpicker-am-pm-block'), 8660 isInput = element.prop('tagName') === 'INPUT', 8661 input = isInput ? element : element.find('input'), 8662 label = $("label[for=" + input.attr("id") + "]"), 8663 self = this; 8664 8665 this.id = uniqueId('cp'); 8666 this.element = element; 8667 this.holder = holder; 8668 this.options = options; 8669 this.isAppended = false; 8670 this.isShown = false; 8671 this.currentView = 'hours'; 8672 this.isInput = isInput; 8673 this.input = input; 8674 this.label = label; 8675 this.popover = popover; 8676 this.plate = plate; 8677 this.hoursView = hoursView; 8678 this.minutesView = minutesView; 8679 this.amPmBlock = amPmBlock; 8680 this.spanHours = popover.find('.clockpicker-span-hours'); 8681 this.spanMinutes = popover.find('.clockpicker-span-minutes'); 8682 this.spanAmPm = popover.find('.clockpicker-span-am-pm'); 8683 this.footer = popover.find('.picker__footer'); 8684 this.amOrPm = "PM"; 8685 8686 // Setup for for 12 hour clock if option is selected 8687 if (options.twelvehour) { 8688 if (!options.ampmclickable) { 8689 this.spanAmPm.empty(); 8690 $('<div id="click-am">AM</div>').appendTo(this.spanAmPm); 8691 $('<div id="click-pm">PM</div>').appendTo(this.spanAmPm); 8692 } else { 8693 this.spanAmPm.empty(); 8694 $('<div id="click-am">AM</div>').on("click", function () { 8695 self.spanAmPm.children('#click-am').addClass("text-primary"); 8696 self.spanAmPm.children('#click-pm').removeClass("text-primary"); 8697 self.amOrPm = "AM"; 8698 }).appendTo(this.spanAmPm); 8699 $('<div id="click-pm">PM</div>').on("click", function () { 8700 self.spanAmPm.children('#click-pm').addClass("text-primary"); 8701 self.spanAmPm.children('#click-am').removeClass("text-primary"); 8702 self.amOrPm = 'PM'; 8703 }).appendTo(this.spanAmPm); 8704 } 8705 } 8706 8707 // Add buttons to footer 8708 $('<button type="button" class="btn-flat picker__clear" tabindex="' + (options.twelvehour ? '3' : '1') + '">' + options.cleartext + '</button>').click($.proxy(this.clear, this)).appendTo(this.footer); 8709 $('<button type="button" class="btn-flat picker__close" tabindex="' + (options.twelvehour ? '3' : '1') + '">' + options.canceltext + '</button>').click($.proxy(this.hide, this)).appendTo(this.footer); 8710 $('<button type="button" class="btn-flat picker__close" tabindex="' + (options.twelvehour ? '3' : '1') + '">' + options.donetext + '</button>').click($.proxy(this.done, this)).appendTo(this.footer); 8711 8712 this.spanHours.click($.proxy(this.toggleView, this, 'hours')); 8713 this.spanMinutes.click($.proxy(this.toggleView, this, 'minutes')); 8714 8715 // Show or toggle 8716 input.on('focus.clockpicker click.clockpicker', $.proxy(this.show, this)); 8717 8718 // Build ticks 8719 var tickTpl = $('<div class="clockpicker-tick"></div>'), 8720 i, 8721 tick, 8722 radian, 8723 radius; 8724 8725 // Hours view 8726 if (options.twelvehour) { 8727 for (i = 1; i < 13; i += 1) { 8728 tick = tickTpl.clone(); 8729 radian = i / 6 * Math.PI; 8730 radius = outerRadius; 8731 tick.css({ 8732 left: dialRadius + Math.sin(radian) * radius - tickRadius, 8733 top: dialRadius - Math.cos(radian) * radius - tickRadius 8734 }); 8735 tick.html(i === 0 ? '00' : i); 8736 hoursView.append(tick); 8737 tick.on(mousedownEvent, mousedown); 8738 } 8739 } else { 8740 for (i = 0; i < 24; i += 1) { 8741 tick = tickTpl.clone(); 8742 radian = i / 6 * Math.PI; 8743 var inner = i > 0 && i < 13; 8744 radius = inner ? innerRadius : outerRadius; 8745 tick.css({ 8746 left: dialRadius + Math.sin(radian) * radius - tickRadius, 8747 top: dialRadius - Math.cos(radian) * radius - tickRadius 8748 }); 8749 tick.html(i === 0 ? '00' : i); 8750 hoursView.append(tick); 8751 tick.on(mousedownEvent, mousedown); 8752 } 8753 } 8754 8755 // Minutes view 8756 for (i = 0; i < 60; i += 5) { 8757 tick = tickTpl.clone(); 8758 radian = i / 30 * Math.PI; 8759 tick.css({ 8760 left: dialRadius + Math.sin(radian) * outerRadius - tickRadius, 8761 top: dialRadius - Math.cos(radian) * outerRadius - tickRadius 8762 }); 8763 tick.html(leadingZero(i)); 8764 minutesView.append(tick); 8765 tick.on(mousedownEvent, mousedown); 8766 } 8767 8768 // Clicking on minutes view space 8769 plate.on(mousedownEvent, function (e) { 8770 if ($(e.target).closest('.clockpicker-tick').length === 0) { 8771 mousedown(e, true); 8772 } 8773 }); 8774 8775 // Mousedown or touchstart 8776 function mousedown(e, space) { 8777 var offset = plate.offset(), 8778 isTouch = /^touch/.test(e.type), 8779 x0 = offset.left + dialRadius, 8780 y0 = offset.top + dialRadius, 8781 dx = (isTouch ? e.originalEvent.touches[0] : e).pageX - x0, 8782 dy = (isTouch ? e.originalEvent.touches[0] : e).pageY - y0, 8783 z = Math.sqrt(dx * dx + dy * dy), 8784 moved = false; 8785 8786 // When clicking on minutes view space, check the mouse position 8787 if (space && (z < outerRadius - tickRadius || z > outerRadius + tickRadius)) { 8788 return; 8789 } 8790 e.preventDefault(); 8791 8792 // Set cursor style of body after 200ms 8793 var movingTimer = setTimeout(function () { 8794 self.popover.addClass('clockpicker-moving'); 8795 }, 200); 8796 8797 // Clock 8798 self.setHand(dx, dy, !space, true); 8799 8800 // Mousemove on document 8801 $doc.off(mousemoveEvent).on(mousemoveEvent, function (e) { 8802 e.preventDefault(); 8803 var isTouch = /^touch/.test(e.type), 8804 x = (isTouch ? e.originalEvent.touches[0] : e).pageX - x0, 8805 y = (isTouch ? e.originalEvent.touches[0] : e).pageY - y0; 8806 if (!moved && x === dx && y === dy) { 8807 // Clicking in chrome on windows will trigger a mousemove event 8808 return; 8809 } 8810 moved = true; 8811 self.setHand(x, y, false, true); 8812 }); 8813 8814 // Mouseup on document 8815 $doc.off(mouseupEvent).on(mouseupEvent, function (e) { 8816 $doc.off(mouseupEvent); 8817 e.preventDefault(); 8818 var isTouch = /^touch/.test(e.type), 8819 x = (isTouch ? e.originalEvent.changedTouches[0] : e).pageX - x0, 8820 y = (isTouch ? e.originalEvent.changedTouches[0] : e).pageY - y0; 8821 if ((space || moved) && x === dx && y === dy) { 8822 self.setHand(x, y); 8823 } 8824 8825 if (self.currentView === 'hours') { 8826 self.toggleView('minutes', duration / 2); 8827 } else if (options.autoclose) { 8828 self.minutesView.addClass('clockpicker-dial-out'); 8829 setTimeout(function () { 8830 self.done(); 8831 }, duration / 2); 8832 } 8833 plate.prepend(canvas); 8834 8835 // Reset cursor style of body 8836 clearTimeout(movingTimer); 8837 self.popover.removeClass('clockpicker-moving'); 8838 8839 // Unbind mousemove event 8840 $doc.off(mousemoveEvent); 8841 }); 8842 } 8843 8844 if (svgSupported) { 8845 // Draw clock hands and others 8846 var canvas = popover.find('.clockpicker-canvas'), 8847 svg = createSvgElement('svg'); 8848 svg.setAttribute('class', 'clockpicker-svg'); 8849 svg.setAttribute('width', diameter); 8850 svg.setAttribute('height', diameter); 8851 var g = createSvgElement('g'); 8852 g.setAttribute('transform', 'translate(' + dialRadius + ',' + dialRadius + ')'); 8853 var bearing = createSvgElement('circle'); 8854 bearing.setAttribute('class', 'clockpicker-canvas-bearing'); 8855 bearing.setAttribute('cx', 0); 8856 bearing.setAttribute('cy', 0); 8857 bearing.setAttribute('r', 4); 8858 var hand = createSvgElement('line'); 8859 hand.setAttribute('x1', 0); 8860 hand.setAttribute('y1', 0); 8861 var bg = createSvgElement('circle'); 8862 bg.setAttribute('class', 'clockpicker-canvas-bg'); 8863 bg.setAttribute('r', tickRadius); 8864 g.appendChild(hand); 8865 g.appendChild(bg); 8866 g.appendChild(bearing); 8867 svg.appendChild(g); 8868 canvas.append(svg); 8869 8870 this.hand = hand; 8871 this.bg = bg; 8872 this.bearing = bearing; 8873 this.g = g; 8874 this.canvas = canvas; 8875 } 8876 8877 raiseCallback(this.options.init); 8878 } 8879 8880 function raiseCallback(callbackFunction) { 8881 if (callbackFunction && typeof callbackFunction === "function") callbackFunction(); 8882 } 8883 8884 // Default options 8885 ClockPicker.DEFAULTS = { 8886 'default': '', // default time, 'now' or '13:14' e.g. 8887 fromnow: 0, // set default time to * milliseconds from now (using with default = 'now') 8888 donetext: 'Ok', // done button text 8889 cleartext: 'Clear', 8890 canceltext: 'Cancel', 8891 autoclose: false, // auto close when minute is selected 8892 ampmclickable: true, // set am/pm button on itself 8893 darktheme: false, // set to dark theme 8894 twelvehour: true, // change to 12 hour AM/PM clock from 24 hour 8895 vibrate: true // vibrate the device when dragging clock hand 8896 }; 8897 8898 // Show or hide popover 8899 ClockPicker.prototype.toggle = function () { 8900 this[this.isShown ? 'hide' : 'show'](); 8901 }; 8902 8903 // Set popover position 8904 ClockPicker.prototype.locate = function () { 8905 var element = this.element, 8906 popover = this.popover, 8907 offset = element.offset(), 8908 width = element.outerWidth(), 8909 height = element.outerHeight(), 8910 align = this.options.align, 8911 self = this; 8912 8913 popover.show(); 8914 }; 8915 8916 // Show popover 8917 ClockPicker.prototype.show = function (e) { 8918 // Not show again 8919 if (this.isShown) { 8920 return; 8921 } 8922 raiseCallback(this.options.beforeShow); 8923 $(':input').each(function () { 8924 $(this).attr('tabindex', -1); 8925 }); 8926 var self = this; 8927 // Initialize 8928 this.input.blur(); 8929 this.popover.addClass('picker--opened'); 8930 this.input.addClass('picker__input picker__input--active'); 8931 $(document.body).css('overflow', 'hidden'); 8932 // Get the time 8933 var value = ((this.input.prop('value') || this.options['default'] || '') + '').split(':'); 8934 if (this.options.twelvehour && !(typeof value[1] === 'undefined')) { 8935 if (value[1].indexOf("AM") > 0) { 8936 this.amOrPm = 'AM'; 8937 } else { 8938 this.amOrPm = 'PM'; 8939 } 8940 value[1] = value[1].replace("AM", "").replace("PM", ""); 8941 } 8942 if (value[0] === 'now') { 8943 var now = new Date(+new Date() + this.options.fromnow); 8944 value = [now.getHours(), now.getMinutes()]; 8945 if (this.options.twelvehour) { 8946 this.amOrPm = value[0] >= 12 && value[0] < 24 ? 'PM' : 'AM'; 8947 } 8948 } 8949 this.hours = +value[0] || 0; 8950 this.minutes = +value[1] || 0; 8951 this.spanHours.html(this.hours); 8952 this.spanMinutes.html(leadingZero(this.minutes)); 8953 if (!this.isAppended) { 8954 8955 // Append popover to input by default 8956 var containerEl = document.querySelector(this.options.container); 8957 if (this.options.container && containerEl) { 8958 containerEl.appendChild(this.popover[0]); 8959 } else { 8960 this.popover.insertAfter(this.input); 8961 } 8962 8963 if (this.options.twelvehour) { 8964 if (this.amOrPm === 'PM') { 8965 this.spanAmPm.children('#click-pm').addClass("text-primary"); 8966 this.spanAmPm.children('#click-am').removeClass("text-primary"); 8967 } else { 8968 this.spanAmPm.children('#click-am').addClass("text-primary"); 8969 this.spanAmPm.children('#click-pm').removeClass("text-primary"); 8970 } 8971 } 8972 // Reset position when resize 8973 $win.on('resize.clockpicker' + this.id, function () { 8974 if (self.isShown) { 8975 self.locate(); 8976 } 8977 }); 8978 this.isAppended = true; 8979 } 8980 // Toggle to hours view 8981 this.toggleView('hours'); 8982 // Set position 8983 this.locate(); 8984 this.isShown = true; 8985 // Hide when clicking or tabbing on any element except the clock and input 8986 $doc.on('click.clockpicker.' + this.id + ' focusin.clockpicker.' + this.id, function (e) { 8987 var target = $(e.target); 8988 if (target.closest(self.popover.find('.picker__wrap')).length === 0 && target.closest(self.input).length === 0) { 8989 self.hide(); 8990 } 8991 }); 8992 // Hide when ESC is pressed 8993 $doc.on('keyup.clockpicker.' + this.id, function (e) { 8994 if (e.keyCode === 27) { 8995 self.hide(); 8996 } 8997 }); 8998 raiseCallback(this.options.afterShow); 8999 }; 9000 // Hide popover 9001 ClockPicker.prototype.hide = function () { 9002 raiseCallback(this.options.beforeHide); 9003 this.input.removeClass('picker__input picker__input--active'); 9004 this.popover.removeClass('picker--opened'); 9005 $(document.body).css('overflow', 'visible'); 9006 this.isShown = false; 9007 $(':input').each(function (index) { 9008 $(this).attr('tabindex', index + 1); 9009 }); 9010 // Unbinding events on document 9011 $doc.off('click.clockpicker.' + this.id + ' focusin.clockpicker.' + this.id); 9012 $doc.off('keyup.clockpicker.' + this.id); 9013 this.popover.hide(); 9014 raiseCallback(this.options.afterHide); 9015 }; 9016 // Toggle to hours or minutes view 9017 ClockPicker.prototype.toggleView = function (view, delay) { 9018 var raiseAfterHourSelect = false; 9019 if (view === 'minutes' && $(this.hoursView).css("visibility") === "visible") { 9020 raiseCallback(this.options.beforeHourSelect); 9021 raiseAfterHourSelect = true; 9022 } 9023 var isHours = view === 'hours', 9024 nextView = isHours ? this.hoursView : this.minutesView, 9025 hideView = isHours ? this.minutesView : this.hoursView; 9026 this.currentView = view; 9027 9028 this.spanHours.toggleClass('text-primary', isHours); 9029 this.spanMinutes.toggleClass('text-primary', !isHours); 9030 9031 // Let's make transitions 9032 hideView.addClass('clockpicker-dial-out'); 9033 nextView.css('visibility', 'visible').removeClass('clockpicker-dial-out'); 9034 9035 // Reset clock hand 9036 this.resetClock(delay); 9037 9038 // After transitions ended 9039 clearTimeout(this.toggleViewTimer); 9040 this.toggleViewTimer = setTimeout(function () { 9041 hideView.css('visibility', 'hidden'); 9042 }, duration); 9043 9044 if (raiseAfterHourSelect) { 9045 raiseCallback(this.options.afterHourSelect); 9046 } 9047 }; 9048 9049 // Reset clock hand 9050 ClockPicker.prototype.resetClock = function (delay) { 9051 var view = this.currentView, 9052 value = this[view], 9053 isHours = view === 'hours', 9054 unit = Math.PI / (isHours ? 6 : 30), 9055 radian = value * unit, 9056 radius = isHours && value > 0 && value < 13 ? innerRadius : outerRadius, 9057 x = Math.sin(radian) * radius, 9058 y = -Math.cos(radian) * radius, 9059 self = this; 9060 9061 if (svgSupported && delay) { 9062 self.canvas.addClass('clockpicker-canvas-out'); 9063 setTimeout(function () { 9064 self.canvas.removeClass('clockpicker-canvas-out'); 9065 self.setHand(x, y); 9066 }, delay); 9067 } else this.setHand(x, y); 9068 }; 9069 9070 // Set clock hand to (x, y) 9071 ClockPicker.prototype.setHand = function (x, y, roundBy5, dragging) { 9072 var radian = Math.atan2(x, -y), 9073 isHours = this.currentView === 'hours', 9074 unit = Math.PI / (isHours || roundBy5 ? 6 : 30), 9075 z = Math.sqrt(x * x + y * y), 9076 options = this.options, 9077 inner = isHours && z < (outerRadius + innerRadius) / 2, 9078 radius = inner ? innerRadius : outerRadius, 9079 value; 9080 9081 if (options.twelvehour) { 9082 radius = outerRadius; 9083 } 9084 9085 // Radian should in range [0, 2PI] 9086 if (radian < 0) { 9087 radian = Math.PI * 2 + radian; 9088 } 9089 9090 // Get the round value 9091 value = Math.round(radian / unit); 9092 9093 // Get the round radian 9094 radian = value * unit; 9095 9096 // Correct the hours or minutes 9097 if (options.twelvehour) { 9098 if (isHours) { 9099 if (value === 0) value = 12; 9100 } else { 9101 if (roundBy5) value *= 5; 9102 if (value === 60) value = 0; 9103 } 9104 } else { 9105 if (isHours) { 9106 if (value === 12) value = 0; 9107 value = inner ? value === 0 ? 12 : value : value === 0 ? 0 : value + 12; 9108 } else { 9109 if (roundBy5) value *= 5; 9110 if (value === 60) value = 0; 9111 } 9112 } 9113 9114 // Once hours or minutes changed, vibrate the device 9115 if (this[this.currentView] !== value) { 9116 if (vibrate && this.options.vibrate) { 9117 // Do not vibrate too frequently 9118 if (!this.vibrateTimer) { 9119 navigator[vibrate](10); 9120 this.vibrateTimer = setTimeout($.proxy(function () { 9121 this.vibrateTimer = null; 9122 }, this), 100); 9123 } 9124 } 9125 } 9126 9127 this[this.currentView] = value; 9128 if (isHours) { 9129 this['spanHours'].html(value); 9130 } else { 9131 this['spanMinutes'].html(leadingZero(value)); 9132 } 9133 9134 // If svg is not supported, just add an active class to the tick 9135 if (!svgSupported) { 9136 this[isHours ? 'hoursView' : 'minutesView'].find('.clockpicker-tick').each(function () { 9137 var tick = $(this); 9138 tick.toggleClass('active', value === +tick.html()); 9139 }); 9140 return; 9141 } 9142 9143 // Set clock hand and others' position 9144 var cx1 = Math.sin(radian) * (radius - tickRadius), 9145 cy1 = -Math.cos(radian) * (radius - tickRadius), 9146 cx2 = Math.sin(radian) * radius, 9147 cy2 = -Math.cos(radian) * radius; 9148 this.hand.setAttribute('x2', cx1); 9149 this.hand.setAttribute('y2', cy1); 9150 this.bg.setAttribute('cx', cx2); 9151 this.bg.setAttribute('cy', cy2); 9152 }; 9153 9154 // Hours and minutes are selected 9155 ClockPicker.prototype.done = function () { 9156 raiseCallback(this.options.beforeDone); 9157 this.hide(); 9158 this.label.addClass('active'); 9159 9160 var last = this.input.prop('value'), 9161 value = leadingZero(this.hours) + ':' + leadingZero(this.minutes); 9162 if (this.options.twelvehour) { 9163 value = value + this.amOrPm; 9164 } 9165 9166 this.input.prop('value', value); 9167 if (value !== last) { 9168 this.input.triggerHandler('change'); 9169 if (!this.isInput) { 9170 this.element.trigger('change'); 9171 } 9172 } 9173 9174 if (this.options.autoclose) this.input.trigger('blur'); 9175 9176 raiseCallback(this.options.afterDone); 9177 }; 9178 9179 // Clear input field 9180 ClockPicker.prototype.clear = function () { 9181 this.hide(); 9182 this.label.removeClass('active'); 9183 9184 var last = this.input.prop('value'), 9185 value = ''; 9186 9187 this.input.prop('value', value); 9188 if (value !== last) { 9189 this.input.triggerHandler('change'); 9190 if (!this.isInput) { 9191 this.element.trigger('change'); 9192 } 9193 } 9194 9195 if (this.options.autoclose) { 9196 this.input.trigger('blur'); 9197 } 9198 }; 9199 9200 // Remove clockpicker from input 9201 ClockPicker.prototype.remove = function () { 9202 this.element.removeData('clockpicker'); 9203 this.input.off('focus.clockpicker click.clockpicker'); 9204 if (this.isShown) { 9205 this.hide(); 9206 } 9207 if (this.isAppended) { 9208 $win.off('resize.clockpicker' + this.id); 9209 this.popover.remove(); 9210 } 9211 }; 9212 9213 // Extends $.fn.clockpicker 9214 $.fn.pickatime = function (option) { 9215 var args = Array.prototype.slice.call(arguments, 1); 9216 return this.each(function () { 9217 var $this = $(this), 9218 data = $this.data('clockpicker'); 9219 if (!data) { 9220 var options = $.extend({}, ClockPicker.DEFAULTS, $this.data(), typeof option == 'object' && option); 9221 $this.data('clockpicker', new ClockPicker($this, options)); 9222 } else { 9223 // Manual operatsions. show, hide, remove, e.g. 9224 if (typeof data[option] === 'function') { 9225 data[option].apply(data, args); 9226 } 9227 } 9228 }); 9229 }; 9230 })(jQuery); 9231 ;(function ($) { 9232 9233 $.fn.characterCounter = function () { 9234 return this.each(function () { 9235 var $input = $(this); 9236 var $counterElement = $input.parent().find('span[class="character-counter"]'); 9237 9238 // character counter has already been added appended to the parent container 9239 if ($counterElement.length) { 9240 return; 9241 } 9242 9243 var itHasLengthAttribute = $input.attr('data-length') !== undefined; 9244 9245 if (itHasLengthAttribute) { 9246 $input.on('input', updateCounter); 9247 $input.on('focus', updateCounter); 9248 $input.on('blur', removeCounterElement); 9249 9250 addCounterElement($input); 9251 } 9252 }); 9253 }; 9254 9255 function updateCounter() { 9256 var maxLength = +$(this).attr('data-length'), 9257 actualLength = +$(this).val().length, 9258 isValidLength = actualLength <= maxLength; 9259 9260 $(this).parent().find('span[class="character-counter"]').html(actualLength + '/' + maxLength); 9261 9262 addInputStyle(isValidLength, $(this)); 9263 } 9264 9265 function addCounterElement($input) { 9266 var $counterElement = $input.parent().find('span[class="character-counter"]'); 9267 9268 if ($counterElement.length) { 9269 return; 9270 } 9271 9272 $counterElement = $('<span/>').addClass('character-counter').css('float', 'right').css('font-size', '12px').css('height', 1); 9273 9274 $input.parent().append($counterElement); 9275 } 9276 9277 function removeCounterElement() { 9278 $(this).parent().find('span[class="character-counter"]').html(''); 9279 } 9280 9281 function addInputStyle(isValidLength, $input) { 9282 var inputHasInvalidClass = $input.hasClass('invalid'); 9283 if (isValidLength && inputHasInvalidClass) { 9284 $input.removeClass('invalid'); 9285 } else if (!isValidLength && !inputHasInvalidClass) { 9286 $input.removeClass('valid'); 9287 $input.addClass('invalid'); 9288 } 9289 } 9290 9291 $(document).ready(function () { 9292 $('input, textarea').characterCounter(); 9293 }); 9294 })(jQuery); 9295 ;(function ($) { 9296 9297 var methods = { 9298 9299 init: function (options) { 9300 var defaults = { 9301 duration: 200, // ms 9302 dist: -100, // zoom scale TODO: make this more intuitive as an option 9303 shift: 0, // spacing for center image 9304 padding: 0, // Padding between non center items 9305 fullWidth: false, // Change to full width styles 9306 indicators: false, // Toggle indicators 9307 noWrap: false, // Don't wrap around and cycle through items. 9308 onCycleTo: null // Callback for when a new slide is cycled to. 9309 }; 9310 options = $.extend(defaults, options); 9311 var namespace = Materialize.objectSelectorString($(this)); 9312 9313 return this.each(function (i) { 9314 9315 var images, item_width, item_height, offset, center, pressed, dim, count, reference, referenceY, amplitude, target, velocity, scrolling, xform, frame, timestamp, ticker, dragged, vertical_dragged; 9316 var $indicators = $('<ul class="indicators"></ul>'); 9317 var scrollingTimeout = null; 9318 var oneTimeCallback = null; 9319 9320 // Initialize 9321 var view = $(this); 9322 var hasMultipleSlides = view.find('.carousel-item').length > 1; 9323 var showIndicators = (view.attr('data-indicators') || options.indicators) && hasMultipleSlides; 9324 var noWrap = view.attr('data-no-wrap') || options.noWrap || !hasMultipleSlides; 9325 var uniqueNamespace = view.attr('data-namespace') || namespace + i; 9326 view.attr('data-namespace', uniqueNamespace); 9327 9328 // Options 9329 var setCarouselHeight = function (imageOnly) { 9330 var firstSlide = view.find('.carousel-item.active').length ? view.find('.carousel-item.active').first() : view.find('.carousel-item').first(); 9331 var firstImage = firstSlide.find('img').first(); 9332 if (firstImage.length) { 9333 if (firstImage[0].complete) { 9334 // If image won't trigger the load event 9335 var imageHeight = firstImage.height(); 9336 if (imageHeight > 0) { 9337 view.css('height', firstImage.height()); 9338 } else { 9339 // If image still has no height, use the natural dimensions to calculate 9340 var naturalWidth = firstImage[0].naturalWidth; 9341 var naturalHeight = firstImage[0].naturalHeight; 9342 var adjustedHeight = view.width() / naturalWidth * naturalHeight; 9343 view.css('height', adjustedHeight); 9344 } 9345 } else { 9346 // Get height when image is loaded normally 9347 firstImage.on('load', function () { 9348 view.css('height', $(this).height()); 9349 }); 9350 } 9351 } else if (!imageOnly) { 9352 var slideHeight = firstSlide.height(); 9353 view.css('height', slideHeight); 9354 } 9355 }; 9356 9357 if (options.fullWidth) { 9358 options.dist = 0; 9359 setCarouselHeight(); 9360 9361 // Offset fixed items when indicators. 9362 if (showIndicators) { 9363 view.find('.carousel-fixed-item').addClass('with-indicators'); 9364 } 9365 } 9366 9367 // Don't double initialize. 9368 if (view.hasClass('initialized')) { 9369 // Recalculate variables 9370 $(window).trigger('resize'); 9371 9372 // Redraw carousel. 9373 view.trigger('carouselNext', [0.000001]); 9374 return true; 9375 } 9376 9377 view.addClass('initialized'); 9378 pressed = false; 9379 offset = target = 0; 9380 images = []; 9381 item_width = view.find('.carousel-item').first().innerWidth(); 9382 item_height = view.find('.carousel-item').first().innerHeight(); 9383 dim = item_width * 2 + options.padding; 9384 9385 view.find('.carousel-item').each(function (i) { 9386 images.push($(this)[0]); 9387 if (showIndicators) { 9388 var $indicator = $('<li class="indicator-item"></li>'); 9389 9390 // Add active to first by default. 9391 if (i === 0) { 9392 $indicator.addClass('active'); 9393 } 9394 9395 // Handle clicks on indicators. 9396 $indicator.click(function (e) { 9397 e.stopPropagation(); 9398 9399 var index = $(this).index(); 9400 cycleTo(index); 9401 }); 9402 $indicators.append($indicator); 9403 } 9404 }); 9405 9406 if (showIndicators) { 9407 view.append($indicators); 9408 } 9409 count = images.length; 9410 9411 function setupEvents() { 9412 if (typeof window.ontouchstart !== 'undefined') { 9413 view.on('touchstart.carousel', tap); 9414 view.on('touchmove.carousel', drag); 9415 view.on('touchend.carousel', release); 9416 } 9417 view.on('mousedown.carousel', tap); 9418 view.on('mousemove.carousel', drag); 9419 view.on('mouseup.carousel', release); 9420 view.on('mouseleave.carousel', release); 9421 view.on('click.carousel', click); 9422 } 9423 9424 function xpos(e) { 9425 // touch event 9426 if (e.targetTouches && e.targetTouches.length >= 1) { 9427 return e.targetTouches[0].clientX; 9428 } 9429 9430 // mouse event 9431 return e.clientX; 9432 } 9433 9434 function ypos(e) { 9435 // touch event 9436 if (e.targetTouches && e.targetTouches.length >= 1) { 9437 return e.targetTouches[0].clientY; 9438 } 9439 9440 // mouse event 9441 return e.clientY; 9442 } 9443 9444 function wrap(x) { 9445 return x >= count ? x % count : x < 0 ? wrap(count + x % count) : x; 9446 } 9447 9448 function scroll(x) { 9449 // Track scrolling state 9450 scrolling = true; 9451 if (!view.hasClass('scrolling')) { 9452 view.addClass('scrolling'); 9453 } 9454 if (scrollingTimeout != null) { 9455 window.clearTimeout(scrollingTimeout); 9456 } 9457 scrollingTimeout = window.setTimeout(function () { 9458 scrolling = false; 9459 view.removeClass('scrolling'); 9460 }, options.duration); 9461 9462 // Start actual scroll 9463 var i, half, delta, dir, tween, el, alignment, xTranslation; 9464 var lastCenter = center; 9465 9466 offset = typeof x === 'number' ? x : offset; 9467 center = Math.floor((offset + dim / 2) / dim); 9468 delta = offset - center * dim; 9469 dir = delta < 0 ? 1 : -1; 9470 tween = -dir * delta * 2 / dim; 9471 half = count >> 1; 9472 9473 if (!options.fullWidth) { 9474 alignment = 'translateX(' + (view[0].clientWidth - item_width) / 2 + 'px) '; 9475 alignment += 'translateY(' + (view[0].clientHeight - item_height) / 2 + 'px)'; 9476 } else { 9477 alignment = 'translateX(0)'; 9478 } 9479 9480 // Set indicator active 9481 if (showIndicators) { 9482 var diff = center % count; 9483 var activeIndicator = $indicators.find('.indicator-item.active'); 9484 if (activeIndicator.index() !== diff) { 9485 activeIndicator.removeClass('active'); 9486 $indicators.find('.indicator-item').eq(diff).addClass('active'); 9487 } 9488 } 9489 9490 // center 9491 // Don't show wrapped items. 9492 if (!noWrap || center >= 0 && center < count) { 9493 el = images[wrap(center)]; 9494 9495 // Add active class to center item. 9496 if (!$(el).hasClass('active')) { 9497 view.find('.carousel-item').removeClass('active'); 9498 $(el).addClass('active'); 9499 } 9500 el.style[xform] = alignment + ' translateX(' + -delta / 2 + 'px)' + ' translateX(' + dir * options.shift * tween * i + 'px)' + ' translateZ(' + options.dist * tween + 'px)'; 9501 el.style.zIndex = 0; 9502 if (options.fullWidth) { 9503 tweenedOpacity = 1; 9504 } else { 9505 tweenedOpacity = 1 - 0.2 * tween; 9506 } 9507 el.style.opacity = tweenedOpacity; 9508 el.style.display = 'block'; 9509 } 9510 9511 for (i = 1; i <= half; ++i) { 9512 // right side 9513 if (options.fullWidth) { 9514 zTranslation = options.dist; 9515 tweenedOpacity = i === half && delta < 0 ? 1 - tween : 1; 9516 } else { 9517 zTranslation = options.dist * (i * 2 + tween * dir); 9518 tweenedOpacity = 1 - 0.2 * (i * 2 + tween * dir); 9519 } 9520 // Don't show wrapped items. 9521 if (!noWrap || center + i < count) { 9522 el = images[wrap(center + i)]; 9523 el.style[xform] = alignment + ' translateX(' + (options.shift + (dim * i - delta) / 2) + 'px)' + ' translateZ(' + zTranslation + 'px)'; 9524 el.style.zIndex = -i; 9525 el.style.opacity = tweenedOpacity; 9526 el.style.display = 'block'; 9527 } 9528 9529 // left side 9530 if (options.fullWidth) { 9531 zTranslation = options.dist; 9532 tweenedOpacity = i === half && delta > 0 ? 1 - tween : 1; 9533 } else { 9534 zTranslation = options.dist * (i * 2 - tween * dir); 9535 tweenedOpacity = 1 - 0.2 * (i * 2 - tween * dir); 9536 } 9537 // Don't show wrapped items. 9538 if (!noWrap || center - i >= 0) { 9539 el = images[wrap(center - i)]; 9540 el.style[xform] = alignment + ' translateX(' + (-options.shift + (-dim * i - delta) / 2) + 'px)' + ' translateZ(' + zTranslation + 'px)'; 9541 el.style.zIndex = -i; 9542 el.style.opacity = tweenedOpacity; 9543 el.style.display = 'block'; 9544 } 9545 } 9546 9547 // center 9548 // Don't show wrapped items. 9549 if (!noWrap || center >= 0 && center < count) { 9550 el = images[wrap(center)]; 9551 el.style[xform] = alignment + ' translateX(' + -delta / 2 + 'px)' + ' translateX(' + dir * options.shift * tween + 'px)' + ' translateZ(' + options.dist * tween + 'px)'; 9552 el.style.zIndex = 0; 9553 if (options.fullWidth) { 9554 tweenedOpacity = 1; 9555 } else { 9556 tweenedOpacity = 1 - 0.2 * tween; 9557 } 9558 el.style.opacity = tweenedOpacity; 9559 el.style.display = 'block'; 9560 } 9561 9562 // onCycleTo callback 9563 if (lastCenter !== center && typeof options.onCycleTo === "function") { 9564 var $curr_item = view.find('.carousel-item').eq(wrap(center)); 9565 options.onCycleTo.call(this, $curr_item, dragged); 9566 } 9567 9568 // One time callback 9569 if (typeof oneTimeCallback === "function") { 9570 oneTimeCallback.call(this, $curr_item, dragged); 9571 oneTimeCallback = null; 9572 } 9573 } 9574 9575 function track() { 9576 var now, elapsed, delta, v; 9577 9578 now = Date.now(); 9579 elapsed = now - timestamp; 9580 timestamp = now; 9581 delta = offset - frame; 9582 frame = offset; 9583 9584 v = 1000 * delta / (1 + elapsed); 9585 velocity = 0.8 * v + 0.2 * velocity; 9586 } 9587 9588 function autoScroll() { 9589 var elapsed, delta; 9590 9591 if (amplitude) { 9592 elapsed = Date.now() - timestamp; 9593 delta = amplitude * Math.exp(-elapsed / options.duration); 9594 if (delta > 2 || delta < -2) { 9595 scroll(target - delta); 9596 requestAnimationFrame(autoScroll); 9597 } else { 9598 scroll(target); 9599 } 9600 } 9601 } 9602 9603 function click(e) { 9604 // Disable clicks if carousel was dragged. 9605 if (dragged) { 9606 e.preventDefault(); 9607 e.stopPropagation(); 9608 return false; 9609 } else if (!options.fullWidth) { 9610 var clickedIndex = $(e.target).closest('.carousel-item').index(); 9611 var diff = wrap(center) - clickedIndex; 9612 9613 // Disable clicks if carousel was shifted by click 9614 if (diff !== 0) { 9615 e.preventDefault(); 9616 e.stopPropagation(); 9617 } 9618 cycleTo(clickedIndex); 9619 } 9620 } 9621 9622 function cycleTo(n) { 9623 var diff = center % count - n; 9624 9625 // Account for wraparound. 9626 if (!noWrap) { 9627 if (diff < 0) { 9628 if (Math.abs(diff + count) < Math.abs(diff)) { 9629 diff += count; 9630 } 9631 } else if (diff > 0) { 9632 if (Math.abs(diff - count) < diff) { 9633 diff -= count; 9634 } 9635 } 9636 } 9637 9638 // Call prev or next accordingly. 9639 if (diff < 0) { 9640 view.trigger('carouselNext', [Math.abs(diff)]); 9641 } else if (diff > 0) { 9642 view.trigger('carouselPrev', [diff]); 9643 } 9644 } 9645 9646 function tap(e) { 9647 // Fixes firefox draggable image bug 9648 if (e.type === 'mousedown' && $(e.target).is('img')) { 9649 e.preventDefault(); 9650 } 9651 pressed = true; 9652 dragged = false; 9653 vertical_dragged = false; 9654 reference = xpos(e); 9655 referenceY = ypos(e); 9656 9657 velocity = amplitude = 0; 9658 frame = offset; 9659 timestamp = Date.now(); 9660 clearInterval(ticker); 9661 ticker = setInterval(track, 100); 9662 } 9663 9664 function drag(e) { 9665 var x, delta, deltaY; 9666 if (pressed) { 9667 x = xpos(e); 9668 y = ypos(e); 9669 delta = reference - x; 9670 deltaY = Math.abs(referenceY - y); 9671 if (deltaY < 30 && !vertical_dragged) { 9672 // If vertical scrolling don't allow dragging. 9673 if (delta > 2 || delta < -2) { 9674 dragged = true; 9675 reference = x; 9676 scroll(offset + delta); 9677 } 9678 } else if (dragged) { 9679 // If dragging don't allow vertical scroll. 9680 e.preventDefault(); 9681 e.stopPropagation(); 9682 return false; 9683 } else { 9684 // Vertical scrolling. 9685 vertical_dragged = true; 9686 } 9687 } 9688 9689 if (dragged) { 9690 // If dragging don't allow vertical scroll. 9691 e.preventDefault(); 9692 e.stopPropagation(); 9693 return false; 9694 } 9695 } 9696 9697 function release(e) { 9698 if (pressed) { 9699 pressed = false; 9700 } else { 9701 return; 9702 } 9703 9704 clearInterval(ticker); 9705 target = offset; 9706 if (velocity > 10 || velocity < -10) { 9707 amplitude = 0.9 * velocity; 9708 target = offset + amplitude; 9709 } 9710 target = Math.round(target / dim) * dim; 9711 9712 // No wrap of items. 9713 if (noWrap) { 9714 if (target >= dim * (count - 1)) { 9715 target = dim * (count - 1); 9716 } else if (target < 0) { 9717 target = 0; 9718 } 9719 } 9720 amplitude = target - offset; 9721 timestamp = Date.now(); 9722 requestAnimationFrame(autoScroll); 9723 9724 if (dragged) { 9725 e.preventDefault(); 9726 e.stopPropagation(); 9727 } 9728 return false; 9729 } 9730 9731 xform = 'transform'; 9732 ['webkit', 'Moz', 'O', 'ms'].every(function (prefix) { 9733 var e = prefix + 'Transform'; 9734 if (typeof document.body.style[e] !== 'undefined') { 9735 xform = e; 9736 return false; 9737 } 9738 return true; 9739 }); 9740 9741 var throttledResize = Materialize.throttle(function () { 9742 if (options.fullWidth) { 9743 item_width = view.find('.carousel-item').first().innerWidth(); 9744 var imageHeight = view.find('.carousel-item.active').height(); 9745 dim = item_width * 2 + options.padding; 9746 offset = center * 2 * item_width; 9747 target = offset; 9748 setCarouselHeight(true); 9749 } else { 9750 scroll(); 9751 } 9752 }, 200); 9753 $(window).off('resize.carousel-' + uniqueNamespace).on('resize.carousel-' + uniqueNamespace, throttledResize); 9754 9755 setupEvents(); 9756 scroll(offset); 9757 9758 $(this).on('carouselNext', function (e, n, callback) { 9759 if (n === undefined) { 9760 n = 1; 9761 } 9762 if (typeof callback === "function") { 9763 oneTimeCallback = callback; 9764 } 9765 9766 target = dim * Math.round(offset / dim) + dim * n; 9767 if (offset !== target) { 9768 amplitude = target - offset; 9769 timestamp = Date.now(); 9770 requestAnimationFrame(autoScroll); 9771 } 9772 }); 9773 9774 $(this).on('carouselPrev', function (e, n, callback) { 9775 if (n === undefined) { 9776 n = 1; 9777 } 9778 if (typeof callback === "function") { 9779 oneTimeCallback = callback; 9780 } 9781 9782 target = dim * Math.round(offset / dim) - dim * n; 9783 if (offset !== target) { 9784 amplitude = target - offset; 9785 timestamp = Date.now(); 9786 requestAnimationFrame(autoScroll); 9787 } 9788 }); 9789 9790 $(this).on('carouselSet', function (e, n, callback) { 9791 if (n === undefined) { 9792 n = 0; 9793 } 9794 if (typeof callback === "function") { 9795 oneTimeCallback = callback; 9796 } 9797 9798 cycleTo(n); 9799 }); 9800 }); 9801 }, 9802 next: function (n, callback) { 9803 $(this).trigger('carouselNext', [n, callback]); 9804 }, 9805 prev: function (n, callback) { 9806 $(this).trigger('carouselPrev', [n, callback]); 9807 }, 9808 set: function (n, callback) { 9809 $(this).trigger('carouselSet', [n, callback]); 9810 }, 9811 destroy: function () { 9812 var uniqueNamespace = $(this).attr('data-namespace'); 9813 $(this).removeAttr('data-namespace'); 9814 $(this).removeClass('initialized'); 9815 $(this).find('.indicators').remove(); 9816 9817 // Remove event handlers 9818 $(this).off('carouselNext carouselPrev carouselSet'); 9819 $(window).off('resize.carousel-' + uniqueNamespace); 9820 if (typeof window.ontouchstart !== 'undefined') { 9821 $(this).off('touchstart.carousel touchmove.carousel touchend.carousel'); 9822 } 9823 $(this).off('mousedown.carousel mousemove.carousel mouseup.carousel mouseleave.carousel click.carousel'); 9824 } 9825 }; 9826 9827 $.fn.carousel = function (methodOrOptions) { 9828 if (methods[methodOrOptions]) { 9829 return methods[methodOrOptions].apply(this, Array.prototype.slice.call(arguments, 1)); 9830 } else if (typeof methodOrOptions === 'object' || !methodOrOptions) { 9831 // Default to "init" 9832 return methods.init.apply(this, arguments); 9833 } else { 9834 $.error('Method ' + methodOrOptions + ' does not exist on jQuery.carousel'); 9835 } 9836 }; // Plugin end 9837 })(jQuery); 9838 ;(function ($) { 9839 9840 var methods = { 9841 init: function (options) { 9842 return this.each(function () { 9843 var origin = $('#' + $(this).attr('data-activates')); 9844 var screen = $('body'); 9845 9846 // Creating tap target 9847 var tapTargetEl = $(this); 9848 var tapTargetWrapper = tapTargetEl.parent('.tap-target-wrapper'); 9849 var tapTargetWave = tapTargetWrapper.find('.tap-target-wave'); 9850 var tapTargetOriginEl = tapTargetWrapper.find('.tap-target-origin'); 9851 var tapTargetContentEl = tapTargetEl.find('.tap-target-content'); 9852 9853 // Creating wrapper 9854 if (!tapTargetWrapper.length) { 9855 tapTargetWrapper = tapTargetEl.wrap($('<div class="tap-target-wrapper"></div>')).parent(); 9856 } 9857 9858 // Creating content 9859 if (!tapTargetContentEl.length) { 9860 tapTargetContentEl = $('<div class="tap-target-content"></div>'); 9861 tapTargetEl.append(tapTargetContentEl); 9862 } 9863 9864 // Creating foreground wave 9865 if (!tapTargetWave.length) { 9866 tapTargetWave = $('<div class="tap-target-wave"></div>'); 9867 9868 // Creating origin 9869 if (!tapTargetOriginEl.length) { 9870 tapTargetOriginEl = origin.clone(true, true); 9871 tapTargetOriginEl.addClass('tap-target-origin'); 9872 tapTargetOriginEl.removeAttr('id'); 9873 tapTargetOriginEl.removeAttr('style'); 9874 tapTargetWave.append(tapTargetOriginEl); 9875 } 9876 9877 tapTargetWrapper.append(tapTargetWave); 9878 } 9879 9880 // Open 9881 var openTapTarget = function () { 9882 if (tapTargetWrapper.is('.open')) { 9883 return; 9884 } 9885 9886 // Adding open class 9887 tapTargetWrapper.addClass('open'); 9888 9889 setTimeout(function () { 9890 tapTargetOriginEl.off('click.tapTarget').on('click.tapTarget', function (e) { 9891 closeTapTarget(); 9892 tapTargetOriginEl.off('click.tapTarget'); 9893 }); 9894 9895 $(document).off('click.tapTarget').on('click.tapTarget', function (e) { 9896 closeTapTarget(); 9897 $(document).off('click.tapTarget'); 9898 }); 9899 9900 var throttledCalc = Materialize.throttle(function () { 9901 calculateTapTarget(); 9902 }, 200); 9903 $(window).off('resize.tapTarget').on('resize.tapTarget', throttledCalc); 9904 }, 0); 9905 }; 9906 9907 // Close 9908 var closeTapTarget = function () { 9909 if (!tapTargetWrapper.is('.open')) { 9910 return; 9911 } 9912 9913 tapTargetWrapper.removeClass('open'); 9914 tapTargetOriginEl.off('click.tapTarget'); 9915 $(document).off('click.tapTarget'); 9916 $(window).off('resize.tapTarget'); 9917 }; 9918 9919 // Pre calculate 9920 var calculateTapTarget = function () { 9921 // Element or parent is fixed position? 9922 var isFixed = origin.css('position') === 'fixed'; 9923 if (!isFixed) { 9924 var parents = origin.parents(); 9925 for (var i = 0; i < parents.length; i++) { 9926 isFixed = $(parents[i]).css('position') == 'fixed'; 9927 if (isFixed) { 9928 break; 9929 } 9930 } 9931 } 9932 9933 // Calculating origin 9934 var originWidth = origin.outerWidth(); 9935 var originHeight = origin.outerHeight(); 9936 var originTop = isFixed ? origin.offset().top - $(document).scrollTop() : origin.offset().top; 9937 var originLeft = isFixed ? origin.offset().left - $(document).scrollLeft() : origin.offset().left; 9938 9939 // Calculating screen 9940 var windowWidth = $(window).width(); 9941 var windowHeight = $(window).height(); 9942 var centerX = windowWidth / 2; 9943 var centerY = windowHeight / 2; 9944 var isLeft = originLeft <= centerX; 9945 var isRight = originLeft > centerX; 9946 var isTop = originTop <= centerY; 9947 var isBottom = originTop > centerY; 9948 var isCenterX = originLeft >= windowWidth * 0.25 && originLeft <= windowWidth * 0.75; 9949 var isCenterY = originTop >= windowHeight * 0.25 && originTop <= windowHeight * 0.75; 9950 9951 // Calculating tap target 9952 var tapTargetWidth = tapTargetEl.outerWidth(); 9953 var tapTargetHeight = tapTargetEl.outerHeight(); 9954 var tapTargetTop = originTop + originHeight / 2 - tapTargetHeight / 2; 9955 var tapTargetLeft = originLeft + originWidth / 2 - tapTargetWidth / 2; 9956 var tapTargetPosition = isFixed ? 'fixed' : 'absolute'; 9957 9958 // Calculating content 9959 var tapTargetTextWidth = isCenterX ? tapTargetWidth : tapTargetWidth / 2 + originWidth; 9960 var tapTargetTextHeight = tapTargetHeight / 2; 9961 var tapTargetTextTop = isTop ? tapTargetHeight / 2 : 0; 9962 var tapTargetTextBottom = 0; 9963 var tapTargetTextLeft = isLeft && !isCenterX ? tapTargetWidth / 2 - originWidth : 0; 9964 var tapTargetTextRight = 0; 9965 var tapTargetTextPadding = originWidth; 9966 var tapTargetTextAlign = isBottom ? 'bottom' : 'top'; 9967 9968 // Calculating wave 9969 var tapTargetWaveWidth = originWidth > originHeight ? originWidth * 2 : originWidth * 2; 9970 var tapTargetWaveHeight = tapTargetWaveWidth; 9971 var tapTargetWaveTop = tapTargetHeight / 2 - tapTargetWaveHeight / 2; 9972 var tapTargetWaveLeft = tapTargetWidth / 2 - tapTargetWaveWidth / 2; 9973 9974 // Setting tap target 9975 var tapTargetWrapperCssObj = {}; 9976 tapTargetWrapperCssObj.top = isTop ? tapTargetTop : ''; 9977 tapTargetWrapperCssObj.right = isRight ? windowWidth - tapTargetLeft - tapTargetWidth : ''; 9978 tapTargetWrapperCssObj.bottom = isBottom ? windowHeight - tapTargetTop - tapTargetHeight : ''; 9979 tapTargetWrapperCssObj.left = isLeft ? tapTargetLeft : ''; 9980 tapTargetWrapperCssObj.position = tapTargetPosition; 9981 tapTargetWrapper.css(tapTargetWrapperCssObj); 9982 9983 // Setting content 9984 tapTargetContentEl.css({ 9985 width: tapTargetTextWidth, 9986 height: tapTargetTextHeight, 9987 top: tapTargetTextTop, 9988 right: tapTargetTextRight, 9989 bottom: tapTargetTextBottom, 9990 left: tapTargetTextLeft, 9991 padding: tapTargetTextPadding, 9992 verticalAlign: tapTargetTextAlign 9993 }); 9994 9995 // Setting wave 9996 tapTargetWave.css({ 9997 top: tapTargetWaveTop, 9998 left: tapTargetWaveLeft, 9999 width: tapTargetWaveWidth, 10000 height: tapTargetWaveHeight 10001 }); 10002 }; 10003 10004 if (options == 'open') { 10005 calculateTapTarget(); 10006 openTapTarget(); 10007 } 10008 10009 if (options == 'close') closeTapTarget(); 10010 }); 10011 }, 10012 open: function () {}, 10013 close: function () {} 10014 }; 10015 10016 $.fn.tapTarget = function (methodOrOptions) { 10017 if (methods[methodOrOptions] || typeof methodOrOptions === 'object') return methods.init.apply(this, arguments); 10018 10019 $.error('Method ' + methodOrOptions + ' does not exist on jQuery.tap-target'); 10020 }; 10021 })(jQuery);