From 82874d33a109d1dc32d7533e6706ac399cdd0891 Mon Sep 17 00:00:00 2001 From: manson Date: Tue, 5 Aug 2014 17:50:16 +0800 Subject: [PATCH] Fix window popstate --- app/assets/javascripts/galleryAPI.js.erb | 30 ++++++++++------ .../javascripts/galleryAPI_frontend.js.erb | 34 ++++++++++++------- 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/app/assets/javascripts/galleryAPI.js.erb b/app/assets/javascripts/galleryAPI.js.erb index 56e7390..67d6b83 100644 --- a/app/assets/javascripts/galleryAPI.js.erb +++ b/app/assets/javascripts/galleryAPI.js.erb @@ -190,30 +190,39 @@ var galleryAPI = function(){ $(".slidectrl .browserfullscreen").show(); } } + window.onpopstate = function(){ + var image_id = document.URL.split('/')[document.URL.split('/').length-1]; + var image = imageArray.filter(function(a){return a._id == image_id})[0]; + imagecount = imageArray.indexOf(image); + changeTheaterImage(image.file.theater.url); + } var changeImage = function(dom){ var pageurl = dom.attr('href'); + if(rcom.getInternetExplorerVersion() == -1){ + if(pageurl!=window.location){ + window.history.pushState({path:pageurl},'',pageurl); + } + }else{ + window.location.hash = pageurl; + } + + changeTheaterImage(dom.attr("data-content")); + } + var changeTheaterImage = function(url){ $img.fadeOut(200,function(){ g.loadstart(); $img.attr("src",""); - $img.attr({"src":dom.attr("data-content"),"height":picHeight+"px"}).load(function(){ + $img.attr({"src":url,"height":picHeight+"px"}).load(function(){ $img.fadeIn(200); g.loadcomplete(); }); - if($rslide.hasClass("fullscreen")){ $img.css({"padding":($rslide.height()-$img.height())/2}) } $slidelist.stop().animate({'height':'0px'}, 300); $slidelist.find("ul").hide(); - if(rcom.getInternetExplorerVersion() == -1){ - if(pageurl!=window.location){ - window.history.pushState({path:pageurl},'',pageurl); - } - }else{ - window.location.hash = pageurl; - } // $(".slideinfo b.info").text(imageArray[imagecount].title); if($('.bt-tag').hasClass("active")) updatePhotoTag(); @@ -224,7 +233,6 @@ var galleryAPI = function(){ if(imageArray.length > 1) updateNavigation(); }) - } var updateNavigation = function(){ var next, prev; @@ -269,7 +277,7 @@ var galleryAPI = function(){ } var albumid = $("#main_pic").attr("data-content"); - g.albumArea.find(".bt-back").attr("href","../galleries/"+albumid); + g.albumArea.find(".bt-back").attr("href",'/'+g.locale+"/admin/galleries/"+albumid); g.albumArea.find(".bt-edit").attr("href","../albums/"+albumid+"/edit"); g.albumArea.css("margin-bottom","0"); picHeight = $(window).height() - ($("#orbit-bar").outerHeight() + $("#orbit_gallery .form-actions").outerHeight()); diff --git a/app/assets/javascripts/galleryAPI_frontend.js.erb b/app/assets/javascripts/galleryAPI_frontend.js.erb index b91c799..55faba6 100644 --- a/app/assets/javascripts/galleryAPI_frontend.js.erb +++ b/app/assets/javascripts/galleryAPI_frontend.js.erb @@ -159,19 +159,39 @@ var galleryAPI = function(){ $(".slidectrl .browserfullscreen").show(); } } + window.onpopstate = function(){ + var image_id = window.location.pathname.split('/')[window.location.pathname.split('/').length-1].split('-'); + var image = imageArray.filter(function(a){return a._id == image_id[1]})[0]; + imagecount = imageArray.indexOf(image); + changeTheaterImage(image.file.theater.url); + } var changeImage = function(dom){ var pageurl = dom.attr('href'); + if(rcom.getInternetExplorerVersion() == -1){ + if(pageurl!=window.location){ + var segments = window.location.pathname.split("/"), + uid = segments[segments.length-1]; + pageurl = window.location.pathname.replace(uid,"-"+pageurl)+"?method=theater"; + window.history.pushState({path:pageurl},'',pageurl); + } + }else{ + window.location.hash = pageurl; + } + + changeTheaterImage(dom.attr("data-content")); + } + var changeTheaterImage = function(url){ $img.fadeOut(200,function(){ g.loadstart(); if($rslide.hasClass("fullscreen")){ - $img.attr({"src":dom.attr("data-content")}).css("height","100%").load(function(){ + $img.attr({"src":url}).css("height","100%").load(function(){ g.loadcomplete(); $img.fadeIn(200); }); }else{ - $img.attr({"src":dom.attr("data-content")}).css("height","auto").load(function(){ + $img.attr({"src":url}).css("height","auto").load(function(){ g.loadcomplete(); $img.fadeIn(200); });; @@ -181,16 +201,6 @@ var galleryAPI = function(){ } $slidelist.stop().animate({'height':'0px'}, 300); $slidelist.find("ul").hide(); - if(rcom.getInternetExplorerVersion() == -1){ - if(pageurl!=window.location){ - var segments = window.location.pathname.split("/"), - uid = segments[segments.length-1]; - pageurl = window.location.pathname.replace(uid,"-"+pageurl)+"?method=theater"; - window.history.pushState({path:pageurl},'',pageurl); - } - }else{ - window.location.hash = pageurl; - } // $(".slideinfo b.info").text(imageArray[imagecount].title); updatePhotoTag(); if(imageArray[imagecount].description)