To participate you must create an account on apostrophenow.org. If you have already done so, click Login.

Changeset 2160

Show
Ignore:
Timestamp:
09/08/10 18:16:25 (17 months ago)
Author:
johnnyoffline
Message:

1. refactored aMenuToggle in aUI.js. Moved it to a.js and made it work with all of the menus (Variants, Add Content, Add Page, Page Settings)
2. refactored some browseHistory JS to be in a.js
3. created globalJavascripts partial to load some general JS at the bottom of layout.php ONCE instead of every time a partial is used.

Location:
plugins/apostrophePlugin/trunk
Files:
1 added
7 modified

Legend:

Unmodified
Added
Removed
  • plugins/apostrophePlugin/trunk/modules/a/templates/_area.php

    r2152 r2160  
    9494      <?php if ($infinite): ?> 
    9595                                <li class="a-move"> 
    96                                   <a href="#" class="a-btn icon a-arrow-up no-label" title="<?php echo a_('Move Up') ?>"><span class="icon"></span><?php echo a_('Move Up') ?></a> 
     96                                  <a href="#move-up" class="a-btn icon a-arrow-up no-label" title="<?php echo a_('Move Up') ?>" onclick="return false;"><span class="icon"></span><?php echo a_('Move Up') ?></a> 
    9797                                </li> 
    9898                                <li class="a-move"> 
    99                                   <a href="#" class="a-btn icon a-arrow-down no-label" title="<?php echo a_('Move Down') ?>"><span class="icon"></span><?php echo a_('Move Down') ?></a> 
     99                                  <a href="#move-down" class="a-btn icon a-arrow-down no-label" title="<?php echo a_('Move Down') ?>" onclick="return false;"><span class="icon"></span><?php echo a_('Move Down') ?></a> 
    100100                                </li> 
    101101      <?php endif ?> 
     
    150150 
    151151                        <?php if ($infinite): ?> 
    152                                 aMenuToggle('#a-add-slot-<?php echo $pageid.'-'.$name ?>', $('#a-add-slot-<?php echo $pageid.'-'.$name ?>').parent(), 'a-options-open', false); 
    153  
    154152                                var newSlot = $('#a-area-<?php echo "$pageid-$name" ?>').find('.a-new-slot'); 
    155153                                if (newSlot.length) { 
     
    180178</script> 
    181179<?php a_js_call('apostrophe.areaUpdateMoveButtons(?, ?, ?)', url_for('a/moveSlot'), $pageid, $name) ?> 
     180<?php a_js_call('apostrophe.menuToggle(?)', array('button' => '#a-add-slot-'.$pageid.'-'.$name, 'classname' => 'a-options-open', 'overlay' => false)) ?> 
    182181<?php endif ?> 
  • plugins/apostrophePlugin/trunk/modules/a/templates/_createPage.php

    r2149 r2160  
    4848                <ul class="a-ui a-controls"> 
    4949                <li><input type="submit" class="a-btn a-submit" value="<?php echo __('Create Page', null, 'apostrophe') ?>" /></li> 
    50                 <li><a href="#" onclick="return false;" class="a-btn icon a-cancel"><?php echo __("Cancel", null, 'apostrophe') ?></a></li> 
     50                <li><a href="#cancel" onclick="return false;" class="a-btn icon a-cancel a-options-cancel" title="<?php echo __('Cancel', null, 'apostrophe') ?>"><?php echo __("Cancel", null, 'apostrophe') ?></a></li> 
    5151                </ul> 
    5252        </div> 
     
    8282                aInputSelfLabel('#a-create-page-title', <?php echo json_encode(__('Page Title', null, 'apostrophe')) ?>); 
    8383 
    84                 aMenuToggle($('#a-create-page-button'), $('#a-create-page-button').parent(), '', true); 
    85  
    8684                $('#a-create-page-button').click(function(){ 
    8785                        $('#a-create-page-title').focus(); 
     
    8987        }); 
    9088</script> 
     89 
     90<?php a_js_call('apostrophe.menuToggle(?)', array('button' => '#a-create-page-button', 'classname' => '', 'overlay' => true)) ?> 
  • plugins/apostrophePlugin/trunk/modules/a/templates/_variant.php

    r2079 r2160  
    4343                                 }); 
    4444                                        $('<?php echo "#a-$pageid-$name-$permid-variant" ?>').children("ul.a-variant-options").hide(); 
    45                                         aMenuToggle('#a-<?php echo $pageid ?>-<?php echo $name ?>-<?php echo $permid ?>-variant-options-toggle', $('#a-<?php echo $pageid ?>-<?php echo $name ?>-<?php echo $permid ?>-variant-options-toggle').parent(), 'a-options-open', false); 
    4645                        }); 
    4746                </script> 
     
    5049  </li> 
    5150<?php endif ?> 
     51 
     52<?php a_js_call('apostrophe.menuToggle(?)', array('button' => '#a-'.$pageid.'-'.$name.'-'.$permid.'-variant-options-toggle', 'classname' => 'a-options-open', 'overlay' => false)) ?> 
  • plugins/apostrophePlugin/trunk/modules/a/templates/layout.php

    r2149 r2160  
    1 <?php use_helper('I18N') ?> 
     1<?php use_helper('a') ?> 
    22<?php // This is a copy of apostrophePlugin/modules/a/templates/layout.php ?> 
    33<?php // It also makes a fine site-wide layout, which gives you global slots on non-page templates ?> 
    44<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    55<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
    6         <?php use_helper('a') ?> 
    76        <?php // If this page is an admin page we don't want to present normal navigation relative to it. ?> 
    87        <?php $page = aTools::getCurrentNonAdminPage() ?> 
     
    9695        </div> 
    9796 
     97        <?php include_partial('a/globalJavascripts') ?> 
     98         
    9899        <?php // Drop in the document.ready stuff at the bottom. ?> 
    99100        <?php // If we try to do this sooner, it works for the template but ?> 
  • plugins/apostrophePlugin/trunk/modules/a/templates/settingsSuccess.php

    r2154 r2160  
    142142                <ul class="a-ui a-controls">             
    143143                  <li><input type="submit" name="submit" value="<?php echo htmlspecialchars(__('Save Changes', null, 'apostrophe')) ?>" class="a-btn a-submit" id="a-page-settings-submit" /></li> 
    144                         <li><?php echo jq_link_to_function(__('Cancel', null, 'apostrophe'), '',  array('class' => 'a-btn icon a-cancel', 'title' => __('Cancel', null, 'apostrophe'))) ?></li> 
     144                        <li><a href="#cancel" onclick="return false;" class="a-btn icon a-cancel a-options-cancel" title="<?php echo __('Cancel', null, 'apostrophe') ?>"><?php echo __('Cancel', null, 'apostrophe') ?></a></li> 
    145145                        <?php if ($page->userHasPrivilege('manage')): ?> 
    146146                                <?php $childMessage = ''; ?> 
     
    157157<script src="/sfJqueryReloadedPlugin/js/plugins/jquery.autocomplete.js"></script> 
    158158<script src="/sfDoctrineActAsTaggablePlugin/js/pkTagahead.js"></script> 
     159 
    159160<?php a_include_js_calls() ?> 
     161 
    160162<script type="text/javascript" charset="utf-8"> 
    161163        $(document).ready(function() { 
  • plugins/apostrophePlugin/trunk/web/js/a.js

    r2158 r2160  
    382382                                                $('#a-slots-' + id + '-' + name).html(result);                   
    383383                                                historyBtn.removeClass('a-disabled');                                            
    384                                                 aCloseHistory(); 
     384                                                _closeHistory(); 
    385385                                                aUI(targetArea, 'history-revert'); 
    386386                                } 
     
    396396                                $('#a-slots-' + id + '-' + name).html(result); 
    397397                                                historyBtn.removeClass('a-disabled');                                                            
    398                                                 aCloseHistory(); 
     398                                                _closeHistory(); 
    399399                                                aUI(targetArea); 
    400400                                } 
     
    410410        } 
    411411 
     412        this.enableBrowseHistoryButtons = function(options) 
     413        { 
     414                var historyBtn = $(options['history_buttons']); 
     415                historyBtn.unbind("click").click(function(event){ 
     416                        event.preventDefault();                  
     417                        _closeHistory(); 
     418                        _browseHistory(historyBtn.closest('div.a-area'));                
     419                }); 
     420        } 
     421         
     422        this.enableCloseHistoryButtons = function(options) 
     423        { 
     424                var closeHistoryBtns = $(options['close_history_buttons']); 
     425                closeHistoryBtns.click(function(){ 
     426                        _closeHistory(); 
     427                }); 
     428        } 
     429         
     430        function _browseHistory(area) 
     431        { 
     432                var areaControls = area.find('ul.a-area-controls'); 
     433                var areaControlsTop = areaControls.offset().top; 
     434         
     435                $('.a-page-overlay').show(); 
     436         
     437                // Clear Old History from the Browser 
     438                if (!area.hasClass('browsing-history'))  
     439                { 
     440                        $('.a-history-browser .a-history-items').html('<tr class="a-history-item"><td class="date"><img src="\/apostrophePlugin\/images\/a-icon-loader.gif"><\/td><td class="editor"><\/td><td class="preview"><\/td><\/tr>'); 
     441                        area.addClass('browsing-history'); 
     442                } 
     443         
     444                // Positioning the History Browser 
     445                $('.a-history-browser').css('top',(areaControlsTop-5)+"px"); //21 = height of buttons plus one margin 
     446                $('.a-history-browser').fadeIn(); 
     447                $('.a-page-overlay').click(function(){ 
     448                        _closeHistory(); 
     449                        $(this).unbind('click'); 
     450                }); 
     451         
     452                $('#a-history-preview-notice-toggle').click(function(){ 
     453                        $('.a-history-preview-notice').children(':not(".a-history-options")').slideUp(); 
     454                }); 
     455        } 
     456 
     457        function _closeHistory() 
     458        { 
     459                $('a.a-history-btn').parents('.a-area').removeClass('browsing-history'); 
     460                $('a.a-history-btn').parents('.a-area').removeClass('previewing-history'); 
     461                $('.a-history-browser, .a-history-preview-notice').hide(); 
     462          $('body').removeClass('history-preview');      
     463                $('.a-page-overlay').fadeOut(); 
     464        } 
     465 
    412466        this.pageSettings = function(options) 
    413467        { 
     
    415469                var aPageSettingsButton = $('#a-page-settings-button');          
    416470 
    417                 aMenuToggle('#a-page-settings-button', $('#a-page-settings-button').parent(), '', true); 
     471                _menuToggle('#a-page-settings-button', '', true); 
    418472 
    419473                aPageSettingsButton.click(function() { 
     
    578632                aUI(editBtn.parents('.a-slot').attr('id')); // Refresh the UI scoped to this Slot 
    579633        } 
     634         
     635        this.menuToggle = function(options) 
     636        {                
     637                var button = options['button']; 
     638                var classname = options['classname']; 
     639                var overlay = options['overlay']; 
     640                _menuToggle(button, classname, overlay); 
     641        } 
     642 
     643 
     644        function _menuToggle(button, classname, overlay) 
     645        {        
     646                /* Usage: aMenuToggle(Object|ID Selector, Object|ID Selector, Undefined|String, Undefined|True|False) */ 
     647 
     648                if (typeof button == "string") { button = $(button); } /* button that toggles the menu open & closed */ 
     649                if (typeof classname == "undefined" || classname == '') { classname = "show-options";   } /* optional classname override to use for toggle & styling */ 
     650                if (typeof overlay != "undefined" && overlay) { overlay = $('.a-page-overlay'); } /* optional full overlay */  
     651                var menu = $(button).parent(); // Use the parent of the button as the menu container 
     652                 
     653                if (menu.attr('id') == '') { 
     654                        // We need an ID for the menu. If the menu doesn't have one, we create it by appending 'menu' to the Button ID 
     655                        newID = button.attr('id')+'-menu'; 
     656                        menu.attr('id', newID); 
     657                } 
     658 
     659                button.unbind('click').click(function() 
     660                { 
     661                        // Button Toggle 
     662                        if (!button.hasClass('aActiveMenu'))  
     663                        {  
     664                                menu.trigger('toggleOpen');  
     665                        } 
     666                        else  
     667                        { 
     668                                menu.trigger('toggleClosed'); 
     669                        } 
     670                }); 
     671 
     672                menu.bind('toggleOpen', function(){ 
     673                        // Open Menu, Create Listener 
     674                        button.addClass('aActiveMenu'); 
     675                        menu.addClass(classname);                        
     676                        if (overlay) { overlay.stop().show(); } 
     677                        $(document).click(function(e){ 
     678                                var target = e.target;  
     679                                target = $(target);   
     680                                if (target.hasClass('.a-page-overlay') || target.hasClass('.a-cancel')) { 
     681                                        menu.trigger('toggleClosed'); 
     682                                } 
     683                                if (!target.parents().is('#'+menu.attr('id'))) { 
     684                                        menu.trigger('toggleClosed'); 
     685                                } 
     686                        });      
     687                }); 
     688 
     689                menu.bind('toggleClosed', function(){ 
     690                        // Close Menu, Destroy Listener 
     691                        button.removeClass('aActiveMenu'); 
     692                        menu.removeClass(classname); 
     693                        if (overlay) { overlay.fadeOut(); } 
     694                        $(document).unbind('click'); // Clear out click event            
     695                }); 
     696 
     697                $('.a-options-cancel').live('click', function(){ 
     698                        // console.log(menu); 
     699                        $(this).closest(menu).trigger('toggleClosed'); 
     700                }); 
     701 
     702        } 
     703         
    580704}  
    581705 
  • plugins/apostrophePlugin/trunk/web/js/aUI.js

    r2089 r2160  
    11function aUI(target) 
    22{ 
    3          
    43        // Grab Target if Passed Through 
    54        if (typeof(target) == 'undefined') // If Not Set 
     
    4544          }); 
    4645        } 
    47  
    48         // Area History Buttons 
    49         $('a.a-history-btn').unbind("click").click(function(event){ 
    50                 event.preventDefault();                  
    51                 aCloseHistory(); 
    52                 aBrowseHistory($(this).parents('div.a-area')); 
    53         }); 
    54          
    55         // Close History Browser 
    56         $('#a-history-close-button, #a-history-heading-button').click(function(){ 
    57                 aCloseHistory(); 
    58         }); 
    5946         
    6047        // Variants 
     
    9986} 
    10087 
    101 function aMenuToggle(button, menu, classname, overlay) 
    102 {        
    103         /* Usage: aMenuToggle(Object|ID(String), Object|ID(String), Undefined|String, Undefined|True|False) */ 
    104         if (typeof button == "string") { button = $(button); } 
    105         if (typeof menu == "string") { menu = $(menu); } 
    106         if (typeof classname == "undefined" || classname == '') { classname = "show-options";   } 
    107         if (typeof overlay != "undefined" && overlay) { overlay = $('.a-page-overlay'); } 
    108          
    109         if (menu.attr('id') == '') { 
    110                 // We need an ID for the menu. If the menu doesn't have one, we create it by appending 'menu' to the Button ID 
    111                 newID = button.attr('id')+'-menu'; 
    112                 menu.attr('id', newID); 
    113         } 
    114          
    115         button.unbind('click').click(function() 
    116         { 
    117                 // Button Toggle 
    118                 if (!button.hasClass('aActiveMenu'))  
    119                 {  
    120                         menu.trigger('toggleOpen');  
    121                 } 
    122                 else  
    123                 { 
    124                         menu.trigger('toggleClosed'); 
    125                 } 
    126         }); 
    127  
    128         menu.bind('toggleOpen', function(){ 
    129                 // Open Menu, Create Listener 
    130                 button.addClass('aActiveMenu'); 
    131                 menu.addClass(classname);                        
    132                 if (overlay) { overlay.stop().show(); } 
    133                 $(document).click(function(e){ 
    134                         var target = e.target;  
    135                         target = $(target);   
    136                         if (target.hasClass('.a-page-overlay') || target.hasClass('.a-cancel')) { 
    137                                 menu.trigger('toggleClosed'); 
    138                         } 
    139                         if (!target.parents().is('#'+menu.attr('id'))) { 
    140                                 menu.trigger('toggleClosed'); 
    141                         } 
    142                 });      
    143         }); 
    144          
    145         menu.bind('toggleClosed', function(){ 
    146                 // Close Menu, Destroy Listener 
    147                 button.removeClass('aActiveMenu'); 
    148                 menu.removeClass(classname); 
    149                 if (overlay) { overlay.fadeOut(); } 
    150                 $(document).unbind('click'); // Clear out click event            
    151         }); 
    152  
    153 } 
    154  
    15588function aAccordion(heading) 
    15689{ 
     
    168101} 
    169102 
    170  
    171 function aBrowseHistory(area) 
    172 { 
    173         var areaControls = area.find('ul.a-area-controls'); 
    174         var areaControlsTop = areaControls.offset().top; 
    175  
    176         $('.a-page-overlay').show(); 
    177                  
    178         // Clear Old History from the Browser 
    179         if (!area.hasClass('browsing-history'))  
    180         { 
    181                 $('.a-history-browser .a-history-items').html('<tr class="a-history-item"><td class="date"><img src="\/apostrophePlugin\/images\/a-icon-loader.gif"><\/td><td class="editor"><\/td><td class="preview"><\/td><\/tr>'); 
    182                 area.addClass('browsing-history'); 
    183         } 
    184                          
    185         // Positioning the History Browser 
    186         $('.a-history-browser').css('top',(areaControlsTop-5)+"px"); //21 = height of buttons plus one margin 
    187         $('.a-history-browser').fadeIn(); 
    188         $('.a-page-overlay').click(function(){ 
    189                 aCloseHistory(); 
    190                 $(this).unbind('click'); 
    191         }); 
    192          
    193         $('#a-history-preview-notice-toggle').click(function(){ 
    194                 $('.a-history-preview-notice').children(':not(".a-history-options")').slideUp(); 
    195         }); 
    196 } 
    197  
    198 function aCloseHistory() 
    199 { 
    200         $('a.a-history-btn').parents('.a-area').removeClass('browsing-history'); 
    201         $('a.a-history-btn').parents('.a-area').removeClass('previewing-history'); 
    202         $('.a-history-browser, .a-history-preview-notice').hide(); 
    203   $('body').removeClass('history-preview');      
    204         $('.a-page-overlay').fadeOut(); 
    205 } 
    206  
    207103$(document).ready(function(){ 
    208104        aUI();