From 078e4d1bbdc920ff6c7a3ba8777fae2b23d38909 Mon Sep 17 00:00:00 2001 From: mistic100 Date: Tue, 18 Jun 2013 10:29:55 +0000 Subject: feature:2928 Factorize JS code for switchBox switchBox("selector for link", "selector for box"); git-svn-id: http://piwigo.org/svn/trunk@23320 68402e56-0260-453c-a942-63ccdbb3a9ee --- themes/default/js/switchbox.js | 11 +++++++++++ themes/default/template/index.tpl | 26 ++++---------------------- themes/default/template/picture.tpl | 19 ++++++------------- 3 files changed, 21 insertions(+), 35 deletions(-) create mode 100644 themes/default/js/switchbox.js diff --git a/themes/default/js/switchbox.js b/themes/default/js/switchbox.js new file mode 100644 index 000000000..9e8167a33 --- /dev/null +++ b/themes/default/js/switchbox.js @@ -0,0 +1,11 @@ +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 diff --git a/themes/default/template/index.tpl b/themes/default/template/index.tpl index 71e8d8ba4..89ac0f2b4 100644 --- a/themes/default/template/index.tpl +++ b/themes/default/template/index.tpl @@ -1,5 +1,7 @@ +{combine_script id='core.switchbox' load='footer' require='jquery' path='themes/default/js/switchbox.js'} {$MENUBAR} + {if isset($errors) or isset($infos)}
{include file='infos_errors.tpl'} @@ -24,17 +26,7 @@ {/if} {/foreach}
- {footer_script require='jquery'}{literal} -jQuery("#sortOrderLink").click(function() { - var elt = jQuery("#sortOrderBox"); - 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("#sortOrderBox").on("mouseleave", function() { - jQuery(this).hide(); -}); - {/literal}{/footer_script} + {footer_script require='core.switchbox'}switchBox("#sortOrderLink", "#sortOrderBox");{/footer_script} {/strip} {/if} {if !empty($image_derivatives)} @@ -51,17 +43,7 @@ jQuery("#sortOrderBox").on("mouseleave", function() { {/if} {/foreach} - {footer_script require='jquery'}{literal} -jQuery("#derivativeSwitchLink").click(function() { - var elt = jQuery("#derivativeSwitchBox"); - 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("#derivativeSwitchBox").on("mouseleave", function() { - jQuery(this).hide(); -}); - {/literal}{/footer_script} + {footer_script require='core.switchbox'}switchBox("#derivativeSwitchLink", "#derivativeSwitchBox");{/footer_script} {/strip} {/if} diff --git a/themes/default/template/picture.tpl b/themes/default/template/picture.tpl index d86434c88..419918aca 100644 --- a/themes/default/template/picture.tpl +++ b/themes/default/template/picture.tpl @@ -1,11 +1,11 @@ -{* Example of resizeable -{include file='include/autosize.inc.tpl'} -*} +{combine_script id='core.switchbox' load='footer' require='jquery' path='themes/default/js/switchbox.js'} {if isset($MENUBAR)}{$MENUBAR}{/if}
+ {if isset($errors) or not empty($infos)} {include file='infos_errors.tpl'} {/if} + {if !empty($PLUGIN_PICTURE_BEFORE)}{$PLUGIN_PICTURE_BEFORE}{/if}
@@ -17,9 +17,10 @@
{$PHOTO}
{include file='picture_nav_buttons.tpl'|@get_extent:'picture_nav_buttons'} +
{if isset($current.unique_derivatives) && count($current.unique_derivatives)>1} -{footer_script require='jquery'}{literal} +{footer_script require='jquery,core.switchbox'}{literal} function changeImgSrc(url,typeSave,typeMap) { var theImg = document.getElementById("theMainImage"); @@ -33,15 +34,7 @@ function changeImgSrc(url,typeSave,typeMap) jQuery('#derivativeChecked'+typeSave).css('visibility','visible'); document.cookie = 'picture_deriv='+typeSave+';path={/literal}{$COOKIE_PATH}{literal}'; } -jQuery("#derivativeSwitchLink").click(function() { - var elt = jQuery("#derivativeSwitchBox"); - 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("#derivativeSwitchBox").on("mouseleave click", function() { - jQuery(this).hide(); -}); +switchBox("#derivativeSwitchLink", "#derivativeSwitchBox"); {/literal}{/footer_script} {strip}  {'Photo sizes'|@translate} -- cgit v1.2.3