{"id":467,"date":"2006-07-25T05:25:55","date_gmt":"2006-07-25T05:25:55","guid":{"rendered":"http:\/\/www.nargalzius.com\/blog2\/http:\/www.nargalzius.com\/blog2\/archives\/2006\/07\/2006_07_25_1325.php"},"modified":"2017-02-11T08:36:34","modified_gmt":"2017-02-11T08:36:34","slug":"another-lightbox-hack","status":"publish","type":"post","link":"http:\/\/nargalzius.com\/blog\/archives\/2006\/07\/25\/another-lightbox-hack","title":{"rendered":"Another Lightbox hack"},"content":{"rendered":"<div class=\"notice\">\n<p class=\"header\"><strong>NOTICE<\/strong><br>CONTENTS NO LONGER APPLICABLE<\/p>\n<p class=\"content\">The content discussed in this post is no longer valid; as I&#8217;m now using a different &#8220;lightbox&#8221; implementation.<br><a href=\"http:\/\/nargalzius.com\/blog\/archives\/2008\/07\/31\/zoom-just-one-look\">More here<\/a><\/p><\/div>\n<p>When opening an image via <a href=\"http:\/\/www.huddletogether.com\/projects\/lightbox2\/\" title=\"Visit site\">lightbox<\/a>, closing an image can get very counter intuitive. The close button is at the bottom right, which sucks if you have an image that&#8217;s larger than the viewing area. Trying to move that close button on the upper right can be too tedious as it requires a lot of modification on the <code>DOM<\/code> script and CSS. The easier thing would be to simply allow users to close the image when they click on it, after all, what else does one person usually do after viewing an image but <em>close<\/em> it right?<\/p>\n<p>A hack for this is <a href=\"http:\/\/www.huddletogether.com\/forum\/comments.php?DiscussionID=173\" title=\"View forum entry\">easy to do,<\/a> however this usually broke <a href=\"http:\/\/www.huddletogether.com\/projects\/lightbox2\/\" title=\"Visit site\">Lightbox<\/a>&#8216;s &#8220;group&#8221; mode &#8211; instead of moving to the previous\/next image, it prioritizes the <em>close<\/em> function assigned to the image container instead of the group mode&#8217;s <em>prev\/next<\/em> overlays &#8211; resulting in the image closing anywhere you click.<\/p>\n<p>The trick was to find another place where I could inject similar code, while making sure that it only does it when it&#8217;s viewing a single image.<!--more-->As of v2.02, search for this code (should be somewhere around line <strong>436<\/strong>)<\/p>\n<p>\/\/ if image is part of set display &#8216;Image x of x&#8217;\nif(imageArray.length > 1){\nElement.show(&#8216;numberDisplay&#8217;);\nElement.setInnerHTML( &#8216;numberDisplay&#8217;, &#8220;Image &#8221; + eval(activeImage + 1) + &#8221; of &#8221; + imageArray.length);\n}<\/p>\n<p>Replace the last <code>}<\/code> (in line <strong>440<\/strong>) with this:<\/p>\n<p>document.getElementById(&#8216;imageContainer&#8217;).onclick = function() { return false; }\n} else {\ndocument.getElementById(&#8216;imageContainer&#8217;).onclick = function() { myLightbox.end(); return false; }\n}<\/p>\n<p>What this does is it applies the <code>onclick<\/code> <em>close<\/em> function <strong>only<\/strong> when you&#8217;re viewing a <em>single<\/em> image. As you can see, the first chunk of code is the part where it displays <em>Image x of x<\/em> when viewing <strong>a set<\/strong> of pictures. The <code>if<\/code> conditional statement simply checks if the imageArray.length <span class=\"footnote_referrer\"><a role=\"button\" tabindex=\"0\" onclick=\"footnote_moveToReference_467_1('footnote_plugin_reference_467_1_1');\" onkeypress=\"footnote_moveToReference_467_1('footnote_plugin_reference_467_1_1');\" ><sup id=\"footnote_plugin_tooltip_467_1_1\" class=\"footnote_plugin_tooltip_text\">1 <\/sup><\/a><span id=\"footnote_plugin_tooltip_text_467_1_1\" class=\"footnote_tooltip\">Simply put, this checks how many images are part of the particular Lightbox instance<\/span><\/span><script type=\"text\/javascript\"> jQuery('#footnote_plugin_tooltip_467_1_1').tooltip({ tip: '#footnote_plugin_tooltip_text_467_1_1', tipClass: 'footnote_tooltip', effect: 'fade', predelay: 0, fadeInSpeed: 200, delay: 400, fadeOutSpeed: 200, position: 'top right', relative: true, offset: [10, 10], });<\/script> is more than one (more than one image) &#8211; then appropriately engages and displays the line <em>Image x of x<\/em><\/p>\n<p>By that logic, you can simply say that adding an <code>else<\/code> would mean it would apply to those that are <em>not<\/em> greater than one&#8230; practically speaking that means <em>one.<\/em> So I decided to plug the close function there.<\/p>\n<p>If you&#8217;re asking why I seemingly put a blank <code>onclick<\/code> function before the <code>else<\/code>, it&#8217;s because for some reason, when you have grouped and single images in one page, Once you engage a single-mode lightbox, it apparently sets the <em>close<\/em> function permanently, <span class=\"footnote_referrer\"><a role=\"button\" tabindex=\"0\" onclick=\"footnote_moveToReference_467_1('footnote_plugin_reference_467_1_2');\" onkeypress=\"footnote_moveToReference_467_1('footnote_plugin_reference_467_1_2');\" ><sup id=\"footnote_plugin_tooltip_467_1_2\" class=\"footnote_plugin_tooltip_text\">2 <\/sup><\/a><span id=\"footnote_plugin_tooltip_text_467_1_2\" class=\"footnote_tooltip\">Subsequent clicks to any Lightbox image (grouped or otherwise, will be closed) <\/span><\/span><script type=\"text\/javascript\"> jQuery('#footnote_plugin_tooltip_467_1_2').tooltip({ tip: '#footnote_plugin_tooltip_text_467_1_2', tipClass: 'footnote_tooltip', effect: 'fade', predelay: 0, fadeInSpeed: 200, delay: 400, fadeOutSpeed: 200, position: 'top right', relative: true, offset: [10, 10], });<\/script> so I guess I just tried explicitly telling it to reset the <code>onclick<\/code> function to nothing.<\/p>\n<h2>Demonstration<\/h2>\n<p>These first two engage a single-mode lightbox view, hence you should be able to close the lightbox by clicking anywhere on the image.<\/p>\n<p><a rel=\"lightbox\" href=\"http:\/\/static.flickr.com\/78\/195194143_c4b4df3a08.jpg\" target=\"_blank\" title=\"You may click on the image for more details\"><img decoding=\"async\" alt=\"\" src=\"http:\/\/static.flickr.com\/78\/195194143_c4b4df3a08_s.jpg\" \/><\/a>\n<a rel=\"lightbox\" href=\"http:\/\/static.flickr.com\/46\/194630588_0c6b5b4a2d.jpg\" target=\"_blank\" title=\"You may click on the image for more details\"><img decoding=\"async\" alt=\"\" src=\"http:\/\/static.flickr.com\/46\/194630588_0c6b5b4a2d_s.jpg\" \/><\/a><\/p>\n<p>These next two are the <em>same<\/em> images, but now grouped in a set. You should be able to click on the next\/prev overlay without accidentally closing the lightbox.<\/p>\n<p><a rel=\"lightbox[group]\" href=\"http:\/\/static.flickr.com\/78\/195194143_c4b4df3a08.jpg\" target=\"_blank\" title=\"You may click on the image for more details\"><img decoding=\"async\" alt=\"\" src=\"http:\/\/static.flickr.com\/78\/195194143_c4b4df3a08_s.jpg\" \/><\/a>\n<a rel=\"lightbox[group]\" href=\"http:\/\/static.flickr.com\/46\/194630588_0c6b5b4a2d.jpg\" target=\"_blank\" title=\"You may click on the image for more details\"><img decoding=\"async\" alt=\"\" src=\"http:\/\/static.flickr.com\/46\/194630588_0c6b5b4a2d_s.jpg\" \/><\/a><\/p><div class=\"speaker-mute footnotes_reference_container\"> <div class=\"footnote_container_prepare\"><p><span role=\"button\" tabindex=\"0\" class=\"footnote_reference_container_label pointer\" onclick=\"footnote_expand_collapse_reference_container_467_1();\">Notes<\/span><span role=\"button\" tabindex=\"0\" class=\"footnote_reference_container_collapse_button\" style=\"display: none;\" onclick=\"footnote_expand_collapse_reference_container_467_1();\">[<a id=\"footnote_reference_container_collapse_button_467_1\">+<\/a>]<\/span><\/p><\/div> <div id=\"footnote_references_container_467_1\" style=\"\"><table class=\"footnotes_table footnote-reference-container\"><caption class=\"accessibility\">Notes<\/caption> <tbody> \r\n\r\n<tr class=\"footnotes_plugin_reference_row\"> <th scope=\"row\" class=\"footnote_plugin_index_combi pointer\"  onclick=\"footnote_moveToAnchor_467_1('footnote_plugin_tooltip_467_1_1');\"><a id=\"footnote_plugin_reference_467_1_1\" class=\"footnote_backlink\"><span class=\"footnote_index_arrow\">&#8673;<\/span>1<\/a><\/th> <td class=\"footnote_plugin_text\">Simply put, this checks how many images are part of the particular Lightbox instance<\/td><\/tr>\r\n\r\n<tr class=\"footnotes_plugin_reference_row\"> <th scope=\"row\" class=\"footnote_plugin_index_combi pointer\"  onclick=\"footnote_moveToAnchor_467_1('footnote_plugin_tooltip_467_1_2');\"><a id=\"footnote_plugin_reference_467_1_2\" class=\"footnote_backlink\"><span class=\"footnote_index_arrow\">&#8673;<\/span>2<\/a><\/th> <td class=\"footnote_plugin_text\">Subsequent clicks to any Lightbox image (grouped or otherwise, will be closed) <\/td><\/tr>\r\n\r\n <\/tbody> <\/table> <\/div><\/div><script type=\"text\/javascript\"> function footnote_expand_reference_container_467_1() { jQuery('#footnote_references_container_467_1').show(); jQuery('#footnote_reference_container_collapse_button_467_1').text('\u2212'); } function footnote_collapse_reference_container_467_1() { jQuery('#footnote_references_container_467_1').hide(); jQuery('#footnote_reference_container_collapse_button_467_1').text('+'); } function footnote_expand_collapse_reference_container_467_1() { if (jQuery('#footnote_references_container_467_1').is(':hidden')) { footnote_expand_reference_container_467_1(); } else { footnote_collapse_reference_container_467_1(); } } function footnote_moveToReference_467_1(p_str_TargetID) { footnote_expand_reference_container_467_1(); var l_obj_Target = jQuery('#' + p_str_TargetID); if (l_obj_Target.length) { jQuery( 'html, body' ).delay( 0 ); jQuery('html, body').animate({ scrollTop: l_obj_Target.offset().top - window.innerHeight * 0.2 }, 380); } } function footnote_moveToAnchor_467_1(p_str_TargetID) { footnote_expand_reference_container_467_1(); var l_obj_Target = jQuery('#' + p_str_TargetID); if (l_obj_Target.length) { jQuery( 'html, body' ).delay( 0 ); jQuery('html, body').animate({ scrollTop: l_obj_Target.offset().top - window.innerHeight * 0.2 }, 380); } }<\/script>","protected":false},"excerpt":{"rendered":"<p>NOTICECONTENTS NO LONGER APPLICABLE The content discussed in this post is no longer valid; as I&#8217;m now using a different &#8220;lightbox&#8221; implementation.More here When opening an image via lightbox, closing an image can get very counter intuitive. The close button is at the bottom right, which sucks if you have an image that&#8217;s larger than &hellip; <p class=\"link-more\"><a href=\"http:\/\/nargalzius.com\/blog\/archives\/2006\/07\/25\/another-lightbox-hack\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Another Lightbox hack&#8221;<\/span><\/a><\/p><\/p>","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","enabled":false},"version":2}},"categories":[5,9,13],"tags":[595,694,810],"class_list":["post-467","post","type-post","status-publish","format-standard","hentry","category-internet","category-nargalzius","category-technology","tag-internet","tag-lightbox","tag-nargalzius"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/nargalzius.com\/blog\/wp-json\/wp\/v2\/posts\/467","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/nargalzius.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nargalzius.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nargalzius.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nargalzius.com\/blog\/wp-json\/wp\/v2\/comments?post=467"}],"version-history":[{"count":4,"href":"http:\/\/nargalzius.com\/blog\/wp-json\/wp\/v2\/posts\/467\/revisions"}],"predecessor-version":[{"id":1891,"href":"http:\/\/nargalzius.com\/blog\/wp-json\/wp\/v2\/posts\/467\/revisions\/1891"}],"wp:attachment":[{"href":"http:\/\/nargalzius.com\/blog\/wp-json\/wp\/v2\/media?parent=467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nargalzius.com\/blog\/wp-json\/wp\/v2\/categories?post=467"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nargalzius.com\/blog\/wp-json\/wp\/v2\/tags?post=467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}