Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

9046 lines
338KB

  1. /*!
  2. * Materialize v0.99.0 (http://materializecss.com)
  3. * Copyright 2014-2017 Materialize
  4. * MIT License (https://raw.githubusercontent.com/Dogfalo/materialize/master/LICENSE)
  5. */
  6. // Check for jQuery.
  7. if (typeof(jQuery) === 'undefined') {
  8. var jQuery;
  9. // Check if require is a defined function.
  10. if (typeof(require) === 'function') {
  11. jQuery = $ = require('jquery');
  12. // Else use the dollar sign alias.
  13. } else {
  14. jQuery = $;
  15. }
  16. }
  17. ;/*
  18. * jQuery Easing v1.4.0 - http://gsgd.co.uk/sandbox/jquery/easing/
  19. * Open source under the BSD License.
  20. * Copyright © 2008 George McGinley Smith
  21. * All rights reserved.
  22. * https://raw.github.com/gdsmith/jquery-easing/master/LICENSE
  23. */
  24. (function (factory) {
  25. if (typeof define === "function" && define.amd) {
  26. define(['jquery'], function ($) {
  27. return factory($);
  28. });
  29. } else if (typeof module === "object" && typeof module.exports === "object") {
  30. exports = factory(require('jquery'));
  31. } else {
  32. factory(jQuery);
  33. }
  34. })(function($){
  35. // Preserve the original jQuery "swing" easing as "jswing"
  36. $.easing['jswing'] = $.easing['swing'];
  37. var pow = Math.pow,
  38. sqrt = Math.sqrt,
  39. sin = Math.sin,
  40. cos = Math.cos,
  41. PI = Math.PI,
  42. c1 = 1.70158,
  43. c2 = c1 * 1.525,
  44. c3 = c1 + 1,
  45. c4 = ( 2 * PI ) / 3,
  46. c5 = ( 2 * PI ) / 4.5;
  47. // x is the fraction of animation progress, in the range 0..1
  48. function bounceOut(x) {
  49. var n1 = 7.5625,
  50. d1 = 2.75;
  51. if ( x < 1/d1 ) {
  52. return n1*x*x;
  53. } else if ( x < 2/d1 ) {
  54. return n1*(x-=(1.5/d1))*x + .75;
  55. } else if ( x < 2.5/d1 ) {
  56. return n1*(x-=(2.25/d1))*x + .9375;
  57. } else {
  58. return n1*(x-=(2.625/d1))*x + .984375;
  59. }
  60. }
  61. $.extend( $.easing,
  62. {
  63. def: 'easeOutQuad',
  64. swing: function (x) {
  65. return $.easing[$.easing.def](x);
  66. },
  67. easeInQuad: function (x) {
  68. return x * x;
  69. },
  70. easeOutQuad: function (x) {
  71. return 1 - ( 1 - x ) * ( 1 - x );
  72. },
  73. easeInOutQuad: function (x) {
  74. return x < 0.5 ?
  75. 2 * x * x :
  76. 1 - pow( -2 * x + 2, 2 ) / 2;
  77. },
  78. easeInCubic: function (x) {
  79. return x * x * x;
  80. },
  81. easeOutCubic: function (x) {
  82. return 1 - pow( 1 - x, 3 );
  83. },
  84. easeInOutCubic: function (x) {
  85. return x < 0.5 ?
  86. 4 * x * x * x :
  87. 1 - pow( -2 * x + 2, 3 ) / 2;
  88. },
  89. easeInQuart: function (x) {
  90. return x * x * x * x;
  91. },
  92. easeOutQuart: function (x) {
  93. return 1 - pow( 1 - x, 4 );
  94. },
  95. easeInOutQuart: function (x) {
  96. return x < 0.5 ?
  97. 8 * x * x * x * x :
  98. 1 - pow( -2 * x + 2, 4 ) / 2;
  99. },
  100. easeInQuint: function (x) {
  101. return x * x * x * x * x;
  102. },
  103. easeOutQuint: function (x) {
  104. return 1 - pow( 1 - x, 5 );
  105. },
  106. easeInOutQuint: function (x) {
  107. return x < 0.5 ?
  108. 16 * x * x * x * x * x :
  109. 1 - pow( -2 * x + 2, 5 ) / 2;
  110. },
  111. easeInSine: function (x) {
  112. return 1 - cos( x * PI/2 );
  113. },
  114. easeOutSine: function (x) {
  115. return sin( x * PI/2 );
  116. },
  117. easeInOutSine: function (x) {
  118. return -( cos( PI * x ) - 1 ) / 2;
  119. },
  120. easeInExpo: function (x) {
  121. return x === 0 ? 0 : pow( 2, 10 * x - 10 );
  122. },
  123. easeOutExpo: function (x) {
  124. return x === 1 ? 1 : 1 - pow( 2, -10 * x );
  125. },
  126. easeInOutExpo: function (x) {
  127. return x === 0 ? 0 : x === 1 ? 1 : x < 0.5 ?
  128. pow( 2, 20 * x - 10 ) / 2 :
  129. ( 2 - pow( 2, -20 * x + 10 ) ) / 2;
  130. },
  131. easeInCirc: function (x) {
  132. return 1 - sqrt( 1 - pow( x, 2 ) );
  133. },
  134. easeOutCirc: function (x) {
  135. return sqrt( 1 - pow( x - 1, 2 ) );
  136. },
  137. easeInOutCirc: function (x) {
  138. return x < 0.5 ?
  139. ( 1 - sqrt( 1 - pow( 2 * x, 2 ) ) ) / 2 :
  140. ( sqrt( 1 - pow( -2 * x + 2, 2 ) ) + 1 ) / 2;
  141. },
  142. easeInElastic: function (x) {
  143. return x === 0 ? 0 : x === 1 ? 1 :
  144. -pow( 2, 10 * x - 10 ) * sin( ( x * 10 - 10.75 ) * c4 );
  145. },
  146. easeOutElastic: function (x) {
  147. return x === 0 ? 0 : x === 1 ? 1 :
  148. pow( 2, -10 * x ) * sin( ( x * 10 - 0.75 ) * c4 ) + 1;
  149. },
  150. easeInOutElastic: function (x) {
  151. return x === 0 ? 0 : x === 1 ? 1 : x < 0.5 ?
  152. -( pow( 2, 20 * x - 10 ) * sin( ( 20 * x - 11.125 ) * c5 )) / 2 :
  153. pow( 2, -20 * x + 10 ) * sin( ( 20 * x - 11.125 ) * c5 ) / 2 + 1;
  154. },
  155. easeInBack: function (x) {
  156. return c3 * x * x * x - c1 * x * x;
  157. },
  158. easeOutBack: function (x) {
  159. return 1 + c3 * pow( x - 1, 3 ) + c1 * pow( x - 1, 2 );
  160. },
  161. easeInOutBack: function (x) {
  162. return x < 0.5 ?
  163. ( pow( 2 * x, 2 ) * ( ( c2 + 1 ) * 2 * x - c2 ) ) / 2 :
  164. ( pow( 2 * x - 2, 2 ) *( ( c2 + 1 ) * ( x * 2 - 2 ) + c2 ) + 2 ) / 2;
  165. },
  166. easeInBounce: function (x) {
  167. return 1 - bounceOut( 1 - x );
  168. },
  169. easeOutBounce: bounceOut,
  170. easeInOutBounce: function (x) {
  171. return x < 0.5 ?
  172. ( 1 - bounceOut( 1 - 2 * x ) ) / 2 :
  173. ( 1 + bounceOut( 2 * x - 1 ) ) / 2;
  174. }
  175. });
  176. });;// Custom Easing
  177. jQuery.extend( jQuery.easing,
  178. {
  179. easeInOutMaterial: function (x, t, b, c, d) {
  180. if ((t/=d/2) < 1) return c/2*t*t + b;
  181. return c/4*((t-=2)*t*t + 2) + b;
  182. }
  183. });;/*! VelocityJS.org (1.2.3). (C) 2014 Julian Shapiro. MIT @license: en.wikipedia.org/wiki/MIT_License */
  184. /*! VelocityJS.org jQuery Shim (1.0.1). (C) 2014 The jQuery Foundation. MIT @license: en.wikipedia.org/wiki/MIT_License. */
  185. /*! Note that this has been modified by Materialize to confirm that Velocity is not already being imported. */
  186. jQuery.Velocity?console.log("Velocity is already loaded. You may be needlessly importing Velocity again; note that Materialize includes Velocity."):(!function(e){function t(e){var t=e.length,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}if(!e.jQuery){var r=function(e,t){return new r.fn.init(e,t)};r.isWindow=function(e){return null!=e&&e==e.window},r.type=function(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?n[i.call(e)]||"object":typeof e},r.isArray=Array.isArray||function(e){return"array"===r.type(e)},r.isPlainObject=function(e){var t;if(!e||"object"!==r.type(e)||e.nodeType||r.isWindow(e))return!1;try{if(e.constructor&&!o.call(e,"constructor")&&!o.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(a){return!1}for(t in e);return void 0===t||o.call(e,t)},r.each=function(e,r,a){var n,o=0,i=e.length,s=t(e);if(a){if(s)for(;i>o&&(n=r.apply(e[o],a),n!==!1);o++);else for(o in e)if(n=r.apply(e[o],a),n===!1)break}else if(s)for(;i>o&&(n=r.call(e[o],o,e[o]),n!==!1);o++);else for(o in e)if(n=r.call(e[o],o,e[o]),n===!1)break;return e},r.data=function(e,t,n){if(void 0===n){var o=e[r.expando],i=o&&a[o];if(void 0===t)return i;if(i&&t in i)return i[t]}else if(void 0!==t){var o=e[r.expando]||(e[r.expando]=++r.uuid);return a[o]=a[o]||{},a[o][t]=n,n}},r.removeData=function(e,t){var n=e[r.expando],o=n&&a[n];o&&r.each(t,function(e,t){delete o[t]})},r.extend=function(){var e,t,a,n,o,i,s=arguments[0]||{},l=1,u=arguments.length,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++)if(null!=(o=arguments[l]))for(n in o)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));return s},r.queue=function(e,a,n){function o(e,r){var a=r||[];return null!=e&&(t(Object(e))?!function(e,t){for(var r=+t.length,a=0,n=e.length;r>a;)e[n++]=t[a++];if(r!==r)for(;void 0!==t[a];)e[n++]=t[a++];return e.length=n,e}(a,"string"==typeof e?[e]:e):[].push.call(a,e)),a}if(e){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||[]}},r.dequeue=function(e,t){r.each(e.nodeType?[e]:e,function(e,a){t=t||"fx";var n=r.queue(a,t),o=n.shift();"inprogress"===o&&(o=n.shift()),o&&("fx"===t&&n.unshift("inprogress"),o.call(a,function(){r.dequeue(a,t)}))})},r.fn=r.prototype={init:function(e){if(e.nodeType)return this[0]=e,this;throw new Error("Not a DOM node.")},offset:function(){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)}},position:function(){function e(){for(var e=this.offsetParent||document;e&&"html"===!e.nodeType.toLowerCase&&"static"===e.style.position;)e=e.offsetParent;return e||document}var t=this[0],e=e.apply(t),a=this.offset(),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}}};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++)n["[object "+s[l]+"]"]=s[l].toLowerCase();r.fn.init.prototype=r.fn,e.Velocity={Utilities:r}}}(window),function(e){"object"==typeof module&&"object"==typeof module.exports?module.exports=e():"function"==typeof define&&define.amd?define(e):e()}(function(){return function(e,t,r,a){function n(e){for(var t=-1,r=e?e.length:0,a=[];++t<r;){var n=e[t];n&&a.push(n)}return a}function o(e){return m.isWrapped(e)?e=[].slice.call(e):m.isNode(e)&&(e=[e]),e}function i(e){var t=f.data(e,"velocity");return null===t?a:t}function s(e){return function(t){return Math.round(t*e)*(1/e)}}function l(e,r,a,n){function o(e,t){return 1-3*t+3*e}function i(e,t){return 3*t-6*e}function s(e){return 3*e}function l(e,t,r){return((o(t,r)*e+i(t,r))*e+s(t))*e}function u(e,t,r){return 3*o(t,r)*e*e+2*i(t,r)*e+s(t)}function c(t,r){for(var n=0;m>n;++n){var o=u(r,e,a);if(0===o)return r;var i=l(r,e,a)-t;r-=i/o}return r}function p(){for(var t=0;b>t;++t)w[t]=l(t*x,e,a)}function f(t,r,n){var o,i,s=0;do i=r+(n-r)/2,o=l(i,e,a)-t,o>0?n=i:r=i;while(Math.abs(o)>h&&++s<v);return i}function d(t){for(var r=0,n=1,o=b-1;n!=o&&w[n]<=t;++n)r+=x;--n;var i=(t-w[n])/(w[n+1]-w[n]),s=r+i*x,l=u(s,e,a);return l>=y?c(t,s):0==l?s:f(t,r,r+x)}function g(){V=!0,(e!=r||a!=n)&&p()}var m=4,y=.001,h=1e-7,v=10,b=11,x=1/(b-1),S="Float32Array"in t;if(4!==arguments.length)return!1;for(var P=0;4>P;++P)if("number"!=typeof arguments[P]||isNaN(arguments[P])||!isFinite(arguments[P]))return!1;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),V=!1,C=function(t){return V||g(),e===r&&a===n?t:0===t?0:1===t?1:l(d(t),r,n)};C.getControlPoints=function(){return[{x:e,y:r},{x:a,y:n}]};var T="generateBezier("+[e,r,a,n]+")";return C.toString=function(){return T},C}function u(e,t){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}function c(e){if(e){var t=(new Date).getTime(),r=b.State.calls.length;r>1e4&&(b.State.calls=n(b.State.calls));for(var o=0;r>o;o++)if(b.State.calls[o]){var s=b.State.calls[o],l=s[0],u=s[2],d=s[3],g=!!d,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++){var P=l[v],V=P.element;if(i(V)){var C=!1;if(u.display!==a&&null!==u.display&&"none"!==u.display){if("flex"===u.display){var T=["-webkit-box","-moz-box","-ms-flexbox","-webkit-flex"];f.each(T,function(e,t){S.setPropertyValue(V,"display",t)})}S.setPropertyValue(V,"display",u.display)}u.visibility!==a&&"hidden"!==u.visibility&&S.setPropertyValue(V,"visibility",u.visibility);for(var k in P)if("element"!==k){var A,F=P[k],j=m.isString(F.easing)?b.Easings[F.easing]:F.easing;if(1===h)A=F.endValue;else{var E=F.endValue-F.startValue;if(A=F.startValue+E*j(h,u,E),!g&&A===F.currentValue)continue}if(F.currentValue=A,"tween"===k)y=A;else{if(S.Hooks.registered[k]){var H=S.Hooks.getRoot(k),N=i(V).rootPropertyValueCache[H];N&&(F.rootPropertyValue=N)}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)}}u.mobileHA&&i(V).transformCache.translate3d===a&&(i(V).transformCache.translate3d="(0px, 0px, 0px)",C=!0),C&&S.flushTransformCache(V)}}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)}}b.State.isTicking&&w(c)}function p(e,t){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++){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)){i(p).isAnimating=!1,i(p).rootPropertyValueCache={};var d=!1;f.each(S.Lists.transforms3D,function(e,t){var r=/^scale/.test(t)?1:0,n=i(p).transformCache[t];i(p).transformCache[t]!==a&&new RegExp("^\\("+r+"[^.]").test(n)&&(d=!0,delete i(p).transformCache[t])}),o.mobileHA&&(d=!0,delete i(p).transformCache.translate3d),d&&S.flushTransformCache(p),S.Values.removeClass(p,"velocity-animating")}if(!t&&o.complete&&!o.loop&&u===c-1)try{o.complete.call(n,n)}catch(g){setTimeout(function(){throw g},1)}s&&o.loop!==!0&&s(n),i(p)&&o.loop===!0&&!t&&(f.each(i(p).tweensContainer,function(e,t){/^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)}),b(p,"reverse",{loop:!0,delay:o.delay})),o.queue!==!1&&f.dequeue(p,o.queue)}b.State.calls[e]=!1;for(var m=0,y=b.State.calls.length;y>m;m++)if(b.State.calls[m]!==!1){l=!0;break}l===!1&&(b.State.isTicking=!1,delete b.State.calls,b.State.calls=[])}var f,d=function(){if(r.documentMode)return r.documentMode;for(var e=7;e>4;e--){var t=r.createElement("div");if(t.innerHTML="<!--[if IE "+e+"]><span></span><![endif]-->",t.getElementsByTagName("span").length)return t=null,e}return a}(),g=function(){var e=0;return t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||function(t){var r,a=(new Date).getTime();return r=Math.max(0,16-(a-e)),e=a+r,setTimeout(function(){t(a+r)},r)}}(),m={isString:function(e){return"string"==typeof e},isArray:Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},isFunction:function(e){return"[object Function]"===Object.prototype.toString.call(e)},isNode:function(e){return e&&e.nodeType},isNodeList:function(e){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)},isWrapped:function(e){return e&&(e.jquery||t.Zepto&&t.Zepto.zepto.isZ(e))},isSVG:function(e){return t.SVGElement&&e instanceof t.SVGElement},isEmptyObject:function(e){for(var t in e)return!1;return!0}},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,v="swing",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){f.data(e,"velocity",{isSVG:m.isSVG(e),isAnimating:!1,computedStyle:null,tweensContainer:null,rootPropertyValueCache:{},transformCache:{}})},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(){function e(e){return-e.tension*e.x-e.friction*e.v}function t(t,r,a){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)}}function r(r,a){var n={dx:r.v,dv:e(r)},o=t(r,.5*a,n),i=t(r,.5*a,o),s=t(r,a,i),l=1/6*(n.dx+2*(o.dx+i.dx)+s.dx),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}return function a(e,t,n){var o,i,s,l={x:-1,v:0,tension:null,friction:null},u=[0],c=0,p=1e-4,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){return u[e*(u.length-1)|0]}:c}}();b.Easings={linear:function(e){return e},swing:function(e){return.5-Math.cos(e*Math.PI)/2},spring:function(e){return 1-Math.cos(4.5*e*Math.PI)*Math.exp(6*-e)}},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){b.Easings[t[0]]=l.apply(null,t[1])});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(){for(var e=0;e<S.Lists.colors.length;e++){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]}var r,a,n;if(d)for(r in S.Hooks.templates){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(" ")])}for(r in S.Hooks.templates){a=S.Hooks.templates[r],n=a[0].split(" ");for(var e in n){var i=r+n[e],s=e;S.Hooks.registered[i]=[r,s]}}},getRoot:function(e){var t=S.Hooks.registered[e];return t?t[0]:e},cleanRootPropertyValue:function(e,t){return S.RegEx.valueUnwrap.test(t)&&(t=t.match(S.RegEx.valueUnwrap)[1]),S.Values.isCSSNullValue(t)&&(t=S.Hooks.templates[e][1]),t},extractValue:function(e,t){var r=S.Hooks.registered[e];if(r){var a=r[0],n=r[1];return t=S.Hooks.cleanRootPropertyValue(a,t),t.toString().match(S.RegEx.valueSplit)[n]}return t},injectValue:function(e,t,r){var a=S.Hooks.registered[e];if(a){var n,o,i=a[0],s=a[1];return r=S.Hooks.cleanRootPropertyValue(i,r),n=r.toString().match(S.RegEx.valueSplit),n[s]=t,o=n.join(" ")}return r}},Normalizations:{registered:{clip:function(e,t,r){switch(e){case"name":return"clip";case"extract":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":return"rect("+r+")"}},blur:function(e,t,r){switch(e){case"name":return b.State.isFirefox?"filter":"-webkit-filter";case"extract":var a=parseFloat(r);if(!a&&0!==a){var n=r.toString().match(/blur\(([0-9]+[A-z]+)\)/i);a=n?n[1]:0}return a;case"inject":return parseFloat(r)?"blur("+r+")":"none"}},opacity:function(e,t,r){if(8>=d)switch(e){case"name":return"filter";case"extract":var a=r.toString().match(/alpha\(opacity=(.*)\)/i);return r=a?a[1]/100:1;case"inject":return t.style.zoom=1,parseFloat(r)>=1?"":"alpha(opacity="+parseInt(100*parseFloat(r),10)+")"}else switch(e){case"name":return"opacity";case"extract":return r;case"inject":return r}}},register:function(){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++)!function(){var t=S.Lists.transformsBase[e];S.Normalizations.registered[t]=function(e,r,n){switch(e){case"name":return"transform";case"extract":return i(r)===a||i(r).transformCache[t]===a?/^scale/i.test(t)?1:0:i(r).transformCache[t].replace(/[()]/g,"");case"inject":var o=!1;switch(t.substr(0,t.length-1)){case"translate":o=!/(%|px|em|rem|vw|vh|\d)$/i.test(n);break;case"scal":case"scale":b.State.isAndroid&&i(r).transformCache[t]===a&&1>n&&(n=1),o=!/(\d)$/i.test(n);break;case"skew":o=!/(deg|\d)$/i.test(n);break;case"rotate":o=!/(deg|\d)$/i.test(n)}return o||(i(r).transformCache[t]="("+n+")"),i(r).transformCache[t]}}}();for(var e=0;e<S.Lists.colors.length;e++)!function(){var t=S.Lists.colors[e];S.Normalizations.registered[t]=function(e,r,n){switch(e){case"name":return t;case"extract":var o;if(S.RegEx.wrappedValueAlreadyExtracted.test(n))o=n;else{var i,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," ")}return 8>=d||3!==o.split(" ").length||(o+=" 1"),o;case"inject":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,"")+")"}}}()}},Names:{camelCase:function(e){return e.replace(/-(\w)/g,function(e,t){return t.toUpperCase()})},SVGAttribute:function(e){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)},prefixCheck:function(e){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++){var n;if(n=0===r?e:t[r]+e.replace(/^\w/,function(e){return e.toUpperCase()}),m.isString(b.State.prefixElement.style[n]))return b.State.prefixMatches[e]=n,[n,!0]}return[e,!1]}},Values:{hexToRgb:function(e){var t,r=/^#?([a-f\d])([a-f\d])([a-f\d])$/i,a=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i;return e=e.replace(r,function(e,t,r,a){return t+t+r+r+a+a}),t=a.exec(e),t?[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]:[0,0,0]},isCSSNullValue:function(e){return 0==e||/^(none|auto|transparent|(rgba\(0, ?0, ?0, ?0\)))$/i.test(e)},getUnitType:function(e){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"},getDisplayType:function(e){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"},addClass:function(e,t){e.classList?e.classList.add(t):e.className+=(e.className.length?" ":"")+t},removeClass:function(e,t){e.classList?e.classList.remove(t):e.className=e.className.toString().replace(new RegExp("(^|\\s)"+t.split(" ").join("|")+"(\\s|$)","gi")," ")}},getPropertyValue:function(e,r,n,o){function s(e,r){function n(){u&&S.setPropertyValue(e,"display","none")}var l=0;if(8>=d)l=f.css(e,r);else{var u=!1;if(/^(width|height)$/.test(r)&&0===S.getPropertyValue(e,"display")&&(u=!0,S.setPropertyValue(e,"display",S.Values.getDisplayType(e))),!o){if("height"===r&&"border-box"!==S.getPropertyValue(e,"boxSizing").toString().toLowerCase()){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}if("width"===r&&"border-box"!==S.getPropertyValue(e,"boxSizing").toString().toLowerCase()){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}}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()}if("auto"===l&&/^(top|right|bottom|left)$/i.test(r)){var m=s(e,"position");("fixed"===m||"absolute"===m&&/top|left/i.test(r))&&(l=f(e).position()[r]+"px")}return l}var l;if(S.Hooks.registered[r]){var u=r,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)}else if(S.Normalizations.registered[r]){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)}if(!/^[\d-]/.test(l))if(i(e)&&i(e).isSVG&&S.Names.SVGAttribute(r))if(/^(height|width)$/i.test(r))try{l=e.getBBox()[r]}catch(m){l=0}else l=e.getAttribute(r);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},setPropertyValue:function(e,r,a,n,o){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{if(S.Hooks.registered[r]){var l=r,u=S.Hooks.getRoot(r);n=n||S.getPropertyValue(e,u),a=S.Hooks.injectValue(l,a,n),r=u}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{e.style[s]=a}catch(c){b.debug&&console.log("Browser does not support ["+a+"] for ["+s+"]")}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)}return[s,a]},flushTransformCache:function(e){function t(t){return parseFloat(S.getPropertyValue(e,t))}var r="";if((d||b.State.isAndroid&&!b.State.isChrome)&&i(e).isSVG){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){/^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])})}else{var n,o;f.each(i(e).transformCache,function(t){return n=i(e).transformCache[t],"transformPerspective"===t?(o=n,!0):(9===d&&"rotateZ"===t&&(t="rotate"),void(r+=t+n+" "))}),o&&(r="perspective"+o+" "+r)}S.setPropertyValue(e,"transform",r)}};S.Hooks.register(),S.Normalizations.register(),b.hook=function(e,t,r){var n=a;return e=o(e),f.each(e,function(e,o){if(i(o)===a&&b.init(o),r===a)n===a&&(n=b.CSS.getPropertyValue(o,t));else{var s=b.CSS.setPropertyValue(o,t,r);"transform"===s[0]&&b.CSS.flushTransformCache(o),n=s}}),n};var P=function(){function e(){return s?k.promise||null:l}function n(){function e(e){function p(e,t){var r=a,n=a,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]}function d(e,t){var r,a;return a=(t||"0").toString().toLowerCase().replace(/[%A-z]+$/,function(e){return r=e,""}),r||(r=S.Values.getUnitType(e)),[a,r]}function h(){var e={myParent:o.parentNode||r.body,position:S.getPropertyValue(o,"position"),fontSize:S.getPropertyValue(o,"fontSize")},a=e.position===L.lastPosition&&e.myParent===L.lastParent,n=e.fontSize===L.lastFontSize;L.lastParent=e.myParent,L.lastPosition=e.position,L.lastFontSize=e.fontSize;var s=100,l={};if(n&&a)l.emToPx=L.lastEmToPx,l.percentToPxWidth=L.lastPercentToPxWidth,l.percentToPxHeight=L.lastPercentToPxHeight;else{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){b.CSS.setPropertyValue(u,t,"hidden")}),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){b.CSS.setPropertyValue(u,t,s+"%")}),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)}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}if(s.begin&&0===V)try{s.begin.call(g,g)}catch(x){setTimeout(function(){throw x},1)}if("scroll"===A){var P,C,T,F=/^x$/i.test(s.axis)?"Left":"Top",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)}else if("reverse"===A){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)if("element"!==H){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)}l=E}else if("start"===A){var E;i(o).tweensContainer&&i(o).isAnimating===!0&&(E=i(o).tweensContainer),f.each(y,function(e,t){if(RegExp("^"+S.Lists.colors.join("$|^")+"$").test(e)){var r=p(t,!0),n=r[0],o=r[1],i=r[2];if(S.RegEx.isHex.test(n)){for(var s=["Red","Green","Blue"],l=S.Values.hexToRgb(n),u=i?S.Values.hexToRgb(i):a,c=0;c<s.length;c++){var f=[l[c]];o&&f.push(o),u!==a&&f.push(u[c]),y[e+s[c]]=f}delete y[e]}}});for(var z in y){var O=p(y[z]),q=O[0],$=O[1],M=O[2];z=S.Names.camelCase(z);var I=S.Hooks.getRoot(z),B=!1;if(i(o).isSVG||"tween"===I||S.Names.prefixCheck(I)[1]!==!1||S.Normalizations.registered[I]!==a){(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,G,Y,D=!1;if(W=d(z,M),M=W[0],Y=W[1],W=d(z,q),q=W[0].replace(/^([+-\/*])=/,function(e,t){return D=t,""}),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{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"%":M*="x"===Q?n.percentToPxWidth:n.percentToPxHeight;break;case"px":break;default:M*=n[Y+"ToPx"]}switch(G){case"%":M*=1/("x"===Q?n.percentToPxWidth:n.percentToPxHeight);break;case"px":break;default:M*=1/n[G+"ToPx"]}}switch(D){case"+":q=M+q;break;case"-":q=M-q;break;case"*":q=M*q;break;case"/":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)}else b.debug&&console.log("Skipping ["+I+"] due to a lack of browser support.")}l.element=o}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++)}var n,o=this,s=f.extend({},b.defaults,v),l={};switch(i(o)===a&&b.init(o),parseFloat(s.delay)&&s.queue!==!1&&f.queue(o,s.queue,function(e){b.velocityQueueEntryFlag=!0,i(o).delayTimer={setTimeout:setTimeout(e,parseFloat(s.delay)),next:e}}),s.duration.toString().toLowerCase()){case"fast":s.duration=200;break;case"normal":s.duration=h;break;case"slow":s.duration=600;break;default: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){return r===!0?(k.promise&&k.resolver(g),!0):(b.velocityQueueEntryFlag=!0,void e(t))}),""!==s.queue&&"fx"!==s.queue||"inprogress"===f.queue(o)[0]||f.dequeue(o)}var s,l,d,g,y,v,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)){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,V=0;if(!/^(stop|finish)$/i.test(y)&&!f.isPlainObject(v)){var C=d+1;v={};for(var T=C;T<arguments.length;T++)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]}var k={promise:null,resolver:null,rejecter:null};s&&b.Promise&&(k.promise=new b.Promise(function(e,t){k.resolver=e,k.rejecter=t}));var A;switch(y){case"scroll":A="scroll";break;case"reverse":A="reverse";break;case"finish":case"stop":f.each(g,function(e,t){i(t)&&i(t).delayTimer&&(clearTimeout(i(t).delayTimer.setTimeout),i(t).delayTimer.next&&i(t).delayTimer.next(),delete i(t).delayTimer)});var F=[];return f.each(b.State.calls,function(e,t){t&&f.each(t[1],function(r,n){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){a===n&&((v===!0||m.isString(v))&&(f.each(f.queue(a,m.isString(v)?v:""),function(e,t){
  187. m.isFunction(t)&&t(null,!0)}),f.queue(a,m.isString(v)?v:"",[])),"stop"===y?(i(a)&&i(a).tweensContainer&&o!==!1&&f.each(i(a).tweensContainer,function(e,t){t.endValue=t.currentValue}),F.push(e)):"finish"===y&&(t[2].duration=1))}):!0})}),"stop"===y&&(f.each(F,function(e,t){p(t,!0)}),k.promise&&k.resolver(g)),e();default:if(!f.isPlainObject(y)||m.isEmptyObject(y)){if(m.isString(y)&&b.Redirects[y]){var j=f.extend({},v),E=j.duration,H=j.delay||0;return j.backwards===!0&&(g=f.extend(!0,[],g).reverse()),f.each(g,function(e,t){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)}),e()}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()}A="start"}var L={lastParent:null,lastPosition:null,lastFontSize:null,lastPercentToPxWidth:null,lastPercentToPxHeight:null,lastEmToPx:null,remToPx:null,vwToPx:null,vhToPx:null},R=[];f.each(g,function(e,t){m.isNode(t)&&n.call(t)});var z,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++){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)}return e()}};b=f.extend(P,b),b.animate=P;var w=t.requestAnimationFrame||g;return b.State.isMobile||r.hidden===a||r.addEventListener("visibilitychange",function(){r.hidden?(w=function(e){return setTimeout(function(){e(!0)},16)},c()):w=t.requestAnimationFrame||g}),e.Velocity=b,e!==t&&(e.fn.velocity=P,e.fn.velocity.defaults=b.defaults),f.each(["Down","Up"],function(e,t){b.Redirects["slide"+t]=function(e,r,n,o,i,s){var l=f.extend({},r),u=l.begin,c=l.complete,p={height:"",marginTop:"",marginBottom:"",paddingTop:"",paddingBottom:""},d={};l.display===a&&(l.display="Down"===t?"inline"===b.CSS.Values.getDisplayType(e)?"inline-block":"block":"none"),l.begin=function(){u&&u.call(i,i);for(var r in p){d[r]=e.style[r];var a=b.CSS.getPropertyValue(e,r);p[r]="Down"===t?[a,0]:[0,a]}d.overflow=e.style.overflow,e.style.overflow="hidden"},l.complete=function(){for(var t in d)e.style[t]=d[t];c&&c.call(i,i),s&&s.resolver(i)},b(e,p,l)}}),f.each(["In","Out"],function(e,t){b.Redirects["fade"+t]=function(e,r,n,o,i,s){var l=f.extend({},r),u={opacity:"In"===t?1:0},c=l.complete;l.complete=n!==o-1?l.begin=null:function(){c&&c.call(i,i),s&&s.resolver(i)},l.display===a&&(l.display="In"===t?"auto":"none"),b(this,u,l)}}),b}(window.jQuery||window.Zepto||window,window,document)}));
  188. ;!function(a,b,c,d){"use strict";function k(a,b,c){return setTimeout(q(a,c),b)}function l(a,b,c){return Array.isArray(a)?(m(a,c[b],c),!0):!1}function m(a,b,c){var e;if(a)if(a.forEach)a.forEach(b,c);else if(a.length!==d)for(e=0;e<a.length;)b.call(c,a[e],e,a),e++;else for(e in a)a.hasOwnProperty(e)&&b.call(c,a[e],e,a)}function n(a,b,c){for(var e=Object.keys(b),f=0;f<e.length;)(!c||c&&a[e[f]]===d)&&(a[e[f]]=b[e[f]]),f++;return a}function o(a,b){return n(a,b,!0)}function p(a,b,c){var e,d=b.prototype;e=a.prototype=Object.create(d),e.constructor=a,e._super=d,c&&n(e,c)}function q(a,b){return function(){return a.apply(b,arguments)}}function r(a,b){return typeof a==g?a.apply(b?b[0]||d:d,b):a}function s(a,b){return a===d?b:a}function t(a,b,c){m(x(b),function(b){a.addEventListener(b,c,!1)})}function u(a,b,c){m(x(b),function(b){a.removeEventListener(b,c,!1)})}function v(a,b){for(;a;){if(a==b)return!0;a=a.parentNode}return!1}function w(a,b){return a.indexOf(b)>-1}function x(a){return a.trim().split(/\s+/g)}function y(a,b,c){if(a.indexOf&&!c)return a.indexOf(b);for(var d=0;d<a.length;){if(c&&a[d][c]==b||!c&&a[d]===b)return d;d++}return-1}function z(a){return Array.prototype.slice.call(a,0)}function A(a,b,c){for(var d=[],e=[],f=0;f<a.length;){var g=b?a[f][b]:a[f];y(e,g)<0&&d.push(a[f]),e[f]=g,f++}return c&&(d=b?d.sort(function(a,c){return a[b]>c[b]}):d.sort()),d}function B(a,b){for(var c,f,g=b[0].toUpperCase()+b.slice(1),h=0;h<e.length;){if(c=e[h],f=c?c+g:b,f in a)return f;h++}return d}function D(){return C++}function E(a){var b=a.ownerDocument;return b.defaultView||b.parentWindow}function ab(a,b){var c=this;this.manager=a,this.callback=b,this.element=a.element,this.target=a.options.inputTarget,this.domHandler=function(b){r(a.options.enable,[a])&&c.handler(b)},this.init()}function bb(a){var b,c=a.options.inputClass;return b=c?c:H?wb:I?Eb:G?Gb:rb,new b(a,cb)}function cb(a,b,c){var d=c.pointers.length,e=c.changedPointers.length,f=b&O&&0===d-e,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}function db(a,b){var c=a.session,d=b.pointers,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,g=c.firstMultiple,h=g?g.center:f.center,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}function eb(a,b){var c=b.center,d=a.offsetDelta||{},e=a.prevDelta||{},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)}function fb(a,b){var f,g,h,j,c=a.lastInterval||b,e=b.timeStamp-c.timeStamp;if(b.eventType!=R&&(e>N||c.velocity===d)){var k=c.deltaX-b.deltaX,l=c.deltaY-b.deltaY,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}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}function gb(a){for(var b=[],c=0;c<a.pointers.length;)b[c]={clientX:h(a.pointers[c].clientX),clientY:h(a.pointers[c].clientY)},c++;return{timeStamp:j(),pointers:b,center:hb(b),deltaX:a.deltaX,deltaY:a.deltaY}}function hb(a){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;)c+=a[e].clientX,d+=a[e].clientY,e++;return{x:h(c/b),y:h(d/b)}}function ib(a,b,c){return{x:b/a||0,y:c/a||0}}function jb(a,b){return a===b?S:i(a)>=i(b)?a>0?T:U:b>0?V:W}function kb(a,b,c){c||(c=$);var d=b[c[0]]-a[c[0]],e=b[c[1]]-a[c[1]];return Math.sqrt(d*d+e*e)}function lb(a,b,c){c||(c=$);var d=b[c[0]]-a[c[0]],e=b[c[1]]-a[c[1]];return 180*Math.atan2(e,d)/Math.PI}function mb(a,b){return lb(b[1],b[0],_)-lb(a[1],a[0],_)}function nb(a,b){return kb(b[0],b[1],_)/kb(a[0],a[1],_)}function rb(){this.evEl=pb,this.evWin=qb,this.allow=!0,this.pressed=!1,ab.apply(this,arguments)}function wb(){this.evEl=ub,this.evWin=vb,ab.apply(this,arguments),this.store=this.manager.session.pointerEvents=[]}function Ab(){this.evTarget=yb,this.evWin=zb,this.started=!1,ab.apply(this,arguments)}function Bb(a,b){var c=z(a.touches),d=z(a.changedTouches);return b&(Q|R)&&(c=A(c.concat(d),"identifier",!0)),[c,d]}function Eb(){this.evTarget=Db,this.targetIds={},ab.apply(this,arguments)}function Fb(a,b){var c=z(a.touches),d=this.targetIds;if(b&(O|P)&&1===c.length)return d[c[0].identifier]=!0,[c,c];var e,f,g=z(a.changedTouches),h=[],i=this.target;if(f=c.filter(function(a){return v(a.target,i)}),b===O)for(e=0;e<f.length;)d[f[e].identifier]=!0,e++;for(e=0;e<g.length;)d[g[e].identifier]&&h.push(g[e]),b&(Q|R)&&delete d[g[e].identifier],e++;return h.length?[A(f.concat(h),"identifier",!0),h]:void 0}function Gb(){ab.apply(this,arguments);var a=q(this.handler,this);this.touch=new Eb(this.manager,a),this.mouse=new rb(this.manager,a)}function Pb(a,b){this.manager=a,this.set(b)}function Qb(a){if(w(a,Mb))return Mb;var b=w(a,Nb),c=w(a,Ob);return b&&c?Nb+" "+Ob:b||c?b?Nb:Ob:w(a,Lb)?Lb:Kb}function Yb(a){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=[]}function Zb(a){return a&Wb?"cancel":a&Ub?"end":a&Tb?"move":a&Sb?"start":""}function $b(a){return a==W?"down":a==V?"up":a==T?"left":a==U?"right":""}function _b(a,b){var c=b.manager;return c?c.get(a):a}function ac(){Yb.apply(this,arguments)}function bc(){ac.apply(this,arguments),this.pX=null,this.pY=null}function cc(){ac.apply(this,arguments)}function dc(){Yb.apply(this,arguments),this._timer=null,this._input=null}function ec(){ac.apply(this,arguments)}function fc(){ac.apply(this,arguments)}function gc(){Yb.apply(this,arguments),this.pTime=!1,this.pCenter=!1,this._timer=null,this._input=null,this.count=0}function hc(a,b){return b=b||{},b.recognizers=s(b.recognizers,hc.defaults.preset),new kc(a,b)}function kc(a,b){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){var b=this.add(new a[0](a[1]));a[2]&&b.recognizeWith(a[2]),a[3]&&b.requireFailure(a[3])},this)}function lc(a,b){var c=a.element;m(a.options.cssProps,function(a,d){c.style[B(c.style,d)]=b?a:""})}function mc(a,c){var d=b.createEvent("Event");d.initEvent(a,!0,!0),d.gesture=c,c.target.dispatchEvent(d)}var e=["","webkit","moz","MS","ms","o"],f=b.createElement("div"),g="function",h=Math.round,i=Math.abs,j=Date.now,C=1,F=/mobile|tablet|ip(ad|hone|od)|android/i,G="ontouchstart"in a,H=B(a,"PointerEvent")!==d,I=G&&F.test(navigator.userAgent),J="touch",K="pen",L="mouse",M="kinect",N=25,O=1,P=2,Q=4,R=8,S=1,T=2,U=4,V=8,W=16,X=T|U,Y=V|W,Z=X|Y,$=["x","y"],_=["clientX","clientY"];ab.prototype={handler:function(){},init:function(){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)},destroy:function(){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)}};var ob={mousedown:O,mousemove:P,mouseup:Q},pb="mousedown",qb="mousemove mouseup";p(rb,ab,{handler:function(a){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}))}});var sb={pointerdown:O,pointermove:P,pointerup:Q,pointercancel:R,pointerout:R},tb={2:J,3:K,4:L,5:M},ub="pointerdown",vb="pointermove pointerup pointercancel";a.MSPointerEvent&&(ub="MSPointerDown",vb="MSPointerMove MSPointerUp MSPointerCancel"),p(wb,ab,{handler:function(a){var b=this.store,c=!1,d=a.type.toLowerCase().replace("ms",""),e=sb[d],f=tb[a.pointerType]||a.pointerType,g=f==J,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))}});var xb={touchstart:O,touchmove:P,touchend:Q,touchcancel:R},yb="touchstart",zb="touchstart touchmove touchend touchcancel";p(Ab,ab,{handler:function(a){var b=xb[a.type];if(b===O&&(this.started=!0),this.started){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})}}});var Cb={touchstart:O,touchmove:P,touchend:Q,touchcancel:R},Db="touchstart touchmove touchend touchcancel";p(Eb,ab,{handler:function(a){var b=Cb[a.type],c=Fb.call(this,a,b);c&&this.callback(this.manager,b,{pointers:c[0],changedPointers:c[1],pointerType:J,srcEvent:a})}}),p(Gb,ab,{handler:function(a,b,c){var d=c.pointerType==J,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)},destroy:function(){this.touch.destroy(),this.mouse.destroy()}});var Hb=B(f.style,"touchAction"),Ib=Hb!==d,Jb="compute",Kb="auto",Lb="manipulation",Mb="none",Nb="pan-x",Ob="pan-y";Pb.prototype={set:function(a){a==Jb&&(a=this.compute()),Ib&&(this.manager.element.style[Hb]=a),this.actions=a.toLowerCase().trim()},update:function(){this.set(this.manager.options.touchAction)},compute:function(){var a=[];return m(this.manager.recognizers,function(b){r(b.options.enable,[b])&&(a=a.concat(b.getTouchAction()))}),Qb(a.join(" "))},preventDefaults:function(a){if(!Ib){var b=a.srcEvent,c=a.offsetDirection;if(this.manager.session.prevented)return b.preventDefault(),void 0;var d=this.actions,e=w(d,Mb),f=w(d,Ob),g=w(d,Nb);return e||f&&c&X||g&&c&Y?this.preventSrc(b):void 0}},preventSrc:function(a){this.manager.session.prevented=!0,a.preventDefault()}};var Rb=1,Sb=2,Tb=4,Ub=8,Vb=Ub,Wb=16,Xb=32;Yb.prototype={defaults:{},set:function(a){return n(this.options,a),this.manager&&this.manager.touchAction.update(),this},recognizeWith:function(a){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},dropRecognizeWith:function(a){return l(a,"dropRecognizeWith",this)?this:(a=_b(a,this),delete this.simultaneous[a.id],this)},requireFailure:function(a){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},dropRequireFailure:function(a){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},hasRequireFailures:function(){return this.requireFail.length>0},canRecognizeWith:function(a){return!!this.simultaneous[a.id]},emit:function(a){function d(d){b.manager.emit(b.options.event+(d?Zb(c):""),a)}var b=this,c=this.state;Ub>c&&d(!0),d(),c>=Ub&&d(!0)},tryEmit:function(a){return this.canEmit()?this.emit(a):(this.state=Xb,void 0)},canEmit:function(){for(var a=0;a<this.requireFail.length;){if(!(this.requireFail[a].state&(Xb|Rb)))return!1;a++}return!0},recognize:function(a){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)},process:function(){},getTouchAction:function(){},reset:function(){}},p(ac,Yb,{defaults:{pointers:1},attrTest:function(a){var b=this.options.pointers;return 0===b||a.pointers.length===b},process:function(a){var b=this.state,c=a.eventType,d=b&(Sb|Tb),e=this.attrTest(a);return d&&(c&R||!e)?b|Wb:d||e?c&Q?b|Ub:b&Sb?b|Tb:Sb:Xb}}),p(bc,ac,{defaults:{event:"pan",threshold:10,pointers:1,direction:Z},getTouchAction:function(){var a=this.options.direction,b=[];return a&X&&b.push(Ob),a&Y&&b.push(Nb),b},directionTest:function(a){var b=this.options,c=!0,d=a.distance,e=a.direction,f=a.deltaX,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},attrTest:function(a){return ac.prototype.attrTest.call(this,a)&&(this.state&Sb||!(this.state&Sb)&&this.directionTest(a))},emit:function(a){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)}}),p(cc,ac,{defaults:{event:"pinch",threshold:0,pointers:2},getTouchAction:function(){return[Mb]},attrTest:function(a){return this._super.attrTest.call(this,a)&&(Math.abs(a.scale-1)>this.options.threshold||this.state&Sb)},emit:function(a){if(this._super.emit.call(this,a),1!==a.scale){var b=a.scale<1?"in":"out";this.manager.emit(this.options.event+b,a)}}}),p(dc,Yb,{defaults:{event:"press",pointers:1,time:500,threshold:5},getTouchAction:function(){return[Kb]},process:function(a){var b=this.options,c=a.pointers.length===b.pointers,d=a.distance<b.threshold,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(){this.state=Vb,this.tryEmit()},b.time,this);else if(a.eventType&Q)return Vb;return Xb},reset:function(){clearTimeout(this._timer)},emit:function(a){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)))}}),p(ec,ac,{defaults:{event:"rotate",threshold:0,pointers:2},getTouchAction:function(){return[Mb]},attrTest:function(a){return this._super.attrTest.call(this,a)&&(Math.abs(a.rotation)>this.options.threshold||this.state&Sb)}}),p(fc,ac,{defaults:{event:"swipe",threshold:10,velocity:.65,direction:X|Y,pointers:1},getTouchAction:function(){return bc.prototype.getTouchAction.call(this)},attrTest:function(a){var c,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},emit:function(a){var b=$b(a.direction);b&&this.manager.emit(this.options.event+b,a),this.manager.emit(this.options.event,a)}}),p(gc,Yb,{defaults:{event:"tap",pointers:1,taps:1,interval:300,time:250,threshold:2,posThreshold:10},getTouchAction:function(){return[Lb]},process:function(a){var b=this.options,c=a.pointers.length===b.pointers,d=a.distance<b.threshold,e=a.deltaTime<b.time;if(this.reset(),a.eventType&O&&0===this.count)return this.failTimeout();if(d&&e&&c){if(a.eventType!=Q)return this.failTimeout();var f=this.pTime?a.timeStamp-this.pTime<b.interval:!0,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(){this.state=Vb,this.tryEmit()},b.interval,this),Sb):Vb}return Xb},failTimeout:function(){return this._timer=k(function(){this.state=Xb},this.options.interval,this),Xb},reset:function(){clearTimeout(this._timer)},emit:function(){this.state==Vb&&(this._input.tapCount=this.count,this.manager.emit(this.options.event,this._input))}}),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,jc=2;kc.prototype={set:function(a){return n(this.options,a),a.touchAction&&this.touchAction.update(),a.inputTarget&&(this.input.destroy(),this.input.target=a.inputTarget,this.input.init()),this},stop:function(a){this.session.stopped=a?jc:ic},recognize:function(a){var b=this.session;if(!b.stopped){this.touchAction.preventDefaults(a);var c,d=this.recognizers,e=b.curRecognizer;(!e||e&&e.state&Vb)&&(e=b.curRecognizer=null);for(var f=0;f<d.length;)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++}},get:function(a){if(a instanceof Yb)return a;for(var b=this.recognizers,c=0;c<b.length;c++)if(b[c].options.event==a)return b[c];return null},add:function(a){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},remove:function(a){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},on:function(a,b){var c=this.handlers;return m(x(a),function(a){c[a]=c[a]||[],c[a].push(b)}),this},off:function(a,b){var c=this.handlers;return m(x(a),function(a){b?c[a].splice(y(c[a],b),1):delete c[a]}),this},emit:function(a,b){this.options.domEvents&&mc(a,b);var c=this.handlers[a]&&this.handlers[a].slice();if(c&&c.length){b.type=a,b.preventDefault=function(){b.srcEvent.preventDefault()};for(var d=0;d<c.length;)c[d](b),d++}},destroy:function(){this.element&&lc(this,!1),this.handlers={},this.session={},this.input.destroy(),this.element=null}},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(){return hc}):"undefined"!=typeof module&&module.exports?module.exports=hc:a[c]=hc}(window,document,"Hammer");;(function(factory) {
  189. if (typeof define === 'function' && define.amd) {
  190. define(['jquery', 'hammerjs'], factory);
  191. } else if (typeof exports === 'object') {
  192. factory(require('jquery'), require('hammerjs'));
  193. } else {
  194. factory(jQuery, Hammer);
  195. }
  196. }(function($, Hammer) {
  197. function hammerify(el, options) {
  198. var $el = $(el);
  199. if(!$el.data("hammer")) {
  200. $el.data("hammer", new Hammer($el[0], options));
  201. }
  202. }
  203. $.fn.hammer = function(options) {
  204. return this.each(function() {
  205. hammerify(this, options);
  206. });
  207. };
  208. // extend the emit method to also trigger jQuery events
  209. Hammer.Manager.prototype.emit = (function(originalEmit) {
  210. return function(type, data) {
  211. originalEmit.call(this, type, data);
  212. $(this.element).trigger({
  213. type: type,
  214. gesture: data
  215. });
  216. };
  217. })(Hammer.Manager.prototype.emit);
  218. }));
  219. ;// Required for Meteor package, the use of window prevents export by Meteor
  220. (function(window){
  221. if(window.Package){
  222. Materialize = {};
  223. } else {
  224. window.Materialize = {};
  225. }
  226. })(window);
  227. /*
  228. * raf.js
  229. * https://github.com/ngryman/raf.js
  230. *
  231. * original requestAnimationFrame polyfill by Erik Möller
  232. * inspired from paul_irish gist and post
  233. *
  234. * Copyright (c) 2013 ngryman
  235. * Licensed under the MIT license.
  236. */
  237. (function(window) {
  238. var lastTime = 0,
  239. vendors = ['webkit', 'moz'],
  240. requestAnimationFrame = window.requestAnimationFrame,
  241. cancelAnimationFrame = window.cancelAnimationFrame,
  242. i = vendors.length;
  243. // try to un-prefix existing raf
  244. while (--i >= 0 && !requestAnimationFrame) {
  245. requestAnimationFrame = window[vendors[i] + 'RequestAnimationFrame'];
  246. cancelAnimationFrame = window[vendors[i] + 'CancelRequestAnimationFrame'];
  247. }
  248. // polyfill with setTimeout fallback
  249. // heavily inspired from @darius gist mod: https://gist.github.com/paulirish/1579671#comment-837945
  250. if (!requestAnimationFrame || !cancelAnimationFrame) {
  251. requestAnimationFrame = function(callback) {
  252. var now = +Date.now(),
  253. nextTime = Math.max(lastTime + 16, now);
  254. return setTimeout(function() {
  255. callback(lastTime = nextTime);
  256. }, nextTime - now);
  257. };
  258. cancelAnimationFrame = clearTimeout;
  259. }
  260. // export to window
  261. window.requestAnimationFrame = requestAnimationFrame;
  262. window.cancelAnimationFrame = cancelAnimationFrame;
  263. }(window));
  264. /**
  265. * Generate approximated selector string for a jQuery object
  266. * @param {jQuery} obj jQuery object to be parsed
  267. * @returns {string}
  268. */
  269. Materialize.objectSelectorString = function(obj) {
  270. var tagStr = obj.prop('tagName') || '';
  271. var idStr = obj.attr('id') || '';
  272. var classStr = obj.attr('class') || '';
  273. return (tagStr + idStr + classStr).replace(/\s/g,'');
  274. };
  275. // Unique Random ID
  276. Materialize.guid = (function() {
  277. function s4() {
  278. return Math.floor((1 + Math.random()) * 0x10000)
  279. .toString(16)
  280. .substring(1);
  281. }
  282. return function() {
  283. return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
  284. s4() + '-' + s4() + s4() + s4();
  285. };
  286. })();
  287. /**
  288. * Escapes hash from special characters
  289. * @param {string} hash String returned from this.hash
  290. * @returns {string}
  291. */
  292. Materialize.escapeHash = function(hash) {
  293. return hash.replace( /(:|\.|\[|\]|,|=)/g, "\\$1" );
  294. };
  295. Materialize.elementOrParentIsFixed = function(element) {
  296. var $element = $(element);
  297. var $checkElements = $element.add($element.parents());
  298. var isFixed = false;
  299. $checkElements.each(function(){
  300. if ($(this).css("position") === "fixed") {
  301. isFixed = true;
  302. return false;
  303. }
  304. });
  305. return isFixed;
  306. };
  307. /**
  308. * Get time in ms
  309. * @license https://raw.github.com/jashkenas/underscore/master/LICENSE
  310. * @type {function}
  311. * @return {number}
  312. */
  313. var getTime = (Date.now || function () {
  314. return new Date().getTime();
  315. });
  316. /**
  317. * Returns a function, that, when invoked, will only be triggered at most once
  318. * during a given window of time. Normally, the throttled function will run
  319. * as much as it can, without ever going more than once per `wait` duration;
  320. * but if you'd like to disable the execution on the leading edge, pass
  321. * `{leading: false}`. To disable execution on the trailing edge, ditto.
  322. * @license https://raw.github.com/jashkenas/underscore/master/LICENSE
  323. * @param {function} func
  324. * @param {number} wait
  325. * @param {Object=} options
  326. * @returns {Function}
  327. */
  328. Materialize.throttle = function(func, wait, options) {
  329. var context, args, result;
  330. var timeout = null;
  331. var previous = 0;
  332. options || (options = {});
  333. var later = function () {
  334. previous = options.leading === false ? 0 : getTime();
  335. timeout = null;
  336. result = func.apply(context, args);
  337. context = args = null;
  338. };
  339. return function () {
  340. var now = getTime();
  341. if (!previous && options.leading === false) previous = now;
  342. var remaining = wait - (now - previous);
  343. context = this;
  344. args = arguments;
  345. if (remaining <= 0) {
  346. clearTimeout(timeout);
  347. timeout = null;
  348. previous = now;
  349. result = func.apply(context, args);
  350. context = args = null;
  351. } else if (!timeout && options.trailing !== false) {
  352. timeout = setTimeout(later, remaining);
  353. }
  354. return result;
  355. };
  356. };
  357. // Velocity has conflicts when loaded with jQuery, this will check for it
  358. // First, check if in noConflict mode
  359. var Vel;
  360. if (jQuery) {
  361. Vel = jQuery.Velocity;
  362. } else if ($) {
  363. Vel = $.Velocity;
  364. } else {
  365. Vel = Velocity;
  366. }
  367. ;(function ($) {
  368. $.fn.collapsible = function(options, methodParam) {
  369. var defaults = {
  370. accordion: undefined,
  371. onOpen: undefined,
  372. onClose: undefined
  373. };
  374. var methodName = options;
  375. options = $.extend(defaults, options);
  376. return this.each(function() {
  377. var $this = $(this);
  378. var $panel_headers = $(this).find('> li > .collapsible-header');
  379. var collapsible_type = $this.data("collapsible");
  380. /****************
  381. Helper Functions
  382. ****************/
  383. // Accordion Open
  384. function accordionOpen(object) {
  385. $panel_headers = $this.find('> li > .collapsible-header');
  386. if (object.hasClass('active')) {
  387. object.parent().addClass('active');
  388. }
  389. else {
  390. object.parent().removeClass('active');
  391. }
  392. if (object.parent().hasClass('active')){
  393. object.siblings('.collapsible-body').stop(true,false).slideDown({ duration: 350, easing: "easeOutQuart", queue: false, complete: function() {$(this).css('height', '');}});
  394. }
  395. else{
  396. object.siblings('.collapsible-body').stop(true,false).slideUp({ duration: 350, easing: "easeOutQuart", queue: false, complete: function() {$(this).css('height', '');}});
  397. }
  398. $panel_headers.not(object).removeClass('active').parent().removeClass('active');
  399. // Close previously open accordion elements.
  400. $panel_headers.not(object).parent().children('.collapsible-body').stop(true,false).each(function() {
  401. if ($(this).is(':visible')) {
  402. $(this).slideUp({
  403. duration: 350,
  404. easing: "easeOutQuart",
  405. queue: false,
  406. complete:
  407. function() {
  408. $(this).css('height', '');
  409. execCallbacks($(this).siblings('.collapsible-header'));
  410. }
  411. });
  412. }
  413. });
  414. }
  415. // Expandable Open
  416. function expandableOpen(object) {
  417. if (object.hasClass('active')) {
  418. object.parent().addClass('active');
  419. }
  420. else {
  421. object.parent().removeClass('active');
  422. }
  423. if (object.parent().hasClass('active')){
  424. object.siblings('.collapsible-body').stop(true,false).slideDown({ duration: 350, easing: "easeOutQuart", queue: false, complete: function() {$(this).css('height', '');}});
  425. }
  426. else {
  427. object.siblings('.collapsible-body').stop(true,false).slideUp({ duration: 350, easing: "easeOutQuart", queue: false, complete: function() {$(this).css('height', '');}});
  428. }
  429. }
  430. // Open collapsible. object: .collapsible-header
  431. function collapsibleOpen(object, noToggle) {
  432. if (!noToggle) {
  433. object.toggleClass('active');
  434. }
  435. if (options.accordion || collapsible_type === "accordion" || collapsible_type === undefined) { // Handle Accordion
  436. accordionOpen(object);
  437. } else { // Handle Expandables
  438. expandableOpen(object);
  439. }
  440. execCallbacks(object);
  441. }
  442. // Handle callbacks
  443. function execCallbacks(object) {
  444. if (object.hasClass('active')) {
  445. if (typeof(options.onOpen) === "function") {
  446. options.onOpen.call(this, object.parent());
  447. }
  448. } else {
  449. if (typeof(options.onClose) === "function") {
  450. options.onClose.call(this, object.parent());
  451. }
  452. }
  453. }
  454. /**
  455. * Check if object is children of panel header
  456. * @param {Object} object Jquery object
  457. * @return {Boolean} true if it is children
  458. */
  459. function isChildrenOfPanelHeader(object) {
  460. var panelHeader = getPanelHeader(object);
  461. return panelHeader.length > 0;
  462. }
  463. /**
  464. * Get panel header from a children element
  465. * @param {Object} object Jquery object
  466. * @return {Object} panel header object
  467. */
  468. function getPanelHeader(object) {
  469. return object.closest('li > .collapsible-header');
  470. }
  471. // Turn off any existing event handlers
  472. function removeEventHandlers() {
  473. $this.off('click.collapse', '> li > .collapsible-header');
  474. }
  475. /***** End Helper Functions *****/
  476. // Methods
  477. if (methodName === 'destroy') {
  478. removeEventHandlers();
  479. return;
  480. } else if (methodParam >= 0 &&
  481. methodParam < $panel_headers.length) {
  482. var $curr_header = $panel_headers.eq(methodParam);
  483. if ($curr_header.length &&
  484. (methodName === 'open' ||
  485. (methodName === 'close' &&
  486. $curr_header.hasClass('active')))) {
  487. collapsibleOpen($curr_header);
  488. }
  489. return;
  490. }
  491. removeEventHandlers();
  492. // Add click handler to only direct collapsible header children
  493. $this.on('click.collapse', '> li > .collapsible-header', function(e) {
  494. var element = $(e.target);
  495. if (isChildrenOfPanelHeader(element)) {
  496. element = getPanelHeader(element);
  497. }
  498. collapsibleOpen(element);
  499. });
  500. // Open first active
  501. if (options.accordion || collapsible_type === "accordion" || collapsible_type === undefined) { // Handle Accordion
  502. collapsibleOpen($panel_headers.filter('.active').first(), true);
  503. } else { // Handle Expandables
  504. $panel_headers.filter('.active').each(function() {
  505. collapsibleOpen($(this), true);
  506. });
  507. }
  508. });
  509. };
  510. $(document).ready(function(){
  511. $('.collapsible').collapsible();
  512. });
  513. }( jQuery ));;(function ($) {
  514. // Add posibility to scroll to selected option
  515. // usefull for select for example
  516. $.fn.scrollTo = function(elem) {
  517. $(this).scrollTop($(this).scrollTop() - $(this).offset().top + $(elem).offset().top);
  518. return this;
  519. };
  520. $.fn.dropdown = function (options) {
  521. var defaults = {
  522. inDuration: 300,
  523. outDuration: 225,
  524. constrainWidth: true, // Constrains width of dropdown to the activator
  525. hover: false,
  526. gutter: 0, // Spacing from edge
  527. belowOrigin: false,
  528. alignment: 'left',
  529. stopPropagation: false
  530. };
  531. // Open dropdown.
  532. if (options === "open") {
  533. this.each(function() {
  534. $(this).trigger('open');
  535. });
  536. return false;
  537. }
  538. // Close dropdown.
  539. if (options === "close") {
  540. this.each(function() {
  541. $(this).trigger('close');
  542. });
  543. return false;
  544. }
  545. this.each(function(){
  546. var origin = $(this);
  547. var curr_options = $.extend({}, defaults, options);
  548. var isFocused = false;
  549. // Dropdown menu
  550. var activates = $("#"+ origin.attr('data-activates'));
  551. function updateOptions() {
  552. if (origin.data('induration') !== undefined)
  553. curr_options.inDuration = origin.data('induration');
  554. if (origin.data('outduration') !== undefined)
  555. curr_options.outDuration = origin.data('outduration');
  556. if (origin.data('constrainwidth') !== undefined)
  557. curr_options.constrainWidth = origin.data('constrainwidth');
  558. if (origin.data('hover') !== undefined)
  559. curr_options.hover = origin.data('hover');
  560. if (origin.data('gutter') !== undefined)
  561. curr_options.gutter = origin.data('gutter');
  562. if (origin.data('beloworigin') !== undefined)
  563. curr_options.belowOrigin = origin.data('beloworigin');
  564. if (origin.data('alignment') !== undefined)
  565. curr_options.alignment = origin.data('alignment');
  566. if (origin.data('stoppropagation') !== undefined)
  567. curr_options.stopPropagation = origin.data('stoppropagation');
  568. }
  569. updateOptions();
  570. // Attach dropdown to its activator
  571. origin.after(activates);
  572. /*
  573. Helper function to position and resize dropdown.
  574. Used in hover and click handler.
  575. */
  576. function placeDropdown(eventType) {
  577. // Check for simultaneous focus and click events.
  578. if (eventType === 'focus') {
  579. isFocused = true;
  580. }
  581. // Check html data attributes
  582. updateOptions();
  583. // Set Dropdown state
  584. activates.addClass('active');
  585. origin.addClass('active');
  586. // Constrain width
  587. if (curr_options.constrainWidth === true) {
  588. activates.css('width', origin.outerWidth());
  589. } else {
  590. activates.css('white-space', 'nowrap');
  591. }
  592. // Offscreen detection
  593. var windowHeight = window.innerHeight;
  594. var originHeight = origin.innerHeight();
  595. var offsetLeft = origin.offset().left;
  596. var offsetTop = origin.offset().top - $(window).scrollTop();
  597. var currAlignment = curr_options.alignment;
  598. var gutterSpacing = 0;
  599. var leftPosition = 0;
  600. // Below Origin
  601. var verticalOffset = 0;
  602. if (curr_options.belowOrigin === true) {
  603. verticalOffset = originHeight;
  604. }
  605. // Check for scrolling positioned container.
  606. var scrollYOffset = 0;
  607. var scrollXOffset = 0;
  608. var wrapper = origin.parent();
  609. if (!wrapper.is('body')) {
  610. if (wrapper[0].scrollHeight > wrapper[0].clientHeight) {
  611. scrollYOffset = wrapper[0].scrollTop;
  612. }
  613. if (wrapper[0].scrollWidth > wrapper[0].clientWidth) {
  614. scrollXOffset = wrapper[0].scrollLeft;
  615. }
  616. }
  617. if (offsetLeft + activates.innerWidth() > $(window).width()) {
  618. // Dropdown goes past screen on right, force right alignment
  619. currAlignment = 'right';
  620. } else if (offsetLeft - activates.innerWidth() + origin.innerWidth() < 0) {
  621. // Dropdown goes past screen on left, force left alignment
  622. currAlignment = 'left';
  623. }
  624. // Vertical bottom offscreen detection
  625. if (offsetTop + activates.innerHeight() > windowHeight) {
  626. // If going upwards still goes offscreen, just crop height of dropdown.
  627. if (offsetTop + originHeight - activates.innerHeight() < 0) {
  628. var adjustedHeight = windowHeight - offsetTop - verticalOffset;
  629. activates.css('max-height', adjustedHeight);
  630. } else {
  631. // Flow upwards.
  632. if (!verticalOffset) {
  633. verticalOffset += originHeight;
  634. }
  635. verticalOffset -= activates.innerHeight();
  636. }
  637. }
  638. // Handle edge alignment
  639. if (currAlignment === 'left') {
  640. gutterSpacing = curr_options.gutter;
  641. leftPosition = origin.position().left + gutterSpacing;
  642. }
  643. else if (currAlignment === 'right') {
  644. // Material icons fix
  645. activates
  646. .stop(true, true)
  647. .css({
  648. opacity: 0,
  649. left: 0
  650. })
  651. var offsetRight = origin.position().left + origin.outerWidth() - activates.outerWidth();
  652. gutterSpacing = -curr_options.gutter;
  653. leftPosition = offsetRight + gutterSpacing;
  654. }
  655. // Position dropdown
  656. activates.css({
  657. position: 'absolute',
  658. top: origin.position().top + verticalOffset + scrollYOffset,
  659. left: leftPosition + scrollXOffset
  660. });
  661. // Show dropdown
  662. activates
  663. .slideDown({
  664. queue: false,
  665. duration: curr_options.inDuration,
  666. easing: 'easeOutCubic',
  667. complete: function() {
  668. $(this).css('height', '');
  669. }
  670. })
  671. .animate( {opacity: 1}, {queue: false, duration: curr_options.inDuration, easing: 'easeOutSine'});
  672. // Add click close handler to document
  673. setTimeout(function() {
  674. $(document).on('click.'+ activates.attr('id'), function (e) {
  675. hideDropdown();
  676. $(document).off('click.'+ activates.attr('id'));
  677. });
  678. }, 0);
  679. }
  680. function hideDropdown() {
  681. // Check for simultaneous focus and click events.
  682. isFocused = false;
  683. activates.fadeOut(curr_options.outDuration);
  684. activates.removeClass('active');
  685. origin.removeClass('active');
  686. $(document).off('click.'+ activates.attr('id'));
  687. setTimeout(function() { activates.css('max-height', ''); }, curr_options.outDuration);
  688. }
  689. // Hover
  690. if (curr_options.hover) {
  691. var open = false;
  692. origin.off('click.' + origin.attr('id'));
  693. // Hover handler to show dropdown
  694. origin.on('mouseenter', function(e){ // Mouse over
  695. if (open === false) {
  696. placeDropdown();
  697. open = true;
  698. }
  699. });
  700. origin.on('mouseleave', function(e){
  701. // If hover on origin then to something other than dropdown content, then close
  702. var toEl = e.toElement || e.relatedTarget; // added browser compatibility for target element
  703. if(!$(toEl).closest('.dropdown-content').is(activates)) {
  704. activates.stop(true, true);
  705. hideDropdown();
  706. open = false;
  707. }
  708. });
  709. activates.on('mouseleave', function(e){ // Mouse out
  710. var toEl = e.toElement || e.relatedTarget;
  711. if(!$(toEl).closest('.dropdown-button').is(origin)) {
  712. activates.stop(true, true);
  713. hideDropdown();
  714. open = false;
  715. }
  716. });
  717. // Click
  718. } else {
  719. // Click handler to show dropdown
  720. origin.off('click.' + origin.attr('id'));
  721. origin.on('click.'+origin.attr('id'), function(e){
  722. if (!isFocused) {
  723. if ( origin[0] == e.currentTarget &&
  724. !origin.hasClass('active') &&
  725. ($(e.target).closest('.dropdown-content').length === 0)) {
  726. e.preventDefault(); // Prevents button click from moving window
  727. if (curr_options.stopPropagation) {
  728. e.stopPropagation();
  729. }
  730. placeDropdown('click');
  731. }
  732. // If origin is clicked and menu is open, close menu
  733. else if (origin.hasClass('active')) {
  734. hideDropdown();
  735. $(document).off('click.'+ activates.attr('id'));
  736. }
  737. }
  738. });
  739. } // End else
  740. // Listen to open and close event - useful for select component
  741. origin.on('open', function(e, eventType) {
  742. placeDropdown(eventType);
  743. });
  744. origin.on('close', hideDropdown);
  745. });
  746. }; // End dropdown plugin
  747. $(document).ready(function(){
  748. $('.dropdown-button').dropdown();
  749. });
  750. }( jQuery ));
  751. ;(function($) {
  752. var _stack = 0,
  753. _lastID = 0,
  754. _generateID = function() {
  755. _lastID++;
  756. return 'materialize-modal-overlay-' + _lastID;
  757. };
  758. var methods = {
  759. init : function(options) {
  760. var defaults = {
  761. opacity: 0.5,
  762. inDuration: 350,
  763. outDuration: 250,
  764. ready: undefined,
  765. complete: undefined,
  766. dismissible: true,
  767. startingTop: '4%',
  768. endingTop: '10%'
  769. };
  770. // Override defaults
  771. options = $.extend(defaults, options);
  772. return this.each(function() {
  773. var $modal = $(this);
  774. var modal_id = $(this).attr("id") || '#' + $(this).data('target');
  775. var closeModal = function() {
  776. var overlayID = $modal.data('overlay-id');
  777. var $overlay = $('#' + overlayID);
  778. $modal.removeClass('open');
  779. // Enable scrolling
  780. $('body').css({
  781. overflow: '',
  782. width: ''
  783. });
  784. $modal.find('.modal-close').off('click.close');
  785. $(document).off('keyup.modal' + overlayID);
  786. $overlay.velocity( { opacity: 0}, {duration: options.outDuration, queue: false, ease: "easeOutQuart"});
  787. // Define Bottom Sheet animation
  788. var exitVelocityOptions = {
  789. duration: options.outDuration,
  790. queue: false,
  791. ease: "easeOutCubic",
  792. // Handle modal ready callback
  793. complete: function() {
  794. $(this).css({display:"none"});
  795. // Call complete callback
  796. if (typeof(options.complete) === "function") {
  797. options.complete.call(this, $modal);
  798. }
  799. $overlay.remove();
  800. _stack--;
  801. }
  802. };
  803. if ($modal.hasClass('bottom-sheet')) {
  804. $modal.velocity({bottom: "-100%", opacity: 0}, exitVelocityOptions);
  805. }
  806. else {
  807. $modal.velocity(
  808. { top: options.startingTop, opacity: 0, scaleX: 0.7},
  809. exitVelocityOptions
  810. );
  811. }
  812. };
  813. var openModal = function($trigger) {
  814. var $body = $('body');
  815. var oldWidth = $body.innerWidth();
  816. $body.css('overflow', 'hidden');
  817. $body.width(oldWidth);
  818. if ($modal.hasClass('open')) {
  819. return;
  820. }
  821. var overlayID = _generateID();
  822. var $overlay = $('<div class="modal-overlay"></div>');
  823. var lStack = (++_stack);
  824. // Store a reference of the overlay
  825. $overlay.attr('id', overlayID).css('z-index', 1000 + lStack * 2);
  826. $modal.data('overlay-id', overlayID).css('z-index', 1000 + lStack * 2 + 1);
  827. $modal.addClass('open');
  828. $("body").append($overlay);
  829. if (options.dismissible) {
  830. $overlay.click(function() {
  831. closeModal();
  832. });
  833. // Return on ESC
  834. $(document).on('keyup.modal' + overlayID, function(e) {
  835. if (e.keyCode === 27) { // ESC key
  836. closeModal();
  837. }
  838. });
  839. }
  840. $modal.find(".modal-close").on('click.close', function(e) {
  841. closeModal();
  842. });
  843. $overlay.css({ display : "block", opacity : 0 });
  844. $modal.css({
  845. display : "block",
  846. opacity: 0
  847. });
  848. $overlay.velocity({opacity: options.opacity}, {duration: options.inDuration, queue: false, ease: "easeOutCubic"});
  849. $modal.data('associated-overlay', $overlay[0]);
  850. // Define Bottom Sheet animation
  851. var enterVelocityOptions = {
  852. duration: options.inDuration,
  853. queue: false,
  854. ease: "easeOutCubic",
  855. // Handle modal ready callback
  856. complete: function() {
  857. if (typeof(options.ready) === "function") {
  858. options.ready.call(this, $modal, $trigger);
  859. }
  860. }
  861. };
  862. if ($modal.hasClass('bottom-sheet')) {
  863. $modal.velocity({bottom: "0", opacity: 1}, enterVelocityOptions);
  864. }
  865. else {
  866. $.Velocity.hook($modal, "scaleX", 0.7);
  867. $modal.css({ top: options.startingTop });
  868. $modal.velocity({top: options.endingTop, opacity: 1, scaleX: '1'}, enterVelocityOptions);
  869. }
  870. };
  871. // Reset handlers
  872. $(document).off('click.modalTrigger', 'a[href="#' + modal_id + '"], [data-target="' + modal_id + '"]');
  873. $(this).off('openModal');
  874. $(this).off('closeModal');
  875. // Close Handlers
  876. $(document).on('click.modalTrigger', 'a[href="#' + modal_id + '"], [data-target="' + modal_id + '"]', function(e) {
  877. options.startingTop = ($(this).offset().top - $(window).scrollTop()) /1.15;
  878. openModal($(this));
  879. e.preventDefault();
  880. }); // done set on click
  881. $(this).on('openModal', function() {
  882. var modal_id = $(this).attr("href") || '#' + $(this).data('target');
  883. openModal();
  884. });
  885. $(this).on('closeModal', function() {
  886. closeModal();
  887. });
  888. }); // done return
  889. },
  890. open : function() {
  891. methods.init.apply( this, arguments );
  892. $(this).trigger('openModal');
  893. },
  894. close : function() {
  895. $(this).trigger('closeModal');
  896. }
  897. };
  898. $.fn.modal = function(methodOrOptions) {
  899. if ( methods[methodOrOptions] ) {
  900. return methods[ methodOrOptions ].apply( this, Array.prototype.slice.call( arguments, 1 ));
  901. } else if ( typeof methodOrOptions === 'object' || ! methodOrOptions ) {
  902. // Default to "init"
  903. return methods.init.apply( this, arguments );
  904. } else {
  905. $.error( 'Method ' + methodOrOptions + ' does not exist on jQuery.modal' );
  906. }
  907. };
  908. })(jQuery);
  909. ;(function ($) {
  910. $.fn.materialbox = function () {
  911. return this.each(function() {
  912. if ($(this).hasClass('initialized')) {
  913. return;
  914. }
  915. $(this).addClass('initialized');
  916. var overlayActive = false;
  917. var doneAnimating = true;
  918. var inDuration = 275;
  919. var outDuration = 200;
  920. var origin = $(this);
  921. var placeholder = $('<div></div>').addClass('material-placeholder');
  922. var originalWidth = 0;
  923. var originalHeight = 0;
  924. var ancestorsChanged;
  925. var ancestor;
  926. var originInlineStyles = origin.attr('style');
  927. origin.wrap(placeholder);
  928. // Start click handler
  929. origin.on('click', function() {
  930. var placeholder = origin.parent('.material-placeholder');
  931. var windowWidth = window.innerWidth;
  932. var windowHeight = window.innerHeight;
  933. var originalWidth = origin.width();
  934. var originalHeight = origin.height();
  935. // If already modal, return to original
  936. if (doneAnimating === false) {
  937. returnToOriginal();
  938. return false;
  939. }
  940. else if (overlayActive && doneAnimating===true) {
  941. returnToOriginal();
  942. return false;
  943. }
  944. // Set states
  945. doneAnimating = false;
  946. origin.addClass('active');
  947. overlayActive = true;
  948. // Set positioning for placeholder
  949. placeholder.css({
  950. width: placeholder[0].getBoundingClientRect().width,
  951. height: placeholder[0].getBoundingClientRect().height,
  952. position: 'relative',
  953. top: 0,
  954. left: 0
  955. });
  956. // Find ancestor with overflow: hidden; and remove it
  957. ancestorsChanged = undefined;
  958. ancestor = placeholder[0].parentNode;
  959. var count = 0;
  960. while (ancestor !== null && !$(ancestor).is(document)) {
  961. var curr = $(ancestor);
  962. if (curr.css('overflow') !== 'visible') {
  963. curr.css('overflow', 'visible');
  964. if (ancestorsChanged === undefined) {
  965. ancestorsChanged = curr;
  966. }
  967. else {
  968. ancestorsChanged = ancestorsChanged.add(curr);
  969. }
  970. }
  971. ancestor = ancestor.parentNode;
  972. }
  973. // Set css on origin
  974. origin.css({
  975. position: 'absolute',
  976. 'z-index': 1000,
  977. 'will-change': 'left, top, width, height'
  978. })
  979. .data('width', originalWidth)
  980. .data('height', originalHeight);
  981. // Add overlay
  982. var overlay = $('<div id="materialbox-overlay"></div>')
  983. .css({
  984. opacity: 0
  985. })
  986. .click(function(){
  987. if (doneAnimating === true)
  988. returnToOriginal();
  989. });
  990. // Put before in origin image to preserve z-index layering.
  991. origin.before(overlay);
  992. // Set dimensions if needed
  993. var overlayOffset = overlay[0].getBoundingClientRect();
  994. overlay.css({
  995. width: windowWidth,
  996. height: windowHeight,
  997. left: -1 * overlayOffset.left,
  998. top: -1 * overlayOffset.top
  999. })
  1000. // Animate Overlay
  1001. overlay.velocity({opacity: 1},
  1002. {duration: inDuration, queue: false, easing: 'easeOutQuad'} );
  1003. // Add and animate caption if it exists
  1004. if (origin.data('caption') !== "") {
  1005. var $photo_caption = $('<div class="materialbox-caption"></div>');
  1006. $photo_caption.text(origin.data('caption'));
  1007. $('body').append($photo_caption);
  1008. $photo_caption.css({ "display": "inline" });
  1009. $photo_caption.velocity({opacity: 1}, {duration: inDuration, queue: false, easing: 'easeOutQuad'});
  1010. }
  1011. // Resize Image
  1012. var ratio = 0;
  1013. var widthPercent = originalWidth / windowWidth;
  1014. var heightPercent = originalHeight / windowHeight;
  1015. var newWidth = 0;
  1016. var newHeight = 0;
  1017. if (widthPercent > heightPercent) {
  1018. ratio = originalHeight / originalWidth;
  1019. newWidth = windowWidth * 0.9;
  1020. newHeight = windowWidth * 0.9 * ratio;
  1021. }
  1022. else {
  1023. ratio = originalWidth / originalHeight;
  1024. newWidth = (windowHeight * 0.9) * ratio;
  1025. newHeight = windowHeight * 0.9;
  1026. }
  1027. // Animate image + set z-index
  1028. if(origin.hasClass('responsive-img')) {
  1029. origin.velocity({'max-width': newWidth, 'width': originalWidth}, {duration: 0, queue: false,
  1030. complete: function(){
  1031. origin.css({left: 0, top: 0})
  1032. .velocity(
  1033. {
  1034. height: newHeight,
  1035. width: newWidth,
  1036. left: $(document).scrollLeft() + windowWidth/2 - origin.parent('.material-placeholder').offset().left - newWidth/2,
  1037. top: $(document).scrollTop() + windowHeight/2 - origin.parent('.material-placeholder').offset().top - newHeight/ 2
  1038. },
  1039. {
  1040. duration: inDuration,
  1041. queue: false,
  1042. easing: 'easeOutQuad',
  1043. complete: function(){doneAnimating = true;}
  1044. }
  1045. );
  1046. } // End Complete
  1047. }); // End Velocity
  1048. }
  1049. else {
  1050. origin.css('left', 0)
  1051. .css('top', 0)
  1052. .velocity(
  1053. {
  1054. height: newHeight,
  1055. width: newWidth,
  1056. left: $(document).scrollLeft() + windowWidth/2 - origin.parent('.material-placeholder').offset().left - newWidth/2,
  1057. top: $(document).scrollTop() + windowHeight/2 - origin.parent('.material-placeholder').offset().top - newHeight/ 2
  1058. },
  1059. {
  1060. duration: inDuration,
  1061. queue: false,
  1062. easing: 'easeOutQuad',
  1063. complete: function(){doneAnimating = true;}
  1064. }
  1065. ); // End Velocity
  1066. }
  1067. // Handle Exit triggers
  1068. $(window).on('scroll.materialbox', function() {
  1069. if (overlayActive) {
  1070. returnToOriginal();
  1071. }
  1072. });
  1073. $(window).on('resize.materialbox', function() {
  1074. if (overlayActive) {
  1075. returnToOriginal();
  1076. }
  1077. });
  1078. $(document).on('keyup.materialbox', function(e) {
  1079. // ESC key
  1080. if (e.keyCode === 27 &&
  1081. doneAnimating === true &&
  1082. overlayActive) {
  1083. returnToOriginal();
  1084. }
  1085. });
  1086. }); // End click handler
  1087. // This function returns the modaled image to the original spot
  1088. function returnToOriginal() {
  1089. doneAnimating = false;
  1090. var placeholder = origin.parent('.material-placeholder');
  1091. var windowWidth = window.innerWidth;
  1092. var windowHeight = window.innerHeight;
  1093. var originalWidth = origin.data('width');
  1094. var originalHeight = origin.data('height');
  1095. origin.velocity("stop", true);
  1096. $('#materialbox-overlay').velocity("stop", true);
  1097. $('.materialbox-caption').velocity("stop", true);
  1098. // disable exit handlers
  1099. $(window).off('scroll.materialbox');
  1100. $(document).off('keyup.materialbox');
  1101. $(window).off('resize.materialbox');
  1102. $('#materialbox-overlay').velocity({opacity: 0}, {
  1103. duration: outDuration, // Delay prevents animation overlapping
  1104. queue: false, easing: 'easeOutQuad',
  1105. complete: function(){
  1106. // Remove Overlay
  1107. overlayActive = false;
  1108. $(this).remove();
  1109. }
  1110. });
  1111. // Resize Image
  1112. origin.velocity(
  1113. {
  1114. width: originalWidth,
  1115. height: originalHeight,
  1116. left: 0,
  1117. top: 0
  1118. },
  1119. {
  1120. duration: outDuration,
  1121. queue: false, easing: 'easeOutQuad',
  1122. complete: function() {
  1123. placeholder.css({
  1124. height: '',
  1125. width: '',
  1126. position: '',
  1127. top: '',
  1128. left: ''
  1129. });
  1130. origin.removeAttr('style');
  1131. origin.attr('style', originInlineStyles);
  1132. // Remove class
  1133. origin.removeClass('active');
  1134. doneAnimating = true;
  1135. // Remove overflow overrides on ancestors
  1136. if (ancestorsChanged) {
  1137. ancestorsChanged.css('overflow', '');
  1138. }
  1139. }
  1140. }
  1141. );
  1142. // Remove Caption + reset css settings on image
  1143. $('.materialbox-caption').velocity({opacity: 0}, {
  1144. duration: outDuration, // Delay prevents animation overlapping
  1145. queue: false, easing: 'easeOutQuad',
  1146. complete: function(){
  1147. $(this).remove();
  1148. }
  1149. });
  1150. }
  1151. });
  1152. };
  1153. $(document).ready(function(){
  1154. $('.materialboxed').materialbox();
  1155. });
  1156. }( jQuery ));
  1157. ;(function ($) {
  1158. $.fn.parallax = function () {
  1159. var window_width = $(window).width();
  1160. // Parallax Scripts
  1161. return this.each(function(i) {
  1162. var $this = $(this);
  1163. $this.addClass('parallax');
  1164. function updateParallax(initial) {
  1165. var container_height;
  1166. if (window_width < 601) {
  1167. container_height = ($this.height() > 0) ? $this.height() : $this.children("img").height();
  1168. }
  1169. else {
  1170. container_height = ($this.height() > 0) ? $this.height() : 500;
  1171. }
  1172. var $img = $this.children("img").first();
  1173. var img_height = $img.height();
  1174. var parallax_dist = img_height - container_height;
  1175. var bottom = $this.offset().top + container_height;
  1176. var top = $this.offset().top;
  1177. var scrollTop = $(window).scrollTop();
  1178. var windowHeight = window.innerHeight;
  1179. var windowBottom = scrollTop + windowHeight;
  1180. var percentScrolled = (windowBottom - top) / (container_height + windowHeight);
  1181. var parallax = Math.round((parallax_dist * percentScrolled));
  1182. if (initial) {
  1183. $img.css('display', 'block');
  1184. }
  1185. if ((bottom > scrollTop) && (top < (scrollTop + windowHeight))) {
  1186. $img.css('transform', "translate3D(-50%," + parallax + "px, 0)");
  1187. }
  1188. }
  1189. // Wait for image load
  1190. $this.children("img").one("load", function() {
  1191. updateParallax(true);
  1192. }).each(function() {
  1193. if (this.complete) $(this).trigger("load");
  1194. });
  1195. $(window).scroll(function() {
  1196. window_width = $(window).width();
  1197. updateParallax(false);
  1198. });
  1199. $(window).resize(function() {
  1200. window_width = $(window).width();
  1201. updateParallax(false);
  1202. });
  1203. });
  1204. };
  1205. }( jQuery ));
  1206. ;(function ($) {
  1207. var methods = {
  1208. init : function(options) {
  1209. var defaults = {
  1210. onShow: null,
  1211. swipeable: false,
  1212. responsiveThreshold: Infinity, // breakpoint for swipeable
  1213. };
  1214. options = $.extend(defaults, options);
  1215. var namespace = Materialize.objectSelectorString($(this));
  1216. return this.each(function(i) {
  1217. var uniqueNamespace = namespace+i;
  1218. // For each set of tabs, we want to keep track of
  1219. // which tab is active and its associated content
  1220. var $this = $(this),
  1221. window_width = $(window).width();
  1222. var $active, $content, $links = $this.find('li.tab a'),
  1223. $tabs_width = $this.width(),
  1224. $tabs_content = $(),
  1225. $tabs_wrapper,
  1226. $tab_width = Math.max($tabs_width, $this[0].scrollWidth) / $links.length,
  1227. $indicator,
  1228. index = prev_index = 0,
  1229. clicked = false,
  1230. clickedTimeout,
  1231. transition = 300;
  1232. // Finds right attribute for indicator based on active tab.
  1233. // el: jQuery Object
  1234. var calcRightPos = function(el) {
  1235. return Math.ceil($tabs_width - el.position().left - el.outerWidth() - $this.scrollLeft());
  1236. };
  1237. // Finds left attribute for indicator based on active tab.
  1238. // el: jQuery Object
  1239. var calcLeftPos = function(el) {
  1240. return Math.floor(el.position().left + $this.scrollLeft());
  1241. };
  1242. // Animates Indicator to active tab.
  1243. // prev_index: Number
  1244. var animateIndicator = function(prev_index) {
  1245. if ((index - prev_index) >= 0) {
  1246. $indicator.velocity({"right": calcRightPos($active) }, { duration: transition, queue: false, easing: 'easeOutQuad'});
  1247. $indicator.velocity({"left": calcLeftPos($active) }, {duration: transition, queue: false, easing: 'easeOutQuad', delay: 90});
  1248. } else {
  1249. $indicator.velocity({"left": calcLeftPos($active) }, { duration: transition, queue: false, easing: 'easeOutQuad'});
  1250. $indicator.velocity({"right": calcRightPos($active) }, {duration: transition, queue: false, easing: 'easeOutQuad', delay: 90});
  1251. }
  1252. };
  1253. // Change swipeable according to responsive threshold
  1254. if (options.swipeable) {
  1255. if (window_width > options.responsiveThreshold) {
  1256. options.swipeable = false;
  1257. }
  1258. }
  1259. // If the location.hash matches one of the links, use that as the active tab.
  1260. $active = $($links.filter('[href="'+location.hash+'"]'));
  1261. // If no match is found, use the first link or any with class 'active' as the initial active tab.
  1262. if ($active.length === 0) {
  1263. $active = $(this).find('li.tab a.active').first();
  1264. }
  1265. if ($active.length === 0) {
  1266. $active = $(this).find('li.tab a').first();
  1267. }
  1268. $active.addClass('active');
  1269. index = $links.index($active);
  1270. if (index < 0) {
  1271. index = 0;
  1272. }
  1273. if ($active[0] !== undefined) {
  1274. $content = $($active[0].hash);
  1275. $content.addClass('active');
  1276. }
  1277. // append indicator then set indicator width to tab width
  1278. if (!$this.find('.indicator').length) {
  1279. $this.append('<li class="indicator"></li>');
  1280. }
  1281. $indicator = $this.find('.indicator');
  1282. // we make sure that the indicator is at the end of the tabs
  1283. $this.append($indicator);
  1284. if ($this.is(":visible")) {
  1285. // $indicator.css({"right": $tabs_width - ((index + 1) * $tab_width)});
  1286. // $indicator.css({"left": index * $tab_width});
  1287. setTimeout(function() {
  1288. $indicator.css({"right": calcRightPos($active) });
  1289. $indicator.css({"left": calcLeftPos($active) });
  1290. }, 0);
  1291. }
  1292. $(window).off('resize.tabs-'+uniqueNamespace).on('resize.tabs-'+uniqueNamespace, function () {
  1293. $tabs_width = $this.width();
  1294. $tab_width = Math.max($tabs_width, $this[0].scrollWidth) / $links.length;
  1295. if (index < 0) {
  1296. index = 0;
  1297. }
  1298. if ($tab_width !== 0 && $tabs_width !== 0) {
  1299. $indicator.css({"right": calcRightPos($active) });
  1300. $indicator.css({"left": calcLeftPos($active) });
  1301. }
  1302. });
  1303. // Initialize Tabs Content.
  1304. if (options.swipeable) {
  1305. // TODO: Duplicate calls with swipeable? handle multiple div wrapping.
  1306. $links.each(function () {
  1307. var $curr_content = $(Materialize.escapeHash(this.hash));
  1308. $curr_content.addClass('carousel-item');
  1309. $tabs_content = $tabs_content.add($curr_content);
  1310. });
  1311. $tabs_wrapper = $tabs_content.wrapAll('<div class="tabs-content carousel"></div>');
  1312. $tabs_content.css('display', '');
  1313. $('.tabs-content.carousel').carousel({
  1314. fullWidth: true,
  1315. noWrap: true,
  1316. onCycleTo: function(item) {
  1317. if (!clicked) {
  1318. var prev_index = index;
  1319. index = $tabs_wrapper.index(item);
  1320. $active = $links.eq(index);
  1321. animateIndicator(prev_index);
  1322. if (typeof(options.onShow) === "function") {
  1323. options.onShow.call($this[0], $content);
  1324. }
  1325. }
  1326. },
  1327. });
  1328. } else {
  1329. // Hide the remaining content
  1330. $links.not($active).each(function () {
  1331. $(Materialize.escapeHash(this.hash)).hide();
  1332. });
  1333. }
  1334. // Bind the click event handler
  1335. $this.off('click.tabs').on('click.tabs', 'a', function(e) {
  1336. if ($(this).parent().hasClass('disabled')) {
  1337. e.preventDefault();
  1338. return;
  1339. }
  1340. // Act as regular link if target attribute is specified.
  1341. if (!!$(this).attr("target")) {
  1342. return;
  1343. }
  1344. clicked = true;
  1345. $tabs_width = $this.width();
  1346. $tab_width = Math.max($tabs_width, $this[0].scrollWidth) / $links.length;
  1347. // Make the old tab inactive.
  1348. $active.removeClass('active');
  1349. var $oldContent = $content
  1350. // Update the variables with the new link and content
  1351. $active = $(this);
  1352. $content = $(Materialize.escapeHash(this.hash));
  1353. $links = $this.find('li.tab a');
  1354. var activeRect = $active.position();
  1355. // Make the tab active.
  1356. $active.addClass('active');
  1357. prev_index = index;
  1358. index = $links.index($(this));
  1359. if (index < 0) {
  1360. index = 0;
  1361. }
  1362. // Change url to current tab
  1363. // window.location.hash = $active.attr('href');
  1364. // Swap content
  1365. if (options.swipeable) {
  1366. if ($tabs_content.length) {
  1367. $tabs_content.carousel('set', index, function() {
  1368. if (typeof(options.onShow) === "function") {
  1369. options.onShow.call($this[0], $content);
  1370. }
  1371. });
  1372. }
  1373. } else {
  1374. if ($content !== undefined) {
  1375. $content.show();
  1376. $content.addClass('active');
  1377. if (typeof(options.onShow) === "function") {
  1378. options.onShow.call(this, $content);
  1379. }
  1380. }
  1381. if ($oldContent !== undefined &&
  1382. !$oldContent.is($content)) {
  1383. $oldContent.hide();
  1384. $oldContent.removeClass('active');
  1385. }
  1386. }
  1387. // Reset clicked state
  1388. clickedTimeout = setTimeout(function(){ clicked = false; }, transition);
  1389. // Update indicator
  1390. animateIndicator(prev_index);
  1391. // Prevent the anchor's default click action
  1392. e.preventDefault();
  1393. });
  1394. });
  1395. },
  1396. select_tab : function( id ) {
  1397. this.find('a[href="#' + id + '"]').trigger('click');
  1398. }
  1399. };
  1400. $.fn.tabs = function(methodOrOptions) {
  1401. if ( methods[methodOrOptions] ) {
  1402. return methods[ methodOrOptions ].apply( this, Array.prototype.slice.call( arguments, 1 ));
  1403. } else if ( typeof methodOrOptions === 'object' || ! methodOrOptions ) {
  1404. // Default to "init"
  1405. return methods.init.apply( this, arguments );
  1406. } else {
  1407. $.error( 'Method ' + methodOrOptions + ' does not exist on jQuery.tabs' );
  1408. }
  1409. };
  1410. $(document).ready(function(){
  1411. $('ul.tabs').tabs();
  1412. });
  1413. }( jQuery ));
  1414. ;(function ($) {
  1415. $.fn.tooltip = function (options) {
  1416. var timeout = null,
  1417. margin = 5;
  1418. // Defaults
  1419. var defaults = {
  1420. delay: 350,
  1421. tooltip: '',
  1422. position: 'bottom',
  1423. html: false
  1424. };
  1425. // Remove tooltip from the activator
  1426. if (options === "remove") {
  1427. this.each(function() {
  1428. $('#' + $(this).attr('data-tooltip-id')).remove();
  1429. $(this).off('mouseenter.tooltip mouseleave.tooltip');
  1430. });
  1431. return false;
  1432. }
  1433. options = $.extend(defaults, options);
  1434. return this.each(function() {
  1435. var tooltipId = Materialize.guid();
  1436. var origin = $(this);
  1437. // Destroy old tooltip
  1438. if (origin.attr('data-tooltip-id')) {
  1439. $('#' + origin.attr('data-tooltip-id')).remove();
  1440. }
  1441. origin.attr('data-tooltip-id', tooltipId);
  1442. // Get attributes.
  1443. var allowHtml,
  1444. tooltipDelay,
  1445. tooltipPosition,
  1446. tooltipText,
  1447. tooltipEl,
  1448. backdrop;
  1449. var setAttributes = function() {
  1450. allowHtml = origin.attr('data-html') ? origin.attr('data-html') === 'true' : options.html;
  1451. tooltipDelay = origin.attr('data-delay');
  1452. tooltipDelay = (tooltipDelay === undefined || tooltipDelay === '') ?
  1453. options.delay : tooltipDelay;
  1454. tooltipPosition = origin.attr('data-position');
  1455. tooltipPosition = (tooltipPosition === undefined || tooltipPosition === '') ?
  1456. options.position : tooltipPosition;
  1457. tooltipText = origin.attr('data-tooltip');
  1458. tooltipText = (tooltipText === undefined || tooltipText === '') ?
  1459. options.tooltip : tooltipText;
  1460. };
  1461. setAttributes();
  1462. var renderTooltipEl = function() {
  1463. var tooltip = $('<div class="material-tooltip"></div>');
  1464. // Create Text span
  1465. if (allowHtml) {
  1466. tooltipText = $('<span></span>').html(tooltipText);
  1467. } else{
  1468. tooltipText = $('<span></span>').text(tooltipText);
  1469. }
  1470. // Create tooltip
  1471. tooltip.append(tooltipText)
  1472. .appendTo($('body'))
  1473. .attr('id', tooltipId);
  1474. // Create backdrop
  1475. backdrop = $('<div class="backdrop"></div>');
  1476. backdrop.appendTo(tooltip);
  1477. return tooltip;
  1478. };
  1479. tooltipEl = renderTooltipEl();
  1480. // Destroy previously binded events
  1481. origin.off('mouseenter.tooltip mouseleave.tooltip');
  1482. // Mouse In
  1483. var started = false, timeoutRef;
  1484. origin.on({'mouseenter.tooltip': function(e) {
  1485. var showTooltip = function() {
  1486. setAttributes();
  1487. started = true;
  1488. tooltipEl.velocity('stop');
  1489. backdrop.velocity('stop');
  1490. tooltipEl.css({ visibility: 'visible', left: '0px', top: '0px' });
  1491. // Tooltip positioning
  1492. var originWidth = origin.outerWidth();
  1493. var originHeight = origin.outerHeight();
  1494. var tooltipHeight = tooltipEl.outerHeight();
  1495. var tooltipWidth = tooltipEl.outerWidth();
  1496. var tooltipVerticalMovement = '0px';
  1497. var tooltipHorizontalMovement = '0px';
  1498. var backdropOffsetWidth = backdrop[0].offsetWidth;
  1499. var backdropOffsetHeight = backdrop[0].offsetHeight;
  1500. var scaleXFactor = 8;
  1501. var scaleYFactor = 8;
  1502. var scaleFactor = 0;
  1503. var targetTop, targetLeft, newCoordinates;
  1504. if (tooltipPosition === "top") {
  1505. // Top Position
  1506. targetTop = origin.offset().top - tooltipHeight - margin;
  1507. targetLeft = origin.offset().left + originWidth/2 - tooltipWidth/2;
  1508. newCoordinates = repositionWithinScreen(targetLeft, targetTop, tooltipWidth, tooltipHeight);
  1509. tooltipVerticalMovement = '-10px';
  1510. backdrop.css({
  1511. bottom: 0,
  1512. left: 0,
  1513. borderRadius: '14px 14px 0 0',
  1514. transformOrigin: '50% 100%',
  1515. marginTop: tooltipHeight,
  1516. marginLeft: (tooltipWidth/2) - (backdropOffsetWidth/2)
  1517. });
  1518. }
  1519. // Left Position
  1520. else if (tooltipPosition === "left") {
  1521. targetTop = origin.offset().top + originHeight/2 - tooltipHeight/2;
  1522. targetLeft = origin.offset().left - tooltipWidth - margin;
  1523. newCoordinates = repositionWithinScreen(targetLeft, targetTop, tooltipWidth, tooltipHeight);
  1524. tooltipHorizontalMovement = '-10px';
  1525. backdrop.css({
  1526. top: '-7px',
  1527. right: 0,
  1528. width: '14px',
  1529. height: '14px',
  1530. borderRadius: '14px 0 0 14px',
  1531. transformOrigin: '95% 50%',
  1532. marginTop: tooltipHeight/2,
  1533. marginLeft: tooltipWidth
  1534. });
  1535. }
  1536. // Right Position
  1537. else if (tooltipPosition === "right") {
  1538. targetTop = origin.offset().top + originHeight/2 - tooltipHeight/2;
  1539. targetLeft = origin.offset().left + originWidth + margin;
  1540. newCoordinates = repositionWithinScreen(targetLeft, targetTop, tooltipWidth, tooltipHeight);
  1541. tooltipHorizontalMovement = '+10px';
  1542. backdrop.css({
  1543. top: '-7px',
  1544. left: 0,
  1545. width: '14px',
  1546. height: '14px',
  1547. borderRadius: '0 14px 14px 0',
  1548. transformOrigin: '5% 50%',
  1549. marginTop: tooltipHeight/2,
  1550. marginLeft: '0px'
  1551. });
  1552. }
  1553. else {
  1554. // Bottom Position
  1555. targetTop = origin.offset().top + origin.outerHeight() + margin;
  1556. targetLeft = origin.offset().left + originWidth/2 - tooltipWidth/2;
  1557. newCoordinates = repositionWithinScreen(targetLeft, targetTop, tooltipWidth, tooltipHeight);
  1558. tooltipVerticalMovement = '+10px';
  1559. backdrop.css({
  1560. top: 0,
  1561. left: 0,
  1562. marginLeft: (tooltipWidth/2) - (backdropOffsetWidth/2)
  1563. });
  1564. }
  1565. // Set tooptip css placement
  1566. tooltipEl.css({
  1567. top: newCoordinates.y,
  1568. left: newCoordinates.x
  1569. });
  1570. // Calculate Scale to fill
  1571. scaleXFactor = Math.SQRT2 * tooltipWidth / parseInt(backdropOffsetWidth);
  1572. scaleYFactor = Math.SQRT2 * tooltipHeight / parseInt(backdropOffsetHeight);
  1573. scaleFactor = Math.max(scaleXFactor, scaleYFactor);
  1574. tooltipEl.velocity({ translateY: tooltipVerticalMovement, translateX: tooltipHorizontalMovement}, { duration: 350, queue: false })
  1575. .velocity({opacity: 1}, {duration: 300, delay: 50, queue: false});
  1576. backdrop.css({ visibility: 'visible' })
  1577. .velocity({opacity:1},{duration: 55, delay: 0, queue: false})
  1578. .velocity({scaleX: scaleFactor, scaleY: scaleFactor}, {duration: 300, delay: 0, queue: false, easing: 'easeInOutQuad'});
  1579. };
  1580. timeoutRef = setTimeout(showTooltip, tooltipDelay); // End Interval
  1581. // Mouse Out
  1582. },
  1583. 'mouseleave.tooltip': function(){
  1584. // Reset State
  1585. started = false;
  1586. clearTimeout(timeoutRef);
  1587. // Animate back
  1588. setTimeout(function() {
  1589. if (started !== true) {
  1590. tooltipEl.velocity({
  1591. opacity: 0, translateY: 0, translateX: 0}, { duration: 225, queue: false});
  1592. backdrop.velocity({opacity: 0, scaleX: 1, scaleY: 1}, {
  1593. duration:225,
  1594. queue: false,
  1595. complete: function(){
  1596. backdrop.css({ visibility: 'hidden' });
  1597. tooltipEl.css({ visibility: 'hidden' });
  1598. started = false;}
  1599. });
  1600. }
  1601. },225);
  1602. }
  1603. });
  1604. });
  1605. };
  1606. var repositionWithinScreen = function(x, y, width, height) {
  1607. var newX = x;
  1608. var newY = y;
  1609. if (newX < 0) {
  1610. newX = 4;
  1611. } else if (newX + width > window.innerWidth) {
  1612. newX -= newX + width - window.innerWidth;
  1613. }
  1614. if (newY < 0) {
  1615. newY = 4;
  1616. } else if (newY + height > window.innerHeight + $(window).scrollTop) {
  1617. newY -= newY + height - window.innerHeight;
  1618. }
  1619. return {x: newX, y: newY};
  1620. };
  1621. $(document).ready(function(){
  1622. $('.tooltipped').tooltip();
  1623. });
  1624. }( jQuery ));
  1625. ;/*!
  1626. * Waves v0.6.4
  1627. * http://fian.my.id/Waves
  1628. *
  1629. * Copyright 2014 Alfiana E. Sibuea and other contributors
  1630. * Released under the MIT license
  1631. * https://github.com/fians/Waves/blob/master/LICENSE
  1632. */
  1633. ;(function(window) {
  1634. 'use strict';
  1635. var Waves = Waves || {};
  1636. var $$ = document.querySelectorAll.bind(document);
  1637. // Find exact position of element
  1638. function isWindow(obj) {
  1639. return obj !== null && obj === obj.window;
  1640. }
  1641. function getWindow(elem) {
  1642. return isWindow(elem) ? elem : elem.nodeType === 9 && elem.defaultView;
  1643. }
  1644. function offset(elem) {
  1645. var docElem, win,
  1646. box = {top: 0, left: 0},
  1647. doc = elem && elem.ownerDocument;
  1648. docElem = doc.documentElement;
  1649. if (typeof elem.getBoundingClientRect !== typeof undefined) {
  1650. box = elem.getBoundingClientRect();
  1651. }
  1652. win = getWindow(doc);
  1653. return {
  1654. top: box.top + win.pageYOffset - docElem.clientTop,
  1655. left: box.left + win.pageXOffset - docElem.clientLeft
  1656. };
  1657. }
  1658. function convertStyle(obj) {
  1659. var style = '';
  1660. for (var a in obj) {
  1661. if (obj.hasOwnProperty(a)) {
  1662. style += (a + ':' + obj[a] + ';');
  1663. }
  1664. }
  1665. return style;
  1666. }
  1667. var Effect = {
  1668. // Effect delay
  1669. duration: 750,
  1670. show: function(e, element) {
  1671. // Disable right click
  1672. if (e.button === 2) {
  1673. return false;
  1674. }
  1675. var el = element || this;
  1676. // Create ripple
  1677. var ripple = document.createElement('div');
  1678. ripple.className = 'waves-ripple';
  1679. el.appendChild(ripple);
  1680. // Get click coordinate and element witdh
  1681. var pos = offset(el);
  1682. var relativeY = (e.pageY - pos.top);
  1683. var relativeX = (e.pageX - pos.left);
  1684. var scale = 'scale('+((el.clientWidth / 100) * 10)+')';
  1685. // Support for touch devices
  1686. if ('touches' in e) {
  1687. relativeY = (e.touches[0].pageY - pos.top);
  1688. relativeX = (e.touches[0].pageX - pos.left);
  1689. }
  1690. // Attach data to element
  1691. ripple.setAttribute('data-hold', Date.now());
  1692. ripple.setAttribute('data-scale', scale);
  1693. ripple.setAttribute('data-x', relativeX);
  1694. ripple.setAttribute('data-y', relativeY);
  1695. // Set ripple position
  1696. var rippleStyle = {
  1697. 'top': relativeY+'px',
  1698. 'left': relativeX+'px'
  1699. };
  1700. ripple.className = ripple.className + ' waves-notransition';
  1701. ripple.setAttribute('style', convertStyle(rippleStyle));
  1702. ripple.className = ripple.className.replace('waves-notransition', '');
  1703. // Scale the ripple
  1704. rippleStyle['-webkit-transform'] = scale;
  1705. rippleStyle['-moz-transform'] = scale;
  1706. rippleStyle['-ms-transform'] = scale;
  1707. rippleStyle['-o-transform'] = scale;
  1708. rippleStyle.transform = scale;
  1709. rippleStyle.opacity = '1';
  1710. rippleStyle['-webkit-transition-duration'] = Effect.duration + 'ms';
  1711. rippleStyle['-moz-transition-duration'] = Effect.duration + 'ms';
  1712. rippleStyle['-o-transition-duration'] = Effect.duration + 'ms';
  1713. rippleStyle['transition-duration'] = Effect.duration + 'ms';
  1714. rippleStyle['-webkit-transition-timing-function'] = 'cubic-bezier(0.250, 0.460, 0.450, 0.940)';
  1715. rippleStyle['-moz-transition-timing-function'] = 'cubic-bezier(0.250, 0.460, 0.450, 0.940)';
  1716. rippleStyle['-o-transition-timing-function'] = 'cubic-bezier(0.250, 0.460, 0.450, 0.940)';
  1717. rippleStyle['transition-timing-function'] = 'cubic-bezier(0.250, 0.460, 0.450, 0.940)';
  1718. ripple.setAttribute('style', convertStyle(rippleStyle));
  1719. },
  1720. hide: function(e) {
  1721. TouchHandler.touchup(e);
  1722. var el = this;
  1723. var width = el.clientWidth * 1.4;
  1724. // Get first ripple
  1725. var ripple = null;
  1726. var ripples = el.getElementsByClassName('waves-ripple');
  1727. if (ripples.length > 0) {
  1728. ripple = ripples[ripples.length - 1];
  1729. } else {
  1730. return false;
  1731. }
  1732. var relativeX = ripple.getAttribute('data-x');
  1733. var relativeY = ripple.getAttribute('data-y');
  1734. var scale = ripple.getAttribute('data-scale');
  1735. // Get delay beetween mousedown and mouse leave
  1736. var diff = Date.now() - Number(ripple.getAttribute('data-hold'));
  1737. var delay = 350 - diff;
  1738. if (delay < 0) {
  1739. delay = 0;
  1740. }
  1741. // Fade out ripple after delay
  1742. setTimeout(function() {
  1743. var style = {
  1744. 'top': relativeY+'px',
  1745. 'left': relativeX+'px',
  1746. 'opacity': '0',
  1747. // Duration
  1748. '-webkit-transition-duration': Effect.duration + 'ms',
  1749. '-moz-transition-duration': Effect.duration + 'ms',
  1750. '-o-transition-duration': Effect.duration + 'ms',
  1751. 'transition-duration': Effect.duration + 'ms',
  1752. '-webkit-transform': scale,
  1753. '-moz-transform': scale,
  1754. '-ms-transform': scale,
  1755. '-o-transform': scale,
  1756. 'transform': scale,
  1757. };
  1758. ripple.setAttribute('style', convertStyle(style));
  1759. setTimeout(function() {
  1760. try {
  1761. el.removeChild(ripple);
  1762. } catch(e) {
  1763. return false;
  1764. }
  1765. }, Effect.duration);
  1766. }, delay);
  1767. },
  1768. // Little hack to make <input> can perform waves effect
  1769. wrapInput: function(elements) {
  1770. for (var a = 0; a < elements.length; a++) {
  1771. var el = elements[a];
  1772. if (el.tagName.toLowerCase() === 'input') {
  1773. var parent = el.parentNode;
  1774. // If input already have parent just pass through
  1775. if (parent.tagName.toLowerCase() === 'i' && parent.className.indexOf('waves-effect') !== -1) {
  1776. continue;
  1777. }
  1778. // Put element class and style to the specified parent
  1779. var wrapper = document.createElement('i');
  1780. wrapper.className = el.className + ' waves-input-wrapper';
  1781. var elementStyle = el.getAttribute('style');
  1782. if (!elementStyle) {
  1783. elementStyle = '';
  1784. }
  1785. wrapper.setAttribute('style', elementStyle);
  1786. el.className = 'waves-button-input';
  1787. el.removeAttribute('style');
  1788. // Put element as child
  1789. parent.replaceChild(wrapper, el);
  1790. wrapper.appendChild(el);
  1791. }
  1792. }
  1793. }
  1794. };
  1795. /**
  1796. * Disable mousedown event for 500ms during and after touch
  1797. */
  1798. var TouchHandler = {
  1799. /* uses an integer rather than bool so there's no issues with
  1800. * needing to clear timeouts if another touch event occurred
  1801. * within the 500ms. Cannot mouseup between touchstart and
  1802. * touchend, nor in the 500ms after touchend. */
  1803. touches: 0,
  1804. allowEvent: function(e) {
  1805. var allow = true;
  1806. if (e.type === 'touchstart') {
  1807. TouchHandler.touches += 1; //push
  1808. } else if (e.type === 'touchend' || e.type === 'touchcancel') {
  1809. setTimeout(function() {
  1810. if (TouchHandler.touches > 0) {
  1811. TouchHandler.touches -= 1; //pop after 500ms
  1812. }
  1813. }, 500);
  1814. } else if (e.type === 'mousedown' && TouchHandler.touches > 0) {
  1815. allow = false;
  1816. }
  1817. return allow;
  1818. },
  1819. touchup: function(e) {
  1820. TouchHandler.allowEvent(e);
  1821. }
  1822. };
  1823. /**
  1824. * Delegated click handler for .waves-effect element.
  1825. * returns null when .waves-effect element not in "click tree"
  1826. */
  1827. function getWavesEffectElement(e) {
  1828. if (TouchHandler.allowEvent(e) === false) {
  1829. return null;
  1830. }
  1831. var element = null;
  1832. var target = e.target || e.srcElement;
  1833. while (target.parentElement !== null) {
  1834. if (!(target instanceof SVGElement) && target.className.indexOf('waves-effect') !== -1) {
  1835. element = target;
  1836. break;
  1837. } else if (target.className.indexOf('waves-effect') !== -1) {
  1838. element = target;
  1839. break;
  1840. }
  1841. target = target.parentElement;
  1842. }
  1843. return element;
  1844. }
  1845. /**
  1846. * Bubble the click and show effect if .waves-effect elem was found
  1847. */
  1848. function showEffect(e) {
  1849. var element = getWavesEffectElement(e);
  1850. if (element !== null) {
  1851. Effect.show(e, element);
  1852. if ('ontouchstart' in window) {
  1853. element.addEventListener('touchend', Effect.hide, false);
  1854. element.addEventListener('touchcancel', Effect.hide, false);
  1855. }
  1856. element.addEventListener('mouseup', Effect.hide, false);
  1857. element.addEventListener('mouseleave', Effect.hide, false);
  1858. }
  1859. }
  1860. Waves.displayEffect = function(options) {
  1861. options = options || {};
  1862. if ('duration' in options) {
  1863. Effect.duration = options.duration;
  1864. }
  1865. //Wrap input inside <i> tag
  1866. Effect.wrapInput($$('.waves-effect'));
  1867. if ('ontouchstart' in window) {
  1868. document.body.addEventListener('touchstart', showEffect, false);
  1869. }
  1870. document.body.addEventListener('mousedown', showEffect, false);
  1871. };
  1872. /**
  1873. * Attach Waves to an input element (or any element which doesn't
  1874. * bubble mouseup/mousedown events).
  1875. * Intended to be used with dynamically loaded forms/inputs, or
  1876. * where the user doesn't want a delegated click handler.
  1877. */
  1878. Waves.attach = function(element) {
  1879. //FUTURE: automatically add waves classes and allow users
  1880. // to specify them with an options param? Eg. light/classic/button
  1881. if (element.tagName.toLowerCase() === 'input') {
  1882. Effect.wrapInput([element]);
  1883. element = element.parentElement;
  1884. }
  1885. if ('ontouchstart' in window) {
  1886. element.addEventListener('touchstart', showEffect, false);
  1887. }
  1888. element.addEventListener('mousedown', showEffect, false);
  1889. };
  1890. window.Waves = Waves;
  1891. document.addEventListener('DOMContentLoaded', function() {
  1892. Waves.displayEffect();
  1893. }, false);
  1894. })(window);
  1895. ;Materialize.toast = function (message, displayLength, className, completeCallback) {
  1896. className = className || "";
  1897. var container = document.getElementById('toast-container');
  1898. // Create toast container if it does not exist
  1899. if (container === null) {
  1900. // create notification container
  1901. container = document.createElement('div');
  1902. container.id = 'toast-container';
  1903. document.body.appendChild(container);
  1904. }
  1905. // Select and append toast
  1906. var newToast = createToast(message);
  1907. // only append toast if message is not undefined
  1908. if(message){
  1909. container.appendChild(newToast);
  1910. }
  1911. newToast.style.opacity = 0;
  1912. // Animate toast in
  1913. Vel(newToast, {translateY: '-35px', opacity: 1 }, {duration: 300,
  1914. easing: 'easeOutCubic',
  1915. queue: false});
  1916. // Allows timer to be pause while being panned
  1917. var timeLeft = displayLength;
  1918. var counterInterval;
  1919. if (timeLeft != null) {
  1920. counterInterval = setInterval (function(){
  1921. if (newToast.parentNode === null)
  1922. window.clearInterval(counterInterval);
  1923. // If toast is not being dragged, decrease its time remaining
  1924. if (!newToast.classList.contains('panning')) {
  1925. timeLeft -= 20;
  1926. }
  1927. if (timeLeft <= 0) {
  1928. // Animate toast out
  1929. Vel(newToast, {"opacity": 0, marginTop: '-40px'}, { duration: 375,
  1930. easing: 'easeOutExpo',
  1931. queue: false,
  1932. complete: function(){
  1933. // Call the optional callback
  1934. if(typeof(completeCallback) === "function")
  1935. completeCallback();
  1936. // Remove toast after it times out
  1937. this[0].parentNode.removeChild(this[0]);
  1938. }
  1939. });
  1940. window.clearInterval(counterInterval);
  1941. }
  1942. }, 20);
  1943. }
  1944. function createToast(html) {
  1945. // Create toast
  1946. var toast = document.createElement('div');
  1947. toast.classList.add('toast');
  1948. if (className) {
  1949. var classes = className.split(' ');
  1950. for (var i = 0, count = classes.length; i < count; i++) {
  1951. toast.classList.add(classes[i]);
  1952. }
  1953. }
  1954. // If type of parameter is HTML Element
  1955. if ( typeof HTMLElement === "object" ? html instanceof HTMLElement : html && typeof html === "object" && html !== null && html.nodeType === 1 && typeof html.nodeName==="string"
  1956. ) {
  1957. toast.appendChild(html);
  1958. }
  1959. else if (html instanceof jQuery) {
  1960. // Check if it is jQuery object
  1961. toast.appendChild(html[0]);
  1962. }
  1963. else {
  1964. // Insert as text;
  1965. toast.innerHTML = html;
  1966. }
  1967. // Bind hammer
  1968. var hammerHandler = new Hammer(toast, {prevent_default: false});
  1969. hammerHandler.on('pan', function(e) {
  1970. var deltaX = e.deltaX;
  1971. var activationDistance = 80;
  1972. // Change toast state
  1973. if (!toast.classList.contains('panning')){
  1974. toast.classList.add('panning');
  1975. }
  1976. var opacityPercent = 1-Math.abs(deltaX / activationDistance);
  1977. if (opacityPercent < 0)
  1978. opacityPercent = 0;
  1979. Vel(toast, {left: deltaX, opacity: opacityPercent }, {duration: 50, queue: false, easing: 'easeOutQuad'});
  1980. });
  1981. hammerHandler.on('panend', function(e) {
  1982. var deltaX = e.deltaX;
  1983. var activationDistance = 80;
  1984. // If toast dragged past activation point
  1985. if (Math.abs(deltaX) > activationDistance) {
  1986. Vel(toast, {marginTop: '-40px'}, { duration: 375,
  1987. easing: 'easeOutExpo',
  1988. queue: false,
  1989. complete: function(){
  1990. if(typeof(completeCallback) === "function") {
  1991. completeCallback();
  1992. }
  1993. toast.parentNode.removeChild(toast);
  1994. }
  1995. });
  1996. } else {
  1997. toast.classList.remove('panning');
  1998. // Put toast back into original position
  1999. Vel(toast, { left: 0, opacity: 1 }, { duration: 300,
  2000. easing: 'easeOutExpo',
  2001. queue: false
  2002. });
  2003. }
  2004. });
  2005. return toast;
  2006. }
  2007. };
  2008. ;(function ($) {
  2009. var methods = {
  2010. init : function(options) {
  2011. var defaults = {
  2012. menuWidth: 300,
  2013. edge: 'left',
  2014. closeOnClick: false,
  2015. draggable: true,
  2016. onOpen: null,
  2017. onClose: null
  2018. };
  2019. options = $.extend(defaults, options);
  2020. $(this).each(function(){
  2021. var $this = $(this);
  2022. var menuId = $this.attr('data-activates');
  2023. var menu = $("#"+ menuId);
  2024. // Set to width
  2025. if (options.menuWidth != 300) {
  2026. menu.css('width', options.menuWidth);
  2027. }
  2028. // Add Touch Area
  2029. var $dragTarget = $('.drag-target[data-sidenav="' + menuId + '"]');
  2030. if (options.draggable) {
  2031. // Regenerate dragTarget
  2032. if ($dragTarget.length) {
  2033. $dragTarget.remove();
  2034. }
  2035. $dragTarget = $('<div class="drag-target"></div>').attr('data-sidenav', menuId);
  2036. $('body').append($dragTarget);
  2037. } else {
  2038. $dragTarget = $();
  2039. }
  2040. if (options.edge == 'left') {
  2041. menu.css('transform', 'translateX(-100%)');
  2042. $dragTarget.css({'left': 0}); // Add Touch Area
  2043. }
  2044. else {
  2045. menu.addClass('right-aligned') // Change text-alignment to right
  2046. .css('transform', 'translateX(100%)');
  2047. $dragTarget.css({'right': 0}); // Add Touch Area
  2048. }
  2049. // If fixed sidenav, bring menu out
  2050. if (menu.hasClass('fixed')) {
  2051. if (window.innerWidth > 992) {
  2052. menu.css('transform', 'translateX(0)');
  2053. }
  2054. }
  2055. // Window resize to reset on large screens fixed
  2056. if (menu.hasClass('fixed')) {
  2057. $(window).resize( function() {
  2058. if (window.innerWidth > 992) {
  2059. // Close menu if window is resized bigger than 992 and user has fixed sidenav
  2060. if ($('#sidenav-overlay').length !== 0 && menuOut) {
  2061. removeMenu(true);
  2062. }
  2063. else {
  2064. // menu.removeAttr('style');
  2065. menu.css('transform', 'translateX(0%)');
  2066. // menu.css('width', options.menuWidth);
  2067. }
  2068. }
  2069. else if (menuOut === false){
  2070. if (options.edge === 'left') {
  2071. menu.css('transform', 'translateX(-100%)');
  2072. } else {
  2073. menu.css('transform', 'translateX(100%)');
  2074. }
  2075. }
  2076. });
  2077. }
  2078. // if closeOnClick, then add close event for all a tags in side sideNav
  2079. if (options.closeOnClick === true) {
  2080. menu.on("click.itemclick", "a:not(.collapsible-header)", function(){
  2081. if (!(window.innerWidth > 992 && menu.hasClass('fixed'))){
  2082. removeMenu();
  2083. }
  2084. });
  2085. }
  2086. var removeMenu = function(restoreNav) {
  2087. panning = false;
  2088. menuOut = false;
  2089. // Reenable scrolling
  2090. $('body').css({
  2091. overflow: '',
  2092. width: ''
  2093. });
  2094. $('#sidenav-overlay').velocity({opacity: 0}, {duration: 200,
  2095. queue: false, easing: 'easeOutQuad',
  2096. complete: function() {
  2097. $(this).remove();
  2098. } });
  2099. if (options.edge === 'left') {
  2100. // Reset phantom div
  2101. $dragTarget.css({width: '', right: '', left: '0'});
  2102. menu.velocity(
  2103. {'translateX': '-100%'},
  2104. { duration: 200,
  2105. queue: false,
  2106. easing: 'easeOutCubic',
  2107. complete: function() {
  2108. if (restoreNav === true) {
  2109. // Restore Fixed sidenav
  2110. menu.removeAttr('style');
  2111. menu.css('width', options.menuWidth);
  2112. }
  2113. }
  2114. });
  2115. }
  2116. else {
  2117. // Reset phantom div
  2118. $dragTarget.css({width: '', right: '0', left: ''});
  2119. menu.velocity(
  2120. {'translateX': '100%'},
  2121. { duration: 200,
  2122. queue: false,
  2123. easing: 'easeOutCubic',
  2124. complete: function() {
  2125. if (restoreNav === true) {
  2126. // Restore Fixed sidenav
  2127. menu.removeAttr('style');
  2128. menu.css('width', options.menuWidth);
  2129. }
  2130. }
  2131. });
  2132. }
  2133. // Callback
  2134. if (typeof(options.onClose) === 'function') {
  2135. options.onClose.call(this, menu);
  2136. }
  2137. }
  2138. // Touch Event
  2139. var panning = false;
  2140. var menuOut = false;
  2141. if (options.draggable) {
  2142. $dragTarget.on('click', function(){
  2143. if (menuOut) {
  2144. removeMenu();
  2145. }
  2146. });
  2147. $dragTarget.hammer({
  2148. prevent_default: false
  2149. }).on('pan', function(e) {
  2150. if (e.gesture.pointerType == "touch") {
  2151. var direction = e.gesture.direction;
  2152. var x = e.gesture.center.x;
  2153. var y = e.gesture.center.y;
  2154. var velocityX = e.gesture.velocityX;
  2155. // Vertical scroll bugfix
  2156. if (x === 0 && y === 0) {
  2157. return;
  2158. }
  2159. // Disable Scrolling
  2160. var $body = $('body');
  2161. var $overlay = $('#sidenav-overlay');
  2162. var oldWidth = $body.innerWidth();
  2163. $body.css('overflow', 'hidden');
  2164. $body.width(oldWidth);
  2165. // If overlay does not exist, create one and if it is clicked, close menu
  2166. if ($overlay.length === 0) {
  2167. $overlay = $('<div id="sidenav-overlay"></div>');
  2168. $overlay.css('opacity', 0).click( function(){
  2169. removeMenu();
  2170. });
  2171. // Run 'onOpen' when sidenav is opened via touch/swipe if applicable
  2172. if (typeof(options.onOpen) === 'function') {
  2173. options.onOpen.call(this, menu);
  2174. }
  2175. $('body').append($overlay);
  2176. }
  2177. // Keep within boundaries
  2178. if (options.edge === 'left') {
  2179. if (x > options.menuWidth) { x = options.menuWidth; }
  2180. else if (x < 0) { x = 0; }
  2181. }
  2182. if (options.edge === 'left') {
  2183. // Left Direction
  2184. if (x < (options.menuWidth / 2)) { menuOut = false; }
  2185. // Right Direction
  2186. else if (x >= (options.menuWidth / 2)) { menuOut = true; }
  2187. menu.css('transform', 'translateX(' + (x - options.menuWidth) + 'px)');
  2188. }
  2189. else {
  2190. // Left Direction
  2191. if (x < (window.innerWidth - options.menuWidth / 2)) {
  2192. menuOut = true;
  2193. }
  2194. // Right Direction
  2195. else if (x >= (window.innerWidth - options.menuWidth / 2)) {
  2196. menuOut = false;
  2197. }
  2198. var rightPos = (x - options.menuWidth / 2);
  2199. if (rightPos < 0) {
  2200. rightPos = 0;
  2201. }
  2202. menu.css('transform', 'translateX(' + rightPos + 'px)');
  2203. }
  2204. // Percentage overlay
  2205. var overlayPerc;
  2206. if (options.edge === 'left') {
  2207. overlayPerc = x / options.menuWidth;
  2208. $overlay.velocity({opacity: overlayPerc }, {duration: 10, queue: false, easing: 'easeOutQuad'});
  2209. }
  2210. else {
  2211. overlayPerc = Math.abs((x - window.innerWidth) / options.menuWidth);
  2212. $overlay.velocity({opacity: overlayPerc }, {duration: 10, queue: false, easing: 'easeOutQuad'});
  2213. }
  2214. }
  2215. }).on('panend', function(e) {
  2216. if (e.gesture.pointerType == "touch") {
  2217. var $overlay = $('#sidenav-overlay');
  2218. var velocityX = e.gesture.velocityX;
  2219. var x = e.gesture.center.x;
  2220. var leftPos = x - options.menuWidth;
  2221. var rightPos = x - options.menuWidth / 2;
  2222. if (leftPos > 0 ) {
  2223. leftPos = 0;
  2224. }
  2225. if (rightPos < 0) {
  2226. rightPos = 0;
  2227. }
  2228. panning = false;
  2229. if (options.edge === 'left') {
  2230. // If velocityX <= 0.3 then the user is flinging the menu closed so ignore menuOut
  2231. if ((menuOut && velocityX <= 0.3) || velocityX < -0.5) {
  2232. // Return menu to open
  2233. if (leftPos !== 0) {
  2234. menu.velocity({'translateX': [0, leftPos]}, {duration: 300, queue: false, easing: 'easeOutQuad'});
  2235. }
  2236. $overlay.velocity({opacity: 1 }, {duration: 50, queue: false, easing: 'easeOutQuad'});
  2237. $dragTarget.css({width: '50%', right: 0, left: ''});
  2238. menuOut = true;
  2239. }
  2240. else if (!menuOut || velocityX > 0.3) {
  2241. // Enable Scrolling
  2242. $('body').css({
  2243. overflow: '',
  2244. width: ''
  2245. });
  2246. // Slide menu closed
  2247. menu.velocity({'translateX': [-1 * options.menuWidth - 10, leftPos]}, {duration: 200, queue: false, easing: 'easeOutQuad'});
  2248. $overlay.velocity({opacity: 0 }, {duration: 200, queue: false, easing: 'easeOutQuad',
  2249. complete: function () {
  2250. // Run 'onClose' when sidenav is closed via touch/swipe if applicable
  2251. if (typeof(options.onClose) === 'function') {
  2252. options.onClose.call(this, menu);
  2253. }
  2254. $(this).remove();
  2255. }});
  2256. $dragTarget.css({width: '10px', right: '', left: 0});
  2257. }
  2258. }
  2259. else {
  2260. if ((menuOut && velocityX >= -0.3) || velocityX > 0.5) {
  2261. // Return menu to open
  2262. if (rightPos !== 0) {
  2263. menu.velocity({'translateX': [0, rightPos]}, {duration: 300, queue: false, easing: 'easeOutQuad'});
  2264. }
  2265. $overlay.velocity({opacity: 1 }, {duration: 50, queue: false, easing: 'easeOutQuad'});
  2266. $dragTarget.css({width: '50%', right: '', left: 0});
  2267. menuOut = true;
  2268. }
  2269. else if (!menuOut || velocityX < -0.3) {
  2270. // Enable Scrolling
  2271. $('body').css({
  2272. overflow: '',
  2273. width: ''
  2274. });
  2275. // Slide menu closed
  2276. menu.velocity({'translateX': [options.menuWidth + 10, rightPos]}, {duration: 200, queue: false, easing: 'easeOutQuad'});
  2277. $overlay.velocity({opacity: 0 }, {duration: 200, queue: false, easing: 'easeOutQuad',
  2278. complete: function () {
  2279. $(this).remove();
  2280. }});
  2281. $dragTarget.css({width: '10px', right: 0, left: ''});
  2282. }
  2283. }
  2284. }
  2285. });
  2286. }
  2287. $this.off('click.sidenav').on('click.sidenav', function() {
  2288. if (menuOut === true) {
  2289. menuOut = false;
  2290. panning = false;
  2291. removeMenu();
  2292. }
  2293. else {
  2294. // Disable Scrolling
  2295. var $body = $('body');
  2296. var $overlay = $('<div id="sidenav-overlay"></div>');
  2297. var oldWidth = $body.innerWidth();
  2298. $body.css('overflow', 'hidden');
  2299. $body.width(oldWidth);
  2300. // Push current drag target on top of DOM tree
  2301. $('body').append($dragTarget);
  2302. if (options.edge === 'left') {
  2303. $dragTarget.css({width: '50%', right: 0, left: ''});
  2304. menu.velocity({'translateX': [0, -1 * options.menuWidth]}, {duration: 300, queue: false, easing: 'easeOutQuad'});
  2305. }
  2306. else {
  2307. $dragTarget.css({width: '50%', right: '', left: 0});
  2308. menu.velocity({'translateX': [0, options.menuWidth]}, {duration: 300, queue: false, easing: 'easeOutQuad'});
  2309. }
  2310. $overlay.css('opacity', 0)
  2311. .click(function(){
  2312. menuOut = false;
  2313. panning = false;
  2314. removeMenu();
  2315. $overlay.velocity({opacity: 0}, {duration: 300, queue: false, easing: 'easeOutQuad',
  2316. complete: function() {
  2317. $(this).remove();
  2318. } });
  2319. });
  2320. $('body').append($overlay);
  2321. $overlay.velocity({opacity: 1}, {duration: 300, queue: false, easing: 'easeOutQuad',
  2322. complete: function () {
  2323. menuOut = true;
  2324. panning = false;
  2325. }
  2326. });
  2327. // Callback
  2328. if (typeof(options.onOpen) === 'function') {
  2329. options.onOpen.call(this, menu);
  2330. }
  2331. }
  2332. return false;
  2333. });
  2334. });
  2335. },
  2336. destroy: function () {
  2337. var $overlay = $('#sidenav-overlay');
  2338. var $dragTarget = $('.drag-target[data-sidenav="' + $(this).attr('data-activates') + '"]');
  2339. $overlay.trigger('click');
  2340. $dragTarget.remove();
  2341. $(this).off('click');
  2342. $overlay.remove();
  2343. },
  2344. show : function() {
  2345. this.trigger('click');
  2346. },
  2347. hide : function() {
  2348. $('#sidenav-overlay').trigger('click');
  2349. }
  2350. };
  2351. $.fn.sideNav = function(methodOrOptions) {
  2352. if ( methods[methodOrOptions] ) {
  2353. return methods[ methodOrOptions ].apply( this, Array.prototype.slice.call( arguments, 1 ));
  2354. } else if ( typeof methodOrOptions === 'object' || ! methodOrOptions ) {
  2355. // Default to "init"
  2356. return methods.init.apply( this, arguments );
  2357. } else {
  2358. $.error( 'Method ' + methodOrOptions + ' does not exist on jQuery.sideNav' );
  2359. }
  2360. }; // Plugin end
  2361. }( jQuery ));
  2362. ;/**
  2363. * Extend jquery with a scrollspy plugin.
  2364. * This watches the window scroll and fires events when elements are scrolled into viewport.
  2365. *
  2366. * throttle() and getTime() taken from Underscore.js
  2367. * https://github.com/jashkenas/underscore
  2368. *
  2369. * @author Copyright 2013 John Smart
  2370. * @license https://raw.github.com/thesmart/jquery-scrollspy/master/LICENSE
  2371. * @see https://github.com/thesmart
  2372. * @version 0.1.2
  2373. */
  2374. (function($) {
  2375. var jWindow = $(window);
  2376. var elements = [];
  2377. var elementsInView = [];
  2378. var isSpying = false;
  2379. var ticks = 0;
  2380. var unique_id = 1;
  2381. var offset = {
  2382. top : 0,
  2383. right : 0,
  2384. bottom : 0,
  2385. left : 0,
  2386. }
  2387. /**
  2388. * Find elements that are within the boundary
  2389. * @param {number} top
  2390. * @param {number} right
  2391. * @param {number} bottom
  2392. * @param {number} left
  2393. * @return {jQuery} A collection of elements
  2394. */
  2395. function findElements(top, right, bottom, left) {
  2396. var hits = $();
  2397. $.each(elements, function(i, element) {
  2398. if (element.height() > 0) {
  2399. var elTop = element.offset().top,
  2400. elLeft = element.offset().left,
  2401. elRight = elLeft + element.width(),
  2402. elBottom = elTop + element.height();
  2403. var isIntersect = !(elLeft > right ||
  2404. elRight < left ||
  2405. elTop > bottom ||
  2406. elBottom < top);
  2407. if (isIntersect) {
  2408. hits.push(element);
  2409. }
  2410. }
  2411. });
  2412. return hits;
  2413. }
  2414. /**
  2415. * Called when the user scrolls the window
  2416. */
  2417. function onScroll(scrollOffset) {
  2418. // unique tick id
  2419. ++ticks;
  2420. // viewport rectangle
  2421. var top = jWindow.scrollTop(),
  2422. left = jWindow.scrollLeft(),
  2423. right = left + jWindow.width(),
  2424. bottom = top + jWindow.height();
  2425. // determine which elements are in view
  2426. var intersections = findElements(top+offset.top + scrollOffset || 200, right+offset.right, bottom+offset.bottom, left+offset.left);
  2427. $.each(intersections, function(i, element) {
  2428. var lastTick = element.data('scrollSpy:ticks');
  2429. if (typeof lastTick != 'number') {
  2430. // entered into view
  2431. element.triggerHandler('scrollSpy:enter');
  2432. }
  2433. // update tick id
  2434. element.data('scrollSpy:ticks', ticks);
  2435. });
  2436. // determine which elements are no longer in view
  2437. $.each(elementsInView, function(i, element) {
  2438. var lastTick = element.data('scrollSpy:ticks');
  2439. if (typeof lastTick == 'number' && lastTick !== ticks) {
  2440. // exited from view
  2441. element.triggerHandler('scrollSpy:exit');
  2442. element.data('scrollSpy:ticks', null);
  2443. }
  2444. });
  2445. // remember elements in view for next tick
  2446. elementsInView = intersections;
  2447. }
  2448. /**
  2449. * Called when window is resized
  2450. */
  2451. function onWinSize() {
  2452. jWindow.trigger('scrollSpy:winSize');
  2453. }
  2454. /**
  2455. * Enables ScrollSpy using a selector
  2456. * @param {jQuery|string} selector The elements collection, or a selector
  2457. * @param {Object=} options Optional.
  2458. throttle : number -> scrollspy throttling. Default: 100 ms
  2459. offsetTop : number -> offset from top. Default: 0
  2460. offsetRight : number -> offset from right. Default: 0
  2461. offsetBottom : number -> offset from bottom. Default: 0
  2462. offsetLeft : number -> offset from left. Default: 0
  2463. activeClass : string -> Class name to be added to the active link. Default: active
  2464. * @returns {jQuery}
  2465. */
  2466. $.scrollSpy = function(selector, options) {
  2467. var defaults = {
  2468. throttle: 100,
  2469. scrollOffset: 200, // offset - 200 allows elements near bottom of page to scroll
  2470. activeClass: 'active',
  2471. getActiveElement: function(id) {
  2472. return 'a[href="#' + id + '"]';
  2473. }
  2474. };
  2475. options = $.extend(defaults, options);
  2476. var visible = [];
  2477. selector = $(selector);
  2478. selector.each(function(i, element) {
  2479. elements.push($(element));
  2480. $(element).data("scrollSpy:id", i);
  2481. // Smooth scroll to section
  2482. $('a[href="#' + $(element).attr('id') + '"]').click(function(e) {
  2483. e.preventDefault();
  2484. var offset = $(Materialize.escapeHash(this.hash)).offset().top + 1;
  2485. $('html, body').animate({ scrollTop: offset - options.scrollOffset }, {duration: 400, queue: false, easing: 'easeOutCubic'});
  2486. });
  2487. });
  2488. offset.top = options.offsetTop || 0;
  2489. offset.right = options.offsetRight || 0;
  2490. offset.bottom = options.offsetBottom || 0;
  2491. offset.left = options.offsetLeft || 0;
  2492. var throttledScroll = Materialize.throttle(function() {
  2493. onScroll(options.scrollOffset);
  2494. }, options.throttle || 100);
  2495. var readyScroll = function(){
  2496. $(document).ready(throttledScroll);
  2497. };
  2498. if (!isSpying) {
  2499. jWindow.on('scroll', readyScroll);
  2500. jWindow.on('resize', readyScroll);
  2501. isSpying = true;
  2502. }
  2503. // perform a scan once, after current execution context, and after dom is ready
  2504. setTimeout(readyScroll, 0);
  2505. selector.on('scrollSpy:enter', function() {
  2506. visible = $.grep(visible, function(value) {
  2507. return value.height() != 0;
  2508. });
  2509. var $this = $(this);
  2510. if (visible[0]) {
  2511. $(options.getActiveElement(visible[0].attr('id'))).removeClass(options.activeClass);
  2512. if ($this.data('scrollSpy:id') < visible[0].data('scrollSpy:id')) {
  2513. visible.unshift($(this));
  2514. }
  2515. else {
  2516. visible.push($(this));
  2517. }
  2518. }
  2519. else {
  2520. visible.push($(this));
  2521. }
  2522. $(options.getActiveElement(visible[0].attr('id'))).addClass(options.activeClass);
  2523. });
  2524. selector.on('scrollSpy:exit', function() {
  2525. visible = $.grep(visible, function(value) {
  2526. return value.height() != 0;
  2527. });
  2528. if (visible[0]) {
  2529. $(options.getActiveElement(visible[0].attr('id'))).removeClass(options.activeClass);
  2530. var $this = $(this);
  2531. visible = $.grep(visible, function(value) {
  2532. return value.attr('id') != $this.attr('id');
  2533. });
  2534. if (visible[0]) { // Check if empty
  2535. $(options.getActiveElement(visible[0].attr('id'))).addClass(options.activeClass);
  2536. }
  2537. }
  2538. });
  2539. return selector;
  2540. };
  2541. /**
  2542. * Listen for window resize events
  2543. * @param {Object=} options Optional. Set { throttle: number } to change throttling. Default: 100 ms
  2544. * @returns {jQuery} $(window)
  2545. */
  2546. $.winSizeSpy = function(options) {
  2547. $.winSizeSpy = function() { return jWindow; }; // lock from multiple calls
  2548. options = options || {
  2549. throttle: 100
  2550. };
  2551. return jWindow.on('resize', Materialize.throttle(onWinSize, options.throttle || 100));
  2552. };
  2553. /**
  2554. * Enables ScrollSpy on a collection of elements
  2555. * e.g. $('.scrollSpy').scrollSpy()
  2556. * @param {Object=} options Optional.
  2557. throttle : number -> scrollspy throttling. Default: 100 ms
  2558. offsetTop : number -> offset from top. Default: 0
  2559. offsetRight : number -> offset from right. Default: 0
  2560. offsetBottom : number -> offset from bottom. Default: 0
  2561. offsetLeft : number -> offset from left. Default: 0
  2562. * @returns {jQuery}
  2563. */
  2564. $.fn.scrollSpy = function(options) {
  2565. return $.scrollSpy($(this), options);
  2566. };
  2567. })(jQuery);
  2568. ;(function ($) {
  2569. $(document).ready(function() {
  2570. // Function to update labels of text fields
  2571. Materialize.updateTextFields = function() {
  2572. 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';
  2573. $(input_selector).each(function(index, element) {
  2574. var $this = $(this);
  2575. if ($(element).val().length > 0 || $(element).is(':focus') || element.autofocus || $this.attr('placeholder') !== undefined) {
  2576. $this.siblings('label').addClass('active');
  2577. } else if ($(element)[0].validity) {
  2578. $this.siblings('label').toggleClass('active', $(element)[0].validity.badInput === true);
  2579. } else {
  2580. $this.siblings('label').removeClass('active');
  2581. }
  2582. });
  2583. };
  2584. // Text based inputs
  2585. 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';
  2586. // Add active if form auto complete
  2587. $(document).on('change', input_selector, function () {
  2588. if($(this).val().length !== 0 || $(this).attr('placeholder') !== undefined) {
  2589. $(this).siblings('label').addClass('active');
  2590. }
  2591. validate_field($(this));
  2592. });
  2593. // Add active if input element has been pre-populated on document ready
  2594. $(document).ready(function() {
  2595. Materialize.updateTextFields();
  2596. });
  2597. // HTML DOM FORM RESET handling
  2598. $(document).on('reset', function(e) {
  2599. var formReset = $(e.target);
  2600. if (formReset.is('form')) {
  2601. formReset.find(input_selector).removeClass('valid').removeClass('invalid');
  2602. formReset.find(input_selector).each(function () {
  2603. if ($(this).attr('value') === '') {
  2604. $(this).siblings('label').removeClass('active');
  2605. }
  2606. });
  2607. // Reset select
  2608. formReset.find('select.initialized').each(function () {
  2609. var reset_text = formReset.find('option[selected]').text();
  2610. formReset.siblings('input.select-dropdown').val(reset_text);
  2611. });
  2612. }
  2613. });
  2614. // Add active when element has focus
  2615. $(document).on('focus', input_selector, function () {
  2616. $(this).siblings('label, .prefix').addClass('active');
  2617. });
  2618. $(document).on('blur', input_selector, function () {
  2619. var $inputElement = $(this);
  2620. var selector = ".prefix";
  2621. if ($inputElement.val().length === 0 && $inputElement[0].validity.badInput !== true && $inputElement.attr('placeholder') === undefined) {
  2622. selector += ", label";
  2623. }
  2624. $inputElement.siblings(selector).removeClass('active');
  2625. validate_field($inputElement);
  2626. });
  2627. window.validate_field = function(object) {
  2628. var hasLength = object.attr('data-length') !== undefined;
  2629. var lenAttr = parseInt(object.attr('data-length'));
  2630. var len = object.val().length;
  2631. if (object.val().length === 0 && object[0].validity.badInput === false) {
  2632. if (object.hasClass('validate')) {
  2633. object.removeClass('valid');
  2634. object.removeClass('invalid');
  2635. }
  2636. }
  2637. else {
  2638. if (object.hasClass('validate')) {
  2639. // Check for character counter attributes
  2640. if ((object.is(':valid') && hasLength && (len <= lenAttr)) || (object.is(':valid') && !hasLength)) {
  2641. object.removeClass('invalid');
  2642. object.addClass('valid');
  2643. }
  2644. else {
  2645. object.removeClass('valid');
  2646. object.addClass('invalid');
  2647. }
  2648. }
  2649. }
  2650. };
  2651. // Radio and Checkbox focus class
  2652. var radio_checkbox = 'input[type=radio], input[type=checkbox]';
  2653. $(document).on('keyup.radio', radio_checkbox, function(e) {
  2654. // TAB, check if tabbing to radio or checkbox.
  2655. if (e.which === 9) {
  2656. $(this).addClass('tabbed');
  2657. var $this = $(this);
  2658. $this.one('blur', function(e) {
  2659. $(this).removeClass('tabbed');
  2660. });
  2661. return;
  2662. }
  2663. });
  2664. // Textarea Auto Resize
  2665. var hiddenDiv = $('.hiddendiv').first();
  2666. if (!hiddenDiv.length) {
  2667. hiddenDiv = $('<div class="hiddendiv common"></div>');
  2668. $('body').append(hiddenDiv);
  2669. }
  2670. var text_area_selector = '.materialize-textarea';
  2671. function textareaAutoResize($textarea) {
  2672. // Set font properties of hiddenDiv
  2673. var fontFamily = $textarea.css('font-family');
  2674. var fontSize = $textarea.css('font-size');
  2675. var lineHeight = $textarea.css('line-height');
  2676. if (fontSize) { hiddenDiv.css('font-size', fontSize); }
  2677. if (fontFamily) { hiddenDiv.css('font-family', fontFamily); }
  2678. if (lineHeight) { hiddenDiv.css('line-height', lineHeight); }
  2679. // Set original-height, if none
  2680. if (!$textarea.data('original-height')) {
  2681. $textarea.data('original-height', $textarea.height());
  2682. }
  2683. if ($textarea.attr('wrap') === 'off') {
  2684. hiddenDiv.css('overflow-wrap', 'normal')
  2685. .css('white-space', 'pre');
  2686. }
  2687. hiddenDiv.text($textarea.val() + '\n');
  2688. var content = hiddenDiv.html().replace(/\n/g, '<br>');
  2689. hiddenDiv.html(content);
  2690. // When textarea is hidden, width goes crazy.
  2691. // Approximate with half of window size
  2692. if ($textarea.is(':visible')) {
  2693. hiddenDiv.css('width', $textarea.width());
  2694. }
  2695. else {
  2696. hiddenDiv.css('width', $(window).width()/2);
  2697. }
  2698. /**
  2699. * Resize if the new height is greater than the
  2700. * original height of the textarea
  2701. */
  2702. if ($textarea.data('original-height') <= hiddenDiv.height()) {
  2703. $textarea.css('height', hiddenDiv.height());
  2704. } else if ($textarea.val().length < $textarea.data('previous-length')) {
  2705. /**
  2706. * In case the new height is less than original height, it
  2707. * means the textarea has less text than before
  2708. * So we set the height to the original one
  2709. */
  2710. $textarea.css('height', $textarea.data('original-height'));
  2711. }
  2712. $textarea.data('previous-length', $textarea.val().length);
  2713. }
  2714. $(text_area_selector).each(function () {
  2715. var $textarea = $(this);
  2716. /**
  2717. * Instead of resizing textarea on document load,
  2718. * store the original height and the original length
  2719. */
  2720. $textarea.data('original-height', $textarea.height());
  2721. $textarea.data('previous-length', $textarea.val().length);
  2722. });
  2723. $('body').on('keyup keydown autoresize', text_area_selector, function () {
  2724. textareaAutoResize($(this));
  2725. });
  2726. // File Input Path
  2727. $(document).on('change', '.file-field input[type="file"]', function () {
  2728. var file_field = $(this).closest('.file-field');
  2729. var path_input = file_field.find('input.file-path');
  2730. var files = $(this)[0].files;
  2731. var file_names = [];
  2732. for (var i = 0; i < files.length; i++) {
  2733. file_names.push(files[i].name);
  2734. }
  2735. path_input.val(file_names.join(", "));
  2736. path_input.trigger('change');
  2737. });
  2738. /****************
  2739. * Range Input *
  2740. ****************/
  2741. var range_type = 'input[type=range]';
  2742. var range_mousedown = false;
  2743. var left;
  2744. $(range_type).each(function () {
  2745. var thumb = $('<span class="thumb"><span class="value"></span></span>');
  2746. $(this).after(thumb);
  2747. });
  2748. var showRangeBubble = function(thumb) {
  2749. var paddingLeft = parseInt(thumb.parent().css('padding-left'));
  2750. var marginLeft = (-7 + paddingLeft) + 'px';
  2751. thumb.velocity({ height: "30px", width: "30px", top: "-30px", marginLeft: marginLeft}, { duration: 300, easing: 'easeOutExpo' });
  2752. };
  2753. var calcRangeOffset = function(range) {
  2754. var width = range.width() - 15;
  2755. var max = parseFloat(range.attr('max'));
  2756. var min = parseFloat(range.attr('min'));
  2757. var percent = (parseFloat(range.val()) - min) / (max - min);
  2758. return percent * width;
  2759. }
  2760. var range_wrapper = '.range-field';
  2761. $(document).on('change', range_type, function(e) {
  2762. var thumb = $(this).siblings('.thumb');
  2763. thumb.find('.value').html($(this).val());
  2764. if (!thumb.hasClass('active')) {
  2765. showRangeBubble(thumb);
  2766. }
  2767. var offsetLeft = calcRangeOffset($(this));
  2768. thumb.addClass('active').css('left', offsetLeft);
  2769. });
  2770. $(document).on('mousedown touchstart', range_type, function(e) {
  2771. var thumb = $(this).siblings('.thumb');
  2772. // If thumb indicator does not exist yet, create it
  2773. if (thumb.length <= 0) {
  2774. thumb = $('<span class="thumb"><span class="value"></span></span>');
  2775. $(this).after(thumb);
  2776. }
  2777. // Set indicator value
  2778. thumb.find('.value').html($(this).val());
  2779. range_mousedown = true;
  2780. $(this).addClass('active');
  2781. if (!thumb.hasClass('active')) {
  2782. showRangeBubble(thumb);
  2783. }
  2784. if (e.type !== 'input') {
  2785. var offsetLeft = calcRangeOffset($(this));
  2786. thumb.addClass('active').css('left', offsetLeft);
  2787. }
  2788. });
  2789. $(document).on('mouseup touchend', range_wrapper, function() {
  2790. range_mousedown = false;
  2791. $(this).removeClass('active');
  2792. });
  2793. $(document).on('input mousemove touchmove', range_wrapper, function(e) {
  2794. var thumb = $(this).children('.thumb');
  2795. var left;
  2796. var input = $(this).find(range_type);
  2797. if (range_mousedown) {
  2798. if (!thumb.hasClass('active')) {
  2799. showRangeBubble(thumb);
  2800. }
  2801. var offsetLeft = calcRangeOffset(input);
  2802. thumb.addClass('active').css('left', offsetLeft);
  2803. thumb.find('.value').html(thumb.siblings(range_type).val());
  2804. }
  2805. });
  2806. $(document).on('mouseout touchleave', range_wrapper, function() {
  2807. if (!range_mousedown) {
  2808. var thumb = $(this).children('.thumb');
  2809. var paddingLeft = parseInt($(this).css('padding-left'));
  2810. var marginLeft = (7 + paddingLeft) + 'px';
  2811. if (thumb.hasClass('active')) {
  2812. thumb.velocity({ height: '0', width: '0', top: '10px', marginLeft: marginLeft}, { duration: 100 });
  2813. }
  2814. thumb.removeClass('active');
  2815. }
  2816. });
  2817. /**************************
  2818. * Auto complete plugin *
  2819. *************************/
  2820. $.fn.autocomplete = function (options) {
  2821. // Defaults
  2822. var defaults = {
  2823. data: {},
  2824. limit: Infinity,
  2825. onAutocomplete: null,
  2826. minLength: 1
  2827. };
  2828. options = $.extend(defaults, options);
  2829. return this.each(function() {
  2830. var $input = $(this);
  2831. var data = options.data,
  2832. count = 0,
  2833. activeIndex = -1,
  2834. oldVal,
  2835. $inputDiv = $input.closest('.input-field'); // Div to append on
  2836. // Check if data isn't empty
  2837. if (!$.isEmptyObject(data)) {
  2838. var $autocomplete = $('<ul class="autocomplete-content dropdown-content"></ul>');
  2839. var $oldAutocomplete;
  2840. // Append autocomplete element.
  2841. // Prevent double structure init.
  2842. if ($inputDiv.length) {
  2843. $oldAutocomplete = $inputDiv.children('.autocomplete-content.dropdown-content').first();
  2844. if (!$oldAutocomplete.length) {
  2845. $inputDiv.append($autocomplete); // Set ul in body
  2846. }
  2847. } else {
  2848. $oldAutocomplete = $input.next('.autocomplete-content.dropdown-content');
  2849. if (!$oldAutocomplete.length) {
  2850. $input.after($autocomplete);
  2851. }
  2852. }
  2853. if ($oldAutocomplete.length) {
  2854. $autocomplete = $oldAutocomplete;
  2855. }
  2856. // Highlight partial match.
  2857. var highlight = function(string, $el) {
  2858. var img = $el.find('img');
  2859. var matchStart = $el.text().toLowerCase().indexOf("" + string.toLowerCase() + ""),
  2860. matchEnd = matchStart + string.length - 1,
  2861. beforeMatch = $el.text().slice(0, matchStart),
  2862. matchText = $el.text().slice(matchStart, matchEnd + 1),
  2863. afterMatch = $el.text().slice(matchEnd + 1);
  2864. $el.html("<span>" + beforeMatch + "<span class='highlight'>" + matchText + "</span>" + afterMatch + "</span>");
  2865. if (img.length) {
  2866. $el.prepend(img);
  2867. }
  2868. };
  2869. // Reset current element position
  2870. var resetCurrentElement = function() {
  2871. activeIndex = -1;
  2872. $autocomplete.find('.active').removeClass('active');
  2873. }
  2874. // Remove autocomplete elements
  2875. var removeAutocomplete = function() {
  2876. $autocomplete.empty();
  2877. resetCurrentElement();
  2878. oldVal = undefined;
  2879. };
  2880. $input.off('blur.autocomplete').on('blur.autocomplete', function() {
  2881. removeAutocomplete();
  2882. });
  2883. // Perform search
  2884. $input.off('keyup.autocomplete focus.autocomplete').on('keyup.autocomplete focus.autocomplete', function (e) {
  2885. // Reset count.
  2886. count = 0;
  2887. var val = $input.val().toLowerCase();
  2888. // Don't capture enter or arrow key usage.
  2889. if (e.which === 13 ||
  2890. e.which === 38 ||
  2891. e.which === 40) {
  2892. return;
  2893. }
  2894. // Check if the input isn't empty
  2895. if (oldVal !== val) {
  2896. removeAutocomplete();
  2897. if (val.length >= options.minLength) {
  2898. for(var key in data) {
  2899. if (data.hasOwnProperty(key) &&
  2900. key.toLowerCase().indexOf(val) !== -1 &&
  2901. key.toLowerCase() !== val) {
  2902. // Break if past limit
  2903. if (count >= options.limit) {
  2904. break;
  2905. }
  2906. var autocompleteOption = $('<li></li>');
  2907. if (!!data[key]) {
  2908. autocompleteOption.append('<img src="'+ data[key] +'" class="right circle"><span>'+ key +'</span>');
  2909. } else {
  2910. autocompleteOption.append('<span>'+ key +'</span>');
  2911. }
  2912. $autocomplete.append(autocompleteOption);
  2913. highlight(val, autocompleteOption);
  2914. count++;
  2915. }
  2916. }
  2917. }
  2918. }
  2919. // Update oldVal
  2920. oldVal = val;
  2921. });
  2922. $input.off('keydown.autocomplete').on('keydown.autocomplete', function (e) {
  2923. // Arrow keys and enter key usage
  2924. var keyCode = e.which,
  2925. liElement,
  2926. numItems = $autocomplete.children('li').length,
  2927. $active = $autocomplete.children('.active').first();
  2928. // select element on Enter
  2929. if (keyCode === 13 && activeIndex >= 0) {
  2930. liElement = $autocomplete.children('li').eq(activeIndex);
  2931. if (liElement.length) {
  2932. liElement.trigger('mousedown.autocomplete');
  2933. e.preventDefault();
  2934. }
  2935. return;
  2936. }
  2937. // Capture up and down key
  2938. if ( keyCode === 38 || keyCode === 40 ) {
  2939. e.preventDefault();
  2940. if (keyCode === 38 &&
  2941. activeIndex > 0) {
  2942. activeIndex--;
  2943. }
  2944. if (keyCode === 40 &&
  2945. activeIndex < (numItems - 1)) {
  2946. activeIndex++;
  2947. }
  2948. $active.removeClass('active');
  2949. if (activeIndex >= 0) {
  2950. $autocomplete.children('li').eq(activeIndex).addClass('active');
  2951. }
  2952. }
  2953. });
  2954. // Set input value
  2955. $autocomplete.on('mousedown.autocomplete touchstart.autocomplete', 'li', function () {
  2956. var text = $(this).text().trim();
  2957. $input.val(text);
  2958. $input.trigger('change');
  2959. removeAutocomplete();
  2960. // Handle onAutocomplete callback.
  2961. if (typeof(options.onAutocomplete) === "function") {
  2962. options.onAutocomplete.call(this, text);
  2963. }
  2964. });
  2965. }
  2966. });
  2967. };
  2968. }); // End of $(document).ready
  2969. /*******************
  2970. * Select Plugin *
  2971. ******************/
  2972. $.fn.material_select = function (callback) {
  2973. $(this).each(function(){
  2974. var $select = $(this);
  2975. if ($select.hasClass('browser-default')) {
  2976. return; // Continue to next (return false breaks out of entire loop)
  2977. }
  2978. var multiple = $select.attr('multiple') ? true : false,
  2979. lastID = $select.data('select-id'); // Tear down structure if Select needs to be rebuilt
  2980. if (lastID) {
  2981. $select.parent().find('span.caret').remove();
  2982. $select.parent().find('input').remove();
  2983. $select.unwrap();
  2984. $('ul#select-options-'+lastID).remove();
  2985. }
  2986. // If destroying the select, remove the selelct-id and reset it to it's uninitialized state.
  2987. if(callback === 'destroy') {
  2988. $select.data('select-id', null).removeClass('initialized');
  2989. return;
  2990. }
  2991. var uniqueID = Materialize.guid();
  2992. $select.data('select-id', uniqueID);
  2993. var wrapper = $('<div class="select-wrapper"></div>');
  2994. wrapper.addClass($select.attr('class'));
  2995. var options = $('<ul id="select-options-' + uniqueID +'" class="dropdown-content select-dropdown ' + (multiple ? 'multiple-select-dropdown' : '') + '"></ul>'),
  2996. selectChildren = $select.children('option, optgroup'),
  2997. valuesSelected = [],
  2998. optionsHover = false;
  2999. var label = $select.find('option:selected').html() || $select.find('option:first').html() || "";
  3000. // Function that renders and appends the option taking into
  3001. // account type and possible image icon.
  3002. var appendOptionWithIcon = function(select, option, type) {
  3003. // Add disabled attr if disabled
  3004. var disabledClass = (option.is(':disabled')) ? 'disabled ' : '';
  3005. var optgroupClass = (type === 'optgroup-option') ? 'optgroup-option ' : '';
  3006. var multipleCheckbox = multiple ? '<input type="checkbox"' + disabledClass + '/><label></label>' : '';
  3007. // add icons
  3008. var icon_url = option.data('icon');
  3009. var classes = option.attr('class');
  3010. if (!!icon_url) {
  3011. var classString = '';
  3012. if (!!classes) classString = ' class="' + classes + '"';
  3013. // Check for multiple type.
  3014. options.append($('<li class="' + disabledClass + optgroupClass + '"><img alt="" src="' + icon_url + '"' + classString + '><span>' + multipleCheckbox + option.html() + '</span></li>'));
  3015. return true;
  3016. }
  3017. // Check for multiple type.
  3018. options.append($('<li class="' + disabledClass + optgroupClass + '"><span>' + multipleCheckbox + option.html() + '</span></li>'));
  3019. };
  3020. /* Create dropdown structure. */
  3021. if (selectChildren.length) {
  3022. selectChildren.each(function() {
  3023. if ($(this).is('option')) {
  3024. // Direct descendant option.
  3025. if (multiple) {
  3026. appendOptionWithIcon($select, $(this), 'multiple');
  3027. } else {
  3028. appendOptionWithIcon($select, $(this));
  3029. }
  3030. } else if ($(this).is('optgroup')) {
  3031. // Optgroup.
  3032. var selectOptions = $(this).children('option');
  3033. options.append($('<li class="optgroup"><span>' + $(this).attr('label') + '</span></li>'));
  3034. selectOptions.each(function() {
  3035. appendOptionWithIcon($select, $(this), 'optgroup-option');
  3036. });
  3037. }
  3038. });
  3039. }
  3040. options.find('li:not(.optgroup)').each(function (i) {
  3041. $(this).click(function (e) {
  3042. // Check if option element is disabled
  3043. if (!$(this).hasClass('disabled') && !$(this).hasClass('optgroup')) {
  3044. var selected = true;
  3045. if (multiple) {
  3046. $('input[type="checkbox"]', this).prop('checked', function(i, v) { return !v; });
  3047. selected = toggleEntryFromArray(valuesSelected, i, $select);
  3048. $newSelect.trigger('focus');
  3049. } else {
  3050. options.find('li').removeClass('active');
  3051. $(this).toggleClass('active');
  3052. $newSelect.val($(this).text());
  3053. }
  3054. activateOption(options, $(this));
  3055. $select.find('option').eq(i).prop('selected', selected);
  3056. // Trigger onchange() event
  3057. $select.trigger('change');
  3058. if (typeof callback !== 'undefined') callback();
  3059. }
  3060. e.stopPropagation();
  3061. });
  3062. });
  3063. // Wrap Elements
  3064. $select.wrap(wrapper);
  3065. // Add Select Display Element
  3066. var dropdownIcon = $('<span class="caret">&#9660;</span>');
  3067. if ($select.is(':disabled'))
  3068. dropdownIcon.addClass('disabled');
  3069. // escape double quotes
  3070. var sanitizedLabelHtml = label.replace(/"/g, '&quot;');
  3071. var $newSelect = $('<input type="text" class="select-dropdown" readonly="true" ' + (($select.is(':disabled')) ? 'disabled' : '') + ' data-activates="select-options-' + uniqueID +'" value="'+ sanitizedLabelHtml +'"/>');
  3072. $select.before($newSelect);
  3073. $newSelect.before(dropdownIcon);
  3074. $newSelect.after(options);
  3075. // Check if section element is disabled
  3076. if (!$select.is(':disabled')) {
  3077. $newSelect.dropdown({'hover': false});
  3078. }
  3079. // Copy tabindex
  3080. if ($select.attr('tabindex')) {
  3081. $($newSelect[0]).attr('tabindex', $select.attr('tabindex'));
  3082. }
  3083. $select.addClass('initialized');
  3084. $newSelect.on({
  3085. 'focus': function (){
  3086. if ($('ul.select-dropdown').not(options[0]).is(':visible')) {
  3087. $('input.select-dropdown').trigger('close');
  3088. }
  3089. if (!options.is(':visible')) {
  3090. $(this).trigger('open', ['focus']);
  3091. var label = $(this).val();
  3092. if (multiple && label.indexOf(',') >= 0) {
  3093. label = label.split(',')[0];
  3094. }
  3095. var selectedOption = options.find('li').filter(function() {
  3096. return $(this).text().toLowerCase() === label.toLowerCase();
  3097. })[0];
  3098. activateOption(options, selectedOption, true);
  3099. }
  3100. },
  3101. 'click': function (e){
  3102. e.stopPropagation();
  3103. }
  3104. });
  3105. $newSelect.on('blur', function() {
  3106. if (!multiple) {
  3107. $(this).trigger('close');
  3108. }
  3109. options.find('li.selected').removeClass('selected');
  3110. });
  3111. options.hover(function() {
  3112. optionsHover = true;
  3113. }, function () {
  3114. optionsHover = false;
  3115. });
  3116. $(window).on({
  3117. 'click': function () {
  3118. multiple && (optionsHover || $newSelect.trigger('close'));
  3119. }
  3120. });
  3121. // Add initial multiple selections.
  3122. if (multiple) {
  3123. $select.find("option:selected:not(:disabled)").each(function () {
  3124. var index = $(this).index();
  3125. toggleEntryFromArray(valuesSelected, index, $select);
  3126. options.find("li").eq(index).find(":checkbox").prop("checked", true);
  3127. });
  3128. }
  3129. /**
  3130. * Make option as selected and scroll to selected position
  3131. * @param {jQuery} collection Select options jQuery element
  3132. * @param {Element} newOption element of the new option
  3133. * @param {Boolean} firstActivation If on first activation of select
  3134. */
  3135. var activateOption = function(collection, newOption, firstActivation) {
  3136. if (newOption) {
  3137. collection.find('li.selected').removeClass('selected');
  3138. var option = $(newOption);
  3139. option.addClass('selected');
  3140. if (!multiple || !!firstActivation) {
  3141. options.scrollTo(option);
  3142. }
  3143. }
  3144. };
  3145. // Allow user to search by typing
  3146. // this array is cleared after 1 second
  3147. var filterQuery = [],
  3148. onKeyDown = function(e){
  3149. // TAB - switch to another input
  3150. if(e.which == 9){
  3151. $newSelect.trigger('close');
  3152. return;
  3153. }
  3154. // ARROW DOWN WHEN SELECT IS CLOSED - open select options
  3155. if(e.which == 40 && !options.is(':visible')){
  3156. $newSelect.trigger('open');
  3157. return;
  3158. }
  3159. // ENTER WHEN SELECT IS CLOSED - submit form
  3160. if(e.which == 13 && !options.is(':visible')){
  3161. return;
  3162. }
  3163. e.preventDefault();
  3164. // CASE WHEN USER TYPE LETTERS
  3165. var letter = String.fromCharCode(e.which).toLowerCase(),
  3166. nonLetters = [9,13,27,38,40];
  3167. if (letter && (nonLetters.indexOf(e.which) === -1)) {
  3168. filterQuery.push(letter);
  3169. var string = filterQuery.join(''),
  3170. newOption = options.find('li').filter(function() {
  3171. return $(this).text().toLowerCase().indexOf(string) === 0;
  3172. })[0];
  3173. if (newOption) {
  3174. activateOption(options, newOption);
  3175. }
  3176. }
  3177. // ENTER - select option and close when select options are opened
  3178. if (e.which == 13) {
  3179. var activeOption = options.find('li.selected:not(.disabled)')[0];
  3180. if(activeOption){
  3181. $(activeOption).trigger('click');
  3182. if (!multiple) {
  3183. $newSelect.trigger('close');
  3184. }
  3185. }
  3186. }
  3187. // ARROW DOWN - move to next not disabled option
  3188. if (e.which == 40) {
  3189. if (options.find('li.selected').length) {
  3190. newOption = options.find('li.selected').next('li:not(.disabled)')[0];
  3191. } else {
  3192. newOption = options.find('li:not(.disabled)')[0];
  3193. }
  3194. activateOption(options, newOption);
  3195. }
  3196. // ESC - close options
  3197. if (e.which == 27) {
  3198. $newSelect.trigger('close');
  3199. }
  3200. // ARROW UP - move to previous not disabled option
  3201. if (e.which == 38) {
  3202. newOption = options.find('li.selected').prev('li:not(.disabled)')[0];
  3203. if(newOption)
  3204. activateOption(options, newOption);
  3205. }
  3206. // Automaticaly clean filter query so user can search again by starting letters
  3207. setTimeout(function(){ filterQuery = []; }, 1000);
  3208. };
  3209. $newSelect.on('keydown', onKeyDown);
  3210. });
  3211. function toggleEntryFromArray(entriesArray, entryIndex, select) {
  3212. var index = entriesArray.indexOf(entryIndex),
  3213. notAdded = index === -1;
  3214. if (notAdded) {
  3215. entriesArray.push(entryIndex);
  3216. } else {
  3217. entriesArray.splice(index, 1);
  3218. }
  3219. select.siblings('ul.dropdown-content').find('li:not(.optgroup)').eq(entryIndex).toggleClass('active');
  3220. // use notAdded instead of true (to detect if the option is selected or not)
  3221. select.find('option').eq(entryIndex).prop('selected', notAdded);
  3222. setValueToInput(entriesArray, select);
  3223. return notAdded;
  3224. }
  3225. function setValueToInput(entriesArray, select) {
  3226. var value = '';
  3227. for (var i = 0, count = entriesArray.length; i < count; i++) {
  3228. var text = select.find('option').eq(entriesArray[i]).text();
  3229. i === 0 ? value += text : value += ', ' + text;
  3230. }
  3231. if (value === '') {
  3232. value = select.find('option:disabled').eq(0).text();
  3233. }
  3234. select.siblings('input.select-dropdown').val(value);
  3235. }
  3236. };
  3237. }( jQuery ));
  3238. ;(function ($) {
  3239. var methods = {
  3240. init : function(options) {
  3241. var defaults = {
  3242. indicators: true,
  3243. height: 400,
  3244. transition: 500,
  3245. interval: 6000
  3246. };
  3247. options = $.extend(defaults, options);
  3248. return this.each(function() {
  3249. // For each slider, we want to keep track of
  3250. // which slide is active and its associated content
  3251. var $this = $(this);
  3252. var $slider = $this.find('ul.slides').first();
  3253. var $slides = $slider.find('> li');
  3254. var $active_index = $slider.find('.active').index();
  3255. var $active, $indicators, $interval;
  3256. if ($active_index != -1) { $active = $slides.eq($active_index); }
  3257. // Transitions the caption depending on alignment
  3258. function captionTransition(caption, duration) {
  3259. if (caption.hasClass("center-align")) {
  3260. caption.velocity({opacity: 0, translateY: -100}, {duration: duration, queue: false});
  3261. }
  3262. else if (caption.hasClass("right-align")) {
  3263. caption.velocity({opacity: 0, translateX: 100}, {duration: duration, queue: false});
  3264. }
  3265. else if (caption.hasClass("left-align")) {
  3266. caption.velocity({opacity: 0, translateX: -100}, {duration: duration, queue: false});
  3267. }
  3268. }
  3269. // This function will transition the slide to any index of the next slide
  3270. function moveToSlide(index) {
  3271. // Wrap around indices.
  3272. if (index >= $slides.length) index = 0;
  3273. else if (index < 0) index = $slides.length -1;
  3274. $active_index = $slider.find('.active').index();
  3275. // Only do if index changes
  3276. if ($active_index != index) {
  3277. $active = $slides.eq($active_index);
  3278. $caption = $active.find('.caption');
  3279. $active.removeClass('active');
  3280. $active.velocity({opacity: 0}, {duration: options.transition, queue: false, easing: 'easeOutQuad',
  3281. complete: function() {
  3282. $slides.not('.active').velocity({opacity: 0, translateX: 0, translateY: 0}, {duration: 0, queue: false});
  3283. } });
  3284. captionTransition($caption, options.transition);
  3285. // Update indicators
  3286. if (options.indicators) {
  3287. $indicators.eq($active_index).removeClass('active');
  3288. }
  3289. $slides.eq(index).velocity({opacity: 1}, {duration: options.transition, queue: false, easing: 'easeOutQuad'});
  3290. $slides.eq(index).find('.caption').velocity({opacity: 1, translateX: 0, translateY: 0}, {duration: options.transition, delay: options.transition, queue: false, easing: 'easeOutQuad'});
  3291. $slides.eq(index).addClass('active');
  3292. // Update indicators
  3293. if (options.indicators) {
  3294. $indicators.eq(index).addClass('active');
  3295. }
  3296. }
  3297. }
  3298. // Set height of slider
  3299. // If fullscreen, do nothing
  3300. if (!$this.hasClass('fullscreen')) {
  3301. if (options.indicators) {
  3302. // Add height if indicators are present
  3303. $this.height(options.height + 40);
  3304. }
  3305. else {
  3306. $this.height(options.height);
  3307. }
  3308. $slider.height(options.height);
  3309. }
  3310. // Set initial positions of captions
  3311. $slides.find('.caption').each(function () {
  3312. captionTransition($(this), 0);
  3313. });
  3314. // Move img src into background-image
  3315. $slides.find('img').each(function () {
  3316. var placeholderBase64 = 'data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
  3317. if ($(this).attr('src') !== placeholderBase64) {
  3318. $(this).css('background-image', 'url("' + $(this).attr('src') + '")' );
  3319. $(this).attr('src', placeholderBase64);
  3320. }
  3321. });
  3322. // dynamically add indicators
  3323. if (options.indicators) {
  3324. $indicators = $('<ul class="indicators"></ul>');
  3325. $slides.each(function( index ) {
  3326. var $indicator = $('<li class="indicator-item"></li>');
  3327. // Handle clicks on indicators
  3328. $indicator.click(function () {
  3329. var $parent = $slider.parent();
  3330. var curr_index = $parent.find($(this)).index();
  3331. moveToSlide(curr_index);
  3332. // reset interval
  3333. clearInterval($interval);
  3334. $interval = setInterval(
  3335. function(){
  3336. $active_index = $slider.find('.active').index();
  3337. if ($slides.length == $active_index + 1) $active_index = 0; // loop to start
  3338. else $active_index += 1;
  3339. moveToSlide($active_index);
  3340. }, options.transition + options.interval
  3341. );
  3342. });
  3343. $indicators.append($indicator);
  3344. });
  3345. $this.append($indicators);
  3346. $indicators = $this.find('ul.indicators').find('li.indicator-item');
  3347. }
  3348. if ($active) {
  3349. $active.show();
  3350. }
  3351. else {
  3352. $slides.first().addClass('active').velocity({opacity: 1}, {duration: options.transition, queue: false, easing: 'easeOutQuad'});
  3353. $active_index = 0;
  3354. $active = $slides.eq($active_index);
  3355. // Update indicators
  3356. if (options.indicators) {
  3357. $indicators.eq($active_index).addClass('active');
  3358. }
  3359. }
  3360. // Adjust height to current slide
  3361. $active.find('img').each(function() {
  3362. $active.find('.caption').velocity({opacity: 1, translateX: 0, translateY: 0}, {duration: options.transition, queue: false, easing: 'easeOutQuad'});
  3363. });
  3364. // auto scroll
  3365. $interval = setInterval(
  3366. function(){
  3367. $active_index = $slider.find('.active').index();
  3368. moveToSlide($active_index + 1);
  3369. }, options.transition + options.interval
  3370. );
  3371. // HammerJS, Swipe navigation
  3372. // Touch Event
  3373. var panning = false;
  3374. var swipeLeft = false;
  3375. var swipeRight = false;
  3376. $this.hammer({
  3377. prevent_default: false
  3378. }).on('pan', function(e) {
  3379. if (e.gesture.pointerType === "touch") {
  3380. // reset interval
  3381. clearInterval($interval);
  3382. var direction = e.gesture.direction;
  3383. var x = e.gesture.deltaX;
  3384. var velocityX = e.gesture.velocityX;
  3385. var velocityY = e.gesture.velocityY;
  3386. $curr_slide = $slider.find('.active');
  3387. if (Math.abs(velocityX) > Math.abs(velocityY)) {
  3388. $curr_slide.velocity({ translateX: x
  3389. }, {duration: 50, queue: false, easing: 'easeOutQuad'});
  3390. }
  3391. // Swipe Left
  3392. if (direction === 4 && (x > ($this.innerWidth() / 2) || velocityX < -0.65)) {
  3393. swipeRight = true;
  3394. }
  3395. // Swipe Right
  3396. else if (direction === 2 && (x < (-1 * $this.innerWidth() / 2) || velocityX > 0.65)) {
  3397. swipeLeft = true;
  3398. }
  3399. // Make Slide Behind active slide visible
  3400. var next_slide;
  3401. if (swipeLeft) {
  3402. next_slide = $curr_slide.next();
  3403. if (next_slide.length === 0) {
  3404. next_slide = $slides.first();
  3405. }
  3406. next_slide.velocity({ opacity: 1
  3407. }, {duration: 300, queue: false, easing: 'easeOutQuad'});
  3408. }
  3409. if (swipeRight) {
  3410. next_slide = $curr_slide.prev();
  3411. if (next_slide.length === 0) {
  3412. next_slide = $slides.last();
  3413. }
  3414. next_slide.velocity({ opacity: 1
  3415. }, {duration: 300, queue: false, easing: 'easeOutQuad'});
  3416. }
  3417. }
  3418. }).on('panend', function(e) {
  3419. if (e.gesture.pointerType === "touch") {
  3420. $curr_slide = $slider.find('.active');
  3421. panning = false;
  3422. curr_index = $slider.find('.active').index();
  3423. if (!swipeRight && !swipeLeft || $slides.length <=1) {
  3424. // Return to original spot
  3425. $curr_slide.velocity({ translateX: 0
  3426. }, {duration: 300, queue: false, easing: 'easeOutQuad'});
  3427. }
  3428. else if (swipeLeft) {
  3429. moveToSlide(curr_index + 1);
  3430. $curr_slide.velocity({translateX: -1 * $this.innerWidth() }, {duration: 300, queue: false, easing: 'easeOutQuad',
  3431. complete: function() {
  3432. $curr_slide.velocity({opacity: 0, translateX: 0}, {duration: 0, queue: false});
  3433. } });
  3434. }
  3435. else if (swipeRight) {
  3436. moveToSlide(curr_index - 1);
  3437. $curr_slide.velocity({translateX: $this.innerWidth() }, {duration: 300, queue: false, easing: 'easeOutQuad',
  3438. complete: function() {
  3439. $curr_slide.velocity({opacity: 0, translateX: 0}, {duration: 0, queue: false});
  3440. } });
  3441. }
  3442. swipeLeft = false;
  3443. swipeRight = false;
  3444. // Restart interval
  3445. clearInterval($interval);
  3446. $interval = setInterval(
  3447. function(){
  3448. $active_index = $slider.find('.active').index();
  3449. if ($slides.length == $active_index + 1) $active_index = 0; // loop to start
  3450. else $active_index += 1;
  3451. moveToSlide($active_index);
  3452. }, options.transition + options.interval
  3453. );
  3454. }
  3455. });
  3456. $this.on('sliderPause', function() {
  3457. clearInterval($interval);
  3458. });
  3459. $this.on('sliderStart', function() {
  3460. clearInterval($interval);
  3461. $interval = setInterval(
  3462. function(){
  3463. $active_index = $slider.find('.active').index();
  3464. if ($slides.length == $active_index + 1) $active_index = 0; // loop to start
  3465. else $active_index += 1;
  3466. moveToSlide($active_index);
  3467. }, options.transition + options.interval
  3468. );
  3469. });
  3470. $this.on('sliderNext', function() {
  3471. $active_index = $slider.find('.active').index();
  3472. moveToSlide($active_index + 1);
  3473. });
  3474. $this.on('sliderPrev', function() {
  3475. $active_index = $slider.find('.active').index();
  3476. moveToSlide($active_index - 1);
  3477. });
  3478. });
  3479. },
  3480. pause : function() {
  3481. $(this).trigger('sliderPause');
  3482. },
  3483. start : function() {
  3484. $(this).trigger('sliderStart');
  3485. },
  3486. next : function() {
  3487. $(this).trigger('sliderNext');
  3488. },
  3489. prev : function() {
  3490. $(this).trigger('sliderPrev');
  3491. }
  3492. };
  3493. $.fn.slider = function(methodOrOptions) {
  3494. if ( methods[methodOrOptions] ) {
  3495. return methods[ methodOrOptions ].apply( this, Array.prototype.slice.call( arguments, 1 ));
  3496. } else if ( typeof methodOrOptions === 'object' || ! methodOrOptions ) {
  3497. // Default to "init"
  3498. return methods.init.apply( this, arguments );
  3499. } else {
  3500. $.error( 'Method ' + methodOrOptions + ' does not exist on jQuery.tooltip' );
  3501. }
  3502. }; // Plugin end
  3503. }( jQuery ));
  3504. ;(function ($) {
  3505. $(document).ready(function() {
  3506. $(document).on('click.card', '.card', function (e) {
  3507. if ($(this).find('> .card-reveal').length) {
  3508. var $card = $(e.target).closest('.card');
  3509. if ($card.data('initialOverflow') === undefined) {
  3510. $card.data(
  3511. 'initialOverflow',
  3512. $card.css('overflow') === undefined ? '' : $card.css('overflow')
  3513. );
  3514. }
  3515. if ($(e.target).is($('.card-reveal .card-title')) || $(e.target).is($('.card-reveal .card-title i'))) {
  3516. // Make Reveal animate down and display none
  3517. $(this).find('.card-reveal').velocity(
  3518. {translateY: 0}, {
  3519. duration: 225,
  3520. queue: false,
  3521. easing: 'easeInOutQuad',
  3522. complete: function() {
  3523. $(this).css({ display: 'none'});
  3524. $card.css('overflow', $card.data('initialOverflow'));
  3525. }
  3526. }
  3527. );
  3528. }
  3529. else if ($(e.target).is($('.card .activator')) ||
  3530. $(e.target).is($('.card .activator i')) ) {
  3531. $card.css('overflow', 'hidden');
  3532. $(this).find('.card-reveal').css({ display: 'block'}).velocity("stop", false).velocity({translateY: '-100%'}, {duration: 300, queue: false, easing: 'easeInOutQuad'});
  3533. }
  3534. }
  3535. });
  3536. });
  3537. }( jQuery ));
  3538. ;(function ($) {
  3539. var materialChipsDefaults = {
  3540. data: [],
  3541. placeholder: '',
  3542. secondaryPlaceholder: '',
  3543. autocompleteOptions: {},
  3544. };
  3545. $(document).ready(function() {
  3546. // Handle removal of static chips.
  3547. $(document).on('click', '.chip .close', function(e){
  3548. var $chips = $(this).closest('.chips');
  3549. if ($chips.attr('data-initialized')) {
  3550. return;
  3551. }
  3552. $(this).closest('.chip').remove();
  3553. });
  3554. });
  3555. $.fn.material_chip = function (options) {
  3556. var self = this;
  3557. this.$el = $(this);
  3558. this.$document = $(document);
  3559. this.SELS = {
  3560. CHIPS: '.chips',
  3561. CHIP: '.chip',
  3562. INPUT: 'input',
  3563. DELETE: '.material-icons',
  3564. SELECTED_CHIP: '.selected',
  3565. };
  3566. if ('data' === options) {
  3567. return this.$el.data('chips');
  3568. }
  3569. var curr_options = $.extend({}, materialChipsDefaults, options);
  3570. self.hasAutocomplete = !$.isEmptyObject(curr_options.autocompleteOptions.data);
  3571. // Initialize
  3572. this.init = function() {
  3573. var i = 0;
  3574. var chips;
  3575. self.$el.each(function(){
  3576. var $chips = $(this);
  3577. var chipId = Materialize.guid();
  3578. self.chipId = chipId;
  3579. if (!curr_options.data || !(curr_options.data instanceof Array)) {
  3580. curr_options.data = [];
  3581. }
  3582. $chips.data('chips', curr_options.data);
  3583. $chips.attr('data-index', i);
  3584. $chips.attr('data-initialized', true);
  3585. if (!$chips.hasClass(self.SELS.CHIPS)) {
  3586. $chips.addClass('chips');
  3587. }
  3588. self.chips($chips, chipId);
  3589. i++;
  3590. });
  3591. };
  3592. this.handleEvents = function() {
  3593. var SELS = self.SELS;
  3594. self.$document.off('click.chips-focus', SELS.CHIPS).on('click.chips-focus', SELS.CHIPS, function(e){
  3595. $(e.target).find(SELS.INPUT).focus();
  3596. });
  3597. self.$document.off('click.chips-select', SELS.CHIP).on('click.chips-select', SELS.CHIP, function(e){
  3598. var $chip = $(e.target);
  3599. if ($chip.length) {
  3600. var wasSelected = $chip.hasClass('selected');
  3601. var $chips = $chip.closest(SELS.CHIPS);
  3602. $(SELS.CHIP).removeClass('selected');
  3603. if (!wasSelected) {
  3604. self.selectChip($chip.index(), $chips);
  3605. }
  3606. }
  3607. });
  3608. self.$document.off('keydown.chips').on('keydown.chips', function(e){
  3609. if ($(e.target).is('input, textarea')) {
  3610. return;
  3611. }
  3612. // delete
  3613. var $chip = self.$document.find(SELS.CHIP + SELS.SELECTED_CHIP);
  3614. var $chips = $chip.closest(SELS.CHIPS);
  3615. var length = $chip.siblings(SELS.CHIP).length;
  3616. var index;
  3617. if (!$chip.length) {
  3618. return;
  3619. }
  3620. if (e.which === 8 || e.which === 46) {
  3621. e.preventDefault();
  3622. index = $chip.index();
  3623. self.deleteChip(index, $chips);
  3624. var selectIndex = null;
  3625. if ((index + 1) < length) {
  3626. selectIndex = index;
  3627. } else if (index === length || (index + 1) === length) {
  3628. selectIndex = length - 1;
  3629. }
  3630. if (selectIndex < 0) selectIndex = null;
  3631. if (null !== selectIndex) {
  3632. self.selectChip(selectIndex, $chips);
  3633. }
  3634. if (!length) $chips.find('input').focus();
  3635. // left
  3636. } else if (e.which === 37) {
  3637. index = $chip.index() - 1;
  3638. if (index < 0) {
  3639. return;
  3640. }
  3641. $(SELS.CHIP).removeClass('selected');
  3642. self.selectChip(index, $chips);
  3643. // right
  3644. } else if (e.which === 39) {
  3645. index = $chip.index() + 1;
  3646. $(SELS.CHIP).removeClass('selected');
  3647. if (index > length) {
  3648. $chips.find('input').focus();
  3649. return;
  3650. }
  3651. self.selectChip(index, $chips);
  3652. }
  3653. });
  3654. self.$document.off('focusin.chips', SELS.CHIPS + ' ' + SELS.INPUT).on('focusin.chips', SELS.CHIPS + ' ' + SELS.INPUT, function(e){
  3655. var $currChips = $(e.target).closest(SELS.CHIPS);
  3656. $currChips.addClass('focus');
  3657. $currChips.siblings('label, .prefix').addClass('active');
  3658. $(SELS.CHIP).removeClass('selected');
  3659. });
  3660. self.$document.off('focusout.chips', SELS.CHIPS + ' ' + SELS.INPUT).on('focusout.chips', SELS.CHIPS + ' ' + SELS.INPUT, function(e){
  3661. var $currChips = $(e.target).closest(SELS.CHIPS);
  3662. $currChips.removeClass('focus');
  3663. // Remove active if empty
  3664. if ($currChips.data('chips') === undefined || !$currChips.data('chips').length) {
  3665. $currChips.siblings('label').removeClass('active');
  3666. }
  3667. $currChips.siblings('.prefix').removeClass('active');
  3668. });
  3669. self.$document.off('keydown.chips-add', SELS.CHIPS + ' ' + SELS.INPUT).on('keydown.chips-add', SELS.CHIPS + ' ' + SELS.INPUT, function(e){
  3670. var $target = $(e.target);
  3671. var $chips = $target.closest(SELS.CHIPS);
  3672. var chipsLength = $chips.children(SELS.CHIP).length;
  3673. // enter
  3674. if (13 === e.which) {
  3675. // Override enter if autocompleting.
  3676. if (self.hasAutocomplete &&
  3677. $chips.find('.autocomplete-content.dropdown-content').length &&
  3678. $chips.find('.autocomplete-content.dropdown-content').children().length) {
  3679. return;
  3680. }
  3681. e.preventDefault();
  3682. self.addChip({tag: $target.val()}, $chips);
  3683. $target.val('');
  3684. return;
  3685. }
  3686. // delete or left
  3687. if ((8 === e.keyCode || 37 === e.keyCode) && '' === $target.val() && chipsLength) {
  3688. e.preventDefault();
  3689. self.selectChip(chipsLength - 1, $chips);
  3690. $target.blur();
  3691. return;
  3692. }
  3693. });
  3694. // Click on delete icon in chip.
  3695. self.$document.off('click.chips-delete', SELS.CHIPS + ' ' + SELS.DELETE).on('click.chips-delete', SELS.CHIPS + ' ' + SELS.DELETE, function(e) {
  3696. var $target = $(e.target);
  3697. var $chips = $target.closest(SELS.CHIPS);
  3698. var $chip = $target.closest(SELS.CHIP);
  3699. e.stopPropagation();
  3700. self.deleteChip($chip.index(), $chips);
  3701. $chips.find('input').focus();
  3702. });
  3703. };
  3704. this.chips = function($chips, chipId) {
  3705. $chips.empty();
  3706. $chips.data('chips').forEach(function(elem){
  3707. $chips.append(self.renderChip(elem));
  3708. });
  3709. $chips.append($('<input id="' + chipId +'" class="input" placeholder="">'));
  3710. self.setPlaceholder($chips);
  3711. // Set for attribute for label
  3712. var label = $chips.next('label');
  3713. if (label.length) {
  3714. label.attr('for', chipId);
  3715. if ($chips.data('chips')!== undefined && $chips.data('chips').length) {
  3716. label.addClass('active');
  3717. }
  3718. }
  3719. // Setup autocomplete if needed.
  3720. var input = $('#' + chipId);
  3721. if (self.hasAutocomplete) {
  3722. curr_options.autocompleteOptions.onAutocomplete = function(val) {
  3723. self.addChip({tag: val}, $chips);
  3724. input.val('');
  3725. input.focus();
  3726. }
  3727. input.autocomplete(curr_options.autocompleteOptions);
  3728. }
  3729. };
  3730. /**
  3731. * Render chip jQuery element.
  3732. * @param {Object} elem
  3733. * @return {jQuery}
  3734. */
  3735. this.renderChip = function(elem) {
  3736. if (!elem.tag) return;
  3737. var $renderedChip = $('<div class="chip"></div>');
  3738. $renderedChip.text(elem.tag);
  3739. if (elem.image) {
  3740. $renderedChip.prepend($('<img />').attr('src', elem.image))
  3741. }
  3742. $renderedChip.append($('<i class="material-icons close">close</i>'));
  3743. return $renderedChip;
  3744. };
  3745. this.setPlaceholder = function($chips) {
  3746. if ($chips.data('chips') !== undefined && $chips.data('chips').length && curr_options.placeholder) {
  3747. $chips.find('input').prop('placeholder', curr_options.placeholder);
  3748. } else if (($chips.data('chips') === undefined || !$chips.data('chips').length) && curr_options.secondaryPlaceholder) {
  3749. $chips.find('input').prop('placeholder', curr_options.secondaryPlaceholder);
  3750. }
  3751. };
  3752. this.isValid = function($chips, elem) {
  3753. var chips = $chips.data('chips');
  3754. var exists = false;
  3755. for (var i=0; i < chips.length; i++) {
  3756. if (chips[i].tag === elem.tag) {
  3757. exists = true;
  3758. return;
  3759. }
  3760. }
  3761. return '' !== elem.tag && !exists;
  3762. };
  3763. this.addChip = function(elem, $chips) {
  3764. if (!self.isValid($chips, elem)) {
  3765. return;
  3766. }
  3767. var $renderedChip = self.renderChip(elem);
  3768. var newData = [];
  3769. var oldData = $chips.data('chips');
  3770. for (var i = 0; i < oldData.length; i++) {
  3771. newData.push(oldData[i]);
  3772. }
  3773. newData.push(elem);
  3774. $chips.data('chips', newData);
  3775. $renderedChip.insertBefore($chips.find('input'));
  3776. $chips.trigger('chip.add', elem);
  3777. self.setPlaceholder($chips);
  3778. };
  3779. this.deleteChip = function(chipIndex, $chips) {
  3780. var chip = $chips.data('chips')[chipIndex];
  3781. $chips.find('.chip').eq(chipIndex).remove();
  3782. var newData = [];
  3783. var oldData = $chips.data('chips');
  3784. for (var i = 0; i < oldData.length; i++) {
  3785. if (i !== chipIndex) {
  3786. newData.push(oldData[i]);
  3787. }
  3788. }
  3789. $chips.data('chips', newData);
  3790. $chips.trigger('chip.delete', chip);
  3791. self.setPlaceholder($chips);
  3792. };
  3793. this.selectChip = function(chipIndex, $chips) {
  3794. var $chip = $chips.find('.chip').eq(chipIndex);
  3795. if ($chip && false === $chip.hasClass('selected')) {
  3796. $chip.addClass('selected');
  3797. $chips.trigger('chip.select', $chips.data('chips')[chipIndex]);
  3798. }
  3799. };
  3800. this.getChipsElement = function(index, $chips) {
  3801. return $chips.eq(index);
  3802. };
  3803. // init
  3804. this.init();
  3805. this.handleEvents();
  3806. };
  3807. }( jQuery ));
  3808. ;(function ($) {
  3809. $.fn.pushpin = function (options) {
  3810. // Defaults
  3811. var defaults = {
  3812. top: 0,
  3813. bottom: Infinity,
  3814. offset: 0
  3815. };
  3816. // Remove pushpin event and classes
  3817. if (options === "remove") {
  3818. this.each(function () {
  3819. if (id = $(this).data('pushpin-id')) {
  3820. $(window).off('scroll.' + id);
  3821. $(this).removeData('pushpin-id').removeClass('pin-top pinned pin-bottom').removeAttr('style');
  3822. }
  3823. });
  3824. return false;
  3825. }
  3826. options = $.extend(defaults, options);
  3827. $index = 0;
  3828. return this.each(function() {
  3829. var $uniqueId = Materialize.guid(),
  3830. $this = $(this),
  3831. $original_offset = $(this).offset().top;
  3832. function removePinClasses(object) {
  3833. object.removeClass('pin-top');
  3834. object.removeClass('pinned');
  3835. object.removeClass('pin-bottom');
  3836. }
  3837. function updateElements(objects, scrolled) {
  3838. objects.each(function () {
  3839. // Add position fixed (because its between top and bottom)
  3840. if (options.top <= scrolled && options.bottom >= scrolled && !$(this).hasClass('pinned')) {
  3841. removePinClasses($(this));
  3842. $(this).css('top', options.offset);
  3843. $(this).addClass('pinned');
  3844. }
  3845. // Add pin-top (when scrolled position is above top)
  3846. if (scrolled < options.top && !$(this).hasClass('pin-top')) {
  3847. removePinClasses($(this));
  3848. $(this).css('top', 0);
  3849. $(this).addClass('pin-top');
  3850. }
  3851. // Add pin-bottom (when scrolled position is below bottom)
  3852. if (scrolled > options.bottom && !$(this).hasClass('pin-bottom')) {
  3853. removePinClasses($(this));
  3854. $(this).addClass('pin-bottom');
  3855. $(this).css('top', options.bottom - $original_offset);
  3856. }
  3857. });
  3858. }
  3859. $(this).data('pushpin-id', $uniqueId);
  3860. updateElements($this, $(window).scrollTop());
  3861. $(window).on('scroll.' + $uniqueId, function () {
  3862. var $scrolled = $(window).scrollTop() + options.offset;
  3863. updateElements($this, $scrolled);
  3864. });
  3865. });
  3866. };
  3867. }( jQuery ));;(function ($) {
  3868. $(document).ready(function() {
  3869. // jQuery reverse
  3870. $.fn.reverse = [].reverse;
  3871. // Hover behaviour: make sure this doesn't work on .click-to-toggle FABs!
  3872. $(document).on('mouseenter.fixedActionBtn', '.fixed-action-btn:not(.click-to-toggle):not(.toolbar)', function(e) {
  3873. var $this = $(this);
  3874. openFABMenu($this);
  3875. });
  3876. $(document).on('mouseleave.fixedActionBtn', '.fixed-action-btn:not(.click-to-toggle):not(.toolbar)', function(e) {
  3877. var $this = $(this);
  3878. closeFABMenu($this);
  3879. });
  3880. // Toggle-on-click behaviour.
  3881. $(document).on('click.fabClickToggle', '.fixed-action-btn.click-to-toggle > a', function(e) {
  3882. var $this = $(this);
  3883. var $menu = $this.parent();
  3884. if ($menu.hasClass('active')) {
  3885. closeFABMenu($menu);
  3886. } else {
  3887. openFABMenu($menu);
  3888. }
  3889. });
  3890. // Toolbar transition behaviour.
  3891. $(document).on('click.fabToolbar', '.fixed-action-btn.toolbar > a', function(e) {
  3892. var $this = $(this);
  3893. var $menu = $this.parent();
  3894. FABtoToolbar($menu);
  3895. });
  3896. });
  3897. $.fn.extend({
  3898. openFAB: function() {
  3899. openFABMenu($(this));
  3900. },
  3901. closeFAB: function() {
  3902. closeFABMenu($(this));
  3903. },
  3904. openToolbar: function() {
  3905. FABtoToolbar($(this));
  3906. },
  3907. closeToolbar: function() {
  3908. toolbarToFAB($(this));
  3909. }
  3910. });
  3911. var openFABMenu = function (btn) {
  3912. var $this = btn;
  3913. if ($this.hasClass('active') === false) {
  3914. // Get direction option
  3915. var horizontal = $this.hasClass('horizontal');
  3916. var offsetY, offsetX;
  3917. if (horizontal === true) {
  3918. offsetX = 40;
  3919. } else {
  3920. offsetY = 40;
  3921. }
  3922. $this.addClass('active');
  3923. $this.find('ul .btn-floating').velocity(
  3924. { scaleY: ".4", scaleX: ".4", translateY: offsetY + 'px', translateX: offsetX + 'px'},
  3925. { duration: 0 });
  3926. var time = 0;
  3927. $this.find('ul .btn-floating').reverse().each( function () {
  3928. $(this).velocity(
  3929. { opacity: "1", scaleX: "1", scaleY: "1", translateY: "0", translateX: '0'},
  3930. { duration: 80, delay: time });
  3931. time += 40;
  3932. });
  3933. }
  3934. };
  3935. var closeFABMenu = function (btn) {
  3936. var $this = btn;
  3937. // Get direction option
  3938. var horizontal = $this.hasClass('horizontal');
  3939. var offsetY, offsetX;
  3940. if (horizontal === true) {
  3941. offsetX = 40;
  3942. } else {
  3943. offsetY = 40;
  3944. }
  3945. $this.removeClass('active');
  3946. var time = 0;
  3947. $this.find('ul .btn-floating').velocity("stop", true);
  3948. $this.find('ul .btn-floating').velocity(
  3949. { opacity: "0", scaleX: ".4", scaleY: ".4", translateY: offsetY + 'px', translateX: offsetX + 'px'},
  3950. { duration: 80 }
  3951. );
  3952. };
  3953. /**
  3954. * Transform FAB into toolbar
  3955. * @param {Object} object jQuery object
  3956. */
  3957. var FABtoToolbar = function(btn) {
  3958. if (btn.attr('data-open') === "true") {
  3959. return;
  3960. }
  3961. var offsetX, offsetY, scaleFactor;
  3962. var windowWidth = window.innerWidth;
  3963. var windowHeight = window.innerHeight;
  3964. var btnRect = btn[0].getBoundingClientRect();
  3965. var anchor = btn.find('> a').first();
  3966. var menu = btn.find('> ul').first();
  3967. var backdrop = $('<div class="fab-backdrop"></div>');
  3968. var fabColor = anchor.css('background-color');
  3969. anchor.append(backdrop);
  3970. offsetX = btnRect.left - (windowWidth / 2) + (btnRect.width / 2);
  3971. offsetY = windowHeight - btnRect.bottom;
  3972. scaleFactor = windowWidth / backdrop.width();
  3973. btn.attr('data-origin-bottom', btnRect.bottom);
  3974. btn.attr('data-origin-left', btnRect.left);
  3975. btn.attr('data-origin-width', btnRect.width);
  3976. // Set initial state
  3977. btn.addClass('active');
  3978. btn.attr('data-open', true);
  3979. btn.css({
  3980. 'text-align': 'center',
  3981. width: '100%',
  3982. bottom: 0,
  3983. left: 0,
  3984. transform: 'translateX(' + offsetX + 'px)',
  3985. transition: 'none'
  3986. });
  3987. anchor.css({
  3988. transform: 'translateY(' + -offsetY + 'px)',
  3989. transition: 'none'
  3990. });
  3991. backdrop.css({
  3992. 'background-color': fabColor
  3993. });
  3994. setTimeout(function() {
  3995. btn.css({
  3996. transform: '',
  3997. transition: 'transform .2s cubic-bezier(0.550, 0.085, 0.680, 0.530), background-color 0s linear .2s'
  3998. });
  3999. anchor.css({
  4000. overflow: 'visible',
  4001. transform: '',
  4002. transition: 'transform .2s'
  4003. });
  4004. setTimeout(function() {
  4005. btn.css({
  4006. overflow: 'hidden',
  4007. 'background-color': fabColor
  4008. });
  4009. backdrop.css({
  4010. transform: 'scale(' + scaleFactor + ')',
  4011. transition: 'transform .2s cubic-bezier(0.550, 0.055, 0.675, 0.190)'
  4012. });
  4013. menu.find('> li > a').css({
  4014. opacity: 1
  4015. });
  4016. // Scroll to close.
  4017. $(window).on('scroll.fabToolbarClose', function() {
  4018. toolbarToFAB(btn);
  4019. $(window).off('scroll.fabToolbarClose');
  4020. $(document).off('click.fabToolbarClose');
  4021. });
  4022. $(document).on('click.fabToolbarClose', function(e) {
  4023. if (!$(e.target).closest(menu).length) {
  4024. toolbarToFAB(btn);
  4025. $(window).off('scroll.fabToolbarClose');
  4026. $(document).off('click.fabToolbarClose');
  4027. }
  4028. });
  4029. }, 100);
  4030. }, 0);
  4031. };
  4032. /**
  4033. * Transform toolbar back into FAB
  4034. * @param {Object} object jQuery object
  4035. */
  4036. var toolbarToFAB = function(btn) {
  4037. if (btn.attr('data-open') !== "true") {
  4038. return;
  4039. }
  4040. var offsetX, offsetY, scaleFactor;
  4041. var windowWidth = window.innerWidth;
  4042. var windowHeight = window.innerHeight;
  4043. var btnWidth = btn.attr('data-origin-width');
  4044. var btnBottom = btn.attr('data-origin-bottom');
  4045. var btnLeft = btn.attr('data-origin-left');
  4046. var anchor = btn.find('> .btn-floating').first();
  4047. var menu = btn.find('> ul').first();
  4048. var backdrop = btn.find('.fab-backdrop');
  4049. var fabColor = anchor.css('background-color');
  4050. offsetX = btnLeft - (windowWidth / 2) + (btnWidth / 2);
  4051. offsetY = windowHeight - btnBottom;
  4052. scaleFactor = windowWidth / backdrop.width();
  4053. // Hide backdrop
  4054. btn.removeClass('active');
  4055. btn.attr('data-open', false);
  4056. btn.css({
  4057. 'background-color': 'transparent',
  4058. transition: 'none'
  4059. });
  4060. anchor.css({
  4061. transition: 'none'
  4062. });
  4063. backdrop.css({
  4064. transform: 'scale(0)',
  4065. 'background-color': fabColor
  4066. });
  4067. menu.find('> li > a').css({
  4068. opacity: ''
  4069. });
  4070. setTimeout(function() {
  4071. backdrop.remove();
  4072. // Set initial state.
  4073. btn.css({
  4074. 'text-align': '',
  4075. width: '',
  4076. bottom: '',
  4077. left: '',
  4078. overflow: '',
  4079. 'background-color': '',
  4080. transform: 'translate3d(' + -offsetX + 'px,0,0)'
  4081. });
  4082. anchor.css({
  4083. overflow: '',
  4084. transform: 'translate3d(0,' + offsetY + 'px,0)'
  4085. });
  4086. setTimeout(function() {
  4087. btn.css({
  4088. transform: 'translate3d(0,0,0)',
  4089. transition: 'transform .2s'
  4090. });
  4091. anchor.css({
  4092. transform: 'translate3d(0,0,0)',
  4093. transition: 'transform .2s cubic-bezier(0.550, 0.055, 0.675, 0.190)'
  4094. });
  4095. }, 20);
  4096. }, 200);
  4097. };
  4098. }( jQuery ));
  4099. ;(function ($) {
  4100. // Image transition function
  4101. Materialize.fadeInImage = function(selectorOrEl) {
  4102. var element;
  4103. if (typeof(selectorOrEl) === 'string') {
  4104. element = $(selectorOrEl);
  4105. } else if (typeof(selectorOrEl) === 'object') {
  4106. element = selectorOrEl;
  4107. } else {
  4108. return;
  4109. }
  4110. element.css({opacity: 0});
  4111. $(element).velocity({opacity: 1}, {
  4112. duration: 650,
  4113. queue: false,
  4114. easing: 'easeOutSine'
  4115. });
  4116. $(element).velocity({opacity: 1}, {
  4117. duration: 1300,
  4118. queue: false,
  4119. easing: 'swing',
  4120. step: function(now, fx) {
  4121. fx.start = 100;
  4122. var grayscale_setting = now/100;
  4123. var brightness_setting = 150 - (100 - now)/1.75;
  4124. if (brightness_setting < 100) {
  4125. brightness_setting = 100;
  4126. }
  4127. if (now >= 0) {
  4128. $(this).css({
  4129. "-webkit-filter": "grayscale("+grayscale_setting+")" + "brightness("+brightness_setting+"%)",
  4130. "filter": "grayscale("+grayscale_setting+")" + "brightness("+brightness_setting+"%)"
  4131. });
  4132. }
  4133. }
  4134. });
  4135. };
  4136. // Horizontal staggered list
  4137. Materialize.showStaggeredList = function(selectorOrEl) {
  4138. var element;
  4139. if (typeof(selectorOrEl) === 'string') {
  4140. element = $(selectorOrEl);
  4141. } else if (typeof(selectorOrEl) === 'object') {
  4142. element = selectorOrEl;
  4143. } else {
  4144. return;
  4145. }
  4146. var time = 0;
  4147. element.find('li').velocity(
  4148. { translateX: "-100px"},
  4149. { duration: 0 });
  4150. element.find('li').each(function() {
  4151. $(this).velocity(
  4152. { opacity: "1", translateX: "0"},
  4153. { duration: 800, delay: time, easing: [60, 10] });
  4154. time += 120;
  4155. });
  4156. };
  4157. $(document).ready(function() {
  4158. // Hardcoded .staggered-list scrollFire
  4159. // var staggeredListOptions = [];
  4160. // $('ul.staggered-list').each(function (i) {
  4161. // var label = 'scrollFire-' + i;
  4162. // $(this).addClass(label);
  4163. // staggeredListOptions.push(
  4164. // {selector: 'ul.staggered-list.' + label,
  4165. // offset: 200,
  4166. // callback: 'showStaggeredList("ul.staggered-list.' + label + '")'});
  4167. // });
  4168. // scrollFire(staggeredListOptions);
  4169. // HammerJS, Swipe navigation
  4170. // Touch Event
  4171. var swipeLeft = false;
  4172. var swipeRight = false;
  4173. // Dismissible Collections
  4174. $('.dismissable').each(function() {
  4175. $(this).hammer({
  4176. prevent_default: false
  4177. }).on('pan', function(e) {
  4178. if (e.gesture.pointerType === "touch") {
  4179. var $this = $(this);
  4180. var direction = e.gesture.direction;
  4181. var x = e.gesture.deltaX;
  4182. var velocityX = e.gesture.velocityX;
  4183. $this.velocity({ translateX: x
  4184. }, {duration: 50, queue: false, easing: 'easeOutQuad'});
  4185. // Swipe Left
  4186. if (direction === 4 && (x > ($this.innerWidth() / 2) || velocityX < -0.75)) {
  4187. swipeLeft = true;
  4188. }
  4189. // Swipe Right
  4190. if (direction === 2 && (x < (-1 * $this.innerWidth() / 2) || velocityX > 0.75)) {
  4191. swipeRight = true;
  4192. }
  4193. }
  4194. }).on('panend', function(e) {
  4195. // Reset if collection is moved back into original position
  4196. if (Math.abs(e.gesture.deltaX) < ($(this).innerWidth() / 2)) {
  4197. swipeRight = false;
  4198. swipeLeft = false;
  4199. }
  4200. if (e.gesture.pointerType === "touch") {
  4201. var $this = $(this);
  4202. if (swipeLeft || swipeRight) {
  4203. var fullWidth;
  4204. if (swipeLeft) { fullWidth = $this.innerWidth(); }
  4205. else { fullWidth = -1 * $this.innerWidth(); }
  4206. $this.velocity({ translateX: fullWidth,
  4207. }, {duration: 100, queue: false, easing: 'easeOutQuad', complete:
  4208. function() {
  4209. $this.css('border', 'none');
  4210. $this.velocity({ height: 0, padding: 0,
  4211. }, {duration: 200, queue: false, easing: 'easeOutQuad', complete:
  4212. function() { $this.remove(); }
  4213. });
  4214. }
  4215. });
  4216. }
  4217. else {
  4218. $this.velocity({ translateX: 0,
  4219. }, {duration: 100, queue: false, easing: 'easeOutQuad'});
  4220. }
  4221. swipeLeft = false;
  4222. swipeRight = false;
  4223. }
  4224. });
  4225. });
  4226. // time = 0
  4227. // // Vertical Staggered list
  4228. // $('ul.staggered-list.vertical li').velocity(
  4229. // { translateY: "100px"},
  4230. // { duration: 0 });
  4231. // $('ul.staggered-list.vertical li').each(function() {
  4232. // $(this).velocity(
  4233. // { opacity: "1", translateY: "0"},
  4234. // { duration: 800, delay: time, easing: [60, 25] });
  4235. // time += 120;
  4236. // });
  4237. // // Fade in and Scale
  4238. // $('.fade-in.scale').velocity(
  4239. // { scaleX: .4, scaleY: .4, translateX: -600},
  4240. // { duration: 0});
  4241. // $('.fade-in').each(function() {
  4242. // $(this).velocity(
  4243. // { opacity: "1", scaleX: 1, scaleY: 1, translateX: 0},
  4244. // { duration: 800, easing: [60, 10] });
  4245. // });
  4246. });
  4247. }( jQuery ));
  4248. ;(function($) {
  4249. var scrollFireEventsHandled = false;
  4250. // Input: Array of JSON objects {selector, offset, callback}
  4251. Materialize.scrollFire = function(options) {
  4252. var onScroll = function() {
  4253. var windowScroll = window.pageYOffset + window.innerHeight;
  4254. for (var i = 0 ; i < options.length; i++) {
  4255. // Get options from each line
  4256. var value = options[i];
  4257. var selector = value.selector,
  4258. offset = value.offset,
  4259. callback = value.callback;
  4260. var currentElement = document.querySelector(selector);
  4261. if ( currentElement !== null) {
  4262. var elementOffset = currentElement.getBoundingClientRect().top + window.pageYOffset;
  4263. if (windowScroll > (elementOffset + offset)) {
  4264. if (value.done !== true) {
  4265. if (typeof(callback) === 'function') {
  4266. callback.call(this, currentElement);
  4267. } else if (typeof(callback) === 'string') {
  4268. var callbackFunc = new Function(callback);
  4269. callbackFunc(currentElement);
  4270. }
  4271. value.done = true;
  4272. }
  4273. }
  4274. }
  4275. }
  4276. };
  4277. var throttledScroll = Materialize.throttle(function() {
  4278. onScroll();
  4279. }, options.throttle || 100);
  4280. if (!scrollFireEventsHandled) {
  4281. window.addEventListener("scroll", throttledScroll);
  4282. window.addEventListener("resize", throttledScroll);
  4283. scrollFireEventsHandled = true;
  4284. }
  4285. // perform a scan once, after current execution context, and after dom is ready
  4286. setTimeout(throttledScroll, 0);
  4287. };
  4288. })(jQuery);
  4289. ;/*!
  4290. * pickadate.js v3.5.0, 2014/04/13
  4291. * By Amsul, http://amsul.ca
  4292. * Hosted on http://amsul.github.io/pickadate.js
  4293. * Licensed under MIT
  4294. */
  4295. (function ( factory ) {
  4296. // AMD.
  4297. if ( typeof define == 'function' && define.amd )
  4298. define( 'picker', ['jquery'], factory )
  4299. // Node.js/browserify.
  4300. else if ( typeof exports == 'object' )
  4301. module.exports = factory( require('jquery') )
  4302. // Browser globals.
  4303. else this.Picker = factory( jQuery )
  4304. }(function( $ ) {
  4305. var $window = $( window )
  4306. var $document = $( document )
  4307. var $html = $( document.documentElement )
  4308. /**
  4309. * The picker constructor that creates a blank picker.
  4310. */
  4311. function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
  4312. // If there’s no element, return the picker constructor.
  4313. if ( !ELEMENT ) return PickerConstructor
  4314. var
  4315. IS_DEFAULT_THEME = false,
  4316. // The state of the picker.
  4317. STATE = {
  4318. id: ELEMENT.id || 'P' + Math.abs( ~~(Math.random() * new Date()) )
  4319. },
  4320. // Merge the defaults and options passed.
  4321. SETTINGS = COMPONENT ? $.extend( true, {}, COMPONENT.defaults, OPTIONS ) : OPTIONS || {},
  4322. // Merge the default classes with the settings classes.
  4323. CLASSES = $.extend( {}, PickerConstructor.klasses(), SETTINGS.klass ),
  4324. // The element node wrapper into a jQuery object.
  4325. $ELEMENT = $( ELEMENT ),
  4326. // Pseudo picker constructor.
  4327. PickerInstance = function() {
  4328. return this.start()
  4329. },
  4330. // The picker prototype.
  4331. P = PickerInstance.prototype = {
  4332. constructor: PickerInstance,
  4333. $node: $ELEMENT,
  4334. /**
  4335. * Initialize everything
  4336. */
  4337. start: function() {
  4338. // If it’s already started, do nothing.
  4339. if ( STATE && STATE.start ) return P
  4340. // Update the picker states.
  4341. STATE.methods = {}
  4342. STATE.start = true
  4343. STATE.open = false
  4344. STATE.type = ELEMENT.type
  4345. // Confirm focus state, convert into text input to remove UA stylings,
  4346. // and set as readonly to prevent keyboard popup.
  4347. ELEMENT.autofocus = ELEMENT == getActiveElement()
  4348. ELEMENT.readOnly = !SETTINGS.editable
  4349. ELEMENT.id = ELEMENT.id || STATE.id
  4350. if ( ELEMENT.type != 'text' ) {
  4351. ELEMENT.type = 'text'
  4352. }
  4353. // Create a new picker component with the settings.
  4354. P.component = new COMPONENT(P, SETTINGS)
  4355. // Create the picker root with a holder and then prepare it.
  4356. P.$root = $( PickerConstructor._.node('div', createWrappedComponent(), CLASSES.picker, 'id="' + ELEMENT.id + '_root" tabindex="0"') )
  4357. prepareElementRoot()
  4358. // If there’s a format for the hidden input element, create the element.
  4359. if ( SETTINGS.formatSubmit ) {
  4360. prepareElementHidden()
  4361. }
  4362. // Prepare the input element.
  4363. prepareElement()
  4364. // Insert the root as specified in the settings.
  4365. if ( SETTINGS.container ) $( SETTINGS.container ).append( P.$root )
  4366. else $ELEMENT.after( P.$root )
  4367. // Bind the default component and settings events.
  4368. P.on({
  4369. start: P.component.onStart,
  4370. render: P.component.onRender,
  4371. stop: P.component.onStop,
  4372. open: P.component.onOpen,
  4373. close: P.component.onClose,
  4374. set: P.component.onSet
  4375. }).on({
  4376. start: SETTINGS.onStart,
  4377. render: SETTINGS.onRender,
  4378. stop: SETTINGS.onStop,
  4379. open: SETTINGS.onOpen,
  4380. close: SETTINGS.onClose,
  4381. set: SETTINGS.onSet
  4382. })
  4383. // Once we’re all set, check the theme in use.
  4384. IS_DEFAULT_THEME = isUsingDefaultTheme( P.$root.children()[ 0 ] )
  4385. // If the element has autofocus, open the picker.
  4386. if ( ELEMENT.autofocus ) {
  4387. P.open()
  4388. }
  4389. // Trigger queued the “start” and “render” events.
  4390. return P.trigger( 'start' ).trigger( 'render' )
  4391. }, //start
  4392. /**
  4393. * Render a new picker
  4394. */
  4395. render: function( entireComponent ) {
  4396. // Insert a new component holder in the root or box.
  4397. if ( entireComponent ) P.$root.html( createWrappedComponent() )
  4398. else P.$root.find( '.' + CLASSES.box ).html( P.component.nodes( STATE.open ) )
  4399. // Trigger the queued “render” events.
  4400. return P.trigger( 'render' )
  4401. }, //render
  4402. /**
  4403. * Destroy everything
  4404. */
  4405. stop: function() {
  4406. // If it’s already stopped, do nothing.
  4407. if ( !STATE.start ) return P
  4408. // Then close the picker.
  4409. P.close()
  4410. // Remove the hidden field.
  4411. if ( P._hidden ) {
  4412. P._hidden.parentNode.removeChild( P._hidden )
  4413. }
  4414. // Remove the root.
  4415. P.$root.remove()
  4416. // Remove the input class, remove the stored data, and unbind
  4417. // the events (after a tick for IE - see `P.close`).
  4418. $ELEMENT.removeClass( CLASSES.input ).removeData( NAME )
  4419. setTimeout( function() {
  4420. $ELEMENT.off( '.' + STATE.id )
  4421. }, 0)
  4422. // Restore the element state
  4423. ELEMENT.type = STATE.type
  4424. ELEMENT.readOnly = false
  4425. // Trigger the queued “stop” events.
  4426. P.trigger( 'stop' )
  4427. // Reset the picker states.
  4428. STATE.methods = {}
  4429. STATE.start = false
  4430. return P
  4431. }, //stop
  4432. /**
  4433. * Open up the picker
  4434. */
  4435. open: function( dontGiveFocus ) {
  4436. // If it’s already open, do nothing.
  4437. if ( STATE.open ) return P
  4438. // Add the “active” class.
  4439. $ELEMENT.addClass( CLASSES.active )
  4440. aria( ELEMENT, 'expanded', true )
  4441. // * A Firefox bug, when `html` has `overflow:hidden`, results in
  4442. // killing transitions :(. So add the “opened” state on the next tick.
  4443. // Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=625289
  4444. setTimeout( function() {
  4445. // Add the “opened” class to the picker root.
  4446. P.$root.addClass( CLASSES.opened )
  4447. aria( P.$root[0], 'hidden', false )
  4448. }, 0 )
  4449. // If we have to give focus, bind the element and doc events.
  4450. if ( dontGiveFocus !== false ) {
  4451. // Set it as open.
  4452. STATE.open = true
  4453. // Prevent the page from scrolling.
  4454. if ( IS_DEFAULT_THEME ) {
  4455. $html.
  4456. css( 'overflow', 'hidden' ).
  4457. css( 'padding-right', '+=' + getScrollbarWidth() )
  4458. }
  4459. // Pass focus to the root element’s jQuery object.
  4460. // * Workaround for iOS8 to bring the picker’s root into view.
  4461. P.$root.eq(0).focus()
  4462. // Bind the document events.
  4463. $document.on( 'click.' + STATE.id + ' focusin.' + STATE.id, function( event ) {
  4464. var target = event.target
  4465. // If the target of the event is not the element, close the picker picker.
  4466. // * Don’t worry about clicks or focusins on the root because those don’t bubble up.
  4467. // Also, for Firefox, a click on an `option` element bubbles up directly
  4468. // to the doc. So make sure the target wasn't the doc.
  4469. // * In Firefox stopPropagation() doesn’t prevent right-click events from bubbling,
  4470. // which causes the picker to unexpectedly close when right-clicking it. So make
  4471. // sure the event wasn’t a right-click.
  4472. if ( target != ELEMENT && target != document && event.which != 3 ) {
  4473. // If the target was the holder that covers the screen,
  4474. // keep the element focused to maintain tabindex.
  4475. P.close( target === P.$root.children()[0] )
  4476. }
  4477. }).on( 'keydown.' + STATE.id, function( event ) {
  4478. var
  4479. // Get the keycode.
  4480. keycode = event.keyCode,
  4481. // Translate that to a selection change.
  4482. keycodeToMove = P.component.key[ keycode ],
  4483. // Grab the target.
  4484. target = event.target
  4485. // On escape, close the picker and give focus.
  4486. if ( keycode == 27 ) {
  4487. P.close( true )
  4488. }
  4489. // Check if there is a key movement or “enter” keypress on the element.
  4490. else if ( target == P.$root[0] && ( keycodeToMove || keycode == 13 ) ) {
  4491. // Prevent the default action to stop page movement.
  4492. event.preventDefault()
  4493. // Trigger the key movement action.
  4494. if ( keycodeToMove ) {
  4495. PickerConstructor._.trigger( P.component.key.go, P, [ PickerConstructor._.trigger( keycodeToMove ) ] )
  4496. }
  4497. // On “enter”, if the highlighted item isn’t disabled, set the value and close.
  4498. else if ( !P.$root.find( '.' + CLASSES.highlighted ).hasClass( CLASSES.disabled ) ) {
  4499. P.set( 'select', P.component.item.highlight ).close()
  4500. }
  4501. }
  4502. // If the target is within the root and “enter” is pressed,
  4503. // prevent the default action and trigger a click on the target instead.
  4504. else if ( $.contains( P.$root[0], target ) && keycode == 13 ) {
  4505. event.preventDefault()
  4506. target.click()
  4507. }
  4508. })
  4509. }
  4510. // Trigger the queued “open” events.
  4511. return P.trigger( 'open' )
  4512. }, //open
  4513. /**
  4514. * Close the picker
  4515. */
  4516. close: function( giveFocus ) {
  4517. // If we need to give focus, do it before changing states.
  4518. if ( giveFocus ) {
  4519. // ....ah yes! It would’ve been incomplete without a crazy workaround for IE :|
  4520. // The focus is triggered *after* the close has completed - causing it
  4521. // to open again. So unbind and rebind the event at the next tick.
  4522. P.$root.off( 'focus.toOpen' ).eq(0).focus()
  4523. setTimeout( function() {
  4524. P.$root.on( 'focus.toOpen', handleFocusToOpenEvent )
  4525. }, 0 )
  4526. }
  4527. // Remove the “active” class.
  4528. $ELEMENT.removeClass( CLASSES.active )
  4529. aria( ELEMENT, 'expanded', false )
  4530. // * A Firefox bug, when `html` has `overflow:hidden`, results in
  4531. // killing transitions :(. So remove the “opened” state on the next tick.
  4532. // Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=625289
  4533. setTimeout( function() {
  4534. // Remove the “opened” and “focused” class from the picker root.
  4535. P.$root.removeClass( CLASSES.opened + ' ' + CLASSES.focused )
  4536. aria( P.$root[0], 'hidden', true )
  4537. }, 0 )
  4538. // If it’s already closed, do nothing more.
  4539. if ( !STATE.open ) return P
  4540. // Set it as closed.
  4541. STATE.open = false
  4542. // Allow the page to scroll.
  4543. if ( IS_DEFAULT_THEME ) {
  4544. $html.
  4545. css( 'overflow', '' ).
  4546. css( 'padding-right', '-=' + getScrollbarWidth() )
  4547. }
  4548. // Unbind the document events.
  4549. $document.off( '.' + STATE.id )
  4550. // Trigger the queued “close” events.
  4551. return P.trigger( 'close' )
  4552. }, //close
  4553. /**
  4554. * Clear the values
  4555. */
  4556. clear: function( options ) {
  4557. return P.set( 'clear', null, options )
  4558. }, //clear
  4559. /**
  4560. * Set something
  4561. */
  4562. set: function( thing, value, options ) {
  4563. var thingItem, thingValue,
  4564. thingIsObject = $.isPlainObject( thing ),
  4565. thingObject = thingIsObject ? thing : {}
  4566. // Make sure we have usable options.
  4567. options = thingIsObject && $.isPlainObject( value ) ? value : options || {}
  4568. if ( thing ) {
  4569. // If the thing isn’t an object, make it one.
  4570. if ( !thingIsObject ) {
  4571. thingObject[ thing ] = value
  4572. }
  4573. // Go through the things of items to set.
  4574. for ( thingItem in thingObject ) {
  4575. // Grab the value of the thing.
  4576. thingValue = thingObject[ thingItem ]
  4577. // First, if the item exists and there’s a value, set it.
  4578. if ( thingItem in P.component.item ) {
  4579. if ( thingValue === undefined ) thingValue = null
  4580. P.component.set( thingItem, thingValue, options )
  4581. }
  4582. // Then, check to update the element value and broadcast a change.
  4583. if ( thingItem == 'select' || thingItem == 'clear' ) {
  4584. $ELEMENT.
  4585. val( thingItem == 'clear' ? '' : P.get( thingItem, SETTINGS.format ) ).
  4586. trigger( 'change' )
  4587. }
  4588. }
  4589. // Render a new picker.
  4590. P.render()
  4591. }
  4592. // When the method isn’t muted, trigger queued “set” events and pass the `thingObject`.
  4593. return options.muted ? P : P.trigger( 'set', thingObject )
  4594. }, //set
  4595. /**
  4596. * Get something
  4597. */
  4598. get: function( thing, format ) {
  4599. // Make sure there’s something to get.
  4600. thing = thing || 'value'
  4601. // If a picker state exists, return that.
  4602. if ( STATE[ thing ] != null ) {
  4603. return STATE[ thing ]
  4604. }
  4605. // Return the submission value, if that.
  4606. if ( thing == 'valueSubmit' ) {
  4607. if ( P._hidden ) {
  4608. return P._hidden.value
  4609. }
  4610. thing = 'value'
  4611. }
  4612. // Return the value, if that.
  4613. if ( thing == 'value' ) {
  4614. return ELEMENT.value
  4615. }
  4616. // Check if a component item exists, return that.
  4617. if ( thing in P.component.item ) {
  4618. if ( typeof format == 'string' ) {
  4619. var thingValue = P.component.get( thing )
  4620. return thingValue ?
  4621. PickerConstructor._.trigger(
  4622. P.component.formats.toString,
  4623. P.component,
  4624. [ format, thingValue ]
  4625. ) : ''
  4626. }
  4627. return P.component.get( thing )
  4628. }
  4629. }, //get
  4630. /**
  4631. * Bind events on the things.
  4632. */
  4633. on: function( thing, method, internal ) {
  4634. var thingName, thingMethod,
  4635. thingIsObject = $.isPlainObject( thing ),
  4636. thingObject = thingIsObject ? thing : {}
  4637. if ( thing ) {
  4638. // If the thing isn’t an object, make it one.
  4639. if ( !thingIsObject ) {
  4640. thingObject[ thing ] = method
  4641. }
  4642. // Go through the things to bind to.
  4643. for ( thingName in thingObject ) {
  4644. // Grab the method of the thing.
  4645. thingMethod = thingObject[ thingName ]
  4646. // If it was an internal binding, prefix it.
  4647. if ( internal ) {
  4648. thingName = '_' + thingName
  4649. }
  4650. // Make sure the thing methods collection exists.
  4651. STATE.methods[ thingName ] = STATE.methods[ thingName ] || []
  4652. // Add the method to the relative method collection.
  4653. STATE.methods[ thingName ].push( thingMethod )
  4654. }
  4655. }
  4656. return P
  4657. }, //on
  4658. /**
  4659. * Unbind events on the things.
  4660. */
  4661. off: function() {
  4662. var i, thingName,
  4663. names = arguments;
  4664. for ( i = 0, namesCount = names.length; i < namesCount; i += 1 ) {
  4665. thingName = names[i]
  4666. if ( thingName in STATE.methods ) {
  4667. delete STATE.methods[thingName]
  4668. }
  4669. }
  4670. return P
  4671. },
  4672. /**
  4673. * Fire off method events.
  4674. */
  4675. trigger: function( name, data ) {
  4676. var _trigger = function( name ) {
  4677. var methodList = STATE.methods[ name ]
  4678. if ( methodList ) {
  4679. methodList.map( function( method ) {
  4680. PickerConstructor._.trigger( method, P, [ data ] )
  4681. })
  4682. }
  4683. }
  4684. _trigger( '_' + name )
  4685. _trigger( name )
  4686. return P
  4687. } //trigger
  4688. } //PickerInstance.prototype
  4689. /**
  4690. * Wrap the picker holder components together.
  4691. */
  4692. function createWrappedComponent() {
  4693. // Create a picker wrapper holder
  4694. return PickerConstructor._.node( 'div',
  4695. // Create a picker wrapper node
  4696. PickerConstructor._.node( 'div',
  4697. // Create a picker frame
  4698. PickerConstructor._.node( 'div',
  4699. // Create a picker box node
  4700. PickerConstructor._.node( 'div',
  4701. // Create the components nodes.
  4702. P.component.nodes( STATE.open ),
  4703. // The picker box class
  4704. CLASSES.box
  4705. ),
  4706. // Picker wrap class
  4707. CLASSES.wrap
  4708. ),
  4709. // Picker frame class
  4710. CLASSES.frame
  4711. ),
  4712. // Picker holder class
  4713. CLASSES.holder
  4714. ) //endreturn
  4715. } //createWrappedComponent
  4716. /**
  4717. * Prepare the input element with all bindings.
  4718. */
  4719. function prepareElement() {
  4720. $ELEMENT.
  4721. // Store the picker data by component name.
  4722. data(NAME, P).
  4723. // Add the “input” class name.
  4724. addClass(CLASSES.input).
  4725. // Remove the tabindex.
  4726. attr('tabindex', -1).
  4727. // If there’s a `data-value`, update the value of the element.
  4728. val( $ELEMENT.data('value') ?
  4729. P.get('select', SETTINGS.format) :
  4730. ELEMENT.value
  4731. )
  4732. // Only bind keydown events if the element isn’t editable.
  4733. if ( !SETTINGS.editable ) {
  4734. $ELEMENT.
  4735. // On focus/click, focus onto the root to open it up.
  4736. on( 'focus.' + STATE.id + ' click.' + STATE.id, function( event ) {
  4737. event.preventDefault()
  4738. P.$root.eq(0).focus()
  4739. }).
  4740. // Handle keyboard event based on the picker being opened or not.
  4741. on( 'keydown.' + STATE.id, handleKeydownEvent )
  4742. }
  4743. // Update the aria attributes.
  4744. aria(ELEMENT, {
  4745. haspopup: true,
  4746. expanded: false,
  4747. readonly: false,
  4748. owns: ELEMENT.id + '_root'
  4749. })
  4750. }
  4751. /**
  4752. * Prepare the root picker element with all bindings.
  4753. */
  4754. function prepareElementRoot() {
  4755. P.$root.
  4756. on({
  4757. // For iOS8.
  4758. keydown: handleKeydownEvent,
  4759. // When something within the root is focused, stop from bubbling
  4760. // to the doc and remove the “focused” state from the root.
  4761. focusin: function( event ) {
  4762. P.$root.removeClass( CLASSES.focused )
  4763. event.stopPropagation()
  4764. },
  4765. // When something within the root holder is clicked, stop it
  4766. // from bubbling to the doc.
  4767. 'mousedown click': function( event ) {
  4768. var target = event.target
  4769. // Make sure the target isn’t the root holder so it can bubble up.
  4770. if ( target != P.$root.children()[ 0 ] ) {
  4771. event.stopPropagation()
  4772. // * For mousedown events, cancel the default action in order to
  4773. // prevent cases where focus is shifted onto external elements
  4774. // when using things like jQuery mobile or MagnificPopup (ref: #249 & #120).
  4775. // Also, for Firefox, don’t prevent action on the `option` element.
  4776. if ( event.type == 'mousedown' && !$( target ).is( 'input, select, textarea, button, option' )) {
  4777. event.preventDefault()
  4778. // Re-focus onto the root so that users can click away
  4779. // from elements focused within the picker.
  4780. P.$root.eq(0).focus()
  4781. }
  4782. }
  4783. }
  4784. }).
  4785. // Add/remove the “target” class on focus and blur.
  4786. on({
  4787. focus: function() {
  4788. $ELEMENT.addClass( CLASSES.target )
  4789. },
  4790. blur: function() {
  4791. $ELEMENT.removeClass( CLASSES.target )
  4792. }
  4793. }).
  4794. // Open the picker and adjust the root “focused” state
  4795. on( 'focus.toOpen', handleFocusToOpenEvent ).
  4796. // If there’s a click on an actionable element, carry out the actions.
  4797. on( 'click', '[data-pick], [data-nav], [data-clear], [data-close]', function() {
  4798. var $target = $( this ),
  4799. targetData = $target.data(),
  4800. targetDisabled = $target.hasClass( CLASSES.navDisabled ) || $target.hasClass( CLASSES.disabled ),
  4801. // * For IE, non-focusable elements can be active elements as well
  4802. // (http://stackoverflow.com/a/2684561).
  4803. activeElement = getActiveElement()
  4804. activeElement = activeElement && ( activeElement.type || activeElement.href )
  4805. // If it’s disabled or nothing inside is actively focused, re-focus the element.
  4806. if ( targetDisabled || activeElement && !$.contains( P.$root[0], activeElement ) ) {
  4807. P.$root.eq(0).focus()
  4808. }
  4809. // If something is superficially changed, update the `highlight` based on the `nav`.
  4810. if ( !targetDisabled && targetData.nav ) {
  4811. P.set( 'highlight', P.component.item.highlight, { nav: targetData.nav } )
  4812. }
  4813. // If something is picked, set `select` then close with focus.
  4814. else if ( !targetDisabled && 'pick' in targetData ) {
  4815. P.set( 'select', targetData.pick )
  4816. }
  4817. // If a “clear” button is pressed, empty the values and close with focus.
  4818. else if ( targetData.clear ) {
  4819. P.clear().close( true )
  4820. }
  4821. else if ( targetData.close ) {
  4822. P.close( true )
  4823. }
  4824. }) //P.$root
  4825. aria( P.$root[0], 'hidden', true )
  4826. }
  4827. /**
  4828. * Prepare the hidden input element along with all bindings.
  4829. */
  4830. function prepareElementHidden() {
  4831. var name
  4832. if ( SETTINGS.hiddenName === true ) {
  4833. name = ELEMENT.name
  4834. ELEMENT.name = ''
  4835. }
  4836. else {
  4837. name = [
  4838. typeof SETTINGS.hiddenPrefix == 'string' ? SETTINGS.hiddenPrefix : '',
  4839. typeof SETTINGS.hiddenSuffix == 'string' ? SETTINGS.hiddenSuffix : '_submit'
  4840. ]
  4841. name = name[0] + ELEMENT.name + name[1]
  4842. }
  4843. P._hidden = $(
  4844. '<input ' +
  4845. 'type=hidden ' +
  4846. // Create the name using the original input’s with a prefix and suffix.
  4847. 'name="' + name + '"' +
  4848. // If the element has a value, set the hidden value as well.
  4849. (
  4850. $ELEMENT.data('value') || ELEMENT.value ?
  4851. ' value="' + P.get('select', SETTINGS.formatSubmit) + '"' :
  4852. ''
  4853. ) +
  4854. '>'
  4855. )[0]
  4856. $ELEMENT.
  4857. // If the value changes, update the hidden input with the correct format.
  4858. on('change.' + STATE.id, function() {
  4859. P._hidden.value = ELEMENT.value ?
  4860. P.get('select', SETTINGS.formatSubmit) :
  4861. ''
  4862. })
  4863. // Insert the hidden input as specified in the settings.
  4864. if ( SETTINGS.container ) $( SETTINGS.container ).append( P._hidden )
  4865. else $ELEMENT.after( P._hidden )
  4866. }
  4867. // For iOS8.
  4868. function handleKeydownEvent( event ) {
  4869. var keycode = event.keyCode,
  4870. // Check if one of the delete keys was pressed.
  4871. isKeycodeDelete = /^(8|46)$/.test(keycode)
  4872. // For some reason IE clears the input value on “escape”.
  4873. if ( keycode == 27 ) {
  4874. P.close()
  4875. return false
  4876. }
  4877. // Check if `space` or `delete` was pressed or the picker is closed with a key movement.
  4878. if ( keycode == 32 || isKeycodeDelete || !STATE.open && P.component.key[keycode] ) {
  4879. // Prevent it from moving the page and bubbling to doc.
  4880. event.preventDefault()
  4881. event.stopPropagation()
  4882. // If `delete` was pressed, clear the values and close the picker.
  4883. // Otherwise open the picker.
  4884. if ( isKeycodeDelete ) { P.clear().close() }
  4885. else { P.open() }
  4886. }
  4887. }
  4888. // Separated for IE
  4889. function handleFocusToOpenEvent( event ) {
  4890. // Stop the event from propagating to the doc.
  4891. event.stopPropagation()
  4892. // If it’s a focus event, add the “focused” class to the root.
  4893. if ( event.type == 'focus' ) {
  4894. P.$root.addClass( CLASSES.focused )
  4895. }
  4896. // And then finally open the picker.
  4897. P.open()
  4898. }
  4899. // Return a new picker instance.
  4900. return new PickerInstance()
  4901. } //PickerConstructor
  4902. /**
  4903. * The default classes and prefix to use for the HTML classes.
  4904. */
  4905. PickerConstructor.klasses = function( prefix ) {
  4906. prefix = prefix || 'picker'
  4907. return {
  4908. picker: prefix,
  4909. opened: prefix + '--opened',
  4910. focused: prefix + '--focused',
  4911. input: prefix + '__input',
  4912. active: prefix + '__input--active',
  4913. target: prefix + '__input--target',
  4914. holder: prefix + '__holder',
  4915. frame: prefix + '__frame',
  4916. wrap: prefix + '__wrap',
  4917. box: prefix + '__box'
  4918. }
  4919. } //PickerConstructor.klasses
  4920. /**
  4921. * Check if the default theme is being used.
  4922. */
  4923. function isUsingDefaultTheme( element ) {
  4924. var theme,
  4925. prop = 'position'
  4926. // For IE.
  4927. if ( element.currentStyle ) {
  4928. theme = element.currentStyle[prop]
  4929. }
  4930. // For normal browsers.
  4931. else if ( window.getComputedStyle ) {
  4932. theme = getComputedStyle( element )[prop]
  4933. }
  4934. return theme == 'fixed'
  4935. }
  4936. /**
  4937. * Get the width of the browser’s scrollbar.
  4938. * Taken from: https://github.com/VodkaBears/Remodal/blob/master/src/jquery.remodal.js
  4939. */
  4940. function getScrollbarWidth() {
  4941. if ( $html.height() <= $window.height() ) {
  4942. return 0
  4943. }
  4944. var $outer = $( '<div style="visibility:hidden;width:100px" />' ).
  4945. appendTo( 'body' )
  4946. // Get the width without scrollbars.
  4947. var widthWithoutScroll = $outer[0].offsetWidth
  4948. // Force adding scrollbars.
  4949. $outer.css( 'overflow', 'scroll' )
  4950. // Add the inner div.
  4951. var $inner = $( '<div style="width:100%" />' ).appendTo( $outer )
  4952. // Get the width with scrollbars.
  4953. var widthWithScroll = $inner[0].offsetWidth
  4954. // Remove the divs.
  4955. $outer.remove()
  4956. // Return the difference between the widths.
  4957. return widthWithoutScroll - widthWithScroll
  4958. }
  4959. /**
  4960. * PickerConstructor helper methods.
  4961. */
  4962. PickerConstructor._ = {
  4963. /**
  4964. * Create a group of nodes. Expects:
  4965. * `
  4966. {
  4967. min: {Integer},
  4968. max: {Integer},
  4969. i: {Integer},
  4970. node: {String},
  4971. item: {Function}
  4972. }
  4973. * `
  4974. */
  4975. group: function( groupObject ) {
  4976. var
  4977. // Scope for the looped object
  4978. loopObjectScope,
  4979. // Create the nodes list
  4980. nodesList = '',
  4981. // The counter starts from the `min`
  4982. counter = PickerConstructor._.trigger( groupObject.min, groupObject )
  4983. // Loop from the `min` to `max`, incrementing by `i`
  4984. for ( ; counter <= PickerConstructor._.trigger( groupObject.max, groupObject, [ counter ] ); counter += groupObject.i ) {
  4985. // Trigger the `item` function within scope of the object
  4986. loopObjectScope = PickerConstructor._.trigger( groupObject.item, groupObject, [ counter ] )
  4987. // Splice the subgroup and create nodes out of the sub nodes
  4988. nodesList += PickerConstructor._.node(
  4989. groupObject.node,
  4990. loopObjectScope[ 0 ], // the node
  4991. loopObjectScope[ 1 ], // the classes
  4992. loopObjectScope[ 2 ] // the attributes
  4993. )
  4994. }
  4995. // Return the list of nodes
  4996. return nodesList
  4997. }, //group
  4998. /**
  4999. * Create a dom node string
  5000. */
  5001. node: function( wrapper, item, klass, attribute ) {
  5002. // If the item is false-y, just return an empty string
  5003. if ( !item ) return ''
  5004. // If the item is an array, do a join
  5005. item = $.isArray( item ) ? item.join( '' ) : item
  5006. // Check for the class
  5007. klass = klass ? ' class="' + klass + '"' : ''
  5008. // Check for any attributes
  5009. attribute = attribute ? ' ' + attribute : ''
  5010. // Return the wrapped item
  5011. return '<' + wrapper + klass + attribute + '>' + item + '</' + wrapper + '>'
  5012. }, //node
  5013. /**
  5014. * Lead numbers below 10 with a zero.
  5015. */
  5016. lead: function( number ) {
  5017. return ( number < 10 ? '0': '' ) + number
  5018. },
  5019. /**
  5020. * Trigger a function otherwise return the value.
  5021. */
  5022. trigger: function( callback, scope, args ) {
  5023. return typeof callback == 'function' ? callback.apply( scope, args || [] ) : callback
  5024. },
  5025. /**
  5026. * If the second character is a digit, length is 2 otherwise 1.
  5027. */
  5028. digits: function( string ) {
  5029. return ( /\d/ ).test( string[ 1 ] ) ? 2 : 1
  5030. },
  5031. /**
  5032. * Tell if something is a date object.
  5033. */
  5034. isDate: function( value ) {
  5035. return {}.toString.call( value ).indexOf( 'Date' ) > -1 && this.isInteger( value.getDate() )
  5036. },
  5037. /**
  5038. * Tell if something is an integer.
  5039. */
  5040. isInteger: function( value ) {
  5041. return {}.toString.call( value ).indexOf( 'Number' ) > -1 && value % 1 === 0
  5042. },
  5043. /**
  5044. * Create ARIA attribute strings.
  5045. */
  5046. ariaAttr: ariaAttr
  5047. } //PickerConstructor._
  5048. /**
  5049. * Extend the picker with a component and defaults.
  5050. */
  5051. PickerConstructor.extend = function( name, Component ) {
  5052. // Extend jQuery.
  5053. $.fn[ name ] = function( options, action ) {
  5054. // Grab the component data.
  5055. var componentData = this.data( name )
  5056. // If the picker is requested, return the data object.
  5057. if ( options == 'picker' ) {
  5058. return componentData
  5059. }
  5060. // If the component data exists and `options` is a string, carry out the action.
  5061. if ( componentData && typeof options == 'string' ) {
  5062. return PickerConstructor._.trigger( componentData[ options ], componentData, [ action ] )
  5063. }
  5064. // Otherwise go through each matched element and if the component
  5065. // doesn’t exist, create a new picker using `this` element
  5066. // and merging the defaults and options with a deep copy.
  5067. return this.each( function() {
  5068. var $this = $( this )
  5069. if ( !$this.data( name ) ) {
  5070. new PickerConstructor( this, name, Component, options )
  5071. }
  5072. })
  5073. }
  5074. // Set the defaults.
  5075. $.fn[ name ].defaults = Component.defaults
  5076. } //PickerConstructor.extend
  5077. function aria(element, attribute, value) {
  5078. if ( $.isPlainObject(attribute) ) {
  5079. for ( var key in attribute ) {
  5080. ariaSet(element, key, attribute[key])
  5081. }
  5082. }
  5083. else {
  5084. ariaSet(element, attribute, value)
  5085. }
  5086. }
  5087. function ariaSet(element, attribute, value) {
  5088. element.setAttribute(
  5089. (attribute == 'role' ? '' : 'aria-') + attribute,
  5090. value
  5091. )
  5092. }
  5093. function ariaAttr(attribute, data) {
  5094. if ( !$.isPlainObject(attribute) ) {
  5095. attribute = { attribute: data }
  5096. }
  5097. data = ''
  5098. for ( var key in attribute ) {
  5099. var attr = (key == 'role' ? '' : 'aria-') + key,
  5100. attrVal = attribute[key]
  5101. data += attrVal == null ? '' : attr + '="' + attribute[key] + '"'
  5102. }
  5103. return data
  5104. }
  5105. // IE8 bug throws an error for activeElements within iframes.
  5106. function getActiveElement() {
  5107. try {
  5108. return document.activeElement
  5109. } catch ( err ) { }
  5110. }
  5111. // Expose the picker constructor.
  5112. return PickerConstructor
  5113. }));
  5114. ;/*!
  5115. * Date picker for pickadate.js v3.5.0
  5116. * http://amsul.github.io/pickadate.js/date.htm
  5117. */
  5118. (function ( factory ) {
  5119. // AMD.
  5120. if ( typeof define == 'function' && define.amd )
  5121. define( ['picker', 'jquery'], factory )
  5122. // Node.js/browserify.
  5123. else if ( typeof exports == 'object' )
  5124. module.exports = factory( require('./picker.js'), require('jquery') )
  5125. // Browser globals.
  5126. else factory( Picker, jQuery )
  5127. }(function( Picker, $ ) {
  5128. /**
  5129. * Globals and constants
  5130. */
  5131. var DAYS_IN_WEEK = 7,
  5132. WEEKS_IN_CALENDAR = 6,
  5133. _ = Picker._;
  5134. /**
  5135. * The date picker constructor
  5136. */
  5137. function DatePicker( picker, settings ) {
  5138. var calendar = this,
  5139. element = picker.$node[ 0 ],
  5140. elementValue = element.value,
  5141. elementDataValue = picker.$node.data( 'value' ),
  5142. valueString = elementDataValue || elementValue,
  5143. formatString = elementDataValue ? settings.formatSubmit : settings.format,
  5144. isRTL = function() {
  5145. return element.currentStyle ?
  5146. // For IE.
  5147. element.currentStyle.direction == 'rtl' :
  5148. // For normal browsers.
  5149. getComputedStyle( picker.$root[0] ).direction == 'rtl'
  5150. }
  5151. calendar.settings = settings
  5152. calendar.$node = picker.$node
  5153. // The queue of methods that will be used to build item objects.
  5154. calendar.queue = {
  5155. min: 'measure create',
  5156. max: 'measure create',
  5157. now: 'now create',
  5158. select: 'parse create validate',
  5159. highlight: 'parse navigate create validate',
  5160. view: 'parse create validate viewset',
  5161. disable: 'deactivate',
  5162. enable: 'activate'
  5163. }
  5164. // The component's item object.
  5165. calendar.item = {}
  5166. calendar.item.clear = null
  5167. calendar.item.disable = ( settings.disable || [] ).slice( 0 )
  5168. calendar.item.enable = -(function( collectionDisabled ) {
  5169. return collectionDisabled[ 0 ] === true ? collectionDisabled.shift() : -1
  5170. })( calendar.item.disable )
  5171. calendar.
  5172. set( 'min', settings.min ).
  5173. set( 'max', settings.max ).
  5174. set( 'now' )
  5175. // When there’s a value, set the `select`, which in turn
  5176. // also sets the `highlight` and `view`.
  5177. if ( valueString ) {
  5178. calendar.set( 'select', valueString, { format: formatString })
  5179. }
  5180. // If there’s no value, default to highlighting “today”.
  5181. else {
  5182. calendar.
  5183. set( 'select', null ).
  5184. set( 'highlight', calendar.item.now )
  5185. }
  5186. // The keycode to movement mapping.
  5187. calendar.key = {
  5188. 40: 7, // Down
  5189. 38: -7, // Up
  5190. 39: function() { return isRTL() ? -1 : 1 }, // Right
  5191. 37: function() { return isRTL() ? 1 : -1 }, // Left
  5192. go: function( timeChange ) {
  5193. var highlightedObject = calendar.item.highlight,
  5194. targetDate = new Date( highlightedObject.year, highlightedObject.month, highlightedObject.date + timeChange )
  5195. calendar.set(
  5196. 'highlight',
  5197. targetDate,
  5198. { interval: timeChange }
  5199. )
  5200. this.render()
  5201. }
  5202. }
  5203. // Bind some picker events.
  5204. picker.
  5205. on( 'render', function() {
  5206. picker.$root.find( '.' + settings.klass.selectMonth ).on( 'change', function() {
  5207. var value = this.value
  5208. if ( value ) {
  5209. picker.set( 'highlight', [ picker.get( 'view' ).year, value, picker.get( 'highlight' ).date ] )
  5210. picker.$root.find( '.' + settings.klass.selectMonth ).trigger( 'focus' )
  5211. }
  5212. })
  5213. picker.$root.find( '.' + settings.klass.selectYear ).on( 'change', function() {
  5214. var value = this.value
  5215. if ( value ) {
  5216. picker.set( 'highlight', [ value, picker.get( 'view' ).month, picker.get( 'highlight' ).date ] )
  5217. picker.$root.find( '.' + settings.klass.selectYear ).trigger( 'focus' )
  5218. }
  5219. })
  5220. }, 1 ).
  5221. on( 'open', function() {
  5222. var includeToday = ''
  5223. if ( calendar.disabled( calendar.get('now') ) ) {
  5224. includeToday = ':not(.' + settings.klass.buttonToday + ')'
  5225. }
  5226. picker.$root.find( 'button' + includeToday + ', select' ).attr( 'disabled', false )
  5227. }, 1 ).
  5228. on( 'close', function() {
  5229. picker.$root.find( 'button, select' ).attr( 'disabled', true )
  5230. }, 1 )
  5231. } //DatePicker
  5232. /**
  5233. * Set a datepicker item object.
  5234. */
  5235. DatePicker.prototype.set = function( type, value, options ) {
  5236. var calendar = this,
  5237. calendarItem = calendar.item
  5238. // If the value is `null` just set it immediately.
  5239. if ( value === null ) {
  5240. if ( type == 'clear' ) type = 'select'
  5241. calendarItem[ type ] = value
  5242. return calendar
  5243. }
  5244. // Otherwise go through the queue of methods, and invoke the functions.
  5245. // Update this as the time unit, and set the final value as this item.
  5246. // * In the case of `enable`, keep the queue but set `disable` instead.
  5247. // And in the case of `flip`, keep the queue but set `enable` instead.
  5248. calendarItem[ ( type == 'enable' ? 'disable' : type == 'flip' ? 'enable' : type ) ] = calendar.queue[ type ].split( ' ' ).map( function( method ) {
  5249. value = calendar[ method ]( type, value, options )
  5250. return value
  5251. }).pop()
  5252. // Check if we need to cascade through more updates.
  5253. if ( type == 'select' ) {
  5254. calendar.set( 'highlight', calendarItem.select, options )
  5255. }
  5256. else if ( type == 'highlight' ) {
  5257. calendar.set( 'view', calendarItem.highlight, options )
  5258. }
  5259. else if ( type.match( /^(flip|min|max|disable|enable)$/ ) ) {
  5260. if ( calendarItem.select && calendar.disabled( calendarItem.select ) ) {
  5261. calendar.set( 'select', calendarItem.select, options )
  5262. }
  5263. if ( calendarItem.highlight && calendar.disabled( calendarItem.highlight ) ) {
  5264. calendar.set( 'highlight', calendarItem.highlight, options )
  5265. }
  5266. }
  5267. return calendar
  5268. } //DatePicker.prototype.set
  5269. /**
  5270. * Get a datepicker item object.
  5271. */
  5272. DatePicker.prototype.get = function( type ) {
  5273. return this.item[ type ]
  5274. } //DatePicker.prototype.get
  5275. /**
  5276. * Create a picker date object.
  5277. */
  5278. DatePicker.prototype.create = function( type, value, options ) {
  5279. var isInfiniteValue,
  5280. calendar = this
  5281. // If there’s no value, use the type as the value.
  5282. value = value === undefined ? type : value
  5283. // If it’s infinity, update the value.
  5284. if ( value == -Infinity || value == Infinity ) {
  5285. isInfiniteValue = value
  5286. }
  5287. // If it’s an object, use the native date object.
  5288. else if ( $.isPlainObject( value ) && _.isInteger( value.pick ) ) {
  5289. value = value.obj
  5290. }
  5291. // If it’s an array, convert it into a date and make sure
  5292. // that it’s a valid date – otherwise default to today.
  5293. else if ( $.isArray( value ) ) {
  5294. value = new Date( value[ 0 ], value[ 1 ], value[ 2 ] )
  5295. value = _.isDate( value ) ? value : calendar.create().obj
  5296. }
  5297. // If it’s a number or date object, make a normalized date.
  5298. else if ( _.isInteger( value ) || _.isDate( value ) ) {
  5299. value = calendar.normalize( new Date( value ), options )
  5300. }
  5301. // If it’s a literal true or any other case, set it to now.
  5302. else /*if ( value === true )*/ {
  5303. value = calendar.now( type, value, options )
  5304. }
  5305. // Return the compiled object.
  5306. return {
  5307. year: isInfiniteValue || value.getFullYear(),
  5308. month: isInfiniteValue || value.getMonth(),
  5309. date: isInfiniteValue || value.getDate(),
  5310. day: isInfiniteValue || value.getDay(),
  5311. obj: isInfiniteValue || value,
  5312. pick: isInfiniteValue || value.getTime()
  5313. }
  5314. } //DatePicker.prototype.create
  5315. /**
  5316. * Create a range limit object using an array, date object,
  5317. * literal “true”, or integer relative to another time.
  5318. */
  5319. DatePicker.prototype.createRange = function( from, to ) {
  5320. var calendar = this,
  5321. createDate = function( date ) {
  5322. if ( date === true || $.isArray( date ) || _.isDate( date ) ) {
  5323. return calendar.create( date )
  5324. }
  5325. return date
  5326. }
  5327. // Create objects if possible.
  5328. if ( !_.isInteger( from ) ) {
  5329. from = createDate( from )
  5330. }
  5331. if ( !_.isInteger( to ) ) {
  5332. to = createDate( to )
  5333. }
  5334. // Create relative dates.
  5335. if ( _.isInteger( from ) && $.isPlainObject( to ) ) {
  5336. from = [ to.year, to.month, to.date + from ];
  5337. }
  5338. else if ( _.isInteger( to ) && $.isPlainObject( from ) ) {
  5339. to = [ from.year, from.month, from.date + to ];
  5340. }
  5341. return {
  5342. from: createDate( from ),
  5343. to: createDate( to )
  5344. }
  5345. } //DatePicker.prototype.createRange
  5346. /**
  5347. * Check if a date unit falls within a date range object.
  5348. */
  5349. DatePicker.prototype.withinRange = function( range, dateUnit ) {
  5350. range = this.createRange(range.from, range.to)
  5351. return dateUnit.pick >= range.from.pick && dateUnit.pick <= range.to.pick
  5352. }
  5353. /**
  5354. * Check if two date range objects overlap.
  5355. */
  5356. DatePicker.prototype.overlapRanges = function( one, two ) {
  5357. var calendar = this
  5358. // Convert the ranges into comparable dates.
  5359. one = calendar.createRange( one.from, one.to )
  5360. two = calendar.createRange( two.from, two.to )
  5361. return calendar.withinRange( one, two.from ) || calendar.withinRange( one, two.to ) ||
  5362. calendar.withinRange( two, one.from ) || calendar.withinRange( two, one.to )
  5363. }
  5364. /**
  5365. * Get the date today.
  5366. */
  5367. DatePicker.prototype.now = function( type, value, options ) {
  5368. value = new Date()
  5369. if ( options && options.rel ) {
  5370. value.setDate( value.getDate() + options.rel )
  5371. }
  5372. return this.normalize( value, options )
  5373. }
  5374. /**
  5375. * Navigate to next/prev month.
  5376. */
  5377. DatePicker.prototype.navigate = function( type, value, options ) {
  5378. var targetDateObject,
  5379. targetYear,
  5380. targetMonth,
  5381. targetDate,
  5382. isTargetArray = $.isArray( value ),
  5383. isTargetObject = $.isPlainObject( value ),
  5384. viewsetObject = this.item.view/*,
  5385. safety = 100*/
  5386. if ( isTargetArray || isTargetObject ) {
  5387. if ( isTargetObject ) {
  5388. targetYear = value.year
  5389. targetMonth = value.month
  5390. targetDate = value.date
  5391. }
  5392. else {
  5393. targetYear = +value[0]
  5394. targetMonth = +value[1]
  5395. targetDate = +value[2]
  5396. }
  5397. // If we’re navigating months but the view is in a different
  5398. // month, navigate to the view’s year and month.
  5399. if ( options && options.nav && viewsetObject && viewsetObject.month !== targetMonth ) {
  5400. targetYear = viewsetObject.year
  5401. targetMonth = viewsetObject.month
  5402. }
  5403. // Figure out the expected target year and month.
  5404. targetDateObject = new Date( targetYear, targetMonth + ( options && options.nav ? options.nav : 0 ), 1 )
  5405. targetYear = targetDateObject.getFullYear()
  5406. targetMonth = targetDateObject.getMonth()
  5407. // If the month we’re going to doesn’t have enough days,
  5408. // keep decreasing the date until we reach the month’s last date.
  5409. while ( /*safety &&*/ new Date( targetYear, targetMonth, targetDate ).getMonth() !== targetMonth ) {
  5410. targetDate -= 1
  5411. /*safety -= 1
  5412. if ( !safety ) {
  5413. throw 'Fell into an infinite loop while navigating to ' + new Date( targetYear, targetMonth, targetDate ) + '.'
  5414. }*/
  5415. }
  5416. value = [ targetYear, targetMonth, targetDate ]
  5417. }
  5418. return value
  5419. } //DatePicker.prototype.navigate
  5420. /**
  5421. * Normalize a date by setting the hours to midnight.
  5422. */
  5423. DatePicker.prototype.normalize = function( value/*, options*/ ) {
  5424. value.setHours( 0, 0, 0, 0 )
  5425. return value
  5426. }
  5427. /**
  5428. * Measure the range of dates.
  5429. */
  5430. DatePicker.prototype.measure = function( type, value/*, options*/ ) {
  5431. var calendar = this
  5432. // If it’s anything false-y, remove the limits.
  5433. if ( !value ) {
  5434. value = type == 'min' ? -Infinity : Infinity
  5435. }
  5436. // If it’s a string, parse it.
  5437. else if ( typeof value == 'string' ) {
  5438. value = calendar.parse( type, value )
  5439. }
  5440. // If it's an integer, get a date relative to today.
  5441. else if ( _.isInteger( value ) ) {
  5442. value = calendar.now( type, value, { rel: value } )
  5443. }
  5444. return value
  5445. } ///DatePicker.prototype.measure
  5446. /**
  5447. * Create a viewset object based on navigation.
  5448. */
  5449. DatePicker.prototype.viewset = function( type, dateObject/*, options*/ ) {
  5450. return this.create([ dateObject.year, dateObject.month, 1 ])
  5451. }
  5452. /**
  5453. * Validate a date as enabled and shift if needed.
  5454. */
  5455. DatePicker.prototype.validate = function( type, dateObject, options ) {
  5456. var calendar = this,
  5457. // Keep a reference to the original date.
  5458. originalDateObject = dateObject,
  5459. // Make sure we have an interval.
  5460. interval = options && options.interval ? options.interval : 1,
  5461. // Check if the calendar enabled dates are inverted.
  5462. isFlippedBase = calendar.item.enable === -1,
  5463. // Check if we have any enabled dates after/before now.
  5464. hasEnabledBeforeTarget, hasEnabledAfterTarget,
  5465. // The min & max limits.
  5466. minLimitObject = calendar.item.min,
  5467. maxLimitObject = calendar.item.max,
  5468. // Check if we’ve reached the limit during shifting.
  5469. reachedMin, reachedMax,
  5470. // Check if the calendar is inverted and at least one weekday is enabled.
  5471. hasEnabledWeekdays = isFlippedBase && calendar.item.disable.filter( function( value ) {
  5472. // If there’s a date, check where it is relative to the target.
  5473. if ( $.isArray( value ) ) {
  5474. var dateTime = calendar.create( value ).pick
  5475. if ( dateTime < dateObject.pick ) hasEnabledBeforeTarget = true
  5476. else if ( dateTime > dateObject.pick ) hasEnabledAfterTarget = true
  5477. }
  5478. // Return only integers for enabled weekdays.
  5479. return _.isInteger( value )
  5480. }).length/*,
  5481. safety = 100*/
  5482. // Cases to validate for:
  5483. // [1] Not inverted and date disabled.
  5484. // [2] Inverted and some dates enabled.
  5485. // [3] Not inverted and out of range.
  5486. //
  5487. // Cases to **not** validate for:
  5488. // • Navigating months.
  5489. // • Not inverted and date enabled.
  5490. // • Inverted and all dates disabled.
  5491. // • ..and anything else.
  5492. if ( !options || !options.nav ) if (
  5493. /* 1 */ ( !isFlippedBase && calendar.disabled( dateObject ) ) ||
  5494. /* 2 */ ( isFlippedBase && calendar.disabled( dateObject ) && ( hasEnabledWeekdays || hasEnabledBeforeTarget || hasEnabledAfterTarget ) ) ||
  5495. /* 3 */ ( !isFlippedBase && (dateObject.pick <= minLimitObject.pick || dateObject.pick >= maxLimitObject.pick) )
  5496. ) {
  5497. // When inverted, flip the direction if there aren’t any enabled weekdays
  5498. // and there are no enabled dates in the direction of the interval.
  5499. if ( isFlippedBase && !hasEnabledWeekdays && ( ( !hasEnabledAfterTarget && interval > 0 ) || ( !hasEnabledBeforeTarget && interval < 0 ) ) ) {
  5500. interval *= -1
  5501. }
  5502. // Keep looping until we reach an enabled date.
  5503. while ( /*safety &&*/ calendar.disabled( dateObject ) ) {
  5504. /*safety -= 1
  5505. if ( !safety ) {
  5506. throw 'Fell into an infinite loop while validating ' + dateObject.obj + '.'
  5507. }*/
  5508. // If we’ve looped into the next/prev month with a large interval, return to the original date and flatten the interval.
  5509. if ( Math.abs( interval ) > 1 && ( dateObject.month < originalDateObject.month || dateObject.month > originalDateObject.month ) ) {
  5510. dateObject = originalDateObject
  5511. interval = interval > 0 ? 1 : -1
  5512. }
  5513. // If we’ve reached the min/max limit, reverse the direction, flatten the interval and set it to the limit.
  5514. if ( dateObject.pick <= minLimitObject.pick ) {
  5515. reachedMin = true
  5516. interval = 1
  5517. dateObject = calendar.create([
  5518. minLimitObject.year,
  5519. minLimitObject.month,
  5520. minLimitObject.date + (dateObject.pick === minLimitObject.pick ? 0 : -1)
  5521. ])
  5522. }
  5523. else if ( dateObject.pick >= maxLimitObject.pick ) {
  5524. reachedMax = true
  5525. interval = -1
  5526. dateObject = calendar.create([
  5527. maxLimitObject.year,
  5528. maxLimitObject.month,
  5529. maxLimitObject.date + (dateObject.pick === maxLimitObject.pick ? 0 : 1)
  5530. ])
  5531. }
  5532. // If we’ve reached both limits, just break out of the loop.
  5533. if ( reachedMin && reachedMax ) {
  5534. break
  5535. }
  5536. // Finally, create the shifted date using the interval and keep looping.
  5537. dateObject = calendar.create([ dateObject.year, dateObject.month, dateObject.date + interval ])
  5538. }
  5539. } //endif
  5540. // Return the date object settled on.
  5541. return dateObject
  5542. } //DatePicker.prototype.validate
  5543. /**
  5544. * Check if a date is disabled.
  5545. */
  5546. DatePicker.prototype.disabled = function( dateToVerify ) {
  5547. var
  5548. calendar = this,
  5549. // Filter through the disabled dates to check if this is one.
  5550. isDisabledMatch = calendar.item.disable.filter( function( dateToDisable ) {
  5551. // If the date is a number, match the weekday with 0index and `firstDay` check.
  5552. if ( _.isInteger( dateToDisable ) ) {
  5553. return dateToVerify.day === ( calendar.settings.firstDay ? dateToDisable : dateToDisable - 1 ) % 7
  5554. }
  5555. // If it’s an array or a native JS date, create and match the exact date.
  5556. if ( $.isArray( dateToDisable ) || _.isDate( dateToDisable ) ) {
  5557. return dateToVerify.pick === calendar.create( dateToDisable ).pick
  5558. }
  5559. // If it’s an object, match a date within the “from” and “to” range.
  5560. if ( $.isPlainObject( dateToDisable ) ) {
  5561. return calendar.withinRange( dateToDisable, dateToVerify )
  5562. }
  5563. })
  5564. // If this date matches a disabled date, confirm it’s not inverted.
  5565. isDisabledMatch = isDisabledMatch.length && !isDisabledMatch.filter(function( dateToDisable ) {
  5566. return $.isArray( dateToDisable ) && dateToDisable[3] == 'inverted' ||
  5567. $.isPlainObject( dateToDisable ) && dateToDisable.inverted
  5568. }).length
  5569. // Check the calendar “enabled” flag and respectively flip the
  5570. // disabled state. Then also check if it’s beyond the min/max limits.
  5571. return calendar.item.enable === -1 ? !isDisabledMatch : isDisabledMatch ||
  5572. dateToVerify.pick < calendar.item.min.pick ||
  5573. dateToVerify.pick > calendar.item.max.pick
  5574. } //DatePicker.prototype.disabled
  5575. /**
  5576. * Parse a string into a usable type.
  5577. */
  5578. DatePicker.prototype.parse = function( type, value, options ) {
  5579. var calendar = this,
  5580. parsingObject = {}
  5581. // If it’s already parsed, we’re good.
  5582. if ( !value || typeof value != 'string' ) {
  5583. return value
  5584. }
  5585. // We need a `.format` to parse the value with.
  5586. if ( !( options && options.format ) ) {
  5587. options = options || {}
  5588. options.format = calendar.settings.format
  5589. }
  5590. // Convert the format into an array and then map through it.
  5591. calendar.formats.toArray( options.format ).map( function( label ) {
  5592. var
  5593. // Grab the formatting label.
  5594. formattingLabel = calendar.formats[ label ],
  5595. // The format length is from the formatting label function or the
  5596. // label length without the escaping exclamation (!) mark.
  5597. formatLength = formattingLabel ? _.trigger( formattingLabel, calendar, [ value, parsingObject ] ) : label.replace( /^!/, '' ).length
  5598. // If there's a format label, split the value up to the format length.
  5599. // Then add it to the parsing object with appropriate label.
  5600. if ( formattingLabel ) {
  5601. parsingObject[ label ] = value.substr( 0, formatLength )
  5602. }
  5603. // Update the value as the substring from format length to end.
  5604. value = value.substr( formatLength )
  5605. })
  5606. // Compensate for month 0index.
  5607. return [
  5608. parsingObject.yyyy || parsingObject.yy,
  5609. +( parsingObject.mm || parsingObject.m ) - 1,
  5610. parsingObject.dd || parsingObject.d
  5611. ]
  5612. } //DatePicker.prototype.parse
  5613. /**
  5614. * Various formats to display the object in.
  5615. */
  5616. DatePicker.prototype.formats = (function() {
  5617. // Return the length of the first word in a collection.
  5618. function getWordLengthFromCollection( string, collection, dateObject ) {
  5619. // Grab the first word from the string.
  5620. var word = string.match( /\w+/ )[ 0 ]
  5621. // If there's no month index, add it to the date object
  5622. if ( !dateObject.mm && !dateObject.m ) {
  5623. dateObject.m = collection.indexOf( word ) + 1
  5624. }
  5625. // Return the length of the word.
  5626. return word.length
  5627. }
  5628. // Get the length of the first word in a string.
  5629. function getFirstWordLength( string ) {
  5630. return string.match( /\w+/ )[ 0 ].length
  5631. }
  5632. return {
  5633. d: function( string, dateObject ) {
  5634. // If there's string, then get the digits length.
  5635. // Otherwise return the selected date.
  5636. return string ? _.digits( string ) : dateObject.date
  5637. },
  5638. dd: function( string, dateObject ) {
  5639. // If there's a string, then the length is always 2.
  5640. // Otherwise return the selected date with a leading zero.
  5641. return string ? 2 : _.lead( dateObject.date )
  5642. },
  5643. ddd: function( string, dateObject ) {
  5644. // If there's a string, then get the length of the first word.
  5645. // Otherwise return the short selected weekday.
  5646. return string ? getFirstWordLength( string ) : this.settings.weekdaysShort[ dateObject.day ]
  5647. },
  5648. dddd: function( string, dateObject ) {
  5649. // If there's a string, then get the length of the first word.
  5650. // Otherwise return the full selected weekday.
  5651. return string ? getFirstWordLength( string ) : this.settings.weekdaysFull[ dateObject.day ]
  5652. },
  5653. m: function( string, dateObject ) {
  5654. // If there's a string, then get the length of the digits
  5655. // Otherwise return the selected month with 0index compensation.
  5656. return string ? _.digits( string ) : dateObject.month + 1
  5657. },
  5658. mm: function( string, dateObject ) {
  5659. // If there's a string, then the length is always 2.
  5660. // Otherwise return the selected month with 0index and leading zero.
  5661. return string ? 2 : _.lead( dateObject.month + 1 )
  5662. },
  5663. mmm: function( string, dateObject ) {
  5664. var collection = this.settings.monthsShort
  5665. // If there's a string, get length of the relevant month from the short
  5666. // months collection. Otherwise return the selected month from that collection.
  5667. return string ? getWordLengthFromCollection( string, collection, dateObject ) : collection[ dateObject.month ]
  5668. },
  5669. mmmm: function( string, dateObject ) {
  5670. var collection = this.settings.monthsFull
  5671. // If there's a string, get length of the relevant month from the full
  5672. // months collection. Otherwise return the selected month from that collection.
  5673. return string ? getWordLengthFromCollection( string, collection, dateObject ) : collection[ dateObject.month ]
  5674. },
  5675. yy: function( string, dateObject ) {
  5676. // If there's a string, then the length is always 2.
  5677. // Otherwise return the selected year by slicing out the first 2 digits.
  5678. return string ? 2 : ( '' + dateObject.year ).slice( 2 )
  5679. },
  5680. yyyy: function( string, dateObject ) {
  5681. // If there's a string, then the length is always 4.
  5682. // Otherwise return the selected year.
  5683. return string ? 4 : dateObject.year
  5684. },
  5685. // Create an array by splitting the formatting string passed.
  5686. toArray: function( formatString ) { return formatString.split( /(d{1,4}|m{1,4}|y{4}|yy|!.)/g ) },
  5687. // Format an object into a string using the formatting options.
  5688. toString: function ( formatString, itemObject ) {
  5689. var calendar = this
  5690. return calendar.formats.toArray( formatString ).map( function( label ) {
  5691. return _.trigger( calendar.formats[ label ], calendar, [ 0, itemObject ] ) || label.replace( /^!/, '' )
  5692. }).join( '' )
  5693. }
  5694. }
  5695. })() //DatePicker.prototype.formats
  5696. /**
  5697. * Check if two date units are the exact.
  5698. */
  5699. DatePicker.prototype.isDateExact = function( one, two ) {
  5700. var calendar = this
  5701. // When we’re working with weekdays, do a direct comparison.
  5702. if (
  5703. ( _.isInteger( one ) && _.isInteger( two ) ) ||
  5704. ( typeof one == 'boolean' && typeof two == 'boolean' )
  5705. ) {
  5706. return one === two
  5707. }
  5708. // When we’re working with date representations, compare the “pick” value.
  5709. if (
  5710. ( _.isDate( one ) || $.isArray( one ) ) &&
  5711. ( _.isDate( two ) || $.isArray( two ) )
  5712. ) {
  5713. return calendar.create( one ).pick === calendar.create( two ).pick
  5714. }
  5715. // When we’re working with range objects, compare the “from” and “to”.
  5716. if ( $.isPlainObject( one ) && $.isPlainObject( two ) ) {
  5717. return calendar.isDateExact( one.from, two.from ) && calendar.isDateExact( one.to, two.to )
  5718. }
  5719. return false
  5720. }
  5721. /**
  5722. * Check if two date units overlap.
  5723. */
  5724. DatePicker.prototype.isDateOverlap = function( one, two ) {
  5725. var calendar = this,
  5726. firstDay = calendar.settings.firstDay ? 1 : 0
  5727. // When we’re working with a weekday index, compare the days.
  5728. if ( _.isInteger( one ) && ( _.isDate( two ) || $.isArray( two ) ) ) {
  5729. one = one % 7 + firstDay
  5730. return one === calendar.create( two ).day + 1
  5731. }
  5732. if ( _.isInteger( two ) && ( _.isDate( one ) || $.isArray( one ) ) ) {
  5733. two = two % 7 + firstDay
  5734. return two === calendar.create( one ).day + 1
  5735. }
  5736. // When we’re working with range objects, check if the ranges overlap.
  5737. if ( $.isPlainObject( one ) && $.isPlainObject( two ) ) {
  5738. return calendar.overlapRanges( one, two )
  5739. }
  5740. return false
  5741. }
  5742. /**
  5743. * Flip the “enabled” state.
  5744. */
  5745. DatePicker.prototype.flipEnable = function(val) {
  5746. var itemObject = this.item
  5747. itemObject.enable = val || (itemObject.enable == -1 ? 1 : -1)
  5748. }
  5749. /**
  5750. * Mark a collection of dates as “disabled”.
  5751. */
  5752. DatePicker.prototype.deactivate = function( type, datesToDisable ) {
  5753. var calendar = this,
  5754. disabledItems = calendar.item.disable.slice(0)
  5755. // If we’re flipping, that’s all we need to do.
  5756. if ( datesToDisable == 'flip' ) {
  5757. calendar.flipEnable()
  5758. }
  5759. else if ( datesToDisable === false ) {
  5760. calendar.flipEnable(1)
  5761. disabledItems = []
  5762. }
  5763. else if ( datesToDisable === true ) {
  5764. calendar.flipEnable(-1)
  5765. disabledItems = []
  5766. }
  5767. // Otherwise go through the dates to disable.
  5768. else {
  5769. datesToDisable.map(function( unitToDisable ) {
  5770. var matchFound
  5771. // When we have disabled items, check for matches.
  5772. // If something is matched, immediately break out.
  5773. for ( var index = 0; index < disabledItems.length; index += 1 ) {
  5774. if ( calendar.isDateExact( unitToDisable, disabledItems[index] ) ) {
  5775. matchFound = true
  5776. break
  5777. }
  5778. }
  5779. // If nothing was found, add the validated unit to the collection.
  5780. if ( !matchFound ) {
  5781. if (
  5782. _.isInteger( unitToDisable ) ||
  5783. _.isDate( unitToDisable ) ||
  5784. $.isArray( unitToDisable ) ||
  5785. ( $.isPlainObject( unitToDisable ) && unitToDisable.from && unitToDisable.to )
  5786. ) {
  5787. disabledItems.push( unitToDisable )
  5788. }
  5789. }
  5790. })
  5791. }
  5792. // Return the updated collection.
  5793. return disabledItems
  5794. } //DatePicker.prototype.deactivate
  5795. /**
  5796. * Mark a collection of dates as “enabled”.
  5797. */
  5798. DatePicker.prototype.activate = function( type, datesToEnable ) {
  5799. var calendar = this,
  5800. disabledItems = calendar.item.disable,
  5801. disabledItemsCount = disabledItems.length
  5802. // If we’re flipping, that’s all we need to do.
  5803. if ( datesToEnable == 'flip' ) {
  5804. calendar.flipEnable()
  5805. }
  5806. else if ( datesToEnable === true ) {
  5807. calendar.flipEnable(1)
  5808. disabledItems = []
  5809. }
  5810. else if ( datesToEnable === false ) {
  5811. calendar.flipEnable(-1)
  5812. disabledItems = []
  5813. }
  5814. // Otherwise go through the disabled dates.
  5815. else {
  5816. datesToEnable.map(function( unitToEnable ) {
  5817. var matchFound,
  5818. disabledUnit,
  5819. index,
  5820. isExactRange
  5821. // Go through the disabled items and try to find a match.
  5822. for ( index = 0; index < disabledItemsCount; index += 1 ) {
  5823. disabledUnit = disabledItems[index]
  5824. // When an exact match is found, remove it from the collection.
  5825. if ( calendar.isDateExact( disabledUnit, unitToEnable ) ) {
  5826. matchFound = disabledItems[index] = null
  5827. isExactRange = true
  5828. break
  5829. }
  5830. // When an overlapped match is found, add the “inverted” state to it.
  5831. else if ( calendar.isDateOverlap( disabledUnit, unitToEnable ) ) {
  5832. if ( $.isPlainObject( unitToEnable ) ) {
  5833. unitToEnable.inverted = true
  5834. matchFound = unitToEnable
  5835. }
  5836. else if ( $.isArray( unitToEnable ) ) {
  5837. matchFound = unitToEnable
  5838. if ( !matchFound[3] ) matchFound.push( 'inverted' )
  5839. }
  5840. else if ( _.isDate( unitToEnable ) ) {
  5841. matchFound = [ unitToEnable.getFullYear(), unitToEnable.getMonth(), unitToEnable.getDate(), 'inverted' ]
  5842. }
  5843. break
  5844. }
  5845. }
  5846. // If a match was found, remove a previous duplicate entry.
  5847. if ( matchFound ) for ( index = 0; index < disabledItemsCount; index += 1 ) {
  5848. if ( calendar.isDateExact( disabledItems[index], unitToEnable ) ) {
  5849. disabledItems[index] = null
  5850. break
  5851. }
  5852. }
  5853. // In the event that we’re dealing with an exact range of dates,
  5854. // make sure there are no “inverted” dates because of it.
  5855. if ( isExactRange ) for ( index = 0; index < disabledItemsCount; index += 1 ) {
  5856. if ( calendar.isDateOverlap( disabledItems[index], unitToEnable ) ) {
  5857. disabledItems[index] = null
  5858. break
  5859. }
  5860. }
  5861. // If something is still matched, add it into the collection.
  5862. if ( matchFound ) {
  5863. disabledItems.push( matchFound )
  5864. }
  5865. })
  5866. }
  5867. // Return the updated collection.
  5868. return disabledItems.filter(function( val ) { return val != null })
  5869. } //DatePicker.prototype.activate
  5870. /**
  5871. * Create a string for the nodes in the picker.
  5872. */
  5873. DatePicker.prototype.nodes = function( isOpen ) {
  5874. var
  5875. calendar = this,
  5876. settings = calendar.settings,
  5877. calendarItem = calendar.item,
  5878. nowObject = calendarItem.now,
  5879. selectedObject = calendarItem.select,
  5880. highlightedObject = calendarItem.highlight,
  5881. viewsetObject = calendarItem.view,
  5882. disabledCollection = calendarItem.disable,
  5883. minLimitObject = calendarItem.min,
  5884. maxLimitObject = calendarItem.max,
  5885. // Create the calendar table head using a copy of weekday labels collection.
  5886. // * We do a copy so we don't mutate the original array.
  5887. tableHead = (function( collection, fullCollection ) {
  5888. // If the first day should be Monday, move Sunday to the end.
  5889. if ( settings.firstDay ) {
  5890. collection.push( collection.shift() )
  5891. fullCollection.push( fullCollection.shift() )
  5892. }
  5893. // Create and return the table head group.
  5894. return _.node(
  5895. 'thead',
  5896. _.node(
  5897. 'tr',
  5898. _.group({
  5899. min: 0,
  5900. max: DAYS_IN_WEEK - 1,
  5901. i: 1,
  5902. node: 'th',
  5903. item: function( counter ) {
  5904. return [
  5905. collection[ counter ],
  5906. settings.klass.weekdays,
  5907. 'scope=col title="' + fullCollection[ counter ] + '"'
  5908. ]
  5909. }
  5910. })
  5911. )
  5912. ) //endreturn
  5913. // Materialize modified
  5914. })( ( settings.showWeekdaysFull ? settings.weekdaysFull : settings.weekdaysLetter ).slice( 0 ), settings.weekdaysFull.slice( 0 ) ), //tableHead
  5915. // Create the nav for next/prev month.
  5916. createMonthNav = function( next ) {
  5917. // Otherwise, return the created month tag.
  5918. return _.node(
  5919. 'div',
  5920. ' ',
  5921. settings.klass[ 'nav' + ( next ? 'Next' : 'Prev' ) ] + (
  5922. // If the focused month is outside the range, disabled the button.
  5923. ( next && viewsetObject.year >= maxLimitObject.year && viewsetObject.month >= maxLimitObject.month ) ||
  5924. ( !next && viewsetObject.year <= minLimitObject.year && viewsetObject.month <= minLimitObject.month ) ?
  5925. ' ' + settings.klass.navDisabled : ''
  5926. ),
  5927. 'data-nav=' + ( next || -1 ) + ' ' +
  5928. _.ariaAttr({
  5929. role: 'button',
  5930. controls: calendar.$node[0].id + '_table'
  5931. }) + ' ' +
  5932. 'title="' + (next ? settings.labelMonthNext : settings.labelMonthPrev ) + '"'
  5933. ) //endreturn
  5934. }, //createMonthNav
  5935. // Create the month label.
  5936. //Materialize modified
  5937. createMonthLabel = function(override) {
  5938. var monthsCollection = settings.showMonthsShort ? settings.monthsShort : settings.monthsFull
  5939. // Materialize modified
  5940. if (override == "short_months") {
  5941. monthsCollection = settings.monthsShort;
  5942. }
  5943. // If there are months to select, add a dropdown menu.
  5944. if ( settings.selectMonths && override == undefined) {
  5945. return _.node( 'select',
  5946. _.group({
  5947. min: 0,
  5948. max: 11,
  5949. i: 1,
  5950. node: 'option',
  5951. item: function( loopedMonth ) {
  5952. return [
  5953. // The looped month and no classes.
  5954. monthsCollection[ loopedMonth ], 0,
  5955. // Set the value and selected index.
  5956. 'value=' + loopedMonth +
  5957. ( viewsetObject.month == loopedMonth ? ' selected' : '' ) +
  5958. (
  5959. (
  5960. ( viewsetObject.year == minLimitObject.year && loopedMonth < minLimitObject.month ) ||
  5961. ( viewsetObject.year == maxLimitObject.year && loopedMonth > maxLimitObject.month )
  5962. ) ?
  5963. ' disabled' : ''
  5964. )
  5965. ]
  5966. }
  5967. }),
  5968. settings.klass.selectMonth + ' browser-default',
  5969. ( isOpen ? '' : 'disabled' ) + ' ' +
  5970. _.ariaAttr({ controls: calendar.$node[0].id + '_table' }) + ' ' +
  5971. 'title="' + settings.labelMonthSelect + '"'
  5972. )
  5973. }
  5974. // Materialize modified
  5975. if (override == "short_months")
  5976. if (selectedObject != null)
  5977. return monthsCollection[ selectedObject.month ];
  5978. else return monthsCollection[ viewsetObject.month ];
  5979. // If there's a need for a month selector
  5980. return _.node( 'div', monthsCollection[ viewsetObject.month ], settings.klass.month )
  5981. }, //createMonthLabel
  5982. // Create the year label.
  5983. // Materialize modified
  5984. createYearLabel = function(override) {
  5985. var focusedYear = viewsetObject.year,
  5986. // If years selector is set to a literal "true", set it to 5. Otherwise
  5987. // divide in half to get half before and half after focused year.
  5988. numberYears = settings.selectYears === true ? 5 : ~~( settings.selectYears / 2 )
  5989. // If there are years to select, add a dropdown menu.
  5990. if ( numberYears ) {
  5991. var
  5992. minYear = minLimitObject.year,
  5993. maxYear = maxLimitObject.year,
  5994. lowestYear = focusedYear - numberYears,
  5995. highestYear = focusedYear + numberYears
  5996. // If the min year is greater than the lowest year, increase the highest year
  5997. // by the difference and set the lowest year to the min year.
  5998. if ( minYear > lowestYear ) {
  5999. highestYear += minYear - lowestYear
  6000. lowestYear = minYear
  6001. }
  6002. // If the max year is less than the highest year, decrease the lowest year
  6003. // by the lower of the two: available and needed years. Then set the
  6004. // highest year to the max year.
  6005. if ( maxYear < highestYear ) {
  6006. var availableYears = lowestYear - minYear,
  6007. neededYears = highestYear - maxYear
  6008. lowestYear -= availableYears > neededYears ? neededYears : availableYears
  6009. highestYear = maxYear
  6010. }
  6011. if ( settings.selectYears && override == undefined ) {
  6012. return _.node( 'select',
  6013. _.group({
  6014. min: lowestYear,
  6015. max: highestYear,
  6016. i: 1,
  6017. node: 'option',
  6018. item: function( loopedYear ) {
  6019. return [
  6020. // The looped year and no classes.
  6021. loopedYear, 0,
  6022. // Set the value and selected index.
  6023. 'value=' + loopedYear + ( focusedYear == loopedYear ? ' selected' : '' )
  6024. ]
  6025. }
  6026. }),
  6027. settings.klass.selectYear + ' browser-default',
  6028. ( isOpen ? '' : 'disabled' ) + ' ' + _.ariaAttr({ controls: calendar.$node[0].id + '_table' }) + ' ' +
  6029. 'title="' + settings.labelYearSelect + '"'
  6030. )
  6031. }
  6032. }
  6033. // Materialize modified
  6034. if (override == "raw")
  6035. return _.node( 'div', focusedYear )
  6036. // Otherwise just return the year focused
  6037. return _.node( 'div', focusedYear, settings.klass.year )
  6038. } //createYearLabel
  6039. // Materialize modified
  6040. createDayLabel = function() {
  6041. if (selectedObject != null)
  6042. return selectedObject.date
  6043. else return nowObject.date
  6044. }
  6045. createWeekdayLabel = function() {
  6046. var display_day;
  6047. if (selectedObject != null)
  6048. display_day = selectedObject.day;
  6049. else
  6050. display_day = nowObject.day;
  6051. var weekday = settings.weekdaysShort[ display_day ];
  6052. return weekday
  6053. }
  6054. // Create and return the entire calendar.
  6055. return _.node(
  6056. // Date presentation View
  6057. 'div',
  6058. _.node(
  6059. // Div for Year
  6060. 'div',
  6061. createYearLabel("raw") ,
  6062. settings.klass.year_display
  6063. )+
  6064. _.node(
  6065. 'span',
  6066. createWeekdayLabel() + ', ',
  6067. "picker__weekday-display"
  6068. )+
  6069. _.node(
  6070. // Div for short Month
  6071. 'span',
  6072. createMonthLabel("short_months") + ' ',
  6073. settings.klass.month_display
  6074. )+
  6075. _.node(
  6076. // Div for Day
  6077. 'span',
  6078. createDayLabel() ,
  6079. settings.klass.day_display
  6080. ),
  6081. settings.klass.date_display
  6082. )+
  6083. // Calendar container
  6084. _.node('div',
  6085. _.node('div',
  6086. _.node('div',
  6087. ( settings.selectYears ? createMonthLabel() + createYearLabel() : createMonthLabel() + createYearLabel() ) +
  6088. createMonthNav() + createMonthNav( 1 ),
  6089. settings.klass.header
  6090. ) + _.node(
  6091. 'table',
  6092. tableHead +
  6093. _.node(
  6094. 'tbody',
  6095. _.group({
  6096. min: 0,
  6097. max: WEEKS_IN_CALENDAR - 1,
  6098. i: 1,
  6099. node: 'tr',
  6100. item: function( rowCounter ) {
  6101. // If Monday is the first day and the month starts on Sunday, shift the date back a week.
  6102. var shiftDateBy = settings.firstDay && calendar.create([ viewsetObject.year, viewsetObject.month, 1 ]).day === 0 ? -7 : 0
  6103. return [
  6104. _.group({
  6105. min: DAYS_IN_WEEK * rowCounter - viewsetObject.day + shiftDateBy + 1, // Add 1 for weekday 0index
  6106. max: function() {
  6107. return this.min + DAYS_IN_WEEK - 1
  6108. },
  6109. i: 1,
  6110. node: 'td',
  6111. item: function( targetDate ) {
  6112. // Convert the time date from a relative date to a target date.
  6113. targetDate = calendar.create([ viewsetObject.year, viewsetObject.month, targetDate + ( settings.firstDay ? 1 : 0 ) ])
  6114. var isSelected = selectedObject && selectedObject.pick == targetDate.pick,
  6115. isHighlighted = highlightedObject && highlightedObject.pick == targetDate.pick,
  6116. isDisabled = disabledCollection && calendar.disabled( targetDate ) || targetDate.pick < minLimitObject.pick || targetDate.pick > maxLimitObject.pick,
  6117. formattedDate = _.trigger( calendar.formats.toString, calendar, [ settings.format, targetDate ] )
  6118. return [
  6119. _.node(
  6120. 'div',
  6121. targetDate.date,
  6122. (function( klasses ) {
  6123. // Add the `infocus` or `outfocus` classes based on month in view.
  6124. klasses.push( viewsetObject.month == targetDate.month ? settings.klass.infocus : settings.klass.outfocus )
  6125. // Add the `today` class if needed.
  6126. if ( nowObject.pick == targetDate.pick ) {
  6127. klasses.push( settings.klass.now )
  6128. }
  6129. // Add the `selected` class if something's selected and the time matches.
  6130. if ( isSelected ) {
  6131. klasses.push( settings.klass.selected )
  6132. }
  6133. // Add the `highlighted` class if something's highlighted and the time matches.
  6134. if ( isHighlighted ) {
  6135. klasses.push( settings.klass.highlighted )
  6136. }
  6137. // Add the `disabled` class if something's disabled and the object matches.
  6138. if ( isDisabled ) {
  6139. klasses.push( settings.klass.disabled )
  6140. }
  6141. return klasses.join( ' ' )
  6142. })([ settings.klass.day ]),
  6143. 'data-pick=' + targetDate.pick + ' ' + _.ariaAttr({
  6144. role: 'gridcell',
  6145. label: formattedDate,
  6146. selected: isSelected && calendar.$node.val() === formattedDate ? true : null,
  6147. activedescendant: isHighlighted ? true : null,
  6148. disabled: isDisabled ? true : null
  6149. })
  6150. ),
  6151. '',
  6152. _.ariaAttr({ role: 'presentation' })
  6153. ] //endreturn
  6154. }
  6155. })
  6156. ] //endreturn
  6157. }
  6158. })
  6159. ),
  6160. settings.klass.table,
  6161. 'id="' + calendar.$node[0].id + '_table' + '" ' + _.ariaAttr({
  6162. role: 'grid',
  6163. controls: calendar.$node[0].id,
  6164. readonly: true
  6165. })
  6166. )
  6167. , settings.klass.calendar_container) // end calendar
  6168. +
  6169. // * For Firefox forms to submit, make sure to set the buttons’ `type` attributes as “button”.
  6170. _.node(
  6171. 'div',
  6172. _.node( 'button', settings.today, "btn-flat picker__today waves-effect",
  6173. 'type=button data-pick=' + nowObject.pick +
  6174. ( isOpen && !calendar.disabled(nowObject) ? '' : ' disabled' ) + ' ' +
  6175. _.ariaAttr({ controls: calendar.$node[0].id }) ) +
  6176. _.node( 'button', settings.clear, "btn-flat picker__clear waves-effect",
  6177. 'type=button data-clear=1' +
  6178. ( isOpen ? '' : ' disabled' ) + ' ' +
  6179. _.ariaAttr({ controls: calendar.$node[0].id }) ) +
  6180. _.node('button', settings.close, "btn-flat picker__close waves-effect",
  6181. 'type=button data-close=true ' +
  6182. ( isOpen ? '' : ' disabled' ) + ' ' +
  6183. _.ariaAttr({ controls: calendar.$node[0].id }) ),
  6184. settings.klass.footer
  6185. ), 'picker__container__wrapper'
  6186. ) //endreturn
  6187. } //DatePicker.prototype.nodes
  6188. /**
  6189. * The date picker defaults.
  6190. */
  6191. DatePicker.defaults = (function( prefix ) {
  6192. return {
  6193. // The title label to use for the month nav buttons
  6194. labelMonthNext: 'Next month',
  6195. labelMonthPrev: 'Previous month',
  6196. // The title label to use for the dropdown selectors
  6197. labelMonthSelect: 'Select a month',
  6198. labelYearSelect: 'Select a year',
  6199. // Months and weekdays
  6200. monthsFull: [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ],
  6201. monthsShort: [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ],
  6202. weekdaysFull: [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ],
  6203. weekdaysShort: [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ],
  6204. // Materialize modified
  6205. weekdaysLetter: [ 'S', 'M', 'T', 'W', 'T', 'F', 'S' ],
  6206. // Today and clear
  6207. today: 'Today',
  6208. clear: 'Clear',
  6209. close: 'Ok',
  6210. // The format to show on the `input` element
  6211. format: 'd mmmm, yyyy',
  6212. // Classes
  6213. klass: {
  6214. table: prefix + 'table',
  6215. header: prefix + 'header',
  6216. // Materialize Added klasses
  6217. date_display: prefix + 'date-display',
  6218. day_display: prefix + 'day-display',
  6219. month_display: prefix + 'month-display',
  6220. year_display: prefix + 'year-display',
  6221. calendar_container: prefix + 'calendar-container',
  6222. // end
  6223. navPrev: prefix + 'nav--prev',
  6224. navNext: prefix + 'nav--next',
  6225. navDisabled: prefix + 'nav--disabled',
  6226. month: prefix + 'month',
  6227. year: prefix + 'year',
  6228. selectMonth: prefix + 'select--month',
  6229. selectYear: prefix + 'select--year',
  6230. weekdays: prefix + 'weekday',
  6231. day: prefix + 'day',
  6232. disabled: prefix + 'day--disabled',
  6233. selected: prefix + 'day--selected',
  6234. highlighted: prefix + 'day--highlighted',
  6235. now: prefix + 'day--today',
  6236. infocus: prefix + 'day--infocus',
  6237. outfocus: prefix + 'day--outfocus',
  6238. footer: prefix + 'footer',
  6239. buttonClear: prefix + 'button--clear',
  6240. buttonToday: prefix + 'button--today',
  6241. buttonClose: prefix + 'button--close'
  6242. }
  6243. }
  6244. })( Picker.klasses().picker + '__' )
  6245. /**
  6246. * Extend the picker to add the date picker.
  6247. */
  6248. Picker.extend( 'pickadate', DatePicker )
  6249. }));
  6250. ;/*!
  6251. * ClockPicker v0.0.7 (http://weareoutman.github.io/clockpicker/)
  6252. * Copyright 2014 Wang Shenwei.
  6253. * Licensed under MIT (https://github.com/weareoutman/clockpicker/blob/gh-pages/LICENSE)
  6254. *
  6255. * Further modified
  6256. * Copyright 2015 Ching Yaw Hao.
  6257. */
  6258. ;(function(){
  6259. var $ = window.jQuery,
  6260. $win = $(window),
  6261. $doc = $(document);
  6262. // Can I use inline svg ?
  6263. var svgNS = 'http://www.w3.org/2000/svg',
  6264. svgSupported = 'SVGAngle' in window && (function() {
  6265. var supported,
  6266. el = document.createElement('div');
  6267. el.innerHTML = '<svg/>';
  6268. supported = (el.firstChild && el.firstChild.namespaceURI) == svgNS;
  6269. el.innerHTML = '';
  6270. return supported;
  6271. })();
  6272. // Can I use transition ?
  6273. var transitionSupported = (function() {
  6274. var style = document.createElement('div').style;
  6275. return 'transition' in style ||
  6276. 'WebkitTransition' in style ||
  6277. 'MozTransition' in style ||
  6278. 'msTransition' in style ||
  6279. 'OTransition' in style;
  6280. })();
  6281. // Listen touch events in touch screen device, instead of mouse events in desktop.
  6282. var touchSupported = 'ontouchstart' in window,
  6283. mousedownEvent = 'mousedown' + ( touchSupported ? ' touchstart' : ''),
  6284. mousemoveEvent = 'mousemove.clockpicker' + ( touchSupported ? ' touchmove.clockpicker' : ''),
  6285. mouseupEvent = 'mouseup.clockpicker' + ( touchSupported ? ' touchend.clockpicker' : '');
  6286. // Vibrate the device if supported
  6287. var vibrate = navigator.vibrate ? 'vibrate' : navigator.webkitVibrate ? 'webkitVibrate' : null;
  6288. function createSvgElement(name) {
  6289. return document.createElementNS(svgNS, name);
  6290. }
  6291. function leadingZero(num) {
  6292. return (num < 10 ? '0' : '') + num;
  6293. }
  6294. // Get a unique id
  6295. var idCounter = 0;
  6296. function uniqueId(prefix) {
  6297. var id = ++idCounter + '';
  6298. return prefix ? prefix + id : id;
  6299. }
  6300. // Clock size
  6301. var dialRadius = 135,
  6302. outerRadius = 105,
  6303. // innerRadius = 80 on 12 hour clock
  6304. innerRadius = 80,
  6305. tickRadius = 20,
  6306. diameter = dialRadius * 2,
  6307. duration = transitionSupported ? 350 : 1;
  6308. // Popover template
  6309. var tpl = [
  6310. '<div class="clockpicker picker">',
  6311. '<div class="picker__holder">',
  6312. '<div class="picker__frame">',
  6313. '<div class="picker__wrap">',
  6314. '<div class="picker__box">',
  6315. '<div class="picker__date-display">',
  6316. '<div class="clockpicker-display">',
  6317. '<div class="clockpicker-display-column">',
  6318. '<span class="clockpicker-span-hours text-primary"></span>',
  6319. ':',
  6320. '<span class="clockpicker-span-minutes"></span>',
  6321. '</div>',
  6322. '<div class="clockpicker-display-column clockpicker-display-am-pm">',
  6323. '<div class="clockpicker-span-am-pm"></div>',
  6324. '</div>',
  6325. '</div>',
  6326. '</div>',
  6327. '<div class="picker__container__wrapper">',
  6328. '<div class="picker__calendar-container">',
  6329. '<div class="clockpicker-plate">',
  6330. '<div class="clockpicker-canvas"></div>',
  6331. '<div class="clockpicker-dial clockpicker-hours"></div>',
  6332. '<div class="clockpicker-dial clockpicker-minutes clockpicker-dial-out"></div>',
  6333. '</div>',
  6334. '<div class="clockpicker-am-pm-block">',
  6335. '</div>',
  6336. '</div>',
  6337. '<div class="picker__footer">',
  6338. '</div>',
  6339. '</div>',
  6340. '</div>',
  6341. '</div>',
  6342. '</div>',
  6343. '</div>',
  6344. '</div>'
  6345. ].join('');
  6346. // ClockPicker
  6347. function ClockPicker(element, options) {
  6348. var popover = $(tpl),
  6349. plate = popover.find('.clockpicker-plate'),
  6350. holder = popover.find('.picker__holder'),
  6351. hoursView = popover.find('.clockpicker-hours'),
  6352. minutesView = popover.find('.clockpicker-minutes'),
  6353. amPmBlock = popover.find('.clockpicker-am-pm-block'),
  6354. isInput = element.prop('tagName') === 'INPUT',
  6355. input = isInput ? element : element.find('input'),
  6356. label = $("label[for=" + input.attr("id") + "]"),
  6357. self = this;
  6358. this.id = uniqueId('cp');
  6359. this.element = element;
  6360. this.holder = holder;
  6361. this.options = options;
  6362. this.isAppended = false;
  6363. this.isShown = false;
  6364. this.currentView = 'hours';
  6365. this.isInput = isInput;
  6366. this.input = input;
  6367. this.label = label;
  6368. this.popover = popover;
  6369. this.plate = plate;
  6370. this.hoursView = hoursView;
  6371. this.minutesView = minutesView;
  6372. this.amPmBlock = amPmBlock;
  6373. this.spanHours = popover.find('.clockpicker-span-hours');
  6374. this.spanMinutes = popover.find('.clockpicker-span-minutes');
  6375. this.spanAmPm = popover.find('.clockpicker-span-am-pm');
  6376. this.footer = popover.find('.picker__footer');
  6377. this.amOrPm = "PM";
  6378. // Setup for for 12 hour clock if option is selected
  6379. if (options.twelvehour) {
  6380. if (!options.ampmclickable) {
  6381. this.spanAmPm.empty();
  6382. $('<div id="click-am">AM</div>').appendTo(this.spanAmPm);
  6383. $('<div id="click-pm">PM</div>').appendTo(this.spanAmPm);
  6384. }
  6385. else {
  6386. this.spanAmPm.empty();
  6387. $('<div id="click-am">AM</div>').on("click", function() {
  6388. self.spanAmPm.children('#click-am').addClass("text-primary");
  6389. self.spanAmPm.children('#click-pm').removeClass("text-primary");
  6390. self.amOrPm = "AM";
  6391. }).appendTo(this.spanAmPm);
  6392. $('<div id="click-pm">PM</div>').on("click", function() {
  6393. self.spanAmPm.children('#click-pm').addClass("text-primary");
  6394. self.spanAmPm.children('#click-am').removeClass("text-primary");
  6395. self.amOrPm = 'PM';
  6396. }).appendTo(this.spanAmPm);
  6397. }
  6398. }
  6399. // Add buttons to footer
  6400. $('<button type="button" class="btn-flat picker__clear" tabindex="' + (options.twelvehour? '3' : '1') + '">' + options.cleartext + '</button>').click($.proxy(this.clear, this)).appendTo(this.footer);
  6401. $('<button type="button" class="btn-flat picker__close" tabindex="' + (options.twelvehour? '3' : '1') + '">' + options.canceltext + '</button>').click($.proxy(this.hide, this)).appendTo(this.footer);
  6402. $('<button type="button" class="btn-flat picker__close" tabindex="' + (options.twelvehour? '3' : '1') + '">' + options.donetext + '</button>').click($.proxy(this.done, this)).appendTo(this.footer);
  6403. this.spanHours.click($.proxy(this.toggleView, this, 'hours'));
  6404. this.spanMinutes.click($.proxy(this.toggleView, this, 'minutes'));
  6405. // Show or toggle
  6406. input.on('focus.clockpicker click.clockpicker', $.proxy(this.show, this));
  6407. // Build ticks
  6408. var tickTpl = $('<div class="clockpicker-tick"></div>'),
  6409. i, tick, radian, radius;
  6410. // Hours view
  6411. if (options.twelvehour) {
  6412. for (i = 1; i < 13; i += 1) {
  6413. tick = tickTpl.clone();
  6414. radian = i / 6 * Math.PI;
  6415. radius = outerRadius;
  6416. tick.css({
  6417. left: dialRadius + Math.sin(radian) * radius - tickRadius,
  6418. top: dialRadius - Math.cos(radian) * radius - tickRadius
  6419. });
  6420. tick.html(i === 0 ? '00' : i);
  6421. hoursView.append(tick);
  6422. tick.on(mousedownEvent, mousedown);
  6423. }
  6424. } else {
  6425. for (i = 0; i < 24; i += 1) {
  6426. tick = tickTpl.clone();
  6427. radian = i / 6 * Math.PI;
  6428. var inner = i > 0 && i < 13;
  6429. radius = inner ? innerRadius : outerRadius;
  6430. tick.css({
  6431. left: dialRadius + Math.sin(radian) * radius - tickRadius,
  6432. top: dialRadius - Math.cos(radian) * radius - tickRadius
  6433. });
  6434. tick.html(i === 0 ? '00' : i);
  6435. hoursView.append(tick);
  6436. tick.on(mousedownEvent, mousedown);
  6437. }
  6438. }
  6439. // Minutes view
  6440. for (i = 0; i < 60; i += 5) {
  6441. tick = tickTpl.clone();
  6442. radian = i / 30 * Math.PI;
  6443. tick.css({
  6444. left: dialRadius + Math.sin(radian) * outerRadius - tickRadius,
  6445. top: dialRadius - Math.cos(radian) * outerRadius - tickRadius
  6446. });
  6447. tick.html(leadingZero(i));
  6448. minutesView.append(tick);
  6449. tick.on(mousedownEvent, mousedown);
  6450. }
  6451. // Clicking on minutes view space
  6452. plate.on(mousedownEvent, function(e) {
  6453. if ($(e.target).closest('.clockpicker-tick').length === 0) {
  6454. mousedown(e, true);
  6455. }
  6456. });
  6457. // Mousedown or touchstart
  6458. function mousedown(e, space) {
  6459. var offset = plate.offset(),
  6460. isTouch = /^touch/.test(e.type),
  6461. x0 = offset.left + dialRadius,
  6462. y0 = offset.top + dialRadius,
  6463. dx = (isTouch ? e.originalEvent.touches[0] : e).pageX - x0,
  6464. dy = (isTouch ? e.originalEvent.touches[0] : e).pageY - y0,
  6465. z = Math.sqrt(dx * dx + dy * dy),
  6466. moved = false;
  6467. // When clicking on minutes view space, check the mouse position
  6468. if (space && (z < outerRadius - tickRadius || z > outerRadius + tickRadius)) {
  6469. return;
  6470. }
  6471. e.preventDefault();
  6472. // Set cursor style of body after 200ms
  6473. var movingTimer = setTimeout(function(){
  6474. self.popover.addClass('clockpicker-moving');
  6475. }, 200);
  6476. // Clock
  6477. self.setHand(dx, dy, !space, true);
  6478. // Mousemove on document
  6479. $doc.off(mousemoveEvent).on(mousemoveEvent, function(e){
  6480. e.preventDefault();
  6481. var isTouch = /^touch/.test(e.type),
  6482. x = (isTouch ? e.originalEvent.touches[0] : e).pageX - x0,
  6483. y = (isTouch ? e.originalEvent.touches[0] : e).pageY - y0;
  6484. if (! moved && x === dx && y === dy) {
  6485. // Clicking in chrome on windows will trigger a mousemove event
  6486. return;
  6487. }
  6488. moved = true;
  6489. self.setHand(x, y, false, true);
  6490. });
  6491. // Mouseup on document
  6492. $doc.off(mouseupEvent).on(mouseupEvent, function(e) {
  6493. $doc.off(mouseupEvent);
  6494. e.preventDefault();
  6495. var isTouch = /^touch/.test(e.type),
  6496. x = (isTouch ? e.originalEvent.changedTouches[0] : e).pageX - x0,
  6497. y = (isTouch ? e.originalEvent.changedTouches[0] : e).pageY - y0;
  6498. if ((space || moved) && x === dx && y === dy) {
  6499. self.setHand(x, y);
  6500. }
  6501. if (self.currentView === 'hours') {
  6502. self.toggleView('minutes', duration / 2);
  6503. } else if (options.autoclose) {
  6504. self.minutesView.addClass('clockpicker-dial-out');
  6505. setTimeout(function(){
  6506. self.done();
  6507. }, duration / 2);
  6508. }
  6509. plate.prepend(canvas);
  6510. // Reset cursor style of body
  6511. clearTimeout(movingTimer);
  6512. self.popover.removeClass('clockpicker-moving');
  6513. // Unbind mousemove event
  6514. $doc.off(mousemoveEvent);
  6515. });
  6516. }
  6517. if (svgSupported) {
  6518. // Draw clock hands and others
  6519. var canvas = popover.find('.clockpicker-canvas'),
  6520. svg = createSvgElement('svg');
  6521. svg.setAttribute('class', 'clockpicker-svg');
  6522. svg.setAttribute('width', diameter);
  6523. svg.setAttribute('height', diameter);
  6524. var g = createSvgElement('g');
  6525. g.setAttribute('transform', 'translate(' + dialRadius + ',' + dialRadius + ')');
  6526. var bearing = createSvgElement('circle');
  6527. bearing.setAttribute('class', 'clockpicker-canvas-bearing');
  6528. bearing.setAttribute('cx', 0);
  6529. bearing.setAttribute('cy', 0);
  6530. bearing.setAttribute('r', 4);
  6531. var hand = createSvgElement('line');
  6532. hand.setAttribute('x1', 0);
  6533. hand.setAttribute('y1', 0);
  6534. var bg = createSvgElement('circle');
  6535. bg.setAttribute('class', 'clockpicker-canvas-bg');
  6536. bg.setAttribute('r', tickRadius);
  6537. g.appendChild(hand);
  6538. g.appendChild(bg);
  6539. g.appendChild(bearing);
  6540. svg.appendChild(g);
  6541. canvas.append(svg);
  6542. this.hand = hand;
  6543. this.bg = bg;
  6544. this.bearing = bearing;
  6545. this.g = g;
  6546. this.canvas = canvas;
  6547. }
  6548. raiseCallback(this.options.init);
  6549. }
  6550. function raiseCallback(callbackFunction) {
  6551. if (callbackFunction && typeof callbackFunction === "function")
  6552. callbackFunction();
  6553. }
  6554. // Default options
  6555. ClockPicker.DEFAULTS = {
  6556. 'default': '', // default time, 'now' or '13:14' e.g.
  6557. fromnow: 0, // set default time to * milliseconds from now (using with default = 'now')
  6558. donetext: 'Ok', // done button text
  6559. cleartext: 'Clear',
  6560. canceltext: 'Cancel',
  6561. autoclose: false, // auto close when minute is selected
  6562. ampmclickable: true, // set am/pm button on itself
  6563. darktheme: false, // set to dark theme
  6564. twelvehour: true, // change to 12 hour AM/PM clock from 24 hour
  6565. vibrate: true // vibrate the device when dragging clock hand
  6566. };
  6567. // Show or hide popover
  6568. ClockPicker.prototype.toggle = function() {
  6569. this[this.isShown ? 'hide' : 'show']();
  6570. };
  6571. // Set popover position
  6572. ClockPicker.prototype.locate = function() {
  6573. var element = this.element,
  6574. popover = this.popover,
  6575. offset = element.offset(),
  6576. width = element.outerWidth(),
  6577. height = element.outerHeight(),
  6578. align = this.options.align,
  6579. self = this;
  6580. popover.show();
  6581. };
  6582. // Show popover
  6583. ClockPicker.prototype.show = function(e){
  6584. // Not show again
  6585. if (this.isShown) {
  6586. return;
  6587. }
  6588. raiseCallback(this.options.beforeShow);
  6589. $(':input').each(function() {
  6590. $(this).attr('tabindex', -1);
  6591. })
  6592. var self = this;
  6593. // Initialize
  6594. this.input.blur();
  6595. this.popover.addClass('picker--opened');
  6596. this.input.addClass('picker__input picker__input--active');
  6597. $(document.body).css('overflow', 'hidden');
  6598. // Get the time
  6599. var value = ((this.input.prop('value') || this.options['default'] || '') + '').split(':');
  6600. if (this.options.twelvehour && !(typeof value[1] === 'undefined')) {
  6601. if (value[1].indexOf("AM") > 0){
  6602. this.amOrPm = 'AM';
  6603. } else {
  6604. this.amOrPm = 'PM';
  6605. }
  6606. value[1] = value[1].replace("AM", "").replace("PM", "");
  6607. }
  6608. if (value[0] === 'now') {
  6609. var now = new Date(+ new Date() + this.options.fromnow);
  6610. value = [
  6611. now.getHours(),
  6612. now.getMinutes()
  6613. ];
  6614. }
  6615. this.hours = + value[0] || 0;
  6616. this.minutes = + value[1] || 0;
  6617. this.spanHours.html(this.hours);
  6618. this.spanMinutes.html(leadingZero(this.minutes));
  6619. if (!this.isAppended) {
  6620. // Append popover to body
  6621. this.popover.insertAfter(this.input);
  6622. if (this.options.twelvehour) {
  6623. if (this.amOrPm === 'PM'){
  6624. this.spanAmPm.children('#click-pm').addClass("text-primary");
  6625. this.spanAmPm.children('#click-am').removeClass("text-primary");
  6626. } else {
  6627. this.spanAmPm.children('#click-am').addClass("text-primary");
  6628. this.spanAmPm.children('#click-pm').removeClass("text-primary");
  6629. }
  6630. }
  6631. // Reset position when resize
  6632. $win.on('resize.clockpicker' + this.id, function() {
  6633. if (self.isShown) {
  6634. self.locate();
  6635. }
  6636. });
  6637. this.isAppended = true;
  6638. }
  6639. // Toggle to hours view
  6640. this.toggleView('hours');
  6641. // Set position
  6642. this.locate();
  6643. this.isShown = true;
  6644. // Hide when clicking or tabbing on any element except the clock and input
  6645. $doc.on('click.clockpicker.' + this.id + ' focusin.clockpicker.' + this.id, function(e) {
  6646. var target = $(e.target);
  6647. if (target.closest(self.popover.find('.picker__wrap')).length === 0 && target.closest(self.input).length === 0) {
  6648. self.hide();
  6649. }
  6650. });
  6651. // Hide when ESC is pressed
  6652. $doc.on('keyup.clockpicker.' + this.id, function(e){
  6653. if (e.keyCode === 27) {
  6654. self.hide();
  6655. }
  6656. });
  6657. raiseCallback(this.options.afterShow);
  6658. };
  6659. // Hide popover
  6660. ClockPicker.prototype.hide = function() {
  6661. raiseCallback(this.options.beforeHide);
  6662. this.input.removeClass('picker__input picker__input--active');
  6663. this.popover.removeClass('picker--opened');
  6664. $(document.body).css('overflow', 'visible');
  6665. this.isShown = false;
  6666. $(':input').each(function(index) {
  6667. $(this).attr('tabindex', index + 1);
  6668. });
  6669. // Unbinding events on document
  6670. $doc.off('click.clockpicker.' + this.id + ' focusin.clockpicker.' + this.id);
  6671. $doc.off('keyup.clockpicker.' + this.id);
  6672. this.popover.hide();
  6673. raiseCallback(this.options.afterHide);
  6674. };
  6675. // Toggle to hours or minutes view
  6676. ClockPicker.prototype.toggleView = function(view, delay) {
  6677. var raiseAfterHourSelect = false;
  6678. if (view === 'minutes' && $(this.hoursView).css("visibility") === "visible") {
  6679. raiseCallback(this.options.beforeHourSelect);
  6680. raiseAfterHourSelect = true;
  6681. }
  6682. var isHours = view === 'hours',
  6683. nextView = isHours ? this.hoursView : this.minutesView,
  6684. hideView = isHours ? this.minutesView : this.hoursView;
  6685. this.currentView = view;
  6686. this.spanHours.toggleClass('text-primary', isHours);
  6687. this.spanMinutes.toggleClass('text-primary', ! isHours);
  6688. // Let's make transitions
  6689. hideView.addClass('clockpicker-dial-out');
  6690. nextView.css('visibility', 'visible').removeClass('clockpicker-dial-out');
  6691. // Reset clock hand
  6692. this.resetClock(delay);
  6693. // After transitions ended
  6694. clearTimeout(this.toggleViewTimer);
  6695. this.toggleViewTimer = setTimeout(function() {
  6696. hideView.css('visibility', 'hidden');
  6697. }, duration);
  6698. if (raiseAfterHourSelect) {
  6699. raiseCallback(this.options.afterHourSelect);
  6700. }
  6701. };
  6702. // Reset clock hand
  6703. ClockPicker.prototype.resetClock = function(delay) {
  6704. var view = this.currentView,
  6705. value = this[view],
  6706. isHours = view === 'hours',
  6707. unit = Math.PI / (isHours ? 6 : 30),
  6708. radian = value * unit,
  6709. radius = isHours && value > 0 && value < 13 ? innerRadius : outerRadius,
  6710. x = Math.sin(radian) * radius,
  6711. y = - Math.cos(radian) * radius,
  6712. self = this;
  6713. if (svgSupported && delay) {
  6714. self.canvas.addClass('clockpicker-canvas-out');
  6715. setTimeout(function(){
  6716. self.canvas.removeClass('clockpicker-canvas-out');
  6717. self.setHand(x, y);
  6718. }, delay);
  6719. } else
  6720. this.setHand(x, y);
  6721. };
  6722. // Set clock hand to (x, y)
  6723. ClockPicker.prototype.setHand = function(x, y, roundBy5, dragging) {
  6724. var radian = Math.atan2(x, - y),
  6725. isHours = this.currentView === 'hours',
  6726. unit = Math.PI / (isHours || roundBy5? 6 : 30),
  6727. z = Math.sqrt(x * x + y * y),
  6728. options = this.options,
  6729. inner = isHours && z < (outerRadius + innerRadius) / 2,
  6730. radius = inner ? innerRadius : outerRadius,
  6731. value;
  6732. if (options.twelvehour) {
  6733. radius = outerRadius;
  6734. }
  6735. // Radian should in range [0, 2PI]
  6736. if (radian < 0) {
  6737. radian = Math.PI * 2 + radian;
  6738. }
  6739. // Get the round value
  6740. value = Math.round(radian / unit);
  6741. // Get the round radian
  6742. radian = value * unit;
  6743. // Correct the hours or minutes
  6744. if (options.twelvehour) {
  6745. if (isHours) {
  6746. if (value === 0)
  6747. value = 12;
  6748. } else {
  6749. if (roundBy5)
  6750. value *= 5;
  6751. if (value === 60)
  6752. value = 0;
  6753. }
  6754. } else {
  6755. if (isHours) {
  6756. if (value === 12)
  6757. value = 0;
  6758. value = inner ? (value === 0 ? 12 : value) : value === 0 ? 0 : value + 12;
  6759. } else {
  6760. if (roundBy5)
  6761. value *= 5;
  6762. if (value === 60)
  6763. value = 0;
  6764. }
  6765. }
  6766. // Once hours or minutes changed, vibrate the device
  6767. if (this[this.currentView] !== value) {
  6768. if (vibrate && this.options.vibrate) {
  6769. // Do not vibrate too frequently
  6770. if (!this.vibrateTimer) {
  6771. navigator[vibrate](10);
  6772. this.vibrateTimer = setTimeout($.proxy(function(){
  6773. this.vibrateTimer = null;
  6774. }, this), 100);
  6775. }
  6776. }
  6777. }
  6778. this[this.currentView] = value;
  6779. if (isHours) {
  6780. this['spanHours'].html(value);
  6781. } else {
  6782. this['spanMinutes'].html(leadingZero(value));
  6783. }
  6784. // If svg is not supported, just add an active class to the tick
  6785. if (!svgSupported) {
  6786. this[isHours ? 'hoursView' : 'minutesView'].find('.clockpicker-tick').each(function(){
  6787. var tick = $(this);
  6788. tick.toggleClass('active', value === + tick.html());
  6789. });
  6790. return;
  6791. }
  6792. // Set clock hand and others' position
  6793. var cx1 = Math.sin(radian) * (radius - tickRadius),
  6794. cy1 = - Math.cos(radian) * (radius - tickRadius),
  6795. cx2 = Math.sin(radian) * radius,
  6796. cy2 = - Math.cos(radian) * radius;
  6797. this.hand.setAttribute('x2', cx1);
  6798. this.hand.setAttribute('y2', cy1);
  6799. this.bg.setAttribute('cx', cx2);
  6800. this.bg.setAttribute('cy', cy2);
  6801. };
  6802. // Hours and minutes are selected
  6803. ClockPicker.prototype.done = function() {
  6804. raiseCallback(this.options.beforeDone);
  6805. this.hide();
  6806. this.label.addClass('active');
  6807. var last = this.input.prop('value'),
  6808. value = leadingZero(this.hours) + ':' + leadingZero(this.minutes);
  6809. if (this.options.twelvehour) {
  6810. value = value + this.amOrPm;
  6811. }
  6812. this.input.prop('value', value);
  6813. if (value !== last) {
  6814. this.input.triggerHandler('change');
  6815. if (!this.isInput) {
  6816. this.element.trigger('change');
  6817. }
  6818. }
  6819. if (this.options.autoclose)
  6820. this.input.trigger('blur');
  6821. raiseCallback(this.options.afterDone);
  6822. };
  6823. // Clear input field
  6824. ClockPicker.prototype.clear = function() {
  6825. this.hide();
  6826. this.label.removeClass('active');
  6827. var last = this.input.prop('value'),
  6828. value = '';
  6829. this.input.prop('value', value);
  6830. if (value !== last) {
  6831. this.input.triggerHandler('change');
  6832. if (! this.isInput) {
  6833. this.element.trigger('change');
  6834. }
  6835. }
  6836. if (this.options.autoclose) {
  6837. this.input.trigger('blur');
  6838. }
  6839. };
  6840. // Remove clockpicker from input
  6841. ClockPicker.prototype.remove = function() {
  6842. this.element.removeData('clockpicker');
  6843. this.input.off('focus.clockpicker click.clockpicker');
  6844. if (this.isShown) {
  6845. this.hide();
  6846. }
  6847. if (this.isAppended) {
  6848. $win.off('resize.clockpicker' + this.id);
  6849. this.popover.remove();
  6850. }
  6851. };
  6852. // Extends $.fn.clockpicker
  6853. $.fn.pickatime = function(option){
  6854. var args = Array.prototype.slice.call(arguments, 1);
  6855. return this.each(function(){
  6856. var $this = $(this),
  6857. data = $this.data('clockpicker');
  6858. if (!data) {
  6859. var options = $.extend({}, ClockPicker.DEFAULTS, $this.data(), typeof option == 'object' && option);
  6860. $this.data('clockpicker', new ClockPicker($this, options));
  6861. } else {
  6862. // Manual operatsions. show, hide, remove, e.g.
  6863. if (typeof data[option] === 'function') {
  6864. data[option].apply(data, args);
  6865. }
  6866. }
  6867. });
  6868. };
  6869. }());
  6870. ;(function ($) {
  6871. $.fn.characterCounter = function(){
  6872. return this.each(function(){
  6873. var $input = $(this);
  6874. var $counterElement = $input.parent().find('span[class="character-counter"]');
  6875. // character counter has already been added appended to the parent container
  6876. if ($counterElement.length) {
  6877. return;
  6878. }
  6879. var itHasLengthAttribute = $input.attr('data-length') !== undefined;
  6880. if(itHasLengthAttribute){
  6881. $input.on('input', updateCounter);
  6882. $input.on('focus', updateCounter);
  6883. $input.on('blur', removeCounterElement);
  6884. addCounterElement($input);
  6885. }
  6886. });
  6887. };
  6888. function updateCounter(){
  6889. var maxLength = +$(this).attr('data-length'),
  6890. actualLength = +$(this).val().length,
  6891. isValidLength = actualLength <= maxLength;
  6892. $(this).parent().find('span[class="character-counter"]')
  6893. .html( actualLength + '/' + maxLength);
  6894. addInputStyle(isValidLength, $(this));
  6895. }
  6896. function addCounterElement($input) {
  6897. var $counterElement = $input.parent().find('span[class="character-counter"]');
  6898. if ($counterElement.length) {
  6899. return;
  6900. }
  6901. $counterElement = $('<span/>')
  6902. .addClass('character-counter')
  6903. .css('float','right')
  6904. .css('font-size','12px')
  6905. .css('height', 1);
  6906. $input.parent().append($counterElement);
  6907. }
  6908. function removeCounterElement(){
  6909. $(this).parent().find('span[class="character-counter"]').html('');
  6910. }
  6911. function addInputStyle(isValidLength, $input){
  6912. var inputHasInvalidClass = $input.hasClass('invalid');
  6913. if (isValidLength && inputHasInvalidClass) {
  6914. $input.removeClass('invalid');
  6915. }
  6916. else if(!isValidLength && !inputHasInvalidClass){
  6917. $input.removeClass('valid');
  6918. $input.addClass('invalid');
  6919. }
  6920. }
  6921. $(document).ready(function(){
  6922. $('input, textarea').characterCounter();
  6923. });
  6924. }( jQuery ));
  6925. ;(function ($) {
  6926. var methods = {
  6927. init : function(options) {
  6928. var defaults = {
  6929. duration: 200, // ms
  6930. dist: -100, // zoom scale TODO: make this more intuitive as an option
  6931. shift: 0, // spacing for center image
  6932. padding: 0, // Padding between non center items
  6933. fullWidth: false, // Change to full width styles
  6934. indicators: false, // Toggle indicators
  6935. noWrap: false, // Don't wrap around and cycle through items.
  6936. onCycleTo: null // Callback for when a new slide is cycled to.
  6937. };
  6938. options = $.extend(defaults, options);
  6939. var namespace = Materialize.objectSelectorString($(this));
  6940. return this.each(function(i) {
  6941. var uniqueNamespace = namespace+i;
  6942. var images, item_width, item_height, offset, center, pressed, dim, count,
  6943. reference, referenceY, amplitude, target, velocity, scrolling,
  6944. xform, frame, timestamp, ticker, dragged, vertical_dragged;
  6945. var $indicators = $('<ul class="indicators"></ul>');
  6946. var scrollingTimeout = null;
  6947. var oneTimeCallback = null;
  6948. // Initialize
  6949. var view = $(this);
  6950. var showIndicators = view.attr('data-indicators') || options.indicators;
  6951. // Options
  6952. var setCarouselHeight = function() {
  6953. var firstImage = view.find('.carousel-item img').first();
  6954. if (firstImage.length) {
  6955. if (firstImage.prop('complete')) {
  6956. view.css('height', firstImage.height());
  6957. } else {
  6958. firstImage.on('load', function(){
  6959. view.css('height', $(this).height());
  6960. });
  6961. }
  6962. } else {
  6963. var imageHeight = view.find('.carousel-item').first().height();
  6964. view.css('height', imageHeight);
  6965. }
  6966. };
  6967. if (options.fullWidth) {
  6968. options.dist = 0;
  6969. setCarouselHeight();
  6970. // Offset fixed items when indicators.
  6971. if (showIndicators) {
  6972. view.find('.carousel-fixed-item').addClass('with-indicators');
  6973. }
  6974. }
  6975. // Don't double initialize.
  6976. if (view.hasClass('initialized')) {
  6977. // Recalculate variables
  6978. $(window).trigger('resize');
  6979. // Redraw carousel.
  6980. $(this).trigger('carouselNext', [0.000001]);
  6981. return true;
  6982. }
  6983. view.addClass('initialized');
  6984. pressed = false;
  6985. offset = target = 0;
  6986. images = [];
  6987. item_width = view.find('.carousel-item').first().innerWidth();
  6988. item_height = view.find('.carousel-item').first().innerHeight();
  6989. dim = item_width * 2 + options.padding;
  6990. view.find('.carousel-item').each(function (i) {
  6991. images.push($(this)[0]);
  6992. if (showIndicators) {
  6993. var $indicator = $('<li class="indicator-item"></li>');
  6994. // Add active to first by default.
  6995. if (i === 0) {
  6996. $indicator.addClass('active');
  6997. }
  6998. // Handle clicks on indicators.
  6999. $indicator.click(function (e) {
  7000. e.stopPropagation();
  7001. var index = $(this).index();
  7002. cycleTo(index);
  7003. });
  7004. $indicators.append($indicator);
  7005. }
  7006. });
  7007. if (showIndicators) {
  7008. view.append($indicators);
  7009. }
  7010. count = images.length;
  7011. function setupEvents() {
  7012. if (typeof window.ontouchstart !== 'undefined') {
  7013. view[0].addEventListener('touchstart', tap);
  7014. view[0].addEventListener('touchmove', drag);
  7015. view[0].addEventListener('touchend', release);
  7016. }
  7017. view[0].addEventListener('mousedown', tap);
  7018. view[0].addEventListener('mousemove', drag);
  7019. view[0].addEventListener('mouseup', release);
  7020. view[0].addEventListener('mouseleave', release);
  7021. view[0].addEventListener('click', click);
  7022. }
  7023. function xpos(e) {
  7024. // touch event
  7025. if (e.targetTouches && (e.targetTouches.length >= 1)) {
  7026. return e.targetTouches[0].clientX;
  7027. }
  7028. // mouse event
  7029. return e.clientX;
  7030. }
  7031. function ypos(e) {
  7032. // touch event
  7033. if (e.targetTouches && (e.targetTouches.length >= 1)) {
  7034. return e.targetTouches[0].clientY;
  7035. }
  7036. // mouse event
  7037. return e.clientY;
  7038. }
  7039. function wrap(x) {
  7040. return (x >= count) ? (x % count) : (x < 0) ? wrap(count + (x % count)) : x;
  7041. }
  7042. function scroll(x) {
  7043. // Track scrolling state
  7044. scrolling = true;
  7045. if (!view.hasClass('scrolling')) {
  7046. view.addClass('scrolling');
  7047. }
  7048. if (scrollingTimeout != null) {
  7049. window.clearTimeout(scrollingTimeout);
  7050. }
  7051. scrollingTimeout = window.setTimeout(function() {
  7052. scrolling = false;
  7053. view.removeClass('scrolling');
  7054. }, options.duration);
  7055. // Start actual scroll
  7056. var i, half, delta, dir, tween, el, alignment, xTranslation;
  7057. var lastCenter = center;
  7058. offset = (typeof x === 'number') ? x : offset;
  7059. center = Math.floor((offset + dim / 2) / dim);
  7060. delta = offset - center * dim;
  7061. dir = (delta < 0) ? 1 : -1;
  7062. tween = -dir * delta * 2 / dim;
  7063. half = count >> 1;
  7064. if (!options.fullWidth) {
  7065. alignment = 'translateX(' + (view[0].clientWidth - item_width) / 2 + 'px) ';
  7066. alignment += 'translateY(' + (view[0].clientHeight - item_height) / 2 + 'px)';
  7067. } else {
  7068. alignment = 'translateX(0)';
  7069. }
  7070. // Set indicator active
  7071. if (showIndicators) {
  7072. var diff = (center % count);
  7073. var activeIndicator = $indicators.find('.indicator-item.active');
  7074. if (activeIndicator.index() !== diff) {
  7075. activeIndicator.removeClass('active');
  7076. $indicators.find('.indicator-item').eq(diff).addClass('active');
  7077. }
  7078. }
  7079. // center
  7080. // Don't show wrapped items.
  7081. if (!options.noWrap || (center >= 0 && center < count)) {
  7082. el = images[wrap(center)];
  7083. // Add active class to center item.
  7084. if (!$(el).hasClass('active')) {
  7085. view.find('.carousel-item').removeClass('active');
  7086. $(el).addClass('active');
  7087. }
  7088. el.style[xform] = alignment +
  7089. ' translateX(' + (-delta / 2) + 'px)' +
  7090. ' translateX(' + (dir * options.shift * tween * i) + 'px)' +
  7091. ' translateZ(' + (options.dist * tween) + 'px)';
  7092. el.style.zIndex = 0;
  7093. if (options.fullWidth) { tweenedOpacity = 1; }
  7094. else { tweenedOpacity = 1 - 0.2 * tween; }
  7095. el.style.opacity = tweenedOpacity;
  7096. el.style.display = 'block';
  7097. }
  7098. for (i = 1; i <= half; ++i) {
  7099. // right side
  7100. if (options.fullWidth) {
  7101. zTranslation = options.dist;
  7102. tweenedOpacity = (i === half && delta < 0) ? 1 - tween : 1;
  7103. } else {
  7104. zTranslation = options.dist * (i * 2 + tween * dir);
  7105. tweenedOpacity = 1 - 0.2 * (i * 2 + tween * dir);
  7106. }
  7107. // Don't show wrapped items.
  7108. if (!options.noWrap || center + i < count) {
  7109. el = images[wrap(center + i)];
  7110. el.style[xform] = alignment +
  7111. ' translateX(' + (options.shift + (dim * i - delta) / 2) + 'px)' +
  7112. ' translateZ(' + zTranslation + 'px)';
  7113. el.style.zIndex = -i;
  7114. el.style.opacity = tweenedOpacity;
  7115. el.style.display = 'block';
  7116. }
  7117. // left side
  7118. if (options.fullWidth) {
  7119. zTranslation = options.dist;
  7120. tweenedOpacity = (i === half && delta > 0) ? 1 - tween : 1;
  7121. } else {
  7122. zTranslation = options.dist * (i * 2 - tween * dir);
  7123. tweenedOpacity = 1 - 0.2 * (i * 2 - tween * dir);
  7124. }
  7125. // Don't show wrapped items.
  7126. if (!options.noWrap || center - i >= 0) {
  7127. el = images[wrap(center - i)];
  7128. el.style[xform] = alignment +
  7129. ' translateX(' + (-options.shift + (-dim * i - delta) / 2) + 'px)' +
  7130. ' translateZ(' + zTranslation + 'px)';
  7131. el.style.zIndex = -i;
  7132. el.style.opacity = tweenedOpacity;
  7133. el.style.display = 'block';
  7134. }
  7135. }
  7136. // center
  7137. // Don't show wrapped items.
  7138. if (!options.noWrap || (center >= 0 && center < count)) {
  7139. el = images[wrap(center)];
  7140. el.style[xform] = alignment +
  7141. ' translateX(' + (-delta / 2) + 'px)' +
  7142. ' translateX(' + (dir * options.shift * tween) + 'px)' +
  7143. ' translateZ(' + (options.dist * tween) + 'px)';
  7144. el.style.zIndex = 0;
  7145. if (options.fullWidth) { tweenedOpacity = 1; }
  7146. else { tweenedOpacity = 1 - 0.2 * tween; }
  7147. el.style.opacity = tweenedOpacity;
  7148. el.style.display = 'block';
  7149. }
  7150. // onCycleTo callback
  7151. if (lastCenter !== center &&
  7152. typeof(options.onCycleTo) === "function") {
  7153. var $curr_item = view.find('.carousel-item').eq(wrap(center));
  7154. options.onCycleTo.call(this, $curr_item, dragged);
  7155. }
  7156. // One time callback
  7157. if (typeof(oneTimeCallback) === "function") {
  7158. oneTimeCallback.call(this, $curr_item, dragged);
  7159. oneTimeCallback = null;
  7160. }
  7161. }
  7162. function track() {
  7163. var now, elapsed, delta, v;
  7164. now = Date.now();
  7165. elapsed = now - timestamp;
  7166. timestamp = now;
  7167. delta = offset - frame;
  7168. frame = offset;
  7169. v = 1000 * delta / (1 + elapsed);
  7170. velocity = 0.8 * v + 0.2 * velocity;
  7171. }
  7172. function autoScroll() {
  7173. var elapsed, delta;
  7174. if (amplitude) {
  7175. elapsed = Date.now() - timestamp;
  7176. delta = amplitude * Math.exp(-elapsed / options.duration);
  7177. if (delta > 2 || delta < -2) {
  7178. scroll(target - delta);
  7179. requestAnimationFrame(autoScroll);
  7180. } else {
  7181. scroll(target);
  7182. }
  7183. }
  7184. }
  7185. function click(e) {
  7186. // Disable clicks if carousel was dragged.
  7187. if (dragged) {
  7188. e.preventDefault();
  7189. e.stopPropagation();
  7190. return false;
  7191. } else if (!options.fullWidth) {
  7192. var clickedIndex = $(e.target).closest('.carousel-item').index();
  7193. var diff = wrap(center) - clickedIndex;
  7194. // Disable clicks if carousel was shifted by click
  7195. if (diff !== 0) {
  7196. e.preventDefault();
  7197. e.stopPropagation();
  7198. }
  7199. cycleTo(clickedIndex);
  7200. }
  7201. }
  7202. function cycleTo(n) {
  7203. var diff = (center % count) - n;
  7204. // Account for wraparound.
  7205. if (!options.noWrap) {
  7206. if (diff < 0) {
  7207. if (Math.abs(diff + count) < Math.abs(diff)) { diff += count; }
  7208. } else if (diff > 0) {
  7209. if (Math.abs(diff - count) < diff) { diff -= count; }
  7210. }
  7211. }
  7212. // Call prev or next accordingly.
  7213. if (diff < 0) {
  7214. view.trigger('carouselNext', [Math.abs(diff)]);
  7215. } else if (diff > 0) {
  7216. view.trigger('carouselPrev', [diff]);
  7217. }
  7218. }
  7219. function tap(e) {
  7220. if (e.type === 'mousedown') {
  7221. e.preventDefault();
  7222. }
  7223. pressed = true;
  7224. dragged = false;
  7225. vertical_dragged = false;
  7226. reference = xpos(e);
  7227. referenceY = ypos(e);
  7228. velocity = amplitude = 0;
  7229. frame = offset;
  7230. timestamp = Date.now();
  7231. clearInterval(ticker);
  7232. ticker = setInterval(track, 100);
  7233. }
  7234. function drag(e) {
  7235. var x, delta, deltaY;
  7236. if (pressed) {
  7237. x = xpos(e);
  7238. y = ypos(e);
  7239. delta = reference - x;
  7240. deltaY = Math.abs(referenceY - y);
  7241. if (deltaY < 30 && !vertical_dragged) {
  7242. // If vertical scrolling don't allow dragging.
  7243. if (delta > 2 || delta < -2) {
  7244. dragged = true;
  7245. reference = x;
  7246. scroll(offset + delta);
  7247. }
  7248. } else if (dragged) {
  7249. // If dragging don't allow vertical scroll.
  7250. e.preventDefault();
  7251. e.stopPropagation();
  7252. return false;
  7253. } else {
  7254. // Vertical scrolling.
  7255. vertical_dragged = true;
  7256. }
  7257. }
  7258. if (dragged) {
  7259. // If dragging don't allow vertical scroll.
  7260. e.preventDefault();
  7261. e.stopPropagation();
  7262. return false;
  7263. }
  7264. }
  7265. function release(e) {
  7266. if (pressed) {
  7267. pressed = false;
  7268. } else {
  7269. return;
  7270. }
  7271. clearInterval(ticker);
  7272. target = offset;
  7273. if (velocity > 10 || velocity < -10) {
  7274. amplitude = 0.9 * velocity;
  7275. target = offset + amplitude;
  7276. }
  7277. target = Math.round(target / dim) * dim;
  7278. // No wrap of items.
  7279. if (options.noWrap) {
  7280. if (target >= dim * (count - 1)) {
  7281. target = dim * (count - 1);
  7282. } else if (target < 0) {
  7283. target = 0;
  7284. }
  7285. }
  7286. amplitude = target - offset;
  7287. timestamp = Date.now();
  7288. requestAnimationFrame(autoScroll);
  7289. if (dragged) {
  7290. e.preventDefault();
  7291. e.stopPropagation();
  7292. }
  7293. return false;
  7294. }
  7295. xform = 'transform';
  7296. ['webkit', 'Moz', 'O', 'ms'].every(function (prefix) {
  7297. var e = prefix + 'Transform';
  7298. if (typeof document.body.style[e] !== 'undefined') {
  7299. xform = e;
  7300. return false;
  7301. }
  7302. return true;
  7303. });
  7304. $(window).off('resize.carousel-'+uniqueNamespace).on('resize.carousel-'+uniqueNamespace, function() {
  7305. if (options.fullWidth) {
  7306. item_width = view.find('.carousel-item').first().innerWidth();
  7307. item_height = view.find('.carousel-item').first().innerHeight();
  7308. dim = item_width * 2 + options.padding;
  7309. offset = center * 2 * item_width;
  7310. target = offset;
  7311. } else {
  7312. scroll();
  7313. }
  7314. });
  7315. setupEvents();
  7316. scroll(offset);
  7317. $(this).on('carouselNext', function(e, n, callback) {
  7318. if (n === undefined) {
  7319. n = 1;
  7320. }
  7321. if (typeof(callback) === "function") {
  7322. oneTimeCallback = callback;
  7323. }
  7324. target = (dim * Math.round(offset / dim)) + (dim * n);
  7325. if (offset !== target) {
  7326. amplitude = target - offset;
  7327. timestamp = Date.now();
  7328. requestAnimationFrame(autoScroll);
  7329. }
  7330. });
  7331. $(this).on('carouselPrev', function(e, n, callback) {
  7332. if (n === undefined) {
  7333. n = 1;
  7334. }
  7335. if (typeof(callback) === "function") {
  7336. oneTimeCallback = callback;
  7337. }
  7338. target = (dim * Math.round(offset / dim)) - (dim * n);
  7339. if (offset !== target) {
  7340. amplitude = target - offset;
  7341. timestamp = Date.now();
  7342. requestAnimationFrame(autoScroll);
  7343. }
  7344. });
  7345. $(this).on('carouselSet', function(e, n, callback) {
  7346. if (n === undefined) {
  7347. n = 0;
  7348. }
  7349. if (typeof(callback) === "function") {
  7350. oneTimeCallback = callback;
  7351. }
  7352. cycleTo(n);
  7353. });
  7354. });
  7355. },
  7356. next : function(n, callback) {
  7357. $(this).trigger('carouselNext', [n, callback]);
  7358. },
  7359. prev : function(n, callback) {
  7360. $(this).trigger('carouselPrev', [n, callback]);
  7361. },
  7362. set : function(n, callback) {
  7363. $(this).trigger('carouselSet', [n, callback]);
  7364. }
  7365. };
  7366. $.fn.carousel = function(methodOrOptions) {
  7367. if ( methods[methodOrOptions] ) {
  7368. return methods[ methodOrOptions ].apply( this, Array.prototype.slice.call( arguments, 1 ));
  7369. } else if ( typeof methodOrOptions === 'object' || ! methodOrOptions ) {
  7370. // Default to "init"
  7371. return methods.init.apply( this, arguments );
  7372. } else {
  7373. $.error( 'Method ' + methodOrOptions + ' does not exist on jQuery.carousel' );
  7374. }
  7375. }; // Plugin end
  7376. }( jQuery ));
  7377. ;(function ($) {
  7378. var methods = {
  7379. init: function (options) {
  7380. return this.each(function() {
  7381. var origin = $('#'+$(this).attr('data-activates'));
  7382. var screen = $('body');
  7383. // Creating tap target
  7384. var tapTargetEl = $(this);
  7385. var tapTargetWrapper = tapTargetEl.parent('.tap-target-wrapper');
  7386. var tapTargetWave = tapTargetWrapper.find('.tap-target-wave');
  7387. var tapTargetOriginEl = tapTargetWrapper.find('.tap-target-origin');
  7388. var tapTargetContentEl = tapTargetEl.find('.tap-target-content');
  7389. // Creating wrapper
  7390. if (!tapTargetWrapper.length) {
  7391. tapTargetWrapper = tapTargetEl.wrap($('<div class="tap-target-wrapper"></div>')).parent();
  7392. }
  7393. // Creating content
  7394. if (!tapTargetContentEl.length) {
  7395. tapTargetContentEl = $('<div class="tap-target-content"></div>');
  7396. tapTargetEl.append(tapTargetContentEl);
  7397. }
  7398. // Creating foreground wave
  7399. if (!tapTargetWave.length) {
  7400. tapTargetWave = $('<div class="tap-target-wave"></div>');
  7401. // Creating origin
  7402. if (!tapTargetOriginEl.length) {
  7403. tapTargetOriginEl = origin.clone(true, true);
  7404. tapTargetOriginEl.addClass('tap-target-origin');
  7405. tapTargetOriginEl.removeAttr('id');
  7406. tapTargetOriginEl.removeAttr('style');
  7407. tapTargetWave.append(tapTargetOriginEl);
  7408. }
  7409. tapTargetWrapper.append(tapTargetWave);
  7410. }
  7411. // Open
  7412. var openTapTarget = function() {
  7413. if (tapTargetWrapper.is('.open')) {
  7414. return;
  7415. }
  7416. // Adding open class
  7417. tapTargetWrapper.addClass('open');
  7418. setTimeout(function() {
  7419. tapTargetOriginEl.off('click.tapTarget').on('click.tapTarget', function(e) {
  7420. closeTapTarget();
  7421. tapTargetOriginEl.off('click.tapTarget');
  7422. });
  7423. $(document).off('click.tapTarget').on('click.tapTarget', function(e) {
  7424. closeTapTarget();
  7425. $(document).off('click.tapTarget');
  7426. });
  7427. var throttledCalc = Materialize.throttle(function() {
  7428. calculateTapTarget();
  7429. }, 200);
  7430. $(window).off('resize.tapTarget').on('resize.tapTarget', throttledCalc);
  7431. }, 0);
  7432. };
  7433. // Close
  7434. var closeTapTarget = function(){
  7435. if (!tapTargetWrapper.is('.open')) {
  7436. return;
  7437. }
  7438. tapTargetWrapper.removeClass('open');
  7439. tapTargetOriginEl.off('click.tapTarget')
  7440. $(document).off('click.tapTarget');
  7441. $(window).off('resize.tapTarget');
  7442. };
  7443. // Pre calculate
  7444. var calculateTapTarget = function() {
  7445. // Element or parent is fixed position?
  7446. var isFixed = origin.css('position') === 'fixed';
  7447. if (!isFixed) {
  7448. var parents = origin.parents();
  7449. for(var i = 0; i < parents.length; i++) {
  7450. isFixed = $(parents[i]).css('position') == 'fixed';
  7451. if (isFixed) {
  7452. break;
  7453. }
  7454. }
  7455. }
  7456. // Calculating origin
  7457. var originWidth = origin.outerWidth();
  7458. var originHeight = origin.outerHeight();
  7459. var originTop = isFixed ? origin.offset().top - $(document).scrollTop() : origin.offset().top;
  7460. var originLeft = isFixed ? origin.offset().left - $(document).scrollLeft() : origin.offset().left;
  7461. // Calculating screen
  7462. var windowWidth = $(window).width();
  7463. var windowHeight = $(window).height();
  7464. var centerX = windowWidth / 2;
  7465. var centerY = windowHeight / 2;
  7466. var isLeft = originLeft <= centerX;
  7467. var isRight = originLeft > centerX;
  7468. var isTop = originTop <= centerY;
  7469. var isBottom = originTop > centerY;
  7470. var isCenterX = originLeft >= windowWidth*0.25 && originLeft <= windowWidth*0.75;
  7471. var isCenterY = originTop >= windowHeight*0.25 && originTop <= windowHeight*0.75;
  7472. // Calculating tap target
  7473. var tapTargetWidth = tapTargetEl.outerWidth();
  7474. var tapTargetHeight = tapTargetEl.outerHeight();
  7475. var tapTargetTop = originTop + originHeight/2 - tapTargetHeight/2;
  7476. var tapTargetLeft = originLeft + originWidth/2 - tapTargetWidth/2;
  7477. var tapTargetPosition = isFixed ? 'fixed' : 'absolute';
  7478. // Calculating content
  7479. var tapTargetTextWidth = isCenterX ? tapTargetWidth : tapTargetWidth/2 + originWidth;
  7480. var tapTargetTextHeight = tapTargetHeight/2;
  7481. var tapTargetTextTop = isTop ? tapTargetHeight/2 : 0;
  7482. var tapTargetTextBottom = 0;
  7483. var tapTargetTextLeft = isLeft && !isCenterX ? tapTargetWidth/2 - originWidth : 0;
  7484. var tapTargetTextRight = 0;
  7485. var tapTargetTextPadding = originWidth;
  7486. var tapTargetTextAlign = isBottom ? 'bottom' : 'top';
  7487. // Calculating wave
  7488. var tapTargetWaveWidth = originWidth > originHeight ? originWidth*2 : originWidth*2;
  7489. var tapTargetWaveHeight = tapTargetWaveWidth;
  7490. var tapTargetWaveTop = tapTargetHeight/2 - tapTargetWaveHeight/2;
  7491. var tapTargetWaveLeft = tapTargetWidth/2 - tapTargetWaveWidth/2;
  7492. // Setting tap target
  7493. var tapTargetWrapperCssObj = {};
  7494. tapTargetWrapperCssObj.top = isTop ? tapTargetTop : '';
  7495. tapTargetWrapperCssObj.right = isRight ? windowWidth - tapTargetLeft - tapTargetWidth : '';
  7496. tapTargetWrapperCssObj.bottom = isBottom ? windowHeight - tapTargetTop - tapTargetHeight : '';
  7497. tapTargetWrapperCssObj.left = isLeft ? tapTargetLeft : '';
  7498. tapTargetWrapperCssObj.position = tapTargetPosition;
  7499. tapTargetWrapper.css(tapTargetWrapperCssObj);
  7500. // Setting content
  7501. tapTargetContentEl.css({
  7502. width: tapTargetTextWidth,
  7503. height: tapTargetTextHeight,
  7504. top: tapTargetTextTop,
  7505. right: tapTargetTextRight,
  7506. bottom: tapTargetTextBottom,
  7507. left: tapTargetTextLeft,
  7508. padding: tapTargetTextPadding,
  7509. verticalAlign: tapTargetTextAlign
  7510. });
  7511. // Setting wave
  7512. tapTargetWave.css({
  7513. top: tapTargetWaveTop,
  7514. left: tapTargetWaveLeft,
  7515. width: tapTargetWaveWidth,
  7516. height: tapTargetWaveHeight
  7517. });
  7518. }
  7519. if (options == 'open') {
  7520. calculateTapTarget();
  7521. openTapTarget();
  7522. }
  7523. if (options == 'close')
  7524. closeTapTarget();
  7525. });
  7526. },
  7527. open: function() {},
  7528. close: function() {}
  7529. };
  7530. $.fn.tapTarget = function(methodOrOptions) {
  7531. if (methods[methodOrOptions] || typeof methodOrOptions === 'object')
  7532. return methods.init.apply( this, arguments );
  7533. $.error( 'Method ' + methodOrOptions + ' does not exist on jQuery.tap-target' );
  7534. };
  7535. }( jQuery ));