From 0b319ddd456faaced5a300db64b48af60e1dbaec Mon Sep 17 00:00:00 2001 From: rvelices Date: Sat, 22 Jun 2013 04:44:48 +0000 Subject: feature 2928: fctorize switchBox (now js is loaded async + also apply to the calendar type links on index page) git-svn-id: http://piwigo.org/svn/trunk@23437 68402e56-0260-453c-a942-63ccdbb3a9ee --- themes/default/js/switchbox.js | 34 +++++++++++++++++++++++----------- themes/default/template/index.tpl | 23 ++++++----------------- themes/default/template/picture.tpl | 6 +++--- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/themes/default/js/switchbox.js b/themes/default/js/switchbox.js index 9e8167a33..4741e7980 100644 --- a/themes/default/js/switchbox.js +++ b/themes/default/js/switchbox.js @@ -1,11 +1,23 @@ -function switchBox(link, box) { - jQuery(link).click(function() { - var elt = jQuery(box); - elt.css("left", Math.min( jQuery(this).offset().left, jQuery(window).width() - elt.outerWidth(true) - 5)) - .css("top", jQuery(this).offset().top + jQuery(this).outerHeight(true)) - .toggle(); - }); - jQuery(box).on("mouseleave click", function() { - jQuery(this).hide(); - }); -} \ No newline at end of file +(function () { + var sbFunc = function(link, box) { + jQuery(link).click(function() { + var elt = jQuery(box); + elt.css("left", Math.min( jQuery(this).offset().left, jQuery(window).width() - elt.outerWidth(true) - 5)) + .css("top", jQuery(this).offset().top + jQuery(this).outerHeight(true)) + .toggle(); + return false; + }); + jQuery(box).on("mouseleave click", function() { + jQuery(this).hide(); + }); + }; + + if (window.SwitchBox) { + for (var i=0; i - {footer_script require='core.switchbox'}switchBox("#sortOrderLink", "#sortOrderBox");{/footer_script} + {footer_script}(SwitchBox=window.SwitchBox||[]).push("#sortOrderLink", "#sortOrderBox");{/footer_script} {/strip} {/if} {if !empty($image_derivatives)} @@ -43,7 +43,7 @@ {/if} {/foreach} - {footer_script require='core.switchbox'}switchBox("#derivativeSwitchLink", "#derivativeSwitchBox");{/footer_script} + {footer_script}(SwitchBox=window.SwitchBox||[]).push("#derivativeSwitchLink", "#derivativeSwitchBox");{/footer_script} {/strip} {/if} @@ -101,26 +101,15 @@ {if isset($chronology_views)}
{'View'|@translate}: - + {foreach from=$chronology_views item=view}{if $view.SELECTED}{$view.CONTENT}{/if}{/foreach} - +
{foreach from=$chronology_views item=view name=loop}{if !$smarty.foreach.loop.first}
{/if} {$view.CONTENT} {/foreach}
- {footer_script require='jquery'}{literal} -function toggleCalendarViewsBox() { - var elt = jQuery("#calendarViewSwitchBox") - , ePos = jQuery("#calendarViewSwitchLink"); - elt.css("left", Math.min( ePos.offset().left, jQuery(window).width() - elt.outerWidth(true) - 5)) - .css("top", ePos.offset().top + ePos.outerHeight(true)) - .toggle(); -}; -jQuery("#calendarViewSwitchBox").on("mouseleave", function() { - jQuery(this).hide(); -}); - {/literal}{/footer_script} + {footer_script}(SwitchBox=window.SwitchBox||[]).push("#calendarViewSwitchLink", "#calendarViewSwitchBox");{/footer_script}
{/if} diff --git a/themes/default/template/picture.tpl b/themes/default/template/picture.tpl index 94be0b03d..5cede3071 100644 --- a/themes/default/template/picture.tpl +++ b/themes/default/template/picture.tpl @@ -1,4 +1,4 @@ -{combine_script id='core.switchbox' load='footer' require='jquery' path='themes/default/js/switchbox.js'} +{combine_script id='core.switchbox' load='async' require='jquery' path='themes/default/js/switchbox.js'} {if isset($MENUBAR)}{$MENUBAR}{/if}
@@ -20,7 +20,7 @@
{if isset($current.unique_derivatives) && count($current.unique_derivatives)>1} -{footer_script require='jquery,core.switchbox'}{literal} +{footer_script require='jquery'}{literal} function changeImgSrc(url,typeSave,typeMap) { var theImg = document.getElementById("theMainImage"); @@ -34,7 +34,7 @@ function changeImgSrc(url,typeSave,typeMap) jQuery('#derivativeChecked'+typeSave).css('visibility','visible'); document.cookie = 'picture_deriv='+typeSave+';path={/literal}{$COOKIE_PATH}{literal}'; } -switchBox("#derivativeSwitchLink", "#derivativeSwitchBox"); +(SwitchBox=window.SwitchBox||[]).push("#derivativeSwitchLink", "#derivativeSwitchBox"); {/literal}{/footer_script} {strip}  {'Photo sizes'|@translate} -- cgit v1.2.3