Last active
August 29, 2015 14:06
-
-
Save tanshio/e72c2ae8854a626b385a to your computer and use it in GitHub Desktop.
pjaxanimation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var palette = {}; | |
| //前のページ | |
| palette.back = {}; | |
| //URL軍団 | |
| palette.url = {}; | |
| $.preload({ | |
| forward: $.pjax.follow, | |
| check: $.pjax.getCache, | |
| encode: true, | |
| ajax: { | |
| done: function ( data, textStatus, XMLHttpRequest ) { | |
| !$.pjax.getCache( this.url ) && $.pjax.setCache( this.url, null, textStatus, XMLHttpRequest ); | |
| } | |
| } | |
| }); | |
| $.pjax({ | |
| area: [ | |
| // '#header, #primary, #secondary', | |
| // '#container', | |
| 'main' | |
| ], | |
| load: { | |
| head: 'base, meta, link', | |
| css: true, | |
| script: true | |
| }, | |
| cache: { | |
| click: true, submit: true, popstate: true, | |
| get: true, post: false | |
| }, | |
| scrollTop: null, | |
| wait: 200, | |
| scope: { | |
| // `/board/`と`/contact/`ディレクトリ下を除くすべてのページでpjaxを使用する。 | |
| '/': ['/', '!*/(request_doc|trial_lesson|tutor-regist)/'] | |
| } | |
| }); | |
| $(document).bind('pjax:fetch', function (e) { | |
| var url = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: ''); | |
| var re = new RegExp(url+"|#|\\?","gi"); | |
| $('#content,aside,footer').animate({'opacity':0},200); | |
| // もう登録してあったら | |
| if(palette.url[e.target.URL.split(re)[1]]){ | |
| $('body,html').animate({scrollTop:0}, 0, "easeInOutSine"); | |
| }else{ | |
| $('body,html').animate({scrollTop:0}, 250, "easeInOutSine"); | |
| $('.loader').fadeIn(125); | |
| } | |
| if( 641 > $( window ).width()){ | |
| $("#footer__nav") | |
| .mmenu( | |
| ) | |
| .on( "closeed.mm", function() { | |
| }) | |
| .trigger( "close.mm" ); | |
| } | |
| //リンク先URLを登録 | |
| palette.url[e.target.URL.split(re)[1]] = 1; | |
| // console.log(palette.url); | |
| console.log(location.pathname+"fetch") | |
| }); | |
| $(document).bind('pjax:render', function(){ | |
| // $('div.loading').children().width('100%'); | |
| // すでに登録済だったら | |
| if(palette.url[location.pathname]){ | |
| console.log('登録済み') | |
| } | |
| setTimeout(function(){ | |
| if(palette.url[location.pathname]){ | |
| $('#content,aside,footer').animate({'opacity':1},0); | |
| $('.loader').fadeOut(250); | |
| }else{ | |
| $('#content,aside,footer').animate({'opacity':1},200); | |
| $('.loader').fadeOut(250); | |
| } | |
| console.log(location.pathname+"render") | |
| },500); | |
| }); | |
| $(document).bind('pjax:ready', function() { | |
| $(document).trigger('preload'); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment