{"id":151,"date":"2010-04-09T20:42:20","date_gmt":"2010-04-09T10:42:20","guid":{"rendered":"http:\/\/chuchuva.com\/pavel\/?p=151"},"modified":"2011-09-20T11:02:40","modified_gmt":"2011-09-20T01:02:40","slug":"using-asual-jquery-address-plugin-for-photo-gallery","status":"publish","type":"post","link":"https:\/\/chuchuva.com\/pavel\/2010\/04\/using-asual-jquery-address-plugin-for-photo-gallery\/","title":{"rendered":"Using Asual jQuery Address plugin for photo gallery"},"content":{"rendered":"<p><a href=\"http:\/\/chuchuva.com\/demo\/asual-jquery-address\/\">Click here to view demo<\/a><\/p>\n<p>Let&#8217;s say you want to build photo gallery. Something like this:<br \/>\n<img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"153\" data-permalink=\"https:\/\/chuchuva.com\/pavel\/2010\/04\/using-asual-jquery-address-plugin-for-photo-gallery\/gallery-mockup\/\" data-orig-file=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/gallery-mockup.gif?fit=270%2C251&amp;ssl=1\" data-orig-size=\"270,251\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"gallery-mockup\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/gallery-mockup.gif?fit=270%2C251&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/gallery-mockup.gif?fit=270%2C251&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/gallery-mockup.gif?resize=270%2C251\" alt=\"\" width=\"270\" height=\"251\" class=\"alignnone size-full wp-image-153\" \/><\/p>\n<p>You want to open next and previous photos without page reload, using Ajax. One problem with this is that browser&#8217;s back button stops working. Fortunately, it&#8217;s easy to fix with <a href=\"http:\/\/www.asual.com\/jquery\/address\/\">jQuery Address plugin<\/a> from Asual. I tried using this plugin and it worked very well. I&#8217;ve put together a simple <a href=\"http:\/\/chuchuva.com\/demo\/asual-jquery-address\/\">demo<\/a>.<\/p>\n<p>For simplicity, let&#8217;s display just a number instead of actual photo:<br \/>\n<img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"154\" data-permalink=\"https:\/\/chuchuva.com\/pavel\/2010\/04\/using-asual-jquery-address-plugin-for-photo-gallery\/gallery-mockup2\/\" data-orig-file=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/gallery-mockup2.gif?fit=261%2C216&amp;ssl=1\" data-orig-size=\"261,216\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"gallery-mockup2\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/gallery-mockup2.gif?fit=261%2C216&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/gallery-mockup2.gif?fit=261%2C216&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/gallery-mockup2.gif?resize=261%2C216\" alt=\"\" width=\"261\" height=\"216\" class=\"alignnone size-full wp-image-154\" \/><\/p>\n<p>Every time you click right arrow the number increases; left arrow decrements the number by one. Simple! Back and forward buttons should work. Also, it would be nice to have different titles in the history:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"155\" data-permalink=\"https:\/\/chuchuva.com\/pavel\/2010\/04\/using-asual-jquery-address-plugin-for-photo-gallery\/browser-history\/\" data-orig-file=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/browser-history.png?fit=181%2C173&amp;ssl=1\" data-orig-size=\"181,173\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"browser-history\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/browser-history.png?fit=181%2C173&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/browser-history.png?fit=181%2C173&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/browser-history.png?resize=181%2C173\" alt=\"\" width=\"181\" height=\"173\" class=\"alignnone size-full wp-image-155\" \/><\/p>\n<p>The code:<\/p>\n<pre><code class=\"prettyprint\">$(function () \r\n{\r\n  $.address.strict(false);\r\n  $.address.externalChange(function(e)\r\n  {\r\n    switchTo(e.value);\r\n  });\r\n\r\n  $(\"#lnk_prev\").click(function(e)\r\n  {\r\n    e.preventDefault();\r\n    var i = $(\"#number\").text() * 1 - 1;\r\n    switchTo(i);\r\n    $.address.value(i);\r\n  });\r\n\r\n  $(\"#lnk_next\").click(function(e)\r\n  {\r\n    e.preventDefault();\r\n    var i = $(\"#number\").text() * 1 + 1;\r\n    switchTo(i);\r\n    $.address.value(i);\r\n  });\r\n});\r\n\r\nfunction switchTo(i)\r\n{\r\n  $(\"#number\").text(i);\r\n  $.address.title(i);\r\n}\r\n<\/code><\/pre>\n<p>The magic happens in click handler. $.address.value method changes page address and adds browser history point. You need to cancel navigation by calling e.preventDefault() \u2014 otherwise browser would follow the link and two history entries would get created.<\/p>\n<p><a href=\"http:\/\/chuchuva.com\/demo\/asual-jquery-address\/\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"158\" data-permalink=\"https:\/\/chuchuva.com\/pavel\/2010\/04\/using-asual-jquery-address-plugin-for-photo-gallery\/gallery-demo\/\" data-orig-file=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/gallery-demo.png?fit=499%2C450&amp;ssl=1\" data-orig-size=\"499,450\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"gallery-demo\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/gallery-demo.png?fit=300%2C270&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/gallery-demo.png?fit=499%2C450&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/gallery-demo.png?resize=499%2C450\" alt=\"\" width=\"499\" height=\"450\" class=\"alignnone size-full wp-image-158\" srcset=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/gallery-demo.png?w=499&amp;ssl=1 499w, https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/gallery-demo.png?resize=300%2C270&amp;ssl=1 300w\" sizes=\"auto, (max-width: 499px) 100vw, 499px\" \/><\/a><\/p>\n<p>Note that you need to disable plugin&#8217;s strict option, otherwise it would add slash symbol immediately after hash symbol, like this: #\/11.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Click here to view demo Let&#8217;s say you want to build photo gallery. Something like this: You want to open next and previous photos without page reload, using Ajax. One problem with this is that browser&#8217;s back button stops working. Fortunately, it&#8217;s easy to fix with jQuery Address plugin from Asual. I tried using this &hellip; <a href=\"https:\/\/chuchuva.com\/pavel\/2010\/04\/using-asual-jquery-address-plugin-for-photo-gallery\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Using Asual jQuery Address plugin for photo gallery<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[8],"tags":[11],"class_list":["post-151","post","type-post","status-publish","format-standard","hentry","category-develop","tag-jquery"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/chuchuva.com\/pavel\/wp-json\/wp\/v2\/posts\/151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chuchuva.com\/pavel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chuchuva.com\/pavel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chuchuva.com\/pavel\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chuchuva.com\/pavel\/wp-json\/wp\/v2\/comments?post=151"}],"version-history":[{"count":0,"href":"https:\/\/chuchuva.com\/pavel\/wp-json\/wp\/v2\/posts\/151\/revisions"}],"wp:attachment":[{"href":"https:\/\/chuchuva.com\/pavel\/wp-json\/wp\/v2\/media?parent=151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chuchuva.com\/pavel\/wp-json\/wp\/v2\/categories?post=151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chuchuva.com\/pavel\/wp-json\/wp\/v2\/tags?post=151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}