/*! Andraia - v0.1.0 - 2014-01-21 * https://github.com/grevory/andraia-js-mobile-framework * Copyright (c) 2014 ; Licensed MIT */ function Andraia(a,b){function c(a){return $(o).size()>0&&$.isFunction(o[a])&&(t=new o[a](q)),$.isEmptyObject(t)?r[a]:t}function d(){this.bindings=[]}var e=this,f={},g={},h=null,i=null,j=null,k="",l=null,m="",n="",o={},p={},q={},r={},s=null,t=null,u=[],v=null,w=null;if(f={templateDirectory:"templates/",enablePageslider:!0,enableFastclick:!0,enableRouter:!0,maxHistory:8,templateEngine:"",pageTransitionSpeed:.25},$.extend(g,f,b),h=function(a){return"#"!==a.charAt(0)?"#"+a:a},g.enableRouter)var x=[];this.error=function(a,b){return a?(v=a,w=b,console.error(b||a),void 0):v},this.registerModel=function(a,b){$.isFunction(b)&&(p[a]=b)},this.loadModel=function(a){return $.isFunction(p[a])?new p[a](q):void 0},this.hasModel=function(a){return!!p[a]},this.registerHelper=function(a,b){return"string"!==$.type(a)?e._error("Could not register helper. The name is not a string."):"function"!==$.type(b)?e._error("Could not register helper. The function is not a function."):(q[a]=b,void 0)},j=function(a){var b=h(a),c=$.Deferred();return $(b).size()>0?(k=$(b).html(),c.resolve(),c):($.get(g.templateDirectory+b.substr(1)+".html",function(a){k=a,$("body").append('"),c.resolve()}),c)},this.registerView=function(a,b,c){a=h(a),$.isFunction(b)&&(o[a]=b),c&&(r[a]=c)},this.bind=function(a,b,c){u.push({selector:a,bindType:b,callbackFtn:c})},this.loadView=function(b){b=h(b),g.enableRouter&&(e.router.currentPage&&e.router.currentPage===b?x&&!x.length&&x.push(b):window.location.hash=b),g.enablePageslider&&$.isFunction(PageSlider)&&!i&&(i=new PageSlider($(a))),j(b).done(function(){d(),s=r[b],$.isFunction(s)&&(s=s(),r[b]=s),k=e.template(k,s),i?i.slidePage($(k),"left"):$(a).html(k),c(b),$.each(u,function(a,c){$(c.selector).unbind(c.bindType+"."+b),$(c.selector).bind(c.bindType+"."+b,c.callbackFtn)})})},l=function(a,b){function c(a){var b=g.templateEngine.toLowerCase();return b.indexOf(a)>=0}if(!b)return a;var d;return"undefined"!=typeof _&&$.isFunction(_)&&c("underscore")?(d=_.template(a))(b):("undefined"!=typeof Handlebars&&c("handlebars")&&(d=Handlebars.compile(a),a=d(b)),"undefined"!=typeof Mustache&&c("mustache")&&(a=Mustache.render(a,b)),"undefined"!=typeof EJS&&c("ejs")&&(a=new EJS({text:a}).render(b)),a)},this.template=function(a,b){return $.isFunction(a)?(l=a,void 0):(l||e._error("No template engine loaded"),a?(a="
"+m+l(a)+n+"
",b?l(a,b):a):"")},this.registerTemplating=function(a){return e.template(a)};var y=function(a){return a=""+a,a.indexOf(".html")>-1?(e._error("This option is not yet available. Cannot load header or footer template from external file."),console.log("Go get template")):(a.indexOf("<")<0&&$(h(a)).size()>0&&(a=$(h(a)).html()),a)};if(this.registerTemplateHeader=function(a){m=y(a)},this.registerTemplateFooter=function(a){n=y(a)},a=a?h(a):"body",g.enableFastclick&&window.addEventListener("load",function(){new FastClick(window.document.body)},!1),this.router={currentPage:window.location.hash,changePage:function(a){a=h(a),e.router.addToHistory(z),e.router.currentPage&&e.loadView(a),e.router.currentPage&&e.router.currentPage!==a||(window.location.hash=a),e.router.currentPage=a},addToHistory:function(a){x.length>=g.maxHistory&&(x=x.slice(1)),x.push(a)},goBack:function(){!x||!x.length||x.length<=1||(window.location.hash=x[x.length-2])}},g.enableRouter){var z="";window.addEventListener("hashchange",function(){var a=e.router.changePage;z=window.location.hash,z&&a(z)})}g.pageTransitionSpeed!==f.pageTransitionSpeed&&$("head").append(" ")}function FastClick(a){"use strict";var b,c=this;if(this.trackingClick=!1,this.trackingClickStart=0,this.targetElement=null,this.touchStartX=0,this.touchStartY=0,this.lastTouchIdentifier=0,this.layer=a,!a||!a.nodeType)throw new TypeError("Layer must be a document node");this.onClick=function(){return FastClick.prototype.onClick.apply(c,arguments)},this.onMouse=function(){return FastClick.prototype.onMouse.apply(c,arguments)},this.onTouchStart=function(){return FastClick.prototype.onTouchStart.apply(c,arguments)},this.onTouchEnd=function(){return FastClick.prototype.onTouchEnd.apply(c,arguments)},this.onTouchCancel=function(){return FastClick.prototype.onTouchCancel.apply(c,arguments)},"undefined"!=typeof window.ontouchstart&&(this.deviceIsAndroid&&(a.addEventListener("mouseover",this.onMouse,!0),a.addEventListener("mousedown",this.onMouse,!0),a.addEventListener("mouseup",this.onMouse,!0)),a.addEventListener("click",this.onClick,!0),a.addEventListener("touchstart",this.onTouchStart,!1),a.addEventListener("touchend",this.onTouchEnd,!1),a.addEventListener("touchcancel",this.onTouchCancel,!1),Event.prototype.stopImmediatePropagation||(a.removeEventListener=function(b,c,d){var e=Node.prototype.removeEventListener;"click"===b?e.call(a,b,c.hijacked||c,d):e.call(a,b,c,d)},a.addEventListener=function(b,c,d){var e=Node.prototype.addEventListener;"click"===b?e.call(a,b,c.hijacked||(c.hijacked=function(a){a.propagationStopped||c(a)}),d):e.call(a,b,c,d)}),"function"==typeof a.onclick&&(b=a.onclick,a.addEventListener("click",function(a){b(a)},!1),a.onclick=null))}function PageSlider(a){var b,a=a,c=[];this.slidePage=function(a){var b=c.length,d=window.location.hash;return 0===b?(c.push(d),this.slidePageFrom(a),void 0):(d===c[b-2]?(c.pop(),this.slidePageFrom(a,"left")):(c.push(d),this.slidePageFrom(a,"right")),void 0)},this.slidePageFrom=function(c,d){return a.append(c),b&&d?(c.attr("class","page "+d),b.on("webkitTransitionEnd mozTransitionEnd transitionend msTransitionEnd oTransitionEnd",function(a){$(a.target).remove()}),a[0].offsetWidth,c.attr("class","page transition center"),b.attr("class","page transition "+("left"===d?"right":"left")),b=c,void 0):(c.attr("class","page center"),b=c,void 0)}}FastClick.prototype.deviceIsAndroid=navigator.userAgent.indexOf("Android")>0,FastClick.prototype.deviceIsIOS=/iP(ad|hone|od)/.test(navigator.userAgent),FastClick.prototype.deviceIsIOS4=FastClick.prototype.deviceIsIOS&&/OS 4_\d(_\d)?/.test(navigator.userAgent),FastClick.prototype.deviceIsIOSWithBadTarget=FastClick.prototype.deviceIsIOS&&/OS ([6-9]|\d{2})_\d/.test(navigator.userAgent),FastClick.prototype.needsClick=function(a){"use strict";switch(a.nodeName.toLowerCase()){case"button":case"input":return this.deviceIsIOS&&"file"===a.type?!0:a.disabled;case"label":case"video":return!0;default:return/\bneedsclick\b/.test(a.className)}},FastClick.prototype.needsFocus=function(a){"use strict";switch(a.nodeName.toLowerCase()){case"textarea":case"select":return!0;case"input":switch(a.type){case"button":case"checkbox":case"file":case"image":case"radio":case"submit":return!1}return!a.disabled;default:return/\bneedsfocus\b/.test(a.className)}},FastClick.prototype.sendClick=function(a,b){"use strict";var c,d;document.activeElement&&document.activeElement!==a&&document.activeElement.blur(),d=b.changedTouches[0],c=document.createEvent("MouseEvents"),c.initMouseEvent("click",!0,!0,window,1,d.screenX,d.screenY,d.clientX,d.clientY,!1,!1,!1,!1,0,null),c.forwardedTouchEvent=!0,a.dispatchEvent(c)},FastClick.prototype.focus=function(a){"use strict";var b;this.deviceIsIOS&&a.setSelectionRange?(b=a.value.length,a.setSelectionRange(b,b)):a.focus()},FastClick.prototype.updateScrollParent=function(a){"use strict";var b,c;if(b=a.fastClickScrollParent,!b||!b.contains(a)){c=a;do{if(c.scrollHeight>c.offsetHeight){b=c,a.fastClickScrollParent=c;break}c=c.parentElement}while(c)}b&&(b.fastClickLastScrollTop=b.scrollTop)},FastClick.prototype.getTargetElementFromEventTarget=function(a){"use strict";return a.nodeType===Node.TEXT_NODE?a.parentNode:a},FastClick.prototype.onTouchStart=function(a){"use strict";var b,c,d;if(b=this.getTargetElementFromEventTarget(a.target),c=a.targetTouches[0],this.deviceIsIOS){if(d=window.getSelection(),d.rangeCount&&!d.isCollapsed)return!0;if(!this.deviceIsIOS4){if(c.identifier===this.lastTouchIdentifier)return a.preventDefault(),!1;this.lastTouchIdentifier=c.identifier,this.updateScrollParent(b)}}return this.trackingClick=!0,this.trackingClickStart=a.timeStamp,this.targetElement=b,this.touchStartX=c.pageX,this.touchStartY=c.pageY,a.timeStamp-this.lastClickTime<200&&a.preventDefault(),!0},FastClick.prototype.touchHasMoved=function(a){"use strict";var b=a.changedTouches[0];return Math.abs(b.pageX-this.touchStartX)>10||Math.abs(b.pageY-this.touchStartY)>10?!0:!1},FastClick.prototype.findControl=function(a){"use strict";return void 0!==a.control?a.control:a.htmlFor?document.getElementById(a.htmlFor):a.querySelector("button, input:not([type=hidden]), keygen, meter, output, progress, select, textarea")},FastClick.prototype.onTouchEnd=function(a){"use strict";var b,c,d,e,f,g=this.targetElement;if(this.touchHasMoved(a)&&(this.trackingClick=!1,this.targetElement=null),!this.trackingClick)return!0;if(a.timeStamp-this.lastClickTime<200)return this.cancelNextClick=!0,!0;if(this.lastClickTime=a.timeStamp,c=this.trackingClickStart,this.trackingClick=!1,this.trackingClickStart=0,this.deviceIsIOSWithBadTarget&&(f=a.changedTouches[0],g=document.elementFromPoint(f.pageX-window.pageXOffset,f.pageY-window.pageYOffset)),d=g.tagName.toLowerCase(),"label"===d){if(b=this.findControl(g)){if(this.focus(g),this.deviceIsAndroid)return!1;g=b}}else if(this.needsFocus(g))return a.timeStamp-c>100||this.deviceIsIOS&&window.top!==window&&"input"===d?(this.targetElement=null,!1):(this.focus(g),this.deviceIsIOS4&&"select"===d||(this.targetElement=null,a.preventDefault()),!1);if(this.deviceIsIOS&&!this.deviceIsIOS4&&(e=g.fastClickScrollParent,e&&e.fastClickLastScrollTop!==e.scrollTop))return!0;if(!this.needsClick(g)){a.preventDefault();var h=this;setTimeout(function(){h.sendClick(g,a)},0)}return!1},FastClick.prototype.onTouchCancel=function(){"use strict";this.trackingClick=!1,this.targetElement=null},FastClick.prototype.onMouse=function(a){"use strict";return this.targetElement?a.forwardedTouchEvent?!0:a.cancelable?!this.needsClick(this.targetElement)||this.cancelNextClick?(a.stopImmediatePropagation?a.stopImmediatePropagation():a.propagationStopped=!0,a.stopPropagation(),a.preventDefault(),!1):!0:!0:!0},FastClick.prototype.onClick=function(a){"use strict";var b;return this.trackingClick?(this.targetElement=null,this.trackingClick=!1,!0):"submit"===a.target.type&&0===a.detail?!0:(b=this.onMouse(a),b||(this.targetElement=null),b)},FastClick.prototype.destroy=function(){"use strict";var a=this.layer;this.deviceIsAndroid&&(a.removeEventListener("mouseover",this.onMouse,!0),a.removeEventListener("mousedown",this.onMouse,!0),a.removeEventListener("mouseup",this.onMouse,!0)),a.removeEventListener("click",this.onClick,!0),a.removeEventListener("touchstart",this.onTouchStart,!1),a.removeEventListener("touchend",this.onTouchEnd,!1),a.removeEventListener("touchcancel",this.onTouchCancel,!1)},FastClick.attach=function(a){"use strict";return new FastClick(a)},"undefined"!=typeof define&&define.amd&&define(function(){"use strict";return FastClick}),"undefined"!=typeof module&&module.exports&&(module.exports=FastClick.attach,module.exports.FastClick=FastClick);