javascript - Photoswipe gallery close event on iOS -
i've implemented fabulous photoswipe library in 1 of recent mobile applications using jquerymobile , i've run small problem using in tandem ios 5 (could others, i've got ios 5 device).
below implemented javascript
<script type="text/javascript"> (function (window, $, photoswipe) { $(document).ready(function () { $('div.gallery-page') .live('pageshow', function (e) { var currentpage = $(e.target), options = {}, photoswipeinstance = $("ul.gallery a", e.target).photoswipe(options, currentpage.attr('id')); photoswipeinstance.show(0); return true; }) .live('pagehide', function (e) { var currentpage = $(e.target), photoswipeinstance = photoswipe.getinstance(currentpage.attr('id')); if (typeof photoswipeinstance != "undefined" && photoswipeinstance != null) { photoswipe.detatch(photoswipeinstance); } console.log($(e.target)); history.back(); return true; }); }); } (window, window.jquery, window.code.photoswipe)); </script> the example above pretty implementation guide says 1 difference: when pageshow event raised , instance has been attached, i'm calling "photoswipeinstance.show(0);" display gallery immediately.
this works fine except when close gallery toolbar, goes static page rather page called from.
my first thought implement method against event "onhide" , perform "history.back();" statement:
photoswipeinstance.addeventhandler(photoswipe.eventtypes.onhide, function (e) { history.back(); }); this worked charm on android, nothing happened on ios, thought double history ios devices:
photoswipeinstance.addeventhandler(photoswipe.eventtypes.onhide, function (e) { console.log(navigator.appversion); if ((/iphone|ipod|ipad.*os 5/gi).test(navigator.appversion)) { history.go(-2); } else { history.back(); } }); but still no luck, ios sits there , laughs @ me. know best way redirect page attached photoswipe instance rather going actual html page? here example of final js markup:
<script type="text/javascript"> (function (window, $, photoswipe) { $(document).ready(function () { $('div.gallery-page') .live('pageshow', function (e) { var currentpage = $(e.target), options = {}, photoswipeinstance = $("ul.gallery a", e.target).photoswipe(options, currentpage.attr('id')); // onhide event wire previous page. photoswipeinstance.addeventhandler(photoswipe.eventtypes.onhide, function (e) { console.log(navigator.appversion); if ((/iphone|ipod|ipad.*os 5/gi).test(navigator.appversion)) { history.go(-2); } else { history.back(); } }); photoswipeinstance.show(0); return true; }) .live('pagehide', function (e) { var currentpage = $(e.target), photoswipeinstance = photoswipe.getinstance(currentpage.attr('id')); if (typeof photoswipeinstance != "undefined" && photoswipeinstance != null) { photoswipe.detatch(photoswipeinstance); } return true; }); }); } (window, window.jquery, window.code.photoswipe)); </script>
i had similar problem - believe onhide event on ios not firing, solved listening toolbar events:
photoswipeinstance.addeventhandler(photoswipe.eventtypes.ontoolbartap, function(e){ if(e.toolbaraction === 'close'){ //i needed use specific location here: window.location.href = "something"; //but think use history history.back(); } });
Comments
Post a Comment