Plugin Directory

Changeset 2291595


Ignore:
Timestamp:
04/25/2020 02:09:01 PM (6 years ago)
Author:
processby
Message:

Responsive sidebar update

Location:
responsive-sidebar/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • responsive-sidebar/trunk/readme.txt

    r2290403 r2291595  
    55Requires at least: 5.0.3
    66Tested up to: 5.4
    7 Stable tag: 1.1.1
     7Stable tag: 1.2.0
    88Requires PHP: 5.6
    99License: GPLv2 or later
     
    3939== Changelog ==
    4040
     41= 1.2.0 =
     42Release Date: Apr 25, 2020
     43
     44* Support for multiple sidebars
     45
     46
    4147= 1.1.1 =
    4248Release Date: Apr 23, 2020
  • responsive-sidebar/trunk/responsive-sidebar.php

    r2290403 r2291595  
    88 * Plugin URI:        https://processby.com/responsive-sidebar-wordpress-plugin/
    99 * Description:       Makes your sidebar responsive.
    10  * Version:           1.1.1
     10 * Version:           1.2.0
    1111 * Author:            Processby
    1212 * Author URI:        https://processby.com
  • responsive-sidebar/trunk/src/Admin/Settings.php

    r2030422 r2291595  
    4949            'maxWidth' => $this->getOption('maxWidth'),
    5050            'sidebarSwipe' => $this->getOption('sidebarSwipe'),
     51            'sidebars' => $this->getOption('sidebars')
    5152        ));
    5253    }
     
    6970    public function updateSettings($settings)
    7071    {
     72        //dump($settings); die;
    7173        if(!isset($settings['sidebarSwipe']))
    7274            $settings['sidebarSwipe'] = 0;
     75
     76        if(!isset($settings['sidebars']))
     77            $settings['sidebars'] = array();
    7378
    7479
  • responsive-sidebar/trunk/src/Frontend/Frontend.php

    r2290403 r2291595  
    6060        add_action('wp_footer', array($this, 'addButtonHtml'));
    6161        add_action('wp_footer', array($this, 'addInlineScript'));
    62 
    63     }
     62        add_action( 'dynamic_sidebar_before', array($this, 'SidebarWrapBefore'), 10, 2 );
     63        add_action( 'dynamic_sidebar_after', array($this, 'SidebarWrapAfter'), 10, 2 );
     64
     65    }
     66
     67    public function SidebarWrapBefore($index, $has_widgets)
     68    {
     69
     70        foreach ($this->options['sidebars'] as  $sidebarId){
     71            if( is_active_sidebar( $sidebarId ) &&  $index == $sidebarId){
     72                echo '<div class="resp-sidebar-wrapper">';
     73            }
     74        }
     75
     76
     77    }
     78
     79    public function SidebarWrapAfter($index, $has_widgets)
     80    {
     81
     82        foreach ($this->options['sidebars'] as  $sidebarId){
     83            if( is_active_sidebar( $sidebarId ) &&  $index == $sidebarId){
     84                echo '</div>';
     85            }
     86        }
     87
     88
     89    }
     90
    6491
    6592    public function enqueueScripts()
    6693    {
    67 
    6894
    6995    }
     
    108134        $hiddenWidth = -$this->settings['sidebarWidth']-10;
    109135
    110         $styles = "<style>
    111         @media screen and (max-width: {$this->options['maxWidth']}px){
    112             #{$this->options['cssClasses']} {
     136
     137        $styles = "<style> @media screen and (max-width: {$this->options['maxWidth']}px){";
     138
     139
     140        if(!empty($this->options['sidebars'])){
     141            $styles .= ".resp-sidebar-wrapper{
    113142            display: block;
    114143            position: fixed;
     
    124153            transition-duration: 0.5s;
    125154            transition-property: left;
    126             }
    127         }
    128         #{$this->options['cssClasses']}.opened {
     155            }";
     156        } elseif(!empty($this->options['cssClasses'])){
     157            $styles .=  "#{$this->options['cssClasses']}{
     158            display: block;
     159            position: fixed;
     160            top: 0;
     161            bottom: -100px;
     162            left: {$hiddenWidth}px;
     163            width: {$this->settings['sidebarWidth']}px;
     164            overflow: auto;
     165            z-index: 9999;
     166            background: {$this->settings['sidebarBackground']};
     167            $sidebarShadows;
     168            padding-bottom: 100px;
     169            transition-duration: 0.5s;
     170            transition-property: left;
     171            }";
     172        }
     173
     174
     175        $styles .= "
     176        }
     177        .resp-sidebar-wrapper.opened {
    129178            left: 0;
    130179        }";
     180
     181        if(!empty($this->options['cssClasses'])){
     182            $styles .= "#{$this->options['cssClasses']}.opened {
     183            left: 0;
     184            }";
     185        }
     186
    131187
    132188        if ($this->settings['enableButton']) {
     
    192248    public function addInlineScript()
    193249    {
    194 
     250        if(!empty($this->options['sidebars'])){
     251
     252        }
    195253        $ResponsiveSidebarScript = "<script type='text/javascript'>
    196254
    197         var wr = document.getElementById('{$this->options['cssClasses']}');
    198         var btn = document.getElementById('responsive-sidebar-btn');
     255        var wrId = document.getElementById('{$this->options['cssClasses']}'); 
     256        var wr = document.getElementsByClassName('resp-sidebar-wrapper');
     257        ";
     258
     259
     260        $ResponsiveSidebarScript .= "var btn = document.getElementById('responsive-sidebar-btn');
    199261        var openedClass = 'opened';
    200262   
    201         if(wr != null){
     263        if(wrId != null || wr.length != 0){
    202264             btn.style.cssText = '';
    203265        }
     
    212274       
    213275        function openMobileSidebar() {
    214             wr.classList.add(openedClass);
     276       
     277        if(wrId != null){
     278             wrId.classList.add(openedClass);
     279        }
     280        if(wr.length != 0){
     281              wr[0].classList.add(openedClass);
     282        }   
    215283            btn.classList.add(openedClass);
    216284           
    217285        }
    218286        function closeMobileSidebar() {
    219             wr.classList.remove(openedClass);
     287         if(wrId != null){
     288             wrId.classList.remove(openedClass);
     289        }
     290        if(wr.length != 0){
     291              wr[0].classList.remove(openedClass);
     292        }
    220293            btn.classList.remove(openedClass);
    221         }";
     294        }
     295       
     296        function findAncestor (el, cls) {
     297            while ((el = el.parentElement) && !el.classList.contains(cls));
     298            return el;
     299        }     
     300        ";
     301
     302
    222303
    223304        if ($this->options['sidebarSwipe']) {
     305
    224306            $ResponsiveSidebarScript .= "
    225307            var touchstartX = 0;
     
    227309            var touchendX = 0;
    228310            var touchendY = 0;
    229             var deltaY = 45;
     311            var deltaY = 60;
    230312            var deltaX = 10;
    231313            var isSwiped;
     
    235317                touchstartX = event.changedTouches[0].screenX;
    236318                touchstartY = event.changedTouches[0].screenY;
    237                 event.path.forEach(function(element) {     
    238                     if(element.classList.contains('widget_price_filter')){
    239                         isSwiped = false;
    240                     }
    241                 });
     319               
     320               if(findAncestor (event.target, 'widget_price_filter') != null){
     321               isSwiped = false;
     322               };
     323               
    242324             
    243325            }, false);
     
    256338                    if (touchendX < touchstartX && distanceY <= deltaY && distanceX >= deltaX) {   
    257339                        if(isSwiped){
    258                               wr.classList.remove(openedClass);
    259                         btn.classList.remove(openedClass);
     340                             closeMobileSidebar();
    260341                        }
    261342                    }
    262                     if (touchendX > touchstartX && distanceY <= deltaY && distanceX >= deltaX) {  
    263                          if(isSwiped){
    264                         wr.classList.add(openedClass);
    265                         btn.classList.add(openedClass);
    266                         }
     343                    if (touchendX > touchstartX && distanceY <= deltaY && distanceX >= deltaX) {
     344                     
     345                         if(isSwiped && touchstartX < 40){
     346                            openMobileSidebar();
     347                         }
    267348                    }     
    268349                }";
  • responsive-sidebar/trunk/src/ResponsiveSidebarPlugin.php

    r2290403 r2291595  
    1414class ResponsiveSidebarPlugin {
    1515
    16     const VERSION = '1.1.1';
     16    const VERSION = '1.2.0';
    1717
    1818    /**
     
    6464        $options['maxWidth'] = Settings::MAX_WIDTH;
    6565        $options['sidebarSwipe'] = Settings::SIDEBAR_SWIPE;
     66        $options['sidebars'] = array();
    6667        update_option(Settings::OPTIONS, $options);
    6768    }
  • responsive-sidebar/trunk/views/admin/section/main-settings.php

    r2032048 r2291595  
    66
    77use  ResponsiveSidebar\Admin\Settings;
     8
     9
     10$sidebarsWidgets = wp_get_sidebars_widgets();
     11global $wp_registered_sidebars;
     12
    813
    914echo '<h3>'.__('Appearance settings', 'responsive-sidebar').' <a href="' .
     
    2631
    2732    <tr>
    28         <th scope="row"><?php _e('Responsive sidebar id','responsive-sidebar') ?></th>
     33        <th scope="row"><?php _e('Select a sidebar','responsive-sidebar') ?></th>
     34        <td>
     35            <?php
     36
     37            foreach ($sidebarsWidgets as $key => $sidebar) {
     38                if(!empty($sidebar) && $key != 'wp_inactive_widgets'){ ?>
     39                    <label>
     40                        <input type="checkbox" name="<?php echo Settings::OPTIONS; ?>[sidebars][]" value="<?= $key; ?>" <?= array_search($key, $sidebars) !== false?'checked':''; ?>>
     41                        <?= $wp_registered_sidebars[$key]['name']; ?>
     42                    </label><br>
     43                    <p><?= $wp_registered_sidebars[$key]['description']; ?></p><br>
     44               <?php }
     45
     46            }
     47            ?>
     48        </td>
     49    </tr>
     50
     51    <tr>
     52        <th scope="row"><?php _e('Or enter the ID of the sidebar','responsive-sidebar') ?></th>
    2953        <td>
    3054            <input type="text"  name="<?=Settings::OPTIONS?>[cssClasses]" size="26" value="<?php echo esc_attr( $cssClasses ) ?>" />
Note: See TracChangeset for help on using the changeset viewer.