/* Zepto v1.2.0 - zepto event ajax form ie - zeptojs.com/license */ !function(t,e){"function"==typeof define&&define.amd?define(function(){return e(t)}):e(t)}(this,function(t){var e=function(){function $(t){return null==t?String(t):S[C.call(t)]||"object"}function F(t){return"function"==$(t)}function k(t){return null!=t&&t==t.window}function M(t){return null!=t&&t.nodeType==t.DOCUMENT_NODE}function R(t){return"object"==$(t)}function Z(t){return R(t)&&!k(t)&&Object.getPrototypeOf(t)==Object.prototype}function z(t){var e=!!t&&"length"in t&&t.length,n=r.type(t);return"function"!=n&&!k(t)&&("array"==n||0===e||"number"==typeof e&&e>0&&e-1 in t)}function q(t){return a.call(t,function(t){return null!=t})}function H(t){return t.length>0?r.fn.concat.apply([],t):t}function I(t){return t.replace(/::/g,"/").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z\d])([A-Z])/g,"$1_$2").replace(/_/g,"-").toLowerCase()}function V(t){return t in l?l[t]:l[t]=new RegExp("(^|\\s)"+t+"(\\s|$)")}function _(t,e){return"number"!=typeof e||h[I(t)]?e:e+"px"}function B(t){var e,n;return c[t]||(e=f.createElement(t),f.body.appendChild(e),n=getComputedStyle(e,"").getPropertyValue("display"),e.parentNode.removeChild(e),"none"==n&&(n="block"),c[t]=n),c[t]}function U(t){return"children"in t?u.call(t.children):r.map(t.childNodes,function(t){return 1==t.nodeType?t:void 0})}function X(t,e){var n,r=t?t.length:0;for(n=0;r>n;n++)this[n]=t[n];this.length=r,this.selector=e||""}function J(t,r,i){for(n in r)i&&(Z(r[n])||L(r[n]))?(Z(r[n])&&!Z(t[n])&&(t[n]={}),L(r[n])&&!L(t[n])&&(t[n]=[]),J(t[n],r[n],i)):r[n]!==e&&(t[n]=r[n])}function W(t,e){return null==e?r(t):r(t).filter(e)}function Y(t,e,n,r){return F(e)?e.call(t,n,r):e}function G(t,e,n){null==n?t.removeAttribute(e):t.setAttribute(e,n)}function K(t,n){var r=t.className||"",i=r&&r.baseVal!==e;return n===e?i?r.baseVal:r:void(i?r.baseVal=n:t.className=n)}function Q(t){try{return t?"true"==t||("false"==t?!1:"null"==t?null:+t+""==t?+t:/^[\[\{]/.test(t)?r.parseJSON(t):t):t}catch(e){return t}}function tt(t,e){e(t);for(var n=0,r=t.childNodes.length;r>n;n++)tt(t.childNodes[n],e)}var e,n,r,i,O,P,o=[],s=o.concat,a=o.filter,u=o.slice,f=t.document,c={},l={},h={"column-count":1,columns:1,"font-weight":1,"line-height":1,opacity:1,"z-index":1,zoom:1},p=/^\s*<(\w+|!)[^>]*>/,d=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,m=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,g=/^(?:body|html)$/i,v=/([A-Z])/g,y=["val","css","html","text","data","width","height","offset"],x=["after","prepend","before","append"],b=f.createElement("table"),E=f.createElement("tr"),j={tr:f.createElement("tbody"),tbody:b,thead:b,tfoot:b,td:E,th:E,"*":f.createElement("div")},w=/complete|loaded|interactive/,T=/^[\w-]*$/,S={},C=S.toString,N={},A=f.createElement("div"),D={tabindex:"tabIndex",readonly:"readOnly","for":"htmlFor","class":"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"},L=Array.isArray||function(t){return t instanceof Array};return N.matches=function(t,e){if(!e||!t||1!==t.nodeType)return!1;var n=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.oMatchesSelector||t.matchesSelector;if(n)return n.call(t,e);var r,i=t.parentNode,o=!i;return o&&(i=A).appendChild(t),r=~N.qsa(i,e).indexOf(t),o&&A.removeChild(t),r},O=function(t){return t.replace(/-+(.)?/g,function(t,e){return e?e.toUpperCase():""})},P=function(t){return a.call(t,function(e,n){return t.indexOf(e)==n})},N.fragment=function(t,n,i){var o,s,a;return d.test(t)&&(o=r(f.createElement(RegExp.$1))),o||(t.replace&&(t=t.replace(m,"<$1>")),n===e&&(n=p.test(t)&&RegExp.$1),n in j||(n="*"),a=j[n],a.innerHTML=""+t,o=r.each(u.call(a.childNodes),function(){a.removeChild(this)})),Z(i)&&(s=r(o),r.each(i,function(t,e){y.indexOf(t)>-1?s[t](e):s.attr(t,e)})),o},N.Z=function(t,e){return new X(t,e)},N.isZ=function(t){return t instanceof N.Z},N.init=function(t,n){var i;if(!t)return N.Z();if("string"==typeof t)if(t=t.trim(),"<"==t[0]&&p.test(t))i=N.fragment(t,RegExp.$1,n),t=null;else{if(n!==e)return r(n).find(t);i=N.qsa(f,t)}else{if(F(t))return r(f).ready(t);if(N.isZ(t))return t;if(L(t))i=q(t);else if(R(t))i=[t],t=null;else if(p.test(t))i=N.fragment(t.trim(),RegExp.$1,n),t=null;else{if(n!==e)return r(n).find(t);i=N.qsa(f,t)}}return N.Z(i,t)},r=function(t,e){return N.init(t,e)},r.extend=function(t){var e,n=u.call(arguments,1);return"boolean"==typeof t&&(e=t,t=n.shift()),n.forEach(function(n){J(t,n,e)}),t},N.qsa=function(t,e){var n,r="#"==e[0],i=!r&&"."==e[0],o=r||i?e.slice(1):e,s=T.test(o);return t.getElementById&&s&&r?(n=t.getElementById(o))?[n]:[]:1!==t.nodeType&&9!==t.nodeType&&11!==t.nodeType?[]:u.call(s&&!r&&t.getElementsByClassName?i?t.getElementsByClassName(o):t.getElementsByTagName(e):t.querySelectorAll(e))},r.contains=f.documentElement.contains?function(t,e){return t!==e&&t.contains(e)}:function(t,e){for(;e&&(e=e.parentNode);)if(e===t)return!0;return!1},r.type=$,r.isFunction=F,r.isWindow=k,r.isArray=L,r.isPlainObject=Z,r.isEmptyObject=function(t){var e;for(e in t)return!1;return!0},r.isNumeric=function(t){var e=Number(t),n=typeof t;return null!=t&&"boolean"!=n&&("string"!=n||t.length)&&!isNaN(e)&&isFinite(e)||!1},r.inArray=function(t,e,n){return o.indexOf.call(e,t,n)},r.camelCase=O,r.trim=function(t){return null==t?"":String.prototype.trim.call(t)},r.uuid=0,r.support={},r.expr={},r.noop=function(){},r.map=function(t,e){var n,i,o,r=[];if(z(t))for(i=0;i=0?t:t+this.length]},toArray:function(){return this.get()},size:function(){return this.length},remove:function(){return this.each(function(){null!=this.parentNode&&this.parentNode.removeChild(this)})},each:function(t){return o.every.call(this,function(e,n){return t.call(e,n,e)!==!1}),this},filter:function(t){return F(t)?this.not(this.not(t)):r(a.call(this,function(e){return N.matches(e,t)}))},add:function(t,e){return r(P(this.concat(r(t,e))))},is:function(t){return this.length>0&&N.matches(this[0],t)},not:function(t){var n=[];if(F(t)&&t.call!==e)this.each(function(e){t.call(this,e)||n.push(this)});else{var i="string"==typeof t?this.filter(t):z(t)&&F(t.item)?u.call(t):r(t);this.forEach(function(t){i.indexOf(t)<0&&n.push(t)})}return r(n)},has:function(t){return this.filter(function(){return R(t)?r.contains(this,t):r(this).find(t).size()})},eq:function(t){return-1===t?this.slice(t):this.slice(t,+t+1)},first:function(){var t=this[0];return t&&!R(t)?t:r(t)},last:function(){var t=this[this.length-1];return t&&!R(t)?t:r(t)},find:function(t){var e,n=this;return e=t?"object"==typeof t?r(t).filter(function(){var t=this;return o.some.call(n,function(e){return r.contains(e,t)})}):1==this.length?r(N.qsa(this[0],t)):this.map(function(){return N.qsa(this,t)}):r()},closest:function(t,e){var n=[],i="object"==typeof t&&r(t);return this.each(function(r,o){for(;o&&!(i?i.indexOf(o)>=0:N.matches(o,t));)o=o!==e&&!M(o)&&o.parentNode;o&&n.indexOf(o)<0&&n.push(o)}),r(n)},parents:function(t){for(var e=[],n=this;n.length>0;)n=r.map(n,function(t){return(t=t.parentNode)&&!M(t)&&e.indexOf(t)<0?(e.push(t),t):void 0});return W(e,t)},parent:function(t){return W(P(this.pluck("parentNode")),t)},children:function(t){return W(this.map(function(){return U(this)}),t)},contents:function(){return this.map(function(){return this.contentDocument||u.call(this.childNodes)})},siblings:function(t){return W(this.map(function(t,e){return a.call(U(e.parentNode),function(t){return t!==e})}),t)},empty:function(){return this.each(function(){this.innerHTML=""})},pluck:function(t){return r.map(this,function(e){return e[t]})},show:function(){return this.each(function(){"none"==this.style.display&&(this.style.display=""),"none"==getComputedStyle(this,"").getPropertyValue("display")&&(this.style.display=B(this.nodeName))})},replaceWith:function(t){return this.before(t).remove()},wrap:function(t){var e=F(t);if(this[0]&&!e)var n=r(t).get(0),i=n.parentNode||this.length>1;return this.each(function(o){r(this).wrapAll(e?t.call(this,o):i?n.cloneNode(!0):n)})},wrapAll:function(t){if(this[0]){r(this[0]).before(t=r(t));for(var e;(e=t.children()).length;)t=e.first();r(t).append(this)}return this},wrapInner:function(t){var e=F(t);return this.each(function(n){var i=r(this),o=i.contents(),s=e?t.call(this,n):t;o.length?o.wrapAll(s):i.append(s)})},unwrap:function(){return this.parent().each(function(){r(this).replaceWith(r(this).children())}),this},clone:function(){return this.map(function(){return this.cloneNode(!0)})},hide:function(){return this.css("display","none")},toggle:function(t){return this.each(function(){var n=r(this);(t===e?"none"==n.css("display"):t)?n.show():n.hide()})},prev:function(t){return r(this.pluck("previousElementSibling")).filter(t||"*")},next:function(t){return r(this.pluck("nextElementSibling")).filter(t||"*")},html:function(t){return 0 in arguments?this.each(function(e){var n=this.innerHTML;r(this).empty().append(Y(this,t,e,n))}):0 in this?this[0].innerHTML:null},text:function(t){return 0 in arguments?this.each(function(e){var n=Y(this,t,e,this.textContent);this.textContent=null==n?"":""+n}):0 in this?this.pluck("textContent").join(""):null},attr:function(t,r){var i;return"string"!=typeof t||1 in arguments?this.each(function(e){if(1===this.nodeType)if(R(t))for(n in t)G(this,n,t[n]);else G(this,t,Y(this,r,e,this.getAttribute(t)))}):0 in this&&1==this[0].nodeType&&null!=(i=this[0].getAttribute(t))?i:e},removeAttr:function(t){return this.each(function(){1===this.nodeType&&t.split(" ").forEach(function(t){G(this,t)},this)})},prop:function(t,e){return t=D[t]||t,1 in arguments?this.each(function(n){this[t]=Y(this,e,n,this[t])}):this[0]&&this[0][t]},removeProp:function(t){return t=D[t]||t,this.each(function(){delete this[t]})},data:function(t,n){var r="data-"+t.replace(v,"-$1").toLowerCase(),i=1 in arguments?this.attr(r,n):this.attr(r);return null!==i?Q(i):e},val:function(t){return 0 in arguments?(null==t&&(t=""),this.each(function(e){this.value=Y(this,t,e,this.value)})):this[0]&&(this[0].multiple?r(this[0]).find("option").filter(function(){return this.selected}).pluck("value"):this[0].value)},offset:function(e){if(e)return this.each(function(t){var n=r(this),i=Y(this,e,t,n.offset()),o=n.offsetParent().offset(),s={top:i.top-o.top,left:i.left-o.left};"static"==n.css("position")&&(s.position="relative"),n.css(s)});if(!this.length)return null;if(f.documentElement!==this[0]&&!r.contains(f.documentElement,this[0]))return{top:0,left:0};var n=this[0].getBoundingClientRect();return{left:n.left+t.pageXOffset,top:n.top+t.pageYOffset,width:Math.round(n.width),height:Math.round(n.height)}},css:function(t,e){if(arguments.length<2){var i=this[0];if("string"==typeof t){if(!i)return;return i.style[O(t)]||getComputedStyle(i,"").getPropertyValue(t)}if(L(t)){if(!i)return;var o={},s=getComputedStyle(i,"");return r.each(t,function(t,e){o[e]=i.style[O(e)]||s.getPropertyValue(e)}),o}}var a="";if("string"==$(t))e||0===e?a=I(t)+":"+_(t,e):this.each(function(){this.style.removeProperty(I(t))});else for(n in t)t[n]||0===t[n]?a+=I(n)+":"+_(n,t[n])+";":this.each(function(){this.style.removeProperty(I(n))});return this.each(function(){this.style.cssText+=";"+a})},index:function(t){return t?this.indexOf(r(t)[0]):this.parent().children().indexOf(this[0])},hasClass:function(t){return t?o.some.call(this,function(t){return this.test(K(t))},V(t)):!1},addClass:function(t){return t?this.each(function(e){if("className"in this){i=[];var n=K(this),o=Y(this,t,e,n);o.split(/\s+/g).forEach(function(t){r(this).hasClass(t)||i.push(t)},this),i.length&&K(this,n+(n?" ":"")+i.join(" "))}}):this},removeClass:function(t){return this.each(function(n){if("className"in this){if(t===e)return K(this,"");i=K(this),Y(this,t,n,i).split(/\s+/g).forEach(function(t){i=i.replace(V(t)," ")}),K(this,i.trim())}})},toggleClass:function(t,n){return t?this.each(function(i){var o=r(this),s=Y(this,t,i,K(this));s.split(/\s+/g).forEach(function(t){(n===e?!o.hasClass(t):n)?o.addClass(t):o.removeClass(t)})}):this},scrollTop:function(t){if(this.length){var n="scrollTop"in this[0];return t===e?n?this[0].scrollTop:this[0].pageYOffset:this.each(n?function(){this.scrollTop=t}:function(){this.scrollTo(this.scrollX,t)})}},scrollLeft:function(t){if(this.length){var n="scrollLeft"in this[0];return t===e?n?this[0].scrollLeft:this[0].pageXOffset:this.each(n?function(){this.scrollLeft=t}:function(){this.scrollTo(t,this.scrollY)})}},position:function(){if(this.length){var t=this[0],e=this.offsetParent(),n=this.offset(),i=g.test(e[0].nodeName)?{top:0,left:0}:e.offset();return n.top-=parseFloat(r(t).css("margin-top"))||0,n.left-=parseFloat(r(t).css("margin-left"))||0,i.top+=parseFloat(r(e[0]).css("border-top-width"))||0,i.left+=parseFloat(r(e[0]).css("border-left-width"))||0,{top:n.top-i.top,left:n.left-i.left}}},offsetParent:function(){return this.map(function(){for(var t=this.offsetParent||f.body;t&&!g.test(t.nodeName)&&"static"==r(t).css("position");)t=t.offsetParent;return t})}},r.fn.detach=r.fn.remove,["width","height"].forEach(function(t){var n=t.replace(/./,function(t){return t[0].toUpperCase()});r.fn[t]=function(i){var o,s=this[0];return i===e?k(s)?s["inner"+n]:M(s)?s.documentElement["scroll"+n]:(o=this.offset())&&o[t]:this.each(function(e){s=r(this),s.css(t,Y(this,i,e,s[t]()))})}}),x.forEach(function(n,i){var o=i%2;r.fn[n]=function(){var n,a,s=r.map(arguments,function(t){var i=[];return n=$(t),"array"==n?(t.forEach(function(t){return t.nodeType!==e?i.push(t):r.zepto.isZ(t)?i=i.concat(t.get()):void(i=i.concat(N.fragment(t)))}),i):"object"==n||null==t?t:N.fragment(t)}),u=this.length>1;return s.length<1?this:this.each(function(e,n){a=o?n:n.parentNode,n=0==i?n.nextSibling:1==i?n.firstChild:2==i?n:null;var c=r.contains(f.documentElement,a);s.forEach(function(e){if(u)e=e.cloneNode(!0);else if(!a)return r(e).remove();a.insertBefore(e,n),c&&tt(e,function(e){if(!(null==e.nodeName||"SCRIPT"!==e.nodeName.toUpperCase()||e.type&&"text/javascript"!==e.type||e.src)){var n=e.ownerDocument?e.ownerDocument.defaultView:t;n.eval.call(n,e.innerHTML)}})})})},r.fn[o?n+"To":"insert"+(i?"Before":"After")]=function(t){return r(t)[n](this),this}}),N.Z.prototype=X.prototype=r.fn,N.uniq=P,N.deserializeValue=Q,r.zepto=N,r}();return t.Zepto=e,void 0===t.$&&(t.$=e),function(e){function h(t){return t._zid||(t._zid=n++)}function p(t,e,n,r){if(e=d(e),e.ns)var i=m(e.ns);return(a[h(t)]||[]).filter(function(t){return t&&(!e.e||t.e==e.e)&&(!e.ns||i.test(t.ns))&&(!n||h(t.fn)===h(n))&&(!r||t.sel==r)})}function d(t){var e=(""+t).split(".");return{e:e[0],ns:e.slice(1).sort().join(" ")}}function m(t){return new RegExp("(?:^| )"+t.replace(" "," .* ?")+"(?: |$)")}function g(t,e){return t.del&&!f&&t.e in c||!!e}function v(t){return l[t]||f&&c[t]||t}function y(t,n,i,o,s,u,f){var c=h(t),p=a[c]||(a[c]=[]);n.split(/\s/).forEach(function(n){if("ready"==n)return e(document).ready(i);var a=d(n);a.fn=i,a.sel=s,a.e in l&&(i=function(t){var n=t.relatedTarget;return!n||n!==this&&!e.contains(this,n)?a.fn.apply(this,arguments):void 0}),a.del=u;var c=u||i;a.proxy=function(e){if(e=T(e),!e.isImmediatePropagationStopped()){e.data=o;var n=c.apply(t,e._args==r?[e]:[e].concat(e._args));return n===!1&&(e.preventDefault(),e.stopPropagation()),n}},a.i=p.length,p.push(a),"addEventListener"in t&&t.addEventListener(v(a.e),a.proxy,g(a,f))})}function x(t,e,n,r,i){var o=h(t);(e||"").split(/\s/).forEach(function(e){p(t,e,n,r).forEach(function(e){delete a[o][e.i],"removeEventListener"in t&&t.removeEventListener(v(e.e),e.proxy,g(e,i))})})}function T(t,n){return(n||!t.isDefaultPrevented)&&(n||(n=t),e.each(w,function(e,r){var i=n[e];t[e]=function(){return this[r]=b,i&&i.apply(n,arguments)},t[r]=E}),t.timeStamp||(t.timeStamp=Date.now()),(n.defaultPrevented!==r?n.defaultPrevented:"returnValue"in n?n.returnValue===!1:n.getPreventDefault&&n.getPreventDefault())&&(t.isDefaultPrevented=b)),t}function S(t){var e,n={originalEvent:t};for(e in t)j.test(e)||t[e]===r||(n[e]=t[e]);return T(n,t)}var r,n=1,i=Array.prototype.slice,o=e.isFunction,s=function(t){return"string"==typeof t},a={},u={},f="onfocusin"in t,c={focus:"focusin",blur:"focusout"},l={mouseenter:"mouseover",mouseleave:"mouseout"};u.click=u.mousedown=u.mouseup=u.mousemove="MouseEvents",e.event={add:y,remove:x},e.proxy=function(t,n){var r=2 in arguments&&i.call(arguments,2);if(o(t)){var a=function(){return t.apply(n,r?r.concat(i.call(arguments)):arguments)};return a._zid=h(t),a}if(s(n))return r?(r.unshift(t[n],t),e.proxy.apply(null,r)):e.proxy(t[n],t);throw new TypeError("expected function")},e.fn.bind=function(t,e,n){return this.on(t,e,n)},e.fn.unbind=function(t,e){return this.off(t,e)},e.fn.one=function(t,e,n,r){return this.on(t,e,n,r,1)};var b=function(){return!0},E=function(){return!1},j=/^([A-Z]|returnValue$|layer[XY]$|webkitMovement[XY]$)/,w={preventDefault:"isDefaultPrevented",stopImmediatePropagation:"isImmediatePropagationStopped",stopPropagation:"isPropagationStopped"};e.fn.delegate=function(t,e,n){return this.on(e,t,n)},e.fn.undelegate=function(t,e,n){return this.off(e,t,n)},e.fn.live=function(t,n){return e(document.body).delegate(this.selector,t,n),this},e.fn.die=function(t,n){return e(document.body).undelegate(this.selector,t,n),this},e.fn.on=function(t,n,a,u,f){var c,l,h=this;return t&&!s(t)?(e.each(t,function(t,e){h.on(t,n,a,e,f)}),h):(s(n)||o(u)||u===!1||(u=a,a=n,n=r),(u===r||a===!1)&&(u=a,a=r),u===!1&&(u=E),h.each(function(r,o){f&&(c=function(t){return x(o,t.type,u),u.apply(this,arguments)}),n&&(l=function(t){var r,s=e(t.target).closest(n,o).get(0);return s&&s!==o?(r=e.extend(S(t),{currentTarget:s,liveFired:o}),(c||u).apply(s,[r].concat(i.call(arguments,1)))):void 0}),y(o,t,u,a,n,l||c)}))},e.fn.off=function(t,n,i){var a=this;return t&&!s(t)?(e.each(t,function(t,e){a.off(t,n,e)}),a):(s(n)||o(i)||i===!1||(i=n,n=r),i===!1&&(i=E),a.each(function(){x(this,t,i,n)}))},e.fn.trigger=function(t,n){return t=s(t)||e.isPlainObject(t)?e.Event(t):T(t),t._args=n,this.each(function(){t.type in c&&"function"==typeof this[t.type]?this[t.type]():"dispatchEvent"in this?this.dispatchEvent(t):e(this).triggerHandler(t,n)})},e.fn.triggerHandler=function(t,n){var r,i;return this.each(function(o,a){r=S(s(t)?e.Event(t):t),r._args=n,r.target=a,e.each(p(a,t.type||t),function(t,e){return i=e.proxy(r),r.isImmediatePropagationStopped()?!1:void 0})}),i},"focusin focusout focus blur load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select keydown keypress keyup error".split(" ").forEach(function(t){e.fn[t]=function(e){return 0 in arguments?this.bind(t,e):this.trigger(t)}}),e.Event=function(t,e){s(t)||(e=t,t=e.type);var n=document.createEvent(u[t]||"Events"),r=!0;if(e)for(var i in e)"bubbles"==i?r=!!e[i]:n[i]=e[i];return n.initEvent(t,r,!0),T(n)}}(e),function(e){function p(t,n,r){var i=e.Event(n);return e(t).trigger(i,r),!i.isDefaultPrevented()}function d(t,e,n,i){return t.global?p(e||r,n,i):void 0}function m(t){t.global&&0===e.active++&&d(t,null,"ajaxStart")}function g(t){t.global&&!--e.active&&d(t,null,"ajaxStop")}function v(t,e){var n=e.context;return e.beforeSend.call(n,t,e)===!1||d(e,n,"ajaxBeforeSend",[t,e])===!1?!1:void d(e,n,"ajaxSend",[t,e])}function y(t,e,n,r){var i=n.context,o="success";n.success.call(i,t,o,e),r&&r.resolveWith(i,[t,o,e]),d(n,i,"ajaxSuccess",[e,n,t]),b(o,e,n)}function x(t,e,n,r,i){var o=r.context;r.error.call(o,n,e,t),i&&i.rejectWith(o,[n,e,t]),d(r,o,"ajaxError",[n,r,t||e]),b(e,n,r)}function b(t,e,n){var r=n.context;n.complete.call(r,e,t),d(n,r,"ajaxComplete",[e,n]),g(n)}function E(t,e,n){if(n.dataFilter==j)return t;var r=n.context;return n.dataFilter.call(r,t,e)}function j(){}function w(t){return t&&(t=t.split(";",2)[0]),t&&(t==c?"html":t==f?"json":a.test(t)?"script":u.test(t)&&"xml")||"text"}function T(t,e){return""==e?t:(t+"&"+e).replace(/[&?]{1,2}/,"?")}function S(t){t.processData&&t.data&&"string"!=e.type(t.data)&&(t.data=e.param(t.data,t.traditional)),!t.data||t.type&&"GET"!=t.type.toUpperCase()&&"jsonp"!=t.dataType||(t.url=T(t.url,t.data),t.data=void 0)}function C(t,n,r,i){return e.isFunction(n)&&(i=r,r=n,n=void 0),e.isFunction(r)||(i=r,r=void 0),{url:t,data:n,success:r,dataType:i}}function O(t,n,r,i){var o,s=e.isArray(n),a=e.isPlainObject(n);e.each(n,function(n,u){o=e.type(u),i&&(n=r?i:i+"["+(a||"object"==o||"array"==o?n:"")+"]"),!i&&s?t.add(u.name,u.value):"array"==o||!r&&"object"==o?O(t,u,r,n):t.add(n,u)})}var i,o,n=+new Date,r=t.document,s=/)<[^<]*)*<\/script>/gi,a=/^(?:text|application)\/javascript/i,u=/^(?:text|application)\/xml/i,f="application/json",c="text/html",l=/^\s*$/,h=r.createElement("a");h.href=t.location.href,e.active=0,e.ajaxJSONP=function(i,o){if(!("type"in i))return e.ajax(i);var c,p,s=i.jsonpCallback,a=(e.isFunction(s)?s():s)||"Zepto"+n++,u=r.createElement("script"),f=t[a],l=function(t){e(u).triggerHandler("error",t||"abort")},h={abort:l};return o&&o.promise(h),e(u).on("load error",function(n,r){clearTimeout(p),e(u).off().remove(),"error"!=n.type&&c?y(c[0],h,i,o):x(null,r||"error",h,i,o),t[a]=f,c&&e.isFunction(f)&&f(c[0]),f=c=void 0}),v(h,i)===!1?(l("abort"),h):(t[a]=function(){c=arguments},u.src=i.url.replace(/\?(.+)=\?/,"?$1="+a),r.head.appendChild(u),i.timeout>0&&(p=setTimeout(function(){l("timeout")},i.timeout)),h)},e.ajaxSettings={type:"GET",beforeSend:j,success:j,error:j,complete:j,context:null,global:!0,xhr:function(){return new t.XMLHttpRequest},accepts:{script:"text/javascript, application/javascript, application/x-javascript",json:f,xml:"application/xml, text/xml",html:c,text:"text/plain"},crossDomain:!1,timeout:0,processData:!0,cache:!0,dataFilter:j},e.ajax=function(n){var u,f,s=e.extend({},n||{}),a=e.Deferred&&e.Deferred();for(i in e.ajaxSettings)void 0===s[i]&&(s[i]=e.ajaxSettings[i]);m(s),s.crossDomain||(u=r.createElement("a"),u.href=s.url,u.href=u.href,s.crossDomain=h.protocol+"//"+h.host!=u.protocol+"//"+u.host),s.url||(s.url=t.location.toString()),(f=s.url.indexOf("#"))>-1&&(s.url=s.url.slice(0,f)),S(s);var c=s.dataType,p=/\?.+=\?/.test(s.url);if(p&&(c="jsonp"),s.cache!==!1&&(n&&n.cache===!0||"script"!=c&&"jsonp"!=c)||(s.url=T(s.url,"_="+Date.now())),"jsonp"==c)return p||(s.url=T(s.url,s.jsonp?s.jsonp+"=?":s.jsonp===!1?"":"callback=?")),e.ajaxJSONP(s,a);var P,d=s.accepts[c],g={},b=function(t,e){g[t.toLowerCase()]=[t,e]},C=/^([\w-]+:)\/\//.test(s.url)?RegExp.$1:t.location.protocol,N=s.xhr(),O=N.setRequestHeader;if(a&&a.promise(N),s.crossDomain||b("X-Requested-With","XMLHttpRequest"),b("Accept",d||"*/*"),(d=s.mimeType||d)&&(d.indexOf(",")>-1&&(d=d.split(",",2)[0]),N.overrideMimeType&&N.overrideMimeType(d)),(s.contentType||s.contentType!==!1&&s.data&&"GET"!=s.type.toUpperCase())&&b("Content-Type",s.contentType||"application/x-www-form-urlencoded"),s.headers)for(o in s.headers)b(o,s.headers[o]);if(N.setRequestHeader=b,N.onreadystatechange=function(){if(4==N.readyState){N.onreadystatechange=j,clearTimeout(P);var t,n=!1;if(N.status>=200&&N.status<300||304==N.status||0==N.status&&"file:"==C){if(c=c||w(s.mimeType||N.getResponseHeader("content-type")),"arraybuffer"==N.responseType||"blob"==N.responseType)t=N.response;else{t=N.responseText;try{t=E(t,c,s),"script"==c?(1,eval)(t):"xml"==c?t=N.responseXML:"json"==c&&(t=l.test(t)?null:e.parseJSON(t))}catch(r){n=r}if(n)return x(n,"parsererror",N,s,a)}y(t,N,s,a)}else x(N.statusText||null,N.status?"error":"abort",N,s,a)}},v(N,s)===!1)return N.abort(),x(null,"abort",N,s,a),N;var A="async"in s?s.async:!0;if(N.open(s.type,s.url,A,s.username,s.password),s.xhrFields)for(o in s.xhrFields)N[o]=s.xhrFields[o];for(o in g)O.apply(N,g[o]);return s.timeout>0&&(P=setTimeout(function(){N.onreadystatechange=j,N.abort(),x(null,"timeout",N,s,a)},s.timeout)),N.send(s.data?s.data:null),N},e.get=function(){return e.ajax(C.apply(null,arguments))},e.post=function(){var t=C.apply(null,arguments);return t.type="POST",e.ajax(t)},e.getJSON=function(){var t=C.apply(null,arguments);return t.dataType="json",e.ajax(t)},e.fn.load=function(t,n,r){if(!this.length)return this;var a,i=this,o=t.split(/\s/),u=C(t,n,r),f=u.success;return o.length>1&&(u.url=o[0],a=o[1]),u.success=function(t){i.html(a?e("
").html(t.replace(s,"")).find(a):t),f&&f.apply(i,arguments)},e.ajax(u),this};var N=encodeURIComponent;e.param=function(t,n){var r=[];return r.add=function(t,n){e.isFunction(n)&&(n=n()),null==n&&(n=""),this.push(N(t)+"="+N(n))},O(r,t,n),r.join("&").replace(/%20/g,"+")}}(e),function(t){t.fn.serializeArray=function(){var e,n,r=[],i=function(t){return t.forEach?t.forEach(i):void r.push({name:e,value:t})};return this[0]&&t.each(this[0].elements,function(r,o){n=o.type,e=o.name,e&&"fieldset"!=o.nodeName.toLowerCase()&&!o.disabled&&"submit"!=n&&"reset"!=n&&"button"!=n&&"file"!=n&&("radio"!=n&&"checkbox"!=n||o.checked)&&i(t(o).val())}),r},t.fn.serialize=function(){var t=[];return this.serializeArray().forEach(function(e){t.push(encodeURIComponent(e.name)+"="+encodeURIComponent(e.value))}),t.join("&")},t.fn.submit=function(e){if(0 in arguments)this.bind("submit",e);else if(this.length){var n=t.Event("submit");this.eq(0).trigger(n),n.isDefaultPrevented()||this.get(0).submit()}return this}}(e),function(){try{getComputedStyle(void 0)}catch(e){var n=getComputedStyle;t.getComputedStyle=function(t,e){try{return n(t,e)}catch(r){return null}}}}(),e}); // Zepto.js // (c) 2010-2016 Thomas Fuchs // Zepto.js may be freely distributed under the MIT license. ;(function($){ var zepto = $.zepto, oldQsa = zepto.qsa, oldMatches = zepto.matches function visible(elem){ elem = $(elem) return !!(elem.width() || elem.height()) && elem.css("display") !== "none" } // Implements a subset from: // http://api.jquery.com/category/selectors/jquery-selector-extensions/ // // Each filter function receives the current index, all nodes in the // considered set, and a value if there were parentheses. The value // of `this` is the node currently being considered. The function returns the // resulting node(s), null, or undefined. // // Complex selectors are not supported: // li:has(label:contains("foo")) + li:has(label:contains("bar")) // ul.inner:first > li var filters = $.expr[':'] = { visible: function(){ if (visible(this)) return this }, hidden: function(){ if (!visible(this)) return this }, selected: function(){ if (this.selected) return this }, checked: function(){ if (this.checked) return this }, parent: function(){ return this.parentNode }, first: function(idx){ if (idx === 0) return this }, last: function(idx, nodes){ if (idx === nodes.length - 1) return this }, eq: function(idx, _, value){ if (idx === value) return this }, contains: function(idx, _, text){ if ($(this).text().indexOf(text) > -1) return this }, has: function(idx, _, sel){ if (zepto.qsa(this, sel).length) return this } } var filterRe = new RegExp('(.*):(\\w+)(?:\\(([^)]+)\\))?$\\s*'), childRe = /^\s*>/, classTag = 'Zepto' + (+new Date()) function process(sel, fn) { // quote the hash in `a[href^=#]` expression sel = sel.replace(/=#\]/g, '="#"]') var filter, arg, match = filterRe.exec(sel) if (match && match[2] in filters) { filter = filters[match[2]], arg = match[3] sel = match[1] if (arg) { var num = Number(arg) if (isNaN(num)) arg = arg.replace(/^["']|["']$/g, '') else arg = num } } return fn(sel, filter, arg) } zepto.qsa = function(node, selector) { return process(selector, function(sel, filter, arg){ try { var taggedParent if (!sel && filter) sel = '*' else if (childRe.test(sel)) // support "> *" child queries by tagging the parent node with a // unique class and prepending that classname onto the selector taggedParent = $(node).addClass(classTag), sel = '.'+classTag+' '+sel var nodes = oldQsa(node, sel) } catch(e) { console.error('error performing selector: %o', selector) throw e } finally { if (taggedParent) taggedParent.removeClass(classTag) } return !filter ? nodes : zepto.uniq($.map(nodes, function(n, i){ return filter.call(n, i, nodes, arg) })) }) } zepto.matches = function(node, selector){ return process(selector, function(sel, filter, arg){ return (!sel || oldMatches(node, sel)) && (!filter || filter.call(node, null, arg) === node) }) } })(Zepto) /*! Lazy Load 2.0.0-beta.2 - MIT license - Copyright 2007-2017 Mika Tuupola */ !function(t,e){"object"==typeof exports?module.exports=e(t):"function"==typeof define&&define.amd?define([],e(t)):t.LazyLoad=e(t)}("undefined"!=typeof global?global:this.window||this.global,function(t){"use strict";function e(t,e){this.settings=r(s,e||{}),this.images=t||document.querySelectorAll(this.settings.selector),this.observer=null,this.init()}const s={src:"data-src",srcset:"data-srcset",selector:".lazyload"},r=function(){let t={},e=!1,s=0,o=arguments.length;"[object Boolean]"===Object.prototype.toString.call(arguments[0])&&(e=arguments[0],s++);for(;s0){e.observer.unobserve(t.target);let s=t.target.getAttribute(e.settings.src),r=t.target.getAttribute(e.settings.srcset);"img"===t.target.tagName.toLowerCase()?(s&&(t.target.src=s),r&&(t.target.srcset=r)):t.target.style.backgroundImage="url("+s+")"}})},s),this.images.forEach(function(t){e.observer.observe(t)})},loadAndDestroy:function(){this.settings&&(this.loadImages(),this.destroy())},loadImages:function(){if(!this.settings)return;let t=this;this.images.forEach(function(e){let s=e.getAttribute(t.settings.src),r=e.getAttribute(t.settings.srcset);"img"===e.tagName.toLowerCase()?(s&&(e.src=s),r&&(e.srcset=r)):e.style.backgroundImage="url("+s+")"})},destroy:function(){this.settings&&(this.observer.disconnect(),this.settings=null)}},t.lazyload=function(t,s){return new e(t,s)},t.jQuery){const s=t.jQuery;s.fn.lazyload=function(t){return t=t||{},t.attribute=t.attribute||"data-src",new e(s.makeArray(this),t),this}}return e}); var appDescription = { addListener: function() { $('#js-expand-app-description').on('click', function(event) { event.preventDefault(); $(this).closest('.app__description').toggleClass('open'); }); }, init: function() { if ($('#js-expand-app-description')) { appDescription.addListener(); } } }; function drawStatisticsv2(){ var data = pricing; var pc = new PriceChart({ canvasId: "price-canvas-v2", padding: 10, pricePadding: 2, gridScale: 1.1, labelIndent: 40, labelFont: '18px Arial', labelFontActive: 'bold 21px Arial', fillStyle: '#9398A1', fillStyleActive: '#D9E1E8', gridColor: "#eeeeee" }, data); pc.draw(); } var PriceChart = function(options, data){ this.options = options; var canvas = document.getElementById(this.options.canvasId); var ctx = canvas.getContext("2d"); this.draw = function(){ this.options.minPrice = 9999; this.options.maxPrice = -9999; for (var i = 0; i < data.changes.length; i++) { var price = parseFloat(data.changes[i].price); if (price < this.options.minPrice) { this.options.minPrice = price; }; if (price > this.options.maxPrice) { this.options.maxPrice = price; }; } if (this.options.minPrice < 0) { this.options.minPrice = 0; }; this.options.currentPrice = parseFloat(data.current_price); this.options.maxPrice = this.options.maxPrice + this.options.pricePadding; this.options.minPrice = this.options.minPrice - this.options.pricePadding; this.options.canvasActualHeight = canvas.height - (this.options.padding * 2); this.options.canvasActualWidth = canvas.width - (this.options.padding * 2); var gridValue = this.options.minPrice; while (gridValue <= this.options.maxPrice){ var gridY = this.options.canvasActualHeight * (1 - gridValue/this.options.maxPrice) + this.options.padding; ctx.strokeStyle="rgba(255,255,255,0.2)"; ctx.lineWidth=1; ctx.beginPath(); ctx.moveTo(0, gridY); ctx.lineTo(this.options.canvasActualWidth - this.options.labelIndent - 20, gridY); ctx.stroke(); var x = this.options.canvasActualWidth - this.options.labelIndent; if (this.options.currentPrice > gridValue-0.5 && this.options.currentPrice < gridValue+0.5) { ctx.font = this.options.labelFontActive; ctx.fillStyle = this.options.fillStyleActive; ctx.fillText("$" + this.options.currentPrice, x, gridY+6); }else{ ctx.font = this.options.labelFont; ctx.fillStyle = this.options.fillStyle; ctx.fillText("$" + Math.round(gridValue), x, gridY+5); }; gridValue += this.options.gridScale; } var currentX = 0; var currentY = this.options.canvasActualHeight * (1 - data.changes[0].price/this.options.maxPrice) + this.options.padding; var xSteps = (this.options.canvasActualWidth - this.options.labelIndent - 20) / data.changes.length; for (var i = 0; i < data.changes.length; i++) { var price = data.changes[i].price; var gridY = this.options.canvasActualHeight * (1 - price/this.options.maxPrice) + this.options.padding; // console.log(this.options.gridXscale); drawToX = currentX + xSteps; drawToY = gridY; ctx.strokeStyle="rgba(255,255,255,0.9)"; ctx.lineWidth=2; ctx.beginPath(); ctx.moveTo(currentX, currentY); ctx.lineTo(drawToX, drawToY); ctx.stroke(); currentX = drawToX; currentY = drawToY; console.log(currentX, currentY); } } }; var AccountPage = { load: function(){ triggerReload('.account-container', function(){}); }, init: function(){ if ($('.account-container').length) { AccountPage.load(); }; } }; function httpGetAsync(theUrl, callback) { var xmlHttp = new XMLHttpRequest(); xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState == 4 && xmlHttp.status == 200) callback(xmlHttp.responseText); } xmlHttp.open("GET", theUrl, true); // true for asynchronous xmlHttp.send(null); } function require(url, callback) { var e = document.createElement("script"); e.src = url; e.type = "text/javascript"; e.addEventListener('load', callback); document.getElementsByTagName("head")[0].appendChild(e); } // window.trackingLoaded = false; function findGetParameter(parameterName) { var result = null, tmp = []; location.search .substr(1) .split("&") .forEach(function(item) { tmp = item.split("="); if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]); }); return result; } function showAll(id) { $(id).find('a').removeClass('minified'); $(id).find('.js-show-all').remove(); } function getCookie(cname) { var name = cname + "="; var decodedCookie = decodeURIComponent(document.cookie); var ca = decodedCookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } function ajax_post(url, data, cb) { var xhr = new XMLHttpRequest(); xhr.open('POST', url); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.onload = function() { if (xhr.status === 200) { cb(xhr.responseText); } }; xhr.send(JSON.stringify(data)); } function lsTest() { var test = 'test'; try { localStorage.setItem(test, test); localStorage.removeItem(test); return true; } catch (e) { return false; } } function appDoScrollTop() { // alert('a'); window.scrollTo(0, 0); } function getURLParams(k) { var p = {}; location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(s, k, v) { p[k] = v }) return k ? p[k] : p; } function getRandomInt(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive } function mobilecheck() { var check = false; (function(a) { if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) check = true; })(navigator.userAgent || navigator.vendor || window.opera); return check; } function triggerReload(selector, cb) { var url = window.location.href; var separator = (window.location.href.indexOf("?") === -1) ? "?" : "&"; if (window.accessToken) { url = window.location.href + separator + "access_token=" + window.accessToken + "&r=" + Math.random(); }else{ url = window.location.href + separator + "r=" + Math.random(); }; var refreshClass = 'element-refreshing'; $(selector).addClass(refreshClass); $.ajax({ url: url, success: function(html) { var html = $(html).find(selector)[0].innerHTML; $(selector).html(html).removeClass(refreshClass); cb(); } }); } var TemplateEngine = function(html, options) { var re = /<%([^%>]+)?%>/g, reExp = /(^( )?(if|for|else|switch|case|break|{|}))(.*)?/g, code = 'var r=[];\n', cursor = 0, match; var add = function(line, js) { js? (code += line.match(reExp) ? line + '\n' : 'r.push(' + line + ');\n') : (code += line != '' ? 'r.push("' + line.replace(/"/g, '\\"') + '");\n' : ''); return add; } while(match = re.exec(html)) { add(html.slice(cursor, match.index))(match[1], true); cursor = match.index + match[0].length; } add(html.substr(cursor, html.length - cursor)); code += 'return r.join("");'; return new Function(code.replace(/[\r\t\n]/g, '')).apply(options); } function render(templateId, items){ var html = ''; if (document.getElementById(templateId)) { var templateText = document.getElementById(templateId).innerHTML; for (var i = 0; i < items.length; i++) { var renderedHtml = TemplateEngine(templateText, items[i]); html += renderedHtml; } }; return html; } var asideNav = { position: function(){ if (!$('.js-aside-nav-toggle').length) { return false; }; var top = $('.js-aside-nav-toggle').height() + $('.js-aside-nav-toggle').offset().top; var left = $('.js-aside-nav-toggle').offset().left; $('.js-aside-nav').css('top', top); $('.js-aside-nav').css('left', left); } }; var GameOverlay = { addHandlers: function(){ $('.js-game-item').on('click', function(event){ event.preventDefault(); var gameUrl = $(this).attr('href'); var id = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(2, 10); // $('body').append('
'); $.ajax({ url: gameUrl, success: function(html) { var html = $(html).find('article.app'); var title = $(html).find('h1.title'); if(html.length) { Modals.spawn(id); Modals.setContent(id, html); Modals.setMode(id, 'fullscreen'); Modals.open(id); lazyload(); // $('.game-overlay#'+id+' .header').append(title); // $('.game-overlay#'+id+' .content').append(html); // btn.removeClass('c-btn--loading'); // lazyload(); } else { // btn.removeClass('c-btn--loading'); // btn.addClass('c-btn--disabled'); // btn.after('no more games to load'); // btn.remove(); // btn.html('this is the end'); } } }); return false; // var containerId = $(this).attr('data-more-id'); // var itemOffset = $('#'+containerId+'').find('.js-container *').length; // // var query = 'test'; // if(findGetParameter('query')) { // var query = findGetParameter('query'); // } else { // var query = ''; // } // console.log(itemOffset); // var separator = (window.location.href.indexOf("?") === -1) ? "?" : "&"; // var url = window.location.href + separator + "offset=" + itemOffset + "&container_id=" + containerId + "&query=" + query ; // var btn = $(this); // btn.addClass('c-btn--loading'); // $.ajax({ // url: url, // success: function(html) { // var html = $(html).find('#'+containerId+' .js-container > *'); // // html.each(function( index ) { // // var $item = $( this ); // // $('#'+containerId+' .js-container').append($item); // // }); // console.log('appending ' + JSON.stringify(html)); // console.log(html.length); // if(html.length) { // $('#'+containerId+' .js-container').append(html); // btn.removeClass('c-btn--loading'); // lazyload(); // } else { // btn.removeClass('c-btn--loading'); // btn.addClass('c-btn--disabled'); // btn.after('no more games to load'); // btn.remove(); // // btn.html('this is the end'); // } // } // }); }); }, init: function(){ if (window.location.href.indexOf("?dev") != -1) { // GameOverlay.addHandlers(); }; // if ($('.js-load-more').length) { // LoadMore.addHandlers(); // }; } }; // var Channel = { store: [], load: function(){ if (!window.accessToken) { return false; }; $.ajax({ dataType: "json", url: '/api/channel/list?access_token=' + window.accessToken, success: function(data){ Channel.store = data; ChannelBtn.updateButtons(); } }); }, join: function(channelType, objectId, cb){ var url = '/api/channel/join'; if (window.accessToken) { url += '?access_token=' + window.accessToken; }; ajax_post(url, { 'object_id': objectId, 'channel_type': channelType, }, function(res){ cb(res); }); } }; var ChannelBtn = { updateButtons: function(){ $('.js-join-channel').each(function(i){ var channelType = $(this).attr('data-channel-type'); var objectId = $(this).attr('data-channel-object-id'); $(this).removeClass('active').removeClass('processing'); if ($(this).attr('data-default-text')) { $(this).text($(this).attr('data-default-text')); }; if (Channel.store.channels) { for (var i = 0; i < Channel.store.channels.length; i++) { var channel = Channel.store.channels[i].channel_object; if (channel.object_id == objectId && channel.type == channelType) { $(this).addClass('active'); if ($(this).attr('data-active-text')) { $(this).text($(this).attr('data-active-text')); }; }; } }; }); }, addHandlers: function(){ if (!$('.js-join-channel').length) { return false; }; $('.js-join-channel').on('click', function(){ var elementId = $(this).attr('id'); var channelType = $(this).attr('data-channel-type'); var objectId = $(this).attr('data-channel-object-id'); var requiresLogin = false; if ($(this).attr('data-require-login')) { requiresLogin = true; }; if (requiresLogin && !window.accessToken) { Modals.open('signin-modal'); Modals.setTitle('signin-modal', $(this).attr('data-require-login')); return false; }; if ($(this).attr('data-processing-text')) { $(this).text($(this).attr('data-processing-text')); }; $(this).addClass('processing'); Channel.join(channelType, objectId, function(){ Channel.load(); }); }); }, init: function(){ // ChannelBtn.updateButtons(); ChannelBtn.addHandlers(); if (lsTest() && localStorage.getItem('accessToken') && $('.js-join-channel').length) { Channel.load(); }; } }; var stickyElems = { init: function(){ if (!$('.js-page-header').length) { return false; }; stickyElems.setBodyPadding(); }, setBodyPadding: function(){ $('body').css('padding-top', stickyElems.measureHeight() +20 ); }, measureHeight: function(){ return $('.js-page-header').height(); } }; var megaMenu = { init: function(){ if (!$('.js-mega-menu-toggle').length) { return false; }; megaMenu.addListeners(); }, addListeners: function(){ $('.js-mega-menu-toggle').on('click', function(event){ megaMenu.toggle(); }); }, toggle: function(){ $('.js-mega-menu').toggleClass('open'); if ( $('.js-mega-menu-toggle').hasClass('close')) { $('.js-mega-menu-toggle').removeClass('close').addClass('open'); } else { $('.js-mega-menu-toggle').removeClass('open').addClass('close'); ga('send', 'event', 'MegaMenu', 'open'); } } }; var VoteBtn = { upvote: function(objectId, objectType, cb){ var url = '/api/vote'; if (window.accessToken) { url += '?access_token=' + window.accessToken; }; ajax_post(url, { 'object_id': objectId, 'object_type': objectType, }, function(res){ cb(res); }); }, addHandlers: function(){ if (!$('[data-vote-object-id]').length) { return false; }; $('[data-vote-object-id]').on('click', function(i){ var elementId = $(this).attr('id'); var objectId = $(this).attr('data-vote-object-id'); var objectType = $(this).attr('data-vote-object-type'); var requiresLogin = false; if ($(this).attr('data-require-login')) { requiresLogin = true; }; if (requiresLogin && !window.accessToken) { Modals.open('signin-modal'); Modals.setTitle('signin-modal', $(this).attr('data-require-login')); return false; }; VoteBtn.upvote(objectId, objectType, function(res){ if (elementId) { triggerReload('#' + elementId + '', function(){}); }; }); }); }, init: function(){ VoteBtn.addHandlers(); } }; var Carousel = { secsPerSlide: 8000, activeItem: 0, loop: function(){ var isHovered = $('.carousel').is(":hover"); if (!isHovered) { Carousel.timer = Carousel.timer - 100; }; if (Carousel.timer <= 0) { Carousel.timer = Carousel.secsPerSlide; Carousel.next(); }; window.setTimeout(Carousel.loop, 100); }, next: function(){ Carousel.activeItem = Carousel.activeItem + 1; if (Carousel.activeItem == $('.carousel .item').length) { Carousel.activeItem = 0; }; $('.carousel .pagination span').removeClass('active'); $('.carousel .pagination span').eq(Carousel.activeItem).addClass('active'); $('.carousel .item').removeClass('active'); $('.carousel .item').eq(Carousel.activeItem).addClass('active'); var offsetWidth = $('.carousel .item').eq(1).width(); Carousel.offset = Carousel.activeItem * (offsetWidth*-1); $('.carousel .inner').css('transform', 'translateX(' + Carousel.offset + 'px)'); }, resizeItems: function(){ $('.carousel .item').width($('.banner')[0].offsetWidth+40); }, init: function(){ Carousel.resizeItems(); window.addEventListener("resize", Carousel.resizeItems); if ($('.carousel').length) { $('.carousel .item').each(function(index){ var itemId = index; $(this).attr('id', itemId); $('.carousel .pagination').append(''); }); $('.carousel .pagination span').eq(0).addClass('active'); $('.carousel .pagination span').on('click', function(){ var activeItem = parseInt($(this).attr('data-item-id'))-1; Carousel.activeItem = activeItem; Carousel.timer = 0; }); Carousel.timer = Carousel.secsPerSlide; window.setTimeout(Carousel.loop, 100); } } }; var Comments = { getReplyForm: function(parentId){ html = `
`; return html; }, renderComment: function(comment){ var html = ''; html += '
'; html += '
'; html += '
'; html += ''+ comment.username + ''; html += '▲ ' + comment.upvotes + ' ' ; html += '' + comment.relative_created_at + ''; html += '
'; html += '
' + comment.body + '
'; html += '
'; if (comment.children.length) { html += '
'; for (var i = 0; i < comment.children.length; i++) { html += Comments.renderComment(comment.children[i]); } html += '
'; }; html += '
'; return html; }, removeEmptyTextareas: function(el){ el.find('.comment .submit-form').each(function(){ var text = $(this).find('textarea').val(); if (!text.length) { $(this).remove(); }; }); }, addHandlers: function(el){ el.find('.js-open-signin-modal').on('click', function(event){ event.preventDefault(); Modals.open('signin-modal'); Modals.setTitle('signin-modal', 'Start a discussion.'); }); el.find('.comment .body').on('click', function(){ var parentId = $(this).parents('.comment').attr('data-comment-id'); if (!$(this).parent().find('.submit-form').length) { Comments.removeEmptyTextareas(el); // el.find('.comment .submit-form').remove(); var form = Comments.getReplyForm(parentId); $(this).parent().append(form); Comments.addHandlers(el); }; }); el.find('.submit-form textarea').on('change keyup paste', function(){ if ($(this).val().length) { $(this).closest('.js-submit-btn').addClass('ready'); }else{ $(this).closest('.js-submit-btn').removeClass('ready'); }; }); el.find('[data-sort-option]').on('click', function(event){ var currentSort = el.attr('data-sort'); var selectedSort = $(this).attr('data-sort-option'); if (currentSort != selectedSort) { el.attr('data-sort', selectedSort); Comments.fetchCommentsContainer(el); // console.log(selectedSort, currentSort); }; // if ($(this).attr('data-sort-option') != el.attr('data-sort')) { // el.attr('data-sort', $(this).attr('data-sort-option')); // }; // Comments.fetchCommentsContainer(el); }); el.find('.submit-form form').on('submit', function(event){ var objectId = el.attr('data-object-id'); var parentId = $(this).attr('data-parent-id'); if (!window.accessToken) { Modals.open('signin-modal'); Modals.setTitle('signin-modal', 'Start a discussion.'); return false; }; event.preventDefault(); var data = { 'text': $(this).find('textarea').val(), 'object_id': objectId, 'parent_id': parentId }; ga('send', 'event', 'Comment', 'submit'); ajax_post('/api/comments/create?access_token=' + window.accessToken, data, function(res){ el.attr('changed', '1'); Comments.fetchCommentsContainer(el); }); }); el.find('[data-upvote-comment]').on('click', function(){ var objectId = $(this).attr('data-upvote-comment'); var objectType = 'comment'; $(this).addClass('disabled'); VoteBtn.upvote(objectId, objectType, function(res){ el.attr('changed', '1'); el.find('.upvotes').removeClass('disabled'); Comments.fetchCommentsContainer(el); // if (elementId) { // triggerReload('#' + elementId + '', function(){}); // }; }); // $.get("/api/comments/upvote?comment_id=" + commentId, function(){ // el.attr('changed', '1'); // el.find('.upvotes').removeClass('disabled'); // Comments.fetchCommentsContainer(el); // }); }); $('.js-toggle-commentform').on('click', function(){ Comments.toggleCommentForm(); }); }, fetchCommentsContainer: function(el){ // el.append('comments'); var objectId = el.attr('data-object-id'); console.log('rendering', objectId); el.attr('changed', '0'); if (!el.attr('data-sort')) { el.attr('data-sort', 'new'); }; el.addClass('container-loading'); // objectId = 'game-1013536952'; $.getJSON( "/api/comments?object_id=" + objectId + "&sort=" + el.attr('data-sort'), function(data) { el.find('*').remove(); el.removeClass('container-loading'); var html = ''; if (!window.accessToken) { html += ''; }; if (window.accessToken) { html += `
`; }; if (data.comments.length) { html += '
'; if (data.count) { html += '
' + data.count + ' ' + (data.count==1 ? 'Comment' : 'Comments') + '
'; }; var sortOptions = [ {'id': 'new', 'title': 'New', 'active': (el.attr('data-sort') == 'new')}, {'id': 'best', 'title': 'Best', 'active': (el.attr('data-sort') == 'best')} ]; html += '
'; for (var i = 0; i < sortOptions.length; i++) { html += '' + sortOptions[i].title + ''; } html += '
'; html += '
'; html += '
'; //
' + data.count + ' Comments
'; }else{ html += '
Be the first to comment!
'; }; html += '
'; for (var i = 0; i < data.comments.length; i++) { html += Comments.renderComment(data.comments[i]); } html += '
'; el.append(html); Comments.addHandlers(el); }); }, toggleCommentForm: function(){ $('.js-commentform').toggleClass('hide'); $('.js-toggle-commentform').toggleClass('hide'); }, watchChanges: function(){ $('.js-comments-wrapper').each(function(){ if ($(this).attr('changed') == '1') { Comments.fetchCommentsContainer($(this)); }; }); window.setTimeout(Comments.watchChanges, 1000); }, init: function(){ if (!$('.js-comments-wrapper').length) { return false; } $('.js-comments-wrapper').each(function(){ Comments.fetchCommentsContainer($(this)); }); Comments.watchChanges(); } }; var PetitionView = { setBackersV2: function(elem, count, max){ countFormat = count.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); maxFormat = max.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); if (count == 0) { elem.remove(); }; if (count == 1) { elem.html('' + countFormat + ' has upvoted. Let\'s go to ' + maxFormat + '!'); } if(count > 1){ elem.html('' + countFormat + ' have upvoted. Let\'s go to ' + maxFormat + '!'); }; elem.find('.js-petition-progress-bar').attr('value', count).attr('max', max); }, setBackers: function(elem, count, max){ countFormat = count.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); maxFormat = max.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); if (count == 0) { elem.find('.js-petition-progress-text').html('Be the first to support this Petition!'); } if (count == 1) { elem.find('.js-petition-progress-text').html('' + countFormat + ' has signed. Let\'s go to ' + maxFormat + '!'); } if(count > 1){ elem.find('.js-petition-progress-text').html('' + countFormat + ' have signed. Let\'s go to ' + maxFormat + '!'); }; elem.find('.js-petition-progress-bar').attr('value', count).attr('max', max); }, getSupporters: function(petitionSlug, cb){ $.getJSON('/no-cache/mailchimp-v2.php?slug=' + petitionSlug + '&action=get_count', function(data) { var count = data.count ? data.count : 0; var max = 100; if (count > 100) { max = 300; }; if (count > 300) { max = 500; }; if (count > 500) { max = 1000; }; if (count > 1000) { max = 2000; }; if (count > 2000) { max = 3000; }; if (count > 3000) { max = 4000; }; if (count > 4000) { max = 5000; }; if (count > 5000) { max = 10000; }; if(lsTest()){ localStorage.setItem(petitionSlug + '_stats_count', count); localStorage.setItem(petitionSlug + '_stats_max', max); } // PetitionView.setBackers(count, max); cb(count, max); }); }, getUpvotes: function(petitionSlug, cb){ $.getJSON('/no-cache/mailchimp-v3.php?slug=' + petitionSlug + '&action=get_upvotes', function(data) { cb(data.count, data.max); }); }, createPetitionCaptionElement: function(elem){ var petitionSlug = elem.attr('data-gameslug'); PetitionView.getUpvotes(petitionSlug, function(count, max){ PetitionView.setBackersV2(elem, count, max); }); }, createPetitionProgressElement: function(elem){ var petitionSlug = elem.attr('data-gameslug'); // console.log(elem, petitionSlug); if(lsTest() && localStorage.getItem(petitionSlug + '_stats_count')){ PetitionView.setBackers(elem, localStorage.getItem(petitionSlug + '_stats_count'), localStorage.getItem(petitionSlug + '_stats_max')); }else{ PetitionView.setBackers(elem, 0, 100); } PetitionView.getSupporters(petitionSlug, function(count, max){ PetitionView.setBackers(elem, count, max); }); }, validateEmail: function(email) { var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(String(email).toLowerCase()); }, disableForm: function(){ $('#mc-embedded-subscribe-form').addClass('disabled'); }, setState: function(type){ if(lsTest()){ localStorage.setItem(petitionSlug + '_state_type', type); } $('div.message').hide(); if (type == 'opt-in-pending') { PetitionView.disableForm(); $('[data-state=opt-in-pending]').show(); }; if (type == 'user-already-supported') { PetitionView.disableForm(); $('[data-state=user-already-supported]').show(); }; if (type == 'opt-in-success') { PetitionView.disableForm(); $('[data-state=opt-in-success]').show(); }; }, addHandlers: function(){ $('.js-upvote-btn').on('click', function(){ var emailAddress = ''; // console.log('test'); $.post('/no-cache/mailchimp-v3.php?slug=' + petitionSlug + '&action=upvote', function(data){ var data = JSON.parse(data); if (data.status == 500) { if(lsTest()){ localStorage.setItem(petitionSlug + '_has_upvoted', '1'); $('#js-submit-form').show(); $('.js-upvote-btn').addClass('disabled'); } }; if (data.status == 200) { if(lsTest()){ localStorage.setItem(petitionSlug + '_has_upvoted', '1'); } $('.js-upvote-btn').addClass('disabled'); ga('send', 'event', 'Game', 'Upvote', petitionSlug); $('#js-submit-form').show(); if ($('.js-petition-caption').length) { // found petition progress bar $('.js-petition-caption').each(function(){ var gameSlug = $(this).attr('data-gameslug'); var elem = $(this); PetitionView.getUpvotes(gameSlug, function(count, max){ PetitionView.setBackersV2(elem, count, max); }); // PetitionView.createPetitionCaptionElement(); }); }; }; }); }); $('form#mc-embedded-subscribe-form').on('submit', function(event){ event.preventDefault(); if (!$('#gdpr').is(":checked")) { alert('Sorry, to participate please accept the terms!') return false; } var emailAddress = $('form input[name=EMAIL]').val(); // var name = $('form input[name=NAME]').val(); if (!PetitionView.validateEmail(emailAddress)) { alert('Sorry, please check that you have entered a valid email address.'); return false; }; $.post('/no-cache/mailchimp-v2.php?slug=' + petitionSlug + '&action=support&email=' + emailAddress, function(data){ data = JSON.parse(data); if (data.status == 400) { PetitionView.setState('user-already-supported'); }; if (data.status == 'pending') { ga('send', 'event', 'Petition', 'SignUp', petitionSlug); PetitionView.setState('opt-in-pending'); }; }); }); }, reloadBackers: function(){ $.getJSON('/no-cache/mailchimp.php?slug=' + petitionSlug + '&action=get_count', function(data) { var count = data.count; var max = 100; if (count > 100) { max = 300; }; if (count > 300) { max = 500; }; if (count > 500) { max = 1000; }; if (count > 1000) { max = 2000; }; if (count > 2000) { max = 3000; }; if (count > 3000) { max = 4000; }; if (count > 4000) { max = 5000; }; if (count > 5000) { max = 10000; }; if(lsTest()){ localStorage.setItem('stats_count', count); localStorage.setItem('stats_max', max); } PetitionView.setBackers(count, max); }); }, init: function(){ if (typeof petitionSlug == 'undefined') { return false; }; if(lsTest() && localStorage.getItem(petitionSlug + '_has_upvoted') == '1'){ $('.js-upvote-btn').addClass('disabled'); $('#js-submit-form').show(); } if(lsTest() && localStorage.getItem(petitionSlug + '_state_type')){ PetitionView.setState(localStorage.getItem(petitionSlug + '_state_type')); } if ($('div.petition').length) { // is petition single if(lsTest() && localStorage.getItem(petitionSlug + '_state_type')){ PetitionView.setState(localStorage.getItem(petitionSlug + '_state_type')); } PetitionView.addHandlers(); // PetitionView.reloadBackers(); // PetitionView.loadActivity(); if (signupSuccess) { ga('send', 'event', 'Petition', 'Confirm', petitionSlug); PetitionView.setState('opt-in-success'); }; }; if ($('.js-petition-caption').length) { // found petition progress bar $('.js-petition-caption').each(function(){ PetitionView.createPetitionCaptionElement($(this)); }); }; if ($('.js-petition-progress').length) { // found petition progress bar $('.js-petition-progress').each(function(){ PetitionView.createPetitionProgressElement($(this)); }); }; } }; var Wishlist = { render: function(html){ if ($(html).find('.wishlist-container').length) { var html = $(html).find('.wishlist-container')[0].innerHTML; $('.wishlist-container').html(html); lazyload(); }; }, load: function(){ if (!window.accessToken) { return false; }; $.ajax({ url: '?access_token=' + window.accessToken + '&r=' + Math.random(), success: function(html){ Wishlist.render(html); } }); }, init: function(){ if ($('.wishlist-container').length) { Wishlist.load(); }; } }; var Forms = { showMessage: function(formElement, type, text){ // console.log(type, text); var $message = $(''); formElement.find('.form--messages .message').remove(); formElement.find('.form--messages').append($message); setTimeout(function(){ $message.removeClass('hidden'); }, 0); setTimeout(function(){ $message.addClass('hidden'); setTimeout(function(){ $message.remove(); }, 200); }, 3500); }, addHandlers: function(formElement){ // formElement.find('.js-autosubmit').on('click', function(){ // alert('a'); // }); formElement.find('form .js-autosubmit').on('input', function(){ formElement.find('form').submit(); }); formElement.find('form').on('submit', function(event){ event.preventDefault(); var formUrl = $(this).attr('action'); var formMethod = $(this).attr('method'); var separator = (formUrl.indexOf("?")===-1)?"?":"&"; var url = formUrl + separator + "access_token=" + window.accessToken + "&r=" + Math.random(); ajax_post(url, $(this).serializeArray(), function(res){ var data = JSON.parse(res); if (data.status == 'error') { Forms.showMessage(formElement, 'warning', data.message); }; if (data.status == 'ok' && data.message) { Forms.showMessage(formElement, 'success', data.message); }; if (data.status == 'ok' && data.redirect_to) { window.location.href = data.redirect_to; }; // triggerReload('#' + formId, function(){}); }); }); }, initForm: function(formElement){ var formId = formElement.attr('id'); // console.log(formElement); if (formElement.hasClass('js-refresh')) { formElement.addClass('initiated'); triggerReload('#' + formId, function(){ Forms.addHandlers($('#' + formId)); }); }; formElement.addClass('initiated'); Forms.addHandlers(formElement); }, refresh: function(){ var components = $('.form--component'); if (components.length) { components.each(function(){ if (!$(this).hasClass('initiated')) { Forms.initForm($(this)); }; }); }; window.setTimeout(Forms.refresh, 500); }, init: function(){ Forms.refresh(); } }; var Bookmarks = { accessToken: '', store: [], load: function(){ if (!window.accessToken) { return false; }; if (!$('.js-bookmark-button').length) { return false; }; $.ajax({ dataType: "json", url: '/api/bookmarks?access_token=' + window.accessToken, success: function(data){ Bookmarks.store = data; Bookmarks.updateButtons(); } }); }, create: function(type, id, cb){ ga('send', 'event', 'Bookmark', 'create', type); ajax_post('/api/bookmarks/create?access_token=' + window.accessToken, { 'type': type, 'id': id }, cb); }, updateButtons: function(){ $('.js-bookmark-button').each(function(i){ var type = $(this).attr('data-type'); var id = $(this).attr('data-id'); $(this).removeClass('active').removeClass('processing'); if ($(this).attr('data-default-text')) { $(this).text($(this).attr('data-default-text')); }; for (var i = 0; i < Bookmarks.store.length; i++) { if (Bookmarks.store[i].type == type && Bookmarks.store[i].object_id == id) { $(this).addClass('active'); if ($(this).attr('data-active-text')) { $(this).text($(this).attr('data-active-text')); }; }; } }); }, addHandlers: function(){ $('.js-bookmark-button').on('click', function(){ if (!window.accessToken) { Modals.open('signin-modal'); Modals.setTitle('signin-modal', 'Start bookmarking games and collections.'); return false; }; var type = $(this).attr('data-type'); var id = $(this).attr('data-id'); if ($(this).attr('data-processing-text')) { $(this).text($(this).attr('data-processing-text')); }; $(this).addClass('processing'); Bookmarks.create(type, id, function(res){ Bookmarks.load(); }); }); }, init: function(){ Bookmarks.accessToken = localStorage.getItem('accessToken'); Bookmarks.addHandlers(); Bookmarks.updateButtons(); if (lsTest() && localStorage.getItem('accessToken')) { Bookmarks.load(); }; } }; var Modals = { getById: function(id){ return $('.c-modal#'+id+''); }, setTitle: function(id, title){ var el = Modals.getById(id); el.find('.c-modal__title').text(title); }, setContent: function(id, content){ var el = Modals.getById(id); el.append(content); }, setMode: function(id, mode){ var el = Modals.getById(id); el.addClass('mode-' + mode); }, spawn: function(id){ $('.js-modal-bg').append('
'); }, open: function(id){ var el = Modals.getById(id); Modals.closeAll(); ga('send', 'event', 'Modal', 'open', id); $('body').addClass('has-modal'); $('.js-modal-bg').addClass('active'); el.addClass('active'); Modals.addHandlers(); }, closeAll: function(){ $('body').removeClass('has-modal'); $('.js-modal-bg, .js-modal-window').removeClass('active'); }, addHandlers: function(){ $('[data-close-modal]').on('click', function(event){ if (event.target !== this) { return; } Modals.closeAll(); }); $('[data-open-modal]').on('click', function(event){ event.preventDefault(); event.stopPropagation(); var id = $(this).attr('data-open-modal'); Modals.open(id); }); }, init: function(){ Modals.addHandlers(); } }; var LoadMore = { addHandlers: function(){ $('.js-load-more [data-more-id]').on('click', function(){ var containerId = $(this).attr('data-more-id'); var itemOffset = $('#'+containerId+'').find('.js-container *').length; // var query = 'test'; if(findGetParameter('query')) { var query = findGetParameter('query'); } else { var query = ''; } console.log(itemOffset); var separator = (window.location.href.indexOf("?") === -1) ? "?" : "&"; var url = window.location.href + separator + "offset=" + itemOffset + "&container_id=" + containerId + "&query=" + query ; var btn = $(this); btn.addClass('c-btn--loading'); $.ajax({ url: url, success: function(html) { var html = $(html).find('#'+containerId+' .js-container > *'); // html.each(function( index ) { // var $item = $( this ); // $('#'+containerId+' .js-container').append($item); // }); console.log('appending ' + JSON.stringify(html)); console.log(html.length); if(html.length) { $('#'+containerId+' .js-container').append(html); btn.removeClass('c-btn--loading'); lazyload(); } else { btn.removeClass('c-btn--loading'); btn.addClass('c-btn--disabled'); btn.after('no more games to load'); btn.remove(); // btn.html('this is the end'); } } }); }); }, init: function(){ if ($('.js-load-more').length) { LoadMore.addHandlers(); }; } }; // var User = { updateDom: function(){ if (!lsTest()) { return false; }; var data = localStorage.getItem('profileInfo'); // console.log(): // if (!data.picture) { // data = JSON.parse(data); // }; if (typeof data == 'string') { data = JSON.parse(data); }; if (data.picture) { $('.js-profile-button-container').append('username'); }; }, setAccessToken: function(accessToken){ window.accessToken = accessToken; localStorage.setItem('accessToken', accessToken); }, getAccessToken: function(){ return window.accessToken ? window.accessToken : false; }, addHandlers: function(){ if ($('#googleSignIn').length) { $('#googleSignIn').on('click', function(){ User.triggerGoogleLogin(); }); }; }, triggerGoogleLogin: function(){ require("https://apis.google.com/js/platform.js", function() { gapi.load('auth2', function(){ // auth2 = gapi.auth2.init({ // client_id: '411684599155-gd21l82c2ph03a7hpiubhijnjl4najdd.apps.googleusercontent.com', // cookiepolicy: 'single_host_origin', // scope: 'profile email' // }); gapi.auth2.authorize({ client_id: '411684599155-gd21l82c2ph03a7hpiubhijnjl4najdd.apps.googleusercontent.com', scope: 'email profile', response_type: 'id_token permission' }, function(response) { if (response.id_token) { httpGetAsync('/authenticate/success?id_token=' + response.id_token, function(res){ var res = JSON.parse(res); if (res.access_token) { User.setAccessToken(res.access_token); if (res.auth_type == 'signup') { ga('send', 'event', 'User', 'signup', 'google'); }; if (res.auth_type == 'login') { ga('send', 'event', 'User', 'signin', 'google'); }; // window.accessToken = res.access_token; // updateButtons("You're signed in!"); window.setTimeout(function(){ Modals.closeAll(); // Bookmarks.load(); }, 1000); }; }); }; }); // auth2.attachClickHandler(element, {}, function(googleUser) { // if (!window.accessToken) { // var id_token = googleUser.getAuthResponse().id_token; // updateButtons("Processing"); // httpGetAsync('/authenticate/success?id_token=' + id_token, function(res){ // var res = JSON.parse(res); // if (res.access_token) { // localStorage.setItem('accessToken', res.access_token); // if (res.auth_type == 'signup') { // ga('send', 'event', 'User', 'signup', 'google'); // }; // if (res.auth_type == 'login') { // ga('send', 'event', 'User', 'signin', 'google'); // }; // window.accessToken = res.access_token; // updateButtons("You're signed in!"); // window.setTimeout(function(){ // Modals.closeAll(); // Bookmarks.load(); // }, 1000); // }; // }); // }; // }, function(error) { // console.log('Sign-in error', error); // }); // // $('#googleSignIn').trigger('click'); }); // var element = document.getElementById('googleSignIn'); }); }, setProfileInfo: function(res){ // window.profileInfo = res; localStorage.setItem('profileInfo', res); }, fetchProfileInfo: function(cb){ var data = localStorage.getItem('profileInfo'); if (typeof data == 'string') { data = JSON.parse(data); }; if (!data && window.accessToken) { httpGetAsync('/api/me?access_token=' + window.accessToken, function(res){ cb(res); // var res = JSON.parse(res); // $('.js-profile-button-container').append('username'); }); }else{ cb(localStorage.getItem('profileInfo')); // window.profileInfo = localStorage.getItem('profileInfo'); // User.updateDom(); // User.setProfileInfo(); // $('.js-profile-button-container').append('username'); }; }, init: function(){ if (!lsTest()) { return false; }; if (localStorage.getItem('accessToken')) { window.accessToken = localStorage.getItem('accessToken'); window.isLoggedIn = true; }else{ window.accessToken = false; window.isLoggedIn = false; }; if (window.isLoggedIn) { if (!localStorage.getItem('profileInfo')) { User.fetchProfileInfo(function(res){ User.setProfileInfo(res); User.updateDom(); }); }else{ User.updateDom(); }; }; User.addHandlers(); } }; var mfiGameSearch = { addHandlers: function() { var $searchInput = $('.js-mfi-game-search'); if($searchInput.val() != '') { $searchInput.addClass('mfi-game-search--filled'); } }, init: function(){ // if ($('.js-mfi-game-search').length) { // mfiGameSearch.addHandlers(); // }; } } function spawnParticles(element){ var kudos = ['copied!']; var id = Date.now(); var offset = element.offset(); var width = element.width(); var clickParticle = $( `
${kudos[getRandomInt(0,kudos.length)]}
`); clickParticle.clone().appendTo('body'); setTimeout(function() { //clickParticle.remove(); $('.id-'+ id).remove(); }, 1000); console.log('created particle'); } // function updateListCount(){ // // var count = $('.js-item:visible').length; // // $(".js-count").text("Showing " + count + " Games"); // } function findGetParameter(parameterName) { var result = null, tmp = []; location.search .substr(1) .split("&") .forEach(function (item) { tmp = item.split("="); if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]); }); return result; } function loadData(itemsPerPage, page, cb){ var querystring = '?page=' + page + '&perpage=' + itemsPerPage; $.ajax({ dataType: "json", url: '/api.php' + querystring, success: function(data){ cb(data); // console.log('altering history'); // window.history.pushState('page2', 'Title', '/' + querystring); } }); } function searchData(itemsPerPage, page, searchQuery, cb){ $.ajax({ dataType: "json", url: '/api.php?page=' + page + '&perpage=' + itemsPerPage + '&s=' + searchQuery, success: function(data){ cb(data); } }); } function updateLoginUi(){ if (window.accessToken) { $('.hide-logged-in').hide(); }else{ $('.hide-logged-out').hide(); }; } function watchLoginState(){ var loggedIn = (window.accessToken && window.accessToken.length > 20); if (loggedIn != window.isLoggedIn) { console.log('login state', loggedIn); window.isLoggedIn = loggedIn; // fire refreshes Bookmarks.load(); Wishlist.load(); AccountPage.load(); User.fetchProfileInfo(function(res){ User.setProfileInfo(res); User.updateDom(); }); updateLoginUi(); $('.js-comments-wrapper').attr('changed', '1'); }; window.setTimeout(watchLoginState, 500); } function initWatchLoginState(){ watchLoginState(); } function emptyList(){ $('.list div').remove(); } var delay = (function(){ var timer = 0; return function(callback, ms){ clearTimeout (timer); timer = setTimeout(callback, ms); }; })(); function drawStatistics(){ var maxValue = 0; for (var i = 0; i < pricing.length; i++) { if (pricing[i] > maxValue) { maxValue = Math.ceil(pricing[i]); }; } maxValue = maxValue + 2; var stageHeight = $('#price-canvas').attr('height'); var stageWidth = $('#price-canvas').attr('width'); // console.log(stageWidth); // var percentage = (pricing[i]/maxValue) * 10; var gridWidth = stageWidth / (pricing.length-1); var gridHeight = stageHeight / 10; // console.log(gridHeight); var c=document.getElementById("price-canvas"); var ctx=c.getContext("2d"); var previousX = false; var previousY = false; for (var i = 0; i < 10; i++) { ctx.strokeStyle="rgba(255,255,255,0.2)"; ctx.lineWidth=1; ctx.beginPath(); ctx.moveTo(0, stageHeight - (i * gridHeight) - 5); ctx.lineTo(stageWidth, stageHeight - (i * gridHeight) - 5); ctx.stroke(); if (i % 2 == 0) { var price = (maxValue/10)*i; ctx.font = "18px Arial"; ctx.fillStyle = "#d9e1e8"; ctx.fillText("$" + Math.round(price), 0, (stageHeight - (i * gridHeight)) - 5); }; } for (var i = 0; i < pricing.length; i++) { var percentage = (pricing[i]/maxValue) * 100; var yOffset = 0; var x = 40 + gridWidth * i; var y = (stageHeight - ((stageHeight / 100) * percentage)) + yOffset; if (!previousX && !previousY) { previousX = x; previousY = y; }; ctx.strokeStyle="#d9e1e8"; ctx.lineWidth=3; if (pricing.length-1 == i) { x = x - 50; ctx.beginPath(); ctx.arc(x,y,3,0,2*Math.PI); ctx.fillStyle = "#d9e1e8"; ctx.fill(); ctx.stroke(); }; ctx.beginPath(); ctx.moveTo(previousX, previousY); ctx.lineTo(x,y); ctx.stroke(); var text = "$" + pricing[i]; previousX = x; previousY = y; } var percentage = (avaragePrice/maxValue) * 100; var y = (stageHeight - ((stageHeight / 100) * percentage)) + yOffset; ctx.beginPath(); ctx.moveTo(40, y); ctx.strokeStyle="rgba(255,255,255,0.4)"; ctx.lineWidth=2; ctx.setLineDash([10, 5]); ctx.lineTo(stageWidth-5,y); ctx.stroke(); } var baseUrl = 'http://controller.wtf'; // var searchFilters = { // init: function(){ // // searchFilters.toggle(); // $('.js-filters-trigger').on('click', function(){ // searchFilters.toggle(); // }); // // $(".js-autosubmit-item").change(function() { // // console.log('change!'); // // $(".js-search-filter-form").submit(); // // }); // }, // toggle: function(){ // $('.js-filters').toggleClass('open'); // // searchFilters.toggleModalBg(); // }, // toggleModalBg: function(){ // if ($('.modal-bg').length) { // $('.modal-bg').addClass('remove'); // $('.modal-bg').remove(); // // $('.modal-bg').animate({ // // opacity: 0, // // }, 400, function() { // // $(this).remove(); // // }); // } else { // $(body).append(''); // } // } // } // var loadingIndicator = { // init: function(){ // if ($('.loadingindicator').length) { // $('.loadingindicator').each(function(i, obj) { // var width = $(obj).width(); // var height = $(obj).height(); // console.log(width, height); // $(obj).find('rect').attr('width', width); // $(obj).find('rect').attr('height', height); // }); // } // } // } $('.js-loading-indicator').click(function (e) { $(this).addClass('animation'); }); // var Search = { // idx: false, // maxResults: 150, // popularSearches: [ // 'Grand Theft Auto', // 'NBA', // 'Simulator', // "Assassin's Creed", // 'Racing', // 'Classic', // 'Space Marshals', // 'Sonic' // ], // data: {}, // query: function(str, cb){ // var searchString = '*' + str + '* ' + str; // console.log('querying', searchString); // var results = Search.idx.search(searchString); // var resultCollection = []; // for (var i = 0; i < results.length; i++) { // if (typeof Search.data[results[i].ref] != 'undefined') { // resultCollection.push(Search.data[results[i].ref]); // if (i >= (Search.maxResults-1)) { // break; // }; // }; // } // cb({ // results: resultCollection, // html: Search.renderResults(resultCollection) // }); // }, // renderResults: function(results){ // return render('list-item', results); // }, // addDocuments: function(data){ // Search.idx = lunr(function () { // this.ref('slug'); // this.field('title'); // this.field('slug'); // this.field('price'); // this.field('top_genre'); // data.forEach(function (doc) { // Search.data[doc.slug] = doc; // this.add(doc); // }, this); // }); // }, // animationLoop: function(){ // if ($('.js-hidden').length) { // $('.js-hidden').each(function(index){ // $(this).removeClass('js-hidden'); // if (index > 0) { // // return false; // }; // }); // }; // window.setTimeout(Search.animationLoop, 60); // }, // clear: function(){ // var ulSelector = 'ul.list--search-results'; // if ($(ulSelector).length) { // $(ulSelector).remove(); // }; // }, // updateUI: function(){ // var searchQuery = $('input[name=query]').val(); // if (searchQuery == '') { // $('.clear-query').remove(); // }else{ // if (!$('.search__field .clear-query').length) { // $('div.search__field').append('×'); // $('.clear-query').on('click', function(){ // $('input[name=query]').val(''); // Search.performQuery(''); // }); // } // }; // if (!$('.list__item').length && searchQuery != '') { // $('.results-text').text('Sorry, no results. :('); // $('.results-text').show(); // }else{ // $('.results-text').hide(); // }; // if (!$('.list__item').length) { // if (!$('.popular-searches div').length) { // for (var i = 0; i < Search.popularSearches.length; i++) { // $('.popular-searches').append('
' + Search.popularSearches[i] + '
'); // } // $('.popular-searches div').on('click', function(){ // var query = $(this).attr('data-search'); // $('input[name=query]').val($(this).attr('data-search')); // Search.performQuery(query); // }); // }; // }else{ // $('.popular-searches div').remove(); // }; // }, // performQuery: function(query){ // var ulSelector = 'ul.list--search-results'; // var totalDocs = Object.keys(Search.data).length; // if (query=='') { // Search.clear(); // Search.updateUI(); // return false; // }; // Search.query(query, function(resultData){ // Search.clear(); // if (resultData.results.length < totalDocs && resultData.results.length > 0) { // var listHtml = ''; // $(listHtml).insertAfter($(".page .search")); // lazyload(); // }; // Search.updateUI(); // }); // }, // init: function(){ // $.getJSON('/data/search-index.json', function(data){ // Search.addDocuments(data); // }); // $('input[name=query]').on('input', function(){ // Search.performQuery($(this).val()); // }); // Search.updateUI(); // // Search.updatePopularSearches(); // Search.animationLoop(); // } // }; // var Auth = { // init: function() { // // var idToken; // // var accessToken; // // var expiresAt; // // var webAuth = new auth0.WebAuth({ // // domain: 'controller-wtf.eu.auth0.com', // // clientID: 'ZNnGsiUDLET3XAroRUhd4o3l5LkoqSev', // // responseType: 'token id_token', // // scope: 'openid', // // redirectUri: 'https://controller.wtf/auth' // // }); // // $('.open-login').on('click', function(){ // // webAuth.authorize(); // // }); // // var loginBtn = document.getElementById('btn-login'); // // loginBtn.addEventListener('click', function(e) { // // e.preventDefault(); // // }); // } // }; $(function(){ // this has to be executed first User.init(); lazyload(); appDescription.init(); PetitionView.init(); // Carousel.init(); // updateListCount(); // modal.toggle(); // searchFilters.init(); LoadMore.init(); Bookmarks.init(); Modals.init(); Wishlist.init(); GameOverlay.init(); AccountPage.init(); Forms.init(); Comments.init(); asideNav.position(); ChannelBtn.init(); VoteBtn.init(); // loadingIndicator.init(); megaMenu.init(); stickyElems.init(); mfiGameSearch.init(); initWatchLoginState(); updateLoginUi(); if ($('#price-canvas').length) { drawStatistics(); } if ($('#price-canvas').length) { drawStatistics(); } if ($('#price-canvas-v2').length) { drawStatisticsv2(); } $('body').removeClass('loaded'); // if(findGetParameter('mode') == 'app' || navigator.userAgent == 'CtrlWtfApp'){ // $('body').addClass('is-app'); // function sendPageInfo(){ // console.log('bridge ready'); // window.parent.postMessage({ // type: 'urlChange', // from: 'website', // page: { // url: window.location.href, // title: document.title // } // }, "*"); // } // function waitForBridge() { // if (window.parent.postMessage.length !== 1){ // setTimeout(waitForBridge, 100); // }else { // sendPageInfo(); // } // } // waitForBridge(); // // document.addEventListener("message", function(event){ // // console.log(event); // // var data = JSON.parse(event.data); // // if (data.from == 'app' && data.action == 'scrollToTop') { // // window.scrollTo(0,0); // // }; // // }, false); // } if (typeof ga === "function") { ga("send", "pageview"); } // $('a').each(function(){ // if ($(this).attr('href').includes("/link/")) { // $(this).addClass('js-conversion-link'); // }; // }); $('.js-conversion-link').on('click', function(event){ event.preventDefault(); var self = this; ga('send', 'event', 'Game', 'ASLinkConversion', $(self).attr('href')); window.setTimeout(function(){ window.location = $(self).attr('href'); }, 50); }); var page = 1; var itemsPerPage = 30; if (typeof getURLParams('page') !== 'undefined') { var page = getURLParams('page'); } $('.js-nextpage').on('click', function(e){ e.preventDefault(); page++; loadData(itemsPerPage, page, function(data){ if (data.games) { $('.list').append(render('template-list-item', data.games)); lazyload(); } }) }); $('.js-product-link-track').on('click', function(){ ga('send', 'event', 'Product', 'View', $(this).attr('href')); }); // $('.toggle-view').each(function(){ // var maxHeight = $(this).attr('data-max-height'); // var id = 'id-' + Date.now(); // $(this).attr('id', id); // $(this).css('max-height', maxHeight + 'px'); // $(this).append('Read More'); // $(this).addClass('closed'); // $(this).find('span').on('click', function(){ // $('#'+id+'').removeClass('closed'); // // $(this).parent('.toggle-view').removeClass('closed'); // // alert('a'); // }); // // console.log(maxHeight); // }); if (typeof lunr != 'undefined') { Search.init(); }; // Auth.init(); if (window.navigator.standalone) { $('body').addClass('standalone'); } if (!mobilecheck()) { $('.js-buybutton').attr('target','_blank'); } })