{"id":167,"date":"2010-04-27T21:41:59","date_gmt":"2010-04-27T11:41:59","guid":{"rendered":"http:\/\/chuchuva.com\/pavel\/?p=167"},"modified":"2010-04-27T17:29:34","modified_gmt":"2010-04-27T07:29:34","slug":"using-jquery-bbq-plugin-for-photo-gallery","status":"publish","type":"post","link":"https:\/\/chuchuva.com\/pavel\/2010\/04\/using-jquery-bbq-plugin-for-photo-gallery\/","title":{"rendered":"Using jQuery BBQ plugin for photo gallery"},"content":{"rendered":"<p><a href=\"http:\/\/chuchuva.com\/demo\/jquery-bbq\/\">Click here to view demo<\/a><\/p>\n<p>Let&#8217;s take <a href=\"http:\/\/chuchuva.com\/pavel\/2010\/04\/using-asual-jquery-address-plugin-for-photo-gallery\/\">previous demo<\/a> and use <a href=\"http:\/\/benalman.com\/projects\/jquery-bbq-plugin\/\">jQuery BBQ plugin<\/a> instead. Our goal is Ajax photo gallery that supports browser&#8217;s back button. We will display numbers instead of actual photos for now.<\/p>\n<pre><code class=\"prettyprint\">$(function () \r\n{\r\n  $(window).bind('hashchange', function(e) {\r\n    var i = parseInt(e.fragment, 10);\r\n    if (!isNaN(i))\r\n      switchTo(i);\r\n  });\r\n  $(window).trigger('hashchange');\r\n});\r\n\r\nfunction switchTo(i)\r\n{\r\n  if ($(\"#number\").text() == i)\r\n    return;\r\n  $(\"#number\").text(i);\r\n  document.title = i;\r\n  if (i > 1)\r\n    $(\"#lnk_prev\").attr(\"href\", \"#\" + (i - 1)).removeClass(\"disabled\");\r\n  else\r\n    $(\"#lnk_prev\").removeAttr(\"href\").addClass(\"disabled\");\r\n  if (i < 20)\r\n    $(\"#lnk_next\").attr(\"href\", \"#\" + (i + 1)).removeClass(\"disabled\");\r\n  else\r\n    $(\"#lnk_next\").removeAttr(\"href\").addClass(\"disabled\");\r\n}\r\n<\/code><\/pre>\n<p>Instead of handling click event we modify href attribute of the links. BBQ will fire hashchange event whenever we \"navigate\" to a new page. No need to prevent default processing \u00e2\u20ac\u201c simple!<\/p>\n<p>One gotcha to watch out for is changing page title. If you take naive approach and simply use document.title (like I did) to set page title you won't see your titles in the history menu in Internet Explorer 7:<br \/>\n<img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"170\" data-permalink=\"https:\/\/chuchuva.com\/pavel\/2010\/04\/using-jquery-bbq-plugin-for-photo-gallery\/bbq-ie7\/\" data-orig-file=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/bbq-ie7.png?fit=336%2C231&amp;ssl=1\" data-orig-size=\"336,231\" 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=\"bbq-ie7\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/bbq-ie7.png?fit=300%2C206&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/bbq-ie7.png?fit=336%2C231&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/bbq-ie7.png?resize=336%2C231\" alt=\"\" width=\"336\" height=\"231\" class=\"alignnone size-full wp-image-170\" srcset=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/bbq-ie7.png?w=336&amp;ssl=1 336w, https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/bbq-ie7.png?resize=300%2C206&amp;ssl=1 300w\" sizes=\"auto, (max-width: 336px) 100vw, 336px\" \/><\/p>\n<p>Compare with Internet Explorer 8:<br \/>\n<img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"171\" data-permalink=\"https:\/\/chuchuva.com\/pavel\/2010\/04\/using-jquery-bbq-plugin-for-photo-gallery\/bbq-ie8\/\" data-orig-file=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/bbq-ie8.png?fit=336%2C232&amp;ssl=1\" data-orig-size=\"336,232\" 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=\"bbq-ie8\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/bbq-ie8.png?fit=300%2C207&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/bbq-ie8.png?fit=336%2C232&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/bbq-ie8.png?resize=336%2C232\" alt=\"\" width=\"336\" height=\"232\" class=\"alignnone size-full wp-image-171\" srcset=\"https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/bbq-ie8.png?w=336&amp;ssl=1 336w, https:\/\/i0.wp.com\/chuchuva.com\/pavel\/images\/2010\/04\/bbq-ie8.png?resize=300%2C207&amp;ssl=1 300w\" sizes=\"auto, (max-width: 336px) 100vw, 336px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Click here to view demo Let&#8217;s take previous demo and use jQuery BBQ plugin instead. Our goal is Ajax photo gallery that supports browser&#8217;s back button. We will display numbers instead of actual photos for now. $(function () { $(window).bind(&#8216;hashchange&#8217;, function(e) { var i = parseInt(e.fragment, 10); if (!isNaN(i)) switchTo(i); }); $(window).trigger(&#8216;hashchange&#8217;); }); function switchTo(i) &hellip; <a href=\"https:\/\/chuchuva.com\/pavel\/2010\/04\/using-jquery-bbq-plugin-for-photo-gallery\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Using jQuery BBQ 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-167","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\/167","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=167"}],"version-history":[{"count":0,"href":"https:\/\/chuchuva.com\/pavel\/wp-json\/wp\/v2\/posts\/167\/revisions"}],"wp:attachment":[{"href":"https:\/\/chuchuva.com\/pavel\/wp-json\/wp\/v2\/media?parent=167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chuchuva.com\/pavel\/wp-json\/wp\/v2\/categories?post=167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chuchuva.com\/pavel\/wp-json\/wp\/v2\/tags?post=167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}