Changeset 23437


Ignore:
Timestamp:
06/22/13 06:44:48 (7 years ago)
Author:
rvelices
Message:

feature 2928: fctorize switchBox (now js is loaded async + also apply to the calendar type links on index page)

Location:
trunk/themes/default
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/themes/default/js/switchbox.js

    r23320 r23437  
    1 function switchBox(link, box) { 
    2   jQuery(link).click(function() { 
    3     var elt = jQuery(box); 
    4     elt.css("left", Math.min( jQuery(this).offset().left, jQuery(window).width() - elt.outerWidth(true) - 5)) 
    5       .css("top", jQuery(this).offset().top + jQuery(this).outerHeight(true)) 
    6       .toggle(); 
    7   }); 
    8   jQuery(box).on("mouseleave click", function() { 
    9     jQuery(this).hide(); 
    10   }); 
    11 } 
     1(function () { 
     2        var sbFunc = function(link, box) { 
     3                jQuery(link).click(function() { 
     4                        var elt = jQuery(box); 
     5                        elt.css("left", Math.min( jQuery(this).offset().left, jQuery(window).width() - elt.outerWidth(true) - 5)) 
     6                                .css("top", jQuery(this).offset().top + jQuery(this).outerHeight(true)) 
     7                                .toggle(); 
     8                        return false; 
     9                }); 
     10                jQuery(box).on("mouseleave click", function() { 
     11                        jQuery(this).hide(); 
     12                }); 
     13        }; 
     14 
     15        if (window.SwitchBox) { 
     16                for (var i=0; i<SwitchBox.length; i+=2) 
     17                        sbFunc(SwitchBox[i], SwitchBox[i+1]); 
     18        } 
     19 
     20        SwitchBox = { 
     21                push: sbFunc 
     22        } 
     23})(); 
  • trunk/themes/default/template/index.tpl

    r23399 r23437  
    1 {combine_script id='core.switchbox' load='footer' require='jquery' path='themes/default/js/switchbox.js'} 
     1{combine_script id='core.switchbox' load='async' require='jquery' path='themes/default/js/switchbox.js'} 
    22{$MENUBAR} 
    33 
     
    2727                        {/foreach} 
    2828                </div> 
    29                 {footer_script require='core.switchbox'}switchBox("#sortOrderLink", "#sortOrderBox");{/footer_script} 
     29                {footer_script}(SwitchBox=window.SwitchBox||[]).push("#sortOrderLink", "#sortOrderBox");{/footer_script} 
    3030                {/strip}</li> 
    3131{/if} 
     
    4444                        {/foreach} 
    4545                </div> 
    46                 {footer_script require='core.switchbox'}switchBox("#derivativeSwitchLink", "#derivativeSwitchBox");{/footer_script} 
     46                {footer_script}(SwitchBox=window.SwitchBox||[]).push("#derivativeSwitchLink", "#derivativeSwitchBox");{/footer_script} 
    4747                {/strip}</li> 
    4848{/if} 
     
    102102{if isset($chronology_views)} 
    103103<div class="calendarViews">{'View'|@translate}: 
    104         <a id="calendarViewSwitchLink" href="javascript:toggleCalendarViewsBox()"> 
     104        <a id="calendarViewSwitchLink" href="#"> 
    105105        {foreach from=$chronology_views item=view}{if $view.SELECTED}{$view.CONTENT}{/if}{/foreach} 
    106         </a>  
     106        </a> 
    107107        <div id="calendarViewSwitchBox" class="switchBox"> 
    108108                {foreach from=$chronology_views item=view name=loop}{if !$smarty.foreach.loop.first}<br>{/if} 
     
    110110                {/foreach} 
    111111        </div> 
    112         {footer_script require='jquery'}{literal} 
    113 function toggleCalendarViewsBox() { 
    114         var elt = jQuery("#calendarViewSwitchBox") 
    115                 , ePos = jQuery("#calendarViewSwitchLink"); 
    116         elt.css("left", Math.min( ePos.offset().left, jQuery(window).width() - elt.outerWidth(true) - 5)) 
    117                 .css("top", ePos.offset().top + ePos.outerHeight(true)) 
    118                 .toggle(); 
    119 }; 
    120 jQuery("#calendarViewSwitchBox").on("mouseleave", function() { 
    121         jQuery(this).hide(); 
    122 }); 
    123         {/literal}{/footer_script} 
     112        {footer_script}(SwitchBox=window.SwitchBox||[]).push("#calendarViewSwitchLink", "#calendarViewSwitchBox");{/footer_script} 
    124113</div> 
    125114{/if} 
  • trunk/themes/default/template/picture.tpl

    r23384 r23437  
    1 {combine_script id='core.switchbox' load='footer' require='jquery' path='themes/default/js/switchbox.js'} 
     1{combine_script id='core.switchbox' load='async' require='jquery' path='themes/default/js/switchbox.js'} 
    22{if isset($MENUBAR)}{$MENUBAR}{/if} 
    33<div id="content"{if isset($MENUBAR)} class="contentWithMenu"{/if}> 
     
    2121<div class="actionButtons"> 
    2222{if isset($current.unique_derivatives) && count($current.unique_derivatives)>1} 
    23 {footer_script require='jquery,core.switchbox'}{literal} 
     23{footer_script require='jquery'}{literal} 
    2424function changeImgSrc(url,typeSave,typeMap) 
    2525{ 
     
    3535        document.cookie = 'picture_deriv='+typeSave+';path={/literal}{$COOKIE_PATH}{literal}'; 
    3636} 
    37 switchBox("#derivativeSwitchLink", "#derivativeSwitchBox"); 
     37(SwitchBox=window.SwitchBox||[]).push("#derivativeSwitchLink", "#derivativeSwitchBox"); 
    3838{/literal}{/footer_script} 
    3939{strip}<a id="derivativeSwitchLink" title="{'Photo sizes'|@translate}" class="pwg-state-default pwg-button" rel="nofollow"> 
Note: See TracChangeset for help on using the changeset viewer.