-
Notifications
You must be signed in to change notification settings - Fork 26
/
backstack-min.js
25 lines (23 loc) · 12.3 KB
/
backstack-min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2012 Piotr Walczyszyn (http://outof.me | @pwalczyszyn)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//////////////////////////////////////////////////////////////////////////////////////
/**
* almond 0.1.1 Copyright (c) 2011, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/jrburke/almond for details
*/
(function(a,b){typeof define=="function"&&define.amd?define(["jquery","underscore","Backbone"],b):a.BackStack=b(a.jQuery||a.Zepto||a.ender,a._,a.Backbone)})(this,function(a,b,c){var d,e,f;return function(a){function l(a,b){var c=b&&b.split("/"),d=g.map,e=d&&d["*"]||{},f,h,i,j,k,l,m;if(a&&a.charAt(0)==="."&&b){c=c.slice(0,c.length-1),a=c.concat(a.split("/"));for(k=0;m=a[k];k++)if(m===".")a.splice(k,1),k-=1;else if(m===".."){if(k===1&&(a[2]===".."||a[0]===".."))return!0;k>0&&(a.splice(k-1,2),k-=2)}a=a.join("/")}if((c||e)&&d){f=a.split("/");for(k=f.length;k>0;k-=1){h=f.slice(0,k).join("/");if(c)for(l=c.length;l>0;l-=1){i=d[c.slice(0,l).join("/")];if(i){i=i[h];if(i){j=i;break}}}j=j||e[h];if(j){f.splice(0,k,j),a=f.join("/");break}}}return a}function m(b,c){return function(){return k.apply(a,i.call(arguments,0).concat([b,c]))}}function n(a){return function(b){return l(b,a)}}function o(a){return function(c){b[a]=c}}function p(d){if(c.hasOwnProperty(d)){var e=c[d];delete c[d],h[d]=!0,j.apply(a,e)}if(!b.hasOwnProperty(d))throw new Error("No "+d);return b[d]}function q(a,b){var c,d,e=a.indexOf("!");return e!==-1?(c=l(a.slice(0,e),b),a=a.slice(e+1),d=p(c),d&&d.normalize?a=d.normalize(a,n(b)):a=l(a,b)):a=l(a,b),{f:c?c+"!"+a:a,n:a,p:d}}function r(a){return function(){return g&&g.config&&g.config[a]||{}}}var b={},c={},g={},h={},i=[].slice,j,k;j=function(d,e,f,g){var i=[],j,k,l,n,s,t;g=g||d;if(typeof f=="function"){e=!e.length&&f.length?["require","exports","module"]:e;for(t=0;t<e.length;t++){s=q(e[t],g),l=s.f;if(l==="require")i[t]=m(d);else if(l==="exports")i[t]=b[d]={},j=!0;else if(l==="module")k=i[t]={id:d,uri:"",exports:b[d],config:r(d)};else if(b.hasOwnProperty(l)||c.hasOwnProperty(l))i[t]=p(l);else if(s.p)s.p.load(s.n,m(g,!0),o(l),{}),i[t]=b[l];else if(!h[l])throw new Error(d+" missing "+l)}n=f.apply(b[d],i);if(d)if(k&&k.exports!==a&&k.exports!==b[d])b[d]=k.exports;else if(n!==a||!j)b[d]=n}else d&&(b[d]=f)},d=e=k=function(b,c,d,e){return typeof b=="string"?p(q(b,c).f):(b.splice||(g=b,c.splice?(b=c,c=d,d=null):b=a),c=c||function(){},e?j(a,b,c,d):setTimeout(function(){j(a,b,c,d)},15),k)},k.config=function(a){return g=a,k},f=function(a,b,d){b.splice||(d=b,b=[]),c[a]=[a,b,d]},f.amd={jQuery:!0}}(),f("almond",function(){}),f("effects/vendorPrefix",[],function(){var a,b=/^(Moz|Webkit|Khtml|O|ms|Icab)(?=[A-Z])/,c=document.getElementsByTagName("script")[0];if("WebkitOpacity"in c.style)a="Webkit";else if("KhtmlOpacity"in c.style)a="Khtml";else for(var d in c.style)if(b.test(d)){a=d.match(b)[0];break}return a.toLowerCase()||""}),f("effects/Effect",["effects/vendorPrefix"],function(a){var c=function(d){d&&b.extend(this,d),this.vendorPrefix=a,this.vendorPrefix=="moz"||this.vendorPrefix==""?this.transitionEndEvent="transitionend":this.vendorPrefix=="ms"?this.transitionEndEvent="MSTransitionEnd":this.transitionEndEvent=this.vendorPrefix+"TransitionEnd"},d=function(){};return c.extend=function(a,e){var f=function(){c.apply(this,arguments)};return b.extend(f,c),d.prototype=c.prototype,f.prototype=new d,a&&b.extend(f.prototype,a),e&&b.extend(f,e),f.prototype.constructor=f,f.__super__=c.prototype,f},c}),f("effects/SlideEffect",["effects/Effect"],function(b){var c=b.extend({direction:"left",fromViewTransitionProps:{duration:.4,easing:"ease-out",delay:0},toViewTransitionProps:{duration:.4,easing:"ease-out",delay:0},play:function(b,c,d,e){var f,g=this,h=0,i,j=g.vendorPrefix==""?"transform":["-"+g.vendorPrefix,"-","transform"].join(""),k=g.vendorPrefix==""?"transition":["-"+g.vendorPrefix,"-","transition"].join(""),l=function(b){if(h>=0){h--;var g=a(b.target);g.css(j,""),g.css(k,""),c&&c[0]==b.target&&c.css("left",0),h==0&&d&&(f&&clearTimeout(f),d.call(e))}};b&&(h++,b.one(g.transitionEndEvent,l),b.css("left",0),b.css(k,[j," ",g.fromViewTransitionProps.duration,"s ",g.fromViewTransitionProps.easing," ",g.fromViewTransitionProps.delay,"s"].join(""))),c&&(h++,c.one(g.transitionEndEvent,l),c.css("left",g.direction=="left"?e.$el.width():-e.$el.width()),c.css(k,[j," ",g.toViewTransitionProps.duration,"s ",g.toViewTransitionProps.easing," ",g.toViewTransitionProps.delay,"s"].join("")),c.css("visibility","visible"));if(b||c)e.$el.css("width"),i="translate3d("+(g.direction=="left"?-e.$el.width():e.$el.width())+"px, 0, 0)";var m=Math.max(g.fromViewTransitionProps.duration,g.toViewTransitionProps.duration)+Math.max(g.fromViewTransitionProps.delay,g.toViewTransitionProps.delay);f=setTimeout(function(){h>0&&(h=-1,console.log("Warning "+g.transitionEndEvent+" didn't trigger in expected time!"),c&&(c.off(g.transitionEndEvent,l),c.css(k,""),c.css(j,""),c.css("left",0)),b&&(b.off(g.transitionEndEvent,l),b.css(k,""),b.css(j,"")),d.call(e))},m*1.5*1e3);var n;b&&c?n=b.add(c):c?n=c:b&&(n=b),n&&n.css(j,i)}});return c}),f("StackNavigator",["effects/SlideEffect"],function(a){function d(a,b){a.__backStackRendered__?a.$el.css({visibility:"hidden"}):(a.stackNavigator=b,typeof a.destructionPolicy=="undefined"&&(a.destructionPolicy="auto"),a.$el.css({position:"absolute",visibility:"hidden",overflow:"hidden",width:"100%",height:"100%"})),b.$el.append(a.el),a.__backStackRendered__||(a.render.call(a),a.__backStackRendered__=!0)}function e(a,c,d){return b.extend({type:a,cancelable:b.isUndefined(d)?!1:d,preventDefault:function(){this.cancelable&&(this.isDefaultPrevented=function(){return!0})},isDefaultPrevented:function(){return!1},trigger:function(a){return a.trigger(this.type,this),this}},c)}function f(c,f,g,h){d(f.instance,this),h=h||this.defaultPushTransition||(this.defaultPushTransition=new a({direction:"left"})),h.play(c?c.instance.$el:null,f.instance.$el,function(){var a=g>0?this.viewsStack.splice(this.viewsStack.length-g,g):c?[c]:null;a!=null&&b.each(a,function(a){e("viewDeactivate",{target:a.instance}).trigger(a.instance),a.instance.destructionPolicy=="never"?a.instance.$el.detach():(a.instance.remove(),a.instance=null)},this),this.viewsStack.push(f),this.activeView=f.instance,e("viewActivate",{target:f.instance}).trigger(f.instance),e("viewChanged",{target:this}).trigger(this),m.call(this)},this)}function g(c,f,g,h){f&&(f.instance=f.instance?f.instance:new f.viewClass(f.options),d(f.instance,this)),h=h||this.defaultPopTransition||(this.defaultPopTransition=new a({direction:"right"})),h.play(c.instance.$el,f?f.instance.$el:null,function(){var a=this.viewsStack.splice(this.viewsStack.length-g,g);b.each(a,function(a){e("viewDeactivate",{target:a.instance}).trigger(a.instance),a.instance.destructionPolicy=="never"?a.instance.$el.detach():(a.instance.remove(),a.instance=null)},this),f?(this.activeView=f.instance,e("viewActivate",{target:f.instance}).trigger(f.instance)):this.activeView=null,e("viewChanged",{target:this}).trigger(this),m.call(this)},this)}function h(a,c,d){var g=b.last(this.viewsStack),h=b.isFunction(a)?new a(c):a,i={instance:h,viewClass:h.constructor,options:c},j=e("viewChanging",{action:"push",fromViewClass:g?g.viewClass:null,fromView:g?g.instance:null,toViewClass:i.viewClass,toView:i.instance},!0).trigger(this);if(j.isDefaultPrevented())return null;f.call(this,g,i,0,d)}function i(a){if(this.viewsStack.length==0)throw new Error("Popping from an empty stack!");var c=b.last(this.viewsStack),d=this.viewsStack.length>1?this.viewsStack[this.viewsStack.length-2]:null,f=e("viewChanging",{action:"pop",fromViewClass:c.viewClass,fromView:c.instance,toViewClass:d?d.viewClass:null,toView:d?d.instance:null},!0).trigger(this);if(f.isDefaultPrevented())return;g.call(this,c,d,1,a)}function j(a){if(this.viewsStack.length==0)throw new Error("Popping from an empty stack!");var c=b.last(this.viewsStack),d=e("viewChanging",{action:"popAll",fromViewClass:c.viewClass,fromView:c.instance,toViewClass:null,toView:null},!0).trigger(this);if(d.isDefaultPrevented())return;g.call(this,c,null,this.viewsStack.length,a)}function k(a,c,d){if(this.viewsStack.length==0)throw new Error("Replacing on an empty stack!");var g=b.last(this.viewsStack),h=b.isFunction(a)?new a(c):a,i={instance:h,viewClass:h.constructor,options:c},j=e("viewChanging",{action:"replace",fromViewClass:g.viewClass,fromView:g.instance,toViewClass:i.viewClass,toView:i.instance},!0).trigger(this);if(j.isDefaultPrevented())return null;f.call(this,g,i,1,d)}function l(a,c,d){if(this.viewsStack.length==0)throw new Error("Replacing on an empty stack!");var g=b.last(this.viewsStack),h=b.isFunction(a)?new a(c):a,i={instance:h,viewClass:h.constructor,options:c},j=e("viewChanging",{action:"replaceAll",fromViewClass:g.viewClass,fromView:g.instance,toViewClass:i.viewClass,toView:i.instance},!0).trigger(this);if(j.isDefaultPrevented())return null;f.call(this,g,i,this.viewsStack.length,d)}function m(){this.actionsQueue.splice(0,1);if(this.actionsQueue.length>0){var a=this.actionsQueue[0],b=Array.prototype.slice.call(a.args);switch(a.fn){case"pushView":h.apply(this,b);break;case"popView":i.apply(this,b);break;case"popAll":j.apply(this,b);break;case"replaceView":k.apply(this,b);break;case"replaceAll":l.apply(this,b)}}}var n=c.View.extend({viewsStack:null,activeView:null,defaultPushTransition:null,defaultPopTransition:null,actionsQueue:null,initialize:function(a){this.$el.css({overflow:"hidden"}),this.viewsStack=[],this.actionsQueue=[],a.popTransition&&(this.defaultPopTransition=a.popTransition),a.pushTransition&&(this.defaultPushTransition=a.pushTransition)},pushView:function(a,b,c){this.actionsQueue.push({fn:"pushView",args:arguments}),this.actionsQueue.length==1&&h.call(this,a,b,c)},popView:function(a){this.actionsQueue.push({fn:"popView",args:arguments}),this.actionsQueue.length==1&&i.call(this,a)},popAll:function(a){this.actionsQueue.push({fn:"popAll",args:arguments}),this.actionsQueue.length==1&&j.call(this,a)},replaceView:function(a,b,c){this.actionsQueue.push({fn:"replaceView",args:arguments}),this.actionsQueue.length==1&&k.call(this,a,b,c)},replaceAll:function(a,b,c){this.actionsQueue.push({fn:"replaceAll",args:arguments}),this.actionsQueue.length==1&&l.call(this,a,b,c)}});return n}),f("effects/FadeEffect",["effects/Effect"],function(b){var c=b.extend({fromViewTransitionProps:{duration:.4,easing:"linear",delay:.1},toViewTransitionProps:{duration:.4,easing:"linear",delay:.1},play:function(b,c,d,e){var f=this,g,h=0,i=f.vendorPrefix==""?"transition":["-"+f.vendorPrefix.toLowerCase(),"-","transition"].join(""),j=function(b){h>=0&&(h--,a(b.target).css(i,""),h==0&&d&&(g&&clearTimeout(g),d.call(e)))};b&&(h++,b.one(f.transitionEndEvent,j),b.css(i,["opacity ",f.fromViewTransitionProps.duration,"s ",f.fromViewTransitionProps.easing," ",f.fromViewTransitionProps.delay,"s"].join(""))),c&&(h++,c.one(f.transitionEndEvent,j),c.css("opacity",0),c.css(i,["opacity ",f.toViewTransitionProps.duration,"s ",f.toViewTransitionProps.easing," ",f.toViewTransitionProps.delay,"s"].join("")),c.css("visibility","visible")),e.$el.css("width");var k=Math.max(f.fromViewTransitionProps.duration,f.toViewTransitionProps.duration)+Math.max(f.fromViewTransitionProps.delay,f.toViewTransitionProps.delay);g=setTimeout(function(){h>0&&(h=-1,console.log("Warning "+f.transitionEndEvent+" didn't trigger in expected time!"),c&&(c.off(f.transitionEndEvent,j),c.css(i,"")),b&&(b.off(f.transitionEndEvent,j),b.css(i,"")),d.call(e))},k*1.5*1e3),c&&c.css("opacity",1),b&&b.css("opacity",0)}});return c}),f("effects/NoEffect",["effects/Effect"],function(a){var b=a.extend();return b.prototype.play=function(a,b,c,d){b&&b.css("visibility","visible"),c.call(d)},b}),{StackNavigator:e("StackNavigator"),Effect:e("effects/Effect"),NoEffect:e("effects/NoEffect"),SlideEffect:e("effects/SlideEffect"),FadeEffect:e("effects/FadeEffect")}})