-
-
Notifications
You must be signed in to change notification settings - Fork 92
/
spa.js
2064 lines (1703 loc) · 64.6 KB
/
spa.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
* SPA v2.0.6
* A webapp framework for routing control and view transitions
* Copyright 2017 zhaoda <http://zhaoda.net>
* Licensed under MIT
*/
;(function($) {
'use strict';
// 兼容jQuery不支持$.os的问题
if(!$.os) {
var os = {},
ua = navigator.userAgent,
platform = navigator.platform,
android = ua.match(/(Android);?[\s\/]+([\d.]+)?/),
ipad = ua.match(/(iPad).*OS\s([\d_]+)/),
ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/),
iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/)
if(android) os.android = true, os.version = android[2]
if(iphone && !ipod) os.ios = os.iphone = true, os.version = iphone[2].replace(/_/g, '.')
if(ipad) os.ios = os.ipad = true, os.version = ipad[2].replace(/_/g, '.')
if(ipod) os.ios = os.ipod = true, os.version = ipod[3] ? ipod[3].replace(/_/g, '.') : null
$.os = os
}
var $win = $(window),
// $(document)
$doc = $(document),
// $(document.body)
$body,
// 浏览器地址栏
location = window.location,
// 浏览器历史记录
history = window.history,
// popstate事件state数据中转
historystate,
// 框架是否已经启动
hasBoot = false,
// 在视图转场过程中,是否阻塞其他转场请求
isPrevent = false,
// 是否是首次打开视图
transitFirst = true,
// 页面视图定义集合
routes = {},
// 面板视图定义集合
panels = {},
// 路由请求历史
hashhistory = [],
// 视图默认z-index
pagezIndex = 2000,
// 前一个视图z-index
prevPagezIndex = 2001,
// 当前视图z-index
curPagezIndex = 2002,
// 缓存视图数量,默认0缓存全部
viewcachecount = 0,
// 页面视图缓存
pagescache = {},
// 面板视图缓存
panelscache = {},
// 视图顺序缓存
viewscache = [],
// 视图数据
viewsdata = {},
// 全凭模式监控层
$fullscreen,
// 透明遮罩层
// $cover,
// loading遮罩层
$loader,
// 当前视图
$curPage,
// 框架样式
viewStyle = 'body {position: relative; margin: 0; padding: 0; width: 100%; overflow: hidden;}\
.spa-fullscreen {position: absolute; left: 0; top: 0; margin: 0; padding: 0; width: 100%; visibility: hidden; overflow: hidden; z-index: -1; }\
.spa-page {position: absolute; left: 0; top: 0; bottom: 0; right: 0; margin: 0; padding: 0; overflow: hidden; z-index: 2000; -webkit-transform: translateZ(0); -webkit-backface-visibility: hidden; -webkit-transform-style: preserve-3d;}\
.spa-page-bg {position: absolute; left: 0; top: 0; bottom: 0; right: 0; margin: 0; padding: 0; }\
.spa-page-body {position: absolute; left: 0; top: 0; bottom: 0; right: 0; margin: 0; padding: 0; overflow: hidden; -webkit-transform: translateZ(0); -webkit-backface-visibility: hidden; -webkit-transform-style: preserve-3d;}\
.spa-scroll {overflow: auto;}\
.spa-scroll-touch {-webkit-overflow-scrolling: touch; }\
.spa-scroll-x {overflow-y: hidden;}\
.spa-scroll-y {overflow-x: hidden;}\
.spa-cover {display: none; position: absolute; left: 0; right: 0; top: 0; bottom: 0; text-align: center; z-index: 5000; }\
.spa-loader {display: none; position: absolute; left: 0; right: 0; top: 0; bottom: 0; text-align: center; overflow: hidden; z-index: 5001; }',
// loading层元素
loaderBody = '<div class="spa-loader-animate"><div class="bg"></div><span class="ball"></span><span class="ball"></span></div>',
// loading层样式
loaderStyle = '.spa-loader-animate {position: absolute; top: 50%; left: 50%;}\
.spa-loader-animate .bg {position: absolute; width: 64px; height: 64px; margin: 0 auto; top: -32px; left: -32px; border-radius: 50%; background: #2C3E50; opacity: 0.5;}\
.spa-loader-animate .ball {display: block; float: left; padding: 8px; margin-top: -8px; margin-left: -10px; -webkit-border-radius: 50%; -moz-border-radius: 50%; -ms-border-radius: 50%; -o-border-radius: 50%; border-radius: 50%;}\
.spa-loader-animate span:nth-child(2) {background: #16A085; -webkit-animation: move-left 800ms ease-in-out infinite alternate; -moz-animation: move-left 800ms ease-in-out infinite alternate; -ms-animation: move-left 800ms ease-in-out infinite alternate; -animation: move-left 800ms ease-in-out infinite alternate;}\
.spa-loader-animate .ball:nth-child(3) {background: #E67E22; -webkit-animation: move-right 800ms ease-in-out infinite alternate; -moz-animation: move-right 800ms ease-in-out infinite alternate; -ms-animation: move-right 800ms ease-in-out infinite alternate; animation: move-right 800ms ease-in-out infinite alternate;}\
@-webkit-keyframes move-left {to {-webkit-transform: translate(20px, 0); transform: translate(20px, 0); background: #e85932;}}\
@-webkit-keyframes move-right {to {-webkit-transform: translate(-20px, 0); transform: translate(-20px, 0); background: #44bbcc;}}'
// spa对外接口
$.spa = {}
// 获取视图数据
$.spa.getViewData = function($view) {
return viewsdata[$view.data('id')]
}
// 获取当前视图
$.spa.getCurPage = function() {
return $curPage
}
// 设置版本号,先留空,打包时会自动添加
$.spa.version = '2.0.6'
/*
* 插入样式
*/
$doc.on('spa:addstyle', function(event, css) {
$('head').append('<style type="text/css">' + css + '</style>')
})
/*
* 全屏模式
*/
;(function() {
var requestID,
resizeID,
winHeight,
winWidth
var adjust = function() {
winHeight = Math.max($win.height(), window.innerHeight),
winWidth = Math.max($win.width(), window.innerWidth)
// 撑高body,收起iphone(ios<7) safari的地址栏
$fullscreen.css({height: winHeight * 2})
window.scrollTo(0, 0)
//缓存window全屏时的高度
$body.data('innerHeight', window.innerHeight)
winHeight = Math.max($win.height(), window.innerHeight)
if($fullscreen.height() != winHeight) {
$body.css({
width: winWidth,
height: winHeight
})
$fullscreen.css({
width: winWidth,
height: winHeight
})
// 发现在某些安卓浏览器全凭模式和非全屏模式切换后
// 手势的第一次的动作失效
// 在这里可以做些处理?
}
}
$win.on('spa:adjustfullscreen' + ($.os.ios?' orientationchange':''), function(event) {
if(requestID !== undefined) {
cancelAnimationFrame(requestID)
requestID = undefined
}
requestID = requestAnimationFrame(adjust)
})
// android下orientationchange触发的时候页面很可能还没有渲染好
// 所以马上取数据或者短延时取数据都有问题。
// 暂时没有特别好的思路来处理这个问题
$.os.android && $win.on('orientationchange', function(event) {
clearTimeout(resizeID)
resizeID = setTimeout(adjust, 500)
})
$win.on('resize', function(event) {
clearTimeout(resizeID)
resizeID = setTimeout(adjust, 200)
})
})()
/*
* scrollfix
*/
$doc.on('spa:scroll', function(event, options) {
var $target = $(event.target),
direction = (options && options.direction) || ''
$target.addClass('spa-scroll' + (direction ? ' spa-scroll-' + direction : ''))
})
$doc.on('spa:removescroll', function(event, options) {
var $target = $(event.target)
$target.removeClass('spa-scroll spa-scroll-x spa-scroll-y')
})
// ios设备才支持scrollfix
$.os.ios && $doc.on('touchstart', '.spa-scroll, .spa-scroll-x, .spa-scroll-y', function(event) {
var $target = $(event.currentTarget),
scrollTop = $target.prop('scrollTop'),
scrollLeft = $target.prop('scrollLeft'),
height = $target.height(),
width = $target.width(),
scrollHeight = $target.prop('scrollHeight'),
scrollWidth = $target.prop('scrollWidth')
if($target.hasClass('spa-scroll') || $target.hasClass('spa-scroll-x')) {
if(scrollLeft < 0) {
// event.preventDefault()
}
if(scrollLeft <= 0) {
$target.prop('scrollLeft', 1)
}
if(scrollLeft + width > scrollWidth) {
// event.preventDefault()
}
if(scrollLeft + width >= scrollWidth) {
$target.prop('scrollLeft', scrollWidth - width - 1)
}
}
if($target.hasClass('spa-scroll') || $target.hasClass('spa-scroll-y')) {
if(scrollTop < 0) {
// event.preventDefault()
}
if(scrollTop <= 0) {
$target.prop('scrollTop', 1)
}
if(scrollTop + height > scrollHeight) {
// event.preventDefault()
}
if(scrollTop + height >= scrollHeight) {
$target.prop('scrollTop', scrollTop - 1)
}
}
})
/*
* fix body { overflow: hidden }
* 阻塞body的滚动条
* 该特性适用于ios6,解决Safari收起地址栏自动全屏的问题,但是会resize后(比如启动输入法)的页面滑动崩溃
* 鉴于该特性已经不适用于ios7+,并且还带来更严重的bug,所以去掉
*/
// $win.on('scroll', function(event) {
// var innerHeight = $body && $body.data('innerHeight')
// if(innerHeight && innerHeight !== window.innerHeight) {
// $win.trigger('spa:adjustfullscreen')
// }
// })
/*
* 监听路由
*/
function getHash(url) {
url = url || location.href
return url.replace(/^[^#]*#?\/?(.*)\/?$/, '$1')
}
$win.on('popstate', function(event) {
// 框架启动前阻止路由请求
if(!hasBoot) return
// 在页面加载和转场过程中阻止路由请求
// if(($cover && $cover.css('display') === 'block') || ($loader && $loader.css('display') === 'block')) {
// return false
// }
if($loader && $loader.css('display') === 'block') {
return false
}
//如果当前页面是面板,则先收起之前的面板,再打开新页面
if($curPage && $curPage.hasClass('spa-panel')) {
var curPageId = $curPage.data('id'),
curPageData = viewsdata[curPageId],
$prevPage = curPageData.prevPage
$prevPage.trigger('spa:openpage')
return false
}
var hash = getHash()
// 如果当前路由请求和上一次路由请求不一样
// 则激活当前路由请求
if(!hashhistory.length || hashhistory[hashhistory.length - 1] !== hash) {
hashhistory.push(hash)
var $page = pagescache[hash],
pushData = event.state || {}
// 如果有中转的state数据,则优先使用,并清除
if(historystate) {
pushData = historystate
historystate = undefined
}
if($page) {
var pageId = $page.data('id'),
pageData = viewsdata[pageId]
// 更新pushData
pageData.oldpushData = pageData.pushData
pageData.pushData = pushData
$page.trigger('spa:openpage')
} else {
$doc.trigger('spa:createpage', {hash: hash, pushData: pushData})
}
}
})
/*
* 设置路由
*/
var optionalParam = /\((.*?)\)/g,
namedParam = /(\(\?)?:\w+/g,
splatParam = /\*\w+/g,
escapeRegExp = /[\-{}\[\]+?.,\\\^$|#\s]/g
var defaultPageOptions = {
route: '', //路由规则
animate: '', //入场动画效果
classname: '', //自定义样式名
view: function() { return {title: '', body: ''} }, //获取页面视图
init: function() {}, //初始化回调函数
beforeopen: function() {}, //打开前回调
afteropen: function() {}, //打开后回调
beforeclose: function() {}, //关闭前回调
afterclose: function() {} //关闭后回调
}
//验证是否是正则表达式对象
function isRegExp(obj) {
return Object.prototype.toString.call(obj) == '[object RegExp]'
}
//路由的字符串表达式转正则表达式
function _routeToRegExp(route) {
route = route.replace(escapeRegExp, '\\$&')
.replace(optionalParam, '(?:$1)?')
.replace(namedParam, function(match, optional){
return optional ? match : '([^\/]+)'
})
.replace(splatParam, '(.*?)')
return '^' + route + '$'
}
$doc.on('spa:route', function(event, options) {
var args = Array.prototype.slice.call(arguments, 1)
if(args.length > 1) {
$.each(args, function(i, route) {
$doc.trigger('spa:route', route)
})
return false
}
var route = options.route || ''
if(!isRegExp(route)) {
route = _routeToRegExp(route)
}
// 页面视图不允许使用面板视图转场动画
if(options.animate && !$.isFunction(options.animate) && isPanelAnimate(options.animate)) {
options.animate = ''
}
routes[route] = $.extend({}, defaultPageOptions, options)
})
/*
* 页面场景
*/
//解析路由请求参数
function _extractParameters(route, hash) {
var params = route.exec(hash).slice(1),
decodeParams = []
$.each(params, function(i, p) {
p && decodeParams.push(decodeURIComponent(p))
})
return decodeParams
}
//切换容器的z-index
function togglePagezIndex($fromPage, $toPage) {
var fromPageData = viewsdata[$fromPage.data('id')],
toPageData = viewsdata[$toPage.data('id')]
// fromPageData && fromPageData.prevPage && fromPageData.prevPage.css({zIndex: pagezIndex})
// toPageData.prevPage && toPageData.prevPage.css({zIndex: pagezIndex})
$fromPage.css({zIndex: prevPagezIndex})
$toPage.css({zIndex: curPagezIndex})
}
var transitPageAnimates = {},
transitPageAnimatesName = {},
transformName,
transitionName,
transitionEndEvent
;(function() {
var transitions = {
'-webkit-transition': ['-webkit-transform', 'webkitTransitionEnd'],
'-moz-transition': ['-moz-transform', 'transitionend'],
'-ms-transition': ['-ms-transform', 'msTransitionEnd'],
'-o-transition': ['-o-transform', 'oTransitionEnd'],
'transition': ['transform', 'transitionend']
},
el = document.createElement('div'),
t
for(t in transitions) {
if(el.style[t] !== undefined) {
transitionName = t
transformName = transitions[t][0]
transitionEndEvent = transitions[t][1]
break
}
}
})()
// $el.transition
$.fn.emulateTransition = function(properties, callback) {
var $el = $(this)
// css3动画是异步无阻塞的,防止同时重绘
requestAnimationFrame(function() {
$el.get(0).offsetWidth
properties[transitionName] = '0.4s'
$el.css(properties).emulateTransitionEndBySpa(function() {
// 过渡动画结束后移除 transition
properties = {}
properties[transitionName] = ''
$el.css(properties)
callback && callback()
})
})
return $el
}
if(!$.fn.transition) {
$.fn.transition = $.fn.emulateTransition
}
// transitionEnd 回调
$.fn.emulateTransitionEndBySpa = function(callback, duration) {
var called = false,
$el = $(this),
endtimer
duration = duration || 500
// 只执行一次
$el.one(transitionEndEvent, function() {
called = true
clearTimeout(endtimer)
callback.call($el)
})
// 确保transitionend被执行
var endcallback = function() {
if(!called) {
$el.trigger(transitionEndEvent)
}
}
endtimer = setTimeout(endcallback, duration)
return $el
}
//默认转场动画
transitPageAnimates.defaultInOut = function($toPage, $fromPage, callback) {
togglePagezIndex($fromPage, $toPage)
callback()
}
//添加转场动画
$doc.on('spa:addTransitPageAnimates', function(event, options) {
var names = []
$.each(options, function(name, fn) {
names.push(name)
})
$.each(names, function(key, value) {
if(key % 2 === 0) {
transitPageAnimatesName[value] = names[key + 1]
} else {
transitPageAnimatesName[value] = names[key - 1]
}
})
$.extend(transitPageAnimates, options)
})
$doc.trigger('spa:addTransitPageAnimates', {
fadeIn: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
toStartCss = {opacity: 0},
toEndCss = {opacity: 1}
toStartCss.opacity = 0
$toPageBody.css(toStartCss)
togglePagezIndex($fromPage, $toPage)
$toPageBody.emulateTransition(toEndCss, function() {
callback()
})
},
fadeOut: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
fromStartCss = {opacity: 0}
$fromPageBody.emulateTransition(fromStartCss, function() {
togglePagezIndex($fromPage, $toPage)
callback()
})
},
slideInLeft: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
toStartCss = {},
toEndCss = {}
toStartCss[transformName] = 'translate(100%, 0)'
toEndCss[transformName] = 'translate(0%, 0)'
$toPageBody.css(toStartCss)
togglePagezIndex($fromPage, $toPage)
$toPageBody.emulateTransition(toEndCss, function() {
callback()
})
},
slideOutRight: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
fromStartCss = {}
fromStartCss[transformName] = 'translate(100%, 0)'
$fromPageBody.emulateTransition(fromStartCss, function() {
togglePagezIndex($fromPage, $toPage)
callback()
})
},
slideInRight: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
toStartCss = {},
toEndCss = {}
toStartCss[transformName] = 'translate(-100%, 0)'
toEndCss[transformName] = 'translate(0%, 0)'
$toPageBody.css(toStartCss)
togglePagezIndex($fromPage, $toPage)
$toPageBody.emulateTransition(toEndCss, function() {
callback()
})
},
slideOutLeft: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
fromStartCss = {}
fromStartCss[transformName] = 'translate(-100%, 0)'
$fromPageBody.emulateTransition(fromStartCss, function() {
togglePagezIndex($fromPage, $toPage)
callback()
})
},
slideInUp: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
toStartCss = {},
toEndCss = {}
toStartCss[transformName] = 'translate(0, 100%)'
toEndCss[transformName] = 'translate(0, 0%)'
$toPageBody.css(toStartCss)
togglePagezIndex($fromPage, $toPage)
$toPageBody.emulateTransition(toEndCss, function() {
callback()
})
},
slideOutDown: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
fromStartCss = {}
fromStartCss[transformName] = 'translate(0, 100%)'
$fromPageBody.emulateTransition(fromStartCss, function() {
togglePagezIndex($fromPage, $toPage)
callback()
})
},
slideInDown: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
toStartCss = {},
toEndCss = {}
toStartCss[transformName] = 'translate(0, -100%)'
toEndCss[transformName] = 'translate(0, 0%)'
$toPageBody.css(toStartCss)
togglePagezIndex($fromPage, $toPage)
$toPageBody.emulateTransition(toEndCss, function() {
callback()
})
},
slideOutUp: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
fromStartCss = {}
fromStartCss[transformName] = 'translate(0, -100%)'
$fromPageBody.emulateTransition(fromStartCss, function() {
togglePagezIndex($fromPage, $toPage)
callback()
})
},
pushInLeft: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
isFinish = 0,
toStartCss = {},
toEndCss = {},
fromStartCss = {}
toStartCss[transformName] = 'translate(100%, 0)'
toEndCss[transformName] = 'translate(0%, 0)'
fromStartCss[transformName] = 'translate(-100%, 0)'
$toPageBody.css(toStartCss)
togglePagezIndex($fromPage, $toPage)
$toPageBody.emulateTransition(toEndCss, function() {
;(++isFinish == 2) && callback()
})
$fromPageBody.emulateTransition(fromStartCss, function() {
;(++isFinish == 2) && callback()
})
},
pushOutRight: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
isFinish = 0,
toStartCss = {},
toEndCss = {},
fromStartCss = {}
toStartCss[transformName] = 'translate(-100%, 0)'
toEndCss[transformName] = 'translate(0%, 0)'
fromStartCss[transformName] = 'translate(100%, 0)'
$toPageBody.css(toStartCss)
togglePagezIndex($fromPage, $toPage)
$toPageBody.emulateTransition(toEndCss, function() {
;(++isFinish == 2) && callback()
})
$fromPageBody.emulateTransition(fromStartCss, function() {
;(++isFinish == 2) && callback()
})
},
pushInRight: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
isFinish = 0,
toStartCss = {},
toEndCss = {},
fromStartCss = {}
toStartCss[transformName] = 'translate(-100%, 0)'
toEndCss[transformName] = 'translate(0%, 0)'
fromStartCss[transformName] = 'translate(100%, 0)'
$toPageBody.css(toStartCss)
togglePagezIndex($fromPage, $toPage)
$toPageBody.emulateTransition(toEndCss, function() {
;(++isFinish == 2) && callback()
})
$fromPageBody.emulateTransition(fromStartCss, function() {
;(++isFinish == 2) && callback()
})
},
pushOutLeft: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
isFinish = 0,
toStartCss = {},
toEndCss = {},
fromStartCss = {}
toStartCss[transformName] = 'translate(100%, 0)'
toEndCss[transformName] = 'translate(0%, 0)'
fromStartCss[transformName] = 'translate(-100%, 0)'
$toPageBody.css(toStartCss)
togglePagezIndex($fromPage, $toPage)
$toPageBody.emulateTransition(toEndCss, function() {
;(++isFinish == 2) && callback()
})
$fromPageBody.emulateTransition(fromStartCss, function() {
;(++isFinish == 2) && callback()
})
},
pushInUp: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
isFinish = 0,
toStartCss = {},
toEndCss = {},
fromStartCss = {}
toStartCss[transformName] = 'translate(0, 100%)'
toEndCss[transformName] = 'translate(0%, 0)'
fromStartCss[transformName] = 'translate(0, -100%)'
$toPageBody.css(toStartCss)
togglePagezIndex($fromPage, $toPage)
$toPageBody.emulateTransition(toEndCss, function() {
;(++isFinish == 2) && callback()
})
$fromPageBody.emulateTransition(fromStartCss, function() {
;(++isFinish == 2) && callback()
})
},
pushOutDown: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
isFinish = 0,
toStartCss = {},
toEndCss = {},
fromStartCss = {}
toStartCss[transformName] = 'translate(0, -100%)'
toEndCss[transformName] = 'translate(0%, 0)'
fromStartCss[transformName] = 'translate(0, 100%)'
$toPageBody.css(toStartCss)
togglePagezIndex($fromPage, $toPage)
$toPageBody.emulateTransition(toEndCss, function() {
;(++isFinish == 2) && callback()
})
$fromPageBody.emulateTransition(fromStartCss, function() {
;(++isFinish == 2) && callback()
})
},
pushInDown: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
isFinish = 0,
toStartCss = {},
toEndCss = {},
fromStartCss = {}
toStartCss[transformName] = 'translate(0, -100%)'
toEndCss[transformName] = 'translate(0%, 0)'
fromStartCss[transformName] = 'translate(0, 100%)'
$toPageBody.css(toStartCss)
togglePagezIndex($fromPage, $toPage)
$toPageBody.emulateTransition(toEndCss, function() {
;(++isFinish == 2) && callback()
})
$fromPageBody.emulateTransition(fromStartCss, function() {
;(++isFinish == 2) && callback()
})
},
pushOutUp: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
isFinish = 0,
toStartCss = {},
toEndCss = {},
fromStartCss = {}
toStartCss[transformName] = 'translate(0, 100%)'
toEndCss[transformName] = 'translate(0%, 0)'
fromStartCss[transformName] = 'translate(0, -100%)'
$toPageBody.css(toStartCss)
togglePagezIndex($fromPage, $toPage)
$toPageBody.emulateTransition(toEndCss, function() {
;(++isFinish == 2) && callback()
})
$fromPageBody.emulateTransition(fromStartCss, function() {
;(++isFinish == 2) && callback()
})
},
zoomIn: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
toStartCss = {},
toEndCss = {}
toStartCss[transformName] = 'scale(0, 0)'
toEndCss[transformName] = 'scale(1, 1)'
$toPageBody.css(toStartCss)
togglePagezIndex($fromPage, $toPage)
$toPageBody.emulateTransition(toEndCss, function() {
callback()
})
},
zoomOut: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
fromStartCss = {}
fromStartCss[transformName] = 'scale(0, 0)'
$fromPageBody.emulateTransition(fromStartCss, function() {
togglePagezIndex($fromPage, $toPage)
callback()
})
},
overlayInLeft: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
pageBodyWidth = $toPageBody.children().width(),
toStartCss = {left: 'auto', width: pageBodyWidth},
toEndCss = {}
toEndCss[transformName] = 'translate(0px, 0)'
$toPageBody.css(toStartCss)
pageBodyWidth = pageBodyWidth * 2 - $toPageBody.prop('clientWidth')
toStartCss = {width: pageBodyWidth}
toStartCss[transformName] = 'translate(' + pageBodyWidth + 'px, 0)'
$toPageBody.css(toStartCss)
togglePagezIndex($fromPage, $toPage)
$toPageBody.emulateTransition(toEndCss, function() {
callback()
})
},
overlayOutRight: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
prevPageBodyWidth = $fromPageBody.width(),
fromStartCss = {},
fromEndCss = {width: 'auto', left: 0}
fromStartCss[transformName] = 'translate(' + prevPageBodyWidth + 'px, 0)'
$fromPageBody.emulateTransition(fromStartCss, function() {
togglePagezIndex($fromPage, $toPage)
$fromPageBody.css(fromEndCss)
callback()
})
},
overlayInRight: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
pageBodyWidth = $toPageBody.children().width(),
toStartCss = {right: 'auto', width: pageBodyWidth},
toEndCss = {}
toEndCss[transformName] = 'translate(0px, 0)'
$toPageBody.css(toStartCss)
pageBodyWidth = pageBodyWidth * 2 - $toPageBody.prop('clientWidth')
toStartCss = {width: pageBodyWidth}
toStartCss[transformName] = 'translate(' + (0 - pageBodyWidth) + 'px, 0)'
$toPageBody.css(toStartCss)
togglePagezIndex($fromPage, $toPage)
$toPageBody.emulateTransition(toEndCss, function() {
callback()
})
},
overlayOutLeft: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
prevPageBodyWidth = $fromPageBody.width(),
fromStartCss = {},
fromEndCss = {width: 'auto', right: 0}
fromStartCss[transformName] = 'translate(' + (0 - prevPageBodyWidth) + 'px, 0)'
$fromPageBody.emulateTransition(fromStartCss, function() {
togglePagezIndex($fromPage, $toPage)
$fromPageBody.css(fromEndCss)
callback()
})
},
overlayInUp: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
pageBodyHeight = $toPageBody.children().height(),
toStartCss = {top: 'auto', height: pageBodyHeight},
toEndCss = {}
toEndCss[transformName] = 'translate(0, 0px)'
$toPageBody.css(toStartCss)
pageBodyHeight = pageBodyHeight * 2 - $toPageBody.prop('clientHeight')
toStartCss = {height: pageBodyHeight}
toStartCss[transformName] = 'translate(0, ' + pageBodyHeight + 'px)'
$toPageBody.css(toStartCss)
togglePagezIndex($fromPage, $toPage)
$toPageBody.emulateTransition(toEndCss, function() {
callback()
})
},
overlayOutDown: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
prevPageBodyHeight = $fromPageBody.height(),
fromStartCss = {},
fromEndCss = {height: 'auto', top: 0}
fromStartCss[transformName] = 'translate(0, ' + prevPageBodyHeight + 'px)'
$fromPageBody.emulateTransition(fromStartCss, function() {
togglePagezIndex($fromPage, $toPage)
$fromPageBody.css(fromEndCss)
callback()
})
},
overlayInDown: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
pageBodyHeight = $toPageBody.children().height(),
toStartCss = {bottom: 'auto', height: pageBodyHeight},
toEndCss = {}
toEndCss[transformName] = 'translate(0, 0px)'
$toPageBody.css(toStartCss)
pageBodyHeight = pageBodyHeight * 2 - $toPageBody.prop('clientHeight')
toStartCss = {height: pageBodyHeight}
toStartCss[transformName] = 'translate(0, ' + (0 - pageBodyHeight) + 'px)'
$toPageBody.css(toStartCss)
togglePagezIndex($fromPage, $toPage)
$toPageBody.emulateTransition(toEndCss, function() {
callback()
})
},
overlayOutUp: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
prevPageBodyHeight = $fromPageBody.height(),
fromStartCss = {},
fromEndCss = {height: 'auto', bottom: 0}
fromStartCss[transformName] = 'translate(0, ' + (0 - prevPageBodyHeight) + 'px)'
$fromPageBody.emulateTransition(fromStartCss, function() {
togglePagezIndex($fromPage, $toPage)
$fromPageBody.css(fromEndCss)
callback()
})
},
revealInLeft: function($toPage, $fromPage, callback) {
var $toPageBody = $('.spa-page-body', $toPage),
$fromPageBody = $('.spa-page-body', $fromPage),
pageBodyWidth = $toPageBody.children().width(),
toStartCss = {left: 'auto', width: pageBodyWidth},
fromStartCss = {}