cordova-plugin-nativepagetransitions
Version:
Slide out the current page to reveal the next one. By a native transitions.
9 lines • 13.6 kB
JavaScript
(function(){"use strict";var t=[],n=null,i;window.addEventListener("hashchange",function(){setTimeout(function(){window.NativePageTransitionsKendoAdapter.enhanceBackbuttons()},100)});i=function(){window.NativePageTransitionsKendoAdapter=this};i.prototype={enhanceBackbuttons:function(){for(var f,e,r,n,i,o,s=document.querySelectorAll('div[data-role="view"]'),u=0;u<s.length;u++)if(f=s[u],f.style.display!="none"){for(e=f.querySelectorAll('a[data-role="backbutton"]:not([data-rel])'),r=0;r<e.length;r++)n=e[r],i=n.getAttribute("href"),i!=null&&n.getAttribute("data-transition-native")!=="false"&&(o=t.pop()||"slide:right",i=="#:back"?o.indexOf("flip")>-1?(n.setAttribute("onclick","event.preventDefault ? event.preventDefault() : event.returnValue = false;"),n.setAttribute("ontouchend","event.preventDefault ? event.preventDefault() : event.returnValue = false; setTimeout(function(){window.kendo.mobile.application.pane.navigate(\"#:back\")},20); window.NativePageTransitionsKendoAdapter.flip('right', null, '100', '100')")):(n.setAttribute("onclick","event.preventDefault ? event.preventDefault() : event.returnValue = false;"),n.setAttribute("ontouchend","event.preventDefault ? event.preventDefault() : event.returnValue = false; setTimeout(function(){window.kendo.mobile.application.pane.navigate(\"#:back\")},20); window.NativePageTransitionsKendoAdapter.slide('right', null, '140', '140')")):(i.indexOf("#")==-1&&(i="#"+i),o.indexOf("flip")>-1?(n.setAttribute("onclick","event.preventDefault ? event.preventDefault() : event.returnValue = false;"),n.setAttribute("ontouchend","event.preventDefault ? event.preventDefault() : event.returnValue = false; window.NativePageTransitionsKendoAdapter.flip('right', '"+i+"', '100', '100')")):(n.setAttribute("onclick","event.preventDefault ? event.preventDefault() : event.returnValue = false;"),n.setAttribute("ontouchend","event.preventDefault ? event.preventDefault() : event.returnValue = false; window.NativePageTransitionsKendoAdapter.slide('right', '"+i+"', '140', '140')"))));return!1}},apply:function(){var u,f,e,s,o,t,r,i,h,c;if(this._checkPluginLoaded()&&window.kendo.mobile.application){if(n==null&&(n=window.kendo.mobile.application.options.transition,n==""&&(n="none"),window.kendo.effects.enabled=!1),window.originalAppNavigate||(window.originalAppNavigate=window.app.navigate,window.app.navigate=function(t,i){var r;t.charAt(0)!=="#"&&(t="#"+t);i===undefined&&(i=n);i===undefined&&(i="slide");i.indexOf("flip")>-1?(r="right",i.indexOf("flip:")>-1&&(r=i.substring(5)),window.NativePageTransitionsKendoAdapter.flip(r,t)):i.indexOf("slide")>-1?(r="left",i.indexOf("slide:")>-1&&(r=i.substring(6)),window.NativePageTransitionsKendoAdapter.slide(r,t)):window.originalAppNavigate(t,i)}),n=="none")u=document.querySelectorAll("a[data-transition]");else for(u=document.querySelectorAll('a[href]:not([data-role="backbutton"]):not([data-rel])'),f=0;f<u.length;f++)e=u[f],s=e.getAttribute("href").toLowerCase(),s.indexOf("window.open")==-1&&s.indexOf("url.loadurl")==-1&&(e.hasAttribute("data-transition")||e.setAttribute("data-transition",n));for(o=0;o<u.length;o++)if(t=u[o],t.getAttribute("data-transition-native")!=="false"&&(r=t.getAttribute("data-transition"),r!=null&&r!="none")){if(i=t.getAttribute("href"),i!=null&&i.indexOf("#")==-1&&i.indexOf(".")>-1&&(i="#"+i),h=t.getAttribute("data-transition-native-androiddelay"),c=t.getAttribute("data-transition-native-iosdelay"),r.indexOf("slide")>-1)this._addSlideEvent(t,r,i,h,c);else if(r.indexOf("flip")>-1)this._addFlipEvent(t,r,i,h,c);else continue;i!=null&&t.removeAttribute("href");t.removeAttribute("data-transition")}}},_addSlideEvent:function(n,t,i,r,u){var f="left";t.indexOf("slide:")>-1&&(f=t.substring(6));n.setAttribute("onclick","window.NativePageTransitionsKendoAdapter.slide('"+f+"', '"+i+"', '"+r+"', '"+u+"')")},_addFlipEvent:function(n,t,i,r,u){var f="right";t.indexOf("flip:")>-1&&(f=t.substring(5));n.setAttribute("onclick","window.NativePageTransitionsKendoAdapter.flip('"+f+"', '"+i+"', '"+r+"', '"+u+"')")},slide:function(n,i,r,u){event.preventDefault?event.preventDefault():event.returnValue=!1;t.push("slide:"+(n=="left"?"right":"left"));window.plugins.nativepagetransitions.slide({direction:n,androiddelay:r,iosdelay:u,href:i},function(){console.log("slide transition finished")},function(n){console.log("slide transition failed: "+n)})},flip:function(n,i,r,u){event.preventDefault?event.preventDefault():event.returnValue=!1;t.push("flip:"+(n=="right"?"left":"right"));window.plugins.nativepagetransitions.flip({direction:n,androiddelay:r,iosdelay:u,href:i},function(){console.log("flip transition finished")},function(n){console.log("flip transition failed: "+n)})},_checkPluginLoaded:function(){return window.plugins&&window.plugins.nativepagetransitions?!0:(console.log("window.plugins.nativepagetransitions is not available, so no native transitions will be applied"),!1)},loadFastClick:function(){if(!window.FastClick&&!window.Origami){
/*
FastClick: polyfill to remove click delays on browsers with touch UIs.
@version 1.0.3
@codingstandard ftlabs-jsv2
@copyright The Financial Times Limited [All Rights Reserved]
@license MIT License
*/
(function n(t,i,r){function u(f,o){if(!i[f]){if(!t[f]){var s="function"==typeof require&&require;if(!o&&s)return s(f,!0);if(e)return e(f,!0);s=Error("Cannot find module '"+f+"'");throw s.code="MODULE_NOT_FOUND",s;}s=i[f]={exports:{}};t[f][0].call(s.exports,function(n){var i=t[f][1][n];return u(i?i:n)},s,s.exports,n,t,i,r)}return i[f].exports}for(var e="function"==typeof require&&require,f=0;f<r.length;f++)u(r[f]);return u})({1:[function(n,t){function i(n,t){function o(n,t){return function(){return n.apply(t,arguments)}}var e;if(t=t||{},this.trackingClick=!1,this.trackingClickStart=0,this.targetElement=null,this.lastTouchIdentifier=this.touchStartY=this.touchStartX=0,this.touchBoundary=t.touchBoundary||10,this.layer=n,this.tapDelay=t.tapDelay||200,!i.notNeeded(n)){for(var f="onMouse onClick onTouchStart onTouchMove onTouchEnd onTouchCancel".split(" "),r=0,s=f.length;r<s;r++)this[f[r]]=o(this[f[r]],this);u&&(n.addEventListener("mouseover",this.onMouse,!0),n.addEventListener("mousedown",this.onMouse,!0),n.addEventListener("mouseup",this.onMouse,!0));n.addEventListener("click",this.onClick,!0);n.addEventListener("touchstart",this.onTouchStart,!1);n.addEventListener("touchmove",this.onTouchMove,!1);n.addEventListener("touchend",this.onTouchEnd,!1);n.addEventListener("touchcancel",this.onTouchCancel,!1);Event.prototype.stopImmediatePropagation||(n.removeEventListener=function(t,i,r){var u=Node.prototype.removeEventListener;"click"===t?u.call(n,t,i.hijacked||i,r):u.call(n,t,i,r)},n.addEventListener=function(t,i,r){var u=Node.prototype.addEventListener;"click"===t?u.call(n,t,i.hijacked||(i.hijacked=function(n){n.propagationStopped||i(n)}),r):u.call(n,t,i,r)});"function"==typeof n.onclick&&(e=n.onclick,n.addEventListener("click",function(n){e(n)},!1),n.onclick=null)}}var u=0<navigator.userAgent.indexOf("Android"),r=/iP(ad|hone|od)/.test(navigator.userAgent),f=r&&/OS 4_\d(_\d)?/.test(navigator.userAgent),e=r&&/OS ([6-9]|\d{2})_\d/.test(navigator.userAgent),o=0<navigator.userAgent.indexOf("BB10");i.prototype.needsClick=function(n){switch(n.nodeName.toLowerCase()){case"button":case"select":case"textarea":if(n.disabled)return!0;break;case"input":if(r&&"file"===n.type||n.disabled)return!0;break;case"label":case"video":return!0}return/\bneedsclick\b/.test(n.className)};i.prototype.needsFocus=function(n){switch(n.nodeName.toLowerCase()){case"textarea":return!0;case"select":return!u;case"input":switch(n.type){case"button":case"checkbox":case"file":case"image":case"radio":case"submit":return!1}return!n.disabled&&!n.readOnly;default:return/\bneedsfocus\b/.test(n.className)}};i.prototype.sendClick=function(n,t){var r,i;document.activeElement&&document.activeElement!==n&&document.activeElement.blur();i=t.changedTouches[0];r=document.createEvent("MouseEvents");r.initMouseEvent(this.determineEventType(n),!0,!0,window,1,i.screenX,i.screenY,i.clientX,i.clientY,!1,!1,!1,!1,0,null);r.forwardedTouchEvent=!0;n.dispatchEvent(r)};i.prototype.determineEventType=function(n){return u&&"select"===n.tagName.toLowerCase()?"mousedown":"click"};i.prototype.focus=function(n){var t;r&&n.setSelectionRange&&0!==n.type.indexOf("date")&&"time"!==n.type?(t=n.value.length,n.setSelectionRange(t,t)):n.focus()};i.prototype.updateScrollParent=function(n){var i,t;if(i=n.fastClickScrollParent,!i||!i.contains(n)){t=n;do{if(t.scrollHeight>t.offsetHeight){i=t;n.fastClickScrollParent=t;break}t=t.parentElement}while(t)}i&&(i.fastClickLastScrollTop=i.scrollTop)};i.prototype.getTargetElementFromEventTarget=function(n){return n.nodeType===Node.TEXT_NODE?n.parentNode:n};i.prototype.onTouchStart=function(n){var i,t,u;if(1<n.targetTouches.length)return!0;if(i=this.getTargetElementFromEventTarget(n.target),t=n.targetTouches[0],r){if(u=window.getSelection(),u.rangeCount&&!u.isCollapsed)return!0;if(!f){if(t.identifier&&t.identifier===this.lastTouchIdentifier)return n.preventDefault(),!1;this.lastTouchIdentifier=t.identifier;this.updateScrollParent(i)}}return this.trackingClick=!0,this.trackingClickStart=n.timeStamp,this.targetElement=i,this.touchStartX=t.pageX,this.touchStartY=t.pageY,n.timeStamp-this.lastClickTime<this.tapDelay&&n.preventDefault(),!0};i.prototype.touchHasMoved=function(n){n=n.changedTouches[0];var t=this.touchBoundary;return Math.abs(n.pageX-this.touchStartX)>t||Math.abs(n.pageY-this.touchStartY)>t?!0:!1};i.prototype.onTouchMove=function(n){return this.trackingClick?((this.targetElement!==this.getTargetElementFromEventTarget(n.target)||this.touchHasMoved(n))&&(this.trackingClick=!1,this.targetElement=null),!0):!0};i.prototype.findControl=function(n){return void 0!==n.control?n.control:n.htmlFor?document.getElementById(n.htmlFor):n.querySelector("button, input:not([type=hidden]), keygen, meter, output, progress, select, textarea")};i.prototype.onTouchEnd=function(n){var i,o,t=this.targetElement;if(!this.trackingClick)return!0;if(n.timeStamp-this.lastClickTime<this.tapDelay)return this.cancelNextClick=!0;if(this.cancelNextClick=!1,this.lastClickTime=n.timeStamp,i=this.trackingClickStart,this.trackingClick=!1,this.trackingClickStart=0,e&&(o=n.changedTouches[0],t=document.elementFromPoint(o.pageX-window.pageXOffset,o.pageY-window.pageYOffset)||t,t.fastClickScrollParent=this.targetElement.fastClickScrollParent),o=t.tagName.toLowerCase(),"label"===o){if(i=this.findControl(t)){if(this.focus(t),u)return!1;t=i}}else if(this.needsFocus(t))return 100<n.timeStamp-i||r&&window.top!==window&&"input"===o?(this.targetElement=null,!1):(this.focus(t),this.sendClick(t,n),r&&"select"===o||(this.targetElement=null,n.preventDefault()),!1);return r&&!f&&(i=t.fastClickScrollParent)&&i.fastClickLastScrollTop!==i.scrollTop?!0:(this.needsClick(t)||(n.preventDefault(),this.sendClick(t,n)),!1)};i.prototype.onTouchCancel=function(){this.trackingClick=!1;this.targetElement=null};i.prototype.onMouse=function(n){return this.targetElement&&!n.forwardedTouchEvent&&n.cancelable?!this.needsClick(this.targetElement)||this.cancelNextClick?(n.stopImmediatePropagation?n.stopImmediatePropagation():n.propagationStopped=!0,n.stopPropagation(),n.preventDefault(),!1):!0:!0};i.prototype.onClick=function(n){return this.trackingClick?(this.targetElement=null,this.trackingClick=!1,!0):"submit"===n.target.type&&0===n.detail?!0:(n=this.onMouse(n),n||(this.targetElement=null),n)};i.prototype.destroy=function(){var n=this.layer;u&&(n.removeEventListener("mouseover",this.onMouse,!0),n.removeEventListener("mousedown",this.onMouse,!0),n.removeEventListener("mouseup",this.onMouse,!0));n.removeEventListener("click",this.onClick,!0);n.removeEventListener("touchstart",this.onTouchStart,!1);n.removeEventListener("touchmove",this.onTouchMove,!1);n.removeEventListener("touchend",this.onTouchEnd,!1);n.removeEventListener("touchcancel",this.onTouchCancel,!1)};i.notNeeded=function(n){var t,i;if("undefined"==typeof ontouchstart)return!0;if(i=+(/Chrome\/([0-9]+)/.exec(navigator.userAgent)||[,0])[1])if(u){if((t=document.querySelector("meta[name=viewport]"))&&(-1!==t.content.indexOf("user-scalable=no")||31<i&&document.documentElement.scrollWidth<=window.outerWidth))return!0}else return!0;return o&&(t=navigator.userAgent.match(/Version\/([0-9]*)\.([0-9]*)/),10<=t[1]&&3<=t[2]&&(t=document.querySelector("meta[name=viewport]"))&&(-1!==t.content.indexOf("user-scalable=no")||document.documentElement.scrollWidth<=window.outerWidth))?!0:"none"===n.style.msTouchAction?!0:!1};i.attach=function(n,t){return new i(n,t)};"function"==typeof define&&"object"==typeof define.amd&&define.amd?define(function(){return i}):"undefined"!=typeof t&&t.exports?(t.exports=i.attach,t.exports.FastClick=i):window.FastClick=i},{}],2:[function(n){window.Origami={fastclick:n("./bower_components/fastclick/lib/fastclick.js")}},{"./bower_components/fastclick/lib/fastclick.js":1}]},{},[2]);document.addEventListener("load",function(){document.dispatchEvent(new CustomEvent("o.load"))});document.addEventListener("DOMContentLoaded",function(){document.dispatchEvent(new CustomEvent("o.DOMContentLoaded"))});var t=Origami.fastclick;t(document.body)}}};document.addEventListener("deviceready",function(){var t=new i,n;t.loadFastClick();t.apply();n=0;document.body.addEventListener("DOMNodeInserted",function(){var t,i,r;event&&(t=event.relatedNode,i=t.getElementsByTagName("a"),i.length>0&&(r=++n,setTimeout(function(){n==r&&window.NativePageTransitionsKendoAdapter.apply()},20)))},!0)},!1)})();