Created
September 25, 2012 13:36
-
-
Save anonymous/3781913 to your computer and use it in GitHub Desktop.
javascript wrapper
This file contains 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
$(document).ready(function(){ | |
// global | |
var uid = 0; | |
var history = 0; | |
// a element call a child, this element go center=>left and the child go right=>center | |
$.fn.slideToNext = function( ) { | |
var child = $("div#article_" + ($('.slide-active').data("id") + 1)); | |
var father = $("div.slide-active"); | |
if (child.length != 0) { | |
console.log(child); | |
father.removeClass('slide-active'); | |
father.animate({'left': '-1000px'}, 1500); | |
child.animate({'left': '0px'}, 1500); | |
child.addClass('slide-active'); | |
history = 1; | |
} | |
}; | |
// a element call his father, this element go center=>right and the father go left=>center | |
$.fn.slideToPrev = function( ) { | |
var child = $("div.slide-active"); | |
var father = $("div#article_" + ($('.slide-active').data("id") - 1)); | |
if (father.length != 0) { | |
child.removeClass('slide-active'); | |
child.animate({'left': '1000px'}, 1500); | |
father.animate({'left': '0px'}, 1500); | |
father.addClass('slide-active'); | |
history = 2; | |
} | |
}; | |
// a element call a child | |
$(".on_child").click(function(e){ | |
e.preventDefault(); | |
$('#wrapper').slideToNext(); | |
// uid++; | |
// history.pushState({uid: uid}, "", "/articles/"); | |
}); | |
// a element call his father | |
$(".on_father").click(function(e){ | |
e.preventDefault(); | |
$('#wrapper').slideToPrev(); | |
// uid++; | |
// history.pushState({uid: uid}, "", "/articles/" + id); | |
}); | |
// gestion du clic sur le bouton précédent du navigateur | |
$(window).bind('popstate', function(event) { | |
// console.log(event.originalEvent.state.uid); | |
// console.log(uid); | |
if (history == 1) { | |
$('#wrapper').slideToPrev() | |
} | |
else { | |
$('#wrapper').slideToNext() | |
} | |
// if (!event.originalEvent.state || event.originalEvent.state.uid < uid) { | |
// if (event.originalEvent.state) { | |
// uid = event.originalEvent.state.uid; | |
// } else { | |
// uid = 0; | |
// } | |
// alert('Prev'); | |
// } else { | |
// uid = event.originalEvent.state.uid; | |
// alert('Next'); | |
// } | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment