From c2bf5d2637c690085b6591ce2755f8b7bdf8b52d Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 6 Oct 2016 01:20:33 +0200 Subject: [PATCH 001/124] First try to fix issues with smoothscroll and mobile browsers - See https://github.com/adchsm/Slidebars/pull/257 - See https://www.adchsm.com/slidebars/help/advanced-usage/scrolling-the-html-or-body-elements/ - See https://wordpress.org/support/topic/conflict-with-off-canvas-sidebars/ - Addresses scroll lock aswell --- css/off-canvas-sidebars.css | 21 ++++++++++++++++++++- js/off-canvas-sidebars.js | 14 +++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/css/off-canvas-sidebars.css b/css/off-canvas-sidebars.css index 77ec34d..d3ec399 100644 --- a/css/off-canvas-sidebars.css +++ b/css/off-canvas-sidebars.css @@ -3,9 +3,28 @@ * * @author Jory Hogeveen * @package off-canvas-sidebars - * @version 0.3 + * @version 0.3.2 */ +/** + * Slidebar CSS overwrites + */ + +html, +.ocs-initialized html { + overflow-y: auto; + height: auto; +} +[canvas=container], +.ocs-initialized [canvas=container] { + overflow-y: hidden; + height: auto; +} + +html.ocs-scroll-lock { + overflow-y: hidden; +} + /** * Sidebar Widths (patched from older version of Slidebars) */ diff --git a/js/off-canvas-sidebars.js b/js/off-canvas-sidebars.js index 6fa90b6..041fabc 100644 --- a/js/off-canvas-sidebars.js +++ b/js/off-canvas-sidebars.js @@ -4,7 +4,7 @@ * ocsOffCanvasSidebars * @author Jory Hogeveen * @package off-canvas-sidebars - * @version 0.3 + * @version 0.3.2 * @global ocsOffCanvasSidebars */ @@ -23,10 +23,14 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { ocsOffCanvasSidebars.slidebarsController = false; ocsOffCanvasSidebars.useAttributeSettings = false; + ocsOffCanvasSidebars.container = false; + ocsOffCanvasSidebars._html = $( 'html' ); ocsOffCanvasSidebars._touchmove = false; ocsOffCanvasSidebars.init = function() { + ocsOffCanvasSidebars.container = $( '[canvas=container]' ); + /** * Function call before initializing * @since 0.3 @@ -44,6 +48,8 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { // Initialize slidebars ocsOffCanvasSidebars.slidebarsController.init(); + ocsOffCanvasSidebars._html.addClass('ocs-initialized'); + /** * Function call after initializing * @since 0.3 @@ -255,11 +261,17 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { // Add close class to canvas container when Slidebar is opened $( controller.events ).on( 'opening', function () { $( '[canvas]' ).addClass( prefix + '-close-any' ); + ocsOffCanvasSidebars._html.addClass( 'ocs-sidebar-active' ); + if ( ocsOffCanvasSidebars._getSetting( 'scroll_lock' ) ) { + ocsOffCanvasSidebars._html.addClass( 'ocs-scroll-lock' ); + } } ); // Add close class to canvas container when Slidebar is opened $( controller.events ).on( 'closing', function () { $( '[canvas]' ).removeClass( prefix + '-close-any' ); + ocsOffCanvasSidebars._html.removeClass( 'ocs-sidebar-active' ); + ocsOffCanvasSidebars._html.removeClass( 'ocs-scroll-lock' ); } ); From b86950f3d808ae79ab001cb662f7abd4b7a979ce Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 6 Oct 2016 19:02:06 +0200 Subject: [PATCH 002/124] Start creating a legacy CSS option for Slidebars --- .../off-canvas-sidebars-frontend.class.php | 3 +- .../off-canvas-sidebars-settings.class.php | 42 +++++++++++++++++-- off-canvas-sidebars.php | 2 +- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/includes/off-canvas-sidebars-frontend.class.php b/includes/off-canvas-sidebars-frontend.class.php index 9b3c847..a917ed9 100644 --- a/includes/off-canvas-sidebars-frontend.class.php +++ b/includes/off-canvas-sidebars-frontend.class.php @@ -351,11 +351,12 @@ function add_styles_scripts() { 'disable_over' => ( $this->general_settings['disable_over'] ) ? (int) $this->general_settings['disable_over'] : false, 'hide_control_classes' => ( $this->general_settings['hide_control_classes'] ) ? true : false, 'scroll_lock' => ( $this->general_settings['scroll_lock'] ) ? true : false, + 'legacy_css' => ( 'legacy-css' == $this->general_settings['compatibility_position_fixed'] ) ? true : false, 'css_prefix' => $this->general_settings['css_prefix'], 'sidebars' => $this->general_settings['sidebars'] ) ); - if ( true === (bool) $this->general_settings['compatibility_position_fixed'] ) { + if ( 'custom-js' == $this->general_settings['compatibility_position_fixed'] ) { wp_enqueue_script( 'ocs-fixed-scrolltop', OCS_PLUGIN_URL . 'js/fixed-scrolltop.js', array( 'jquery' ), $version, true ); } diff --git a/includes/off-canvas-sidebars-settings.class.php b/includes/off-canvas-sidebars-settings.class.php index 0799753..61324cf 100644 --- a/includes/off-canvas-sidebars-settings.class.php +++ b/includes/off-canvas-sidebars-settings.class.php @@ -268,12 +268,31 @@ function register_general_settings() { add_settings_field( 'compatibility_position_fixed', esc_attr__( 'Compatibility for fixed elements', 'off-canvas-sidebars' ), - array( $this, 'checkbox_option' ), + array( $this, 'radio_option' ), $this->settings_tab, 'section_general', array( 'name' => 'compatibility_position_fixed', - 'label' => '('.__( 'Experimental', 'off-canvas-sidebars' ).')' + 'default' => 'none', + 'options' => array( + 'none' => array( + 'name' => 'none', + 'label' => __( 'No', 'off-canvas-sidebars' ), + 'value' => 'none' + ), + 'legacy-css' => array( + 'name' => 'legacy-css', + 'label' => __( 'Legacy CSS solution', 'off-canvas-sidebars' ) . ' (' . __( 'Use basic CSS positioning instead of CSS3 transform with hardware acceleration', 'off-canvas-sidebars' ) . ')', + 'value' => 'legacy-css', + 'description' => __( 'This is your best option if your site uses sticky menus and/or other fixed elements within the site container.', 'off-canvas-sidebars' ) + ), + 'custom-js' => array( + 'name' => 'custom-js', + 'label' => __( 'JavaScript solution', 'off-canvas-sidebars' ) . ' ('.__( 'Experimental', 'off-canvas-sidebars' ).')', + 'value' => 'custom-js', + 'description' => __( 'While still in development, this could fix compatibility issues with fixed elements.', 'off-canvas-sidebars' ) + ) + ), ) ); } @@ -678,6 +697,7 @@ function radio_option( $args ) {
+

@@ -868,7 +888,6 @@ function validate_input( $input ) { $output['hide_control_classes'] = $this->validate_checkbox( $output['hide_control_classes'] ); $output['scroll_lock'] = $this->validate_checkbox( $output['scroll_lock'] ); $output['use_fastclick'] = $this->validate_checkbox( $output['use_fastclick'] ); - $output['compatibility_position_fixed'] = $this->validate_checkbox( $output['compatibility_position_fixed'] ); // Numeric values (not integers!) $output['disable_over'] = $this->validate_numeric( $output['disable_over'] ); @@ -880,6 +899,9 @@ function validate_input( $input ) { // Attribute validation $output['css_prefix'] = $this->validate_id( $output['css_prefix'] ); + // Validate radio options + $output['compatibility_position_fixed'] = $this->validate_radio( $output['compatibility_position_fixed'], array( 'none', 'custom-js', 'legacy-css' ), 'none' ); + // Set default values if no value is set if ( empty( $output['css_prefix'] ) ) { $output['css_prefix'] = 'ocs'; @@ -968,6 +990,20 @@ function validate_checkbox( $value ) { return ( ! empty( $value ) && $value == 1 ) ? (int) strip_tags( $value ) : 0; } + /** + * Validates radio values against the possible options + * + * @since 0.3.2 + * + * @param string $value + * @param array $options + * @param string $default + * @return int $value + */ + function validate_radio( $value, $options, $default ) { + return ( ! empty( $value ) && in_array( $value, $options ) ) ? strip_tags( $value ) : $default; + } + /** * Validates id values, used by validate_input * diff --git a/off-canvas-sidebars.php b/off-canvas-sidebars.php index 5d32032..67c163c 100644 --- a/off-canvas-sidebars.php +++ b/off-canvas-sidebars.php @@ -140,7 +140,7 @@ final class OCS_Off_Canvas_Sidebars 'website_before_hook' => 'website_before', 'website_after_hook' => 'website_after', 'use_fastclick' => 0, - 'compatibility_position_fixed' => 0, + 'compatibility_position_fixed' => 'none', 'css_prefix' => 'ocs', 'sidebars' => array(), ); From d4a9f0941fe127bc1c640170b30b2960e9d84fdf Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 6 Oct 2016 19:02:28 +0200 Subject: [PATCH 003/124] Bugfix - updating settings checkboxes didn't work --- includes/off-canvas-sidebars-settings.class.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/includes/off-canvas-sidebars-settings.class.php b/includes/off-canvas-sidebars-settings.class.php index 61324cf..7363d4e 100644 --- a/includes/off-canvas-sidebars-settings.class.php +++ b/includes/off-canvas-sidebars-settings.class.php @@ -821,6 +821,14 @@ function validate_input( $input ) { } unset( $input['sidebars']['ocs_add_new'] ); + if ( $_POST['ocs_tab'] == $this->settings_tab ) { + $input[ 'enable_frontend' ] = ( ! empty ( $input[ 'enable_frontend' ] ) ) ? 1 : 0; + $input[ 'site_close' ] = ( ! empty ( $input[ 'site_close' ] ) ) ? 1 : 0; + $input[ 'hide_control_classes' ] = ( ! empty ( $input[ 'hide_control_classes' ] ) ) ? 1 : 0; + $input[ 'scroll_lock' ] = ( ! empty ( $input[ 'scroll_lock' ] ) ) ? 1 : 0; + $input[ 'use_fastclick' ] = ( ! empty ( $input[ 'use_fastclick' ] ) ) ? 1 : 0; + } + // Handle existing sidebars if ( isset( $input['sidebars'] ) ) { From 262bb3a5d31c803c5c1193dba42804cba18ad0b7 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 6 Oct 2016 19:02:54 +0200 Subject: [PATCH 004/124] Update ocs sidebar content value to use validate_radio() --- includes/off-canvas-sidebars-settings.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/off-canvas-sidebars-settings.class.php b/includes/off-canvas-sidebars-settings.class.php index 7363d4e..00c820f 100644 --- a/includes/off-canvas-sidebars-settings.class.php +++ b/includes/off-canvas-sidebars-settings.class.php @@ -936,8 +936,8 @@ function validate_input( $input ) { $output['sidebars'][ $sidebar_id ]['disable_over'] = $this->validate_numeric( $output['sidebars'][ $sidebar_id ]['disable_over'] ); $output['sidebars'][ $sidebar_id ]['animation_speed'] = $this->validate_numeric( $output['sidebars'][ $sidebar_id ]['animation_speed'] ); - // Validate content value + set to default of not valid - $output['sidebars'][ $sidebar_id ]['content'] = ( ! empty( $output['sidebars'][ $sidebar_id ]['content'] ) && in_array( $output['sidebars'][ $sidebar_id ]['content'], array( 'sidebar', 'menu', 'action' ) ) ) ? $output['sidebars'][ $sidebar_id ]['content'] : 'sidebar'; + // Validate radio options + $output['sidebars'][ $sidebar_id ]['content'] = $this->validate_radio( $output['sidebars'][ $sidebar_id ]['content'], array( 'sidebar', 'menu', 'action' ), 'sidebar' ); $new_sidebar_id = $this->validate_id( $sidebar_id ); if ( $sidebar_id != $new_sidebar_id ) { From a100c85e340e3572f46e2374934278dfdad113e1 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 6 Oct 2016 19:04:41 +0200 Subject: [PATCH 005/124] Prepare Slidebars for legacy mode --- slidebars/slidebars.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/slidebars/slidebars.js b/slidebars/slidebars.js index 25bf225..5df6f0d 100644 --- a/slidebars/slidebars.js +++ b/slidebars/slidebars.js @@ -15,7 +15,7 @@ var slidebars; (function($) { - + slidebars = function () { /** @@ -28,6 +28,9 @@ slidebars = function () { // Object of Slidebars offCanvas = {}, + // Create reference to this object for use in functions + self = this, + // Variables, permitted sides and styles init = false, registered = false, @@ -103,6 +106,8 @@ slidebars = function () { * Initialization */ + this.legacy = false; + this.init = function ( callback ) { // Check if Slidebars has been initialized if ( init ) { From cc09aa6f58c70fe36893fd794d22d142c2b93eda Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 6 Oct 2016 19:05:46 +0200 Subject: [PATCH 006/124] Add legacy CSS functionality to the Slidebars library --- slidebars/slidebars.js | 84 +++++++++++++++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 13 deletions(-) diff --git a/slidebars/slidebars.js b/slidebars/slidebars.js index 5df6f0d..75f217d 100644 --- a/slidebars/slidebars.js +++ b/slidebars/slidebars.js @@ -10,6 +10,8 @@ /*! * Modified by: Jory Hogeveen + * + * @since 0.3.2 Add score for this reference + Add legacy CSS support (no hardware acceleration) */ var slidebars; @@ -58,14 +60,26 @@ slidebars = function () { // Amount to animate if ( offCanvas[ id ].active ) { - if ( offCanvas[ id ].side === 'top' ) { - amount = '0px, ' + offCanvas[ id ].element.css( 'height' ); - } else if ( offCanvas[ id ].side === 'right' ) { - amount = '-' + offCanvas[ id ].element.css( 'width' ) + ', 0px'; - } else if ( offCanvas[ id ].side === 'bottom' ) { - amount = '0px, -' + offCanvas[ id ].element.css( 'height' ); - } else if ( offCanvas[ id ].side === 'left' ) { - amount = offCanvas[ id ].element.css( 'width' ) + ', 0px'; + if ( self.legacy ) { + if ( offCanvas[ id ].side === 'top' ) { + amount = offCanvas[ id ].element.css( 'height' ); + } else if ( offCanvas[ id ].side === 'right' ) { + amount = offCanvas[ id ].element.css( 'width' ); + } else if ( offCanvas[ id ].side === 'bottom' ) { + amount = offCanvas[ id ].element.css( 'height' ); + } else if ( offCanvas[ id ].side === 'left' ) { + amount = offCanvas[ id ].element.css( 'width' ); + } + } else { + if ( offCanvas[ id ].side === 'top' ) { + amount = '0px, ' + offCanvas[ id ].element.css( 'height' ); + } else if ( offCanvas[ id ].side === 'right' ) { + amount = '-' + offCanvas[ id ].element.css( 'width' ) + ', 0px'; + } else if ( offCanvas[ id ].side === 'bottom' ) { + amount = '0px, -' + offCanvas[ id ].element.css( 'height' ); + } else if ( offCanvas[ id ].side === 'left' ) { + amount = offCanvas[ id ].element.css( 'width' ) + ', 0px'; + } } } @@ -250,10 +264,33 @@ slidebars = function () { var animationProperties = getAnimationProperties( id ); // Apply css - animationProperties.elements.css( { - 'transition-duration': animationProperties.duration + 'ms', - 'transform': 'translate(' + animationProperties.amount + ')' - } ); + var css = { 'transition-duration': animationProperties.duration + 'ms' }; + + if ( self.legacy ) { + css[ offCanvas[ id ].side ] = animationProperties.amount; + + var canvasSide; + if ( offCanvas[ id ].side == 'right' || offCanvas[ id ].side == 'bottom' ) { + // Bottom and Right animation for slidebars and the container are not the same + if ( offCanvas[ id ].side == 'right' ) { + canvasSide = 'left'; + } else if ( offCanvas[ id ].side == 'bottom' ) { + canvasSide = 'top'; + } + // Move container + canvas.css( 'transition-duration', animationProperties.duration + 'ms' ); + canvas.css( canvasSide, '-' + animationProperties.amount ); + // Open slidebar + animationProperties.elements.not( canvas ).css( css ); + } else { + // Top and Left sides can use the same css as all other elements. + animationProperties.elements.css( css ); + } + + } else { + css.transform = 'translate(' + animationProperties.amount + ')'; + animationProperties.elements.css( css ); + } // Transition completed setTimeout( function () { @@ -309,7 +346,28 @@ slidebars = function () { var animationProperties = getAnimationProperties( id ); // Apply css - animationProperties.elements.css( 'transform', '' ); + if ( self.legacy ) { + + var canvasSide; + if ( offCanvas[ id ].side == 'right' || offCanvas[ id ].side == 'bottom' ) { + // Bottom and Right animation for slidebars and the container are not the same + if ( offCanvas[ id ].side == 'right' ) { + canvasSide = 'left'; + } else if ( offCanvas[ id ].side == 'bottom' ) { + canvasSide = 'top'; + } + // Reset container + canvas.css( canvasSide, '' ); + // Close slidebar + animationProperties.elements.not( canvas ).css( offCanvas[ id ].side, '' ); + } else { + // Top and Left sides can use the same css as all other elements. + animationProperties.elements.css( offCanvas[ id ].side, '' ); + } + + } else { + animationProperties.elements.css( 'transform', '' ); + } // Transition completetion setTimeout( function () { From 81aeec1745dd0730089d18e72876e254e9cd4a24 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 6 Oct 2016 19:06:45 +0200 Subject: [PATCH 007/124] New private function: _getTranslateAxis() to get the pixel values from the `transform` attribute --- js/off-canvas-sidebars.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/js/off-canvas-sidebars.js b/js/off-canvas-sidebars.js index 041fabc..3d50990 100644 --- a/js/off-canvas-sidebars.js +++ b/js/off-canvas-sidebars.js @@ -130,6 +130,33 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { return false; }; + ocsOffCanvasSidebars._getTranslateAxis = function( obj, axis ) { + obj = $( obj ); + var transformMatrix = obj.css("-webkit-transform") || + obj.css("-moz-transform") || + obj.css("-ms-transform") || + obj.css("-o-transform") || + obj.css("transform"); + if ( transformMatrix ) { + var matrix = transformMatrix.replace(/[^0-9\-.,]/g, '').split(','); + var val = false; + switch ( axix ) { + case 'x': + val = matrix[12] || matrix[4]; //translate x + break; + case 'y': + val = matrix[13] || matrix[5]; //translate y + break; + case 'z': + val = matrix[14] || matrix[6]; //translate z + break; + } + return parseFloat( val ); + } else { + return 0; + } + }; + // Prevent swipe events to be seen as a click (bug in some browsers) $( document ).on( 'touchmove', function() { ocsOffCanvasSidebars._touchmove = true; From 894eeeafb0a5ef7ca08b5e02c9d1c1efa2e6a0bf Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 6 Oct 2016 19:08:54 +0200 Subject: [PATCH 008/124] Add ocs-scroll-lock class handling --- js/off-canvas-sidebars.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/off-canvas-sidebars.js b/js/off-canvas-sidebars.js index 3d50990..f1cc5c1 100644 --- a/js/off-canvas-sidebars.js +++ b/js/off-canvas-sidebars.js @@ -289,7 +289,7 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { $( controller.events ).on( 'opening', function () { $( '[canvas]' ).addClass( prefix + '-close-any' ); ocsOffCanvasSidebars._html.addClass( 'ocs-sidebar-active' ); - if ( ocsOffCanvasSidebars._getSetting( 'scroll_lock' ) ) { + if ( ocsOffCanvasSidebars._getSetting( 'scroll_lock', false ) ) { ocsOffCanvasSidebars._html.addClass( 'ocs-scroll-lock' ); } } ); @@ -297,8 +297,7 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { // Add close class to canvas container when Slidebar is opened $( controller.events ).on( 'closing', function () { $( '[canvas]' ).removeClass( prefix + '-close-any' ); - ocsOffCanvasSidebars._html.removeClass( 'ocs-sidebar-active' ); - ocsOffCanvasSidebars._html.removeClass( 'ocs-scroll-lock' ); + ocsOffCanvasSidebars._html.removeClass( 'ocs-sidebar-active ocs-scroll-lock' ); } ); @@ -327,7 +326,8 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { // Disable scrolling on active sidebar $( '#' + prefix + '-site' ).on( 'scroll touchmove mousewheel', function( e ) { - if ( ocsOffCanvasSidebars._getSetting( 'scroll_lock' ) && false != controller.getActiveSlidebar() ) { + //if ( ocsOffCanvasSidebars._getSetting( 'scroll_lock' ) && false != controller.getActiveSlidebar() ) { + if ( ocsOffCanvasSidebars._html.hasClass( 'ocs-scroll-lock' ) ) { e.preventDefault(); e.stopPropagation(); return false; From 9a514d74dac7bc14a10d377ce2404340f5875b86 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 6 Oct 2016 19:09:26 +0200 Subject: [PATCH 009/124] Improve sidebarId check --- js/off-canvas-sidebars.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/js/off-canvas-sidebars.js b/js/off-canvas-sidebars.js index f1cc5c1..9c4f598 100644 --- a/js/off-canvas-sidebars.js +++ b/js/off-canvas-sidebars.js @@ -82,13 +82,17 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { * Internal function, do not overwrite * @since 0.3 + * @param key the setting key to look for + * @param sidebarId bool|null|string false = check for an active slidebar, null or no value = only the global setting */ ocsOffCanvasSidebars._getSetting = function( key, sidebarId ) { var overwrite, setting; var prefix = ocsOffCanvasSidebars.css_prefix; - if ( ! sidebarId ) { - sidebarId = ocsOffCanvasSidebars.slidebarsController.getActiveSlidebar(); + if ( typeof sidebarId != 'undefined' ) { + if ( ! sidebarId && null !== sidebarId ) { + sidebarId = ocsOffCanvasSidebars.slidebarsController.getActiveSlidebar(); + } } if ( sidebarId ) { From 1f8663e35db417fa6b7de2f011999974d20ccadd Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 6 Oct 2016 19:12:10 +0200 Subject: [PATCH 010/124] Move Slidebars init --- js/off-canvas-sidebars.js | 59 ++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/js/off-canvas-sidebars.js b/js/off-canvas-sidebars.js index 9c4f598..01fa12d 100644 --- a/js/off-canvas-sidebars.js +++ b/js/off-canvas-sidebars.js @@ -29,35 +29,6 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { ocsOffCanvasSidebars.init = function() { - ocsOffCanvasSidebars.container = $( '[canvas=container]' ); - - /** - * Function call before initializing - * @since 0.3 - */ - if ( typeof ocsBeforeInitHook == 'function' ) { - ocsBeforeInitHook(); - } - - // Slidebars constructor - ocsOffCanvasSidebars.slidebarsController = new slidebars(); - - if ( false === ocsOffCanvasSidebars.slidebarsController ) { - return; - } - // Initialize slidebars - ocsOffCanvasSidebars.slidebarsController.init(); - - ocsOffCanvasSidebars._html.addClass('ocs-initialized'); - - /** - * Function call after initializing - * @since 0.3 - */ - if ( typeof ocsAfterInitHook == 'function' ) { - ocsAfterInitHook(); - } - /** * Validate the disable_over setting ( using _getSetting() ) @@ -161,6 +132,36 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { } }; + ocsOffCanvasSidebars.container = $( '[canvas=container]' ); + + /** + * Function call before initializing + * @since 0.3 + */ + if ( typeof ocsBeforeInitHook == 'function' ) { + ocsBeforeInitHook(); + } + + // Slidebars constructor + ocsOffCanvasSidebars.slidebarsController = new slidebars(); + + if ( false === ocsOffCanvasSidebars.slidebarsController ) { + return; + } + + // Initialize slidebars + ocsOffCanvasSidebars.slidebarsController.init(); + + ocsOffCanvasSidebars._html.addClass('ocs-initialized'); + + /** + * Function call after initializing + * @since 0.3 + */ + if ( typeof ocsAfterInitHook == 'function' ) { + ocsAfterInitHook(); + } + // Prevent swipe events to be seen as a click (bug in some browsers) $( document ).on( 'touchmove', function() { ocsOffCanvasSidebars._touchmove = true; From 4bf907472ed4f01926ae5d4256a7f660f1ea844c Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 6 Oct 2016 19:12:30 +0200 Subject: [PATCH 011/124] Set the legacy_css attribute in out global JS object and in Slidebars --- js/off-canvas-sidebars.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/js/off-canvas-sidebars.js b/js/off-canvas-sidebars.js index 01fa12d..8302e18 100644 --- a/js/off-canvas-sidebars.js +++ b/js/off-canvas-sidebars.js @@ -14,6 +14,7 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { "disable_over": false, "hide_control_classes": false, "scroll_lock": false, + "legacy_css": false, "css_prefix": 'ocs', "sidebars": {} }; @@ -149,6 +150,12 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { return; } + // Legacy CSS mode? + if ( ocsOffCanvasSidebars.legacy_css ) { + ocsOffCanvasSidebars.slidebarsController.legacy = true; + ocsOffCanvasSidebars._html.addClass('ocs-legacy'); + } + // Initialize slidebars ocsOffCanvasSidebars.slidebarsController.init(); From 7f4762cdbfe52184c9ca99fc3f6adcbc497f1536 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 6 Oct 2016 19:14:14 +0200 Subject: [PATCH 012/124] Improve the target and positioning mechanism for scrollTop() --- js/fixed-scrolltop.js | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/js/fixed-scrolltop.js b/js/fixed-scrolltop.js index a2585bd..b1ea84e 100644 --- a/js/fixed-scrolltop.js +++ b/js/fixed-scrolltop.js @@ -16,43 +16,49 @@ } var curScrollTopElements; - var ocs_site = $('#' + prefix + '-site'); + var scrollTarget = ocs_site = $('#' + prefix + '-site'); + if ( 'auto' != ocs_site.css('overflow-y') ) { + scrollTarget = $( window ); + } if ( ocs_site.css('transform') != 'none' ) { curScrollTopElements = $('#' + prefix + '-site *').filter( function(){ return $(this).css('position') === 'fixed'; } ); ocsScrollTopFixed(); - ocs_site.on('scroll resize', function() { + scrollTarget.on('scroll resize', function() { var newScrollTopElements = $('#' + prefix + '-site *').filter( function(){ return $(this).css('position') === 'fixed'; } ); - curScrollTopElements = curScrollTopElements.add(newScrollTopElements); + curScrollTopElements = curScrollTopElements.add( newScrollTopElements ); ocsScrollTopFixed(); - }); + } ); } function ocsScrollTopFixed() { if ( curScrollTopElements.length > 0 ) { - var scrollTop = ocs_site.scrollTop(); - var winHeight = $(window).height(); - var conOffset = ocs_site.offset(); - var conHeight = ocs_site.outerHeight(); + var scrollTop = scrollTarget.scrollTop(), + winHeight = $(window).height(), + gblOffset = $('body').offset(), + conOffset = ocs_site.offset(), + conHeight = ocs_site.outerHeight(); curScrollTopElements.each( function() { if ( $(this).css('position') == 'fixed' ) { - var top = $(this).css('top'); - var bottom = $(this).css('bottom'); - var px; + var top = $(this).css('top'), + bottom = $(this).css('bottom'), + px; if ( top == 'auto' && bottom != 'auto' ) { - px = ( scrollTop + winHeight ) - ( conOffset.top + conHeight ); + px = ( scrollTop + winHeight ) - ( conOffset.top + conHeight ) + gblOffset.top; } else { - px = scrollTop - conOffset.top; + px = scrollTop - conOffset.top + gblOffset.top; } $(this).css({ - '-webkit-transform': 'translateY(' + px + 'px)', - '-moz-transform': 'translateY(' + px + 'px)', - 'transform': 'translateY(' + px + 'px)' + '-webkit-transform': 'translate( 0px, ' + px + 'px )', + '-moz-transform': 'translate( 0px, ' + px + 'px )', + '-o-transform': 'translate( 0px, ' + px + 'px )', + 'transform': 'translate( 0px, ' + px + 'px )' }); } else { $(this).css({ '-webkit-transform' : '', '-moz-transform' : '', + '-o-transform' : '', 'transform' : '' }); } From d98ee53db491a131a7a6e64dba5e67967dfab1bb Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 6 Oct 2016 19:15:23 +0200 Subject: [PATCH 013/124] Check for an active top sidebar and add it to the calculation if active --- js/fixed-scrolltop.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/js/fixed-scrolltop.js b/js/fixed-scrolltop.js index b1ea84e..e4a2c3a 100644 --- a/js/fixed-scrolltop.js +++ b/js/fixed-scrolltop.js @@ -38,6 +38,16 @@ gblOffset = $('body').offset(), conOffset = ocs_site.offset(), conHeight = ocs_site.outerHeight(); + + var activeSidebar = ocsOffCanvasSidebars.slidebarsController.getActiveSlidebar(); + if ( activeSidebar ) { + var sidebar = ocsOffCanvasSidebars.slidebarsController.getSlidebar( activeSidebar ); + if ( sidebar.side == 'top' ) { + gblOffset.top += sidebar.element.height(); + } else if ( sidebar.side == 'top' ) { + gblOffset.top -= sidebar.element.height(); + } + } curScrollTopElements.each( function() { if ( $(this).css('position') == 'fixed' ) { var top = $(this).css('top'), From aa40ac9e6d040a762b0fb60d67790808e0d6bedd Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 6 Oct 2016 19:17:17 +0200 Subject: [PATCH 014/124] Fix position issues for fixed elements on slidebar animations in legacy CSS mode --- js/off-canvas-sidebars.js | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/js/off-canvas-sidebars.js b/js/off-canvas-sidebars.js index 8302e18..e27587c 100644 --- a/js/off-canvas-sidebars.js +++ b/js/off-canvas-sidebars.js @@ -161,6 +161,53 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { ocsOffCanvasSidebars._html.addClass('ocs-initialized'); + /** + * Fix position issues for fixed elements on slidebar animations + * @since 0.3.2 + */ + $( ocsOffCanvasSidebars.slidebarsController.events ).on( 'opening opened closing closed', function( e, sidebar_id ) { + var slidebar = ocsOffCanvasSidebars.slidebarsController.getSlidebar( sidebar_id ); + var duration = parseFloat( slidebar.element.css( 'transitionDuration' ), 10 ) * 1000; + if ( slidebar.side == 'top' || slidebar.side == 'bottom' ) { + var elements = $('#' + ocsOffCanvasSidebars.css_prefix + '-site *').filter( function(){ return $(this).css('position') === 'fixed'; } ); + elements.attr( { 'canvas-fixed': 'fixed' } ); + + // Legacy mode (only needed for location: top) + if ( ocsOffCanvasSidebars.legacy_css && slidebar.side == 'top' && slidebar.style != 'overlay' ) { + var offset; + if ( slidebar.style == 'reveal' ) { + offset = 0; //parseInt( slidebar.element.css( 'height' ).replace('px', '') ); + } else { + offset = parseInt( slidebar.element.css( 'margin-top' ).replace('px', '').replace('-', '') ); + } + elements.each( function() { + // Set animation + if ( e.type == 'opening' ) { + $(this).css( { + '-webkit-transition': 'top ' + duration + 'ms', + '-moz-transition': 'top ' + duration + 'ms', + '-o-transition': 'top ' + duration + 'ms', + 'transition': 'top ' + duration + 'ms' + } ); + $(this).css('top', parseInt( $(this).css('top').replace('px', '') ) + offset + 'px' ); + } + // Remove animation + else if ( e.type == 'closing') { + $(this).css('top', parseInt( $(this).css('top').replace('px', '') ) - offset + 'px' ); + setTimeout( function() { + $(this).css( { + '-webkit-transition': '', + '-moz-transition': '', + '-o-transition': '', + 'transition': '' + } ); + }, duration ); + } + } ); + } + } + } ); + /** * Function call after initializing * @since 0.3 From bf3b099b006a97b3bccea6ee775cfa8467c9c643 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 6 Oct 2016 19:18:02 +0200 Subject: [PATCH 015/124] Fix position issues for fixed elements on slidebar animations in fixed-scrolltop-fix mode --- js/fixed-scrolltop.js | 21 +++++++++++++++++++++ js/off-canvas-sidebars.js | 24 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/js/fixed-scrolltop.js b/js/fixed-scrolltop.js index e4a2c3a..28eb214 100644 --- a/js/fixed-scrolltop.js +++ b/js/fixed-scrolltop.js @@ -29,6 +29,27 @@ curScrollTopElements = curScrollTopElements.add( newScrollTopElements ); ocsScrollTopFixed(); } ); + scrollTarget.on('slidebar_event', ocsSlidebarEventFixed ); + } + + function ocsSlidebarEventFixed( e, eventType, slidebar ) { + if ( ( eventType == 'opened' || eventType == 'closed' ) && ( slidebar.side == 'bottom' ) ) { //slidebar.side == 'top' || + curScrollTopElements.each( function() { + var px = ocsOffCanvasSidebars._getTranslateAxis( this, 'y' ); + var offset = slidebar.element.height(); + if ( eventType == 'opened' ) { + px += offset; + } else if ( eventType == 'closed' ) { + px -= offset; + } + $( this ).css( { + '-webkit-transform': 'translate( 0px, ' + px + 'px )', + '-moz-transform': 'translate( 0px, ' + px + 'px )', + '-o-transform': 'translate( 0px, ' + px + 'px )', + 'transform': 'translate( 0px, ' + px + 'px )' + } ); + } ); + } } function ocsScrollTopFixed() { diff --git a/js/off-canvas-sidebars.js b/js/off-canvas-sidebars.js index e27587c..5f70215 100644 --- a/js/off-canvas-sidebars.js +++ b/js/off-canvas-sidebars.js @@ -205,6 +205,30 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { } } ); } + // Normal mode (only sets a transition for use in fixed-scrolltop.js) + else { + elements.each( function() { + //var curVal = ocsOffCanvasSidebars._getTranslateAxis( this, 'y' ); + //console.log( curVal ); + if ( e.type == 'opening' || e.type == 'closing' ) { + $( this ).css( { + '-webkit-transition': 'transform ' + duration + 'ms', + '-moz-transition': 'transform ' + duration + 'ms', + '-o-transition': 'transform ' + duration + 'ms', + 'transition': 'transform ' + duration + 'ms' + } ); + //$(this).css('transform', 'translate( 0px, ' + curVal + slidebar.element.height() + 'px )' ); + } else if ( e.type == 'opened' || e.type == 'closed' ) { + $(this).css( { + '-webkit-transition': '', + '-moz-transition': '', + '-o-transition': '', + 'transition': '' + } ); + } + } ); + } + $(window).trigger( 'slidebar_event', [ e.type, slidebar ] ); } } ); From 3a9f0aeb3ab2879dd893ef1b38fabcb71f8a0e3b Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 6 Oct 2016 19:18:28 +0200 Subject: [PATCH 016/124] Fix CSS for legacy mode --- css/off-canvas-sidebars.css | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/css/off-canvas-sidebars.css b/css/off-canvas-sidebars.css index d3ec399..d2bd85c 100644 --- a/css/off-canvas-sidebars.css +++ b/css/off-canvas-sidebars.css @@ -25,6 +25,35 @@ html.ocs-scroll-lock { overflow-y: hidden; } +[canvas-fixed] { + -webkit-transform: translate( 0px, 0px ); + -ms-transform: translate( 0px, 0px ); + transform: translate( 0px, 0px ); + -webkit-backface-visibility: hidden; +} + +.ocs-legacy [canvas] {top: 0; right: 0; bottom: 0; left: 0;} +.ocs-legacy [canvas], +.ocs-legacy [off-canvas] { + -webkit-transform: none; + -moz-transform: none; + -ms-transform: none; + -o-transform: none; + transform: none; + -webkit-transition: transform 300ms, top 300ms, bottom 300ms, left 300ms, right 300ms; + -moz-transition: transform 300ms, top 300ms, bottom 300ms, left 300ms, right 300ms; + -ms-transition: transform 300ms, top 300ms, bottom 300ms, left 300ms, right 300ms; + -o-transition: transform 300ms, top 300ms, bottom 300ms, left 300ms, right 300ms; + transition: transform 300ms, top 300ms, bottom 300ms, left 300ms, right 300ms; +} +.ocs-legacy [canvas-fixed] { + -webkit-transform: none; + -moz-transform: none; + -ms-transform: none; + -o-transform: none; + transform: none; +} + /** * Sidebar Widths (patched from older version of Slidebars) */ From 00a9718ca2e1e4d91f3f57a22d6eab817a8abe44 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 6 Oct 2016 19:18:48 +0200 Subject: [PATCH 017/124] Fix swift style animation for legacy CSS mode --- slidebars/slidebars.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/slidebars/slidebars.js b/slidebars/slidebars.js index 75f217d..a812528 100644 --- a/slidebars/slidebars.js +++ b/slidebars/slidebars.js @@ -216,6 +216,17 @@ slidebars = function () { // Apply negative margins if ( offCanvas[ id ].style === 'push' || offCanvas[ id ].style === 'overlay' || offCanvas[ id ].style === 'shift' ) { offCanvas[ id ].element.css( 'margin-' + offCanvas[ id ].side, '-' + offset ); + + // Fix shift style locations for legacy mode (1.9 to fix minor px rendering issues) + if ( self.legacy && offCanvas[ id ].style === 'shift' ) { + var shiftPos; + if ( offCanvas[ id ].side == 'top' || offCanvas[ id ].side == 'bottom' ) { + shiftPos = offCanvas[ id ].element.height() / 1.9; + } else if ( offCanvas[ id ].side == 'left' || offCanvas[ id ].side == 'right' ) { + shiftPos = offCanvas[ id ].element.width() / 1.9; + } + offCanvas[ id ].element.css( offCanvas[ id ].side, shiftPos + 'px' ); + } } } } @@ -365,6 +376,17 @@ slidebars = function () { animationProperties.elements.css( offCanvas[ id ].side, '' ); } + // Fix shift style for legacy mode (1.9 to fix minor px rendering issues) + if ( offCanvas[ id ].style == 'shift' ) { + var shiftPos; + if ( offCanvas[ id ].side == 'top' || offCanvas[ id ].side == 'bottom' ) { + shiftPos = offCanvas[ id ].element.height() / 1.9; + } else if ( offCanvas[ id ].side == 'left' || offCanvas[ id ].side == 'right' ) { + shiftPos = offCanvas[ id ].element.width() / 1.9; + } + offCanvas[ id ].element.css( offCanvas[ id ].side, shiftPos + 'px' ); + } + } else { animationProperties.elements.css( 'transform', '' ); } From 6b8e4a2b9e71d0ed7854f1a209c836dab0676afb Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 6 Oct 2016 19:19:15 +0200 Subject: [PATCH 018/124] Add compatibility with the WP Admin Bar --- js/off-canvas-sidebars.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/js/off-canvas-sidebars.js b/js/off-canvas-sidebars.js index 5f70215..840c7f4 100644 --- a/js/off-canvas-sidebars.js +++ b/js/off-canvas-sidebars.js @@ -161,6 +161,26 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { ocsOffCanvasSidebars._html.addClass('ocs-initialized'); + /** + * Compatibility with WP Admin Bar + * @since 0.3.2 + */ + if ( $('body').hasClass('admin-bar') ) { + $( window ).on('load resize', function() { + var bodyOffset = $( 'body' ).offset(); + $( '.' + ocsOffCanvasSidebars.css_prefix + '-slidebar' ).each( function() { + // Top slidebars + if ( $(this).hasClass( 'ocs-location-top' ) ) { + $(this).css( 'margin-top', parseInt( $(this).css('margin-top').replace( 'px', '' ) ) + bodyOffset.top + 'px' ); + } + // Bottom slidebars + else if ( $(this).hasClass( 'ocs-location-left' ) || $(this).hasClass( 'ocs-location-right' ) ) { + $(this).css( 'margin-top', bodyOffset.top + 'px' ); + } + } ); + } ); + } + /** * Fix position issues for fixed elements on slidebar animations * @since 0.3.2 From 6ee1100f402b997d1764c20b0a6ff3a6e5716473 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 6 Oct 2016 19:19:54 +0200 Subject: [PATCH 019/124] Doc fixes --- includes/off-canvas-sidebars-settings.class.php | 5 +++-- off-canvas-sidebars.php | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/includes/off-canvas-sidebars-settings.class.php b/includes/off-canvas-sidebars-settings.class.php index 00c820f..fd6dda1 100644 --- a/includes/off-canvas-sidebars-settings.class.php +++ b/includes/off-canvas-sidebars-settings.class.php @@ -265,6 +265,7 @@ function register_general_settings() { 'description' => __( 'Devices with touch capability often have a 300ms delay on click triggers. FastClick is a JavaScript library purposely built to elimate the delay where neccesary.', 'off-canvas-sidebars' ) ) ); + add_settings_field( 'compatibility_position_fixed', esc_attr__( 'Compatibility for fixed elements', 'off-canvas-sidebars' ), @@ -991,8 +992,8 @@ function migrate_sidebars_widgets( $oldId, $newId ) { * * @since 0.1.2 * - * @param mixed $value - * @return int $value + * @param mixed $value + * @return int $value */ function validate_checkbox( $value ) { return ( ! empty( $value ) && $value == 1 ) ? (int) strip_tags( $value ) : 0; diff --git a/off-canvas-sidebars.php b/off-canvas-sidebars.php index 67c163c..8946526 100644 --- a/off-canvas-sidebars.php +++ b/off-canvas-sidebars.php @@ -510,7 +510,7 @@ private function db_update() { $settings = $this->general_settings; $db_version = strtolower( $settings['db_version'] ); - // Compare versions + // Upgrade to 0.2.x if ( version_compare( $db_version, '0.2', '<' ) ) { foreach ( $settings['sidebars'] as $sidebar_id => $sidebar_data ) { if ( empty( $sidebar_data['label'] ) ) { @@ -535,6 +535,8 @@ private function db_update() { } } } + + // Upgrade to 0.3.x if ( version_compare( $db_version, '0.3', '<' ) && version_compare( $db_version, '0', '>' ) ) { $settings['css_prefix'] = 'sb'; // Old Slidebars classes } From 68e2c5b75a2dfbaa60a5b16571185e0ea5d9ebb6 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 6 Oct 2016 19:30:03 +0200 Subject: [PATCH 020/124] Typo --- js/off-canvas-sidebars.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/off-canvas-sidebars.js b/js/off-canvas-sidebars.js index 840c7f4..211bb32 100644 --- a/js/off-canvas-sidebars.js +++ b/js/off-canvas-sidebars.js @@ -116,7 +116,7 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { if ( transformMatrix ) { var matrix = transformMatrix.replace(/[^0-9\-.,]/g, '').split(','); var val = false; - switch ( axix ) { + switch ( axis ) { case 'x': val = matrix[12] || matrix[4]; //translate x break; From 13b6e822384d7aaa5c1584e335dd71e98672946c Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 6 Oct 2016 23:08:30 +0200 Subject: [PATCH 021/124] Revert "Bugfix - updating settings checkboxes didn't work" This reverts commit d4a9f0941fe127bc1c640170b30b2960e9d84fdf. --- includes/off-canvas-sidebars-settings.class.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/includes/off-canvas-sidebars-settings.class.php b/includes/off-canvas-sidebars-settings.class.php index fd6dda1..6b34be6 100644 --- a/includes/off-canvas-sidebars-settings.class.php +++ b/includes/off-canvas-sidebars-settings.class.php @@ -822,14 +822,6 @@ function validate_input( $input ) { } unset( $input['sidebars']['ocs_add_new'] ); - if ( $_POST['ocs_tab'] == $this->settings_tab ) { - $input[ 'enable_frontend' ] = ( ! empty ( $input[ 'enable_frontend' ] ) ) ? 1 : 0; - $input[ 'site_close' ] = ( ! empty ( $input[ 'site_close' ] ) ) ? 1 : 0; - $input[ 'hide_control_classes' ] = ( ! empty ( $input[ 'hide_control_classes' ] ) ) ? 1 : 0; - $input[ 'scroll_lock' ] = ( ! empty ( $input[ 'scroll_lock' ] ) ) ? 1 : 0; - $input[ 'use_fastclick' ] = ( ! empty ( $input[ 'use_fastclick' ] ) ) ? 1 : 0; - } - // Handle existing sidebars if ( isset( $input['sidebars'] ) ) { From 16d3a5fcf14f832c6cca71e1b3bdde7102521afd Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 6 Oct 2016 23:10:01 +0200 Subject: [PATCH 022/124] compatibility_position_fixed is now a radio option --- includes/off-canvas-sidebars-settings.class.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/includes/off-canvas-sidebars-settings.class.php b/includes/off-canvas-sidebars-settings.class.php index ff7ca29..fd6dda1 100644 --- a/includes/off-canvas-sidebars-settings.class.php +++ b/includes/off-canvas-sidebars-settings.class.php @@ -823,12 +823,11 @@ function validate_input( $input ) { unset( $input['sidebars']['ocs_add_new'] ); if ( $_POST['ocs_tab'] == $this->settings_tab ) { - $input[ 'enable_frontend' ] = ( ! empty ( $input[ 'enable_frontend' ] ) ) ? 1 : 0; - $input[ 'site_close' ] = ( ! empty ( $input[ 'site_close' ] ) ) ? 1 : 0; - $input[ 'hide_control_classes' ] = ( ! empty ( $input[ 'hide_control_classes' ] ) ) ? 1 : 0; - $input[ 'scroll_lock' ] = ( ! empty ( $input[ 'scroll_lock' ] ) ) ? 1 : 0; - $input[ 'use_fastclick' ] = ( ! empty ( $input[ 'use_fastclick' ] ) ) ? 1 : 0; - $input[ 'compatibility_position_fixed' ] = ( ! empty ( $input[ 'compatibility_position_fixed' ] ) ) ? 1 : 0; + $input[ 'enable_frontend' ] = ( ! empty ( $input[ 'enable_frontend' ] ) ) ? 1 : 0; + $input[ 'site_close' ] = ( ! empty ( $input[ 'site_close' ] ) ) ? 1 : 0; + $input[ 'hide_control_classes' ] = ( ! empty ( $input[ 'hide_control_classes' ] ) ) ? 1 : 0; + $input[ 'scroll_lock' ] = ( ! empty ( $input[ 'scroll_lock' ] ) ) ? 1 : 0; + $input[ 'use_fastclick' ] = ( ! empty ( $input[ 'use_fastclick' ] ) ) ? 1 : 0; } // Handle existing sidebars From adcbf6ef03da587ba2b7ed73f8614a8a6470a0fb Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Sat, 8 Oct 2016 19:48:09 +0200 Subject: [PATCH 023/124] Rename off-canvas-sidebars-api.class.php to api.php --- includes/{off-canvas-sidebars-api.class.php => api.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename includes/{off-canvas-sidebars-api.class.php => api.php} (100%) diff --git a/includes/off-canvas-sidebars-api.class.php b/includes/api.php similarity index 100% rename from includes/off-canvas-sidebars-api.class.php rename to includes/api.php From 25cfe50e32cf0e3137fa5c8ad02ee9a8cf3d2181 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Sat, 8 Oct 2016 19:48:26 +0200 Subject: [PATCH 024/124] Rename off-canvas-sidebars-frontend.class.php to class-frontend.php --- ...{off-canvas-sidebars-frontend.class.php => class-frontend.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename includes/{off-canvas-sidebars-frontend.class.php => class-frontend.php} (100%) diff --git a/includes/off-canvas-sidebars-frontend.class.php b/includes/class-frontend.php similarity index 100% rename from includes/off-canvas-sidebars-frontend.class.php rename to includes/class-frontend.php From 72df1bca36e1c8726ccca98641a82dac7f091e61 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Sat, 8 Oct 2016 19:48:41 +0200 Subject: [PATCH 025/124] Rename off-canvas-sidebars-menu-meta-box.class.php to class-menu-meta-box.php --- ...sidebars-menu-meta-box.class.php => class-menu-meta-box.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename includes/{off-canvas-sidebars-menu-meta-box.class.php => class-menu-meta-box.php} (99%) diff --git a/includes/off-canvas-sidebars-menu-meta-box.class.php b/includes/class-menu-meta-box.php similarity index 99% rename from includes/off-canvas-sidebars-menu-meta-box.class.php rename to includes/class-menu-meta-box.php index e6e39d0..1e985ee 100644 --- a/includes/off-canvas-sidebars-menu-meta-box.class.php +++ b/includes/class-menu-meta-box.php @@ -270,4 +270,4 @@ public static function get_instance() { return self::$_instance; } -} // end class \ No newline at end of file +} // end class From 7e5632d086ca8181931af6eaa1b21192805f1737 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Sat, 8 Oct 2016 19:48:56 +0200 Subject: [PATCH 026/124] Rename off-canvas-sidebars-settings.class.php to class-settings.php --- ...ff-canvas-sidebars-settings.class.php => class-settings.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename includes/{off-canvas-sidebars-settings.class.php => class-settings.php} (99%) diff --git a/includes/off-canvas-sidebars-settings.class.php b/includes/class-settings.php similarity index 99% rename from includes/off-canvas-sidebars-settings.class.php rename to includes/class-settings.php index fd6dda1..66f9944 100644 --- a/includes/off-canvas-sidebars-settings.class.php +++ b/includes/class-settings.php @@ -1313,4 +1313,4 @@ public static function get_instance() { return self::$_instance; } -} // end class \ No newline at end of file +} // end class From d3a7a4c115784745979e0980fa6887c100d589d7 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Sat, 8 Oct 2016 19:49:16 +0200 Subject: [PATCH 027/124] Rename off-canvas-sidebars-widget.php to control-widget.php --- widgets/{off-canvas-sidebars-widget.php => control-widget.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename widgets/{off-canvas-sidebars-widget.php => control-widget.php} (100%) diff --git a/widgets/off-canvas-sidebars-widget.php b/widgets/control-widget.php similarity index 100% rename from widgets/off-canvas-sidebars-widget.php rename to widgets/control-widget.php From 9caac29ba935458a8ed22df0e0618fe4a42f4dfc Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Sat, 8 Oct 2016 19:50:27 +0200 Subject: [PATCH 028/124] Update includes for new filenames --- off-canvas-sidebars.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/off-canvas-sidebars.php b/off-canvas-sidebars.php index a001724..1bdd675 100644 --- a/off-canvas-sidebars.php +++ b/off-canvas-sidebars.php @@ -3,7 +3,7 @@ * Plugin Name: Off-Canvas Sidebars * Description: Add off-canvas sidebars using the Slidebars jQuery plugin * Plugin URI: https://wordpress.org/plugins/off-canvas-sidebars/ - * Version: 0.3.1.1 + * Version: 0.3.2-dev * Author: Jory Hogeveen * Author URI: http://www.keraweb.nl * Text Domain: off-canvas-sidebars @@ -190,7 +190,7 @@ private function __construct() { add_action( 'init', array( $this, 'init' ) ); // Load the OCS API - include_once 'includes/off-canvas-sidebars-api.class.php'; + include_once 'includes/api.php'; $this->general_settings = ( get_option( $this->general_key ) ) ? get_option( $this->general_key ) : array(); $this->maybe_db_update(); @@ -200,13 +200,13 @@ private function __construct() { $this->general_labels = $this->get_general_labels(); // Register the widget - include_once 'widgets/off-canvas-sidebars-widget.php'; + include_once 'widgets/control-widget.php'; add_action( 'widgets_init', function() { register_widget( 'OCS_Off_Canvas_Sidebars_Control_Widget' ); } ); // Load menu-meta-box option - include_once 'includes/off-canvas-sidebars-menu-meta-box.class.php'; + include_once 'includes/class-menu-meta-box.php'; OCS_Off_Canvas_Sidebars_Menu_Meta_box::get_instance(); } else { @@ -236,7 +236,7 @@ function init() { if ( is_admin() ) { // Load the admin - include_once 'includes/off-canvas-sidebars-settings.class.php'; + include_once 'includes/class-settings.php'; OCS_Off_Canvas_Sidebars_Settings::get_instance(); // Add settings link to plugins page @@ -246,7 +246,7 @@ function init() { // If a sidebar is enabled, load the front-end if ( $this->is_sidebar_enabled() ) { - include_once 'includes/off-canvas-sidebars-frontend.class.php'; + include_once 'includes/class-frontend.php'; OCS_Off_Canvas_Sidebars_Frontend::get_instance(); } } From 5dcd813f79cdd298a9d1ed494ebea82ed4ec74af Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Sat, 8 Oct 2016 19:52:08 +0200 Subject: [PATCH 029/124] First version of our trigger element API --- includes/api.php | 47 ++++++++++++++++++++++ includes/class-frontend.php | 78 +++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) diff --git a/includes/api.php b/includes/api.php index befbafa..03c2c76 100644 --- a/includes/api.php +++ b/includes/api.php @@ -32,6 +32,53 @@ function the_ocs_off_canvas_sidebar( $sidebars = false ) { } } +/** + * Output a trigger element for off-canvas sidebars + * + * @since 0.3.2 + * @param array $atts { + * Required array of arguments + * @type string id (Required) The off-canvas sidebar ID. + * @type string action The trigger action. Default: toggle + * @type string element The HTML element. Default: button + * @type int|string button Add a button class? 0 = no, 1 = yes. Default: 0 + * @type string text The text to show. Default: '' + * @type array attr Other attributes to add { + * Format: attribute name (array key) => attribute value + * } + * } + * @param string $content (Optional) $content + * @return string + */ +function the_ocs_control_trigger( $atts, $content = '' ) { + if ( $instance = Off_Canvas_Sidebars_Frontend() ) { + + if ( empty( $atts['id'] ) ) { + return __( 'No Off-Canvas Sidebar ID provided.', 'off-canvas-sidebars' ); + } + + $atts = shortcode_atts( array( + 'id' => false, + 'action' => 'toggle', // toggle|open|close + 'element' => 'button', // button|span|i|b|a|etc. + 'button' => 0, // 1|0 + 'text' => '', // Text to show + 'attr' => array(), // An array of attribute keys and their values + 'echo' => true + ), $atts, 'ocs_trigger' ); + + if ( ! empty( $content ) ) { + $atts['text'] = $content; + } + + $return = $instance->do_control_trigger( $atts[ 'id' ], $atts ); + if ( (boolean) $atts['echo'] ) { + echo $return; + } + return $return; + } +} + /** * Main instance of Off-Canvas Sidebars Frontend. * diff --git a/includes/class-frontend.php b/includes/class-frontend.php index a917ed9..2b14d0f 100644 --- a/includes/class-frontend.php +++ b/includes/class-frontend.php @@ -330,6 +330,84 @@ function get_sidebar_attributes( $sidebar, $data ) { return $return; } + /** + * Generate a trigger element + * + * @param string $sidebar_id + * @param array $args see API: the_ocs_control_trigger() for info + * @return string + */ + public function do_control_trigger( $sidebar_id, $args = array() ) { + + $sidebar_id = (string) $sidebar_id; + + $defaults = array( + 'action' => 'toggle', // toggle|open|close + 'element' => 'button', // button|span|i|b|a|etc. + 'button' => 0, // 1|0 + 'text' => '', // Text to show + 'attr' => array() // An array of attribute keys and their values + ); + $args = array_merge( $defaults, $args ); + + if ( in_array( $args['element'], array( 'base', 'body', 'html', 'link', 'meta', 'noscript', 'style', 'script', 'title' ) ) ) { + return '' . __( 'This element is not supported for use as a button', 'off-canvas-sidebars' ) . ''; + } + + $singleton = false; + + // Is it a singleton element? Add the text to the attributes + if ( in_array( $args['element'], array( 'br', 'hr', 'img', 'input' ) ) ) { + $singleton = true; + if ( 'img' == $args['element'] && empty( $args['attr']['alt'] ) ) { + $args['attr']['alt'] = $args['text']; + } + if ( 'input' == $args['element'] && empty( $args['attr']['value'] ) ) { + $args['attr']['value'] = $args['text']; + } + } + + $attr = ''; + if ( empty( $args['attr']['class'] ) ) { + $args['attr']['class'] = array(); + } + foreach ( $args['attr'] as $key => $value ) { + if ( 'class' == $key ) { + // Add our own classes + $classes = array( + $this->general_settings['css_prefix'] . '-button', + $this->general_settings['css_prefix'] . '-' . $args['action'], + $this->general_settings['css_prefix'] . '-' . $args['action'] . '-' . $sidebar_id + ); + if ( ! is_array( $value ) ) { + $value = explode( ' ', $value ); + } + foreach ( $classes as $class ) { + if ( ! in_array( $class, $value ) ) { + $value[] = $class; + } + } + // Add a button class + if ( (int) $args['button'] && ! in_array( 'button', $value ) ) { + $value[] = 'button'; + } + } + if ( is_array( $value ) ) { + $value = implode( ' ', $value ); + } + $attr .= ' ' . esc_attr( $key ) . '="' . esc_attr( (string) $value ) . '"'; + } + + $return = '<' . $args['element'] . $attr; + if ( $singleton ) { + $return .= ' />'; + } else { + $return .= '>' . $args['text'] . ''; + } + + return $return; + } + /** * Add necessary scripts and styles * From 8ac6d28988e93e94d0188e803b375e6908e0892f Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Sat, 8 Oct 2016 19:52:29 +0200 Subject: [PATCH 030/124] Attach a shortcode to the trigger element API --- includes/api.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/includes/api.php b/includes/api.php index 03c2c76..ae657e0 100644 --- a/includes/api.php +++ b/includes/api.php @@ -79,6 +79,45 @@ function the_ocs_control_trigger( $atts, $content = '' ) { } } +/** + * Shortcode handler for the_ocs_control_trigger() + * + * Example 1 (simple shortcode with all options): + * [ocs_trigger id="left" action="open" element="a" button="1" text="My trigger button!" attr="href: #; rel: nofollow; alt: Yay!!"] + * + * Example 2 (nested shortcode with some options: + * [ocs_trigger id="right" attr="type:button;alt:Yay!!"]My trigger button text[/ocs_trigger] + * + * @since 0.3.2 + * @see the_ocs_control_trigger() + */ +function shortcode_ocs_control_trigger( $atts, $content = '' ) { + // Shortcodes don't echo + $atts[ 'echo' ] = false; + + if ( empty( $atts['attr'] ) && ! empty( $atts['attributes'] ) ) { + $atts['attr'] = $atts['attributes']; + unset( $atts['attributes'] ); + } + + // Parse attributes send through the shortcode + if ( ! empty( $atts['attr'] ) ) { + $attr = explode( ';', $atts['attr'] ); + $atts['attr'] = array(); + foreach ( $attr as $key => $value ) { + $attr[ $key ] = explode( ':', $value ); + if ( count( $attr[ $key ] ) > 1 ) { + $attribute = trim( $attr[ $key ][0] ); + unset( $attr[ $key ][0] ); + $atts['attr'][ $attribute ] = trim( implode( ':', $attr[ $key ] ) ); + } + } + } + + return the_ocs_control_trigger( $atts, $content ); +} +add_shortcode( 'ocs_trigger', 'shortcode_ocs_control_trigger' ); + /** * Main instance of Off-Canvas Sidebars Frontend. * From 3171e24b809b93d95aaf5f2744c046db7e123591 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Sat, 8 Oct 2016 20:27:08 +0200 Subject: [PATCH 031/124] Docs & minor improvements - Always inset $atts['attributes'] --- includes/api.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/includes/api.php b/includes/api.php index ae657e0..54e2f49 100644 --- a/includes/api.php +++ b/includes/api.php @@ -89,16 +89,20 @@ function the_ocs_control_trigger( $atts, $content = '' ) { * [ocs_trigger id="right" attr="type:button;alt:Yay!!"]My trigger button text[/ocs_trigger] * * @since 0.3.2 - * @see the_ocs_control_trigger() + * @see the_ocs_control_trigger() for detailed info + * @param array $atts + * @param string $content (Optional) $content + * @return string */ function shortcode_ocs_control_trigger( $atts, $content = '' ) { // Shortcodes don't echo $atts[ 'echo' ] = false; + // You can also use `attributes` instead of `attr` for readability (if both are used, `attributes` is ignored) if ( empty( $atts['attr'] ) && ! empty( $atts['attributes'] ) ) { $atts['attr'] = $atts['attributes']; - unset( $atts['attributes'] ); } + unset( $atts['attributes'] ); // Parse attributes send through the shortcode if ( ! empty( $atts['attr'] ) ) { From 0913599b635e2c5fb66a344a5c36c1f1203d8389 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Sat, 8 Oct 2016 20:28:34 +0200 Subject: [PATCH 032/124] Better shortcode function name --- includes/api.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/api.php b/includes/api.php index 54e2f49..2031528 100644 --- a/includes/api.php +++ b/includes/api.php @@ -88,13 +88,13 @@ function the_ocs_control_trigger( $atts, $content = '' ) { * Example 2 (nested shortcode with some options: * [ocs_trigger id="right" attr="type:button;alt:Yay!!"]My trigger button text[/ocs_trigger] * - * @since 0.3.2 - * @see the_ocs_control_trigger() for detailed info + * @since 0.3.2 + * @see the_ocs_control_trigger() for detailed info * @param array $atts * @param string $content (Optional) $content * @return string */ -function shortcode_ocs_control_trigger( $atts, $content = '' ) { +function shortcode_ocs_trigger( $atts, $content = '' ) { // Shortcodes don't echo $atts[ 'echo' ] = false; @@ -120,7 +120,7 @@ function shortcode_ocs_control_trigger( $atts, $content = '' ) { return the_ocs_control_trigger( $atts, $content ); } -add_shortcode( 'ocs_trigger', 'shortcode_ocs_control_trigger' ); +add_shortcode( 'ocs_trigger', 'shortcode_ocs_trigger' ); /** * Main instance of Off-Canvas Sidebars Frontend. From 749dca0ad6f213091354097e082377baab5240bb Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Sat, 15 Oct 2016 00:36:35 +0200 Subject: [PATCH 033/124] Fix CSS selector --- css/off-canvas-sidebars.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/css/off-canvas-sidebars.css b/css/off-canvas-sidebars.css index d2bd85c..fc23dcf 100644 --- a/css/off-canvas-sidebars.css +++ b/css/off-canvas-sidebars.css @@ -11,7 +11,7 @@ */ html, -.ocs-initialized html { +html.ocs-initialized { overflow-y: auto; height: auto; } From 1493be0639706e504ec2e280ad1a55bcffa756c1 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Sat, 15 Oct 2016 00:37:17 +0200 Subject: [PATCH 034/124] Use event triggers --- js/fixed-scrolltop.js | 2 +- js/off-canvas-sidebars.js | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/js/fixed-scrolltop.js b/js/fixed-scrolltop.js index 28eb214..a88c079 100644 --- a/js/fixed-scrolltop.js +++ b/js/fixed-scrolltop.js @@ -8,7 +8,7 @@ */ ( function ( $ ) { - $(window).load(function () { + $(window).on( 'ocs_initialized', function () { var prefix = 'ocs'; if ( typeof ocsOffCanvasSidebars != 'undefined' ) { diff --git a/js/off-canvas-sidebars.js b/js/off-canvas-sidebars.js index 211bb32..5af638d 100644 --- a/js/off-canvas-sidebars.js +++ b/js/off-canvas-sidebars.js @@ -135,6 +135,8 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { ocsOffCanvasSidebars.container = $( '[canvas=container]' ); + $(window).trigger( 'ocs_loaded', this ); + /** * Function call before initializing * @since 0.3 @@ -161,6 +163,8 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { ocsOffCanvasSidebars._html.addClass('ocs-initialized'); + $(window).trigger( 'ocs_initialized', this ); + /** * Compatibility with WP Admin Bar * @since 0.3.2 @@ -355,10 +359,7 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { return; } - // Close the slidebar, no need to check the disable_over setting since we're closing the slidebar - //if ( ocsOffCanvasSidebars._checkDisableOver( prefix + '-' + id ) ) { - controller.close( prefix + '-' + id ); - //} + controller.close( prefix + '-' + id ); } ); } ); From dd1a005cfa9aef8c85305726e4768669fb42089b Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Sat, 15 Oct 2016 00:37:49 +0200 Subject: [PATCH 035/124] Extend scrollTop fix into the ocs javascript object --- js/fixed-scrolltop.js | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/js/fixed-scrolltop.js b/js/fixed-scrolltop.js index a88c079..ad68e6a 100644 --- a/js/fixed-scrolltop.js +++ b/js/fixed-scrolltop.js @@ -4,35 +4,32 @@ * Compatibility for fixed elements with Slidebars * @author Jory Hogeveen * @package off-canvas-slidebars - * @version 0.3.1 + * @version 0.4 */ ( function ( $ ) { $(window).on( 'ocs_initialized', function () { - var prefix = 'ocs'; - if ( typeof ocsOffCanvasSidebars != 'undefined' ) { - prefix = ocsOffCanvasSidebars.css_prefix; - } + var prefix = ocsOffCanvasSidebars.css_prefix; var curScrollTopElements; - var scrollTarget = ocs_site = $('#' + prefix + '-site'); + var scrollTarget = ocs_site = ocsOffCanvasSidebars.container; if ( 'auto' != ocs_site.css('overflow-y') ) { scrollTarget = $( window ); } if ( ocs_site.css('transform') != 'none' ) { - curScrollTopElements = $('#' + prefix + '-site *').filter( function(){ return $(this).css('position') === 'fixed'; } ); - ocsScrollTopFixed(); - scrollTarget.on('scroll resize', function() { - var newScrollTopElements = $('#' + prefix + '-site *').filter( function(){ return $(this).css('position') === 'fixed'; } ); + curScrollTopElements = $('#' + prefix + '-site *').filter( function() { return $(this).css('position') === 'fixed'; } ); + ocsOffCanvasSidebars.scrollTopFixed(); + scrollTarget.on( 'scroll resize', function() { + var newScrollTopElements = $('#' + prefix + '-site *').filter( function() { return $(this).css('position') === 'fixed'; } ); curScrollTopElements = curScrollTopElements.add( newScrollTopElements ); - ocsScrollTopFixed(); + ocsOffCanvasSidebars.scrollTopFixed(); } ); - scrollTarget.on('slidebar_event', ocsSlidebarEventFixed ); + scrollTarget.on( 'slidebar_event', ocsOffCanvasSidebars.slidebarEventFixed ); } - function ocsSlidebarEventFixed( e, eventType, slidebar ) { + ocsOffCanvasSidebars.slidebarEventFixed = function( e, eventType, slidebar ) { if ( ( eventType == 'opened' || eventType == 'closed' ) && ( slidebar.side == 'bottom' ) ) { //slidebar.side == 'top' || curScrollTopElements.each( function() { var px = ocsOffCanvasSidebars._getTranslateAxis( this, 'y' ); @@ -50,9 +47,9 @@ } ); } ); } - } + }; - function ocsScrollTopFixed() { + ocsOffCanvasSidebars.scrollTopFixed = function() { if ( curScrollTopElements.length > 0 ) { var scrollTop = scrollTarget.scrollTop(), winHeight = $(window).height(), @@ -62,7 +59,7 @@ var activeSidebar = ocsOffCanvasSidebars.slidebarsController.getActiveSlidebar(); if ( activeSidebar ) { - var sidebar = ocsOffCanvasSidebars.slidebarsController.getSlidebar( activeSidebar ); + var sidebar = ocsOffCanvasSidebars.slidebarsController.getSlidebar( activeSidebar ); if ( sidebar.side == 'top' ) { gblOffset.top += sidebar.element.height(); } else if ( sidebar.side == 'top' ) { @@ -95,7 +92,7 @@ } } ); } - } + }; }); From ffb43159d6f96806780a2a66e00121e8edc3cd8b Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Sat, 15 Oct 2016 00:38:05 +0200 Subject: [PATCH 036/124] Improve size calculation in legacy mode --- slidebars/slidebars.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/slidebars/slidebars.js b/slidebars/slidebars.js index a812528..32761be 100644 --- a/slidebars/slidebars.js +++ b/slidebars/slidebars.js @@ -11,7 +11,7 @@ /*! * Modified by: Jory Hogeveen * - * @since 0.3.2 Add score for this reference + Add legacy CSS support (no hardware acceleration) + * @since 0.4 Add scope for this reference + Add legacy CSS support (no hardware acceleration) */ var slidebars; @@ -62,13 +62,17 @@ slidebars = function () { if ( offCanvas[ id ].active ) { if ( self.legacy ) { if ( offCanvas[ id ].side === 'top' ) { - amount = offCanvas[ id ].element.css( 'height' ); + //amount = offCanvas[ id ].element.css( 'height' ); + amount = offCanvas[ id ].element.css( 'margin-top' ).replace('-',''); } else if ( offCanvas[ id ].side === 'right' ) { - amount = offCanvas[ id ].element.css( 'width' ); + //amount = offCanvas[ id ].element.css( 'width' ); + amount = offCanvas[ id ].element.css( 'margin-right' ).replace('-',''); } else if ( offCanvas[ id ].side === 'bottom' ) { - amount = offCanvas[ id ].element.css( 'height' ); + //amount = offCanvas[ id ].element.css( 'height' ); + amount = offCanvas[ id ].element.css( 'margin-bottom' ).replace('-',''); } else if ( offCanvas[ id ].side === 'left' ) { - amount = offCanvas[ id ].element.css( 'width' ); + //amount = offCanvas[ id ].element.css( 'width' ); + amount = offCanvas[ id ].element.css( 'margin-left' ).replace('-',''); } } else { if ( offCanvas[ id ].side === 'top' ) { From 78716320eb032178f6c2308b57d2a0f9efca790f Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Sat, 15 Oct 2016 01:21:24 +0200 Subject: [PATCH 037/124] Fix CSS selectors for attribute values See https://github.com/adchsm/Slidebars/issues/261 PR on Slidebars: https://github.com/adchsm/Slidebars/pull/262 --- slidebars/slidebars.css | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/slidebars/slidebars.css b/slidebars/slidebars.css index 40efd0d..ba7936d 100644 --- a/slidebars/slidebars.css +++ b/slidebars/slidebars.css @@ -63,45 +63,45 @@ html, body { -webkit-overflow-scrolling: touch; /* Enables momentum scrolling on iOS devices, may be removed by setting to 'auto' in your own CSS. */ } -[off-canvas*=top] { +[off-canvas*=" top"] { width: 100%; height: 255px; top: 0; } -[off-canvas*=right] { +[off-canvas*=" right"] { width: 255px; height: 100%; top: 0; right: 0; } -[off-canvas*=bottom] { +[off-canvas*=" bottom"] { width: 100%; height: 255px; bottom: 0; } -[off-canvas*=left] { +[off-canvas*=" left"] { width: 255px; height: 100%; top: 0; left: 0; } -[off-canvas*=reveal] { +[off-canvas*=" reveal"] { z-index: 0; } -[off-canvas*=push] { +[off-canvas*=" push"] { z-index: 1; } -[off-canvas*=overlay] { +[off-canvas*=" overlay"] { z-index: 9999; } -[off-canvas*=shift] { +[off-canvas*=" shift"] { z-index: 0; } @@ -118,22 +118,22 @@ html, body { -webkit-backface-visibility: hidden; /* Prevents flickering, may be removed if experiencing problems with fixed background images in Chrome. */ } -[off-canvas*=shift][off-canvas*=top] { +[off-canvas*=" shift"][off-canvas*=" top"] { -webkit-transform: translate( 0px, 50% ); transform: translate( 0px, 50% ); } -[off-canvas*=shift][off-canvas*=right] { +[off-canvas*=" shift"][off-canvas*=" right"] { -webkit-transform: translate( -50%, 0px ); transform: translate( -50%, 0px ); } -[off-canvas*=shift][off-canvas*=bottom] { +[off-canvas*=" shift"][off-canvas*=" bottom"] { -webkit-transform: translate( 0px, -50% ); transform: translate( 0px, -50% ); } -[off-canvas*=shift][off-canvas*=left] { +[off-canvas*=" shift"][off-canvas*=" left"] { -webkit-transform: translate( 50%, 0px ); transform: translate( 50%, 0px ); } From 75e7fda689c3a5c175f1ce13c7470115d269b383 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 20 Oct 2016 14:41:27 +0200 Subject: [PATCH 038/124] Improve property/variable names --- includes/class-frontend.php | 104 +++++++++++++++++-------------- includes/class-menu-meta-box.php | 20 +++--- includes/class-settings.php | 22 +++---- off-canvas-sidebars.php | 34 +++++----- widgets/control-widget.php | 22 +++---- 5 files changed, 105 insertions(+), 97 deletions(-) diff --git a/includes/class-frontend.php b/includes/class-frontend.php index 2b14d0f..a7d1590 100644 --- a/includes/class-frontend.php +++ b/includes/class-frontend.php @@ -20,7 +20,7 @@ final class OCS_Off_Canvas_Sidebars_Frontend */ protected static $_instance = null; - private $general_settings = array(); + private $settings = array(); /** * @since 0.3 private constructor @@ -29,7 +29,7 @@ final class OCS_Off_Canvas_Sidebars_Frontend private function __construct() { $this->load_plugin_data(); - if ( $this->general_settings['enable_frontend'] == true ) { + if ( $this->settings['enable_frontend'] == true ) { $this->default_actions(); } @@ -42,10 +42,10 @@ private function __construct() { /** * Get plugin defaults + * @since 0.1 */ private function load_plugin_data() { - $off_canvas_sidebars = Off_Canvas_Sidebars(); - $this->general_settings = $off_canvas_sidebars->get_settings(); + $this->settings = Off_Canvas_Sidebars()->get_settings(); } /** @@ -56,8 +56,8 @@ private function load_plugin_data() { */ private function default_actions() { - $before_hook = trim( $this->general_settings['website_before_hook'] ); - $after_hook = trim( $this->general_settings['website_after_hook'] ); + $before_hook = trim( $this->settings['website_before_hook'] ); + $after_hook = trim( $this->settings['website_after_hook'] ); if ( get_template() == 'genesis' ) { $before_hook = 'genesis_before'; @@ -96,10 +96,10 @@ function before_site() { do_action( 'ocs_container_before' ); $atts = array( - 'ocs-site_close' => ( $this->general_settings['site_close'] ) ? true : false, - 'ocs-disable_over' => ( $this->general_settings['disable_over'] ) ? (int) $this->general_settings['disable_over'] : false, - 'ocs-hide_control_classes' => ( $this->general_settings['hide_control_classes'] ) ? true : false, - 'ocs-scroll_lock' => ( $this->general_settings['scroll_lock'] ) ? true : false, + 'ocs-site_close' => ( $this->settings['site_close'] ) ? true : false, + 'ocs-disable_over' => ( $this->settings['disable_over'] ) ? (int) $this->settings['disable_over'] : false, + 'ocs-hide_control_classes' => ( $this->settings['hide_control_classes'] ) ? true : false, + 'ocs-scroll_lock' => ( $this->settings['scroll_lock'] ) ? true : false, ); foreach ( $atts as $name => $value ) { @@ -109,7 +109,7 @@ function before_site() { $atts[ $name ] = $name . '="' . $value . '"'; } - echo '
'; + echo '
'; // Add content before other content in the site container do_action( 'ocs_container_inner_before' ); @@ -127,7 +127,7 @@ function after_site() { // Add content after other content in the site container do_action( 'ocs_container_inner_after' ); - if ( $this->general_settings['frontend_type'] != 'jquery' ) { + if ( $this->settings['frontend_type'] != 'jquery' ) { echo '
'; // close #ocs-site } // Add content after the site container @@ -147,7 +147,7 @@ function after_site_script() { ?> general_settings['sidebars'] ) ) { - foreach ( $this->general_settings['sidebars'] as $sidebar => $sidebar_data ) { - if ( ! empty( $sidebar_data['enable'] ) ) { - $this->do_sidebar( $sidebar ); - } + if ( ! empty( $this->settings['sidebars'] ) ) { + foreach ( $this->settings['sidebars'] as $sidebar_id => $sidebar_data ) { + $this->do_sidebar( $sidebar_id ); } } } @@ -175,15 +173,20 @@ function do_sidebars() { * Echos a sidebar * * @since 0.1 + * @param string $sidebar_id * @return void * @access public */ function do_sidebar( $sidebar_id ) { - if ( ! empty( $this->general_settings['sidebars'][ $sidebar_id ] ) ) { + if ( ! empty( $this->settings['sidebars'][ $sidebar_id ] ) ) { - $sidebar_data = $this->general_settings['sidebars'][ $sidebar_id ]; + $sidebar_data = $this->settings['sidebars'][ $sidebar_id ]; + + if ( empty( $sidebar_data['enable'] ) ) { + return; + } - echo '
get_sidebar_attributes( $sidebar_id, $sidebar_data ) . '>'; + echo '
get_sidebar_attributes( $sidebar_id, $sidebar_data ) . '>'; /** * Action to add content before the default sidebar content @@ -273,17 +276,19 @@ function do_sidebar( $sidebar_id ) { * * @since 0.1 * @since 0.3 Overwrite global setting attributes + * @param string $sidebar_id + * @param array $data * @return string */ - function get_sidebar_attributes( $sidebar, $data ) { - $prefix = $this->general_settings['css_prefix']; + function get_sidebar_attributes( $sidebar_id, $data ) { + $prefix = $this->settings['css_prefix']; $atts = array(); $atts['class'] = array(); $atts['class'][] = $prefix . '-slidebar'; - $atts['class'][] = $prefix . '-' . esc_attr( $sidebar ); + $atts['class'][] = $prefix . '-' . esc_attr( $sidebar_id ); $atts['class'][] = 'ocs-slidebar'; - $atts['class'][] = 'ocs-' . esc_attr( $sidebar ); + $atts['class'][] = 'ocs-' . esc_attr( $sidebar_id ); $atts['class'][] = 'ocs-size-' . esc_attr( $data['size'] ); $atts['class'][] = 'ocs-location-' . esc_attr( $data['location'] ); $atts['class'][] = 'ocs-style-' . esc_attr( $data['style'] ); @@ -299,15 +304,15 @@ function get_sidebar_attributes( $sidebar, $data ) { * @param string $sidebar_id The ID of this sidebar as configured in: Appearances > Off-Canvas Sidebars > Sidebars * @param array $sidebar_data The sidebar settings */ - $atts['class'] = apply_filters( 'ocs_sidebar_classes', $atts['class'], $sidebar, $data ); + $atts['class'] = apply_filters( 'ocs_sidebar_classes', $atts['class'], $sidebar_id, $data ); // Slidebars 2.0 $atts['off-canvas'] = array( - $prefix . '-' . esc_attr( $sidebar ), // ID + $prefix . '-' . esc_attr( $sidebar_id ), // ID esc_attr( $data['location'] ), // Location esc_attr( $data['style'] ) // Animation style ); - $atts['ocs-sidebar-id'] = esc_attr( $sidebar ); + $atts['ocs-sidebar-id'] = esc_attr( $sidebar_id ); // Overwrite global settings if ( true === (bool) $data['overwrite_global_settings'] ) { @@ -375,9 +380,9 @@ public function do_control_trigger( $sidebar_id, $args = array() ) { if ( 'class' == $key ) { // Add our own classes $classes = array( - $this->general_settings['css_prefix'] . '-button', - $this->general_settings['css_prefix'] . '-' . $args['action'], - $this->general_settings['css_prefix'] . '-' . $args['action'] . '-' . $sidebar_id + $this->settings['css_prefix'] . '-button', + $this->settings['css_prefix'] . '-' . $args['action'], + $this->settings['css_prefix'] . '-' . $args['action'] . '-' . $sidebar_id ); if ( ! is_array( $value ) ) { $value = explode( ' ', $value ); @@ -424,22 +429,29 @@ function add_styles_scripts() { wp_enqueue_style( 'off-canvas-sidebars', OCS_PLUGIN_URL . 'css/off-canvas-sidebars.css', array(), $version ); // @todo: '.$suffix.' wp_enqueue_script( 'off-canvas-sidebars', OCS_PLUGIN_URL . 'js/off-canvas-sidebars.js', array( 'jquery', 'slidebars' ), $version, true ); // @todo: '.$suffix.' + + $sidebars = array(); + foreach ( $this->settings['sidebars'] as $sidebar_id => $sidebar_data ) { + if ( ! empty( $sidebar_data['enable'] ) ) { + $sidebars[ $sidebar_id ] = $sidebar_data; + } + } wp_localize_script( 'off-canvas-sidebars', 'ocsOffCanvasSidebars', array( - 'site_close' => ( $this->general_settings['site_close'] ) ? true : false, - 'disable_over' => ( $this->general_settings['disable_over'] ) ? (int) $this->general_settings['disable_over'] : false, - 'hide_control_classes' => ( $this->general_settings['hide_control_classes'] ) ? true : false, - 'scroll_lock' => ( $this->general_settings['scroll_lock'] ) ? true : false, - 'legacy_css' => ( 'legacy-css' == $this->general_settings['compatibility_position_fixed'] ) ? true : false, - 'css_prefix' => $this->general_settings['css_prefix'], - 'sidebars' => $this->general_settings['sidebars'] + 'site_close' => ( $this->settings['site_close'] ) ? true : false, + 'disable_over' => ( $this->settings['disable_over'] ) ? (int) $this->settings['disable_over'] : false, + 'hide_control_classes' => ( $this->settings['hide_control_classes'] ) ? true : false, + 'scroll_lock' => ( $this->settings['scroll_lock'] ) ? true : false, + 'legacy_css' => ( 'legacy-css' == $this->settings['compatibility_position_fixed'] ) ? true : false, + 'css_prefix' => $this->settings['css_prefix'], + 'sidebars' => $sidebars ) ); - if ( 'custom-js' == $this->general_settings['compatibility_position_fixed'] ) { + if ( 'custom-js' == $this->settings['compatibility_position_fixed'] ) { wp_enqueue_script( 'ocs-fixed-scrolltop', OCS_PLUGIN_URL . 'js/fixed-scrolltop.js', array( 'jquery' ), $version, true ); } // FastClick library https://github.com/ftlabs/fastclick - if ( true === (bool) $this->general_settings['use_fastclick'] ) { + if ( true === (bool) $this->settings['use_fastclick'] ) { wp_enqueue_script( 'fastclick', OCS_PLUGIN_URL . 'js/fastclick.js', array(), false, true ); } } @@ -468,23 +480,23 @@ function add_inline_scripts() { */ function add_inline_styles() { if ( ! is_admin() ) { - $prefix = $this->general_settings['css_prefix']; + $prefix = $this->settings['css_prefix']; ?> widget_setting ][ $sidebar_id ]['enable'] == 1 ) { $widget_data = $instance[ $this->widget_setting ][ $sidebar_id ]; $classes = array( - $prefix . '-button', + $prefix . '-trigger', $prefix . '-toggle', $prefix . '-toggle-' . $sidebar_id ); From 051f69d93d6ad5d19bbd933bff678ccc12ee660e Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 20 Oct 2016 14:55:40 +0200 Subject: [PATCH 040/124] Allow `class` or `classes` parameter instead of `button` for more flexibility --- includes/api.php | 26 ++++++++++++++++---------- includes/class-frontend.php | 22 +++++++++++++++------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/includes/api.php b/includes/api.php index 2031528..99f6ce2 100644 --- a/includes/api.php +++ b/includes/api.php @@ -35,15 +35,15 @@ function the_ocs_off_canvas_sidebar( $sidebars = false ) { /** * Output a trigger element for off-canvas sidebars * - * @since 0.3.2 + * @since 0.4 * @param array $atts { * Required array of arguments - * @type string id (Required) The off-canvas sidebar ID. - * @type string action The trigger action. Default: toggle - * @type string element The HTML element. Default: button - * @type int|string button Add a button class? 0 = no, 1 = yes. Default: 0 - * @type string text The text to show. Default: '' - * @type array attr Other attributes to add { + * @type string id (Required) The off-canvas sidebar ID. + * @type string text The text to show. Default: '' + * @type string action The trigger action. Default: toggle + * @type string element The HTML element. Default: button + * @type array|string class Add extra classes? Also accepts a string with classes separated with a space + * @type array attr Other attributes to add { * Format: attribute name (array key) => attribute value * } * } @@ -59,10 +59,10 @@ function the_ocs_control_trigger( $atts, $content = '' ) { $atts = shortcode_atts( array( 'id' => false, + 'text' => '', // Text to show 'action' => 'toggle', // toggle|open|close 'element' => 'button', // button|span|i|b|a|etc. - 'button' => 0, // 1|0 - 'text' => '', // Text to show + 'class' => array(), // Extra classes, also accepts a string with classes separated with a space 'attr' => array(), // An array of attribute keys and their values 'echo' => true ), $atts, 'ocs_trigger' ); @@ -88,7 +88,7 @@ function the_ocs_control_trigger( $atts, $content = '' ) { * Example 2 (nested shortcode with some options: * [ocs_trigger id="right" attr="type:button;alt:Yay!!"]My trigger button text[/ocs_trigger] * - * @since 0.3.2 + * @since 0.4 * @see the_ocs_control_trigger() for detailed info * @param array $atts * @param string $content (Optional) $content @@ -104,6 +104,12 @@ function shortcode_ocs_trigger( $atts, $content = '' ) { } unset( $atts['attributes'] ); + // You can also use `classes` instead of `class` for readability (if both are used, `classes` is ignored) + if ( empty( $atts['class'] ) && ! empty( $atts['classes'] ) ) { + $atts['class'] = $atts['classes']; + } + unset( $atts['classes'] ); + // Parse attributes send through the shortcode if ( ! empty( $atts['attr'] ) ) { $attr = explode( ';', $atts['attr'] ); diff --git a/includes/class-frontend.php b/includes/class-frontend.php index 9f353dc..22394b7 100644 --- a/includes/class-frontend.php +++ b/includes/class-frontend.php @@ -338,6 +338,7 @@ function get_sidebar_attributes( $sidebar_id, $data ) { /** * Generate a trigger element * + * @since 0.4 * @param string $sidebar_id * @param array $args see API: the_ocs_control_trigger() for info * @return string @@ -347,10 +348,10 @@ public function do_control_trigger( $sidebar_id, $args = array() ) { $sidebar_id = (string) $sidebar_id; $defaults = array( + 'text' => '', // Text to show 'action' => 'toggle', // toggle|open|close 'element' => 'button', // button|span|i|b|a|etc. - 'button' => 0, // 1|0 - 'text' => '', // Text to show + 'class' => array(), // Extra classes (space separated), also accepts an array of classes 'attr' => array() // An array of attribute keys and their values ); $args = array_merge( $defaults, $args ); @@ -379,7 +380,7 @@ public function do_control_trigger( $sidebar_id, $args = array() ) { foreach ( $args['attr'] as $key => $value ) { if ( 'class' == $key ) { // Add our own classes - $classes = array( + $ocs_classes = array( $this->settings['css_prefix'] . '-trigger', $this->settings['css_prefix'] . '-' . $args['action'], $this->settings['css_prefix'] . '-' . $args['action'] . '-' . $sidebar_id @@ -387,14 +388,21 @@ public function do_control_trigger( $sidebar_id, $args = array() ) { if ( ! is_array( $value ) ) { $value = explode( ' ', $value ); } - foreach ( $classes as $class ) { + foreach ( $ocs_classes as $class ) { if ( ! in_array( $class, $value ) ) { $value[] = $class; } } - // Add a button class - if ( (int) $args['button'] && ! in_array( 'button', $value ) ) { - $value[] = 'button'; + + // Optionally add extra classes + if ( ! empty( $args['class'] ) ) { + $classes_extra = explode( ' ', $args['class'] ); + foreach ( $classes_extra as $c ) { + $c = esc_attr( $c ); + if ( ! in_array( $c, $value ) ) { + $value[] = $c; + } + } } } if ( is_array( $value ) ) { From 9eeef57c7aba3b93fb47c31424eb3e9bcd901de3 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 20 Oct 2016 15:01:14 +0200 Subject: [PATCH 041/124] Compat if the user defined a `class` and `attr` with a class attribute --- includes/class-frontend.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/class-frontend.php b/includes/class-frontend.php index 22394b7..63ddfec 100644 --- a/includes/class-frontend.php +++ b/includes/class-frontend.php @@ -396,8 +396,10 @@ public function do_control_trigger( $sidebar_id, $args = array() ) { // Optionally add extra classes if ( ! empty( $args['class'] ) ) { - $classes_extra = explode( ' ', $args['class'] ); - foreach ( $classes_extra as $c ) { + if ( ! is_array( $args['class'] ) ) { + $args['class'] = explode( ' ', $args['class'] ); + } + foreach ( $args['class'] as $c ) { $c = esc_attr( $c ); if ( ! in_array( $c, $value ) ) { $value[] = $c; From 6489bff6a0565df7d007f38ce7b26a4c78616d74 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Fri, 13 Jan 2017 05:07:58 +0100 Subject: [PATCH 042/124] Docs fix + indentation --- off-canvas-sidebars.php | 86 ++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/off-canvas-sidebars.php b/off-canvas-sidebars.php index 0af5d5d..af5531c 100644 --- a/off-canvas-sidebars.php +++ b/off-canvas-sidebars.php @@ -92,7 +92,7 @@ final class OCS_Off_Canvas_Sidebars /** * Plugin key * - * @var bool + * @var string * @since 0.1 */ protected $plugin_key = 'off-canvas-sidebars-settings'; @@ -100,7 +100,7 @@ final class OCS_Off_Canvas_Sidebars /** * Plugin general settings key, also used as option key * - * @var bool + * @var string * @since 0.1 */ protected $general_key = 'off_canvas_sidebars_options'; @@ -108,7 +108,7 @@ final class OCS_Off_Canvas_Sidebars /** * Plugin settings * - * @var bool + * @var array * @since 0.1 */ protected $settings = array(); @@ -116,7 +116,7 @@ final class OCS_Off_Canvas_Sidebars /** * Plugin settings * - * @var bool + * @var array * @since 0.1 */ protected $general_labels = array(); @@ -124,51 +124,53 @@ final class OCS_Off_Canvas_Sidebars /** * Default settings * - * @var bool + * @var array * @since 0.2 */ protected $default_settings = array( - 'db_version' => '0', - 'enable_frontend' => 1, - 'frontend_type' => 'action', - 'site_close' => 1, - 'disable_over' => '', - 'hide_control_classes' => 0, - 'scroll_lock' => 0, - 'background_color_type' => '', - 'background_color' => '', - 'website_before_hook' => 'website_before', - 'website_after_hook' => 'website_after', - 'use_fastclick' => 0, - 'compatibility_position_fixed' => 'none', - 'css_prefix' => 'ocs', - 'sidebars' => array(), + 'db_version' => '0', + 'enable_frontend' => 1, + 'frontend_type' => 'action', + 'site_close' => 1, + 'disable_over' => '', + 'hide_control_classes' => 0, + 'scroll_lock' => 0, + 'background_color_type' => '', + 'background_color' => '', + 'website_before_hook' => 'website_before', + 'website_after_hook' => 'website_after', + 'use_fastclick' => 0, + 'compatibility_position_fixed' => 'none', + 'shortcode_rendering_wp_editor' => 0, + 'css_prefix' => 'ocs', + 'sidebars' => array(), ); /** * Default sidebar settings * - * @var bool + * @var array * @since 0.2 */ protected $default_sidebar_settings = array( - 'enable' => 0, - 'label' => '', - 'content' => 'sidebar', - 'location' => 'left', - 'style' => 'push', - 'size' => 'default', - 'size_input' => '', - 'size_input_type' => '%', - 'animation_speed' => '', - 'padding' => '', - 'background_color' => '', - 'background_color_type' => '', + 'enable' => 0, + 'label' => '', + 'content' => 'sidebar', + 'location' => 'left', + 'style' => 'push', + 'size' => 'default', + 'size_input' => '', + 'size_input_type' => '%', + 'animation_speed' => '', + 'padding' => '', + 'background_color' => '', + 'background_color_type' => '', + /* Global overwrites */ 'overwrite_global_settings' => 0, - 'site_close' => 1, - 'disable_over' => '', - 'hide_control_classes' => 0, - 'scroll_lock' => 0, + 'site_close' => 1, + 'disable_over' => '', + 'hide_control_classes' => 0, + 'scroll_lock' => 0, ); /** @@ -245,10 +247,8 @@ function init() { } else { // If a sidebar is enabled, load the front-end - if ( $this->is_sidebar_enabled() ) { - include_once 'includes/class-frontend.php'; - OCS_Off_Canvas_Sidebars_Frontend::get_instance(); - } + include_once 'includes/class-frontend.php'; + OCS_Off_Canvas_Sidebars_Frontend::get_instance(); } } @@ -328,7 +328,7 @@ function validate_settings( $settings, $defaults ) { * Returns the default settings * * @since 0.2 - * @return string + * @return array */ function get_default_settings() { return $this->default_settings; } @@ -336,7 +336,7 @@ function get_default_settings() { return $this->default_settings; } * Returns the default sidebar_settings * * @since 0.2 - * @return string + * @return array */ function get_default_sidebar_settings() { return $this->default_sidebar_settings; } From 8f1d7d9fc4d42586959fa507a60e7196ef3fcd08 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Fri, 13 Jan 2017 05:08:24 +0100 Subject: [PATCH 043/124] Add legacy class to the body for instant results in page rendering --- includes/class-frontend.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/includes/class-frontend.php b/includes/class-frontend.php index 63ddfec..6629c81 100644 --- a/includes/class-frontend.php +++ b/includes/class-frontend.php @@ -38,6 +38,8 @@ private function __construct() { add_action( 'wp_enqueue_scripts', array( $this, 'add_styles_scripts' ) ); //add_action( 'wp_footer', array( $this, 'add_inline_scripts' ), 999999999 ); // enforce last addition add_action( 'wp_head', array( $this, 'add_inline_styles' ) ); + + add_filter( 'body_class', array( $this, 'filter_body_class' ) ); } /** @@ -48,6 +50,20 @@ private function load_plugin_data() { $this->settings = Off_Canvas_Sidebars()->get_settings(); } + /** + * Add classes to the body + * + * @since 1.4 + * @param array $classes + * @return array + */ + public function filter_body_class( $classes ) { + if ( ( 'legacy-css' == $this->settings['compatibility_position_fixed'] ) ) { + $classes[] = 'ocs-legacy'; + } + return $classes; + } + /** * Add default actions * From ca67f3abc49a69c0c60cac7ee837cd0401d0878f Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Fri, 13 Jan 2017 05:12:56 +0100 Subject: [PATCH 044/124] Useless brackets --- includes/class-frontend.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-frontend.php b/includes/class-frontend.php index 6629c81..ccb0e11 100644 --- a/includes/class-frontend.php +++ b/includes/class-frontend.php @@ -58,7 +58,7 @@ private function load_plugin_data() { * @return array */ public function filter_body_class( $classes ) { - if ( ( 'legacy-css' == $this->settings['compatibility_position_fixed'] ) ) { + if ( 'legacy-css' == $this->settings['compatibility_position_fixed'] ) { $classes[] = 'ocs-legacy'; } return $classes; From 2a3eca061b1b19172d7baf971ad09c331267219d Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Fri, 13 Jan 2017 05:20:41 +0100 Subject: [PATCH 045/124] Improve admin sections --- includes/class-settings.php | 74 +++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/includes/class-settings.php b/includes/class-settings.php index c55c975..2248733 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -108,15 +108,29 @@ function register_settings() { add_settings_section( 'section_general', esc_attr__( 'Global Settings', 'off-canvas-sidebars' ), - array( $this, 'register_general_settings' ), + '', $this->settings_tab ); + add_settings_section( + 'section_frontend', + esc_attr__( 'Frontend Settings', 'off-canvas-sidebars' ), + '', + $this->settings_tab + ); + add_settings_section( + 'section_admin', + esc_attr__( 'Admin Settings', 'off-canvas-sidebars' ), + '', + $this->settings_tab + ); + + $this->register_general_settings(); // Register sidebar settings - foreach ( $this->general_settings['sidebars'] as $sidebar => $sidebar_data ) { + foreach ( $this->settings['sidebars'] as $sidebar => $sidebar_data ) { add_settings_section( 'section_sidebar_'.$sidebar, - __( 'Off-Canvas Sidebar', 'off-canvas-sidebars' ) . ' - ' . $this->general_settings['sidebars'][ $sidebar ]['label'] . '', + __( 'Off-Canvas Sidebar', 'off-canvas-sidebars' ) . ' - ' . $this->settings['sidebars'][ $sidebar ]['label'] . '', array( $this, 'register_general_settings' ), $this->sidebars_tab ); @@ -126,13 +140,32 @@ function register_settings() { do_action( 'off_canvas_sidebar_settings' ); } + /** + * General settings + * @since 0.1 + */ function register_general_settings() { + + /* + * General + */ + add_settings_field( + 'enabled_sidebars', + esc_attr__( 'Enable Sidebars', 'off-canvas-sidebars' ), + array( $this, 'enabled_sidebars_option' ), + $this->settings_tab, + 'section_general' + ); + + /* + * Frontend + */ add_settings_field( 'enable_frontend', esc_attr__( 'Enable front-end', 'off-canvas-sidebars' ), array( $this, 'checkbox_option' ), $this->settings_tab, - 'section_general', + 'section_frontend', array( 'name' => 'enable_frontend', 'label' => __( 'Let this plugin add the necessary elements on the front-end.', 'off-canvas-sidebars' ), @@ -144,33 +177,26 @@ function register_general_settings() { esc_attr__( 'Front-end type', 'off-canvas-sidebars' ), array( $this, 'frontend_type_option' ), $this->settings_tab, - 'section_general' + 'section_frontend' );*/ add_settings_field( 'css_prefix', esc_attr__( 'CSS Prefix', 'off-canvas-sidebars' ), array( $this, 'text_option' ), $this->settings_tab, - 'section_general', + 'section_frontend', array( 'name' => 'css_prefix', 'label' => __( 'Default', 'off-canvas-sidebars' ) . ': ocs', 'placeholder' => 'ocs', ) ); - add_settings_field( - 'enabled_sidebars', - esc_attr__( 'Enable Sidebars', 'off-canvas-sidebars' ), - array( $this, 'enabled_sidebars_option' ), - $this->settings_tab, - 'section_general' - ); add_settings_field( 'site_close', esc_attr__( 'Close sidebar when clicking on the site', 'off-canvas-sidebars' ), array( $this, 'checkbox_option' ), $this->settings_tab, - 'section_general', + 'section_frontend', array( 'name' => 'site_close', 'label' => __( 'Enables closing of a off-canvas sidebar by clicking on the site. Default: true.', 'off-canvas-sidebars' ) @@ -181,7 +207,7 @@ function register_general_settings() { esc_attr__( 'Disable over', 'off-canvas-sidebars' ), array( $this, 'number_option' ), $this->settings_tab, - 'section_general', + 'section_frontend', array( 'name' => 'disable_over', 'description' => __( 'Disable off-canvas sidebars over specified screen width. Leave blank to disable.', 'off-canvas-sidebars' ), @@ -193,7 +219,7 @@ function register_general_settings() { esc_attr__( 'Auto-hide control classes', 'off-canvas-sidebars' ), array( $this, 'checkbox_option' ), $this->settings_tab, - 'section_general', + 'section_frontend', array( 'name' => 'hide_control_classes', 'label' => __( 'Hide off-canvas sidebar control classes over width specified in "Disable over". Default: false.', 'off-canvas-sidebars' ) @@ -204,7 +230,7 @@ function register_general_settings() { esc_attr__( 'Scroll lock', 'off-canvas-sidebars' ), array( $this, 'checkbox_option' ), $this->settings_tab, - 'section_general', + 'section_frontend', array( 'name' => 'scroll_lock', 'label' => __( 'Prevent site content scrolling whilst a off-canvas sidebar is open. Default: false.', 'off-canvas-sidebars' ) @@ -215,7 +241,7 @@ function register_general_settings() { esc_attr__( 'Background color', 'off-canvas-sidebars' ), array( $this, 'color_option' ), $this->settings_tab, - 'section_general', + 'section_frontend', array( 'name' => 'background_color', 'description' => __( 'Choose a background color for the site container. Default: #ffffff.', 'off-canvas-sidebars' ) @@ -227,10 +253,10 @@ function register_general_settings() { if ( '' != apply_filters( 'ocs_website_before_hook', '' ) ) { add_settings_field( 'website_before_hook', - esc_attr__( 'website_before hook name', 'off-canvas-sidebars' ), + 'website_before ' . esc_attr__( 'hook name', 'off-canvas-sidebars' ), array( $this, 'text_option' ), $this->settings_tab, - 'section_general', + 'section_frontend', array( 'name' => 'website_before_hook', 'placeholder' => 'website_before' @@ -241,10 +267,10 @@ function register_general_settings() { if ( '' != apply_filters( 'ocs_website_after_hook', '' ) ) { add_settings_field( 'website_after_hook', - esc_attr__( 'website_after hook name', 'off-canvas-sidebars' ), + 'website_after ' . esc_attr__( 'hook name', 'off-canvas-sidebars' ), array( $this, 'text_option' ), $this->settings_tab, - 'section_general', + 'section_frontend', array( 'name' => 'website_after_hook', 'placeholder' => 'website_after' @@ -258,7 +284,7 @@ function register_general_settings() { esc_attr__( 'Use the FastClick library?', 'off-canvas-sidebars' ), array( $this, 'checkbox_option' ), $this->settings_tab, - 'section_general', + 'section_frontend', array( 'name' => 'use_fastclick', 'label' => __( 'Yes. Default: disabled', 'off-canvas-sidebars' ), @@ -271,7 +297,7 @@ function register_general_settings() { esc_attr__( 'Compatibility for fixed elements', 'off-canvas-sidebars' ), array( $this, 'radio_option' ), $this->settings_tab, - 'section_general', + 'section_frontend', array( 'name' => 'compatibility_position_fixed', 'default' => 'none', From 47d0d78bc309330e8fddbab40e99ea14b46ab397 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Fri, 13 Jan 2017 05:20:48 +0100 Subject: [PATCH 046/124] Genesis compat fix --- includes/class-settings.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/class-settings.php b/includes/class-settings.php index 2248733..4c58ebc 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -248,9 +248,9 @@ function register_general_settings() { ) ); // Genesis already has before and after hooks set - if ( get_template() != 'genesis' ) { + if ( get_template() !== 'genesis' ) { // Check if the before hook is filtered. If it is this setting is not needed - if ( '' != apply_filters( 'ocs_website_before_hook', '' ) ) { + if ( '' == apply_filters( 'ocs_website_before_hook', '' ) ) { add_settings_field( 'website_before_hook', 'website_before ' . esc_attr__( 'hook name', 'off-canvas-sidebars' ), @@ -264,7 +264,7 @@ function register_general_settings() { ); } // Check if the after hook is filtered. If it is this setting is not needed - if ( '' != apply_filters( 'ocs_website_after_hook', '' ) ) { + if ( '' == apply_filters( 'ocs_website_after_hook', '' ) ) { add_settings_field( 'website_after_hook', 'website_after ' . esc_attr__( 'hook name', 'off-canvas-sidebars' ), From e3af2bed638a8b49c2964d7e0ddfb30e57851843 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Fri, 13 Jan 2017 08:42:42 +0100 Subject: [PATCH 047/124] Typo --- slidebars/slidebars.css | 2 +- slidebars/slidebars.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/slidebars/slidebars.css b/slidebars/slidebars.css index ba7936d..a8e23ee 100644 --- a/slidebars/slidebars.css +++ b/slidebars/slidebars.css @@ -50,7 +50,7 @@ html, body { } /** - * Off-Canavs + * Off-Canvas */ [off-canvas] { diff --git a/slidebars/slidebars.js b/slidebars/slidebars.js index 32761be..2aa147c 100644 --- a/slidebars/slidebars.js +++ b/slidebars/slidebars.js @@ -140,7 +140,7 @@ slidebars = function () { // Make sure a valid id, side and style are specified if ( ! parameters || ! parameters[ 0 ] || sides.indexOf( parameters[ 1 ] ) === -1 || styles.indexOf( parameters[ 2 ] ) === -1 ) { - throw "Error registering Slidebar, please specifiy a valid id, side and style'."; + throw "Error registering Slidebar, please specify a valid id, side and style'."; } // Register Slidebar From 65cfe01281bef1f5736528a6029bca20975e4e1d Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Fri, 13 Jan 2017 08:43:14 +0100 Subject: [PATCH 048/124] Improve show/hide + UI in settings page --- css/off-canvas-sidebars-admin.css | 2 ++ js/off-canvas-sidebars-settings.js | 41 +++++++++++++++++------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/css/off-canvas-sidebars-admin.css b/css/off-canvas-sidebars-admin.css index 59d3cf0..7732c22 100644 --- a/css/off-canvas-sidebars-admin.css +++ b/css/off-canvas-sidebars-admin.css @@ -17,6 +17,8 @@ .ocs-credits .inner { padding-left: 10px; padding-right: 10px; } .ocs-credits h3 { font-size: 14px; line-height: 1.4; margin: 0; padding: 8px 12px; border-bottom: 1px solid #eee; } +.off-canvas-sidebars-settings .postbox-container { float: none; } + .postbox.section-sidebar { -webkit-transition: all .1s; -moz-transition: all .1s; diff --git a/js/off-canvas-sidebars-settings.js b/js/off-canvas-sidebars-settings.js index a4a25d7..e381df7 100644 --- a/js/off-canvas-sidebars-settings.js +++ b/js/off-canvas-sidebars-settings.js @@ -33,6 +33,7 @@ if ( typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS == 'undefined' ) { var sidebar_id = $(this).attr('id').replace('section_sidebar_', ''); ocs_show_hide_options_radio( '.off_canvas_sidebars_options_sidebars_' + sidebar_id + '_background_color_type', '.off_canvas_sidebars_options_sidebars_' + sidebar_id + '_background_color_wrapper', 'color', false ); + ocs_show_hide_options_radio( '.off_canvas_sidebars_options_sidebars_' + sidebar_id + '_location', '#off_canvas_sidebars_options_sidebars_' + sidebar_id + '_style_reveal, #off_canvas_sidebars_options_sidebars_' + sidebar_id + '_style_shift', [ 'left', 'right' ], 'label' ); ocs_show_hide_options( '.off_canvas_sidebars_options_sidebars_' + sidebar_id + '_overwrite_global_settings', '.off_canvas_sidebars_options_sidebars_' + sidebar_id + '_site_close', 'tr' ); ocs_show_hide_options( '.off_canvas_sidebars_options_sidebars_' + sidebar_id + '_overwrite_global_settings', '.off_canvas_sidebars_options_sidebars_' + sidebar_id + '_disable_over', 'tr' ); @@ -45,50 +46,56 @@ if ( typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS == 'undefined' ) { function ocs_show_hide_options( trigger, target, parent ) { - if ( ! $(trigger).is(':checked') ) { + if ( ! $( trigger ).is(':checked') ) { if ( parent ) { - $(target).closest(parent).slideUp('fast'); + $( target ).closest( parent ).slideUp('fast'); } else { - $(target).slideUp('fast'); + $( target ).slideUp('fast'); } } - $(trigger).change( function() { + $( trigger ).change( function() { if ( $(this).is(':checked') ) { if ( parent ) { - $(target).closest(parent).slideDown('fast'); + $( target ).closest( parent ).slideDown('fast'); } else { - $(target).slideDown('fast'); + $( target ).slideDown('fast'); } } else { if ( parent ) { - $(target).closest(parent).slideUp('fast'); + $( target ).closest( parent ).slideUp('fast'); } else { - $(target).slideUp('fast'); + $( target ).slideUp('fast'); } } }); } function ocs_show_hide_options_radio( trigger, target, compare, parent ) { - if ( $(trigger).val() != compare ) { + if ( ! $.isArray( compare ) ) { + compare = [ compare ]; + } + if ( parent ) { + parent += ', ' + parent + ' + br'; + } + if ( $.inArray( $( trigger + ':checked' ).val(), compare ) < 0 ) { if ( parent ) { - $(target).closest(parent).slideUp('fast'); + $( target ).closest( parent ).slideUp('fast'); } else { - $(target).slideUp('fast'); + $( target ).slideUp('fast'); } } - $(trigger).change( function() { - if ($(this).val() == compare) { + $( trigger ).change( function() { + if ( $.inArray( $( trigger + ':checked' ).val(), compare ) >= 0 ) { if ( parent ) { - $(target).closest(parent).slideDown('fast'); + $( target ).closest( parent ).slideDown('fast'); } else { - $(target).slideDown('fast'); + $( target ).slideDown('fast'); } } else { if ( parent ) { - $(target).closest(parent).slideUp('fast'); + $( target ).closest( parent ).slideUp('fast'); } else { - $(target).slideUp('fast'); + $( target ).slideUp('fast'); } } }); From 00f13a2aacbe3e171af46a5d1535ab0b4cea0197 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Fri, 13 Jan 2017 08:44:12 +0100 Subject: [PATCH 049/124] Temp remove the use of minified files (still a dev state) --- includes/class-frontend.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/includes/class-frontend.php b/includes/class-frontend.php index ccb0e11..71d1475 100644 --- a/includes/class-frontend.php +++ b/includes/class-frontend.php @@ -448,13 +448,13 @@ public function do_control_trigger( $sidebar_id, $args = array() ) { * @return void */ function add_styles_scripts() { - $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; + $suffix = '';//defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; // @todo: create minified files $version = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? time() : OCS_PLUGIN_VERSION; wp_enqueue_style( 'slidebars', OCS_PLUGIN_URL . 'slidebars/slidebars'.$suffix.'.css', array(), '2.0.2' ); wp_enqueue_script( 'slidebars', OCS_PLUGIN_URL . 'slidebars/slidebars'.$suffix.'.js', array( 'jquery' ), '2.0.2', true ); - wp_enqueue_style( 'off-canvas-sidebars', OCS_PLUGIN_URL . 'css/off-canvas-sidebars.css', array(), $version ); // @todo: '.$suffix.' - wp_enqueue_script( 'off-canvas-sidebars', OCS_PLUGIN_URL . 'js/off-canvas-sidebars.js', array( 'jquery', 'slidebars' ), $version, true ); // @todo: '.$suffix.' + wp_enqueue_style( 'off-canvas-sidebars', OCS_PLUGIN_URL . 'css/off-canvas-sidebars'.$suffix.'.css', array(), $version ); + wp_enqueue_script( 'off-canvas-sidebars', OCS_PLUGIN_URL . 'js/off-canvas-sidebars'.$suffix.'.js', array( 'jquery', 'slidebars' ), $version, true ); $sidebars = array(); foreach ( $this->settings['sidebars'] as $sidebar_id => $sidebar_data ) { @@ -469,16 +469,17 @@ function add_styles_scripts() { 'scroll_lock' => ( $this->settings['scroll_lock'] ) ? true : false, 'legacy_css' => ( 'legacy-css' == $this->settings['compatibility_position_fixed'] ) ? true : false, 'css_prefix' => $this->settings['css_prefix'], - 'sidebars' => $sidebars + 'sidebars' => $sidebars, + '_debug' => ( defined('WP_DEBUG') && WP_DEBUG ) ? true : false, ) ); if ( 'custom-js' == $this->settings['compatibility_position_fixed'] ) { - wp_enqueue_script( 'ocs-fixed-scrolltop', OCS_PLUGIN_URL . 'js/fixed-scrolltop.js', array( 'jquery' ), $version, true ); + wp_enqueue_script( 'ocs-fixed-scrolltop', OCS_PLUGIN_URL . 'js/fixed-scrolltop'.$suffix.'.js', array( 'jquery' ), $version, true ); } // FastClick library https://github.com/ftlabs/fastclick if ( true === (bool) $this->settings['use_fastclick'] ) { - wp_enqueue_script( 'fastclick', OCS_PLUGIN_URL . 'js/fastclick.js', array(), false, true ); + wp_enqueue_script( 'fastclick', OCS_PLUGIN_URL . 'js/fastclick'.$suffix.'.js', array(), false, true ); } } From 8fdb7a0a177b3229eeb26e1113ef9643c810369f Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Fri, 13 Jan 2017 13:30:02 +0100 Subject: [PATCH 050/124] Add CSS vendors for more compatibility --- slidebars/slidebars.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/slidebars/slidebars.js b/slidebars/slidebars.js index 2aa147c..261598c 100644 --- a/slidebars/slidebars.js +++ b/slidebars/slidebars.js @@ -279,7 +279,12 @@ slidebars = function () { var animationProperties = getAnimationProperties( id ); // Apply css - var css = { 'transition-duration': animationProperties.duration + 'ms' }; + var css = { + '-webkit-transition-duration': animationProperties.duration + 'ms', + '-moz-transition-duration': animationProperties.duration + 'ms', + '-o-transition-duration': animationProperties.duration + 'ms', + 'transition-duration': animationProperties.duration + 'ms' + }; if ( self.legacy ) { css[ offCanvas[ id ].side ] = animationProperties.amount; @@ -293,7 +298,12 @@ slidebars = function () { canvasSide = 'top'; } // Move container - canvas.css( 'transition-duration', animationProperties.duration + 'ms' ); + canvas.css( { + '-webkit-transition-duration': animationProperties.duration + 'ms', + '-moz-transition-duration': animationProperties.duration + 'ms', + '-o-transition-duration': animationProperties.duration + 'ms', + 'transition-duration': animationProperties.duration + 'ms', + } ); canvas.css( canvasSide, '-' + animationProperties.amount ); // Open slidebar animationProperties.elements.not( canvas ).css( css ); @@ -398,7 +408,12 @@ slidebars = function () { // Transition completetion setTimeout( function () { // Remove transition duration - animationProperties.elements.css( 'transition-duration', '' ); + animationProperties.elements.css( { + '-webkit-transition-duration': '', + '-moz-transition-duration': '', + '-o-transition-duration': '', + 'transition-duration': '' + } ); // Hide the Slidebar offCanvas[ id ].element.css( 'display', '' ); From d261ee9abc998f4a51c8fb2e26f259b532107ee4 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Fri, 13 Jan 2017 13:32:40 +0100 Subject: [PATCH 051/124] Simplify amount calculation --- slidebars/slidebars.js | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/slidebars/slidebars.js b/slidebars/slidebars.js index 261598c..398b720 100644 --- a/slidebars/slidebars.js +++ b/slidebars/slidebars.js @@ -47,6 +47,7 @@ slidebars = function () { // Variables var elements = $(), amount = '0px, 0px', + size = '0px', duration = parseFloat( offCanvas[ id ].element.css( 'transitionDuration' ), 10 ) * 1000; // Elements to animate @@ -59,30 +60,23 @@ slidebars = function () { } // Amount to animate - if ( offCanvas[ id ].active ) { + if ( offCanvas[ id ].active || self.legacy ) { + if ( offCanvas[ id ].side === 'top' || offCanvas[ id ].side === 'bottom' ) { + size = offCanvas[ id ].element.css( 'height' ); + } else { + size = offCanvas[ id ].element.css( 'width' ); + } if ( self.legacy ) { - if ( offCanvas[ id ].side === 'top' ) { - //amount = offCanvas[ id ].element.css( 'height' ); - amount = offCanvas[ id ].element.css( 'margin-top' ).replace('-',''); - } else if ( offCanvas[ id ].side === 'right' ) { - //amount = offCanvas[ id ].element.css( 'width' ); - amount = offCanvas[ id ].element.css( 'margin-right' ).replace('-',''); - } else if ( offCanvas[ id ].side === 'bottom' ) { - //amount = offCanvas[ id ].element.css( 'height' ); - amount = offCanvas[ id ].element.css( 'margin-bottom' ).replace('-',''); - } else if ( offCanvas[ id ].side === 'left' ) { - //amount = offCanvas[ id ].element.css( 'width' ); - amount = offCanvas[ id ].element.css( 'margin-left' ).replace('-',''); - } + amount = size; } else { if ( offCanvas[ id ].side === 'top' ) { - amount = '0px, ' + offCanvas[ id ].element.css( 'height' ); + amount = '0px, ' + size; } else if ( offCanvas[ id ].side === 'right' ) { - amount = '-' + offCanvas[ id ].element.css( 'width' ) + ', 0px'; + amount = '-' + size + ', 0px'; } else if ( offCanvas[ id ].side === 'bottom' ) { - amount = '0px, -' + offCanvas[ id ].element.css( 'height' ); + amount = '0px, -' + size; } else if ( offCanvas[ id ].side === 'left' ) { - amount = offCanvas[ id ].element.css( 'width' ) + ', 0px'; + amount = size + ', 0px'; } } } From a88fabdc8c0171489b8279c024322e5f93e39906 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Fri, 13 Jan 2017 13:39:59 +0100 Subject: [PATCH 052/124] Combine jQuery selectors + _debug property --- js/off-canvas-sidebars.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/js/off-canvas-sidebars.js b/js/off-canvas-sidebars.js index 5af638d..65b05e0 100644 --- a/js/off-canvas-sidebars.js +++ b/js/off-canvas-sidebars.js @@ -16,7 +16,8 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { "scroll_lock": false, "legacy_css": false, "css_prefix": 'ocs', - "sidebars": {} + "sidebars": {}, + "_debug": false }; } @@ -27,6 +28,7 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { ocsOffCanvasSidebars.container = false; ocsOffCanvasSidebars._html = $( 'html' ); ocsOffCanvasSidebars._touchmove = false; + ocsOffCanvasSidebars._toolbar = $('body').hasClass('admin-bar'); ocsOffCanvasSidebars.init = function() { @@ -169,7 +171,7 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { * Compatibility with WP Admin Bar * @since 0.3.2 */ - if ( $('body').hasClass('admin-bar') ) { + if ( ocsOffCanvasSidebars._toolbar ) { $( window ).on('load resize', function() { var bodyOffset = $( 'body' ).offset(); $( '.' + ocsOffCanvasSidebars.css_prefix + '-slidebar' ).each( function() { @@ -297,10 +299,11 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { }; ocsOffCanvasSidebars.setupTriggers = function() { - var controller = ocsOffCanvasSidebars.slidebarsController; - var prefix = ocsOffCanvasSidebars.css_prefix; + var controller = ocsOffCanvasSidebars.slidebarsController, + prefix = ocsOffCanvasSidebars.css_prefix, + sidebarElements = $( '.' + prefix + '-slidebar' ); - $( '.' + prefix + '-slidebar' ).each( function() { + sidebarElements.each( function() { var id = $( this ).attr( 'ocs-sidebar-id' ); ocsOffCanvasSidebars.setSidebarDefaultSettings( id ); @@ -408,7 +411,7 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { // Disable slidebars when the window is wider than the set width var disableOver = function() { var prefix = ocsOffCanvasSidebars.css_prefix; - $( '.' + prefix + '-slidebar' ).each( function() { + sidebarElements.each( function() { var id = $( this ).attr( 'ocs-sidebar-id' ); if ( ! ocsOffCanvasSidebars._checkDisableOver( prefix + '-' + id ) ) { From 52d504dd1f9b0164906bd14c38feca64039f5ed1 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Fri, 13 Jan 2017 13:40:32 +0100 Subject: [PATCH 053/124] Improve scroll_lock functionality --- css/off-canvas-sidebars.css | 3 --- js/off-canvas-sidebars.js | 19 +++++++++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/css/off-canvas-sidebars.css b/css/off-canvas-sidebars.css index fc23dcf..061d65c 100644 --- a/css/off-canvas-sidebars.css +++ b/css/off-canvas-sidebars.css @@ -21,9 +21,6 @@ html.ocs-initialized { height: auto; } -html.ocs-scroll-lock { - overflow-y: hidden; -} [canvas-fixed] { -webkit-transform: translate( 0px, 0px ); diff --git a/js/off-canvas-sidebars.js b/js/off-canvas-sidebars.js index 65b05e0..e96e516 100644 --- a/js/off-canvas-sidebars.js +++ b/js/off-canvas-sidebars.js @@ -431,8 +431,8 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { disableOver(); $( window ).on( 'resize', disableOver ); - // Disable scrolling on active sidebar - $( '#' + prefix + '-site' ).on( 'scroll touchmove mousewheel', function( e ) { + // Disable scrolling outside of active sidebar + $( '#' + prefix + '-site' ).on( 'scroll touchmove mousewheel DOMMouseScroll', function( e ) { //if ( ocsOffCanvasSidebars._getSetting( 'scroll_lock' ) && false != controller.getActiveSlidebar() ) { if ( ocsOffCanvasSidebars._html.hasClass( 'ocs-scroll-lock' ) ) { e.preventDefault(); @@ -441,6 +441,21 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { } } ); + // Disable scrolling site when scrolling inside active sidebar + sidebarElements.on( 'scroll touchmove mousewheel DOMMouseScroll', function( e ) { + //if ( ocsOffCanvasSidebars._getSetting( 'scroll_lock', false ) ) { + if ( ocsOffCanvasSidebars._html.hasClass( 'ocs-scroll-lock' ) ) { + var $this = $(this); + if ( e.originalEvent.deltaY < 0 ) { + /* scrolling up */ + return ( $this.scrollTop() > 0 ); + } else { + /* scrolling down */ + return ( $this.scrollTop() + $this.innerHeight() < $this[0].scrollHeight ); + } + } + } ); + }; if ( $( '#' + ocsOffCanvasSidebars.css_prefix + '-site' ).length && ( typeof slidebars != 'undefined' ) ) { From 4ad444a9f41e926ad86129d9b5900c8e7bec822c Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Fri, 13 Jan 2017 13:41:39 +0100 Subject: [PATCH 054/124] Remove invalid code + markup - Hook functions are replaced by window triggers - There is no `-ms-transition` - parseFloat doesn't accept a second parameter --- css/off-canvas-sidebars.css | 1 - js/off-canvas-sidebars.js | 24 ++++-------------------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/css/off-canvas-sidebars.css b/css/off-canvas-sidebars.css index 061d65c..c38eba4 100644 --- a/css/off-canvas-sidebars.css +++ b/css/off-canvas-sidebars.css @@ -39,7 +39,6 @@ html.ocs-initialized { transform: none; -webkit-transition: transform 300ms, top 300ms, bottom 300ms, left 300ms, right 300ms; -moz-transition: transform 300ms, top 300ms, bottom 300ms, left 300ms, right 300ms; - -ms-transition: transform 300ms, top 300ms, bottom 300ms, left 300ms, right 300ms; -o-transition: transform 300ms, top 300ms, bottom 300ms, left 300ms, right 300ms; transition: transform 300ms, top 300ms, bottom 300ms, left 300ms, right 300ms; } diff --git a/js/off-canvas-sidebars.js b/js/off-canvas-sidebars.js index e96e516..59045df 100644 --- a/js/off-canvas-sidebars.js +++ b/js/off-canvas-sidebars.js @@ -139,14 +139,6 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { $(window).trigger( 'ocs_loaded', this ); - /** - * Function call before initializing - * @since 0.3 - */ - if ( typeof ocsBeforeInitHook == 'function' ) { - ocsBeforeInitHook(); - } - // Slidebars constructor ocsOffCanvasSidebars.slidebarsController = new slidebars(); @@ -193,7 +185,7 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { */ $( ocsOffCanvasSidebars.slidebarsController.events ).on( 'opening opened closing closed', function( e, sidebar_id ) { var slidebar = ocsOffCanvasSidebars.slidebarsController.getSlidebar( sidebar_id ); - var duration = parseFloat( slidebar.element.css( 'transitionDuration' ), 10 ) * 1000; + var duration = parseFloat( slidebar.element.css( 'transitionDuration' ) /*, 10*/ ) * 1000; if ( slidebar.side == 'top' || slidebar.side == 'bottom' ) { var elements = $('#' + ocsOffCanvasSidebars.css_prefix + '-site *').filter( function(){ return $(this).css('position') === 'fixed'; } ); elements.attr( { 'canvas-fixed': 'fixed' } ); @@ -215,11 +207,11 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { '-o-transition': 'top ' + duration + 'ms', 'transition': 'top ' + duration + 'ms' } ); - $(this).css('top', parseInt( $(this).css('top').replace('px', '') ) + offset + 'px' ); + $(this).css( 'top', parseInt( $(this).css('top').replace('px', '') ) + offset + 'px' ); } // Remove animation - else if ( e.type == 'closing') { - $(this).css('top', parseInt( $(this).css('top').replace('px', '') ) - offset + 'px' ); + else if ( e.type == 'closing' ) { + $(this).css( 'top', parseInt( $(this).css('top').replace('px', '') ) - offset + 'px' ); setTimeout( function() { $(this).css( { '-webkit-transition': '', @@ -258,14 +250,6 @@ if ( typeof ocsOffCanvasSidebars == 'undefined' ) { } } ); - /** - * Function call after initializing - * @since 0.3 - */ - if ( typeof ocsAfterInitHook == 'function' ) { - ocsAfterInitHook(); - } - // Prevent swipe events to be seen as a click (bug in some browsers) $( document ).on( 'touchmove', function() { ocsOffCanvasSidebars._touchmove = true; From e9b40c7f29efc8937aadbcb312a8c2414f9bd554 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Fri, 13 Jan 2017 18:36:23 +0100 Subject: [PATCH 055/124] First version of the shortcode generator settings tab --- css/off-canvas-sidebars-admin.css | 8 ++ includes/class-settings.php | 194 +++++++++++++++++++++++++++-- js/off-canvas-sidebars-settings.js | 140 +++++++++++++++++++++ 3 files changed, 334 insertions(+), 8 deletions(-) diff --git a/css/off-canvas-sidebars-admin.css b/css/off-canvas-sidebars-admin.css index 7732c22..cff820f 100644 --- a/css/off-canvas-sidebars-admin.css +++ b/css/off-canvas-sidebars-admin.css @@ -43,6 +43,14 @@ margin: 10px -300px 10px 20px; width: 280px; } + + .off-canvas-sidebars-settings .postbox-container .postbox-third { + float: left; + width: 33%; + margin-left: 0.5%; + box-sizing: border-box; + } + .off-canvas-sidebars-settings .postbox-container .postbox-third.first { margin-left: 0;} } @media only screen and (min-width: 959px) { diff --git a/includes/class-settings.php b/includes/class-settings.php index 4c58ebc..a1ca9cb 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -23,6 +23,7 @@ final class OCS_Off_Canvas_Sidebars_Settings private $general_key = ''; private $settings_tab = 'ocs-settings'; private $sidebars_tab = 'ocs-sidebars'; + private $shortcode_tab = 'ocs-shortcode'; private $importexport_tab = 'ocs-importexport'; private $plugin_key = ''; private $plugin_tabs = array(); @@ -75,6 +76,7 @@ function enqueue_styles_scripts( $hook ) { wp_localize_script( 'off-canvas-sidebars-settings', 'OCS_OFF_CANVAS_SIDEBARS_SETTINGS', array( 'general_key' => $this->general_key, 'plugin_key' => $this->plugin_key, + 'css_prefix' => $this->settings['css_prefix'], '__required_fields_not_set' => __( 'Some required fields are not set!', 'off-canvas-sidebars' ), ) ); @@ -101,6 +103,7 @@ function add_admin_menus() { function register_settings() { $this->plugin_tabs[ $this->settings_tab ] = esc_attr__( 'Settings', 'off-canvas-sidebars' ); $this->plugin_tabs[ $this->sidebars_tab ] = esc_attr__( 'Sidebars', 'off-canvas-sidebars' ); + $this->plugin_tabs[ $this->shortcode_tab ] = esc_attr__( 'Shortcodes', 'off-canvas-sidebars' ); register_setting( $this->settings_tab, $this->general_key, array( $this, 'validate_input' ) ); register_setting( $this->sidebars_tab, $this->general_key, array( $this, 'validate_input' ) ); @@ -672,9 +675,16 @@ function text_option( $args ) { $prefixValue[ $args['name'] ] = $args['value']; } $classes = $this->get_option_classes( $prefixClasses, $args['name'] ); + if ( ! empty( $args['class'] ) ) { + $classes .= ' ' . $args['class']; + } ?>

@@ -720,7 +730,9 @@ function radio_option( $args ) { } $classes = $this->get_option_classes( $prefixClasses, $args['name'] ); ?>
- +
@@ -733,6 +745,37 @@ function radio_option( $args ) { } } + function select_option( $args ) { + $prefixes = $this->get_option_prefixes( $args ); + $prefixName = $prefixes['prefixName']; + $prefixValue = $prefixes['prefixValue']; + $prefixId = $prefixes['prefixId']; + $prefixClasses = $prefixes['prefixClasses']; + if ( isset( $args['name'] ) && isset( $args['options'] ) ) { + if ( isset( $args['value'] ) ) { + $prefixValue[ $args['name'] ] = $args['value']; + } + if ( ! empty( $args['default'] ) && empty( $prefixValue[ $args['name'] ] ) ) { + $prefixValue[ $args['name'] ] = $args['default']; + } + $classes = $this->get_option_classes( $prefixClasses, $args['name'] ); + ?>
+
+ +

+ +
get_option_prefixes( $args ); $prefixName = $prefixes['prefixName']; @@ -815,7 +858,7 @@ function get_option_prefixes( $args ) { function get_option_classes( $classes, $append ) { if ( $append ) { foreach ( $classes as $key => $class ) { - if ( ! in_array( $class, array( 'required' ) ) ) + if ( ! in_array( $class, array( 'required', 'widefat' ) ) ) $classes[ $key ] = $class . '_' . $append; } } @@ -1028,7 +1071,7 @@ function validate_checkbox( $value ) { /** * Validates radio values against the possible options * - * @since 0.3.2 + * @since 0.4 * * @param string $value * @param array $options @@ -1086,6 +1129,7 @@ function remove_whitespace( $value ) { */ function plugin_options_page() { $tab = isset( $_GET['tab'] ) ? $_GET['tab'] : $this->settings_tab; + $do_submit = ( in_array( $tab, array( $this->settings_tab, $this->sidebars_tab ) ) ) ? true : false; ?>

@@ -1095,7 +1139,7 @@ function plugin_options_page() {
- importexport_tab ) { ?> +

@@ -1115,12 +1159,13 @@ function plugin_options_page() {
do_settings_sections( $tab ); ?> + + shortcode_tab ) $this->shortcode_tab(); ?> + importexport_tab ) $this->importexport_tab(); ?>
- - importexport_tab ) $this->importexport_fields(); ?> - importexport_tab ) submit_button(); ?> + @@ -1228,7 +1273,140 @@ function plugin_options_tabs() { echo ''; } - function importexport_fields() { + function shortcode_tab() { + ?> +
+

:

+
+ +
+ '; + + echo '

' . __( 'Options', 'off-canvas-sidebars' ) . ':

'; + + echo '
'; + echo ''; + echo ''; + echo '
'; + + $sidebar_select = array(); + foreach( $this->settings['sidebars'] as $sidebar_id => $sidebar_data ) { + $sidebar_select[] = array( + 'value' => $sidebar_id, + 'label' => $sidebar_data['label'] + ); + } + $this->select_option( array( + 'name' => 'sidebar', + 'label' => __( 'Sidebar ID', 'off-canvas-sidebars' ), + 'description' => __( '(Required) The off-canvas sidebar ID', 'off-canvas-sidebars' ), + 'options' => $sidebar_select + ) ); + + echo '
'; + + $this->text_option( array( + 'name' => 'text', + 'label' => __( 'Text', 'off-canvas-sidebars' ), + 'value' => '', + 'class' => 'widefat', + 'description' => __( 'Limited HTML allowed', 'off-canvas-sidebars' ), + 'multiline' => true + ) ); + + echo '
'; + + echo '
'; + + echo '

' . __( 'Optional options', 'off-canvas-sidebars' ) . ':

'; + + echo '
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + + echo '
'; + + $this->select_option( array( + 'name' => 'action', + 'label' => __( 'Trigger action', 'off-canvas-sidebars' ), + 'options' => array( + array( + 'label' => __( 'Toggle', 'off-canvas-sidebars' ) . ' (' . __( 'Default', 'off-canvas-sidebars' ) . ')', + 'value' => '' + ), + array( 'label' => __( 'Open', 'off-canvas-sidebars' ), 'value' => 'open' ), + array( 'label' => __( 'Close', 'off-canvas-sidebars' ), 'value' => 'close' ), + ), + //'tooltip' => __( 'The trigger action. Default: toggle', 'off-canvas-sidebars' ), + ) ); + + echo '
'; + + $elements = array( 'button', 'span', 'a', 'b', 'strong', 'i', 'em', 'img', 'div' ); + $element_values = array(); + foreach ( $elements as $e ) { + $element_values[] = array( + 'value' => $e, + 'label' => '' . $e . '' + ); + } + $this->select_option( array( + 'name' => 'element', + 'label' => __( 'HTML element', 'off-canvas-sidebars' ), + 'options' => $element_values, + 'description' => __( 'Choose wisely', 'off-canvas-sidebars' ), + ) ); + + echo '
'; + + $this->text_option( array( + 'name' => 'class', + 'label' => __( 'Extra classes', 'off-canvas-sidebars' ), + 'value' => '', + 'class' => 'widefat', + 'description' => __( 'Separate multiple classes with a space', 'off-canvas-sidebars' ), + ) ); + + echo '
'; + + $this->text_option( array( + 'name' => 'attr', + 'label' => __( 'Custom attributes', 'off-canvas-sidebars' ), + 'value' => '', + 'class' => 'widefat', + 'description' => __( 'key : value ; key : value', 'off-canvas-sidebars' ), + 'multiline' => true + ) ); + + echo '
'; + + $this->checkbox_option( array( + 'name' => 'nested', + 'label' => __( 'Nested shortcode', 'off-canvas-sidebars' ) . '?', + 'value' => '', + 'description' => __( '[ocs_trigger text="Your text"] or [ocs_trigger]Your text[/ocs_trigger]', 'off-canvas-sidebars' ), + ) ); + + echo '
'; + ?> +
+

:

+
+
+
+

HTML:

+
+ +
+

diff --git a/js/off-canvas-sidebars-settings.js b/js/off-canvas-sidebars-settings.js index e381df7..78b7af2 100644 --- a/js/off-canvas-sidebars-settings.js +++ b/js/off-canvas-sidebars-settings.js @@ -11,6 +11,7 @@ if ( typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS == 'undefined' ) { var OCS_OFF_CANVAS_SIDEBARS_SETTINGS = { 'general_key': 'off_canvas_sidebars_options', 'plugin_key': 'off-canvas-sidebars-settings', + 'css_prefix': 'ocs', '__required_fields_not_set': '' //Some required fields are not set! }; } @@ -202,6 +203,145 @@ if ( typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS == 'undefined' ) { } + if ( tab.val() == 'ocs-shortcode' ) { + + var fields = [ 'sidebar', 'text', 'action', 'element', 'class', 'attr', 'nested' ]; + + for ( var i = 0, l = fields.length; i < l; i++ ) { + $( '#off_canvas_sidebars_options_' + fields[i] ).on( 'change keyup', function() { + create_shortcode(); + }); + } + + function create_shortcode() { + var field_data = {}; + for ( var i = 0, l = fields.length; i < l; i++ ) { + field_data[ fields[i] ] = $( '#off_canvas_sidebars_options_' + fields[i] ); + } + + var shortcode = 'ocs_trigger'; + + //start the shortcode tag + var shortcode_str = '[' + shortcode; + + // Loop through our known fields + for ( var field in field_data ) { + if ( typeof field_data[ field ] != 'undefined' ) { + if ( field != 'text' && field != 'nested' ) { + if ( field_data[ field ].is(':checked') ) { + shortcode_str += ' ' + field + '="1"'; + } else if ( field_data[ field ].val().length ) { + shortcode_str += ' ' + field + '="' + field_data[ field ].val().replace( /(\r\n|\n|\r)/gm, '' ) + '"'; + } + } + } + } + + // If the test contains a double quote, force it to be nested for compatibility + if ( field_data.text.val().length && field_data.text.val().indexOf( '"' ) !== -1 ) { + field_data.nested = true; + } + + //add panel text + if ( field_data.nested.is(':checked') ) { + shortcode_str += ']' + field_data.text.val() + '[/' + shortcode + ']'; + } else { + if ( field_data.text.val().length ) { + shortcode_str += ' text="' + field_data.text.val() + '"'; + } + shortcode_str += ']'; + } + + $('textarea#ocs_shortcode').val( shortcode_str ); + + create_shortcode_preview( field_data ); + } + + function create_shortcode_preview( field_data ) { + + var element = ( field_data.element.val() ) ? field_data.element.val() : 'button', + attributes = ( field_data.attr.val() ) ? attrStringToObject( field_data.attr.val() ) : {}, + prefix = OCS_OFF_CANVAS_SIDEBARS_SETTINGS.css_prefix, + action = ( field_data.action.val() ) ? field_data.action.val() : 'toggle'; + + var classes = prefix + '-trigger ' + prefix + '-' + action; + + if ( field_data.sidebar.val() ) { + classes += ' lekkerdan-' + action + '-' + field_data.sidebar.val(); + } + if ( field_data.class.val() ) { + classes += ' ' + field_data.class.val(); + } + if ( attributes.class ) { + classes += ' ' + attributes.class; + } + attributes.class = classes; + + var singleton = false; + if ( element == 'input' ) { + singleton = true; + attributes.value = field_data.text.val(); + } + if ( element == 'img' ) { + singleton = true; + attributes.value = field_data.text.val(); + } + + var html = ''; + if ( singleton ) { + html = '<' + element + ' ' + attrObjectToHTML( attributes ) + '>'; + } else { + html = '<' + element + ' ' + attrObjectToHTML( attributes ) + '>' + field_data.text.val() + ''; + } + + $( '#ocs_shortcode_preview' ).html( html ); + + $( '#ocs_shortcode_html' ).val( html ); + + } + + } + + /** + * Convert OCS formatted attribute string to object + * + * In: key:value;key:value + * Out: { key: value, key: value } + * + * @param attrString + * @returns Object + */ + function attrStringToObject( attrString ) { + var arr = attrString.split( ';' ), + atts = {}; + for ( var key in arr ) { + arr[ key ] = arr[ key ].split( ':' ); + if ( arr[ key ][ 0 ].trim().length ) { + var name = arr[ key ][ 0 ].trim(); + arr[ key ].splice( 0, 1 ); + atts[ name ] = arr[ key ].join( ':' ); + } + } + return atts; + } + + /** + * Convert object to OCS formatted attribute string + * + * In: { key: value, key: value } + * Out: key:value;key:value + * + * @param attrObj + * @returns String + */ + function attrObjectToHTML( attrObj ) { + var atts = []; + for ( var name in attrObj ) { + atts.push( name + '="' + attrObj[ name ] + '"' ); + } + return atts.join( ' ' ); + } + }; OCS_OFF_CANVAS_SIDEBARS_SETTINGS.init(); From c4ee9c2aa19460ec900a031c259d35c56b045416 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Sun, 15 Jan 2017 12:59:15 +0100 Subject: [PATCH 056/124] Doc updates and fixes --- includes/api.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/includes/api.php b/includes/api.php index 99f6ce2..f7cf98c 100644 --- a/includes/api.php +++ b/includes/api.php @@ -13,12 +13,13 @@ /** * Echos one, multiple or all OCS sidebars * + * @api * @since 0.3 - * @param string|array|bool $sidebars (Optional) The ID of this sidebar as configured in: Appearances > Off-Canvas Sidebars > Sidebars + * @param string|array $sidebars (Optional) The ID of this sidebar as configured in: Appearances > Off-Canvas Sidebars > Sidebars */ -function the_ocs_off_canvas_sidebar( $sidebars = false ) { +function the_ocs_off_canvas_sidebar( $sidebars = '' ) { if ( $instance = Off_Canvas_Sidebars_Frontend() ) { - if ( false === $sidebars ) { + if ( empty( $sidebars ) ) { $instance->do_sidebars(); } else { if ( is_array( $sidebars ) ) { @@ -35,6 +36,7 @@ function the_ocs_off_canvas_sidebar( $sidebars = false ) { /** * Output a trigger element for off-canvas sidebars * + * @api * @since 0.4 * @param array $atts { * Required array of arguments @@ -77,6 +79,7 @@ function the_ocs_control_trigger( $atts, $content = '' ) { } return $return; } + return ''; } /** @@ -137,7 +140,7 @@ function shortcode_ocs_trigger( $atts, $content = '' ) { * @return OCS_Off_Canvas_Sidebars_Frontend|false */ function Off_Canvas_Sidebars_Frontend() { - if ( class_exists( 'OCS_Off_Canvas_Sidebars_Frontend' ) ) { + if ( is_callable( array( 'OCS_Off_Canvas_Sidebars_Frontend', 'get_instance' ) ) ) { return OCS_Off_Canvas_Sidebars_Frontend::get_instance(); } return false; From 9fcb56d07ab0516a02b8447443bbd143cdd5f914 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Sun, 15 Jan 2017 13:36:47 +0100 Subject: [PATCH 057/124] Improve UI for radio and checkboxes --- css/off-canvas-sidebars-admin.css | 5 ++++ includes/class-settings.php | 44 ++++++++++++++++--------------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/css/off-canvas-sidebars-admin.css b/css/off-canvas-sidebars-admin.css index cff820f..4b5a10b 100644 --- a/css/off-canvas-sidebars-admin.css +++ b/css/off-canvas-sidebars-admin.css @@ -27,6 +27,11 @@ } .postbox.section-sidebar:hover { opacity: 1 !important; } +.off-canvas-sidebars-settings fieldset.radio label, +.off-canvas-sidebars-settings fieldset.checkbox label { display: block } + +.off-canvas-sidebars-settings input + select { vertical-align: top; } + @media only screen and (min-width: 850px) { .off-canvas-sidebars-settings { margin-right: 300px; diff --git a/includes/class-settings.php b/includes/class-settings.php index a1ca9cb..912aa56 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -558,8 +558,8 @@ function frontend_type_option( $args ) { $prefixName = $prefixes['prefixName']; $prefixValue = $prefixes['prefixValue']; $prefixId = $prefixes['prefixId']; - ?>
-
+ ?>
+

@@ -573,11 +573,11 @@ function enabled_sidebars_option() { $prefixId = $this->general_key.'_sidebars'; //$prefixClasses = array( $prefixId ); if ( ! empty( $this->settings['sidebars'] ) ) { - ?>
$sidebar_data) { //$classes = $this->get_option_classes( $prefixClasses, 'enable' ); ?> -
+ @@ -598,10 +598,10 @@ function sidebar_location( $args ) { $prefixClasses = $prefixes['prefixClasses']; if ( isset( $args['sidebar'] ) ) { $classes = $this->get_option_classes( $prefixClasses, 'location' ); - ?>
-
-
-
+ ?>
+ + +

@@ -618,12 +618,14 @@ function sidebar_size( $args ) { $prefixClasses = $prefixes['prefixClasses']; if ( isset( $args['sidebar'] ) ) { $classes = $this->get_option_classes( $prefixClasses, 'size' ); - ?>
-
-
-
- : -
+ ?>
+ + + +
+ : />
-
-
+ ?>
+ + +

@@ -704,7 +706,7 @@ function checkbox_option( $args ) { $prefixValue[ $args['name'] ] = $args['value']; } $classes = $this->get_option_classes( $prefixClasses, $args['name'] ); - ?>
+ ?>
@@ -729,13 +731,13 @@ function radio_option( $args ) { $prefixValue[ $args['name'] ] = $args['default']; } $classes = $this->get_option_classes( $prefixClasses, $args['name'] ); - ?>
+ ?>

+
From a85cb820715f5226a0ba8cfb80e0ad53607cec48 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Sun, 15 Jan 2017 13:38:14 +0100 Subject: [PATCH 058/124] Better access handling - Set capability at admin_init() - Check capability again before on import --- includes/class-settings.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/includes/class-settings.php b/includes/class-settings.php index 912aa56..dc14218 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -29,6 +29,7 @@ final class OCS_Off_Canvas_Sidebars_Settings private $plugin_tabs = array(); private $settings = array(); private $general_labels = array(); + private $capability = 'edit_theme_options'; /** * @since 0.1 @@ -53,6 +54,14 @@ function load_plugin_data() { $this->settings = $off_canvas_sidebars->get_settings(); $this->general_labels = $off_canvas_sidebars->get_general_labels(); $this->general_key = $off_canvas_sidebars->get_general_key(); + + /** + * Change the capability for the OCS settings + * @since 1.4 + * @param string + * @return string + */ + $this->capability = apply_filters( 'ocs_settings_capability', $this->capability ); } /** @@ -90,7 +99,7 @@ function add_admin_menus() { add_theme_page( esc_attr__( 'Off-Canvas Sidebars', 'off-canvas-sidebars' ), esc_attr__( 'Off-Canvas Sidebars', 'off-canvas-sidebars' ), - apply_filters( 'ocs_settings_capability', 'edit_theme_options' ), + $this->capability, $this->plugin_key, array( $this, 'plugin_options_page' ) ); @@ -1425,6 +1434,13 @@ function importexport_tab() { function register_importexport_settings() { $this->plugin_tabs[ $this->importexport_tab ] = esc_attr__( 'Import/Export', 'off-canvas-sidebars' ); + /** + * Filter documented in $this->load_plugin_data() + */ + if ( ! current_user_can( $this->capability ) ) { + return; + } + if ( isset( $_GET['gocs_message'] ) ) { $gocs_message_class = ''; From 8c087c8ccceb3d107b64c22be453f5f730b0286a Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Sun, 15 Jan 2017 14:36:18 +0100 Subject: [PATCH 059/124] UI improvements for OCS widget - See #27 --- widgets/control-widget.php | 135 ++++++++++++++++++++++++++++++------- 1 file changed, 109 insertions(+), 26 deletions(-) diff --git a/widgets/control-widget.php b/widgets/control-widget.php index e01cbd5..701aa8b 100644 --- a/widgets/control-widget.php +++ b/widgets/control-widget.php @@ -57,10 +57,11 @@ public function widget( $args, $instance ) { $prefix = $this->settings['css_prefix']; // outputs the content of the widget - echo $args['before_widget'].'
'; + echo $args['before_widget']; ?> -
+
+
settings['sidebars'] as $sidebar_id => $sidebar_data ) { if ( $sidebar_data['enable'] == 1 && $instance[ $this->widget_setting ][ $sidebar_id ]['enable'] == 1 ) { @@ -71,6 +72,7 @@ public function widget( $args, $instance ) { $prefix . '-toggle-' . $sidebar_id ); if ( $widget_data['button_class'] == 1 ) { + //$classes[] = $prefix . '-button'; $classes[] = 'button'; } ?> @@ -92,9 +94,10 @@ public function widget( $args, $instance ) {
+
'.$args['after_widget']; + echo $args['after_widget']; } /** @@ -107,15 +110,16 @@ public function form( $instance ) { $off_canvas_sidebars = Off_Canvas_Sidebars(); $this->load_plugin_data(); $instance = $this->merge_settings( $instance ); + $field_id = $this->get_field_id( $this->widget_setting ); ?> -

-   +

+   settings['sidebars'] as $sidebar_id => $value ) { if ( empty( $this->settings['sidebars'][ $sidebar_id ]['enable'] ) ) { continue; } ?> -   +  

@@ -129,39 +133,60 @@ public function form( $instance ) {
+ + +
settings['sidebars'] as $sidebar_id => $value ) { if ( empty( $this->settings['sidebars'][ $sidebar_id ]['enable'] ) ) { continue; } - $hidden = ''; - if ( empty( $instance[ $this->widget_setting ][ $sidebar_id ]['enable'] ) ) { + //$hidden = ''; + //if ( empty( $instance[ $this->widget_setting ][ $sidebar_id ]['enable'] ) ) { $hidden = 'style="display:none;"'; - } + //} ?> -
> -

+
> +

- widget_setting ][ $sidebar_id ]['show_label'], 1 ); ?>> - + widget_setting ][ $sidebar_id ]['show_label'], 1 ); ?>> +

-

widget_setting ][ $sidebar_id ]['show_label'] != 1)?'style="display: none;"':''; ?>> - - +

widget_setting ][ $sidebar_id ]['show_label'] != 1)?'style="display: none;"':''; ?>> + +

- widget_setting ][ $sidebar_id ]['show_icon'], 1 ); ?>> - + widget_setting ][ $sidebar_id ]['show_icon'], 1 ); ?>> +

-

widget_setting ][ $sidebar_id ]['show_icon'] != 1)?'style="display: none;"':''; ?>> - - +

widget_setting ][ $sidebar_id ]['show_icon'] != 1)?'style="display: none;"':''; ?>> + +

- widget_setting ][ $sidebar_id ]['button_class'], 1 ); ?>> - + widget_setting ][ $sidebar_id ]['button_class'], 1 ); ?>> +


+

@@ -170,15 +195,73 @@ public function form( $instance ) {

+ - + widget_setting => array() + $this->widget_setting => array(), ); foreach ( $this->settings['sidebars'] as $key => $value ) { $defaults[ $this->widget_setting ][ $key ] = array( - 'enable' => 0, - 'show_label' => 0, - 'label' => 'menu', - 'show_icon' => 1, - 'icon' => false, - 'button_class' => 1 + 'enable' => 0, + 'show_label' => 0, + 'label' => 'menu', + 'show_icon' => 1, + 'icon' => false, + 'button_class' => 1, ); }; From d0ea64d1706a56bf9cd9198ffe88bc55dfbadac2 Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Sat, 29 Apr 2017 20:14:56 +0200 Subject: [PATCH 061/124] Plugin info block --- off-canvas-sidebars.php | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/off-canvas-sidebars.php b/off-canvas-sidebars.php index 80620ec..4db30b6 100644 --- a/off-canvas-sidebars.php +++ b/off-canvas-sidebars.php @@ -1,18 +1,26 @@ + * @package Off_Canvas_Sidebars + * @since 0.1 + * @version 0.4-dev + * @licence GPL-2.0+ + * @link https://github.com/JoryHogeveen/off-canvas-sidebars + * + * @wordpress-plugin + * Plugin Name: Off-Canvas Sidebars + * Description: Add off-canvas sidebars using the Slidebars jQuery plugin + * Plugin URI: https://wordpress.org/plugins/off-canvas-sidebars/ + * Version: 0.4-dev + * Author: Jory Hogeveen + * Author URI: http://www.keraweb.nl + * Text Domain: off-canvas-sidebars + * Domain Path: /languages/ + * License: GPL-2.0+ + * License URI: http://www.gnu.org/licenses/gpl-2.0.html + * GitHub Plugin URI: https://github.com/JoryHogeveen/off-canvas-sidebars + * + * @copyright 2015-2017 Jory Hogeveen * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by From 2920309b3ef184ffa5fb92418b6cd43d619b64b4 Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Sat, 29 Apr 2017 20:15:06 +0200 Subject: [PATCH 062/124] Minimum WP version 4.1 --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index 79be980..ff24458 100644 --- a/readme.txt +++ b/readme.txt @@ -2,7 +2,7 @@ Contributors: keraweb Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=YGPLMLU7XQ9E8&lc=NL&item_name=Off%2dCanvas%20Sidebars&item_number=JWPP%2dOCS¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted Tags: genesis, off-canvas, menus, widgets, sidebars, slidebars, jQuery, app, mobile, tablet, responsive -Requires at least: 3.8 +Requires at least: 4.1 Tested up to: 4.6 Stable tag: 0.3.1.1 From a782027320b6f0a19d2217e8a2d11c2f7eabf7f4 Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Sat, 29 Apr 2017 21:22:15 +0200 Subject: [PATCH 063/124] Improve code readability + some bug fixes --- widgets/control-widget.php | 124 +++++++++++++++++++++++-------------- 1 file changed, 79 insertions(+), 45 deletions(-) diff --git a/widgets/control-widget.php b/widgets/control-widget.php index 1cdcc54..9774394 100644 --- a/widgets/control-widget.php +++ b/widgets/control-widget.php @@ -112,6 +112,8 @@ public function form( $instance ) { $off_canvas_sidebars = off_canvas_sidebars(); $this->load_plugin_data(); $instance = $this->merge_settings( $instance ); + + $ocs = $instance[ $this->widget_setting ]; $field_id = $this->get_field_id( $this->widget_setting ); ?>

@@ -145,9 +147,9 @@ public function form( $instance ) { if ( empty( $this->settings['sidebars'][ $sidebar_id ]['enable'] ) ) { continue; } - $class = ' ocs-tab'; - if ( empty( $instance[ $this->widget_setting ][ $sidebar_id ]['enable'] ) ) { - $class = ' disabled'; + $class = 'ocs-tab'; + if ( empty( $ocs[ $sidebar_id ]['enable'] ) ) { + $class .= ' disabled'; } ?>

@@ -164,29 +166,30 @@ public function form( $instance ) { continue; } //$hidden = ''; - //if ( empty( $instance[ $this->widget_setting ][ $sidebar_id ]['enable'] ) ) { + //if ( empty( $ocs[ $sidebar_id ]['enable'] ) ) { $hidden = 'style="display:none;"'; //} ?>
>

- widget_setting ][ $sidebar_id ]['show_label'], 1 ); ?>> + >

-

widget_setting ][ $sidebar_id ]['show_label'] ) ? 'style="display: none;"' : ''; ?>> +

> - + +

- widget_setting ][ $sidebar_id ]['show_icon'], 1 ); ?>> + >

-

widget_setting ][ $sidebar_id ]['show_icon'] ) ? 'style="display: none;"' : ''; ?>> +

> - +

- widget_setting ][ $sidebar_id ]['button_class'], 1 ); ?>> + >


@@ -236,7 +239,7 @@ public function form( $instance ) { - - Date: Fri, 25 Aug 2017 17:03:47 +0200 Subject: [PATCH 095/124] More style fixes --- includes/class-settings.php | 52 +++++++++++++++++++++---------------- widgets/control-widget.php | 3 ++- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/includes/class-settings.php b/includes/class-settings.php index 0d0bc56..f80d9ef 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -880,25 +880,29 @@ public function plugin_options_page() { $do_submit = ( in_array( $this->tab, array( $this->settings_tab, $this->sidebars_tab ), true ) ) ? true : false; ?>
-

+

plugin_options_tabs(); ?> -
+
-
+

- + tab === $this->settings_tab ) { ?> -

click here for documentation.', 'off-canvas-sidebars' ), 'https://wordpress.org/plugins/off-canvas-sidebars/installation/' ); ?>

+

+ click here for documentation.', 'off-canvas-sidebars' ), 'https://wordpress.org/plugins/off-canvas-sidebars/installation/' ); + ?> +

general_labels['compatibility_notice_theme']; ?>

tab === $this->sidebars_tab ) { ?>

- +

@@ -920,30 +924,32 @@ public function plugin_options_page() {
-

+

-

+

- Documentation or talk about them in the Support forum', 'off-canvas-sidebars' ), 'https://wordpress.org/plugins/off-canvas-sidebars/installation/', 'https://wordpress.org/support/plugin/off-canvas-sidebars' ) ?> + Documentation or talk about them in the Support forum', 'off-canvas-sidebars' ), 'https://wordpress.org/plugins/off-canvas-sidebars/installation/', 'https://wordpress.org/support/plugin/off-canvas-sidebars' ); + ?>


-

+

PayPal - The safer, easier way to pay online!

-
-
-
+
+
+


-

+

- +


- +
@@ -1029,7 +1035,7 @@ function plugin_options_tabs() { private function shortcode_tab() { ?>
-

:

+

:

@@ -1152,7 +1158,7 @@ private function shortcode_tab() { echo '
'; ?>
-

:

+

:

@@ -1171,12 +1177,12 @@ private function importexport_tab() { ?>

-

+

- + plugin_key . '-submit', false ); ?> - +

- Date: Mon, 28 Aug 2017 17:55:16 +0200 Subject: [PATCH 096/124] Fix esLint issues --- js/fixed-scrolltop.js | 2 +- js/off-canvas-sidebars-settings.js | 22 +++++++++--------- js/off-canvas-sidebars.js | 21 +++++++++-------- slidebars/slidebars.js | 36 +++++++++++++++--------------- 4 files changed, 42 insertions(+), 39 deletions(-) diff --git a/js/fixed-scrolltop.js b/js/fixed-scrolltop.js index 6defc4e..e282a57 100644 --- a/js/fixed-scrolltop.js +++ b/js/fixed-scrolltop.js @@ -60,7 +60,7 @@ }; ocsOffCanvasSidebars.scrollTopFixed = function() { - if ( curScrollTopElements.length > 0 ) { + if ( curScrollTopElements.length ) { var scrollTop = scrollTarget.scrollTop(), winHeight = $window.height(), gblOffset = $body.offset(), diff --git a/js/off-canvas-sidebars-settings.js b/js/off-canvas-sidebars-settings.js index 6ecef29..4fe1d3a 100644 --- a/js/off-canvas-sidebars-settings.js +++ b/js/off-canvas-sidebars-settings.js @@ -262,7 +262,7 @@ if ( 'undefined' === typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS ) { } // If the test contains a double quote, force it to be nested for compatibility - if ( field_data.text.val().length && field_data.text.val().indexOf( '"' ) !== -1 ) { + if ( field_data.text.val().length && -1 < field_data.text.val().indexOf( '"' ) ) { field_data.nested = true; } @@ -284,7 +284,7 @@ if ( 'undefined' === typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS ) { /** * Parses the shortcode data for a HTML preview. * @since 0.4 - * @param {object} field_data + * @param {object} field_data The shortcode data. * @return {null} Nothing. */ function create_shortcode_preview( field_data ) { @@ -336,8 +336,8 @@ if ( 'undefined' === typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS ) { * Out: { key: value, key: value } * * @since 0.4 - * @param {string} attrString - * @return {object} + * @param {string} attrString The attribute string. + * @return {object} The attribute object. */ function attrHTMLToObject( attrString ) { var arr = attrString.trim().split( '" ' ), @@ -360,8 +360,8 @@ if ( 'undefined' === typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS ) { * Out: { key: value, key: value } * * @since 0.4 - * @param {string} attrString - * @return {object} + * @param {string} attrString The attribute string. + * @return {object} The attribute object. */ function attrStringToObject( attrString ) { var arr = attrString.split( ';' ), @@ -386,8 +386,8 @@ if ( 'undefined' === typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS ) { * Out: key="value" key="value" * * @since 0.4 - * @param {object} attrObj - * @return {string} + * @param {object} attrObj The attribute object. + * @return {string} The attribute string. */ function attrObjectToHTML( attrObj ) { var atts = []; @@ -406,8 +406,8 @@ if ( 'undefined' === typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS ) { * Out: key:value;key:value * * @since 0.4 - * @param {object} attrObj - * @return {string} + * @param {object} attrObj The attribute object. + * @return {string} The attribute string. */ function attrObjectToString( attrObj ) { var atts = []; @@ -424,7 +424,7 @@ if ( 'undefined' === typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS ) { * @param {string} s The string. * @param {string} a The attribute to find. * @param {bool} f @todo - * @return {string|bool} + * @return {string|bool} The attribute value or false. */ function getAttr( s, a, f ) { var n = new RegExp( a + '=\"([^\"]+)\"', 'g' ).exec( s ); diff --git a/js/off-canvas-sidebars.js b/js/off-canvas-sidebars.js index 1814f4a..156cccd 100644 --- a/js/off-canvas-sidebars.js +++ b/js/off-canvas-sidebars.js @@ -41,7 +41,7 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { * Validate the disable_over setting ( using _getSetting() ) * Internal function, do not overwrite * @since 0.3 - * @param {string} sidebarId + * @param {string} sidebarId The sidebar ID. * @return {bool} disableOver status. */ ocsOffCanvasSidebars._checkDisableOver = function( sidebarId ) { @@ -61,8 +61,10 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { * Internal function, do not overwrite * @since 0.3 - * @param key the setting key to look for - * @param sidebarId bool|null|string false = check for an active slidebar, null or no value = only the global setting + * @param {string} key The setting key to look for + * @param {string|bool|null} sidebarId The sidebar ID. + * Pass `false` to check for an active slidebar. + * Pass `null` or no value for only the global setting. * @return {string|bool} The setting or false. */ ocsOffCanvasSidebars._getSetting = function( key, sidebarId ) { @@ -270,6 +272,7 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { /** * Set the default settings for sidebars if they are not found. * @since 0.3 + * @param {string} sidebarId The sidebar ID. * @return {null} Nothing. */ ocsOffCanvasSidebars.setSidebarDefaultSettings = function( sidebarId ) { @@ -441,9 +444,9 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { //if ( ocsOffCanvasSidebars._getSetting( 'scroll_lock', false ) ) { if ( ocsOffCanvasSidebars._html.hasClass( 'ocs-scroll-lock' ) ) { var $this = $(this); - if ( e.originalEvent.deltaY < 0 ) { + if ( 0 > e.originalEvent.deltaY ) { /* scrolling up */ - return ( $this.scrollTop() > 0 ); + return ( 0 < $this.scrollTop() ); } else { /* scrolling down */ return ( $this.scrollTop() + $this.innerHeight() < $this[0].scrollHeight ); @@ -460,16 +463,16 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { */ ocsOffCanvasSidebars.getFixedElements = function() { return $('#' + ocsOffCanvasSidebars.css_prefix + '-site *').filter( function() { - return $(this).css('position') === 'fixed'; + return ( 'fixed' === $(this).css('position') ); } ); }; /** * Automatically apply browser prefixes before setting CSS values. * @since 0.4 - * @param {object} elem - * @param {string} prop - * @param {string|number} value + * @param {object} elem The element. + * @param {string} prop The CSS property. + * @param {string|number} value The CSS property value. * @return {null} Nothing. */ ocsOffCanvasSidebars.cssCompat = function( elem, prop, value ) { diff --git a/slidebars/slidebars.js b/slidebars/slidebars.js index 5587b99..0341212 100644 --- a/slidebars/slidebars.js +++ b/slidebars/slidebars.js @@ -51,22 +51,22 @@ slidebars = function () { duration = parseFloat( offCanvas[ id ].element.css( 'transitionDuration' )/*, 10*/ ) * 1000; // Elements to animate - if ( offCanvas[ id ].style === 'reveal' || offCanvas[ id ].style === 'push' || offCanvas[ id ].style === 'shift' ) { + if ( 'reveal' === offCanvas[ id ].style || 'push' === offCanvas[ id ].style || 'shift' === offCanvas[ id ].style ) { elements = elements.add( canvas ); } // @todo, fix reveal support for top and bottom - if ( offCanvas[ id ].style === 'reveal' && ( offCanvas[ id ].side === 'top' || offCanvas[ id ].side === 'bottom' ) ) { + if ( 'reveal' === offCanvas[ id ].style && ( 'top' === offCanvas[ id ].side || 'bottom' === offCanvas[ id ].side ) ) { elements = elements.add( offCanvas[ id ].element ); } - if ( offCanvas[ id ].style === 'push' || offCanvas[ id ].style === 'overlay' || offCanvas[ id ].style === 'shift' ) { + if ( 'push' === offCanvas[ id ].style || 'overlay' === offCanvas[ id ].style || 'shift' === offCanvas[ id ].style ) { elements = elements.add( offCanvas[ id ].element ); } // Amount to animate if ( offCanvas[ id ].active || self.legacy ) { - if ( offCanvas[ id ].side === 'top' || offCanvas[ id ].side === 'bottom' ) { + if ( 'top' === offCanvas[ id ].side || 'bottom' === offCanvas[ id ].side ) { size = offCanvas[ id ].element.css( 'height' ); } else { size = offCanvas[ id ].element.css( 'width' ); @@ -74,7 +74,7 @@ slidebars = function () { if ( self.legacy ) { amount = size; } else { - if ( offCanvas[ id ].side === 'top' ) { + if ( 'top' === offCanvas[ id ].side ) { amount = '0px, ' + size; } else if ( offCanvas[ id ].side === 'right' ) { amount = '-' + size + ', 0px'; @@ -134,7 +134,7 @@ slidebars = function () { var parameters = $( this ).attr( 'off-canvas' ).split( ' ', 3 ); // Make sure a valid id, side and style are specified - if ( ! parameters || ! parameters[ 0 ] || sides.indexOf( parameters[ 1 ] ) === -1 || styles.indexOf( parameters[ 2 ] ) === -1 ) { + if ( ! parameters || ! parameters[ 0 ] || -1 === sides.indexOf( parameters[ 1 ] ) || -1 === styles.indexOf( parameters[ 2 ] ) ) { throw "Error registering Slidebar, please specify a valid id, side and style'."; } @@ -156,7 +156,7 @@ slidebars = function () { $( events ).trigger( 'init' ); // Run callback - if ( typeof callback === 'function' ) { + if ( 'function' === typeof callback ) { callback(); } }; @@ -176,7 +176,7 @@ slidebars = function () { $( events ).trigger( 'exit' ); // Run callback - if ( typeof callback === 'function' ) { + if ( 'function' === typeof callback ) { callback(); } }; @@ -206,7 +206,7 @@ slidebars = function () { // Calculate offset var offset; - if ( offCanvas[ id ].side === 'top' || offCanvas[ id ].side === 'bottom' ) { + if ( 'top' === offCanvas[ id ].side || 'bottom' === offCanvas[ id ].side ) { offset = offCanvas[ id ].element.css( 'height' ); } else { offset = offCanvas[ id ].element.css( 'width' ); @@ -214,9 +214,9 @@ slidebars = function () { // Apply negative margins var do_offset = false; - if ( offCanvas[ id ].style === 'push' || offCanvas[ id ].style === 'overlay' || offCanvas[ id ].style === 'shift' ) { + if ( 'push' === offCanvas[ id ].style || 'overlay' === offCanvas[ id ].style || 'shift' === offCanvas[ id ].style ) { do_offset = true; - } else if ( offCanvas[ id ].style === 'reveal' && ( offCanvas[ id ].side === 'top' || offCanvas[ id ].side === 'bottom' ) ) { + } else if ( 'reveal' === offCanvas[ id ].style && ( 'top' === offCanvas[ id ].side || 'bottom' === offCanvas[ id ].side ) ) { // temp disabled style condition to enable reveal location as well for top and bottom // @todo, fix reveal support for top and bottom, current result is behaviour similar to push do_offset = true; @@ -225,7 +225,7 @@ slidebars = function () { offCanvas[ id ].element.css( 'margin-' + offCanvas[ id ].side, '-' + offset ); // Fix shift style locations for legacy mode (1.9 to fix minor px rendering issues) - if ( self.legacy && offCanvas[ id ].style === 'shift' ) { + if ( self.legacy && 'shift' === offCanvas[ id ].style ) { var shiftPos; if ( 'top' === offCanvas[ id ].side || 'bottom' === offCanvas[ id ].side ) { shiftPos = offCanvas[ id ].element.height() / 1.9; @@ -250,7 +250,7 @@ slidebars = function () { $( events ).trigger( 'css' ); // Run callback - if ( typeof callback === 'function' ) { + if ( 'function' === typeof callback ) { callback(); } }; @@ -330,7 +330,7 @@ slidebars = function () { $( events ).trigger( 'opened', [ offCanvas[ id ].id ] ); // Run callback - if ( typeof callback === 'function' ) { + if ( 'function' === typeof callback ) { callback(); } }, animationProperties.duration ); @@ -346,7 +346,7 @@ slidebars = function () { this.close = function ( id, callback ) { // Shift callback arguments - if ( typeof id === 'function' ) { + if ( 'function' === typeof id ) { callback = id; id = null; } @@ -433,7 +433,7 @@ slidebars = function () { $( events ).trigger( 'closed', [ offCanvas[ id ].id ] ); // Run callback - if ( typeof callback === 'function' ) { + if ( 'function' === typeof callback ) { callback(); } }, animationProperties.duration ); @@ -456,7 +456,7 @@ slidebars = function () { // It's open, close it this.close( id, function () { // Run callback - if ( typeof callback === 'function' ) { + if ( 'function' === typeof callback ) { callback(); } } ); @@ -464,7 +464,7 @@ slidebars = function () { // It's closed, open it this.open( id, function () { // Run callback - if ( typeof callback === 'function' ) { + if ( 'function' === typeof callback ) { callback(); } } ); From c72873126919ed5ad1dfdc40b2e247a7a79585c7 Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Mon, 28 Aug 2017 18:03:15 +0200 Subject: [PATCH 097/124] More style fixes --- includes/class-form.php | 2 +- includes/class-menu-meta-box.php | 8 ++++---- slidebars/slidebars.js | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/includes/class-form.php b/includes/class-form.php index eee2604..a4a97a5 100644 --- a/includes/class-form.php +++ b/includes/class-form.php @@ -58,7 +58,7 @@ function enabled_sidebars_option() { } else { $tab = ( isset( $this->sidebars_tab ) ) ? '&tab=' . $this->sidebars_tab : ''; echo '' - . esc_html__( 'Click here to add off-canvas sidebars', 'off-canvas-sidebars' ) . ''; + . esc_html__( 'Click here to add off-canvas sidebars', 'off-canvas-sidebars' ) . ''; } } diff --git a/includes/class-menu-meta-box.php b/includes/class-menu-meta-box.php index c28d201..f5e3ab1 100644 --- a/includes/class-menu-meta-box.php +++ b/includes/class-menu-meta-box.php @@ -91,10 +91,10 @@ function meta_box() { is_sidebar_enabled() ) { + echo '
  • ' . $this->general_labels['no_sidebars_available'] . '
  • '; + } ?> - is_sidebar_enabled() ) { ?> -
  • general_labels['no_sidebars_available']; ?>
  • -
    is_sidebar_enabled() ) { ?> @@ -148,7 +148,7 @@ public function admin_enqueue_scripts() { 'meta_key' => '_off_canvas_control_menu_item', ) ); - // the options values for the language switcher + // the options values for the triggers. $data['val'] = array(); foreach ( $items as $item ) $data['val'][ $item ] = get_post_meta( $item, '_off_canvas_control_menu_item', true ); diff --git a/slidebars/slidebars.js b/slidebars/slidebars.js index 0341212..5dbaef5 100644 --- a/slidebars/slidebars.js +++ b/slidebars/slidebars.js @@ -76,11 +76,11 @@ slidebars = function () { } else { if ( 'top' === offCanvas[ id ].side ) { amount = '0px, ' + size; - } else if ( offCanvas[ id ].side === 'right' ) { + } else if ( 'right' === offCanvas[ id ].side ) { amount = '-' + size + ', 0px'; - } else if ( offCanvas[ id ].side === 'bottom' ) { + } else if ( 'bottom' === offCanvas[ id ].side ) { amount = '0px, -' + size; - } else if ( offCanvas[ id ].side === 'left' ) { + } else if ( 'left' === offCanvas[ id ].side ) { amount = size + ', 0px'; } } From 2a8916ab36d0f01bb55036ba4f1bb7a15ed91db5 Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Tue, 29 Aug 2017 01:06:45 +0200 Subject: [PATCH 098/124] 0.4 updater + phpDocs + use to GH for issues and docs --- includes/class-settings.php | 4 +- off-canvas-sidebars.php | 109 +++++++++++++++++++----------------- 2 files changed, 61 insertions(+), 52 deletions(-) diff --git a/includes/class-settings.php b/includes/class-settings.php index f80d9ef..5ce8fa7 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -896,7 +896,7 @@ public function plugin_options_page() {

    click here for documentation.', 'off-canvas-sidebars' ), 'https://wordpress.org/plugins/off-canvas-sidebars/installation/' ); + echo sprintf( __( 'You can add the control buttons with a widget, menu item or with custom code, click here for documentation.', 'off-canvas-sidebars' ), 'https://github.com/JoryHogeveen/off-canvas-sidebars/wiki/theme-setup' ); ?>

    general_labels['compatibility_notice_theme']; ?>

    @@ -930,7 +930,7 @@ public function plugin_options_page() {

    Documentation or talk about them in the Support forum', 'off-canvas-sidebars' ), 'https://wordpress.org/plugins/off-canvas-sidebars/installation/', 'https://wordpress.org/support/plugin/off-canvas-sidebars' ); + echo sprintf( __( 'If you are having problems with this plugin, checkout plugin Documentation or talk about them in the Support forum', 'off-canvas-sidebars' ), 'https://github.com/JoryHogeveen/off-canvas-sidebars/wiki/', 'https://github.com/JoryHogeveen/off-canvas-sidebars/issues' ); ?>


    diff --git a/off-canvas-sidebars.php b/off-canvas-sidebars.php index 2b0917f..53fbcb6 100644 --- a/off-canvas-sidebars.php +++ b/off-canvas-sidebars.php @@ -59,7 +59,7 @@ final class OCS_Off_Canvas_Sidebars protected static $_instance = null; /** - * Plugin version + * Plugin version. * * @var string * @since 0.1 @@ -67,7 +67,7 @@ final class OCS_Off_Canvas_Sidebars protected $version = OCS_PLUGIN_VERSION; /** - * Database version + * Database version. * * @var string * @since 0.2 @@ -75,7 +75,7 @@ final class OCS_Off_Canvas_Sidebars protected $db_version = '0'; /** - * User ignore nag key + * User ignore nag key. * * @var string * @since 0.1 @@ -83,7 +83,7 @@ final class OCS_Off_Canvas_Sidebars protected $noticeKey = 'ocs_ignore_theme_compatibility_notice'; /** - * Current user object + * Current user object. * * @var object * @since 0.1 @@ -99,7 +99,7 @@ final class OCS_Off_Canvas_Sidebars protected $enable = false; /** - * Plugin key + * Plugin key. * * @var string * @since 0.1 @@ -107,7 +107,7 @@ final class OCS_Off_Canvas_Sidebars protected $plugin_key = 'off-canvas-sidebars-settings'; /** - * Plugin general settings key, also used as option key + * Plugin general settings key, also used as option key. * * @var string * @since 0.1 @@ -115,7 +115,7 @@ final class OCS_Off_Canvas_Sidebars protected $general_key = 'off_canvas_sidebars_options'; /** - * Plugin settings + * Plugin settings. * * @var array * @since 0.1 @@ -123,7 +123,7 @@ final class OCS_Off_Canvas_Sidebars protected $settings = array(); /** - * Plugin settings + * Plugin settings. * * @var array * @since 0.1 @@ -131,7 +131,7 @@ final class OCS_Off_Canvas_Sidebars protected $general_labels = array(); /** - * Default settings + * Default settings. * * @var array * @since 0.2 @@ -156,7 +156,7 @@ final class OCS_Off_Canvas_Sidebars ); /** - * Default sidebar settings + * Default sidebar settings. * * @var array * @since 0.2 @@ -174,7 +174,7 @@ final class OCS_Off_Canvas_Sidebars 'padding' => '', 'background_color' => '', 'background_color_type' => '', - /* Global overwrites */ + // Global overwrites. 'overwrite_global_settings' => 0, 'site_close' => 1, 'disable_over' => '', @@ -183,7 +183,7 @@ final class OCS_Off_Canvas_Sidebars ); /** - * Init function to register plugin hook + * Init function to register plugin hook. * * @since 0.1 * @access private @@ -191,30 +191,30 @@ final class OCS_Off_Canvas_Sidebars private function __construct() { self::$_instance = $this; - // DB version for the current plugin version (only major version tags) + // DB version for the current plugin version (only major version tags). $this->db_version = substr( OCS_PLUGIN_VERSION, 0, 3 ); - $this->enable = true; // Added for possible use in future + $this->enable = true; // Added for possible use in future. if ( true === $this->enable ) { // Lets start! add_action( 'init', array( $this, 'init' ) ); - // Load the OCS API - include_once 'includes/api.php'; + // Load the OCS API. + include_once( OCS_PLUGIN_DIR . 'includes/api.php' ); - $this->settings = ( get_option( $this->general_key ) ) ? get_option( $this->general_key ) : array(); + $this->settings = (array) get_option( $this->general_key, array() ); $this->maybe_db_update(); - // Merge DB settings with default settings + // Merge DB settings with default settings. $this->settings = $this->get_settings(); $this->general_labels = $this->get_general_labels(); - // Register the widget + // Register the widget. include_once( OCS_PLUGIN_DIR . 'widgets/control-widget.php' ); add_action( 'widgets_init', array( $this, 'widgets_init' ) ); - // Load menu-meta-box option + // Load menu-meta-box option. include_once( OCS_PLUGIN_DIR . 'includes/class-menu-meta-box.php' ); OCS_Off_Canvas_Sidebars_Menu_Meta_Box::get_instance(); @@ -227,41 +227,41 @@ private function __construct() { } /** - * Init function/action to check current user, load nessesary data and classes, register hooks + * Init function/action to check current user, load nessesary data and classes, register hooks. * * @return void * @since 0.1 */ function init() { - // Get the current user + // Get the current user. //$this->curUser = wp_get_current_user(); - // Load translations + // Load translations. $this->load_textdomain(); - // Register the enabled sidebars + // Register the enabled sidebars. $this->register_sidebars(); if ( is_admin() ) { - // Load the settings page + // Load the settings page. include_once( OCS_PLUGIN_DIR . 'includes/class-form.php' ); include_once( OCS_PLUGIN_DIR . 'includes/class-settings.php' ); OCS_Off_Canvas_Sidebars_Settings::get_instance(); - // Add settings link to plugins page + // Add settings link to plugins page. add_filter( 'plugin_action_links', array( $this, 'add_settings_link' ), 10, 2 ); } else { - // If a sidebar is enabled, load the front-end + // If a sidebar is enabled, load the front-end. include_once( OCS_PLUGIN_DIR . 'includes/class-frontend.php' ); OCS_Off_Canvas_Sidebars_Frontend::get_instance(); } } /** - * Register widgets + * Register widgets. * @since 0.4 */ function widgets_init() { @@ -269,8 +269,8 @@ function widgets_init() { } /** - * Add notice when theme is not compatible - * Checks for version in the notice ignore meta value. If the version is the same (user has clicked ignore), then hide it + * Add notice when theme is not compatible. + * Checks for version in the notice ignore meta value. If the version is the same (user has clicked ignore), then hide it. * * @return void * @since 0.1 @@ -286,8 +286,8 @@ function compatibility_notice() { } /** - * AJAX handler - * Stores plugin version + * AJAX handler. + * Stores plugin version. * * Store format: boolean * @@ -299,7 +299,7 @@ function ignore_compatibility_notice() { } /** - * Merge database plugin settings with default settings + * Merge database plugin settings with default settings. * * @since 0.1 * @return array @@ -318,7 +318,7 @@ function get_settings() { } /** - * Validate setting keys + * Validate setting keys. * * @since 0.2 * @param array $settings @@ -341,7 +341,7 @@ function validate_settings( $settings, $defaults ) { } /** - * Returns the default settings + * Returns the default settings. * * @since 0.2 * @return array @@ -351,7 +351,7 @@ function get_default_settings() { } /** - * Returns the default sidebar_settings + * Returns the default sidebar_settings. * * @since 0.2 * @return array @@ -361,7 +361,7 @@ function get_default_sidebar_settings() { } /** - * Returns the plugin version + * Returns the plugin version. * * @since 0.1.2 * @return string @@ -371,7 +371,7 @@ function get_version() { } /** - * Returns the plugin key + * Returns the plugin key. * * @since 0.1 * @return string @@ -381,7 +381,7 @@ function get_plugin_key() { } /** - * Returns the general key (plugin settings) + * Returns the general key (plugin settings). * * @since 0.1 * @return string @@ -391,7 +391,7 @@ function get_general_key() { } /** - * Returns the general labels + * Returns the general labels. * * @since 0.1 * @return array @@ -400,12 +400,12 @@ function get_general_labels() { return array( 'no_sidebars_available' => __( 'Please enable an off-canvas sidebar', 'off-canvas-sidebars' ), // Translators: %s stands for the URL. - 'compatibility_notice_theme' => sprintf( __( 'If this plugin is not working as it should then your theme might not be compatible with this plugin, please let me know!', 'off-canvas-sidebars' ), 'https://wordpress.org/support/plugin/off-canvas-sidebars' ), + 'compatibility_notice_theme' => sprintf( __( 'If this plugin is not working as it should then your theme might not be compatible with this plugin, please let me know!', 'off-canvas-sidebars' ), 'https://github.com/JoryHogeveen/off-canvas-sidebars/issues' ), ); } /** - * Returns a sidebar key based on its label + * Returns a sidebar key based on its label. * * @since 0.1 * @param string $label @@ -420,7 +420,7 @@ function get_sidebar_key_by_label( $label ) { } /** - * Checks if a sidebar is enabled + * Checks if a sidebar is enabled. * * @since 0.1 * @return bool @@ -434,7 +434,7 @@ function is_sidebar_enabled() { } /** - * Register slidebar sidebars + * Register slidebar sidebars. * Also checks if theme is based on the Genesis Framework. * * @since 0.1 @@ -459,14 +459,14 @@ function register_sidebars() { ); /** - * Filter the register_sidebar arguments + * Filter the register_sidebar arguments. * * Please note that the ID will be overwritten! * * @since 0.3 * * @see https://codex.wordpress.org/Function_Reference/register_sidebar - * @see $default_sidebar_settings for the sidebar settings + * @see $default_sidebar_settings for the sidebar settings. * * @param array $args The register_sidebar() arguments * @param string $sidebar_id The ID of this sidebar as configured in: Appearances > Off-Canvas Sidebars > Sidebars @@ -496,7 +496,7 @@ function register_sidebars() { } /** - * Add Settings link to plugin's entry on the Plugins page + * Add Settings link to plugin's entry on the Plugins page. * * @since 0.1 * @param array $links @@ -522,7 +522,7 @@ function load_textdomain() { } /** - * Update settings + * Update settings. * * @since 0.2 * @access private @@ -560,7 +560,16 @@ private function db_update() { // Upgrade to 0.3.x if ( version_compare( $db_version, '0.3', '<' ) && version_compare( $db_version, '0', '>' ) ) { - $settings['css_prefix'] = 'sb'; // Old Slidebars classes + // Old Slidebars classes prefix. + $settings['css_prefix'] = 'sb'; + } + + // Upgrade to 0.4 + if ( version_compare( $db_version, '0.4', '<' ) ) { + if ( ! empty( $settings['compatibility_position_fixed'] ) ) { + // This was the only option before 0.4. + $settings['compatibility_position_fixed'] = 'custom-js'; + } } $settings['db_version'] = $this->db_version; @@ -569,7 +578,7 @@ private function db_update() { } /** - * Check the correct DB version in the DB + * Check the correct DB version in the DB. * * @since 0.2 * @access public From c3a5fb1903cf67e4e0d7bdc1106b4064dce9ea61 Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Tue, 29 Aug 2017 04:00:24 +0200 Subject: [PATCH 099/124] Enhance settings JS + fix docs --- includes/api.php | 46 +++--- includes/class-menu-meta-box.php | 2 +- includes/class-settings.php | 164 +++++++++++----------- js/fixed-scrolltop.js | 6 +- js/off-canvas-sidebars-settings.js | 216 ++++++++++++++--------------- js/off-canvas-sidebars.js | 5 +- slidebars/slidebars.css | 6 + 7 files changed, 226 insertions(+), 219 deletions(-) diff --git a/includes/api.php b/includes/api.php index b2bee6f..63d5522 100644 --- a/includes/api.php +++ b/includes/api.php @@ -5,7 +5,7 @@ * API * @author Jory Hogeveen * @package off-canvas-sidebars - * @version 0.3 + * @version 0.4 */ if ( ! defined( 'ABSPATH' ) ) { @@ -13,11 +13,11 @@ } /** - * Echos one, multiple or all OCS sidebars + * Echos one, multiple or all OCS sidebars. * * @api * @since 0.3 - * @param string|array $sidebars (Optional) The ID of this sidebar as configured in: Appearances > Off-Canvas Sidebars > Sidebars + * @param string|array $sidebars (Optional) The ID of this sidebar as configured in: Appearances > Off-Canvas Sidebars > Sidebars. */ function the_ocs_off_canvas_sidebar( $sidebars = '' ) { $instance = off_canvas_sidebars_frontend(); @@ -37,22 +37,22 @@ function the_ocs_off_canvas_sidebar( $sidebars = '' ) { } /** - * Output a trigger element for off-canvas sidebars + * Output a trigger element for off-canvas sidebars. * * @api * @since 0.4 * @param array $atts { * Required array of arguments * @type string id (Required) The off-canvas sidebar ID. - * @type string text The text to show. Default: '' - * @type string action The trigger action. Default: toggle - * @type string element The HTML element. Default: button - * @type array|string class Add extra classes? Also accepts a string with classes separated with a space - * @type array attr Other attributes to add { - * Format: attribute name (array key) => attribute value + * @type string text The text to show. Default: ''. + * @type string action The trigger action. Default: `toggle`. + * @type string element The HTML element. Default: `button`. + * @type array|string class Add extra classes? Also accepts a string with classes separated with a space. + * @type array attr { + * Other attributes to add. Format: attribute name (array key) => attribute value * } * } - * @param string $content (Optional) $content + * @param string $content (Optional) HTML/text string. * @return string */ function the_ocs_control_trigger( $atts, $content = '' ) { @@ -65,11 +65,11 @@ function the_ocs_control_trigger( $atts, $content = '' ) { $atts = shortcode_atts( array( 'id' => false, - 'text' => '', // Text to show + 'text' => '', // Text to show. 'action' => 'toggle', // toggle|open|close 'element' => 'button', // button|span|i|b|a|etc. - 'class' => array(), // Extra classes, also accepts a string with classes separated with a space - 'attr' => array(), // An array of attribute keys and their values + 'class' => array(), // Extra classes, also accepts a string with classes separated with a space. + 'attr' => array(), // An array of attribute keys and their values. 'echo' => true, ), $atts, 'ocs_trigger' ); @@ -88,7 +88,7 @@ function the_ocs_control_trigger( $atts, $content = '' ) { } /** - * Shortcode handler for the_ocs_control_trigger() + * Shortcode handler for the_ocs_control_trigger(). * * Example 1 (simple shortcode with all options): * [ocs_trigger id="left" action="open" element="a" button="1" text="My trigger button!" attr="href: #; rel: nofollow; alt: Yay!!"] @@ -97,28 +97,28 @@ function the_ocs_control_trigger( $atts, $content = '' ) { * [ocs_trigger id="right" attr="type:button;alt:Yay!!"]My trigger button text[/ocs_trigger] * * @since 0.4 - * @see the_ocs_control_trigger() for detailed info + * @see the_ocs_control_trigger() for detailed info. * @param array $atts - * @param string $content (Optional) $content + * @param string $content (Optional) HTML/text string. * @return string */ function shortcode_ocs_trigger( $atts, $content = '' ) { - // Shortcodes don't echo + // Shortcodes don't echo. $atts['echo'] = false; - // You can also use `attributes` instead of `attr` for readability (if both are used, `attributes` is ignored) + // You can also use `attributes` instead of `attr` for readability. If both are used, `attributes` is ignored. if ( empty( $atts['attr'] ) && ! empty( $atts['attributes'] ) ) { $atts['attr'] = $atts['attributes']; } unset( $atts['attributes'] ); - // You can also use `classes` instead of `class` for readability (if both are used, `classes` is ignored) + // You can also use `classes` instead of `class` for readability. If both are used, `classes` is ignored. if ( empty( $atts['class'] ) && ! empty( $atts['classes'] ) ) { $atts['class'] = $atts['classes']; } unset( $atts['classes'] ); - // Parse attributes send through the shortcode + // Parse attributes send through the shortcode. if ( ! empty( $atts['attr'] ) ) { $attr = explode( ';', $atts['attr'] ); $atts['attr'] = array(); @@ -142,11 +142,11 @@ function shortcode_ocs_trigger( $atts, $content = '' ) { * Returns the main instance of OCS_Off_Canvas_Sidebars_Frontend to prevent the need to use globals. * * @since 0.3 - * @return OCS_Off_Canvas_Sidebars_Frontend|false + * @return OCS_Off_Canvas_Sidebars_Frontend */ function off_canvas_sidebars_frontend() { if ( is_callable( array( 'OCS_Off_Canvas_Sidebars_Frontend', 'get_instance' ) ) ) { return OCS_Off_Canvas_Sidebars_Frontend::get_instance(); } - return false; + return null; } diff --git a/includes/class-menu-meta-box.php b/includes/class-menu-meta-box.php index f5e3ab1..388fb5f 100644 --- a/includes/class-menu-meta-box.php +++ b/includes/class-menu-meta-box.php @@ -5,7 +5,7 @@ * Menu Meta Box * @author Jory Hogeveen * @package off-canvas-sidebars - * @version 0.3 + * @version 0.4 * * Credits to the Polylang plugin */ diff --git a/includes/class-settings.php b/includes/class-settings.php index 5ce8fa7..afc8968 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -37,7 +37,7 @@ final class OCS_Off_Canvas_Sidebars_Settings extends OCS_Off_Canvas_Sidebars_For /** * @since 0.1 - * @since 0.3 private constructor + * @since 0.3 Private constructor. * @access private */ private function __construct() { @@ -54,7 +54,7 @@ private function __construct() { } /** - * Get plugin defaults + * Get plugin defaults. * @since 0.1 */ public function load_plugin_data() { @@ -64,7 +64,7 @@ public function load_plugin_data() { $this->general_key = $off_canvas_sidebars->get_general_key(); /** - * Change the capability for the OCS settings + * Change the capability for the OCS settings. * @since 0.4 * @param string * @return string @@ -73,24 +73,24 @@ public function load_plugin_data() { } /** - * Enqueue our styles and scripts only when it's our page + * Enqueue our styles and scripts only when it's our page. * @since 0.1 - * @param $hook + * @param string $hook */ public function enqueue_styles_scripts( $hook ) { if ( 'appearance_page_' . $this->plugin_key !== $hook ) { return; } - // Add the color picker css and script file + // Add the color picker css and script file. wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( 'wp-color-picker' ); wp_enqueue_script( 'postbox' ); - // Add our own scripts + // Add our own scripts. wp_enqueue_style( 'off-canvas-sidebars-admin', OCS_PLUGIN_URL . '/css/off-canvas-sidebars-admin.css', array(), OCS_PLUGIN_VERSION ); wp_enqueue_script( 'off-canvas-sidebars-settings', OCS_PLUGIN_URL . '/js/off-canvas-sidebars-settings.js', array( 'jquery' ), OCS_PLUGIN_VERSION, true ); - wp_localize_script( 'off-canvas-sidebars-settings', 'OCS_OFF_CANVAS_SIDEBARS_SETTINGS', array( + wp_localize_script( 'off-canvas-sidebars-settings', 'ocsOffCanvasSidebarsSettings', array( 'general_key' => $this->general_key, 'plugin_key' => $this->plugin_key, 'css_prefix' => $this->settings['css_prefix'], @@ -100,7 +100,7 @@ public function enqueue_styles_scripts( $hook ) { } /** - * Create admin page under the appearance menu + * Create admin page under the appearance menu. * @since 0.1 */ public function add_admin_menus() { @@ -114,7 +114,7 @@ public function add_admin_menus() { } /** - * Register our settings + * Register our settings. * @since 0.1 */ public function register_settings() { @@ -146,7 +146,7 @@ public function register_settings() { $this->register_general_settings(); - // Register sidebar settings + // Register sidebar settings. foreach ( $this->settings['sidebars'] as $sidebar => $sidebar_data ) { add_settings_section( 'section_sidebar_' . $sidebar, @@ -161,15 +161,17 @@ public function register_settings() { } /** - * General settings + * General settings. + * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @todo Refactor to enable above checks? + * * @since 0.1 */ private function register_general_settings() { /* - * General + * General. */ add_settings_field( 'enabled_sidebars', @@ -180,7 +182,7 @@ private function register_general_settings() { ); /* - * Frontend + * Frontend. */ add_settings_field( 'enable_frontend', @@ -270,9 +272,9 @@ private function register_general_settings() { 'description' => __( 'Choose a background color for the site container. Default: #ffffff.', 'off-canvas-sidebars' ), ) ); - // Genesis already has before and after hooks set + // Genesis already has before and after hooks set. if ( get_template() !== 'genesis' ) { - // Check if the before hook is filtered. If it is this setting is not needed + // Check if the before hook is filtered. If it is this setting is not needed. if ( '' === apply_filters( 'ocs_website_before_hook', '' ) ) { add_settings_field( 'website_before_hook', @@ -286,7 +288,7 @@ private function register_general_settings() { ) ); } - // Check if the after hook is filtered. If it is this setting is not needed + // Check if the after hook is filtered. If it is this setting is not needed. if ( '' === apply_filters( 'ocs_website_after_hook', '' ) ) { add_settings_field( 'website_after_hook', @@ -301,7 +303,7 @@ private function register_general_settings() { ); } } - //https://github.com/ftlabs/fastclick + // https://github.com/ftlabs/fastclick add_settings_field( 'use_fastclick', esc_attr__( 'Use the FastClick library?', 'off-canvas-sidebars' ), @@ -349,9 +351,11 @@ private function register_general_settings() { } /** - * Sidebar settings + * Sidebar settings. + * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @todo Refactor to enable above checks? + * * @param string $sidebar_id * @since 0.1 */ @@ -584,16 +588,16 @@ private function register_sidebar_settings( $sidebar_id ) { * @return array $output */ protected function parse_input( $input ) { - // First set current values + // First set current values. $current = $this->settings; - // Add new sidebar + // Add new sidebar. if ( ! empty( $input['sidebars']['ocs_add_new'] ) ) { $new_sidebar_id = $this->validate_id( $input['sidebars']['ocs_add_new'] ); if ( empty( $input['sidebars'][ $new_sidebar_id ] ) && empty( $current['sidebars'][ $new_sidebar_id ] ) ) { $input['sidebars'][ $new_sidebar_id ] = array( 'enable' => 1, - 'label' => strip_tags( stripslashes( $input['sidebars']['ocs_add_new'] ) ), + 'label' => strip_tags( stripslashes( $input['sidebars']['ocs_add_new'] ) ), ); } else { add_settings_error( @@ -614,10 +618,10 @@ protected function parse_input( $input ) { $input['use_fastclick'] = $this->validate_numeric_boolean( $input, 'use_fastclick' ); } - // Handle existing sidebars + // Handle existing sidebars. $input = $this->parse_sidebars_input( $input, $current ); - // Overwrite non existing values with current values + // Overwrite non existing values with current values. foreach ( $current as $key => $value ) { if ( ! isset( $input[ $key ] ) ) { $input[ $key ] = $value; @@ -648,24 +652,24 @@ private function parse_sidebars_input( $input, $current ) { if ( ! isset( $sidebars[ $sidebar_id ] ) ) { $sidebars[ $sidebar_id ] = $current[ $sidebar_id ]; - // Sidebars are set but this sidebar isn't checked as active + // Sidebars are set but this sidebar isn't checked as active. $sidebars[ $sidebar_id ]['enable'] = 0; continue; } - // Global settings page + // Global settings page. if ( count( $sidebars[ $sidebar_id ] ) < 2 ) { $current[ $sidebar_id ]['enable'] = $this->validate_checkbox( $sidebars[ $sidebar_id ]['enable'] ); $sidebars[ $sidebar_id ] = $current[ $sidebar_id ]; continue; } - // Default label is sidebar ID + // Default label is sidebar ID. if ( empty( $sidebars[ $sidebar_id ]['label'] ) ) { $sidebars[ $sidebar_id ]['label'] = $sidebar_id; } - // Change sidebar ID + // Change sidebar ID. if ( ! empty( $sidebars[ $sidebar_id ]['id'] ) && $sidebar_id !== $sidebars[ $sidebar_id ]['id'] ) { $new_sidebar_id = $this->validate_id( $sidebars[ $sidebar_id ]['id'] ); @@ -679,10 +683,16 @@ private function parse_sidebars_input( $input, $current ) { unset( $sidebars[ $sidebar_id ] ); + // Migrate existing widgets to the new sidebar. $this->migrate_sidebars_widgets( $sidebar_id, $new_sidebar_id ); + } else { - // Translators: %s stands for a sidebar ID. - add_settings_error( $sidebar_id . '_duplicate_id', esc_attr( 'ocs_duplicate_id' ), sprintf( __( 'The ID %s already exists! The ID is not changed.', 'off-canvas-sidebars' ), '' . $new_sidebar_id . '' ) ); + add_settings_error( + $sidebar_id . '_duplicate_id', + esc_attr( 'ocs_duplicate_id' ), + // Translators: %s stands for a sidebar ID. + sprintf( __( 'The ID %s already exists! The ID is not changed.', 'off-canvas-sidebars' ), '' . $new_sidebar_id . '' ) + ); } } } @@ -693,7 +703,7 @@ private function parse_sidebars_input( $input, $current ) { } /** - * Validates post values + * Validates post values. * @since 0.1 * @param array $input * @return array $output @@ -703,27 +713,27 @@ public function validate_input( $input ) { $output = $this->parse_input( $input ); if ( $this->post_tab === $this->settings_tab ) { - // Make sure unchecked checkboxes are 0 on save + // Make sure unchecked checkboxes are 0 on save. $output['enable_frontend'] = $this->validate_checkbox( $output['enable_frontend'] ); $output['site_close'] = $this->validate_checkbox( $output['site_close'] ); $output['hide_control_classes'] = $this->validate_checkbox( $output['hide_control_classes'] ); $output['scroll_lock'] = $this->validate_checkbox( $output['scroll_lock'] ); $output['use_fastclick'] = $this->validate_checkbox( $output['use_fastclick'] ); - // Numeric values (not integers!) + // Numeric values, not integers! $output['disable_over'] = $this->validate_numeric( $output['disable_over'] ); - // Remove whitespaces + // Remove whitespaces. $output['website_before_hook'] = $this->remove_whitespace( $output['website_before_hook'] ); $output['website_after_hook'] = $this->remove_whitespace( $output['website_after_hook'] ); - // Attribute validation + // Attribute validation. $output['css_prefix'] = $this->validate_id( $output['css_prefix'] ); - // Validate radio options + // Validate radio options. $output['compatibility_position_fixed'] = $this->validate_radio( $output['compatibility_position_fixed'], array( 'none', 'custom-js', 'legacy-css' ), 'none' ); - // Set default values if no value is set + // Set default values if no value is set. if ( empty( $output['css_prefix'] ) ) { $output['css_prefix'] = 'ocs'; } @@ -731,7 +741,7 @@ public function validate_input( $input ) { foreach ( $output['sidebars'] as $sidebar_id => $sidebar_data ) { - // Delete sidebar + // Delete sidebar. if ( ! empty( $input['sidebars'][ $sidebar_id ]['delete'] ) ) { unset( $input['sidebars'][ $sidebar_id ] ); unset( $output['sidebars'][ $sidebar_id ] ); @@ -739,19 +749,19 @@ public function validate_input( $input ) { $sidebar = $output['sidebars'][ $sidebar_id ]; - // Make sure unchecked checkboxes are 0 on save + // Make sure unchecked checkboxes are 0 on save. $sidebar['enable'] = $this->validate_checkbox( $sidebar['enable'] ); $sidebar['overwrite_global_settings'] = $this->validate_checkbox( $sidebar['overwrite_global_settings'] ); $sidebar['site_close'] = $this->validate_checkbox( $sidebar['site_close'] ); $sidebar['hide_control_classes'] = $this->validate_checkbox( $sidebar['hide_control_classes'] ); $sidebar['scroll_lock'] = $this->validate_checkbox( $sidebar['scroll_lock'] ); - // Numeric values (not integers!) + // Numeric values, not integers! $sidebar['padding'] = $this->validate_numeric( $sidebar['padding'] ); $sidebar['disable_over'] = $this->validate_numeric( $sidebar['disable_over'] ); $sidebar['animation_speed'] = $this->validate_numeric( $sidebar['animation_speed'] ); - // Validate radio options + // Validate radio options. $sidebar['content'] = $this->validate_radio( $sidebar['content'], array( 'sidebar', 'menu', 'action' ), 'sidebar' ); $output['sidebars'][ $sidebar_id ] = $sidebar; @@ -768,9 +778,9 @@ public function validate_input( $input ) { } } // End foreach(). - // Validate global settings with defaults + // Validate global settings with defaults. $output = off_canvas_sidebars()->validate_settings( $output, off_canvas_sidebars()->get_default_settings() ); - // Validate sidebar settings with defaults + // Validate sidebar settings with defaults. foreach ( $output['sidebars'] as $sidebar_id => $sidebar_settings ) { $output['sidebars'][ $sidebar_id ] = off_canvas_sidebars()->validate_settings( $sidebar_settings, off_canvas_sidebars()->get_default_sidebar_settings() ); } @@ -781,7 +791,7 @@ public function validate_input( $input ) { } /** - * Validates checkbox boolean values, used by validate_input + * Validates checkbox boolean values, used by validate_input(). * @since 0.4 * @param mixed $value * @param string $key @@ -795,7 +805,7 @@ public function validate_numeric_boolean( $value, $key = '' ) { } /** - * Validates checkbox values, used by validate_input + * Validates checkbox values, used by validate_input(). * @since 0.1.2 * @param mixed $value * @return int @@ -805,11 +815,11 @@ public function validate_checkbox( $value ) { } /** - * Validates radio values against the possible options + * Validates radio values against the possible options. * @since 0.4 - * @param string $value - * @param array $options - * @param string $default + * @param string $value + * @param array $options + * @param string $default * @return int */ public function validate_radio( $value, $options, $default ) { @@ -817,10 +827,10 @@ public function validate_radio( $value, $options, $default ) { } /** - * Validates id values, used by validate_input + * Validates id values, used by validate_input. * @since 0.2 - * @since 0.3 Convert to lowercase and convert spaces to dashes before preg_replace - * @param string $value + * @since 0.3 Convert to lowercase and convert spaces to dashes before preg_replace(). + * @param string $value * @return string */ public function validate_id( $value ) { @@ -828,9 +838,9 @@ public function validate_id( $value ) { } /** - * Validates numeric values, used by validate_input + * Validates numeric values, used by validate_input(). * @since 0.2.2 - * @param mixed $value + * @param mixed $value * @return string */ public function validate_numeric( $value ) { @@ -838,9 +848,9 @@ public function validate_numeric( $value ) { } /** - * Remove whitespace + * Remove whitespace. * @since 0.3 - * @param mixed $value + * @param mixed $value * @return string */ public function remove_whitespace( $value ) { @@ -848,10 +858,9 @@ public function remove_whitespace( $value ) { } /** - * Updates the existing widgets when a sidebar ID changes + * Updates the existing widgets when a sidebar ID changes. * * @since 0.3 - * * @param string $old_id * @param string $new_id */ @@ -868,11 +877,9 @@ public function migrate_sidebars_widgets( $old_id, $new_id ) { wp_set_sidebars_widgets( $sidebars_widgets ); } - /* - * Plugin Options page rendering goes here, checks - * for active tab and replaces key with the related - * settings key. Uses the plugin_options_tabs method - * to render the tabs. + /** + * Plugin Options page rendering goes here, checks for active tab and replaces key with the related settings key. + * Uses the plugin_options_tabs() method to render the tabs. * * @since 0.1 */ @@ -961,12 +968,12 @@ public function plugin_options_page() { /** * This function is similar to the function in the Settings API, only the output HTML is changed. - * Print out the settings fields for a particular settings section + * Print out the settings fields for a particular settings section. * * @since 0.1 * - * @global $wp_settings_sections array of settings sections - * @global $wp_settings_fields array of settings fields and their pages/sections + * @global $wp_settings_sections array of settings sections. + * @global $wp_settings_fields array of settings fields and their pages/sections. * * @param string $page Slug title of the admin page who's settings fields you want to show. * param string $section Slug title of the settings section who's fields you want to show. @@ -1012,11 +1019,8 @@ protected function do_settings_sections( $page ) { } /** - * Renders our tabs in the plugin options page, - * walks through the object's tabs array and prints - * them one by one. Provides the heading for the - * plugin_options_page method. - * + * Renders our tabs in the plugin options page, walks through the object's tabs array and prints them one by one. + * Provides the heading for the plugin_options_page() method. * @since 0.1 */ function plugin_options_tabs() { @@ -1030,7 +1034,7 @@ function plugin_options_tabs() { /** * Shortcode tab. - * @since 0.4 + * @since 0.4 */ private function shortcode_tab() { ?> @@ -1171,7 +1175,7 @@ private function shortcode_tab() { /** * Import/Export tab. - * @since 0.1 + * @since 0.1 */ private function importexport_tab() { ?> @@ -1189,13 +1193,13 @@ private function importexport_tab() { /** * Import/Export handler. - * @since 0.1 + * @since 0.1 */ public function register_importexport_settings() { $this->plugin_tabs[ $this->importexport_tab ] = esc_attr__( 'Import/Export', 'off-canvas-sidebars' ); /** - * Filter documented in $this->load_plugin_data() + * Filter documented in $this->load_plugin_data(). */ if ( ! current_user_can( $this->capability ) || $this->tab !== $this->importexport_tab ) { return; @@ -1228,7 +1232,7 @@ public function register_importexport_settings() { } } - // @codingStandardsIgnoreLine - export settings + // @codingStandardsIgnoreLine - export settings. if ( isset( $_GET[ $this->plugin_key . '-export' ] ) ) { header( "Content-Disposition: attachment; filename=" . $this->plugin_key . ".txt" ); header( 'Content-Type: text/plain; charset=utf-8' ); @@ -1241,7 +1245,7 @@ public function register_importexport_settings() { exit; } - // @codingStandardsIgnoreLine - import settings + // @codingStandardsIgnoreLine - import settings. if ( isset( $_POST[ $this->plugin_key . '-import' ] ) ) { if ( $_FILES[ $this->plugin_key . '-import-file' ]['tmp_name'] ) { @@ -1256,10 +1260,10 @@ public function register_importexport_settings() { $settings[ $key ] = json_decode( sanitize_text_field( $value ), true ); } - // Validate global settings + // Validate global settings. $settings = off_canvas_sidebars()->validate_settings( $settings, off_canvas_sidebars()->get_default_settings() ); - // Validate sidebar settings + // Validate sidebar settings. if ( ! empty( $settings['sidebars'] ) ) { foreach ( $settings['sidebars'] as $sidebar_id => $sidebar_settings ) { $settings['sidebars'][ $sidebar_id ] = off_canvas_sidebars()->validate_settings( $sidebar_settings, off_canvas_sidebars()->get_default_sidebar_settings() ); @@ -1296,4 +1300,4 @@ public static function get_instance() { return self::$_instance; } -} // end class +} // End class(). diff --git a/js/fixed-scrolltop.js b/js/fixed-scrolltop.js index e282a57..a62fc06 100644 --- a/js/fixed-scrolltop.js +++ b/js/fixed-scrolltop.js @@ -1,12 +1,14 @@ ;/** * Off-Canvas Sidebars plugin fixed-scrolltop.js * - * Compatibility for fixed elements with Slidebars + * Compatibility for fixed elements with Slidebars. * @author Jory Hogeveen * @package off-canvas-slidebars * @version 0.4 + * @global ocsOffCanvasSidebars + * @preserve */ -( function ( $ ) { +( function( $ ) { var $window = $(window); var $body = $('body'); diff --git a/js/off-canvas-sidebars-settings.js b/js/off-canvas-sidebars-settings.js index 4fe1d3a..4c09c67 100644 --- a/js/off-canvas-sidebars-settings.js +++ b/js/off-canvas-sidebars-settings.js @@ -1,89 +1,99 @@ ;/** - * Off-Canvas Sidebars plugin + * Off-Canvas Sidebars plugin settings * - * OCS_OFF_CANVAS_SIDEBARS_SETTINGS * @author Jory Hogeveen * @package off-canvas-sidebars - * @version 0.3 + * @version 0.4 + * @global ocsOffCanvasSidebarsSettings + * @preserve */ -if ( 'undefined' === typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS ) { - var OCS_OFF_CANVAS_SIDEBARS_SETTINGS = { - 'general_key': 'off_canvas_sidebars_options', - 'plugin_key': 'off-canvas-sidebars-settings', - 'css_prefix': 'ocs', - '__required_fields_not_set': '' //Some required fields are not set! +if ( 'undefined' === typeof ocsOffCanvasSidebarsSettings ) { + var ocsOffCanvasSidebarsSettings = { + general_key: 'off_canvas_sidebars_options', + plugin_key: 'off-canvas-sidebars-settings', + css_prefix: 'ocs', + __required_fields_not_set: 'Some required fields are not set!' }; } -(function($) { +( function( $ ) { - OCS_OFF_CANVAS_SIDEBARS_SETTINGS.init = function() { + var $document = $(document); + ocsOffCanvasSidebarsSettings.init = function() { var tab = $('#ocs_tab'); var postbox = $('.postbox'); - // close postboxes that should be closed + // Close postboxes that should be closed. $('.if-js-closed').removeClass('if-js-closed').addClass('closed'); - // postboxes setup - postboxes.add_postbox_toggles( OCS_OFF_CANVAS_SIDEBARS_SETTINGS.plugin_key ); + // Postboxes setup. + postboxes.add_postbox_toggles( ocsOffCanvasSidebarsSettings.plugin_key ); if ( 'ocs-sidebars' === tab.val() ) { postbox.each( function() { - var sidebar_id = $(this).attr('id').replace('section_sidebar_', ''); - - ocs_show_hide_options_radio( '.off_canvas_sidebars_options_sidebars_' + sidebar_id + '_background_color_type', '.off_canvas_sidebars_options_sidebars_' + sidebar_id + '_background_color_wrapper', 'color', false ); - ocs_show_hide_options_radio( '.off_canvas_sidebars_options_sidebars_' + sidebar_id + '_location', '#off_canvas_sidebars_options_sidebars_' + sidebar_id + '_style_reveal, #off_canvas_sidebars_options_sidebars_' + sidebar_id + '_style_shift', [ 'left', 'right' ], 'label' ); - - ocs_show_hide_options( '.off_canvas_sidebars_options_sidebars_' + sidebar_id + '_overwrite_global_settings', '.off_canvas_sidebars_options_sidebars_' + sidebar_id + '_site_close', 'tr' ); - ocs_show_hide_options( '.off_canvas_sidebars_options_sidebars_' + sidebar_id + '_overwrite_global_settings', '.off_canvas_sidebars_options_sidebars_' + sidebar_id + '_disable_over', 'tr' ); - ocs_show_hide_options( '.off_canvas_sidebars_options_sidebars_' + sidebar_id + '_overwrite_global_settings', '.off_canvas_sidebars_options_sidebars_' + sidebar_id + '_hide_control_classes', 'tr' ); - ocs_show_hide_options( '.off_canvas_sidebars_options_sidebars_' + sidebar_id + '_overwrite_global_settings', '.off_canvas_sidebars_options_sidebars_' + sidebar_id + '_scroll_lock', 'tr' ); + var prefix = 'off_canvas_sidebars_options_sidebars_', + sidebar_id = $(this).attr('id').replace('section_sidebar_', ''), + sidebar_prefix = prefix + sidebar_id; + + ocs_show_hide_options_radio( + '.' + sidebar_prefix + '_background_color_type', + '.' + sidebar_prefix + '_background_color_wrapper', + 'color', + false + ); + ocs_show_hide_options_radio( + '.' + sidebar_prefix + '_location', + '#' + sidebar_prefix + '_style_reveal, #' + sidebar_prefix + '_style_shift', + [ 'left', 'right' ], + 'label' + ); + + ocs_show_hide_options( '.' + sidebar_prefix + '_overwrite_global_settings', '.' + sidebar_prefix + '_site_close', 'tr' ); + ocs_show_hide_options( '.' + sidebar_prefix + '_overwrite_global_settings', '.' + sidebar_prefix + '_disable_over', 'tr' ); + ocs_show_hide_options( '.' + sidebar_prefix + '_overwrite_global_settings', '.' + sidebar_prefix + '_hide_control_classes', 'tr' ); + ocs_show_hide_options( '.' + sidebar_prefix + '_overwrite_global_settings', '.' + sidebar_prefix + '_scroll_lock', 'tr' ); } ); } else { - ocs_show_hide_options_radio( '.off_canvas_sidebars_options_background_color_type', '.off_canvas_sidebars_options_background_color_wrapper', 'color' ); + ocs_show_hide_options_radio( + '.off_canvas_sidebars_options_background_color_type', + '.off_canvas_sidebars_options_background_color_wrapper', + 'color', + false + ); } /** * Auto show/hide handler for checkbox elements. * @todo Rename? - * @param {string} trigger The trigger element selector. - * @param {string} target The target element selector. - * @param {string} parent The parent element selector. + * @param {string} trigger The trigger element selector. + * @param {string} target The target element selector. + * @param {string|boolean|null} parent The parent element selector. * @return {null} Nothing. */ function ocs_show_hide_options( trigger, target, parent ) { + if ( parent ) { + target = $( target ).closest( parent ); + } if ( ! $( trigger ).is(':checked') ) { - if ( parent ) { - $( target ).closest( parent ).slideUp('fast'); - } else { - $( target ).slideUp('fast'); - } + $( target ).slideUp('fast'); } $( trigger ).change( function() { if ( $(this).is(':checked') ) { - if ( parent ) { - $( target ).closest( parent ).slideDown('fast'); - } else { - $( target ).slideDown('fast'); - } + $( target ).slideDown('fast'); } else { - if ( parent ) { - $( target ).closest( parent ).slideUp('fast'); - } else { - $( target ).slideUp('fast'); - } + $( target ).slideUp('fast'); } - }); + } ); } /** * Auto show/hide handler for radio elements. - * @param {string} trigger The trigger element selector. - * @param {string} target The target element selector. - * @param {string} compare The compare value. - * @param {string} parent The parent element selector. + * @param {string} trigger The trigger element selector. + * @param {string} target The target element selector. + * @param {string|object} compare The compare value. + * @param {string|boolean|null} parent The parent element selector. * @return {null} Nothing. */ function ocs_show_hide_options_radio( trigger, target, compare, parent ) { @@ -92,80 +102,68 @@ if ( 'undefined' === typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS ) { } if ( parent ) { parent += ', ' + parent + ' + br'; - } - if ( 0 > $.inArray( $( trigger + ':checked' ).val(), compare ) ) { - if ( parent ) { - $( target ).closest( parent ).slideUp('fast'); - } else { - $( target ).slideUp('fast'); - } + target = $( target ).closest( parent ); } $( trigger ).change( function() { if ( 0 <= $.inArray( $( trigger + ':checked' ).val(), compare ) ) { - if ( parent ) { - $( target ).closest( parent ).slideDown('fast'); - } else { - $( target ).slideDown('fast'); - } + $( target ).slideDown('fast'); } else { - if ( parent ) { - $( target ).closest( parent ).slideUp('fast'); - } else { - $( target ).slideUp('fast'); - } + $( target ).slideUp('fast'); } - }); + } ).trigger( 'change' ); } - // Enable the WP Color Picker + // Enable the WP Color Picker. $('input.color-picker').wpColorPicker(); - // Validate required fields - $('input.required').each(function(){ + // Validate required fields. + $('input.required').each( function() { var $this = $(this); - $this.on('change', function() { + $this.on( 'change', function() { if ( ! $this.val() ) { $this.parents('tr').addClass('form-invalid'); } else { $this.parents('tr').removeClass('form-invalid'); } - }); - }); + } ); + } ); - // Validate form submit - $( '#' + OCS_OFF_CANVAS_SIDEBARS_SETTINGS.general_key ).submit( function(e) { + // Validate form submit. + $( '#' + ocsOffCanvasSidebarsSettings.general_key ).submit( function( e ) { var valid = true; //var errors = {}; - $('input.required', this).each(function(){ + $( 'input.required', this ).each( function() { if ( ! $(this).val() ) { $(this).trigger('change'); valid = false; } - }); + } ); if ( ! valid ) { e.preventDefault(); - alert( OCS_OFF_CANVAS_SIDEBARS_SETTINGS.__required_fields_not_set ); + alert( ocsOffCanvasSidebarsSettings.__required_fields_not_set ); } } ); if ( 'ocs-sidebars' === tab.val() ) { - // Dynamic sidebar ID + // Dynamic sidebar ID. if ( $('.js-dynamic-id').length ) { postbox.each( function() { var sidebar = this; $( '.js-dynamic-id', sidebar ).text( $( 'input.off_canvas_sidebars_options_sidebars_id', sidebar ).val() ); $('.sidebar_classes').show(); $( 'input.off_canvas_sidebars_options_sidebars_id', this ).on('keyup', function() { - $('.js-dynamic-id', sidebar).text( $(this).val() ); + $( '.js-dynamic-id', sidebar ).text( $(this).val() ); } ); } ); } - // Half opacity for closed disabled sidebars + // Half opacity for closed disabled sidebars. + // @todo Use classes instead of CSS. postbox.each( function() { var sidebar = this, $sidebar = $( sidebar ); + $sidebar.css({'border-left':'5px solid #eee'}); if ( ! $( 'input.off_canvas_sidebars_options_sidebars_enable', sidebar ).is(':checked') ) { if ( $sidebar.hasClass('closed') ) { @@ -197,11 +195,14 @@ if ( 'undefined' === typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS ) { } ); } ); - // Hide options when set to delete - $(document).on( 'change', '.off_canvas_sidebars_options_sidebars_delete', function() { - var sidebar = $(this).parents('.postbox'); - if ( $(this).is(':checked') ) { - var parent_row = $(this).parents('tr'); + // Hide options when set to delete. + $document.on( 'change', '.off_canvas_sidebars_options_sidebars_delete', function() { + var $this = $(this), + sidebar = $this.parents('.postbox'), + $sidebar = $( sidebar ); + + if ( $this.is(':checked') ) { + var parent_row = $this.parents('tr'); $( 'tr', sidebar ).hide( 'fast', function() { $( 'tr', sidebar ).each(function(){ if ( $(this).is( parent_row ) ) { @@ -209,10 +210,10 @@ if ( 'undefined' === typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS ) { } }); } ); - $(sidebar).css('opacity', '0.5'); - $(sidebar).css('border-left-color','#dc3232'); + $sidebar.css('opacity', '0.5'); + $sidebar.css('border-left-color','#dc3232'); } else { - $(sidebar).css('opacity', ''); + $sidebar.css('opacity', ''); $( 'tr', sidebar ).show( 'fast' ); $('input.off_canvas_sidebars_options_sidebars_enable', sidebar).trigger('change'); } @@ -225,7 +226,7 @@ if ( 'undefined' === typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS ) { var fields = [ 'sidebar', 'text', 'action', 'element', 'class', 'attr', 'nested' ]; for ( var i = 0, l = fields.length; i < l; i++ ) { - $( '#off_canvas_sidebars_options_' + fields[i] ).on( 'change keyup', function() { + $( '#off_canvas_sidebars_options_' + fields[ i ] ).on( 'change keyup', function() { create_shortcode(); }); } @@ -240,15 +241,15 @@ if ( 'undefined' === typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS ) { function create_shortcode() { var field_data = {}; for ( var i = 0, l = fields.length; i < l; i++ ) { - field_data[ fields[i] ] = $( '#off_canvas_sidebars_options_' + fields[i] ); + field_data[ fields[ i ] ] = $( '#off_canvas_sidebars_options_' + fields[ i ] ); } var shortcode = 'ocs_trigger'; - //start the shortcode tag + // Start the shortcode tag. var shortcode_str = '[' + shortcode; - // Loop through our known fields + // Loop through our known fields. for ( var field in field_data ) { if ( 'undefined' !== typeof field_data[ field ] ) { if ( 'text' !== field && 'nested' !== field ) { @@ -261,12 +262,12 @@ if ( 'undefined' === typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS ) { } } - // If the test contains a double quote, force it to be nested for compatibility + // If the test contains a double quote, force it to be nested for compatibility. if ( field_data.text.val().length && -1 < field_data.text.val().indexOf( '"' ) ) { field_data.nested = true; } - //add panel text + // Add panel text. if ( field_data.nested.is(':checked') ) { shortcode_str += ']' + field_data.text.val() + '[/' + shortcode + ']'; } else { @@ -291,10 +292,11 @@ if ( 'undefined' === typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS ) { var element = ( field_data.element.val() ) ? field_data.element.val() : 'button', attributes = ( field_data.attr.val() ) ? attrStringToObject( field_data.attr.val() ) : {}, - prefix = OCS_OFF_CANVAS_SIDEBARS_SETTINGS.css_prefix, - action = ( field_data.action.val() ) ? field_data.action.val() : 'toggle'; - - var classes = prefix + '-trigger ' + prefix + '-' + action; + prefix = ocsOffCanvasSidebarsSettings.css_prefix, + action = ( field_data.action.val() ) ? field_data.action.val() : 'toggle', + classes = prefix + '-trigger ' + prefix + '-' + action, + singleton = false, + html = ''; if ( field_data.sidebar.val() ) { classes += ' ' + prefix + '-' + action + '-' + field_data.sidebar.val(); @@ -307,17 +309,11 @@ if ( 'undefined' === typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS ) { } attributes.class = classes; - var singleton = false; - if ( 'input' === element ) { - singleton = true; - attributes.value = field_data.text.val(); - } - if ( 'img' === element ) { + if ( 'input' === element || 'img' === element ) { singleton = true; attributes.value = field_data.text.val(); } - var html = ''; if ( singleton ) { html = '<' + element + ' ' + attrObjectToHTML( attributes ) + '>'; } else { @@ -331,7 +327,7 @@ if ( 'undefined' === typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS ) { } /** - * Convert HTML formatted attribute string to object + * Convert HTML formatted attribute string to object. * In: key="value" key="value" * Out: { key: value, key: value } * @@ -354,7 +350,7 @@ if ( 'undefined' === typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS ) { } /** - * Convert OCS formatted attribute string to object + * Convert OCS formatted attribute string to object. * * In: key:value;key:value * Out: { key: value, key: value } @@ -380,7 +376,7 @@ if ( 'undefined' === typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS ) { } /** - * Convert object to OCS formatted attribute string + * Convert object to OCS formatted attribute string. * * In: { key: value, key: value } * Out: key="value" key="value" @@ -400,7 +396,7 @@ if ( 'undefined' === typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS ) { } /** - * Convert object to HTML formatted attribute string + * Convert object to HTML formatted attribute string. * * In: { key: value, key: value } * Out: key:value;key:value @@ -437,6 +433,6 @@ if ( 'undefined' === typeof OCS_OFF_CANVAS_SIDEBARS_SETTINGS ) { }; - OCS_OFF_CANVAS_SIDEBARS_SETTINGS.init(); + ocsOffCanvasSidebarsSettings.init(); -})(jQuery); \ No newline at end of file +} ) ( jQuery ); \ No newline at end of file diff --git a/js/off-canvas-sidebars.js b/js/off-canvas-sidebars.js index 156cccd..57b5a84 100644 --- a/js/off-canvas-sidebars.js +++ b/js/off-canvas-sidebars.js @@ -1,7 +1,6 @@ ;/** * Off-Canvas Sidebars plugin * - * ocsOffCanvasSidebars * @author Jory Hogeveen * @package off-canvas-sidebars * @version 0.4 @@ -22,7 +21,7 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { }; } -(function($) { +( function( $ ) { var $document = $(document); var $window = $(window); @@ -488,4 +487,4 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { ocsOffCanvasSidebars.init(); } -}) (jQuery); \ No newline at end of file +} ) ( jQuery ); \ No newline at end of file diff --git a/slidebars/slidebars.css b/slidebars/slidebars.css index a8e23ee..8b6e63f 100644 --- a/slidebars/slidebars.css +++ b/slidebars/slidebars.css @@ -8,6 +8,12 @@ * License url: http://www.adchsm.com/slidebars/license/ */ +/*! + * Modified by: Jory Hogeveen + * + * @since 0.4 Enhance location selectors, added quotes. + */ + /** * Box Model, Html & Body */ From 31bbf1d672d4284485216fe7a8a4baa7a659253d Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Tue, 29 Aug 2017 04:51:19 +0200 Subject: [PATCH 100/124] Allow 25 char variables --- tests/phpmd.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/phpmd.xml b/tests/phpmd.xml index 1d659b7..3af5c9c 100644 --- a/tests/phpmd.xml +++ b/tests/phpmd.xml @@ -78,6 +78,7 @@ + @@ -85,5 +86,10 @@ + + + + + From c3c9ed51941b840e03fd529bd494a3c03dd5981d Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Tue, 29 Aug 2017 04:51:44 +0200 Subject: [PATCH 101/124] Fix add new sidebar error --- includes/class-settings.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/includes/class-settings.php b/includes/class-settings.php index afc8968..0c8d1fd 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -595,9 +595,12 @@ protected function parse_input( $input ) { if ( ! empty( $input['sidebars']['ocs_add_new'] ) ) { $new_sidebar_id = $this->validate_id( $input['sidebars']['ocs_add_new'] ); if ( empty( $input['sidebars'][ $new_sidebar_id ] ) && empty( $current['sidebars'][ $new_sidebar_id ] ) ) { - $input['sidebars'][ $new_sidebar_id ] = array( - 'enable' => 1, - 'label' => strip_tags( stripslashes( $input['sidebars']['ocs_add_new'] ) ), + $input['sidebars'][ $new_sidebar_id ] = array_merge( + off_canvas_sidebars()->get_default_sidebar_settings(), + array( + 'enable' => 1, + 'label' => strip_tags( stripslashes( $input['sidebars']['ocs_add_new'] ) ), + ) ); } else { add_settings_error( From 0c0aba165c8f8eeb187bc139f756b92d2881e51d Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Tue, 29 Aug 2017 04:53:15 +0200 Subject: [PATCH 102/124] Last fixes for the different style options for legacy mode --- js/fixed-scrolltop.js | 2 +- js/off-canvas-sidebars.js | 12 +++++++----- slidebars/slidebars.js | 4 +++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/js/fixed-scrolltop.js b/js/fixed-scrolltop.js index a62fc06..c4cfc46 100644 --- a/js/fixed-scrolltop.js +++ b/js/fixed-scrolltop.js @@ -42,7 +42,7 @@ ocsOffCanvasSidebars.slidebarEventFixed = function( e, eventType, slidebar ) { // Bottom slidebars. - if ( ( 'bottom' === slidebar.side ) && ( 'opening' === eventType || 'closing' === eventType ) ) { + if ( ( 'bottom' === slidebar.side && 'overlay' !== slidebar.style ) && ( 'opening' === eventType || 'closing' === eventType ) ) { curScrollTopElements.each( function() { var px = ocsOffCanvasSidebars._getTranslateAxis( this, 'y' ); var offset = slidebar.element.height(); diff --git a/js/off-canvas-sidebars.js b/js/off-canvas-sidebars.js index 57b5a84..26bfa38 100644 --- a/js/off-canvas-sidebars.js +++ b/js/off-canvas-sidebars.js @@ -205,13 +205,15 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { elements.attr( { 'canvas-fixed': 'fixed' } ); // Legacy mode (only needed for location: top) - if ( ocsOffCanvasSidebars.legacy_css && 'top' === slidebar.side && 'overlay' !== slidebar.style ) { + // @todo, temp apply for reveal aswell + if ( ocsOffCanvasSidebars.legacy_css && 'top' === slidebar.side && ( 'overlay' !== slidebar.style && 'reveal' !== slidebar.style ) ) { var offset; - if ( 'reveal' === slidebar.style ) { - offset = 0; //parseInt( slidebar.element.css( 'height' ).replace('px', '') ); - } else { + // @todo, temp apply for reveal, should be 0 + //if ( 'reveal' === slidebar.style ) { + //offset = 0; //parseInt( slidebar.element.css( 'height' ).replace('px', '') ); + //} else { offset = parseInt( slidebar.element.css( 'margin-top' ).replace('px', '').replace('-', '') ); - } + //} //Compatibility with WP Admin Bar // @todo, condition for setting diff --git a/slidebars/slidebars.js b/slidebars/slidebars.js index 5dbaef5..2978fc3 100644 --- a/slidebars/slidebars.js +++ b/slidebars/slidebars.js @@ -311,7 +311,9 @@ slidebars = function () { }; canvasCss[ canvasSide ] = '-' + animationProperties.amount; // Move container - canvas.css( canvasCss ); + if ( 'overlay' !== offCanvas[ id ].style ) { + canvas.css( canvasCss ); + } // Open slidebar animationProperties.elements.not( canvas ).css( css ); } else { From 5d6a7887626e6656c153ca510a2e2bc64c200168 Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Tue, 29 Aug 2017 04:59:20 +0200 Subject: [PATCH 103/124] Minify and docs --- css/off-canvas-sidebars-admin.css | 3 +- css/off-canvas-sidebars-admin.min.css | 9 +++ css/off-canvas-sidebars.min.css | 9 +++ js/off-canvas-sidebars.js | 88 +++++++++++++-------------- slidebars/slidebars.css | 5 +- slidebars/slidebars.js | 6 +- slidebars/slidebars.min.css | 8 ++- slidebars/slidebars.min.js | 10 +-- 8 files changed, 80 insertions(+), 58 deletions(-) create mode 100644 css/off-canvas-sidebars-admin.min.css create mode 100644 css/off-canvas-sidebars.min.css diff --git a/css/off-canvas-sidebars-admin.css b/css/off-canvas-sidebars-admin.css index f77fc81..9276787 100644 --- a/css/off-canvas-sidebars-admin.css +++ b/css/off-canvas-sidebars-admin.css @@ -1,9 +1,10 @@ -/** +/*! * Off-Canvas Sidebars plugin * * @author Jory Hogeveen * @package off-canvas-sidebars * @version 0.4 + * @preserve */ .ocs-credits { diff --git a/css/off-canvas-sidebars-admin.min.css b/css/off-canvas-sidebars-admin.min.css new file mode 100644 index 0000000..b5ce97b --- /dev/null +++ b/css/off-canvas-sidebars-admin.min.css @@ -0,0 +1,9 @@ +/*! + * Off-Canvas Sidebars plugin + * + * @author Jory Hogeveen + * @package off-canvas-sidebars + * @version 0.4 + * @preserve + */ +.ocs-credits{overflow:hidden;background:#fff;position:relative;margin:0;box-shadow:0 0 0 1px rgba(0,0,0,0.05)}.ocs-credits .inner{padding-left:10px;padding-right:10px}.ocs-credits h3{font-size:14px;line-height:1.4;margin:0;padding:8px 12px;border-bottom:1px solid #eee}.off-canvas-sidebars-settings .postbox-container{float:none}.postbox.section-sidebar{-webkit-transition:all .1s;-moz-transition:all .1s;-o-transition:all .1s;transition:all .1s}.postbox.section-sidebar:hover{opacity:1 !important}.off-canvas-sidebars-settings fieldset.radio label,.off-canvas-sidebars-settings fieldset.checkbox label{display:block}.off-canvas-sidebars-settings fieldset.radio label+br{display:none}.off-canvas-sidebars-settings fieldset.radio label+.description{margin-bottom:.5em;display:inline-block}.off-canvas-sidebars-settings input+select{vertical-align:top}@media only screen and (min-width:850px){.off-canvas-sidebars-settings{margin-right:300px}.off-canvas-sidebars-settings form{float:left;min-width:100%;width:auto}.ocs-credits{float:right;margin:10px -300px 10px 20px;width:280px}.off-canvas-sidebars-settings .postbox-container .postbox-third{float:left;width:33%;margin-left:.5%;box-sizing:border-box}.off-canvas-sidebars-settings .postbox-container .postbox-third.first{margin-left:0}}@media only screen and (min-width:959px){.ocs-credits{position:fixed;right:0;margin:10px 20px}} \ No newline at end of file diff --git a/css/off-canvas-sidebars.min.css b/css/off-canvas-sidebars.min.css new file mode 100644 index 0000000..e7fb711 --- /dev/null +++ b/css/off-canvas-sidebars.min.css @@ -0,0 +1,9 @@ +/*! + * Off-Canvas Sidebars plugin + * + * @author Jory Hogeveen + * @package off-canvas-sidebars + * @version 0.4 + * @preserve + */ +html,html.ocs-initialized{overflow-y:auto;height:auto}[canvas=container],.ocs-initialized [canvas=container]{overflow-y:hidden;height:auto}.ocs-legacy [canvas]{top:0;right:0;bottom:0;left:0}.ocs-legacy [canvas],.ocs-legacy [off-canvas]{-webkit-transform:none;-moz-transform:none;-ms-transform:none;-o-transform:none;transform:none;-webkit-transition:-webkit-transform 300ms,top 300ms,bottom 300ms,left 300ms,right 300ms,clip-path 0;-moz-transition:-moz-transform 300ms,top 300ms,bottom 300ms,left 300ms,right 300ms,clip-path 0;-o-transition:-o-transform 300ms,top 300ms,bottom 300ms,left 300ms,right 300ms,clip-path 0;transition:transform 300ms,top 300ms,bottom 300ms,left 300ms,right 300ms,clip-path 0}[off-canvas*=" top"][off-canvas*=" reveal"],[off-canvas*=" top"][off-canvas*=" shift"],[off-canvas*=" bottom"][off-canvas*=" reveal"],[off-canvas*=" bottom"][off-canvas*=" shift"]{z-index:1}.ocs-size-default.ocs-location-left,.ocs-size-default.ocs-location-right{width:30%}.ocs-size-small.ocs-location-left,.ocs-size-small.ocs-location-right{width:15%}.ocs-size-large.ocs-location-left,.ocs-size-large.ocs-location-right{width:45%}.ocs-size-default.ocs-location-top,.ocs-size-default.ocs-location-bottom{height:30%}.ocs-size-small.ocs-location-top,.ocs-size-small.ocs-location-bottom{height:15%}.ocs-size-large.ocs-location-top,.ocs-size-large.ocs-location-bottom{height:45%}@media(max-width:480px){.ocs-size-default.ocs-location-left,.ocs-size-default.ocs-location-right{width:60%}.ocs-size-small.ocs-location-left,.ocs-size-small.ocs-location-right{width:35%}.ocs-size-large.ocs-location-left,.ocs-size-large.ocs-location-right{width:85%}.ocs-size-default.ocs-location-top,.ocs-size-default.ocs-location-bottom{height:40%}.ocs-size-small.ocs-location-top,.ocs-size-small.ocs-location-bottom{height:20%}.ocs-size-large.ocs-location-top,.ocs-size-large.ocs-location-bottom{height:60%}}@media(min-width:481px){.ocs-size-default.ocs-location-left,.ocs-size-default.ocs-location-right{width:50%}.ocs-size-small.ocs-location-left,.ocs-size-small.ocs-location-right{width:30%}.ocs-size-large.ocs-location-left,.ocs-size-large.ocs-location-right{width:70%}.ocs-size-default.ocs-location-top,.ocs-size-default.ocs-location-bottom{height:40%}.ocs-size-small.ocs-location-top,.ocs-size-small.ocs-location-bottom{height:20%}.ocs-size-large.ocs-location-top,.ocs-size-large.ocs-location-bottom{height:60%}}@media(min-width:768px){.ocs-size-default.ocs-location-left,.ocs-size-default.ocs-location-right{width:40%}.ocs-size-small.ocs-location-left,.ocs-size-small.ocs-location-right{width:25%}.ocs-size-large.ocs-location-left,.ocs-size-large.ocs-location-right{width:55%}.ocs-size-default.ocs-location-top,.ocs-size-default.ocs-location-bottom{height:35%}.ocs-size-small.ocs-location-top,.ocs-size-small.ocs-location-bottom{height:20%}.ocs-size-large.ocs-location-top,.ocs-size-large.ocs-location-bottom{height:55%}}@media(min-width:992px){.ocs-size-default.ocs-location-left,.ocs-size-default.ocs-location-right{width:30%}.ocs-size-small.ocs-location-left,.ocs-size-small.ocs-location-right{width:15%}.ocs-size-large.ocs-location-left,.ocs-size-large.ocs-location-right{width:45%}.ocs-size-default.ocs-location-top,.ocs-size-default.ocs-location-bottom{height:30%}.ocs-size-small.ocs-location-top,.ocs-size-small.ocs-location-bottom{height:15%}.ocs-size-large.ocs-location-top,.ocs-size-large.ocs-location-bottom{height:45%}}@media(min-width:1200px){.ocs-size-default.ocs-location-left,.ocs-size-default.ocs-location-right{width:25%}.ocs-size-small.ocs-location-left,.ocs-size-small.ocs-location-right{width:10%}.ocs-size-large.ocs-location-left,.ocs-size-large.ocs-location-right{width:40%}.ocs-size-default.ocs-location-top,.ocs-size-default.ocs-location-bottom{height:25%}.ocs-size-small.ocs-location-top,.ocs-size-small.ocs-location-bottom{height:10%}.ocs-size-large.ocs-location-top,.ocs-size-large.ocs-location-bottom{height:40%}} \ No newline at end of file diff --git a/js/off-canvas-sidebars.js b/js/off-canvas-sidebars.js index 26bfa38..ac3ccbe 100644 --- a/js/off-canvas-sidebars.js +++ b/js/off-canvas-sidebars.js @@ -37,8 +37,8 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { ocsOffCanvasSidebars.init = function() { /** - * Validate the disable_over setting ( using _getSetting() ) - * Internal function, do not overwrite + * Validate the disable_over setting ( using _getSetting() ). + * Internal function, do not overwrite. * @since 0.3 * @param {string} sidebarId The sidebar ID. * @return {bool} disableOver status. @@ -55,12 +55,12 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { }; /** - * Get the global setting or the sidebar setting (if set to overwrite) - - * Internal function, do not overwrite - + * Get the global setting or the sidebar setting (if set to overwrite). + * + * Internal function, do not overwrite. + * * @since 0.3 - * @param {string} key The setting key to look for + * @param {string} key The setting key to look for. * @param {string|bool|null} sidebarId The sidebar ID. * Pass `false` to check for an active slidebar. * Pass `null` or no value for only the global setting. @@ -88,7 +88,7 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { } } - // Fallback/Overwrite to enable sidebar settings from available attributes + // Fallback/Overwrite to enable sidebar settings from available attributes. } else { var sidebarElement = $( '#' + sidebarId ); overwrite = sidebarElement.attr( 'ocs-overwrite_global_settings' ); @@ -133,13 +133,13 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { var val = false; switch ( axis ) { case 'x': - val = matrix[12] || matrix[4]; //translate x + val = matrix[12] || matrix[4]; //translate x. break; case 'y': - val = matrix[13] || matrix[5]; //translate y + val = matrix[13] || matrix[5]; //translate y. break; case 'z': - val = matrix[14] || matrix[6]; //translate z + val = matrix[14] || matrix[6]; //translate z. break; } return parseFloat( val ); @@ -152,7 +152,7 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { $window.trigger( 'ocs_loaded', this ); - // Slidebars constructor + // Slidebars constructor. ocsOffCanvasSidebars.slidebarsController = new slidebars(); if ( false === ocsOffCanvasSidebars.slidebarsController ) { @@ -165,7 +165,7 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { ocsOffCanvasSidebars._html.addClass('ocs-legacy'); } - // Initialize slidebars + // Initialize slidebars. ocsOffCanvasSidebars.slidebarsController.init(); ocsOffCanvasSidebars._html.addClass('ocs-initialized'); @@ -173,7 +173,7 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { $window.trigger( 'ocs_initialized', this ); /** - * Compatibility with WP Admin Bar + * Compatibility with WP Admin Bar. * @since 0.4 */ if ( ocsOffCanvasSidebars._toolbar ) { @@ -194,7 +194,7 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { } /** - * Fix position issues for fixed elements on slidebar animations + * Fix position issues for fixed elements on slidebar animations. * @since 0.4 */ $( ocsOffCanvasSidebars.slidebarsController.events ).on( 'opening opened closing closed', function( e, sidebar_id ) { @@ -204,7 +204,7 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { var elements = ocsOffCanvasSidebars.getFixedElements(); elements.attr( { 'canvas-fixed': 'fixed' } ); - // Legacy mode (only needed for location: top) + // Legacy mode (only needed for location: top). // @todo, temp apply for reveal aswell if ( ocsOffCanvasSidebars.legacy_css && 'top' === slidebar.side && ( 'overlay' !== slidebar.style && 'reveal' !== slidebar.style ) ) { var offset; @@ -215,7 +215,7 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { offset = parseInt( slidebar.element.css( 'margin-top' ).replace('px', '').replace('-', '') ); //} - //Compatibility with WP Admin Bar + //Compatibility with WP Admin Bar. // @todo, condition for setting if ( ocsOffCanvasSidebars._toolbar ) { var bodyOffset = $body.offset(); @@ -224,12 +224,12 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { elements.each( function() { var $this = $(this); - // Set animation + // Set animation. if ( 'opening' === e.type ) { ocsOffCanvasSidebars.cssCompat( $this, 'transition', 'top ' + duration + 'ms' ); $this.css( 'top', parseInt( $this.css('top').replace('px', '') ) + offset + 'px' ); } - // Remove animation + // Remove animation. else if ( 'closing' === e.type ) { $this.css( 'top', parseInt( $this.css('top').replace('px', '') ) - offset + 'px' ); setTimeout( function() { @@ -238,7 +238,7 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { } } ); } - // Normal mode (only sets a transition for use in fixed-scrolltop.js) + // Normal mode (only sets a transition for use in fixed-scrolltop.js). else { elements.each( function() { var $this = $(this); @@ -256,7 +256,7 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { } } ); - // Prevent swipe events to be seen as a click (bug in some browsers) + // Prevent swipe events to be seen as a click (bug in some browsers). $document.on( 'touchmove', function() { ocsOffCanvasSidebars._touchmove = true; } ); @@ -264,7 +264,7 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { ocsOffCanvasSidebars._touchmove = false; } ); - // Validate type, this could be changed with the hooks + // Validate type, this could be changed with the hooks. if ( 'function' === typeof ocsOffCanvasSidebars.setupTriggers ) { ocsOffCanvasSidebars.setupTriggers(); } @@ -305,55 +305,55 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { ocsOffCanvasSidebars.setSidebarDefaultSettings( id ); /** - * Toggle the sidebar + * Toggle the sidebar. * @since 0.1 */ $document.on( 'touchend click', '.' + prefix + '-toggle-' + id, function( e ) { - // Stop default action and bubbling + // Stop default action and bubbling. e.stopPropagation(); e.preventDefault(); - // Prevent touch+swipe + // Prevent touch+swipe. if ( true === ocsOffCanvasSidebars._touchmove ) { return; } - // Toggle the slidebar with respect for the disable_over setting + // Toggle the slidebar with respect for the disable_over setting. if ( ocsOffCanvasSidebars._checkDisableOver( prefix + '-' + id ) ) { controller.toggle( prefix + '-' + id ); } } ); /** - * Open the sidebar + * Open the sidebar. * @since 0.3 */ $document.on( 'touchend click', '.' + prefix + '-open-' + id, function( e ) { - // Stop default action and bubbling + // Stop default action and bubbling. e.stopPropagation(); e.preventDefault(); - // Prevent touch+swipe + // Prevent touch+swipe. if ( true === ocsOffCanvasSidebars._touchmove ) { return; } - // Open the slidebar with respect for the disable_over setting + // Open the slidebar with respect for the disable_over setting. if ( ocsOffCanvasSidebars._checkDisableOver( prefix + '-' + id ) ) { controller.open( prefix + '-' + id ); } } ); /** - * Close the sidebar + * Close the sidebar. * @since 0.3 */ $document.on( 'touchend click', '.' + prefix + '-close-' + id, function( e ) { - // Stop default action and bubbling + // Stop default action and bubbling. e.stopPropagation(); e.preventDefault(); - // Prevent touch+swipe + // Prevent touch+swipe. if ( true === ocsOffCanvasSidebars._touchmove ) { return; } @@ -363,7 +363,7 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { } ); - // Close any + // Close any. $document.on( 'touchend click', '.' + prefix + '-close-any', function( e ) { if ( ocsOffCanvasSidebars._getSetting( 'site_close', false ) ) { e.preventDefault(); @@ -372,14 +372,14 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { } } ); - // Close the slidebar after clicking a link + // Close the slidebar after clicking a link. $( 'a' ).not( '.' + prefix + '-trigger' ).on( 'touchend click', function() { if ( ! $(this).parents( '.' + prefix + '-trigger' ).length ) { controller.close(); } } ); - // Close Slidebars when clicking on a link within a slidebar + // Close Slidebars when clicking on a link within a slidebar. /*$( '[off-canvas] a' ).on( 'touchend click', function( e ) { e.preventDefault(); e.stopPropagation(); @@ -392,7 +392,7 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { } ); } );*/ - // Add close class to canvas container when Slidebar is opened + // Add close class to canvas container when Slidebar is opened. $( controller.events ).on( 'opening', function () { $( '[canvas]' ).addClass( prefix + '-close-any' ); ocsOffCanvasSidebars._html.addClass( 'ocs-sidebar-active' ); @@ -401,13 +401,13 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { } } ); - // Add close class to canvas container when Slidebar is opened + // Add close class to canvas container when Slidebar is opened. $( controller.events ).on( 'closing', function () { $( '[canvas]' ).removeClass( prefix + '-close-any' ); ocsOffCanvasSidebars._html.removeClass( 'ocs-sidebar-active ocs-scroll-lock' ); } ); - // Disable slidebars when the window is wider than the set width + // Disable slidebars when the window is wider than the set width. var disableOver = function() { var prefix = ocsOffCanvasSidebars.css_prefix; sidebarElements.each( function() { @@ -417,7 +417,7 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { if ( controller.isActiveSlidebar( prefix + '-' + id ) ) { controller.close(); } - // Hide control classes + // Hide control classes. if ( ocsOffCanvasSidebars._getSetting( 'hide_control_classes', prefix + '-' + id ) ) { $( '.' + prefix + '-toggle-' + id ).hide(); } @@ -430,7 +430,7 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { disableOver(); $window.on( 'resize', disableOver ); - // Disable scrolling outside of active sidebar + // Disable scrolling outside of active sidebar. $( '#' + prefix + '-site' ).on( 'scroll touchmove mousewheel DOMMouseScroll', function( e ) { //if ( ocsOffCanvasSidebars._getSetting( 'scroll_lock' ) && false != controller.getActiveSlidebar() ) { if ( ocsOffCanvasSidebars._html.hasClass( 'ocs-scroll-lock' ) ) { @@ -440,16 +440,16 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { } } ); - // Disable scrolling site when scrolling inside active sidebar + // Disable scrolling site when scrolling inside active sidebar. sidebarElements.on( 'scroll touchmove mousewheel DOMMouseScroll', function( e ) { //if ( ocsOffCanvasSidebars._getSetting( 'scroll_lock', false ) ) { if ( ocsOffCanvasSidebars._html.hasClass( 'ocs-scroll-lock' ) ) { var $this = $(this); if ( 0 > e.originalEvent.deltaY ) { - /* scrolling up */ + // scrolling up. return ( 0 < $this.scrollTop() ); } else { - /* scrolling down */ + // scrolling down. return ( $this.scrollTop() + $this.innerHeight() < $this[0].scrollHeight ); } } diff --git a/slidebars/slidebars.css b/slidebars/slidebars.css index 8b6e63f..3e41579 100644 --- a/slidebars/slidebars.css +++ b/slidebars/slidebars.css @@ -6,10 +6,9 @@ * Author url: http://www.adchsm.com/ * License: MIT * License url: http://www.adchsm.com/slidebars/license/ - */ - -/*! + * * Modified by: Jory Hogeveen + * Version numbers below are related to Off-Canvas Sidebars, not Slidebars. * * @since 0.4 Enhance location selectors, added quotes. */ diff --git a/slidebars/slidebars.js b/slidebars/slidebars.js index 2978fc3..70d5229 100644 --- a/slidebars/slidebars.js +++ b/slidebars/slidebars.js @@ -6,10 +6,9 @@ * Author url: http://www.adchsm.com/ * License: MIT * License url: http://www.adchsm.com/slidebars/license/ - */ - -/*! + * * Modified by: Jory Hogeveen + * Version numbers below are related to Off-Canvas Sidebars, not Slidebars. * * @since 0.4 Add scope for this reference + Add legacy CSS support (no hardware acceleration) */ @@ -431,6 +430,7 @@ slidebars = function () { // Hide the Slidebar offCanvas[ id ].element.css( 'display', '' ); + // Trigger event $( events ).trigger( 'closed', [ offCanvas[ id ].id ] ); diff --git a/slidebars/slidebars.min.css b/slidebars/slidebars.min.css index 86896d1..b2f7dea 100644 --- a/slidebars/slidebars.min.css +++ b/slidebars/slidebars.min.css @@ -6,6 +6,10 @@ * Author url: http://www.adchsm.com/ * License: MIT * License url: http://www.adchsm.com/slidebars/license/ + * + * Modified by: Jory Hogeveen + * Version numbers below are related to Off-Canvas Sidebars, not Slidebars. + * + * @since 0.4 Enhance location selectors, added quotes. */ - -[canvas],[off-canvas*=push]{z-index:1}[off-canvas*=reveal],[off-canvas*=shift]{z-index:0}[canvas=container],[off-canvas],body,html{margin:0;padding:0;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}body,html{width:100%;height:100%;overflow:hidden}[canvas=container]{width:100%;height:100%;overflow-y:auto;position:relative;background-color:#fff;-webkit-overflow-scrolling:touch}[canvas=container]:after,[canvas=container]:before{clear:both;content:'';display:table}[off-canvas]{display:none;position:fixed;overflow:hidden;overflow-y:auto;background-color:#000;color:#fff;-webkit-overflow-scrolling:touch}[off-canvas*=top]{width:100%;height:255px;top:0}[off-canvas*=right]{width:255px;height:100%;top:0;right:0}[off-canvas*=bottom]{width:100%;height:255px;bottom:0}[off-canvas*=left]{width:255px;height:100%;top:0;left:0}[off-canvas*=overlay]{z-index:9999}[canvas],[off-canvas]{-webkit-transform:translate(0,0);-ms-transform:translate(0,0);transform:translate(0,0);-webkit-transition:-webkit-transform .3s;transition:transform .3s;-webkit-backface-visibility:hidden}[off-canvas*=shift][off-canvas*=top]{-webkit-transform:translate(0,50%);transform:translate(0,50%)}[off-canvas*=shift][off-canvas*=right]{-webkit-transform:translate(-50%,0);transform:translate(-50%,0)}[off-canvas*=shift][off-canvas*=bottom]{-webkit-transform:translate(0,-50%);transform:translate(0,-50%)}[off-canvas*=shift][off-canvas*=left]{-webkit-transform:translate(50%,0);transform:translate(50%,0)}@media print{[canvas]{-webkit-transform:translate(0,0)!important;-ms-transform:translate(0,0)!important;transform:translate(0,0)!important}[off-canvas]{display:none!important}} \ No newline at end of file +html,body,[canvas=container],[off-canvas]{margin:0;padding:0;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}html,body{width:100%;height:100%;overflow:hidden}[canvas]{z-index:1}[canvas=container]{width:100%;height:100%;overflow-y:auto;position:relative;background-color:white;-webkit-overflow-scrolling:touch}[canvas=container]:before,[canvas=container]:after{clear:both;content:'';display:table}[off-canvas]{display:none;position:fixed;overflow:hidden;overflow-y:auto;background-color:black;color:white;-webkit-overflow-scrolling:touch}[off-canvas*=" top"]{width:100%;height:255px;top:0}[off-canvas*=" right"]{width:255px;height:100%;top:0;right:0}[off-canvas*=" bottom"]{width:100%;height:255px;bottom:0}[off-canvas*=" left"]{width:255px;height:100%;top:0;left:0}[off-canvas*=" reveal"]{z-index:0}[off-canvas*=" push"]{z-index:1}[off-canvas*=" overlay"]{z-index:9999}[off-canvas*=" shift"]{z-index:0}[canvas],[off-canvas]{-webkit-transform:translate(0,0);-ms-transform:translate(0,0);transform:translate(0,0);-webkit-transition:-webkit-transform 300ms;transition:transform 300ms;-webkit-backface-visibility:hidden}[off-canvas*=" shift"][off-canvas*=" top"]{-webkit-transform:translate(0,50%);transform:translate(0,50%)}[off-canvas*=" shift"][off-canvas*=" right"]{-webkit-transform:translate(-50%,0);transform:translate(-50%,0)}[off-canvas*=" shift"][off-canvas*=" bottom"]{-webkit-transform:translate(0,-50%);transform:translate(0,-50%)}[off-canvas*=" shift"][off-canvas*=" left"]{-webkit-transform:translate(50%,0);transform:translate(50%,0)}@media print{[canvas]{-webkit-transform:translate(0,0) !important;-ms-transform:translate(0,0) !important;transform:translate(0,0) !important}[off-canvas]{display:none !important}} \ No newline at end of file diff --git a/slidebars/slidebars.min.js b/slidebars/slidebars.min.js index 37f000d..239fb58 100644 --- a/slidebars/slidebars.min.js +++ b/slidebars/slidebars.min.js @@ -6,10 +6,10 @@ * Author url: http://www.adchsm.com/ * License: MIT * License url: http://www.adchsm.com/slidebars/license/ - */ - -/*! + * * Modified by: Jory Hogeveen + * Version numbers below are related to Off-Canvas Sidebars, not Slidebars. + * + * @since 0.4 Add scope for this reference + Add legacy CSS support (no hardware acceleration) */ - -var slidebars;!function($){slidebars=function(){var t=$("[canvas]"),e={},i=!1,n=!1,s=["top","right","bottom","left"],r=["reveal","push","overlay","shift"],o=function(i){var n=$(),s="0px, 0px",r=1e3*parseFloat(e[i].element.css("transitionDuration"),10);return("reveal"===e[i].style||"push"===e[i].style||"shift"===e[i].style)&&(n=n.add(t)),("push"===e[i].style||"overlay"===e[i].style||"shift"===e[i].style)&&(n=n.add(e[i].element)),e[i].active&&("top"===e[i].side?s="0px, "+e[i].element.css("height"):"right"===e[i].side?s="-"+e[i].element.css("width")+", 0px":"bottom"===e[i].side?s="0px, -"+e[i].element.css("height"):"left"===e[i].side&&(s=e[i].element.css("width")+", 0px")),{elements:n,amount:s,duration:r}},c=function(t,i,n,s){return a(t)?!1:void(e[t]={id:t,side:i,style:n,element:s,active:!1})},a=function(t){return e.hasOwnProperty(t)?!0:!1};this.init=function(t){return i?!1:(n||($("[off-canvas]").each(function(){var t=$(this).attr("off-canvas").split(" ",3);return t&&t[0]&&-1!==s.indexOf(t[1])&&-1!==r.indexOf(t[2])?void c(t[0],t[1],t[2],$(this)):!1}),n=!0),i=!0,this.css(),$(f).trigger("init"),void("function"==typeof t&&t()))},this.exit=function(t){if(!i)return!1;var e=function(){i=!1,$(f).trigger("exit"),"function"==typeof t&&t()};this.getActiveSlidebar()?this.close(e):e()},this.css=function(t){if(!i)return!1;for(var n in e)if(a(n)){var s;s="top"===e[n].side||"bottom"===e[n].side?e[n].element.css("height"):e[n].element.css("width"),("push"===e[n].style||"overlay"===e[n].style||"shift"===e[n].style)&&e[n].element.css("margin-"+e[n].side,"-"+s)}this.getActiveSlidebar()&&this.open(this.getActiveSlidebar()),$(f).trigger("css"),"function"==typeof t&&t()},this.open=function(t,n){if(!i)return!1;if(!t||!a(t))return!1;var s=function(){e[t].active=!0,e[t].element.css("display","block"),$(f).trigger("opening",[e[t].id]);var i=o(t);i.elements.css({"transition-duration":i.duration+"ms",transform:"translate("+i.amount+")"}),setTimeout(function(){$(f).trigger("opened",[e[t].id]),"function"==typeof n&&n()},i.duration)};this.getActiveSlidebar()&&this.getActiveSlidebar()!==t?this.close(s):s()},this.close=function(t,n){if("function"==typeof t&&(n=t,t=null),!i)return!1;if(t&&!a(t))return!1;if(t||(t=this.getActiveSlidebar()),t&&e[t].active){e[t].active=!1,$(f).trigger("closing",[e[t].id]);var s=o(t);s.elements.css("transform",""),setTimeout(function(){s.elements.css("transition-duration",""),e[t].element.css("display",""),$(f).trigger("closed",[e[t].id]),"function"==typeof n&&n()},s.duration)}},this.toggle=function(t,n){return i&&t&&a(t)?void(e[t].active?this.close(t,function(){"function"==typeof n&&n()}):this.open(t,function(){"function"==typeof n&&n()})):!1},this.isActive=function(){return i},this.isActiveSlidebar=function(t){return i&&t&&a(t)?e[t].active:!1},this.getActiveSlidebar=function(){if(!i)return!1;var t=!1;for(var n in e)if(a(n)&&e[n].active){t=e[n].id;break}return t},this.getSlidebars=function(){if(!i)return!1;var t=[];for(var n in e)a(n)&&t.push(e[n].id);return t},this.getSlidebar=function(t){return i&&t&&t&&a(t)?e[t]:!1},this.events={};var f=this.events;$(window).on("resize",this.css.bind(this))};}(jQuery); \ No newline at end of file +var slidebars;(function($){slidebars=function(){var canvas=$("[canvas]"),canvas_fixed=$("[canvas-fixed]");offCanvas={},self=this,init=false,registered=false,sides=["top","right","bottom","left"],styles=["reveal","push","overlay","shift"],getAnimationProperties=function(id){var elements=$(),amount="0px, 0px",size="0px",duration=parseFloat(offCanvas[id].element.css("transitionDuration"))*1e3;if("reveal"===offCanvas[id].style||"push"===offCanvas[id].style||"shift"===offCanvas[id].style){elements=elements.add(canvas)}if("reveal"===offCanvas[id].style&&("top"===offCanvas[id].side||"bottom"===offCanvas[id].side)){elements=elements.add(offCanvas[id].element)}if("push"===offCanvas[id].style||"overlay"===offCanvas[id].style||"shift"===offCanvas[id].style){elements=elements.add(offCanvas[id].element)}if(offCanvas[id].active||self.legacy){if("top"===offCanvas[id].side||"bottom"===offCanvas[id].side){size=offCanvas[id].element.css("height")}else{size=offCanvas[id].element.css("width")}if(self.legacy){amount=size}else{if("top"===offCanvas[id].side){amount="0px, "+size}else if("right"===offCanvas[id].side){amount="-"+size+", 0px"}else if("bottom"===offCanvas[id].side){amount="0px, -"+size}else if("left"===offCanvas[id].side){amount=size+", 0px"}}}return{elements:elements,amount:amount,duration:duration}},registerSlidebar=function(id,side,style,element){if(isRegisteredSlidebar(id)){throw"Error registering Slidebar, a Slidebar with id '"+id+"' already exists."}offCanvas[id]={id:id,side:side,style:style,element:element,active:false}},isRegisteredSlidebar=function(id){return offCanvas.hasOwnProperty(id)};this.legacy=false;this.init=function(callback){if(init){throw"Slidebars has already been initialized."}if(!registered){$("[off-canvas]").each(function(){var parameters=$(this).attr("off-canvas").split(" ",3);if(!parameters||!parameters[0]||-1===sides.indexOf(parameters[1])||-1===styles.indexOf(parameters[2])){throw"Error registering Slidebar, please specify a valid id, side and style'."}registerSlidebar(parameters[0],parameters[1],parameters[2],$(this))});registered=true}init=true;this.css();$(events).trigger("init");if("function"===typeof callback){callback()}};this.exit=function(callback){if(!init){throw"Slidebars hasn't been initialized."}var exit=function(){init=false;$(events).trigger("exit");if("function"===typeof callback){callback()}};if(this.getActiveSlidebar()){this.close(exit)}else{exit()}};this.css=function(callback){if(!init){throw"Slidebars hasn't been initialized."}for(var id in offCanvas){if(offCanvas.hasOwnProperty(id)&&isRegisteredSlidebar(id)){var offset;if("top"===offCanvas[id].side||"bottom"===offCanvas[id].side){offset=offCanvas[id].element.css("height")}else{offset=offCanvas[id].element.css("width")}var do_offset=false;if("push"===offCanvas[id].style||"overlay"===offCanvas[id].style||"shift"===offCanvas[id].style){do_offset=true}else if("reveal"===offCanvas[id].style&&("top"===offCanvas[id].side||"bottom"===offCanvas[id].side)){do_offset=true}if(do_offset){offCanvas[id].element.css("margin-"+offCanvas[id].side,"-"+offset);if(self.legacy&&"shift"===offCanvas[id].style){var shiftPos;if("top"===offCanvas[id].side||"bottom"===offCanvas[id].side){shiftPos=offCanvas[id].element.height()/1.9}else if("left"===offCanvas[id].side||"right"===offCanvas[id].side){shiftPos=offCanvas[id].element.width()/1.9}if("left"===offCanvas[id].side||"right"===offCanvas[id].side){offCanvas[id].element.css(offCanvas[id].side,shiftPos+"px")}}}}}if(this.getActiveSlidebar()){this.open(this.getActiveSlidebar())}$(events).trigger("css");if("function"===typeof callback){callback()}};this.open=function(id,callback){if(!init){throw"Slidebars hasn't been initialized."}if(!id||!isRegisteredSlidebar(id)){throw"Error opening Slidebar, there is no Slidebar with id '"+id+"'."}var open=function(){offCanvas[id].active=true;offCanvas[id].element.css("display","block");$(events).trigger("opening",[offCanvas[id].id]);var animationProperties=getAnimationProperties(id);var css={"-webkit-transition-duration":animationProperties.duration+"ms","-moz-transition-duration":animationProperties.duration+"ms","-o-transition-duration":animationProperties.duration+"ms","transition-duration":animationProperties.duration+"ms"};if(self.legacy){css[offCanvas[id].side]=animationProperties.amount;var canvasSide;if("right"===offCanvas[id].side||"bottom"===offCanvas[id].side){if("right"===offCanvas[id].side){canvasSide="left"}else if("bottom"===offCanvas[id].side){canvasSide="top"}var canvasCss={"-webkit-transition-duration":animationProperties.duration+"ms","-moz-transition-duration":animationProperties.duration+"ms","-o-transition-duration":animationProperties.duration+"ms","transition-duration":animationProperties.duration+"ms"};canvasCss[canvasSide]="-"+animationProperties.amount;if("overlay"!==offCanvas[id].style){canvas.css(canvasCss)}animationProperties.elements.not(canvas).css(css)}else{animationProperties.elements.css(css)}}else{css.transform="translate("+animationProperties.amount+")";animationProperties.elements.css(css)}setTimeout(function(){$(events).trigger("opened",[offCanvas[id].id]);if("function"===typeof callback){callback()}},animationProperties.duration)};if(this.getActiveSlidebar()&&this.getActiveSlidebar()!==id){this.close(open)}else{open()}};this.close=function(id,callback){if("function"===typeof id){callback=id;id=null}if(!init){throw"Slidebars hasn't been initialized."}if(id&&!isRegisteredSlidebar(id)){throw"Error closing Slidebar, there is no Slidebar with id '"+id+"'."}if(!id){id=this.getActiveSlidebar()}if(id&&offCanvas[id].active){offCanvas[id].active=false;$(events).trigger("closing",[offCanvas[id].id]);var animationProperties=getAnimationProperties(id);if(self.legacy){var css={};var canvasSide;if("right"===offCanvas[id].side||"bottom"===offCanvas[id].side){if("right"===offCanvas[id].side){canvasSide="left"}else if("bottom"===offCanvas[id].side){canvasSide="top"}canvas.css(canvasSide,"");animationProperties.elements.not(canvas).css(offCanvas[id].side,"")}else{animationProperties.elements.css(offCanvas[id].side,"")}if("shift"===offCanvas[id].style){var shiftPos;if("top"===offCanvas[id].side||"bottom"===offCanvas[id].side){shiftPos=offCanvas[id].element.height()/1.9}else if("left"===offCanvas[id].side||"right"===offCanvas[id].side){shiftPos=offCanvas[id].element.width()/1.9}if("left"===offCanvas[id].side||"right"===offCanvas[id].side){offCanvas[id].element.css(offCanvas[id].side,shiftPos+"px")}}}else{animationProperties.elements.css("transform","")}setTimeout(function(){animationProperties.elements.css({"-webkit-transition-duration":"","-moz-transition-duration":"","-o-transition-duration":"","transition-duration":""});offCanvas[id].element.css("display","");$(events).trigger("closed",[offCanvas[id].id]);if("function"===typeof callback){callback()}},animationProperties.duration)}};this.toggle=function(id,callback){if(!init){throw"Slidebars hasn't been initialized."}if(!id||!isRegisteredSlidebar(id)){throw"Error toggling Slidebar, there is no Slidebar with id '"+id+"'."}if(offCanvas[id].active){this.close(id,function(){if("function"===typeof callback){callback()}})}else{this.open(id,function(){if("function"===typeof callback){callback()}})}};this.isActive=function(id){return init};this.isActiveSlidebar=function(id){if(!init){throw"Slidebars hasn't been initialized."}if(!id){throw"You must provide a Slidebar id."}if(!isRegisteredSlidebar(id)){throw"Error retrieving Slidebar, there is no Slidebar with id '"+id+"'."}return offCanvas[id].active};this.getActiveSlidebar=function(){if(!init){throw"Slidebars hasn't been initialized."}var active=false;for(var id in offCanvas){if(isRegisteredSlidebar(id)){if(offCanvas[id].active){active=offCanvas[id].id;break}}}return active};this.getSlidebars=function(){if(!init){throw"Slidebars hasn't been initialized."}var slidebarsArray=[];for(var id in offCanvas){if(isRegisteredSlidebar(id)){slidebarsArray.push(offCanvas[id].id)}}return slidebarsArray};this.getSlidebar=function(id){if(!init){throw"Slidebars hasn't been initialized."}if(!id){throw"You must pass a Slidebar id."}if(!id||!isRegisteredSlidebar(id)){throw"Error retrieving Slidebar, there is no Slidebar with id '"+id+"'."}return offCanvas[id]};this.events={};var events=this.events;$(window).on("resize",this.css.bind(this))}})(jQuery); \ No newline at end of file From f9d85061ea5c43a90e0c0c91439080889cb10d45 Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Tue, 29 Aug 2017 05:15:23 +0200 Subject: [PATCH 104/124] Codestyle --- includes/class-menu-meta-box.php | 115 ++++++++++++++++--------------- 1 file changed, 60 insertions(+), 55 deletions(-) diff --git a/includes/class-menu-meta-box.php b/includes/class-menu-meta-box.php index 388fb5f..f242eba 100644 --- a/includes/class-menu-meta-box.php +++ b/includes/class-menu-meta-box.php @@ -7,7 +7,7 @@ * @package off-canvas-sidebars * @version 0.4 * - * Credits to the Polylang plugin + * Credits to the Polylang plugin. */ if ( ! defined( 'ABSPATH' ) ) { @@ -127,9 +127,9 @@ public function admin_enqueue_scripts() { wp_enqueue_script( 'off_canvas_control_nav_menu', OCS_PLUGIN_URL . '/js/nav-menu' . $suffix . '.js', array( 'jquery' ), $version ); $data['strings'] = array( - 'show_icon' => __( 'Show icon', 'off-canvas-sidebars' ), - 'icon' => __( 'Icon classes', 'off-canvas-sidebars' ), - 'menu_item_type' => __( 'Off-Canvas Control', 'off-canvas-sidebars' ), + 'show_icon' => __( 'Show icon', 'off-canvas-sidebars' ), + 'icon' => __( 'Icon classes', 'off-canvas-sidebars' ), + 'menu_item_type' => __( 'Off-Canvas Control', 'off-canvas-sidebars' ), 'no_sidebars_available' => $this->general_labels['no_sidebars_available'], ); $data['controls'] = array(); @@ -168,54 +168,57 @@ public function admin_enqueue_scripts() { public function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0 ) { $off_canvas_sidebars = off_canvas_sidebars(); + // @codingStandardsIgnoreLine if ( empty( $_POST['menu-item-url'][ $menu_item_db_id ] ) || '#off_canvas_control' !== $_POST['menu-item-url'][ $menu_item_db_id ] ) return; - // security check - // as 'wp_update_nav_menu_item' can be called from outside WP admin - if ( current_user_can( 'edit_theme_options' ) ) { + // Security check since 'wp_update_nav_menu_item' can be called from outside WP admin. + if ( ! current_user_can( 'edit_theme_options' ) ) { + return; + } - check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' ); + check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' ); - $available_controls = array(); - foreach ( $this->settings['sidebars'] as $sidebar => $sidebar_data ) { - $available_controls[ $sidebar ] = $sidebar_data['label']; - } - - // Autoselect control when adding a new item - $default_control = ''; - if ( in_array( $_POST['menu-item-title'][ $menu_item_db_id ], $available_controls, true ) ) { - $default_control = $off_canvas_sidebars->get_sidebar_key_by_label( $_POST['menu-item-title'][ $menu_item_db_id ] ); - } - $options = array( 'off-canvas-control' => $default_control ); // default values + $available_controls = array(); + foreach ( $this->settings['sidebars'] as $sidebar => $sidebar_data ) { + $available_controls[ $sidebar ] = $sidebar_data['label']; + } - // our jQuery form has not been displayed - if ( empty( $_POST['menu-item-off-canvas-control-detect'][ $menu_item_db_id ] ) ) { + // Auto select control when adding a new item. + $default_control = ''; + if ( in_array( $_POST['menu-item-title'][ $menu_item_db_id ], $available_controls, true ) ) { + $default_control = $off_canvas_sidebars->get_sidebar_key_by_label( $_POST['menu-item-title'][ $menu_item_db_id ] ); + } + // default values. + $options = array( 'off-canvas-control' => $default_control ); - if ( ! get_post_meta( $menu_item_db_id, '_off_canvas_control_menu_item', true ) ) // our options were never saved - update_post_meta( $menu_item_db_id, '_off_canvas_control_menu_item', $options ); + // Our jQuery form has not been displayed. + if ( empty( $_POST['menu-item-off-canvas-control-detect'][ $menu_item_db_id ] ) ) { - } else { + // Our options were never saved. + if ( ! get_post_meta( $menu_item_db_id, '_off_canvas_control_menu_item', true ) ) { + update_post_meta( $menu_item_db_id, '_off_canvas_control_menu_item', $options ); + } - $options['off-canvas-control'] = ''; + } else { - // If only one is available, allways select it - if ( ! empty( $_POST['menu-item-off-canvas-control'][ $menu_item_db_id ] ) && array_key_exists( $_POST['menu-item-off-canvas-control'][ $menu_item_db_id ], $available_controls ) ) { - $options['off-canvas-control'] = strip_tags( stripslashes( $_POST['menu-item-off-canvas-control'][ $menu_item_db_id ] ) ); - } + $options['off-canvas-control'] = ''; - // If only one sidebar is available, allways select its control - /*if (count($available_controls) == 1) { - $options['off-canvas-control'] = $off_canvas_sidebars->get_sidebar_key_by_label( $available_controls[0] ); - }*/ - update_post_meta( $menu_item_db_id, '_off_canvas_control_menu_item', $options ); // allow us to easily identify our nav menu item + // If only one is available, always select it. + if ( ! empty( $_POST['menu-item-off-canvas-control'][ $menu_item_db_id ] ) && + array_key_exists( $_POST['menu-item-off-canvas-control'][ $menu_item_db_id ], $available_controls ) + ) { + $options['off-canvas-control'] = strip_tags( stripslashes( $_POST['menu-item-off-canvas-control'][ $menu_item_db_id ] ) ); } - } // End if(). + + // Allow us to easily identify our nav menu item. + update_post_meta( $menu_item_db_id, '_off_canvas_control_menu_item', $options ); + } } /* - * splits the one item of backend in several items on frontend - * take care to menu_order as it is used later in wp_nav_menu + * Splits the one item of backend in several items on frontend. + * Takes care to menu_order as it is used later in wp_nav_menu. * * @since 0.1 * @@ -225,32 +228,34 @@ public function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0 ) { public function wp_get_nav_menu_items( $items ) { if ( function_exists( 'doing_action' ) && doing_action( 'customize_register' ) || is_admin() ) { - // needed since WP 4.3, doing_action available since WP 3.9 + // Needed since WP 4.3, doing_action available since WP 3.9. return $items; } foreach ( $items as $key => $item ) { $options = get_post_meta( $item->ID, '_off_canvas_control_menu_item', true ); - if ( $options ) { - $item->url = ''; - if ( isset( $this->settings['sidebars'][ $options['off-canvas-control'] ] ) && $this->settings['sidebars'][ $options['off-canvas-control'] ]['enable'] ) { - //$item->title = $options['show_flags'] && $options['show_names'] ? $lang['flag'].' '.esc_html($lang['name']) : ($options['show_flags'] ? $lang['flag'] : esc_html($lang['name'])); - - $link_classes = $this->link_classes; - if ( ! is_array( $link_classes ) ) { - $link_classes = explode( ' ', $link_classes ); - } - - if ( ! empty( $options['off-canvas-control'] ) ) { - $link_classes[] = $this->settings['css_prefix'] . '-toggle-' . $options['off-canvas-control']; - } + if ( ! $options ) { + continue; + } + $item->url = ''; + if ( isset( $this->settings['sidebars'][ $options['off-canvas-control'] ] ) && + $this->settings['sidebars'][ $options['off-canvas-control'] ]['enable'] + ) { + + $link_classes = $this->link_classes; + if ( ! is_array( $link_classes ) ) { + $link_classes = explode( ' ', $link_classes ); + } - if ( ! is_array( $item->classes ) ) { - $item->classes = explode( ' ', $item->classes ); - } + if ( ! empty( $options['off-canvas-control'] ) ) { + $link_classes[] = $this->settings['css_prefix'] . '-toggle-' . $options['off-canvas-control']; + } - $item->classes = array_merge( $item->classes, $link_classes ); + if ( ! is_array( $item->classes ) ) { + $item->classes = explode( ' ', $item->classes ); } + + $item->classes = array_merge( $item->classes, $link_classes ); } } From 1d9497c2c7ba39989a2995fe745457084542c912 Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Tue, 29 Aug 2017 05:18:06 +0200 Subject: [PATCH 105/124] Use cssCompat() method --- js/fixed-scrolltop.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/js/fixed-scrolltop.js b/js/fixed-scrolltop.js index c4cfc46..2563c7c 100644 --- a/js/fixed-scrolltop.js +++ b/js/fixed-scrolltop.js @@ -51,12 +51,7 @@ } else if ( 'closing' === eventType ) { px -= offset; } - $(this).css( { - '-webkit-transform': 'translate( 0px, ' + px + 'px )', - '-moz-transform': 'translate( 0px, ' + px + 'px )', - '-o-transform': 'translate( 0px, ' + px + 'px )', - 'transform': 'translate( 0px, ' + px + 'px )' - } ); + ocsOffCanvasSidebars.cssCompat( $(this), 'transform', 'translate( 0px, ' + px + 'px )' ); } ); } }; From ade337914830e9c6e688bd2ef92e9b69c2b3152f Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Tue, 29 Aug 2017 05:28:50 +0200 Subject: [PATCH 106/124] Patch another link to GH --- includes/class-settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-settings.php b/includes/class-settings.php index 0c8d1fd..18bad06 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -194,7 +194,7 @@ private function register_general_settings() { 'name' => 'enable_frontend', 'label' => __( 'Let this plugin add the necessary elements on the front-end.', 'off-canvas-sidebars' ), // Translators: %s stands for a URL. - 'description' => sprintf( __( 'Read this to setup your theme for support! (Themes based on the Genesis Framework are supported by default)', 'off-canvas-sidebars' ), 'https://wordpress.org/plugins/off-canvas-sidebars/installation/' ), + 'description' => sprintf( __( 'Read this to setup your theme for support! (Themes based on the Genesis Framework are supported by default)', 'off-canvas-sidebars' ), 'https://github.com/JoryHogeveen/off-canvas-sidebars/wiki/theme-setup' ), ) ); /*add_settings_field( From 32b370b1eed6128fbfb9a34669c36e169900653b Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Tue, 29 Aug 2017 18:27:36 +0200 Subject: [PATCH 107/124] Enhance setting page layout --- css/off-canvas-sidebars-admin.css | 9 ++++++--- css/off-canvas-sidebars-admin.min.css | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/css/off-canvas-sidebars-admin.css b/css/off-canvas-sidebars-admin.css index 9276787..e3fd97b 100644 --- a/css/off-canvas-sidebars-admin.css +++ b/css/off-canvas-sidebars-admin.css @@ -28,10 +28,13 @@ } .postbox.section-sidebar:hover { opacity: 1 !important; } +.off-canvas-sidebars-settings .form-table tbody > tr:not(:last-child) { border-bottom: 1px solid #eee; } +.off-canvas-sidebars-settings .form-table:not(:last-child) { margin-bottom: 1em; border-bottom: 1px solid #eee; } + .off-canvas-sidebars-settings fieldset.radio label, .off-canvas-sidebars-settings fieldset.checkbox label { display: block } -.off-canvas-sidebars-settings fieldset.radio label + br {display: none;} -.off-canvas-sidebars-settings fieldset.radio label + .description {margin-bottom: .5em; display: inline-block;} +.off-canvas-sidebars-settings fieldset.radio label + br { display: none; } +.off-canvas-sidebars-settings fieldset.radio label + .description { margin-bottom: .5em; display: inline-block; } .off-canvas-sidebars-settings input + select { vertical-align: top; } @@ -58,7 +61,7 @@ margin-left: 0.5%; box-sizing: border-box; } - .off-canvas-sidebars-settings .postbox-container .postbox-third.first { margin-left: 0;} + .off-canvas-sidebars-settings .postbox-container .postbox-third.first { margin-left: 0; } } @media only screen and (min-width: 959px) { diff --git a/css/off-canvas-sidebars-admin.min.css b/css/off-canvas-sidebars-admin.min.css index b5ce97b..fbbc535 100644 --- a/css/off-canvas-sidebars-admin.min.css +++ b/css/off-canvas-sidebars-admin.min.css @@ -6,4 +6,4 @@ * @version 0.4 * @preserve */ -.ocs-credits{overflow:hidden;background:#fff;position:relative;margin:0;box-shadow:0 0 0 1px rgba(0,0,0,0.05)}.ocs-credits .inner{padding-left:10px;padding-right:10px}.ocs-credits h3{font-size:14px;line-height:1.4;margin:0;padding:8px 12px;border-bottom:1px solid #eee}.off-canvas-sidebars-settings .postbox-container{float:none}.postbox.section-sidebar{-webkit-transition:all .1s;-moz-transition:all .1s;-o-transition:all .1s;transition:all .1s}.postbox.section-sidebar:hover{opacity:1 !important}.off-canvas-sidebars-settings fieldset.radio label,.off-canvas-sidebars-settings fieldset.checkbox label{display:block}.off-canvas-sidebars-settings fieldset.radio label+br{display:none}.off-canvas-sidebars-settings fieldset.radio label+.description{margin-bottom:.5em;display:inline-block}.off-canvas-sidebars-settings input+select{vertical-align:top}@media only screen and (min-width:850px){.off-canvas-sidebars-settings{margin-right:300px}.off-canvas-sidebars-settings form{float:left;min-width:100%;width:auto}.ocs-credits{float:right;margin:10px -300px 10px 20px;width:280px}.off-canvas-sidebars-settings .postbox-container .postbox-third{float:left;width:33%;margin-left:.5%;box-sizing:border-box}.off-canvas-sidebars-settings .postbox-container .postbox-third.first{margin-left:0}}@media only screen and (min-width:959px){.ocs-credits{position:fixed;right:0;margin:10px 20px}} \ No newline at end of file +.ocs-credits{overflow:hidden;background:#fff;position:relative;margin:0;box-shadow:0 0 0 1px rgba(0,0,0,0.05)}.ocs-credits .inner{padding-left:10px;padding-right:10px}.ocs-credits h3{font-size:14px;line-height:1.4;margin:0;padding:8px 12px;border-bottom:1px solid #eee}.off-canvas-sidebars-settings .postbox-container{float:none}.postbox.section-sidebar{-webkit-transition:all .1s;-moz-transition:all .1s;-o-transition:all .1s;transition:all .1s}.postbox.section-sidebar:hover{opacity:1 !important}.off-canvas-sidebars-settings .form-table tbody>tr:not(:last-child){border-bottom:1px solid #eee}.off-canvas-sidebars-settings .form-table:not(:last-child){margin-bottom:1em;border-bottom:1px solid #eee}.off-canvas-sidebars-settings fieldset.radio label,.off-canvas-sidebars-settings fieldset.checkbox label{display:block}.off-canvas-sidebars-settings fieldset.radio label+br{display:none}.off-canvas-sidebars-settings fieldset.radio label+.description{margin-bottom:.5em;display:inline-block}.off-canvas-sidebars-settings input+select{vertical-align:top}@media only screen and (min-width:850px){.off-canvas-sidebars-settings{margin-right:300px}.off-canvas-sidebars-settings form{float:left;min-width:100%;width:auto}.ocs-credits{float:right;margin:10px -300px 10px 20px;width:280px}.off-canvas-sidebars-settings .postbox-container .postbox-third{float:left;width:33%;margin-left:.5%;box-sizing:border-box}.off-canvas-sidebars-settings .postbox-container .postbox-third.first{margin-left:0}}@media only screen and (min-width:959px){.ocs-credits{position:fixed;right:0;margin:10px 20px}} \ No newline at end of file From cb17f798614f4a25c0b062608897264b6c73aaaa Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Tue, 29 Aug 2017 18:28:25 +0200 Subject: [PATCH 108/124] Enhance nav menu script + jsDoc --- includes/class-menu-meta-box.php | 2 +- js/nav-menu.js | 60 ++++++++++---------------------- slidebars/slidebars.js | 12 +++++-- slidebars/slidebars.min.js | 12 +++++-- 4 files changed, 38 insertions(+), 48 deletions(-) diff --git a/includes/class-menu-meta-box.php b/includes/class-menu-meta-box.php index f242eba..5307812 100644 --- a/includes/class-menu-meta-box.php +++ b/includes/class-menu-meta-box.php @@ -154,7 +154,7 @@ public function admin_enqueue_scripts() { $data['val'][ $item ] = get_post_meta( $item, '_off_canvas_control_menu_item', true ); // send all these data to javascript - wp_localize_script( 'off_canvas_control_nav_menu', 'off_canvas_control_data', $data ); + wp_localize_script( 'off_canvas_control_nav_menu', 'ocsNavControl', $data ); } /* diff --git a/js/nav-menu.js b/js/nav-menu.js index 315a6b5..9f0afe7 100644 --- a/js/nav-menu.js +++ b/js/nav-menu.js @@ -5,12 +5,14 @@ * @author Jory Hogeveen * @package off-canvas-slidebars * @version 0.4 + * @global ocsNavControl + * @preserve * * Credits to the Polylang plugin for inspiration */ -if ( 'undefined' === typeof off_canvas_control_data ) { - var off_canvas_control_data = {}; +if ( 'undefined' === typeof ocsNavControl ) { + var ocsNavControl = {}; } jQuery( document ).ready( function( $ ) { @@ -22,41 +24,35 @@ jQuery( document ).ready( function( $ ) { $this.addClass('off-canvas-control'); /* If control selected, then show it */ - if ( off_canvas_control_data.val[ db_id ]['off-canvas-control']) { - var key = off_canvas_control_data.val[ db_id ]['off-canvas-control']; - control_type = ' (' + off_canvas_control_data.controls[ key ] + ')'; + if ( ocsNavControl.val[ db_id ]['off-canvas-control']) { + var key = ocsNavControl.val[ db_id ]['off-canvas-control']; + control_type = ' (' + ocsNavControl.controls[ key ] + ')'; } - $this.find('.menu-item-bar .item-type').html( off_canvas_control_data.strings.menu_item_type + control_type ); + $this.find('.menu-item-bar .item-type').html( ocsNavControl.strings.menu_item_type + control_type ); }); - /* change menu type label on selecting a controller */ + /* Change menu type label on selecting a controller */ $(document).on( 'change', '.field-off-canvas-control input', function() { var key = $(this).val(); - var control_type = ' (' + off_canvas_control_data.controls[ key ] + ')'; - $(this).parents('.menu-item').find('.menu-item-bar .item-type').html( off_canvas_control_data.strings.menu_item_type + control_type ); + var control_type = ' (' + ocsNavControl.controls[ key ] + ')'; + $(this).parents('.menu-item').find('.menu-item-bar .item-type').html( ocsNavControl.strings.menu_item_type + control_type ); } ); - /* init/change menu item options */ + /* Init/change menu item options */ $('#update-nav-menu').bind( 'click load', function(e) { if ( e.target && e.target.className && -1 < e.target.className.indexOf('item-edit')) { $('input[value="#off_canvas_control"][type=text]').parent().parent().parent().each( function() { var $this = $(this), item = $this.attr('id').substring(19), - strings = off_canvas_control_data.strings, - controls = off_canvas_control_data.controls, + strings = ocsNavControl.strings, + controls = ocsNavControl.controls, option; - $this.children('p.field-url, p.field-link-target, .field-xfn, .field-description').remove(); // remove default fields we don't need + // Remove default fields we don't need + $this.children('p.field-url, p.field-link-target, .field-xfn, .field-description').remove(); + // Change description width. $this.children('p.field-css-classes').removeClass('description-thin').addClass('description-wide'); - /*option = $('').attr({ - type: 'hidden', - id: 'edit-menu-item-title-'+item, - name: 'menu-item-title['+item+']', - value: off_canvas_control_data.title - }); - $this.append(option);*/ - option = $('').attr( { type: 'hidden', id: 'edit-menu-item-url-' + item, @@ -81,7 +77,7 @@ jQuery( document ).ready( function( $ ) { continue; } var checked = ''; - if (( 'undefined' !== typeof off_canvas_control_data.val[ item ] && key === off_canvas_control_data.val[ item ]['off-canvas-control'] ) ) { + if (( 'undefined' !== typeof ocsNavControl.val[ item ] && key === ocsNavControl.val[ item ]['off-canvas-control'] ) ) { checked = ' checked="checked"'; } o += ' '; @@ -95,25 +91,7 @@ jQuery( document ).ready( function( $ ) { if ( 1 === $field_control_options.length ) { $field_control_options.prop('checked', true); } - /* - ids = Array('menu_item_type'); // reverse order - // add the fields - for(var i = 0; i < ids.length; i++) { - p = $('

    ').attr('class', 'description'); - $(this).prepend(p); - label = $('

    ' ).html( content ); + + $( html ).find( '.mceItem.ocsTrigger' ).each( function () { + var attr = parseHTMLToData( this ); + var text = parseElementText( this ); + var nested = window.decodeURIComponent( $( this ).attr( 'data-ocs-nested' ) ); + + if ( 'true' === nested ) { + delete attr.text; + attr = attrObjectToHTML( attr ); + $( this ).replaceWith( '[' + shortcode + ' ' + attr + ']' + text + '[/' + shortcode + ']' ); + } else { + attr.text = text; + attr = attrObjectToHTML( attr ); + $( this ).replaceWith( '[' + shortcode + ' ' + attr + ']' ); + } + } ); + + content = $( html ).html(); + return content; + } + + /** + * + * @param cls + * @param data + * @param con + * @param nested + * @returns {string} + */ + function parseDataToHTML( cls, data, con, nested ) { + var attrData = { + //id: getAttr( data, 'id' ), + //action: getAttr( data, 'action' ), + element: getAttr( data, 'element' ), + class: getAttr( data, 'class' ), + attributes: getAttr( data, 'attr' ) + }; + + if ( ! nested ) { + con = getAttr( data, 'text' ); + } + + if ( ! attrData.attributes.length ) { + attrData.attributes = getAttr( data, 'attributes' ); + } + + if ( ! attrData.class.length ) { + attrData.class = getAttr( data, 'classes' ); + } + + if ( ! attrData.element.length ) { + attrData.element = 'button'; + } + + var attributes = attrStringToObject( attrData.attributes ); + + var classes = []; + classes.push( 'mceItem', cls ); + if ( 'string' === typeof attributes.class ) { + classes = classes.concat( attributes.class.split( ' ' ) ); + delete attributes.class; + } + if ( attrData.class.length ) { + classes = classes.concat( attrData.class.split( ' ' ) ); + } + + attrData.class = arrayFilterUnique( classes, true, true ).join( ' ' ); + attributes.class = arrayFilterUnique( classes, true, false ).join( ' ' ); + attributes = objectRemoveEmpty( attributes ); + + data = attrHTMLToObject( data ); + for ( var key in attrData ) { + data[ key ] = attrData[ key ]; + } + // Remove duplicates and empty values + data = objectRemoveEmpty( data ); + data = attrObjectToHTML( data ); + + data = window.encodeURIComponent( data ); + + var content = window.encodeURIComponent( con ); + // Some text is required for the editor to work properly + if ( ! content.length && 'img' !== attrData.element ) { + content = con = ' '; + } + + if ( 'img' === attrData.element ) { // && typeof elAttributes.alt != 'string' + attributes.alt = content; + } + + var elAttributes = attrObjectToHTML( attributes ); + + if ( $.inArray( attrData.element, singletons ) > -1 ) { + // singleton element + //nested = false; + + return '<' + attrData.element + ' ' + elAttributes + ' ' + 'data-ocs-nested="' + nested + '" ' + 'data-ocs-attr="' + data + '" data-ocs-text="' + content + '" />'; + } else { + return '<' + attrData.element + ' ' + elAttributes + ' ' + 'data-ocs-nested="' + nested + '" ' + 'data-ocs-attr="' + data + '" data-ocs-text="' + content + '">' + con + ''; + } + // data-mce-resize="false" data-mce-placeholder="1" + } + + /** + * + * @param el + * @returns {Object} + */ + function parseHTMLToData( el ) { + var attr = window.decodeURIComponent( $( el ).attr( 'data-ocs-attr' ) ); + + var attributes = attrHTMLToObject( attr ); + var elAttributes = attrElementToObject( el ); + + // Overwrites + if ( 'undefined' !== typeof attributes.attributes ) { + if ( 'string' !== typeof attributes.attr ) { + attributes.attr = attributes.attributes; + } + delete attributes.attributes; + } + if ( 'undefined' !== typeof attributes.classes ) { + if ( 'string' !== typeof attributes.class ) { + attributes.class = attributes.classes; + } + delete attributes.classes; + } + + // Converting + if ( 'string' === typeof attributes.attr ) { + attributes.attr = attrStringToObject( attributes.attr ); + } else { + attributes.attr = {}; + } + + for ( var key in elAttributes ) { + if ('class' === key && elAttributes.class.length ) { + // append + if ( 'string' === typeof attributes.class ) { + attributes.class += ' ' + elAttributes.class; + } else { + attributes.class = elAttributes.class; + } + } else if ( key.indexOf( 'data-' ) === -1 && 'string' === typeof elAttributes[ key ] ) { + // overwrite, check for alt tag for images + if ( 'alt' === key && $( el ).is( 'img' ) ) { + delete attributes.attr[ key ]; + } else { + attributes.attr[ key ] = '' + elAttributes[ key ]; + } + } + } + + if ( 'string' === typeof attributes.class && attributes.class.trim().length ) { + // Convert classes to an array + attributes.class = attributes.class.split( ' ' ); + // Remove MCE plugin defined classes + attributes.class = arrayFilterUnique( attributes.class, true, true ); + // Rejoin the classes + attributes.class = attributes.class.join( ' ' ); + } + + if ( 'object' === typeof attributes.attr ) { + attributes.attr = attrObjectToString( attributes.attr ); + } + + // Remove duplicate and empty attributes + attributes = objectRemoveEmpty( attributes ); + + return attributes; + } + + /** + * + * @param el + * @returns {string} + */ + function parseElementText( el ) { + var $el = $( el ), + text = window.decodeURIComponent( $el.attr( 'data-ocs-text' ) ); + if ( $el.html().length ) { + text = $el.html(); + } + + // Images have the alt tag for text + if ( $el.is('img') ) { + if ( $el.attr('alt') ) { + text = $el.attr('alt'); + } else { + text = ''; + } + } + return text; + } + + /** + * + * @param el + * @param editor + */ + function removeTriggerData( el, editor ) { + var $el = $( el ); + $el.removeClass( 'mceItem' ); + $el.removeClass( 'ocsTrigger' ); + $el.removeAttr( 'data-ocs-attr' ); + $el.removeAttr( 'data-ocs-text' ); + $el.removeAttr( 'data-ocs-nested' ); + //$el.removeAttr( 'data-mce-placeholder' ); + } + + /** + * @param s + * @param a + * @param f + * @returns {*} + */ + function getAttr( s, a, f ) { + var n = new RegExp( a + '=\"([^\"]+)\"', 'g' ).exec( s ); + if ( true === f && !n && -1 === s.indexOf( a + '="' ) ) { + // Attribute does not exist + return false; + } + return n ? window.decodeURIComponent( n[ 1 ] ).trim() : ''; + } + + /** + * Get attributes from a jQuery element + * If it contains multiple elements it only returns attributes from the first + * + * In: element + * Out: { key: value, key: value } + * + * @param el + * @returns Object + */ + function attrElementToObject( el ) { + var $el = $( el ), + atts = {}; + if ( $el.length ) { + $.each( $el[ 0 ].attributes, function ( index, attr ) { + atts[ attr.name ] = attr.value; + } ); + } + return atts; + } + + /** + * Convert HTML formatted attribute string to object + * In: key="value" key="value" + * Out: { key: value, key: value } + * + * @param attrString + * @returns Object + */ + function attrHTMLToObject( attrString ) { + var arr = attrString.trim().split( '" ' ), + atts = {}; + for ( var key in arr ) { + arr[ key ] = arr[ key ].split( '="' ); + if ( arr[ key ][ 0 ].trim().length ) { + atts[ arr[ key ][ 0 ].trim() ] = getAttr( attrString, arr[ key ][ 0 ] ); + } + } + return atts; + } + + /** + * Convert OCS formatted attribute string to object + * + * In: key:value;key:value + * Out: { key: value, key: value } + * + * @param attrString + * @returns Object + */ + function attrStringToObject( attrString ) { + var arr = attrString.split( ';' ), + atts = {}; + for ( var key in arr ) { + arr[ key ] = arr[ key ].split( ':' ); + if ( arr[ key ][ 0 ].trim().length ) { + var name = arr[ key ][ 0 ].trim(); + arr[ key ].splice( 0, 1 ); + atts[ name ] = arr[ key ].join( ':' ); + } + } + return atts; + } + + /** + * Convert object to OCS formatted attribute string + * + * In: { key: value, key: value } + * Out: key="value" key="value" + * + * @param attrObj + * @returns String + */ + function attrObjectToHTML( attrObj ) { + var atts = []; + for ( var name in attrObj ) { + atts.push( name + '="' + attrObj[ name ] + '"' ); + } + return atts.join( ' ' ); + } + + /** + * Convert object to HTML formatted attribute string + * + * In: { key: value, key: value } + * Out: key:value;key:value + * + * @param attrObj + * @returns String + */ + function attrObjectToString( attrObj ) { + var atts = []; + for ( var name in attrObj ) { + atts.push( name + ':' + attrObj[ name ] ); + } + return atts.join( ';' ); + } + + /** + * Return unique values only + * + * @param array Array + * @param empty bool Remove empty keys? + * @param ocs bool Check this plugin's defines classes + * @returns Array + */ + function arrayFilterUnique( array, empty, ocs ) { + if ( ! array.length ) { + return []; + } + return $.grep( array, function ( el, index ) { + if ( empty && !el.length ) { + return false; + } + if ( ocs && $.inArray( el, mceClasses ) > -1 ) { + return false; + } + return index === $.inArray( el, array ); + } ); + } + + /** + * Remove empty properties from object + * Only objects with strings as parameters allowed! + * + * @param obj Object + * @returns Object + */ + function objectRemoveEmpty( obj ) { + for ( var name in obj ) { + if ( 'string' === typeof obj[ name ] ) { + obj[ name ] = obj[ name ].trim(); + } + if ( obj[ name ] === null || obj[ name ] === undefined || ! obj[ name ].length ) { + delete obj[ name ]; + } + } + return obj; + } + + } ); + +//} )(); +} )( window.tinymce, jQuery ); diff --git a/off-canvas-sidebars.php b/off-canvas-sidebars.php index 53fbcb6..1dd08c1 100644 --- a/off-canvas-sidebars.php +++ b/off-canvas-sidebars.php @@ -150,7 +150,7 @@ final class OCS_Off_Canvas_Sidebars 'website_after_hook' => 'website_after', 'use_fastclick' => 0, 'compatibility_position_fixed' => 'none', - 'shortcode_rendering_wp_editor' => 0, + 'wp_editor_shortcode_rendering' => 0, 'css_prefix' => 'ocs', 'sidebars' => array(), ); @@ -249,6 +249,10 @@ function init() { include_once( OCS_PLUGIN_DIR . 'includes/class-settings.php' ); OCS_Off_Canvas_Sidebars_Settings::get_instance(); + // Load the WP Editor shortcode generator. + include_once( OCS_PLUGIN_DIR . 'includes/class-editor-shortcode-generator.php' ); + OCS_Off_Canvas_Sidebars_Editor_Shortcode_Generator::get_instance(); + // Add settings link to plugins page. add_filter( 'plugin_action_links', array( $this, 'add_settings_link' ), 10, 2 ); From c3c8c060c27ebf5eed067dfe777ad42135d9b444 Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Tue, 29 Aug 2017 18:29:29 +0200 Subject: [PATCH 110/124] Add minified files (still disabled) --- includes/class-frontend.php | 2 +- js/mce-plugin-shortcode.min.js | 12 ++++++++++++ js/nav-menu.min.js | 13 +++++++++++++ js/off-canvas-sidebars-settings.min.js | 10 ++++++++++ js/off-canvas-sidebars.min.js | 10 ++++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 js/mce-plugin-shortcode.min.js create mode 100644 js/nav-menu.min.js create mode 100644 js/off-canvas-sidebars-settings.min.js create mode 100644 js/off-canvas-sidebars.min.js diff --git a/includes/class-frontend.php b/includes/class-frontend.php index 3c074cf..0bd2a74 100644 --- a/includes/class-frontend.php +++ b/includes/class-frontend.php @@ -454,7 +454,7 @@ public function do_control_trigger( $sidebar_id, $args = array() ) { * @return void */ function add_styles_scripts() { - // @todo: create minified files + // @todo Validate and use minified files $suffix = '';//defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; $version = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? time() : OCS_PLUGIN_VERSION; diff --git a/js/mce-plugin-shortcode.min.js b/js/mce-plugin-shortcode.min.js new file mode 100644 index 0000000..7346fa1 --- /dev/null +++ b/js/mce-plugin-shortcode.min.js @@ -0,0 +1,12 @@ +;/** + * Off-Canvas Sidebars tinymce shortcode UI + * + * @author Jory Hogeveen + * @package off-canvas-slidebars + * @version 0.4 + * @global ocsMceSettings + * @preserve + * + * https://generatewp.com/take-shortcodes-ultimate-level/ + */ +(function(tinymce,$){tinymce.PluginManager.add("off_canvas_sidebars",function(editor,url){var toolbar;var toolbarImg;var toolbarLink;var toolbarElement;var shortcode="ocs_trigger";var mceClasses=["mceItem","ocsTrigger",ocsMceSettings.prefix+"-trigger"];var singletons=["br","hr","img","input"];$(document).ready(function(){if("undefined"!==typeof ocsMceSettings){$(".ocs-shortcode-generator").removeClass("hidden")}});$(document).on("click","#wp-"+editor.id+"-wrap .wp-media-buttons button.ocs-shortcode-generator",function(){var selection=editor.selection.getContent(),$selection=$(selection),data={};if(selection.length){if($selection.is("img")){data.text=$selection.attr("alt");data.element="img";data.class=$selection.attr("class");var attr=[];if($selection.attr("src")){attr.push("src:"+$selection.attr("src"))}if($selection.attr("width")){attr.push("width:"+$selection.attr("width"))}if($selection.attr("height")){attr.push("height:"+$selection.attr("height"))}if($selection.attr("title")){attr.push("title:"+$selection.attr("title"))}data.attr=attr.join(";")}else{data.text=selection;data.element="span"}}editor.execCommand("ocs_trigger_popup","",data);return false});editor.addCommand("ocs_trigger_popup",function(ui,v){var fields=[];var defaults=$.extend(true,{},ocsMceSettings.fields);for(var field in defaults){if(!defaults.hasOwnProperty(field)){continue}var fieldData=defaults[field];if(v[field]){if("checkbox"===fieldData.type){fieldData.checked=v[field]}else{fieldData.value=v[field]}}if("text"===fieldData.name&&"img"===v.element){fieldData.label="Alt";fieldData.tooltip="";fieldData.multiline=false}fields.push(fieldData)}var popup=editor.windowManager.open({title:ocsMceSettings.title,body:fields,onsubmit:function(e){var shortcode_str="["+shortcode;for(var field in ocsMceSettings.fields){if(!ocsMceSettings.fields.hasOwnProperty(field)){continue}if("container"===ocsMceSettings.fields[field].type){continue}if("undefined"!==typeof e.data[field]){if(-1>=$.inArray(field,["text","nested"])){if("checkbox"===ocsMceSettings.fields[field].type&&e.data[field]){shortcode_str+=" "+field+'="1"'}else if(e.data[field].length){shortcode_str+=" "+field+'="'+e.data[field].replace(/(\r\n|\n|\r)/gm,"")+'"'}}}}if(e.data.text.length&&e.data.text.indexOf('"')!==-1){e.data.nested=true}if("undefined"!==typeof e.data.nested&&e.data.nested){shortcode_str+="]"+e.data.text+"[/"+shortcode+"]"}else{if(e.data.text.length){shortcode_str+=' text="'+e.data.text+'"'}shortcode_str+="]"}editor.insertContent(shortcode_str)}})});editor.addButton("ocs_trigger_popup",{tooltip:"Edit Off-Canvas trigger",icon:"dashicon dashicons-admin-links",label:"Edit Off-Canvas trigger",title:"Off-Canvas trigger",onclick:function(){doTriggerPopup(toolbarElement,editor)}});editor.addButton("ocs_trigger_unlink",{tooltip:"Remove Off-Canvas trigger",icon:"dashicon dashicons-editor-unlink",label:"Remove Off-Canvas trigger",onclick:function(){removeTriggerData(toolbarElement,editor);toolbarElement=null;tinymce.toolbar=null}});editor.addButton("ocs_trigger_remove",{tooltip:"Remove",icon:"dashicon dashicons-no",label:"Remove",onclick:function(){$(toolbarElement).remove();toolbarElement=null;editor.execCommand("unlink")}});editor.on("preinit",function(){if(editor.wp&&editor.wp._createToolbar){toolbar=editor.wp._createToolbar(["ocs_trigger_popup","ocs_trigger_unlink","ocs_trigger_remove"],true);toolbarImg=editor.wp._createToolbar(["wp_img_alignleft","wp_img_aligncenter","wp_img_alignright","wp_img_alignnone","ocs_trigger_popup","ocs_trigger_unlink","wp_img_edit","wp_img_remove"],true);toolbarLink=editor.wp._createToolbar(["wp_link_preview","ocs_trigger_popup","ocs_trigger_unlink","wp_link_edit","wp_link_remove"],true)}});editor.on("wptoolbar",function(e){if(e.element.className.indexOf("ocsTrigger")>-1){toolbarElement=e.element;if($(e.element).is("img")){e.toolbar=toolbarImg}else if($(e.element).is("a")){e.toolbar=toolbarLink}else{e.toolbar=toolbar}}});editor.on("NodeChange",function(e){if(e.element.className.indexOf("ocsTrigger")>-1){$(e.target.container).closest(".wp-editor-wrap").find("button.ocs-shortcode-generator").attr("disabled",true)}else{$(e.target.container).closest(".wp-editor-wrap").find("button.ocs-shortcode-generator").attr("disabled",false)}});editor.on("Blur",function(e){$(e.target.container).closest(".wp-editor-wrap").find("button.ocs-shortcode-generator").attr("disabled",false)});editor.on("BeforeSetcontent",function(e){if(ocsMceSettings.render){e.content=replaceShortcodes(e.content)}});editor.on("GetContent",function(e){e.content=restoreShortcodes(e.content)});editor.on("DblClick",function(e){if(e.target.className.indexOf("ocsTrigger")>-1){doTriggerPopup(e.target,this)}});function doTriggerPopup(el,curEditor){curEditor.selection.select(el);var $el=$(el),attr=parseHTMLToData(el),data={};for(var field in ocsMceSettings.fields){if(!ocsMceSettings.fields.hasOwnProperty(field)){continue}if("container"===ocsMceSettings.fields[field].type){continue}if("checkbox"===ocsMceSettings.fields[field].type){data[field]="1"===attr[field]}else{data[field]=attr[field]}}data=objectRemoveEmpty(data);data.nested="true"===$el.attr("data-ocs-nested");data.text=parseElementText(el);curEditor.execCommand("ocs_trigger_popup","",data)}function replaceShortcodes(content){content=content.replace(/\[ocs_trigger([^\]]*)\]([^\]]*)\[\/ocs_trigger\]/g,function(all,attr,con){return parseDataToHTML("ocsTrigger",attr,con,true)});content=content.replace(/\[ocs_trigger([^\]]*)\]/g,function(all,attr){return parseDataToHTML("ocsTrigger",attr,"",false)});return content}function restoreShortcodes(content){var html=$("
    ").html(content);$(html).find(".mceItem.ocsTrigger").each(function(){var attr=parseHTMLToData(this);var text=parseElementText(this);var nested=window.decodeURIComponent($(this).attr("data-ocs-nested"));if("true"===nested){delete attr.text;attr=attrObjectToHTML(attr);$(this).replaceWith("["+shortcode+" "+attr+"]"+text+"[/"+shortcode+"]")}else{attr.text=text;attr=attrObjectToHTML(attr);$(this).replaceWith("["+shortcode+" "+attr+"]")}});content=$(html).html();return content}function parseDataToHTML(cls,data,con,nested){var attrData={element:getAttr(data,"element"),"class":getAttr(data,"class"),attributes:getAttr(data,"attr")};if(!nested){con=getAttr(data,"text")}if(!attrData.attributes.length){attrData.attributes=getAttr(data,"attributes")}if(!attrData.class.length){attrData.class=getAttr(data,"classes")}if(!attrData.element.length){attrData.element="button"}var attributes=attrStringToObject(attrData.attributes);var classes=[];classes.push("mceItem",cls);if("string"===typeof attributes.class){classes=classes.concat(attributes.class.split(" "));delete attributes.class}if(attrData.class.length){classes=classes.concat(attrData.class.split(" "))}attrData.class=arrayFilterUnique(classes,true,true).join(" ");attributes.class=arrayFilterUnique(classes,true,false).join(" ");attributes=objectRemoveEmpty(attributes);data=attrHTMLToObject(data);for(var key in attrData){data[key]=attrData[key]}data=objectRemoveEmpty(data);data=attrObjectToHTML(data);data=window.encodeURIComponent(data);var content=window.encodeURIComponent(con);if(!content.length&&"img"!==attrData.element){content=con=" "}if("img"===attrData.element){attributes.alt=content}var elAttributes=attrObjectToHTML(attributes);if($.inArray(attrData.element,singletons)>-1){return"<"+attrData.element+" "+elAttributes+" "+'data-ocs-nested="'+nested+'" '+'data-ocs-attr="'+data+'" data-ocs-text="'+content+'" />'}else{return"<"+attrData.element+" "+elAttributes+" "+'data-ocs-nested="'+nested+'" '+'data-ocs-attr="'+data+'" data-ocs-text="'+content+'">'+con+""}}function parseHTMLToData(el){var attr=window.decodeURIComponent($(el).attr("data-ocs-attr"));var attributes=attrHTMLToObject(attr);var elAttributes=attrElementToObject(el);if("undefined"!==typeof attributes.attributes){if("string"!==typeof attributes.attr){attributes.attr=attributes.attributes}delete attributes.attributes}if("undefined"!==typeof attributes.classes){if("string"!==typeof attributes.class){attributes.class=attributes.classes}delete attributes.classes}if("string"===typeof attributes.attr){attributes.attr=attrStringToObject(attributes.attr)}else{attributes.attr={}}for(var key in elAttributes){if("class"===key&&elAttributes.class.length){if("string"===typeof attributes.class){attributes.class+=" "+elAttributes.class}else{attributes.class=elAttributes.class}}else if(key.indexOf("data-")===-1&&"string"===typeof elAttributes[key]){if("alt"===key&&$(el).is("img")){delete attributes.attr[key]}else{attributes.attr[key]=""+elAttributes[key]}}}if("string"===typeof attributes.class&&attributes.class.trim().length){attributes.class=attributes.class.split(" ");attributes.class=arrayFilterUnique(attributes.class,true,true);attributes.class=attributes.class.join(" ")}if("object"===typeof attributes.attr){attributes.attr=attrObjectToString(attributes.attr)}attributes=objectRemoveEmpty(attributes);return attributes}function parseElementText(el){var $el=$(el),text=window.decodeURIComponent($el.attr("data-ocs-text"));if($el.html().length){text=$el.html()}if($el.is("img")){if($el.attr("alt")){text=$el.attr("alt")}else{text=""}}return text}function removeTriggerData(el,editor){var $el=$(el);$el.removeClass("mceItem");$el.removeClass("ocsTrigger");$el.removeAttr("data-ocs-attr");$el.removeAttr("data-ocs-text");$el.removeAttr("data-ocs-nested")}function getAttr(s,a,f){var n=new RegExp(a+'="([^"]+)"',"g").exec(s);if(true===f&&!n&&-1===s.indexOf(a+'="')){return false}return n?window.decodeURIComponent(n[1]).trim():""}function attrElementToObject(el){var $el=$(el),atts={};if($el.length){$.each($el[0].attributes,function(index,attr){atts[attr.name]=attr.value})}return atts}function attrHTMLToObject(attrString){var arr=attrString.trim().split('" '),atts={};for(var key in arr){arr[key]=arr[key].split('="');if(arr[key][0].trim().length){atts[arr[key][0].trim()]=getAttr(attrString,arr[key][0])}}return atts}function attrStringToObject(attrString){var arr=attrString.split(";"),atts={};for(var key in arr){arr[key]=arr[key].split(":");if(arr[key][0].trim().length){var name=arr[key][0].trim();arr[key].splice(0,1);atts[name]=arr[key].join(":")}}return atts}function attrObjectToHTML(attrObj){var atts=[];for(var name in attrObj){atts.push(name+'="'+attrObj[name]+'"')}return atts.join(" ")}function attrObjectToString(attrObj){var atts=[];for(var name in attrObj){atts.push(name+":"+attrObj[name])}return atts.join(";")}function arrayFilterUnique(array,empty,ocs){if(!array.length){return[]}return $.grep(array,function(el,index){if(empty&&!el.length){return false}if(ocs&&$.inArray(el,mceClasses)>-1){return false}return index===$.inArray(el,array)})}function objectRemoveEmpty(obj){for(var name in obj){if("string"===typeof obj[name]){obj[name]=obj[name].trim()}if(obj[name]===null||obj[name]===undefined||!obj[name].length){delete obj[name]}}return obj}})})(window.tinymce,jQuery); \ No newline at end of file diff --git a/js/nav-menu.min.js b/js/nav-menu.min.js new file mode 100644 index 0000000..9072fdd --- /dev/null +++ b/js/nav-menu.min.js @@ -0,0 +1,13 @@ +;/** + * Off-Canvas Sidebars menu meta box scripts + * + * Menu Meta Box scripts + * @author Jory Hogeveen + * @package off-canvas-slidebars + * @version 0.4 + * @global ocsNavControl + * @preserve + * + * Credits to the Polylang plugin for inspiration + */ +if("undefined"===typeof ocsNavControl){var ocsNavControl={}}jQuery(document).ready(function($){$("input[value='#off_canvas_control'][type=text]").parent().parent().parent().parent().each(function(){var $this=$(this),control_type="",db_id=$this.find(".menu-item-data-db-id").val();$this.addClass("off-canvas-control");if(ocsNavControl.val[db_id]["off-canvas-control"]){var key=ocsNavControl.val[db_id]["off-canvas-control"];control_type=' ('+ocsNavControl.controls[key]+")"}$this.find(".menu-item-bar .item-type").html(ocsNavControl.strings.menu_item_type+control_type)});$(document).on("change",".field-off-canvas-control input",function(){var key=$(this).val();var control_type=' ('+ocsNavControl.controls[key]+")";$(this).parents(".menu-item").find(".menu-item-bar .item-type").html(ocsNavControl.strings.menu_item_type+control_type)});$("#update-nav-menu").bind("click load",function(e){if(e.target&&e.target.className&&-1").attr({type:"hidden",id:"edit-menu-item-url-"+item,name:"menu-item-url["+item+"]",value:"#off_canvas_control"});$this.append(option);option=$("").attr({type:"hidden",id:"edit-menu-item-off-canvas-control-detect-"+item,name:"menu-item-off-canvas-control-detect["+item+"]",value:1});$this.append(option);var o="";o+='

    '+strings.menu_item_type+"
    ";for(var key in controls){if(!controls.hasOwnProperty(key)){continue}var checked="";if("undefined"!==typeof ocsNavControl.val[item]&&key===ocsNavControl.val[item]["off-canvas-control"]){checked=' checked="checked"'}o+=' ";o+='
    "}o+="

    ";$this.prepend(o);var $field_control_options=$this.children("p.field-off-canvas-control").find('input[type="radio"]');if(1===$field_control_options.length){$field_control_options.prop("checked",true)}})}})}); \ No newline at end of file diff --git a/js/off-canvas-sidebars-settings.min.js b/js/off-canvas-sidebars-settings.min.js new file mode 100644 index 0000000..3a6d279 --- /dev/null +++ b/js/off-canvas-sidebars-settings.min.js @@ -0,0 +1,10 @@ +;/** + * Off-Canvas Sidebars plugin settings + * + * @author Jory Hogeveen + * @package off-canvas-sidebars + * @version 0.4 + * @global ocsOffCanvasSidebarsSettings + * @preserve + */ +if("undefined"===typeof ocsOffCanvasSidebarsSettings){var ocsOffCanvasSidebarsSettings={general_key:"off_canvas_sidebars_options",plugin_key:"off-canvas-sidebars-settings",css_prefix:"ocs",__required_fields_not_set:"Some required fields are not set!"}}(function($){var $document=$(document);ocsOffCanvasSidebarsSettings.init=function(){var tab=$("#ocs_tab");var postbox=$(".postbox");$(".if-js-closed").removeClass("if-js-closed").addClass("closed");postboxes.add_postbox_toggles(ocsOffCanvasSidebarsSettings.plugin_key);if("ocs-sidebars"===tab.val()){postbox.each(function(){var prefix="off_canvas_sidebars_options_sidebars_",sidebar_id=$(this).attr("id").replace("section_sidebar_",""),sidebar_prefix=prefix+sidebar_id;ocs_show_hide_options_radio("."+sidebar_prefix+"_background_color_type","."+sidebar_prefix+"_background_color_wrapper","color",false);ocs_show_hide_options_radio("."+sidebar_prefix+"_location","#"+sidebar_prefix+"_style_reveal, #"+sidebar_prefix+"_style_shift",["left","right"],"label");ocs_show_hide_options("."+sidebar_prefix+"_overwrite_global_settings","."+sidebar_prefix+"_site_close","tr");ocs_show_hide_options("."+sidebar_prefix+"_overwrite_global_settings","."+sidebar_prefix+"_disable_over","tr");ocs_show_hide_options("."+sidebar_prefix+"_overwrite_global_settings","."+sidebar_prefix+"_hide_control_classes","tr");ocs_show_hide_options("."+sidebar_prefix+"_overwrite_global_settings","."+sidebar_prefix+"_scroll_lock","tr")})}else{ocs_show_hide_options_radio(".off_canvas_sidebars_options_background_color_type",".off_canvas_sidebars_options_background_color_wrapper","color",false)}function ocs_show_hide_options(trigger,target,parent){if(parent){target=$(target).closest(parent)}if(!$(trigger).is(":checked")){$(target).slideUp("fast")}$(trigger).change(function(){if($(this).is(":checked")){$(target).slideDown("fast")}else{$(target).slideUp("fast")}})}function ocs_show_hide_options_radio(trigger,target,compare,parent){if(!$.isArray(compare)){compare=[compare]}if(parent){parent+=", "+parent+" + br";target=$(target).closest(parent)}$(trigger).change(function(){if(0<=$.inArray($(trigger+":checked").val(),compare)){$(target).slideDown("fast")}else{$(target).slideUp("fast")}}).trigger("change")}$("input.color-picker").wpColorPicker();$("input.required").each(function(){var $this=$(this);$this.on("change",function(){if(!$this.val()){$this.parents("tr").addClass("form-invalid")}else{$this.parents("tr").removeClass("form-invalid")}})});$("#"+ocsOffCanvasSidebarsSettings.general_key).submit(function(e){var valid=true;$("input.required",this).each(function(){if(!$(this).val()){$(this).trigger("change");valid=false}});if(!valid){e.preventDefault();alert(ocsOffCanvasSidebarsSettings.__required_fields_not_set)}});if("ocs-sidebars"===tab.val()){if($(".js-dynamic-id").length){postbox.each(function(){var sidebar=this;$(".js-dynamic-id",sidebar).text($("input.off_canvas_sidebars_options_sidebars_id",sidebar).val());$(".sidebar_classes").show();$("input.off_canvas_sidebars_options_sidebars_id",this).on("keyup",function(){$(".js-dynamic-id",sidebar).text($(this).val())})})}postbox.each(function(){var sidebar=this,$sidebar=$(sidebar);$sidebar.css({"border-left":"5px solid #eee"});if(!$("input.off_canvas_sidebars_options_sidebars_enable",sidebar).is(":checked")){if($sidebar.hasClass("closed")){$sidebar.css("opacity","0.75")}$sidebar.css("border-left-color","#ffb900")}else{$sidebar.css("border-left-color","#46b450")}$("input.off_canvas_sidebars_options_sidebars_enable",sidebar).on("change",function(){if(!$(this).is(":checked")){$sidebar.css("border-left-color","#ffb900");if($sidebar.hasClass("closed")){$sidebar.css("opacity","0.75")}else{$sidebar.css("opacity","")}}else{$sidebar.css("border-left-color","#46b450");$sidebar.css("opacity","")}});$sidebar.on("click",function(){if(!$("input.off_canvas_sidebars_options_sidebars_enable",sidebar).is(":checked")&&$sidebar.hasClass("closed")){$sidebar.css("opacity","0.75")}else{$sidebar.css("opacity","")}})});$document.on("change",".off_canvas_sidebars_options_sidebars_delete",function(){var $this=$(this),sidebar=$this.parents(".postbox"),$sidebar=$(sidebar);if($this.is(":checked")){var parent_row=$this.parents("tr");$("tr",sidebar).hide("fast",function(){$("tr",sidebar).each(function(){if($(this).is(parent_row)){$(this).show("fast")}})});$sidebar.css("opacity","0.5");$sidebar.css("border-left-color","#dc3232")}else{$sidebar.css("opacity","");$("tr",sidebar).show("fast");$("input.off_canvas_sidebars_options_sidebars_enable",sidebar).trigger("change")}})}if("ocs-shortcode"===tab.val()){var fields=["sidebar","text","action","element","class","attr","nested"];for(var i=0,l=fields.length;i"}else{html="<"+element+" "+attrObjectToHTML(attributes)+">"+field_data.text.val()+""}$("#ocs_shortcode_preview").html(html);$("#ocs_shortcode_html").val(html)}function attrHTMLToObject(attrString){var arr=attrString.trim().split('" '),atts={};for(var key in arr){if(arr.hasOwnProperty(key)){arr[key]=arr[key].split('="');if(arr[key][0].trim().length){atts[arr[key][0].trim()]=getAttr(attrString,arr[key][0],false)}}}return atts}function attrStringToObject(attrString){var arr=attrString.split(";"),atts={};for(var key in arr){if(arr.hasOwnProperty(key)){arr[key]=arr[key].split(":");if(arr[key][0].trim().length){var name=arr[key][0].trim();arr[key].splice(0,1);atts[name]=arr[key].join(":")}}}return atts}function attrObjectToHTML(attrObj){var atts=[];for(var name in attrObj){if(attrObj.hasOwnProperty(name)){atts.push(name+'="'+attrObj[name]+'"')}}return atts.join(" ")}function attrObjectToString(attrObj){var atts=[];for(var name in attrObj){if(attrObj.hasOwnProperty(name)){atts.push(name+":"+attrObj[name])}}return atts.join(";")}function getAttr(s,a,f){var n=new RegExp(a+'="([^"]+)"',"g").exec(s);if(true===f&&!n&&-1===s.indexOf(a+'="')){return false}return n?window.decodeURIComponent(n[1]).trim():""}};ocsOffCanvasSidebarsSettings.init()})(jQuery); \ No newline at end of file diff --git a/js/off-canvas-sidebars.min.js b/js/off-canvas-sidebars.min.js new file mode 100644 index 0000000..ff4ff9a --- /dev/null +++ b/js/off-canvas-sidebars.min.js @@ -0,0 +1,10 @@ +;/** + * Off-Canvas Sidebars plugin + * + * @author Jory Hogeveen + * @package off-canvas-sidebars + * @version 0.4 + * @global ocsOffCanvasSidebars + * @preserve + */ +if("undefined"===typeof ocsOffCanvasSidebars){var ocsOffCanvasSidebars={site_close:true,disable_over:false,hide_control_classes:false,scroll_lock:false,legacy_css:false,fixed_elements:"",css_prefix:"ocs",sidebars:{},_debug:false}}(function($){var $document=$(document);var $window=$(window);var $body=$("body");ocsOffCanvasSidebars.slidebarsController=false;ocsOffCanvasSidebars.useAttributeSettings=false;ocsOffCanvasSidebars.container=false;ocsOffCanvasSidebars._html=$("html");ocsOffCanvasSidebars._touchmove=false;ocsOffCanvasSidebars._toolbar=$body.hasClass("admin-bar");ocsOffCanvasSidebars.init=function(){if(ocsOffCanvasSidebars.fixed_elements){$(ocsOffCanvasSidebars.fixed_elements).each(function(){var $this=$(this);if(!$this.parents("[canvas]")){$this.attr("canvas",1)}else{$this.attr("canvas-inner",1)}})}ocsOffCanvasSidebars._checkDisableOver=function(sidebarId){var check=true;var disableOver=parseInt(ocsOffCanvasSidebars._getSetting("disable_over",sidebarId));if(disableOver&&!isNaN(disableOver)){if($window.width()>disableOver){check=false}}return check};ocsOffCanvasSidebars._getSetting=function(key,sidebarId){var overwrite,setting;var prefix=ocsOffCanvasSidebars.css_prefix;if("undefined"!==typeof sidebarId){if(!sidebarId&&null!==sidebarId){sidebarId=ocsOffCanvasSidebars.slidebarsController.getActiveSlidebar()}}if(sidebarId){if(!$.isEmptyObject(ocsOffCanvasSidebars.sidebars)&&!ocsOffCanvasSidebars.useAttributeSettings){sidebarId=sidebarId.replace(prefix+"-","");if(ocsOffCanvasSidebars.sidebars[sidebarId].overwrite_global_settings){setting=ocsOffCanvasSidebars.sidebars[sidebarId][key];if(setting){return setting}else{return false}}}else{var sidebarElement=$("#"+sidebarId);overwrite=sidebarElement.attr("ocs-overwrite_global_settings");if(overwrite){setting=sidebarElement.attr("ocs-"+key);if("undefined"!==typeof setting){return setting}else{return false}}}}if(ocsOffCanvasSidebars.hasOwnProperty(key)&&!ocsOffCanvasSidebars.useAttributeSettings){return ocsOffCanvasSidebars[key]}else{setting=$("#"+prefix+"-site").attr("ocs-"+key);if("undefined"!==typeof setting){return setting}}return false};ocsOffCanvasSidebars._getTranslateAxis=function(obj,axis){obj=$(obj);var transformMatrix=obj.css("-webkit-transform")||obj.css("-moz-transform")||obj.css("-ms-transform")||obj.css("-o-transform")||obj.css("transform");if(transformMatrix){var matrix=transformMatrix.replace(/[^0-9\-.,]/g,"").split(",");var val=false;switch(axis){case"x":val=matrix[12]||matrix[4];break;case"y":val=matrix[13]||matrix[5];break;case"z":val=matrix[14]||matrix[6];break}return parseFloat(val)}else{return 0}};ocsOffCanvasSidebars.container=$("[canvas=container]");$window.trigger("ocs_loaded",this);ocsOffCanvasSidebars.slidebarsController=new slidebars;if(false===ocsOffCanvasSidebars.slidebarsController){return}if(ocsOffCanvasSidebars.legacy_css){ocsOffCanvasSidebars.slidebarsController.legacy=true;ocsOffCanvasSidebars._html.addClass("ocs-legacy")}ocsOffCanvasSidebars.slidebarsController.init();ocsOffCanvasSidebars._html.addClass("ocs-initialized");$window.trigger("ocs_initialized",this);if(ocsOffCanvasSidebars._toolbar){$window.on("load resize",function(){var bodyOffset=$body.offset();$("."+ocsOffCanvasSidebars.css_prefix+"-slidebar").each(function(){if($(this).hasClass("ocs-location-top")){$(this).css("margin-top",parseInt($(this).css("margin-top").replace("px",""))+bodyOffset.top+"px")}else if($(this).hasClass("ocs-location-left")||$(this).hasClass("ocs-location-right")){$(this).css("margin-top",bodyOffset.top+"px")}})})}$(ocsOffCanvasSidebars.slidebarsController.events).on("opening opened closing closed",function(e,sidebar_id){var slidebar=ocsOffCanvasSidebars.slidebarsController.getSlidebar(sidebar_id);var duration=parseFloat(slidebar.element.css("transitionDuration"))*1e3;if("top"===slidebar.side||"bottom"===slidebar.side){var elements=ocsOffCanvasSidebars.getFixedElements();elements.attr({"canvas-fixed":"fixed"});if(ocsOffCanvasSidebars.legacy_css&&"top"===slidebar.side&&("overlay"!==slidebar.style&&"reveal"!==slidebar.style)){var offset;offset=parseInt(slidebar.element.css("margin-top").replace("px","").replace("-",""));if(ocsOffCanvasSidebars._toolbar){var bodyOffset=$body.offset();offset+=bodyOffset.top}elements.each(function(){var $this=$(this);if("opening"===e.type){ocsOffCanvasSidebars.cssCompat($this,"transition","top "+duration+"ms");$this.css("top",parseInt($this.css("top").replace("px",""))+offset+"px")}else if("closing"===e.type){$this.css("top",parseInt($this.css("top").replace("px",""))-offset+"px");setTimeout(function(){ocsOffCanvasSidebars.cssCompat($this,"transition","")},duration)}})}else{elements.each(function(){var $this=$(this);if("opening"===e.type||"closing"===e.type){ocsOffCanvasSidebars.cssCompat($this,"transition","transform "+duration+"ms")}else if("opened"===e.type||"closed"===e.type){ocsOffCanvasSidebars.cssCompat($this,"transition","")}})}$window.trigger("slidebar_event",[e.type,slidebar])}});$document.on("touchmove",function(){ocsOffCanvasSidebars._touchmove=true});$document.on("touchstart",function(){ocsOffCanvasSidebars._touchmove=false});if("function"===typeof ocsOffCanvasSidebars.setupTriggers){ocsOffCanvasSidebars.setupTriggers()}};ocsOffCanvasSidebars.setSidebarDefaultSettings=function(sidebarId){if("undefined"===typeof ocsOffCanvasSidebars.sidebars[sidebarId]){ocsOffCanvasSidebars.sidebars[sidebarId]={overwrite_global_settings:false,site_close:ocsOffCanvasSidebars.site_close,disable_over:ocsOffCanvasSidebars.disable_over,hide_control_classes:ocsOffCanvasSidebars.hide_control_classes,scroll_lock:ocsOffCanvasSidebars.scroll_lock}}};ocsOffCanvasSidebars.setupTriggers=function(){var controller=ocsOffCanvasSidebars.slidebarsController,prefix=ocsOffCanvasSidebars.css_prefix,sidebarElements=$("."+prefix+"-slidebar");sidebarElements.each(function(){var id=$(this).attr("ocs-sidebar-id");ocsOffCanvasSidebars.setSidebarDefaultSettings(id);$document.on("touchend click","."+prefix+"-toggle-"+id,function(e){e.stopPropagation();e.preventDefault();if(true===ocsOffCanvasSidebars._touchmove){return}if(ocsOffCanvasSidebars._checkDisableOver(prefix+"-"+id)){controller.toggle(prefix+"-"+id)}});$document.on("touchend click","."+prefix+"-open-"+id,function(e){e.stopPropagation();e.preventDefault();if(true===ocsOffCanvasSidebars._touchmove){return}if(ocsOffCanvasSidebars._checkDisableOver(prefix+"-"+id)){controller.open(prefix+"-"+id)}});$document.on("touchend click","."+prefix+"-close-"+id,function(e){e.stopPropagation();e.preventDefault();if(true===ocsOffCanvasSidebars._touchmove){return}controller.close(prefix+"-"+id)})});$document.on("touchend click","."+prefix+"-close-any",function(e){if(ocsOffCanvasSidebars._getSetting("site_close",false)){e.preventDefault();e.stopPropagation();controller.close()}});$("a").not("."+prefix+"-trigger").on("touchend click",function(){if(!$(this).parents("."+prefix+"-trigger").length){controller.close()}});$(controller.events).on("opening",function(){$("[canvas]").addClass(prefix+"-close-any");ocsOffCanvasSidebars._html.addClass("ocs-sidebar-active");if(ocsOffCanvasSidebars._getSetting("scroll_lock",false)){ocsOffCanvasSidebars._html.addClass("ocs-scroll-lock")}});$(controller.events).on("closing",function(){$("[canvas]").removeClass(prefix+"-close-any");ocsOffCanvasSidebars._html.removeClass("ocs-sidebar-active ocs-scroll-lock")});var disableOver=function(){var prefix=ocsOffCanvasSidebars.css_prefix;sidebarElements.each(function(){var id=$(this).attr("ocs-sidebar-id");if(!ocsOffCanvasSidebars._checkDisableOver(prefix+"-"+id)){if(controller.isActiveSlidebar(prefix+"-"+id)){controller.close()}if(ocsOffCanvasSidebars._getSetting("hide_control_classes",prefix+"-"+id)){$("."+prefix+"-toggle-"+id).hide()}}else{$("."+prefix+"-toggle-"+id).show()}})};disableOver();$window.on("resize",disableOver);$("#"+prefix+"-site").on("scroll touchmove mousewheel DOMMouseScroll",function(e){if(ocsOffCanvasSidebars._html.hasClass("ocs-scroll-lock")){e.preventDefault();e.stopPropagation();return false}});sidebarElements.on("scroll touchmove mousewheel DOMMouseScroll",function(e){if(ocsOffCanvasSidebars._html.hasClass("ocs-scroll-lock")){var $this=$(this);if(0>e.originalEvent.deltaY){return 0<$this.scrollTop()}else{return $this.scrollTop()+$this.innerHeight()<$this[0].scrollHeight}}})};ocsOffCanvasSidebars.getFixedElements=function(){return $("#"+ocsOffCanvasSidebars.css_prefix+"-site *").filter(function(){return"fixed"===$(this).css("position")})};ocsOffCanvasSidebars.cssCompat=function(elem,prop,value){var data={};data["-webkit-"+prop]=value;data["-moz-"+prop]=value;data["-o-"+prop]=value;data[prop]=value;$(elem).css(data)};if($("#"+ocsOffCanvasSidebars.css_prefix+"-site").length&&"undefined"!==typeof slidebars){ocsOffCanvasSidebars.init()}})(jQuery); \ No newline at end of file From 37d79ee0be5b08ee13e88d71794eb1b9293162a9 Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Tue, 29 Aug 2017 18:41:44 +0200 Subject: [PATCH 111/124] More minor UI stuff --- widgets/control-widget.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/widgets/control-widget.php b/widgets/control-widget.php index ea7353a..a2739b0 100644 --- a/widgets/control-widget.php +++ b/widgets/control-widget.php @@ -122,19 +122,19 @@ public function form( $instance ) { $field_id = $this->get_field_id( $this->widget_setting ); ?>

    -   + :
    settings['sidebars'] as $sidebar_id => $value ) { if ( empty( $this->settings['sidebars'][ $sidebar_id ]['enable'] ) ) { continue; } ?> - + -   +

    @@ -206,7 +206,12 @@ public function form( $instance ) {

    > - +


    From 9034668099b5ae18c5d48722a3acdacb41b9d2e1 Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Tue, 29 Aug 2017 18:44:55 +0200 Subject: [PATCH 112/124] 0.4-rc1 --- off-canvas-sidebars.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/off-canvas-sidebars.php b/off-canvas-sidebars.php index 1dd08c1..8d4fad7 100644 --- a/off-canvas-sidebars.php +++ b/off-canvas-sidebars.php @@ -3,7 +3,7 @@ * @author Jory Hogeveen * @package Off_Canvas_Sidebars * @since 0.1 - * @version 0.4-dev + * @version 0.4-rc1 * @licence GPL-2.0+ * @link https://github.com/JoryHogeveen/off-canvas-sidebars * @@ -11,7 +11,7 @@ * Plugin Name: Off-Canvas Sidebars * Description: Add off-canvas sidebars using the Slidebars jQuery plugin * Plugin URI: https://wordpress.org/plugins/off-canvas-sidebars/ - * Version: 0.4-dev + * Version: 0.4-rc1 * Author: Jory Hogeveen * Author URI: http://www.keraweb.nl * Text Domain: off-canvas-sidebars @@ -42,7 +42,7 @@ die(); } -define( 'OCS_PLUGIN_VERSION', '0.4-dev' ); +define( 'OCS_PLUGIN_VERSION', '0.4-rc1' ); define( 'OCS_FILE', __FILE__ ); define( 'OCS_BASENAME', plugin_basename( OCS_FILE ) ); define( 'OCS_PLUGIN_DIR', plugin_dir_path( OCS_FILE ) ); From d0fed9aab75dcfc5c474b6f2657b5ed854933c5b Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Tue, 29 Aug 2017 23:54:51 +0200 Subject: [PATCH 113/124] JS CodeStyle --- js/mce-plugin-shortcode.js | 239 ++++++++++++++++------------- js/mce-plugin-shortcode.min.js | 2 +- js/off-canvas-sidebars-settings.js | 8 +- 3 files changed, 139 insertions(+), 110 deletions(-) diff --git a/js/mce-plugin-shortcode.js b/js/mce-plugin-shortcode.js index 1bd02d0..5338c7c 100644 --- a/js/mce-plugin-shortcode.js +++ b/js/mce-plugin-shortcode.js @@ -66,13 +66,13 @@ return false; } ); - //add popup + // Add popup. editor.addCommand( 'ocs_trigger_popup', function ( ui, v ) { var fields = []; - // Used $.extent() to remove the original object reference + // Used $.extent() to remove the original object reference. var defaults = $.extend( true, {}, ocsMceSettings.fields ); - //setup defaults + // Setup defaults. for ( var field in defaults ) { if ( ! defaults.hasOwnProperty( field ) ) { continue; @@ -93,16 +93,16 @@ fields.push( fieldData ); } - //open the popup + // Open the popup. var popup = editor.windowManager.open( { title: ocsMceSettings.title, body: fields, - //when the ok button is clicked + // When the ok button is clicked. onsubmit: function ( e ) { - //start the shortcode tag + // Start the shortcode tag. var shortcode_str = '[' + shortcode; - // Loop through our known fields + // Loop through our known fields. for ( var field in ocsMceSettings.fields ) { if ( ! ocsMceSettings.fields.hasOwnProperty( field ) ) { continue; @@ -121,12 +121,12 @@ } } - // If the test contains a double quote, force it to be nested for compatibility - if ( e.data.text.length && e.data.text.indexOf( '"' ) !== -1 ) { + // If the test contains a double quote, force it to be nested for compatibility. + if ( e.data.text.length && -1 !== e.data.text.indexOf( '"' ) ) { e.data.nested = true; } - //add panel text + // Add panel text. if ( 'undefined' !== typeof e.data.nested && e.data.nested ) { shortcode_str += ']' + e.data.text + '[/' + shortcode + ']'; } else { @@ -136,7 +136,7 @@ shortcode_str += ']'; } - //insert shortcode to TinyMCE + // Insert shortcode to TinyMCE. editor.insertContent( shortcode_str ); } } ); @@ -156,7 +156,7 @@ } } ); - // Add toolbar remove button + // Add toolbar remove button. editor.addButton( 'ocs_trigger_unlink', { tooltip: 'Remove Off-Canvas trigger', icon: 'dashicon dashicons-editor-unlink', @@ -170,7 +170,7 @@ } } ); - // Add toolbar remove button + // Add toolbar remove button. editor.addButton( 'ocs_trigger_remove', { tooltip: 'Remove', icon: 'dashicon dashicons-no', @@ -183,7 +183,7 @@ } } ); - // Create toolbar + // Create toolbar. editor.on( 'preinit', function () { if ( editor.wp && editor.wp._createToolbar ) { toolbar = editor.wp._createToolbar( [ @@ -213,9 +213,9 @@ } } ); - // Show toolbar + // Show toolbar. editor.on( 'wptoolbar', function ( e ) { - if ( e.element.className.indexOf( 'ocsTrigger' ) > -1 ) { + if ( -1 < e.element.className.indexOf( 'ocsTrigger' ) ) { toolbarElement = e.element; if ( $( e.element ).is( 'img' ) ) { e.toolbar = toolbarImg; @@ -228,16 +228,16 @@ } } ); - // Disable our button if the selected text is already a OCS shortcode + // Disable our button if the selected text is already a OCS shortcode. editor.on( 'NodeChange', function ( e ) { - if ( e.element.className.indexOf( 'ocsTrigger' ) > -1 ) { + if ( -1 < e.element.className.indexOf( 'ocsTrigger' ) ) { $( e.target.container ).closest( '.wp-editor-wrap' ).find( 'button.ocs-shortcode-generator' ).attr( 'disabled', true ); } else { $( e.target.container ).closest( '.wp-editor-wrap' ).find( 'button.ocs-shortcode-generator' ).attr( 'disabled', false ); } } ); - // Always enable the button again when the editor gets blurred (out of focus) + // Always enable the button again when the editor gets blurred (out of focus). editor.on( 'Blur', function ( e ) { $( e.target.container ).closest( '.wp-editor-wrap' ).find( 'button.ocs-shortcode-generator' ).attr( 'disabled', false ); } ); @@ -253,7 +253,7 @@ } ); editor.on( 'DblClick', function ( e ) { - if ( e.target.className.indexOf( 'ocsTrigger' ) > -1 ) { + if ( -1 < e.target.className.indexOf( 'ocsTrigger' ) ) { doTriggerPopup( e.target, this ); } } ); @@ -261,8 +261,9 @@ /** * Sets the selected element and the element data before triggering the popup * - * @param el - * @param curEditor + * @param {string} el The element HTML. + * @param {object} curEditor The current editor. + * @return {null} Nothing. */ function doTriggerPopup( el, curEditor ) { curEditor.selection.select( el ); @@ -270,7 +271,7 @@ attr = parseHTMLToData( el ), data = {}; - // Loop through our known fields + // Loop through our known fields. for ( var field in ocsMceSettings.fields ) { if ( ! ocsMceSettings.fields.hasOwnProperty( field ) ) { continue; @@ -287,13 +288,18 @@ data = objectRemoveEmpty( data ); - // overwrites + // overwrites. data.nested = ( 'true' === $el.attr( 'data-ocs-nested' ) ); data.text = parseElementText( el ); curEditor.execCommand( 'ocs_trigger_popup', '', data ); } + /** + * Find the OCS shortcode in a block of text and parse them to actual HTML. + * @param {string} content The content. + * @return {string} The new HTML. + */ function replaceShortcodes( content ) { //match [ocs_trigger(attr)](con)[/ocs_trigger] @@ -309,6 +315,11 @@ return content; } + /** + * Convert Trigger HTML into shortcodes. + * @param {string} content The content. + * @return {string} The new HTML. + */ function restoreShortcodes( content ) { var html = $( '
    ' ).html( content ); @@ -334,32 +345,32 @@ } /** - * - * @param cls - * @param data - * @param con - * @param nested - * @returns {string} + * Convert data to HTML. + * @param {string} cls Class. + * @param {string} data Attribute data. + * @param {string} con Content. + * @param {boolean} nested Is it a nested shortcode? + * @return {string} The HTML. */ function parseDataToHTML( cls, data, con, nested ) { var attrData = { //id: getAttr( data, 'id' ), //action: getAttr( data, 'action' ), - element: getAttr( data, 'element' ), - class: getAttr( data, 'class' ), - attributes: getAttr( data, 'attr' ) + element: getAttr( data, 'element', false ), + class: getAttr( data, 'class', false ), + attributes: getAttr( data, 'attr', false ) }; if ( ! nested ) { - con = getAttr( data, 'text' ); + con = getAttr( data, 'text', false ); } if ( ! attrData.attributes.length ) { - attrData.attributes = getAttr( data, 'attributes' ); + attrData.attributes = getAttr( data, 'attributes', false ); } if ( ! attrData.class.length ) { - attrData.class = getAttr( data, 'classes' ); + attrData.class = getAttr( data, 'classes', false ); } if ( ! attrData.element.length ) { @@ -384,41 +395,44 @@ data = attrHTMLToObject( data ); for ( var key in attrData ) { - data[ key ] = attrData[ key ]; + if ( attrData.hasOwnProperty( key ) ) { + data[ key ] = attrData[ key ]; + } } - // Remove duplicates and empty values + // Remove duplicates and empty values. data = objectRemoveEmpty( data ); data = attrObjectToHTML( data ); data = window.encodeURIComponent( data ); var content = window.encodeURIComponent( con ); - // Some text is required for the editor to work properly + // Some text is required for the editor to work properly. if ( ! content.length && 'img' !== attrData.element ) { content = con = ' '; } - if ( 'img' === attrData.element ) { // && typeof elAttributes.alt != 'string' + if ( 'img' === attrData.element ) { // && 'string' !== typeof elAttributes.alt attributes.alt = content; } - var elAttributes = attrObjectToHTML( attributes ); + attributes['data-ocs-nested'] = nested; + attributes['data-ocs-attr'] = data; + attributes['data-ocs-text'] = content; - if ( $.inArray( attrData.element, singletons ) > -1 ) { - // singleton element - //nested = false; + var elAttributes = attrObjectToHTML( attributes ); - return '<' + attrData.element + ' ' + elAttributes + ' ' + 'data-ocs-nested="' + nested + '" ' + 'data-ocs-attr="' + data + '" data-ocs-text="' + content + '" />'; + if ( -1 < $.inArray( attrData.element, singletons ) ) { + return '<' + attrData.element + ' ' + elAttributes + ' />'; } else { - return '<' + attrData.element + ' ' + elAttributes + ' ' + 'data-ocs-nested="' + nested + '" ' + 'data-ocs-attr="' + data + '" data-ocs-text="' + content + '">' + con + ''; + return '<' + attrData.element + ' ' + elAttributes + '>' + con + ''; } // data-mce-resize="false" data-mce-placeholder="1" } /** - * - * @param el - * @returns {Object} + * Convert attribute string to attribute object. + * @param {string|object} el The element. + * @return {Object} */ function parseHTMLToData( el ) { var attr = window.decodeURIComponent( $( el ).attr( 'data-ocs-attr' ) ); @@ -426,7 +440,7 @@ var attributes = attrHTMLToObject( attr ); var elAttributes = attrElementToObject( el ); - // Overwrites + // Overwrites. if ( 'undefined' !== typeof attributes.attributes ) { if ( 'string' !== typeof attributes.attr ) { attributes.attr = attributes.attributes; @@ -440,7 +454,7 @@ delete attributes.classes; } - // Converting + // Converting. if ( 'string' === typeof attributes.attr ) { attributes.attr = attrStringToObject( attributes.attr ); } else { @@ -455,8 +469,8 @@ } else { attributes.class = elAttributes.class; } - } else if ( key.indexOf( 'data-' ) === -1 && 'string' === typeof elAttributes[ key ] ) { - // overwrite, check for alt tag for images + } else if ( -1 === key.indexOf( 'data-' ) && 'string' === typeof elAttributes[ key ] ) { + // overwrite, check for alt tag for images. if ( 'alt' === key && $( el ).is( 'img' ) ) { delete attributes.attr[ key ]; } else { @@ -466,11 +480,11 @@ } if ( 'string' === typeof attributes.class && attributes.class.trim().length ) { - // Convert classes to an array + // Convert classes to an array. attributes.class = attributes.class.split( ' ' ); - // Remove MCE plugin defined classes + // Remove MCE plugin defined classes. attributes.class = arrayFilterUnique( attributes.class, true, true ); - // Rejoin the classes + // Rejoin the classes. attributes.class = attributes.class.join( ' ' ); } @@ -478,16 +492,16 @@ attributes.attr = attrObjectToString( attributes.attr ); } - // Remove duplicate and empty attributes + // Remove duplicate and empty attributes. attributes = objectRemoveEmpty( attributes ); return attributes; } /** - * - * @param el - * @returns {string} + * Get the element text, also checks for nested element attributes. + * @param {string|object} el The element. + * @return {string} The text. */ function parseElementText( el ) { var $el = $( el ), @@ -496,7 +510,7 @@ text = $el.html(); } - // Images have the alt tag for text + // Images have the alt tag for text. if ( $el.is('img') ) { if ( $el.attr('alt') ) { text = $el.attr('alt'); @@ -508,9 +522,9 @@ } /** - * - * @param el - * @param editor + * Remove OCS classes & attributes. + * @param {string|object} el The element. + * @param {object} editor The editor. */ function removeTriggerData( el, editor ) { var $el = $( el ); @@ -523,10 +537,10 @@ } /** - * @param s - * @param a - * @param f - * @returns {*} + * @param {string} s The string. + * @param {string} a The attribute to find. + * @param {boolean} f @todo + * @return {string|boolean} The attribute value or false. */ function getAttr( s, a, f ) { var n = new RegExp( a + '=\"([^\"]+)\"', 'g' ).exec( s ); @@ -544,8 +558,9 @@ * In: element * Out: { key: value, key: value } * - * @param el - * @returns Object + * @since 0.4 + * @param {string|object} el The element. + * @return {object} The attribute object. */ function attrElementToObject( el ) { var $el = $( el ), @@ -559,89 +574,101 @@ } /** - * Convert HTML formatted attribute string to object + * Convert HTML formatted attribute string to object. * In: key="value" key="value" * Out: { key: value, key: value } * - * @param attrString - * @returns Object + * @since 0.4 + * @param {string} attrString The attribute string. + * @return {object} The attribute object. */ function attrHTMLToObject( attrString ) { var arr = attrString.trim().split( '" ' ), atts = {}; for ( var key in arr ) { - arr[ key ] = arr[ key ].split( '="' ); - if ( arr[ key ][ 0 ].trim().length ) { - atts[ arr[ key ][ 0 ].trim() ] = getAttr( attrString, arr[ key ][ 0 ] ); + if ( arr.hasOwnProperty( key ) ) { + arr[ key ] = arr[ key ].split( '="' ); + if ( arr[ key ][ 0 ].trim().length ) { + atts[ arr[ key ][ 0 ].trim() ] = getAttr( attrString, arr[ key ][ 0 ], false ); + } } } return atts; } /** - * Convert OCS formatted attribute string to object + * Convert OCS formatted attribute string to object. * * In: key:value;key:value * Out: { key: value, key: value } * - * @param attrString - * @returns Object + * @since 0.4 + * @param {string} attrString The attribute string. + * @return {object} The attribute object. */ function attrStringToObject( attrString ) { var arr = attrString.split( ';' ), atts = {}; for ( var key in arr ) { - arr[ key ] = arr[ key ].split( ':' ); - if ( arr[ key ][ 0 ].trim().length ) { - var name = arr[ key ][ 0 ].trim(); - arr[ key ].splice( 0, 1 ); - atts[ name ] = arr[ key ].join( ':' ); + if ( arr.hasOwnProperty( key ) ) { + arr[ key ] = arr[ key ].split( ':' ); + if ( arr[ key ][ 0 ].trim().length ) { + var name = arr[ key ][ 0 ].trim(); + arr[ key ].splice( 0, 1 ); + atts[ name ] = arr[ key ].join( ':' ); + } } } return atts; } /** - * Convert object to OCS formatted attribute string + * Convert object to OCS formatted attribute string. * * In: { key: value, key: value } * Out: key="value" key="value" * - * @param attrObj - * @returns String + * @since 0.4 + * @param {object} attrObj The attribute object. + * @return {string} The attribute string. */ function attrObjectToHTML( attrObj ) { var atts = []; for ( var name in attrObj ) { - atts.push( name + '="' + attrObj[ name ] + '"' ); + if ( attrObj.hasOwnProperty( name ) ) { + atts.push( name + '="' + attrObj[ name ] + '"' ); + } } return atts.join( ' ' ); } /** - * Convert object to HTML formatted attribute string + * Convert object to HTML formatted attribute string. * * In: { key: value, key: value } * Out: key:value;key:value * - * @param attrObj - * @returns String + * @since 0.4 + * @param {object} attrObj The attribute object. + * @return {string} The attribute string. */ function attrObjectToString( attrObj ) { var atts = []; for ( var name in attrObj ) { - atts.push( name + ':' + attrObj[ name ] ); + if ( attrObj.hasOwnProperty( name ) ) { + atts.push( name + ':' + attrObj[ name ] ); + } } return atts.join( ';' ); } /** - * Return unique values only + * Return unique values only. * - * @param array Array - * @param empty bool Remove empty keys? - * @param ocs bool Check this plugin's defines classes - * @returns Array + * @param {object} array The array to filter. + * @param {boolean} empty Remove empty keys? + * @param {boolean} ocs Check this plugin's defines classes. + * @return {object} The filtered array. */ function arrayFilterUnique( array, empty, ocs ) { if ( ! array.length ) { @@ -651,7 +678,7 @@ if ( empty && !el.length ) { return false; } - if ( ocs && $.inArray( el, mceClasses ) > -1 ) { + if ( ocs && -1 < $.inArray( el, mceClasses ) ) { return false; } return index === $.inArray( el, array ); @@ -659,18 +686,21 @@ } /** - * Remove empty properties from object - * Only objects with strings as parameters allowed! + * Remove empty properties from object. + * Only objects with strings as values allowed! * - * @param obj Object - * @returns Object + * @param {object} obj The object to filter. + * @return {object} The object without empty keys. */ function objectRemoveEmpty( obj ) { for ( var name in obj ) { + if ( ! obj.hasOwnProperty( name ) ) { + continue; + } if ( 'string' === typeof obj[ name ] ) { obj[ name ] = obj[ name ].trim(); } - if ( obj[ name ] === null || obj[ name ] === undefined || ! obj[ name ].length ) { + if ( null === obj[ name ] || undefined === obj[ name ] || ! obj[ name ].length ) { delete obj[ name ]; } } @@ -679,5 +709,4 @@ } ); -//} )(); -} )( window.tinymce, jQuery ); +} ) ( window.tinymce, jQuery ); diff --git a/js/mce-plugin-shortcode.min.js b/js/mce-plugin-shortcode.min.js index 7346fa1..414287c 100644 --- a/js/mce-plugin-shortcode.min.js +++ b/js/mce-plugin-shortcode.min.js @@ -9,4 +9,4 @@ * * https://generatewp.com/take-shortcodes-ultimate-level/ */ -(function(tinymce,$){tinymce.PluginManager.add("off_canvas_sidebars",function(editor,url){var toolbar;var toolbarImg;var toolbarLink;var toolbarElement;var shortcode="ocs_trigger";var mceClasses=["mceItem","ocsTrigger",ocsMceSettings.prefix+"-trigger"];var singletons=["br","hr","img","input"];$(document).ready(function(){if("undefined"!==typeof ocsMceSettings){$(".ocs-shortcode-generator").removeClass("hidden")}});$(document).on("click","#wp-"+editor.id+"-wrap .wp-media-buttons button.ocs-shortcode-generator",function(){var selection=editor.selection.getContent(),$selection=$(selection),data={};if(selection.length){if($selection.is("img")){data.text=$selection.attr("alt");data.element="img";data.class=$selection.attr("class");var attr=[];if($selection.attr("src")){attr.push("src:"+$selection.attr("src"))}if($selection.attr("width")){attr.push("width:"+$selection.attr("width"))}if($selection.attr("height")){attr.push("height:"+$selection.attr("height"))}if($selection.attr("title")){attr.push("title:"+$selection.attr("title"))}data.attr=attr.join(";")}else{data.text=selection;data.element="span"}}editor.execCommand("ocs_trigger_popup","",data);return false});editor.addCommand("ocs_trigger_popup",function(ui,v){var fields=[];var defaults=$.extend(true,{},ocsMceSettings.fields);for(var field in defaults){if(!defaults.hasOwnProperty(field)){continue}var fieldData=defaults[field];if(v[field]){if("checkbox"===fieldData.type){fieldData.checked=v[field]}else{fieldData.value=v[field]}}if("text"===fieldData.name&&"img"===v.element){fieldData.label="Alt";fieldData.tooltip="";fieldData.multiline=false}fields.push(fieldData)}var popup=editor.windowManager.open({title:ocsMceSettings.title,body:fields,onsubmit:function(e){var shortcode_str="["+shortcode;for(var field in ocsMceSettings.fields){if(!ocsMceSettings.fields.hasOwnProperty(field)){continue}if("container"===ocsMceSettings.fields[field].type){continue}if("undefined"!==typeof e.data[field]){if(-1>=$.inArray(field,["text","nested"])){if("checkbox"===ocsMceSettings.fields[field].type&&e.data[field]){shortcode_str+=" "+field+'="1"'}else if(e.data[field].length){shortcode_str+=" "+field+'="'+e.data[field].replace(/(\r\n|\n|\r)/gm,"")+'"'}}}}if(e.data.text.length&&e.data.text.indexOf('"')!==-1){e.data.nested=true}if("undefined"!==typeof e.data.nested&&e.data.nested){shortcode_str+="]"+e.data.text+"[/"+shortcode+"]"}else{if(e.data.text.length){shortcode_str+=' text="'+e.data.text+'"'}shortcode_str+="]"}editor.insertContent(shortcode_str)}})});editor.addButton("ocs_trigger_popup",{tooltip:"Edit Off-Canvas trigger",icon:"dashicon dashicons-admin-links",label:"Edit Off-Canvas trigger",title:"Off-Canvas trigger",onclick:function(){doTriggerPopup(toolbarElement,editor)}});editor.addButton("ocs_trigger_unlink",{tooltip:"Remove Off-Canvas trigger",icon:"dashicon dashicons-editor-unlink",label:"Remove Off-Canvas trigger",onclick:function(){removeTriggerData(toolbarElement,editor);toolbarElement=null;tinymce.toolbar=null}});editor.addButton("ocs_trigger_remove",{tooltip:"Remove",icon:"dashicon dashicons-no",label:"Remove",onclick:function(){$(toolbarElement).remove();toolbarElement=null;editor.execCommand("unlink")}});editor.on("preinit",function(){if(editor.wp&&editor.wp._createToolbar){toolbar=editor.wp._createToolbar(["ocs_trigger_popup","ocs_trigger_unlink","ocs_trigger_remove"],true);toolbarImg=editor.wp._createToolbar(["wp_img_alignleft","wp_img_aligncenter","wp_img_alignright","wp_img_alignnone","ocs_trigger_popup","ocs_trigger_unlink","wp_img_edit","wp_img_remove"],true);toolbarLink=editor.wp._createToolbar(["wp_link_preview","ocs_trigger_popup","ocs_trigger_unlink","wp_link_edit","wp_link_remove"],true)}});editor.on("wptoolbar",function(e){if(e.element.className.indexOf("ocsTrigger")>-1){toolbarElement=e.element;if($(e.element).is("img")){e.toolbar=toolbarImg}else if($(e.element).is("a")){e.toolbar=toolbarLink}else{e.toolbar=toolbar}}});editor.on("NodeChange",function(e){if(e.element.className.indexOf("ocsTrigger")>-1){$(e.target.container).closest(".wp-editor-wrap").find("button.ocs-shortcode-generator").attr("disabled",true)}else{$(e.target.container).closest(".wp-editor-wrap").find("button.ocs-shortcode-generator").attr("disabled",false)}});editor.on("Blur",function(e){$(e.target.container).closest(".wp-editor-wrap").find("button.ocs-shortcode-generator").attr("disabled",false)});editor.on("BeforeSetcontent",function(e){if(ocsMceSettings.render){e.content=replaceShortcodes(e.content)}});editor.on("GetContent",function(e){e.content=restoreShortcodes(e.content)});editor.on("DblClick",function(e){if(e.target.className.indexOf("ocsTrigger")>-1){doTriggerPopup(e.target,this)}});function doTriggerPopup(el,curEditor){curEditor.selection.select(el);var $el=$(el),attr=parseHTMLToData(el),data={};for(var field in ocsMceSettings.fields){if(!ocsMceSettings.fields.hasOwnProperty(field)){continue}if("container"===ocsMceSettings.fields[field].type){continue}if("checkbox"===ocsMceSettings.fields[field].type){data[field]="1"===attr[field]}else{data[field]=attr[field]}}data=objectRemoveEmpty(data);data.nested="true"===$el.attr("data-ocs-nested");data.text=parseElementText(el);curEditor.execCommand("ocs_trigger_popup","",data)}function replaceShortcodes(content){content=content.replace(/\[ocs_trigger([^\]]*)\]([^\]]*)\[\/ocs_trigger\]/g,function(all,attr,con){return parseDataToHTML("ocsTrigger",attr,con,true)});content=content.replace(/\[ocs_trigger([^\]]*)\]/g,function(all,attr){return parseDataToHTML("ocsTrigger",attr,"",false)});return content}function restoreShortcodes(content){var html=$("
    ").html(content);$(html).find(".mceItem.ocsTrigger").each(function(){var attr=parseHTMLToData(this);var text=parseElementText(this);var nested=window.decodeURIComponent($(this).attr("data-ocs-nested"));if("true"===nested){delete attr.text;attr=attrObjectToHTML(attr);$(this).replaceWith("["+shortcode+" "+attr+"]"+text+"[/"+shortcode+"]")}else{attr.text=text;attr=attrObjectToHTML(attr);$(this).replaceWith("["+shortcode+" "+attr+"]")}});content=$(html).html();return content}function parseDataToHTML(cls,data,con,nested){var attrData={element:getAttr(data,"element"),"class":getAttr(data,"class"),attributes:getAttr(data,"attr")};if(!nested){con=getAttr(data,"text")}if(!attrData.attributes.length){attrData.attributes=getAttr(data,"attributes")}if(!attrData.class.length){attrData.class=getAttr(data,"classes")}if(!attrData.element.length){attrData.element="button"}var attributes=attrStringToObject(attrData.attributes);var classes=[];classes.push("mceItem",cls);if("string"===typeof attributes.class){classes=classes.concat(attributes.class.split(" "));delete attributes.class}if(attrData.class.length){classes=classes.concat(attrData.class.split(" "))}attrData.class=arrayFilterUnique(classes,true,true).join(" ");attributes.class=arrayFilterUnique(classes,true,false).join(" ");attributes=objectRemoveEmpty(attributes);data=attrHTMLToObject(data);for(var key in attrData){data[key]=attrData[key]}data=objectRemoveEmpty(data);data=attrObjectToHTML(data);data=window.encodeURIComponent(data);var content=window.encodeURIComponent(con);if(!content.length&&"img"!==attrData.element){content=con=" "}if("img"===attrData.element){attributes.alt=content}var elAttributes=attrObjectToHTML(attributes);if($.inArray(attrData.element,singletons)>-1){return"<"+attrData.element+" "+elAttributes+" "+'data-ocs-nested="'+nested+'" '+'data-ocs-attr="'+data+'" data-ocs-text="'+content+'" />'}else{return"<"+attrData.element+" "+elAttributes+" "+'data-ocs-nested="'+nested+'" '+'data-ocs-attr="'+data+'" data-ocs-text="'+content+'">'+con+""}}function parseHTMLToData(el){var attr=window.decodeURIComponent($(el).attr("data-ocs-attr"));var attributes=attrHTMLToObject(attr);var elAttributes=attrElementToObject(el);if("undefined"!==typeof attributes.attributes){if("string"!==typeof attributes.attr){attributes.attr=attributes.attributes}delete attributes.attributes}if("undefined"!==typeof attributes.classes){if("string"!==typeof attributes.class){attributes.class=attributes.classes}delete attributes.classes}if("string"===typeof attributes.attr){attributes.attr=attrStringToObject(attributes.attr)}else{attributes.attr={}}for(var key in elAttributes){if("class"===key&&elAttributes.class.length){if("string"===typeof attributes.class){attributes.class+=" "+elAttributes.class}else{attributes.class=elAttributes.class}}else if(key.indexOf("data-")===-1&&"string"===typeof elAttributes[key]){if("alt"===key&&$(el).is("img")){delete attributes.attr[key]}else{attributes.attr[key]=""+elAttributes[key]}}}if("string"===typeof attributes.class&&attributes.class.trim().length){attributes.class=attributes.class.split(" ");attributes.class=arrayFilterUnique(attributes.class,true,true);attributes.class=attributes.class.join(" ")}if("object"===typeof attributes.attr){attributes.attr=attrObjectToString(attributes.attr)}attributes=objectRemoveEmpty(attributes);return attributes}function parseElementText(el){var $el=$(el),text=window.decodeURIComponent($el.attr("data-ocs-text"));if($el.html().length){text=$el.html()}if($el.is("img")){if($el.attr("alt")){text=$el.attr("alt")}else{text=""}}return text}function removeTriggerData(el,editor){var $el=$(el);$el.removeClass("mceItem");$el.removeClass("ocsTrigger");$el.removeAttr("data-ocs-attr");$el.removeAttr("data-ocs-text");$el.removeAttr("data-ocs-nested")}function getAttr(s,a,f){var n=new RegExp(a+'="([^"]+)"',"g").exec(s);if(true===f&&!n&&-1===s.indexOf(a+'="')){return false}return n?window.decodeURIComponent(n[1]).trim():""}function attrElementToObject(el){var $el=$(el),atts={};if($el.length){$.each($el[0].attributes,function(index,attr){atts[attr.name]=attr.value})}return atts}function attrHTMLToObject(attrString){var arr=attrString.trim().split('" '),atts={};for(var key in arr){arr[key]=arr[key].split('="');if(arr[key][0].trim().length){atts[arr[key][0].trim()]=getAttr(attrString,arr[key][0])}}return atts}function attrStringToObject(attrString){var arr=attrString.split(";"),atts={};for(var key in arr){arr[key]=arr[key].split(":");if(arr[key][0].trim().length){var name=arr[key][0].trim();arr[key].splice(0,1);atts[name]=arr[key].join(":")}}return atts}function attrObjectToHTML(attrObj){var atts=[];for(var name in attrObj){atts.push(name+'="'+attrObj[name]+'"')}return atts.join(" ")}function attrObjectToString(attrObj){var atts=[];for(var name in attrObj){atts.push(name+":"+attrObj[name])}return atts.join(";")}function arrayFilterUnique(array,empty,ocs){if(!array.length){return[]}return $.grep(array,function(el,index){if(empty&&!el.length){return false}if(ocs&&$.inArray(el,mceClasses)>-1){return false}return index===$.inArray(el,array)})}function objectRemoveEmpty(obj){for(var name in obj){if("string"===typeof obj[name]){obj[name]=obj[name].trim()}if(obj[name]===null||obj[name]===undefined||!obj[name].length){delete obj[name]}}return obj}})})(window.tinymce,jQuery); \ No newline at end of file +(function(tinymce,$){tinymce.PluginManager.add("off_canvas_sidebars",function(editor,url){var toolbar;var toolbarImg;var toolbarLink;var toolbarElement;var shortcode="ocs_trigger";var mceClasses=["mceItem","ocsTrigger",ocsMceSettings.prefix+"-trigger"];var singletons=["br","hr","img","input"];$(document).ready(function(){if("undefined"!==typeof ocsMceSettings){$(".ocs-shortcode-generator").removeClass("hidden")}});$(document).on("click","#wp-"+editor.id+"-wrap .wp-media-buttons button.ocs-shortcode-generator",function(){var selection=editor.selection.getContent(),$selection=$(selection),data={};if(selection.length){if($selection.is("img")){data.text=$selection.attr("alt");data.element="img";data.class=$selection.attr("class");var attr=[];if($selection.attr("src")){attr.push("src:"+$selection.attr("src"))}if($selection.attr("width")){attr.push("width:"+$selection.attr("width"))}if($selection.attr("height")){attr.push("height:"+$selection.attr("height"))}if($selection.attr("title")){attr.push("title:"+$selection.attr("title"))}data.attr=attr.join(";")}else{data.text=selection;data.element="span"}}editor.execCommand("ocs_trigger_popup","",data);return false});editor.addCommand("ocs_trigger_popup",function(ui,v){var fields=[];var defaults=$.extend(true,{},ocsMceSettings.fields);for(var field in defaults){if(!defaults.hasOwnProperty(field)){continue}var fieldData=defaults[field];if(v[field]){if("checkbox"===fieldData.type){fieldData.checked=v[field]}else{fieldData.value=v[field]}}if("text"===fieldData.name&&"img"===v.element){fieldData.label="Alt";fieldData.tooltip="";fieldData.multiline=false}fields.push(fieldData)}var popup=editor.windowManager.open({title:ocsMceSettings.title,body:fields,onsubmit:function(e){var shortcode_str="["+shortcode;for(var field in ocsMceSettings.fields){if(!ocsMceSettings.fields.hasOwnProperty(field)){continue}if("container"===ocsMceSettings.fields[field].type){continue}if("undefined"!==typeof e.data[field]){if(-1>=$.inArray(field,["text","nested"])){if("checkbox"===ocsMceSettings.fields[field].type&&e.data[field]){shortcode_str+=" "+field+'="1"'}else if(e.data[field].length){shortcode_str+=" "+field+'="'+e.data[field].replace(/(\r\n|\n|\r)/gm,"")+'"'}}}}if(e.data.text.length&&-1!==e.data.text.indexOf('"')){e.data.nested=true}if("undefined"!==typeof e.data.nested&&e.data.nested){shortcode_str+="]"+e.data.text+"[/"+shortcode+"]"}else{if(e.data.text.length){shortcode_str+=' text="'+e.data.text+'"'}shortcode_str+="]"}editor.insertContent(shortcode_str)}})});editor.addButton("ocs_trigger_popup",{tooltip:"Edit Off-Canvas trigger",icon:"dashicon dashicons-admin-links",label:"Edit Off-Canvas trigger",title:"Off-Canvas trigger",onclick:function(){doTriggerPopup(toolbarElement,editor)}});editor.addButton("ocs_trigger_unlink",{tooltip:"Remove Off-Canvas trigger",icon:"dashicon dashicons-editor-unlink",label:"Remove Off-Canvas trigger",onclick:function(){removeTriggerData(toolbarElement,editor);toolbarElement=null;tinymce.toolbar=null}});editor.addButton("ocs_trigger_remove",{tooltip:"Remove",icon:"dashicon dashicons-no",label:"Remove",onclick:function(){$(toolbarElement).remove();toolbarElement=null;editor.execCommand("unlink")}});editor.on("preinit",function(){if(editor.wp&&editor.wp._createToolbar){toolbar=editor.wp._createToolbar(["ocs_trigger_popup","ocs_trigger_unlink","ocs_trigger_remove"],true);toolbarImg=editor.wp._createToolbar(["wp_img_alignleft","wp_img_aligncenter","wp_img_alignright","wp_img_alignnone","ocs_trigger_popup","ocs_trigger_unlink","wp_img_edit","wp_img_remove"],true);toolbarLink=editor.wp._createToolbar(["wp_link_preview","ocs_trigger_popup","ocs_trigger_unlink","wp_link_edit","wp_link_remove"],true)}});editor.on("wptoolbar",function(e){if(-1").html(content);$(html).find(".mceItem.ocsTrigger").each(function(){var attr=parseHTMLToData(this);var text=parseElementText(this);var nested=window.decodeURIComponent($(this).attr("data-ocs-nested"));if("true"===nested){delete attr.text;attr=attrObjectToHTML(attr);$(this).replaceWith("["+shortcode+" "+attr+"]"+text+"[/"+shortcode+"]")}else{attr.text=text;attr=attrObjectToHTML(attr);$(this).replaceWith("["+shortcode+" "+attr+"]")}});content=$(html).html();return content}function parseDataToHTML(cls,data,con,nested){var attrData={element:getAttr(data,"element",false),"class":getAttr(data,"class",false),attributes:getAttr(data,"attr",false)};if(!nested){con=getAttr(data,"text",false)}if(!attrData.attributes.length){attrData.attributes=getAttr(data,"attributes",false)}if(!attrData.class.length){attrData.class=getAttr(data,"classes",false)}if(!attrData.element.length){attrData.element="button"}var attributes=attrStringToObject(attrData.attributes);var classes=[];classes.push("mceItem",cls);if("string"===typeof attributes.class){classes=classes.concat(attributes.class.split(" "));delete attributes.class}if(attrData.class.length){classes=classes.concat(attrData.class.split(" "))}attrData.class=arrayFilterUnique(classes,true,true).join(" ");attributes.class=arrayFilterUnique(classes,true,false).join(" ");attributes=objectRemoveEmpty(attributes);data=attrHTMLToObject(data);for(var key in attrData){if(attrData.hasOwnProperty(key)){data[key]=attrData[key]}}data=objectRemoveEmpty(data);data=attrObjectToHTML(data);data=window.encodeURIComponent(data);var content=window.encodeURIComponent(con);if(!content.length&&"img"!==attrData.element){content=con=" "}if("img"===attrData.element){attributes.alt=content}attributes["data-ocs-nested"]=nested;attributes["data-ocs-attr"]=data;attributes["data-ocs-text"]=content;var elAttributes=attrObjectToHTML(attributes);if(-1<$.inArray(attrData.element,singletons)){return"<"+attrData.element+" "+elAttributes+" />"}else{return"<"+attrData.element+" "+elAttributes+">"+con+""}}function parseHTMLToData(el){var attr=window.decodeURIComponent($(el).attr("data-ocs-attr"));var attributes=attrHTMLToObject(attr);var elAttributes=attrElementToObject(el);if("undefined"!==typeof attributes.attributes){if("string"!==typeof attributes.attr){attributes.attr=attributes.attributes}delete attributes.attributes}if("undefined"!==typeof attributes.classes){if("string"!==typeof attributes.class){attributes.class=attributes.classes}delete attributes.classes}if("string"===typeof attributes.attr){attributes.attr=attrStringToObject(attributes.attr)}else{attributes.attr={}}for(var key in elAttributes){if("class"===key&&elAttributes.class.length){if("string"===typeof attributes.class){attributes.class+=" "+elAttributes.class}else{attributes.class=elAttributes.class}}else if(-1===key.indexOf("data-")&&"string"===typeof elAttributes[key]){if("alt"===key&&$(el).is("img")){delete attributes.attr[key]}else{attributes.attr[key]=""+elAttributes[key]}}}if("string"===typeof attributes.class&&attributes.class.trim().length){attributes.class=attributes.class.split(" ");attributes.class=arrayFilterUnique(attributes.class,true,true);attributes.class=attributes.class.join(" ")}if("object"===typeof attributes.attr){attributes.attr=attrObjectToString(attributes.attr)}attributes=objectRemoveEmpty(attributes);return attributes}function parseElementText(el){var $el=$(el),text=window.decodeURIComponent($el.attr("data-ocs-text"));if($el.html().length){text=$el.html()}if($el.is("img")){if($el.attr("alt")){text=$el.attr("alt")}else{text=""}}return text}function removeTriggerData(el,editor){var $el=$(el);$el.removeClass("mceItem");$el.removeClass("ocsTrigger");$el.removeAttr("data-ocs-attr");$el.removeAttr("data-ocs-text");$el.removeAttr("data-ocs-nested")}function getAttr(s,a,f){var n=new RegExp(a+'="([^"]+)"',"g").exec(s);if(true===f&&!n&&-1===s.indexOf(a+'="')){return false}return n?window.decodeURIComponent(n[1]).trim():""}function attrElementToObject(el){var $el=$(el),atts={};if($el.length){$.each($el[0].attributes,function(index,attr){atts[attr.name]=attr.value})}return atts}function attrHTMLToObject(attrString){var arr=attrString.trim().split('" '),atts={};for(var key in arr){if(arr.hasOwnProperty(key)){arr[key]=arr[key].split('="');if(arr[key][0].trim().length){atts[arr[key][0].trim()]=getAttr(attrString,arr[key][0],false)}}}return atts}function attrStringToObject(attrString){var arr=attrString.split(";"),atts={};for(var key in arr){if(arr.hasOwnProperty(key)){arr[key]=arr[key].split(":");if(arr[key][0].trim().length){var name=arr[key][0].trim();arr[key].splice(0,1);atts[name]=arr[key].join(":")}}}return atts}function attrObjectToHTML(attrObj){var atts=[];for(var name in attrObj){if(attrObj.hasOwnProperty(name)){atts.push(name+'="'+attrObj[name]+'"')}}return atts.join(" ")}function attrObjectToString(attrObj){var atts=[];for(var name in attrObj){if(attrObj.hasOwnProperty(name)){atts.push(name+":"+attrObj[name])}}return atts.join(";")}function arrayFilterUnique(array,empty,ocs){if(!array.length){return[]}return $.grep(array,function(el,index){if(empty&&!el.length){return false}if(ocs&&-1<$.inArray(el,mceClasses)){return false}return index===$.inArray(el,array)})}function objectRemoveEmpty(obj){for(var name in obj){if(!obj.hasOwnProperty(name)){continue}if("string"===typeof obj[name]){obj[name]=obj[name].trim()}if(null===obj[name]||undefined===obj[name]||!obj[name].length){delete obj[name]}}return obj}})})(window.tinymce,jQuery); \ No newline at end of file diff --git a/js/off-canvas-sidebars-settings.js b/js/off-canvas-sidebars-settings.js index 4c09c67..41d9df7 100644 --- a/js/off-canvas-sidebars-settings.js +++ b/js/off-canvas-sidebars-settings.js @@ -417,10 +417,10 @@ if ( 'undefined' === typeof ocsOffCanvasSidebarsSettings ) { /** * @since 0.4 - * @param {string} s The string. - * @param {string} a The attribute to find. - * @param {bool} f @todo - * @return {string|bool} The attribute value or false. + * @param {string} s The string. + * @param {string} a The attribute to find. + * @param {boolean} f @todo + * @return {string|boolean} The attribute value or false. */ function getAttr( s, a, f ) { var n = new RegExp( a + '=\"([^\"]+)\"', 'g' ).exec( s ); From fdca6ca27dd40705b0379cc6219f381f8062d0a4 Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Wed, 30 Aug 2017 01:02:18 +0200 Subject: [PATCH 114/124] Php CodeStyle --- includes/api.php | 1 - includes/class-editor-shortcode-generator.php | 220 +++++++++--------- includes/class-form.php | 1 - includes/class-frontend.php | 1 - includes/class-menu-meta-box.php | 34 +-- includes/class-settings.php | 1 - widgets/control-widget.php | 111 ++++----- 7 files changed, 191 insertions(+), 178 deletions(-) diff --git a/includes/api.php b/includes/api.php index 63d5522..e2c3f0e 100644 --- a/includes/api.php +++ b/includes/api.php @@ -2,7 +2,6 @@ /** * Off-Canvas Sidebars plugin API * - * API * @author Jory Hogeveen * @package off-canvas-sidebars * @version 0.4 diff --git a/includes/class-editor-shortcode-generator.php b/includes/class-editor-shortcode-generator.php index 72c88fb..c20bb28 100644 --- a/includes/class-editor-shortcode-generator.php +++ b/includes/class-editor-shortcode-generator.php @@ -2,7 +2,6 @@ /** * Off-Canvas Sidebars plugin shortcode generator * - * Shortcode generator * @author Jory Hogeveen * @package off-canvas-sidebars * @version 0.4 @@ -25,13 +24,13 @@ final class OCS_Off_Canvas_Sidebars_Editor_Shortcode_Generator private $settings = array(); /** - * This class gets called in the init hook + * This class gets called in the init hook. * * @since 0.4 * @access private */ private function __construct() { - // check user permissions + // Check user permissions. /*if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) { return; }*/ @@ -47,7 +46,7 @@ private function __construct() { } /** - * Get plugin defaults + * Get plugin defaults. * @since 0.4 */ function load_plugin_data() { @@ -55,21 +54,24 @@ function load_plugin_data() { } /** - * Show our own button + * Show our own button. + * * @since 0.4 * @param string $editor_id The Editor ID. */ function media_buttons( $editor_id ) { //dashicons-move dashicons-editor-code -?> + +settings['sidebars'] as $sidebar_id => $sidebar_data ) { - if ( empty( $sidebar_data['enable'] ) ) { - continue; - } - $label = $sidebar_id; - if ( ! empty( $sidebar_data['label'] ) ) { - $label = $sidebar_data['label'] . ' (' . $sidebar_id . ')'; - } - $sidebars[] = array( - 'text' => $label, - 'value' => $sidebar_id, - ); + $sidebars = array(); + foreach ( $this->settings['sidebars'] as $sidebar_id => $sidebar_data ) { + if ( empty( $sidebar_data['enable'] ) ) { + continue; } - - $elements = array( 'button', 'span', 'a', 'b', 'strong', 'i', 'em', 'img', 'div' ); - $element_values = array(); - foreach ( $elements as $e ) { - $element_values[] = array( - 'text' => '<' . $e . '>', - 'value' => $e, - ); + $label = $sidebar_id; + if ( ! empty( $sidebar_data['label'] ) ) { + $label = $sidebar_data['label'] . ' (' . $sidebar_id . ')'; } + $sidebars[] = array( + 'text' => $label, + 'value' => $sidebar_id, + ); + } - $fields = array( - 'id' => array( - 'type' => 'listbox', - 'name' => 'id', - 'label' => __( 'Sidebar ID', 'off-canvas-sidebars' ), - 'value' => '', - 'values' => $sidebars, - 'tooltip' => __( '(Required) The off-canvas sidebar ID', 'off-canvas-sidebars' ), - ), - 'text' => array( - 'type' => 'textbox', - 'name' => 'text', - 'label' => __( 'Text', 'off-canvas-sidebars' ), - 'value' => '', - 'tooltip' => __( 'Limited HTML allowed', 'off-canvas-sidebars' ), - 'multiline' => true, - ), - 'optional_container' => array( - 'type' => 'container', - 'html' => '' . __( 'Optional options', 'off-canvas-sidebars' ) . ':', - ), - 'action' => array( - 'type' => 'listbox', - 'name' => 'action', - 'label' => __( 'Trigger action', 'off-canvas-sidebars' ), - 'value' => '', - 'values' => array( - array( - 'text' => __( 'Toggle', 'off-canvas-sidebars' ) . ' (' . __( 'Default', 'off-canvas-sidebars' ) . ')', - 'value' => '', - ), - array( 'text' => __( 'Open', 'off-canvas-sidebars' ), 'value' => 'open' ), - array( 'text' => __( 'Close', 'off-canvas-sidebars' ), 'value' => 'close' ), - ), - //'tooltip' => __( 'The trigger action. Default: toggle', 'off-canvas-sidebars' ), - ), - 'element' => array( - 'type' => 'listbox', - 'name' => 'element', - 'label' => __( 'HTML element', 'off-canvas-sidebars' ), - 'value' => '', - 'values' => $element_values, - 'tooltip' => __( 'Choose wisely', 'off-canvas-sidebars' ), - ), - 'class' => array( - 'type' => 'textbox', - 'name' => 'class', - 'label' => __( 'Extra classes', 'off-canvas-sidebars' ), - 'value' => '', - 'tooltip' => __( 'Separate multiple classes with a space', 'off-canvas-sidebars' ), - ), - 'attr' => array( - 'type' => 'textbox', - 'name' => 'attr', - 'label' => __( 'Custom attributes', 'off-canvas-sidebars' ), - 'value' => '', - 'tooltip' => __( 'key : value ; key : value', 'off-canvas-sidebars' ), - 'multiline' => true, - ), - 'nested' => array( - 'type' => 'checkbox', - 'name' => 'nested', - 'label' => __( 'Nested shortcode', 'off-canvas-sidebars' ) . '?', - 'value' => '', - 'tooltip' => __( '[ocs_trigger text="Your text"] or [ocs_trigger]Your text[/ocs_trigger]', 'off-canvas-sidebars' ), - ), + $elements = array( 'button', 'span', 'a', 'b', 'strong', 'i', 'em', 'img', 'div' ); + $element_values = array(); + foreach ( $elements as $e ) { + $element_values[] = array( + 'text' => '<' . $e . '>', + 'value' => $e, ); + } + $fields = array( + 'id' => array( + 'type' => 'listbox', + 'name' => 'id', + 'label' => __( 'Sidebar ID', 'off-canvas-sidebars' ), + 'value' => '', + 'values' => $sidebars, + 'tooltip' => __( '(Required) The off-canvas sidebar ID', 'off-canvas-sidebars' ), + ), + 'text' => array( + 'type' => 'textbox', + 'name' => 'text', + 'label' => __( 'Text', 'off-canvas-sidebars' ), + 'value' => '', + 'tooltip' => __( 'Limited HTML allowed', 'off-canvas-sidebars' ), + 'multiline' => true, + ), + 'optional_container' => array( + 'type' => 'container', + 'html' => '' . __( 'Optional options', 'off-canvas-sidebars' ) . ':', + ), + 'action' => array( + 'type' => 'listbox', + 'name' => 'action', + 'label' => __( 'Trigger action', 'off-canvas-sidebars' ), + 'value' => '', + 'values' => array( + array( + 'text' => __( 'Toggle', 'off-canvas-sidebars' ) . ' (' . __( 'Default', 'off-canvas-sidebars' ) . ')', + 'value' => '', + ), + array( + 'text' => __( 'Open', 'off-canvas-sidebars' ), + 'value' => 'open', + ), + array( + 'text' => __( 'Close', 'off-canvas-sidebars' ), + 'value' => 'close', + ), + ), + //'tooltip' => __( 'The trigger action. Default: toggle', 'off-canvas-sidebars' ), + ), + 'element' => array( + 'type' => 'listbox', + 'name' => 'element', + 'label' => __( 'HTML element', 'off-canvas-sidebars' ), + 'value' => '', + 'values' => $element_values, + 'tooltip' => __( 'Choose wisely', 'off-canvas-sidebars' ), + ), + 'class' => array( + 'type' => 'textbox', + 'name' => 'class', + 'label' => __( 'Extra classes', 'off-canvas-sidebars' ), + 'value' => '', + 'tooltip' => __( 'Separate multiple classes with a space', 'off-canvas-sidebars' ), + ), + 'attr' => array( + 'type' => 'textbox', + 'name' => 'attr', + 'label' => __( 'Custom attributes', 'off-canvas-sidebars' ), + 'value' => '', + 'tooltip' => __( 'key : value ; key : value', 'off-canvas-sidebars' ), + 'multiline' => true, + ), + 'nested' => array( + 'type' => 'checkbox', + 'name' => 'nested', + 'label' => __( 'Nested shortcode', 'off-canvas-sidebars' ) . '?', + 'value' => '', + 'tooltip' => __( '[ocs_trigger text="Your text"] or [ocs_trigger]Your text[/ocs_trigger]', 'off-canvas-sidebars' ), + ), + ); ?> * @package off-canvas-sidebars * @version 0.4 diff --git a/includes/class-frontend.php b/includes/class-frontend.php index 0bd2a74..c3b8f79 100644 --- a/includes/class-frontend.php +++ b/includes/class-frontend.php @@ -2,7 +2,6 @@ /** * Off-Canvas Sidebars plugin front-end * - * Front-end * @author Jory Hogeveen * @package off-canvas-sidebars * @version 0.4 diff --git a/includes/class-menu-meta-box.php b/includes/class-menu-meta-box.php index 5307812..88569ce 100644 --- a/includes/class-menu-meta-box.php +++ b/includes/class-menu-meta-box.php @@ -2,7 +2,6 @@ /** * Off-Canvas Sidebars menu meta box * - * Menu Meta Box * @author Jory Hogeveen * @package off-canvas-sidebars * @version 0.4 @@ -24,6 +23,8 @@ final class OCS_Off_Canvas_Sidebars_Menu_Meta_Box */ protected static $_instance = null; + protected $meta_key = '_off_canvas_control_menu_item'; + private $general_key = ''; private $plugin_key = ''; //private $plugin_tabs = array(); @@ -52,11 +53,11 @@ private function __construct() { * Get plugin defaults */ function load_plugin_data() { - $off_canvas_sidebars = off_canvas_sidebars(); - $this->settings = $off_canvas_sidebars->get_settings(); + $off_canvas_sidebars = off_canvas_sidebars(); + $this->settings = $off_canvas_sidebars->get_settings(); $this->general_labels = $off_canvas_sidebars->get_general_labels(); - $this->general_key = $off_canvas_sidebars->get_general_key(); - $this->plugin_key = $off_canvas_sidebars->get_plugin_key(); + $this->general_key = $off_canvas_sidebars->get_general_key(); + $this->plugin_key = $off_canvas_sidebars->get_plugin_key(); foreach ( $this->link_classes as $key => $class ) { $this->link_classes[ $key ] = $this->settings['css_prefix'] . $class; @@ -64,7 +65,14 @@ function load_plugin_data() { } function add_meta_box() { - add_meta_box( $this->plugin_key . '-meta-box', __( 'Off-Canvas Control', 'off-canvas-sidebars' ), array( $this, 'meta_box' ), 'nav-menus', 'side', 'low' ); + add_meta_box( + $this->plugin_key . '-meta-box', + esc_html__( 'Off-Canvas Control', 'off-canvas-sidebars' ), + array( $this, 'meta_box' ), + 'nav-menus', + 'side', + 'low' + ); } function meta_box() { @@ -145,13 +153,13 @@ public function admin_enqueue_scripts() { 'nopaging' => true, 'post_type' => 'nav_menu_item', 'fields' => 'ids', - 'meta_key' => '_off_canvas_control_menu_item', + 'meta_key' => $this->meta_key, ) ); // the options values for the triggers. $data['val'] = array(); foreach ( $items as $item ) - $data['val'][ $item ] = get_post_meta( $item, '_off_canvas_control_menu_item', true ); + $data['val'][ $item ] = get_post_meta( $item, $this->meta_key, true ); // send all these data to javascript wp_localize_script( 'off_canvas_control_nav_menu', 'ocsNavControl', $data ); @@ -196,8 +204,8 @@ public function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0 ) { if ( empty( $_POST['menu-item-off-canvas-control-detect'][ $menu_item_db_id ] ) ) { // Our options were never saved. - if ( ! get_post_meta( $menu_item_db_id, '_off_canvas_control_menu_item', true ) ) { - update_post_meta( $menu_item_db_id, '_off_canvas_control_menu_item', $options ); + if ( ! get_post_meta( $menu_item_db_id, $this->meta_key, true ) ) { + update_post_meta( $menu_item_db_id, $this->meta_key, $options ); } } else { @@ -212,7 +220,7 @@ public function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0 ) { } // Allow us to easily identify our nav menu item. - update_post_meta( $menu_item_db_id, '_off_canvas_control_menu_item', $options ); + update_post_meta( $menu_item_db_id, $this->meta_key, $options ); } } @@ -233,7 +241,7 @@ public function wp_get_nav_menu_items( $items ) { } foreach ( $items as $key => $item ) { - $options = get_post_meta( $item->ID, '_off_canvas_control_menu_item', true ); + $options = get_post_meta( $item->ID, $this->meta_key, true ); if ( ! $options ) { continue; } @@ -244,7 +252,7 @@ public function wp_get_nav_menu_items( $items ) { $link_classes = $this->link_classes; if ( ! is_array( $link_classes ) ) { - $link_classes = explode( ' ', $link_classes ); + $link_classes = explode( ' ', (string) $link_classes ); } if ( ! empty( $options['off-canvas-control'] ) ) { diff --git a/includes/class-settings.php b/includes/class-settings.php index ea67b63..7dc4101 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -2,7 +2,6 @@ /** * Off-Canvas Sidebars plugin settings * - * Settings * @author Jory Hogeveen * @package off-canvas-sidebars * @version 0.4 diff --git a/widgets/control-widget.php b/widgets/control-widget.php index a2739b0..1d67364 100644 --- a/widgets/control-widget.php +++ b/widgets/control-widget.php @@ -2,7 +2,6 @@ /** * Off-Canvas Sidebars control widget * - * Control Widget * @author Jory Hogeveen * @package off-canvas-slidebars * @version 0.4 @@ -22,7 +21,6 @@ final class OCS_Off_Canvas_Sidebars_Control_Widget extends WP_Widget * Sets up the widgets name etc */ public function __construct() { - // widget actual processes parent::__construct( 'Off-Canvas-Control', __( 'Off-Canvas Control', 'off-canvas-sidebars' ), @@ -31,12 +29,11 @@ public function __construct() { 'description' => __( 'Button to trigger off-canvas sidebars', 'off-canvas-sidebars' ), ) ); - $this->load_plugin_data(); } /** - * Get plugin defaults + * Get plugin defaults. */ function load_plugin_data() { $off_canvas_sidebars = off_canvas_sidebars(); @@ -47,10 +44,10 @@ function load_plugin_data() { } /** - * Outputs the content of the widget + * Outputs the content of the widget. * - * @param array $args - * @param array $instance + * @param array $args + * @param array $instance */ public function widget( $args, $instance ) { @@ -58,7 +55,6 @@ public function widget( $args, $instance ) { $instance = $this->merge_settings( $instance ); $prefix = $this->settings['css_prefix']; - // outputs the content of the widget echo $args['before_widget']; echo '
    '; @@ -103,14 +99,14 @@ public function widget( $args, $instance ) { } /** - * Outputs the options form on admin + * Outputs the options form on admin. * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @todo Refactor to enable above checks? * - * @param array $instance The widget options + * @param array $instance The widget options. * @return void */ public function form( $instance ) { @@ -120,6 +116,7 @@ public function form( $instance ) { $ocs = $instance[ $this->widget_setting ]; $field_id = $this->get_field_id( $this->widget_setting ); + $field_name = $this->get_field_name( $this->widget_setting ); ?>

    :
    @@ -131,7 +128,7 @@ public function form( $instance ) { ?> @@ -139,7 +136,7 @@ public function form( $instance ) {

    is_sidebar_enabled() ) { echo '

    ' . $this->general_labels['no_sidebars_available'] . '

    '; } else { @@ -181,32 +178,31 @@ public function form( $instance ) { if ( empty( $this->settings['sidebars'][ $sidebar_id ]['enable'] ) ) { continue; } - //$hidden = ''; - //if ( empty( $ocs[ $sidebar_id ]['enable'] ) ) { - $hidden = 'style="display:none;"'; - //} + $hidden = 'style="display:none;"'; + $field_sidebar_id = $field_id . '_' . $sidebar_id; + $field_sidebar_name = $field_name . '[' . $sidebar_id . ']'; ?> -
    > +
    >

    - > - + > +

    -

    > - - +

    > + +

    - > - + > +

    -

    > - - +

    > + +

    - > -

    - + tab === $this->importexport_tab ) { + $form_action = 'themes.php?page=' . $this->plugin_key . '&tab=' . $this->importexport_tab; + } + ?> + + @@ -1195,10 +1203,15 @@ private function shortcode_tab() { * @since 0.1 */ private function importexport_tab() { + $export_link = add_query_arg( 'action', 'export' ); ?>

    -

    +

    + + + +

    @@ -1212,45 +1225,57 @@ private function importexport_tab() { * Import/Export handler. * @since 0.1 */ - public function register_importexport_settings() { + public function maybe_importexport_settings() { + static $done; + if ( $done ) { + return; + } + $done = true; + + // @codingStandardsIgnoreLine + $get = $_GET; $post = $_POST; + $this->plugin_tabs[ $this->importexport_tab ] = esc_attr__( 'Import/Export', 'off-canvas-sidebars' ); /** - * Filter documented in $this->load_plugin_data(). + * Check if it is the correct page. + * Capability filter documented in $this->load_plugin_data(). */ - if ( ! current_user_can( $this->capability ) || $this->tab !== $this->importexport_tab ) { + if ( ! current_user_can( $this->capability ) || + ! isset( $get['page'] ) || $this->plugin_key !== $get['page'] || + $this->tab !== $this->importexport_tab ) { return; } - // @codingStandardsIgnoreLine - if ( isset( $_GET['gocs_message'] ) ) { + if ( isset( $get['ocs_import_result'] ) ) { - $gocs_message_class = ''; - $gocs_message = ''; + $result_class = ''; + $ocs_import_result = ''; - // @codingStandardsIgnoreLine - switch ( $_GET['gocs_message'] ) { + switch ( $get['ocs_import_result'] ) { case 1: - $gocs_message_class = 'updated'; - $gocs_message = esc_attr__( 'Settings Imported', 'off-canvas-sidebars' ); + $result_class = 'updated'; + $ocs_import_result = esc_attr__( 'Settings Imported', 'off-canvas-sidebars' ); break; case 2: - $gocs_message_class = 'error'; - $gocs_message = esc_attr__( 'Invalid Settings File', 'off-canvas-sidebars' ); + $result_class = 'error'; + $ocs_import_result = esc_attr__( 'Invalid Settings File', 'off-canvas-sidebars' ); break; case 3: - $gocs_message_class = 'error'; - $gocs_message = esc_attr__( 'No Settings File Selected', 'off-canvas-sidebars' ); + $result_class = 'error'; + $ocs_import_result = esc_attr__( 'No Settings File Selected', 'off-canvas-sidebars' ); break; } - if ( ! empty( $gocs_message ) ) { - echo '

    ' . esc_html( $gocs_message ) . '

    '; + if ( ! empty( $ocs_import_result ) ) { + echo '

    ' . esc_html( $ocs_import_result ) . '

    '; } + + return; } - // @codingStandardsIgnoreLine - export settings. - if ( isset( $_GET[ $this->plugin_key . '-export' ] ) ) { + // Export settings. + if ( ! empty( $get['action'] ) && 'export' === $get['action'] ) { header( "Content-Disposition: attachment; filename=" . $this->plugin_key . ".txt" ); header( 'Content-Type: text/plain; charset=utf-8' ); $general = $this->settings; @@ -1259,11 +1284,11 @@ public function register_importexport_settings() { foreach ( $general as $id => $text ) echo "$id\t" . wp_json_encode( $text ) . "\n"; echo "[STOP=OCS SETTINGS]"; - exit; + die(); } - // @codingStandardsIgnoreLine - import settings. - if ( isset( $_POST[ $this->plugin_key . '-import' ] ) ) { + // Import settings. + if ( ! empty( $post[ $this->plugin_key . '-import' ] ) && ! empty( $_FILES[ $this->plugin_key . '-import-file' ] ) ) { if ( $_FILES[ $this->plugin_key . '-import-file' ]['tmp_name'] ) { @@ -1274,7 +1299,7 @@ public function register_importexport_settings() { $settings = array(); foreach ( $import as $import_option ) { list( $key, $value ) = explode( "\t", $import_option ); - $settings[ $key ] = json_decode( sanitize_text_field( $value ), true ); + $settings[ $key ] = json_decode( $value, true ); } // Validate global settings. @@ -1287,18 +1312,21 @@ public function register_importexport_settings() { } } + $settings = array_merge( off_canvas_sidebars()->get_settings(), $settings ); + update_option( $this->general_key, $settings ); - $gocs_message = 1; + $ocs_import_result = 1; } else { - $gocs_message = 2; + $ocs_import_result = 2; } } else { - $gocs_message = 3; + $ocs_import_result = 3; } - wp_redirect( admin_url( '/themes.php?page=' . $this->plugin_key . '&tab=' . $this->importexport_tab . '&gocs_message=' . esc_attr( $gocs_message ) ) ); - exit; + wp_redirect( admin_url( '/themes.php?page=' . $this->plugin_key . '&tab=' . $this->importexport_tab . '&ocs_import_result=' . esc_attr( $ocs_import_result ) ) ); + die(); } // End if(). + } /** From 6c7d18a7abec382ebfae9b27bdb62703e442ddb4 Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Thu, 31 Aug 2017 04:44:50 +0200 Subject: [PATCH 117/124] 0.4-rc2 --- off-canvas-sidebars.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/off-canvas-sidebars.php b/off-canvas-sidebars.php index 8d4fad7..6c8ea0a 100644 --- a/off-canvas-sidebars.php +++ b/off-canvas-sidebars.php @@ -3,7 +3,7 @@ * @author Jory Hogeveen * @package Off_Canvas_Sidebars * @since 0.1 - * @version 0.4-rc1 + * @version 0.4-rc2 * @licence GPL-2.0+ * @link https://github.com/JoryHogeveen/off-canvas-sidebars * @@ -11,7 +11,7 @@ * Plugin Name: Off-Canvas Sidebars * Description: Add off-canvas sidebars using the Slidebars jQuery plugin * Plugin URI: https://wordpress.org/plugins/off-canvas-sidebars/ - * Version: 0.4-rc1 + * Version: 0.4-rc2 * Author: Jory Hogeveen * Author URI: http://www.keraweb.nl * Text Domain: off-canvas-sidebars @@ -42,7 +42,7 @@ die(); } -define( 'OCS_PLUGIN_VERSION', '0.4-rc1' ); +define( 'OCS_PLUGIN_VERSION', '0.4-rc2' ); define( 'OCS_FILE', __FILE__ ); define( 'OCS_BASENAME', plugin_basename( OCS_FILE ) ); define( 'OCS_PLUGIN_DIR', plugin_dir_path( OCS_FILE ) ); @@ -293,7 +293,7 @@ function compatibility_notice() { * AJAX handler. * Stores plugin version. * - * Store format: boolean + * Store format: `boolean` * * @since 0.1 */ @@ -311,9 +311,9 @@ function ignore_compatibility_notice() { function get_settings() { $settings = $this->settings; - // Validate global settings + // Validate global settings. $settings = $this->validate_settings( $settings, $this->get_default_settings() ); - // Validate sidebar settings + // Validate sidebar settings. foreach ( $settings['sidebars'] as $sidebar_id => $sidebar_settings ) { $settings['sidebars'][ $sidebar_id ] = $this->validate_settings( $sidebar_settings, $this->get_default_sidebar_settings() ); } @@ -662,8 +662,8 @@ public function __wakeup() { * * @since 0.3 * @access public - * @param string - * @param array + * @param string $method + * @param array $args * @return null */ public function __call( $method = '', $args = array() ) { @@ -676,7 +676,7 @@ public function __call( $method = '', $args = array() ) { return null; } -} // end class +} // End class(). /** * Main instance of Off-Canvas Sidebars. From e6e82ce2d7bbafdba16e7833305c881dd5c04510 Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Wed, 6 Sep 2017 01:54:49 +0200 Subject: [PATCH 118/124] Fix overlay issues with shift and reveal on pages not that don't have full height, currently done in JS window resize --- css/off-canvas-sidebars.css | 1 + js/off-canvas-sidebars.js | 24 ++++++++++++++++-------- js/off-canvas-sidebars.min.js | 2 +- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/css/off-canvas-sidebars.css b/css/off-canvas-sidebars.css index f3e5a1d..2d6d135 100644 --- a/css/off-canvas-sidebars.css +++ b/css/off-canvas-sidebars.css @@ -11,6 +11,7 @@ * Slidebar CSS overwrites */ +/* @fixme Fix overlay issues with shift and reveal on pages not that don't have full height, currently done in JS window resize. */ html, html.ocs-initialized { overflow-y: auto; diff --git a/js/off-canvas-sidebars.js b/js/off-canvas-sidebars.js index ac3ccbe..ec2c5e5 100644 --- a/js/off-canvas-sidebars.js +++ b/js/off-canvas-sidebars.js @@ -25,12 +25,12 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { var $document = $(document); var $window = $(window); + var $html = $('html'); var $body = $('body'); ocsOffCanvasSidebars.slidebarsController = false; ocsOffCanvasSidebars.useAttributeSettings = false; ocsOffCanvasSidebars.container = false; - ocsOffCanvasSidebars._html = $( 'html' ); ocsOffCanvasSidebars._touchmove = false; ocsOffCanvasSidebars._toolbar = $body.hasClass('admin-bar'); @@ -162,13 +162,13 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { // Legacy CSS mode? if ( ocsOffCanvasSidebars.legacy_css ) { ocsOffCanvasSidebars.slidebarsController.legacy = true; - ocsOffCanvasSidebars._html.addClass('ocs-legacy'); + $html.addClass('ocs-legacy'); } // Initialize slidebars. ocsOffCanvasSidebars.slidebarsController.init(); - ocsOffCanvasSidebars._html.addClass('ocs-initialized'); + $html.addClass('ocs-initialized'); $window.trigger( 'ocs_initialized', this ); @@ -395,16 +395,16 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { // Add close class to canvas container when Slidebar is opened. $( controller.events ).on( 'opening', function () { $( '[canvas]' ).addClass( prefix + '-close-any' ); - ocsOffCanvasSidebars._html.addClass( 'ocs-sidebar-active' ); + $html.addClass( 'ocs-sidebar-active' ); if ( ocsOffCanvasSidebars._getSetting( 'scroll_lock', false ) ) { - ocsOffCanvasSidebars._html.addClass( 'ocs-scroll-lock' ); + $html.addClass( 'ocs-scroll-lock' ); } } ); // Add close class to canvas container when Slidebar is opened. $( controller.events ).on( 'closing', function () { $( '[canvas]' ).removeClass( prefix + '-close-any' ); - ocsOffCanvasSidebars._html.removeClass( 'ocs-sidebar-active ocs-scroll-lock' ); + $html.removeClass( 'ocs-sidebar-active ocs-scroll-lock' ); } ); // Disable slidebars when the window is wider than the set width. @@ -433,7 +433,7 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { // Disable scrolling outside of active sidebar. $( '#' + prefix + '-site' ).on( 'scroll touchmove mousewheel DOMMouseScroll', function( e ) { //if ( ocsOffCanvasSidebars._getSetting( 'scroll_lock' ) && false != controller.getActiveSlidebar() ) { - if ( ocsOffCanvasSidebars._html.hasClass( 'ocs-scroll-lock' ) ) { + if ( $html.hasClass( 'ocs-scroll-lock' ) ) { e.preventDefault(); e.stopPropagation(); return false; @@ -443,7 +443,7 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { // Disable scrolling site when scrolling inside active sidebar. sidebarElements.on( 'scroll touchmove mousewheel DOMMouseScroll', function( e ) { //if ( ocsOffCanvasSidebars._getSetting( 'scroll_lock', false ) ) { - if ( ocsOffCanvasSidebars._html.hasClass( 'ocs-scroll-lock' ) ) { + if ( $html.hasClass( 'ocs-scroll-lock' ) ) { var $this = $(this); if ( 0 > e.originalEvent.deltaY ) { // scrolling up. @@ -455,6 +455,14 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { } } ); + /** + * @fixme Fix for reveal and shift styles when page does not have enough height. + * @since 0.4 + */ + $window.on( 'resize', function() { + ocsOffCanvasSidebars.container.css( 'min-height', $window.innerHeight() - parseInt( $html.css('margin-top'), 10 ) ); + } ).trigger( 'resize' ); + }; /** diff --git a/js/off-canvas-sidebars.min.js b/js/off-canvas-sidebars.min.js index ff4ff9a..b3645ee 100644 --- a/js/off-canvas-sidebars.min.js +++ b/js/off-canvas-sidebars.min.js @@ -7,4 +7,4 @@ * @global ocsOffCanvasSidebars * @preserve */ -if("undefined"===typeof ocsOffCanvasSidebars){var ocsOffCanvasSidebars={site_close:true,disable_over:false,hide_control_classes:false,scroll_lock:false,legacy_css:false,fixed_elements:"",css_prefix:"ocs",sidebars:{},_debug:false}}(function($){var $document=$(document);var $window=$(window);var $body=$("body");ocsOffCanvasSidebars.slidebarsController=false;ocsOffCanvasSidebars.useAttributeSettings=false;ocsOffCanvasSidebars.container=false;ocsOffCanvasSidebars._html=$("html");ocsOffCanvasSidebars._touchmove=false;ocsOffCanvasSidebars._toolbar=$body.hasClass("admin-bar");ocsOffCanvasSidebars.init=function(){if(ocsOffCanvasSidebars.fixed_elements){$(ocsOffCanvasSidebars.fixed_elements).each(function(){var $this=$(this);if(!$this.parents("[canvas]")){$this.attr("canvas",1)}else{$this.attr("canvas-inner",1)}})}ocsOffCanvasSidebars._checkDisableOver=function(sidebarId){var check=true;var disableOver=parseInt(ocsOffCanvasSidebars._getSetting("disable_over",sidebarId));if(disableOver&&!isNaN(disableOver)){if($window.width()>disableOver){check=false}}return check};ocsOffCanvasSidebars._getSetting=function(key,sidebarId){var overwrite,setting;var prefix=ocsOffCanvasSidebars.css_prefix;if("undefined"!==typeof sidebarId){if(!sidebarId&&null!==sidebarId){sidebarId=ocsOffCanvasSidebars.slidebarsController.getActiveSlidebar()}}if(sidebarId){if(!$.isEmptyObject(ocsOffCanvasSidebars.sidebars)&&!ocsOffCanvasSidebars.useAttributeSettings){sidebarId=sidebarId.replace(prefix+"-","");if(ocsOffCanvasSidebars.sidebars[sidebarId].overwrite_global_settings){setting=ocsOffCanvasSidebars.sidebars[sidebarId][key];if(setting){return setting}else{return false}}}else{var sidebarElement=$("#"+sidebarId);overwrite=sidebarElement.attr("ocs-overwrite_global_settings");if(overwrite){setting=sidebarElement.attr("ocs-"+key);if("undefined"!==typeof setting){return setting}else{return false}}}}if(ocsOffCanvasSidebars.hasOwnProperty(key)&&!ocsOffCanvasSidebars.useAttributeSettings){return ocsOffCanvasSidebars[key]}else{setting=$("#"+prefix+"-site").attr("ocs-"+key);if("undefined"!==typeof setting){return setting}}return false};ocsOffCanvasSidebars._getTranslateAxis=function(obj,axis){obj=$(obj);var transformMatrix=obj.css("-webkit-transform")||obj.css("-moz-transform")||obj.css("-ms-transform")||obj.css("-o-transform")||obj.css("transform");if(transformMatrix){var matrix=transformMatrix.replace(/[^0-9\-.,]/g,"").split(",");var val=false;switch(axis){case"x":val=matrix[12]||matrix[4];break;case"y":val=matrix[13]||matrix[5];break;case"z":val=matrix[14]||matrix[6];break}return parseFloat(val)}else{return 0}};ocsOffCanvasSidebars.container=$("[canvas=container]");$window.trigger("ocs_loaded",this);ocsOffCanvasSidebars.slidebarsController=new slidebars;if(false===ocsOffCanvasSidebars.slidebarsController){return}if(ocsOffCanvasSidebars.legacy_css){ocsOffCanvasSidebars.slidebarsController.legacy=true;ocsOffCanvasSidebars._html.addClass("ocs-legacy")}ocsOffCanvasSidebars.slidebarsController.init();ocsOffCanvasSidebars._html.addClass("ocs-initialized");$window.trigger("ocs_initialized",this);if(ocsOffCanvasSidebars._toolbar){$window.on("load resize",function(){var bodyOffset=$body.offset();$("."+ocsOffCanvasSidebars.css_prefix+"-slidebar").each(function(){if($(this).hasClass("ocs-location-top")){$(this).css("margin-top",parseInt($(this).css("margin-top").replace("px",""))+bodyOffset.top+"px")}else if($(this).hasClass("ocs-location-left")||$(this).hasClass("ocs-location-right")){$(this).css("margin-top",bodyOffset.top+"px")}})})}$(ocsOffCanvasSidebars.slidebarsController.events).on("opening opened closing closed",function(e,sidebar_id){var slidebar=ocsOffCanvasSidebars.slidebarsController.getSlidebar(sidebar_id);var duration=parseFloat(slidebar.element.css("transitionDuration"))*1e3;if("top"===slidebar.side||"bottom"===slidebar.side){var elements=ocsOffCanvasSidebars.getFixedElements();elements.attr({"canvas-fixed":"fixed"});if(ocsOffCanvasSidebars.legacy_css&&"top"===slidebar.side&&("overlay"!==slidebar.style&&"reveal"!==slidebar.style)){var offset;offset=parseInt(slidebar.element.css("margin-top").replace("px","").replace("-",""));if(ocsOffCanvasSidebars._toolbar){var bodyOffset=$body.offset();offset+=bodyOffset.top}elements.each(function(){var $this=$(this);if("opening"===e.type){ocsOffCanvasSidebars.cssCompat($this,"transition","top "+duration+"ms");$this.css("top",parseInt($this.css("top").replace("px",""))+offset+"px")}else if("closing"===e.type){$this.css("top",parseInt($this.css("top").replace("px",""))-offset+"px");setTimeout(function(){ocsOffCanvasSidebars.cssCompat($this,"transition","")},duration)}})}else{elements.each(function(){var $this=$(this);if("opening"===e.type||"closing"===e.type){ocsOffCanvasSidebars.cssCompat($this,"transition","transform "+duration+"ms")}else if("opened"===e.type||"closed"===e.type){ocsOffCanvasSidebars.cssCompat($this,"transition","")}})}$window.trigger("slidebar_event",[e.type,slidebar])}});$document.on("touchmove",function(){ocsOffCanvasSidebars._touchmove=true});$document.on("touchstart",function(){ocsOffCanvasSidebars._touchmove=false});if("function"===typeof ocsOffCanvasSidebars.setupTriggers){ocsOffCanvasSidebars.setupTriggers()}};ocsOffCanvasSidebars.setSidebarDefaultSettings=function(sidebarId){if("undefined"===typeof ocsOffCanvasSidebars.sidebars[sidebarId]){ocsOffCanvasSidebars.sidebars[sidebarId]={overwrite_global_settings:false,site_close:ocsOffCanvasSidebars.site_close,disable_over:ocsOffCanvasSidebars.disable_over,hide_control_classes:ocsOffCanvasSidebars.hide_control_classes,scroll_lock:ocsOffCanvasSidebars.scroll_lock}}};ocsOffCanvasSidebars.setupTriggers=function(){var controller=ocsOffCanvasSidebars.slidebarsController,prefix=ocsOffCanvasSidebars.css_prefix,sidebarElements=$("."+prefix+"-slidebar");sidebarElements.each(function(){var id=$(this).attr("ocs-sidebar-id");ocsOffCanvasSidebars.setSidebarDefaultSettings(id);$document.on("touchend click","."+prefix+"-toggle-"+id,function(e){e.stopPropagation();e.preventDefault();if(true===ocsOffCanvasSidebars._touchmove){return}if(ocsOffCanvasSidebars._checkDisableOver(prefix+"-"+id)){controller.toggle(prefix+"-"+id)}});$document.on("touchend click","."+prefix+"-open-"+id,function(e){e.stopPropagation();e.preventDefault();if(true===ocsOffCanvasSidebars._touchmove){return}if(ocsOffCanvasSidebars._checkDisableOver(prefix+"-"+id)){controller.open(prefix+"-"+id)}});$document.on("touchend click","."+prefix+"-close-"+id,function(e){e.stopPropagation();e.preventDefault();if(true===ocsOffCanvasSidebars._touchmove){return}controller.close(prefix+"-"+id)})});$document.on("touchend click","."+prefix+"-close-any",function(e){if(ocsOffCanvasSidebars._getSetting("site_close",false)){e.preventDefault();e.stopPropagation();controller.close()}});$("a").not("."+prefix+"-trigger").on("touchend click",function(){if(!$(this).parents("."+prefix+"-trigger").length){controller.close()}});$(controller.events).on("opening",function(){$("[canvas]").addClass(prefix+"-close-any");ocsOffCanvasSidebars._html.addClass("ocs-sidebar-active");if(ocsOffCanvasSidebars._getSetting("scroll_lock",false)){ocsOffCanvasSidebars._html.addClass("ocs-scroll-lock")}});$(controller.events).on("closing",function(){$("[canvas]").removeClass(prefix+"-close-any");ocsOffCanvasSidebars._html.removeClass("ocs-sidebar-active ocs-scroll-lock")});var disableOver=function(){var prefix=ocsOffCanvasSidebars.css_prefix;sidebarElements.each(function(){var id=$(this).attr("ocs-sidebar-id");if(!ocsOffCanvasSidebars._checkDisableOver(prefix+"-"+id)){if(controller.isActiveSlidebar(prefix+"-"+id)){controller.close()}if(ocsOffCanvasSidebars._getSetting("hide_control_classes",prefix+"-"+id)){$("."+prefix+"-toggle-"+id).hide()}}else{$("."+prefix+"-toggle-"+id).show()}})};disableOver();$window.on("resize",disableOver);$("#"+prefix+"-site").on("scroll touchmove mousewheel DOMMouseScroll",function(e){if(ocsOffCanvasSidebars._html.hasClass("ocs-scroll-lock")){e.preventDefault();e.stopPropagation();return false}});sidebarElements.on("scroll touchmove mousewheel DOMMouseScroll",function(e){if(ocsOffCanvasSidebars._html.hasClass("ocs-scroll-lock")){var $this=$(this);if(0>e.originalEvent.deltaY){return 0<$this.scrollTop()}else{return $this.scrollTop()+$this.innerHeight()<$this[0].scrollHeight}}})};ocsOffCanvasSidebars.getFixedElements=function(){return $("#"+ocsOffCanvasSidebars.css_prefix+"-site *").filter(function(){return"fixed"===$(this).css("position")})};ocsOffCanvasSidebars.cssCompat=function(elem,prop,value){var data={};data["-webkit-"+prop]=value;data["-moz-"+prop]=value;data["-o-"+prop]=value;data[prop]=value;$(elem).css(data)};if($("#"+ocsOffCanvasSidebars.css_prefix+"-site").length&&"undefined"!==typeof slidebars){ocsOffCanvasSidebars.init()}})(jQuery); \ No newline at end of file +if("undefined"===typeof ocsOffCanvasSidebars){var ocsOffCanvasSidebars={site_close:true,disable_over:false,hide_control_classes:false,scroll_lock:false,legacy_css:false,fixed_elements:"",css_prefix:"ocs",sidebars:{},_debug:false}}(function($){var $document=$(document);var $window=$(window);var $html=$("html");var $body=$("body");ocsOffCanvasSidebars.slidebarsController=false;ocsOffCanvasSidebars.useAttributeSettings=false;ocsOffCanvasSidebars.container=false;ocsOffCanvasSidebars._touchmove=false;ocsOffCanvasSidebars._toolbar=$body.hasClass("admin-bar");ocsOffCanvasSidebars.init=function(){if(ocsOffCanvasSidebars.fixed_elements){$(ocsOffCanvasSidebars.fixed_elements).each(function(){var $this=$(this);if(!$this.parents("[canvas]")){$this.attr("canvas",1)}else{$this.attr("canvas-inner",1)}})}ocsOffCanvasSidebars._checkDisableOver=function(sidebarId){var check=true;var disableOver=parseInt(ocsOffCanvasSidebars._getSetting("disable_over",sidebarId));if(disableOver&&!isNaN(disableOver)){if($window.width()>disableOver){check=false}}return check};ocsOffCanvasSidebars._getSetting=function(key,sidebarId){var overwrite,setting;var prefix=ocsOffCanvasSidebars.css_prefix;if("undefined"!==typeof sidebarId){if(!sidebarId&&null!==sidebarId){sidebarId=ocsOffCanvasSidebars.slidebarsController.getActiveSlidebar()}}if(sidebarId){if(!$.isEmptyObject(ocsOffCanvasSidebars.sidebars)&&!ocsOffCanvasSidebars.useAttributeSettings){sidebarId=sidebarId.replace(prefix+"-","");if(ocsOffCanvasSidebars.sidebars[sidebarId].overwrite_global_settings){setting=ocsOffCanvasSidebars.sidebars[sidebarId][key];if(setting){return setting}else{return false}}}else{var sidebarElement=$("#"+sidebarId);overwrite=sidebarElement.attr("ocs-overwrite_global_settings");if(overwrite){setting=sidebarElement.attr("ocs-"+key);if("undefined"!==typeof setting){return setting}else{return false}}}}if(ocsOffCanvasSidebars.hasOwnProperty(key)&&!ocsOffCanvasSidebars.useAttributeSettings){return ocsOffCanvasSidebars[key]}else{setting=$("#"+prefix+"-site").attr("ocs-"+key);if("undefined"!==typeof setting){return setting}}return false};ocsOffCanvasSidebars._getTranslateAxis=function(obj,axis){obj=$(obj);var transformMatrix=obj.css("-webkit-transform")||obj.css("-moz-transform")||obj.css("-ms-transform")||obj.css("-o-transform")||obj.css("transform");if(transformMatrix){var matrix=transformMatrix.replace(/[^0-9\-.,]/g,"").split(",");var val=false;switch(axis){case"x":val=matrix[12]||matrix[4];break;case"y":val=matrix[13]||matrix[5];break;case"z":val=matrix[14]||matrix[6];break}return parseFloat(val)}else{return 0}};ocsOffCanvasSidebars.container=$("[canvas=container]");$window.trigger("ocs_loaded",this);ocsOffCanvasSidebars.slidebarsController=new slidebars;if(false===ocsOffCanvasSidebars.slidebarsController){return}if(ocsOffCanvasSidebars.legacy_css){ocsOffCanvasSidebars.slidebarsController.legacy=true;$html.addClass("ocs-legacy")}ocsOffCanvasSidebars.slidebarsController.init();$html.addClass("ocs-initialized");$window.trigger("ocs_initialized",this);if(ocsOffCanvasSidebars._toolbar){$window.on("load resize",function(){var bodyOffset=$body.offset();$("."+ocsOffCanvasSidebars.css_prefix+"-slidebar").each(function(){if($(this).hasClass("ocs-location-top")){$(this).css("margin-top",parseInt($(this).css("margin-top").replace("px",""))+bodyOffset.top+"px")}else if($(this).hasClass("ocs-location-left")||$(this).hasClass("ocs-location-right")){$(this).css("margin-top",bodyOffset.top+"px")}})})}$(ocsOffCanvasSidebars.slidebarsController.events).on("opening opened closing closed",function(e,sidebar_id){var slidebar=ocsOffCanvasSidebars.slidebarsController.getSlidebar(sidebar_id);var duration=parseFloat(slidebar.element.css("transitionDuration"))*1e3;if("top"===slidebar.side||"bottom"===slidebar.side){var elements=ocsOffCanvasSidebars.getFixedElements();elements.attr({"canvas-fixed":"fixed"});if(ocsOffCanvasSidebars.legacy_css&&"top"===slidebar.side&&("overlay"!==slidebar.style&&"reveal"!==slidebar.style)){var offset;offset=parseInt(slidebar.element.css("margin-top").replace("px","").replace("-",""));if(ocsOffCanvasSidebars._toolbar){var bodyOffset=$body.offset();offset+=bodyOffset.top}elements.each(function(){var $this=$(this);if("opening"===e.type){ocsOffCanvasSidebars.cssCompat($this,"transition","top "+duration+"ms");$this.css("top",parseInt($this.css("top").replace("px",""))+offset+"px")}else if("closing"===e.type){$this.css("top",parseInt($this.css("top").replace("px",""))-offset+"px");setTimeout(function(){ocsOffCanvasSidebars.cssCompat($this,"transition","")},duration)}})}else{elements.each(function(){var $this=$(this);if("opening"===e.type||"closing"===e.type){ocsOffCanvasSidebars.cssCompat($this,"transition","transform "+duration+"ms")}else if("opened"===e.type||"closed"===e.type){ocsOffCanvasSidebars.cssCompat($this,"transition","")}})}$window.trigger("slidebar_event",[e.type,slidebar])}});$document.on("touchmove",function(){ocsOffCanvasSidebars._touchmove=true});$document.on("touchstart",function(){ocsOffCanvasSidebars._touchmove=false});if("function"===typeof ocsOffCanvasSidebars.setupTriggers){ocsOffCanvasSidebars.setupTriggers()}};ocsOffCanvasSidebars.setSidebarDefaultSettings=function(sidebarId){if("undefined"===typeof ocsOffCanvasSidebars.sidebars[sidebarId]){ocsOffCanvasSidebars.sidebars[sidebarId]={overwrite_global_settings:false,site_close:ocsOffCanvasSidebars.site_close,disable_over:ocsOffCanvasSidebars.disable_over,hide_control_classes:ocsOffCanvasSidebars.hide_control_classes,scroll_lock:ocsOffCanvasSidebars.scroll_lock}}};ocsOffCanvasSidebars.setupTriggers=function(){var controller=ocsOffCanvasSidebars.slidebarsController,prefix=ocsOffCanvasSidebars.css_prefix,sidebarElements=$("."+prefix+"-slidebar");sidebarElements.each(function(){var id=$(this).attr("ocs-sidebar-id");ocsOffCanvasSidebars.setSidebarDefaultSettings(id);$document.on("touchend click","."+prefix+"-toggle-"+id,function(e){e.stopPropagation();e.preventDefault();if(true===ocsOffCanvasSidebars._touchmove){return}if(ocsOffCanvasSidebars._checkDisableOver(prefix+"-"+id)){controller.toggle(prefix+"-"+id)}});$document.on("touchend click","."+prefix+"-open-"+id,function(e){e.stopPropagation();e.preventDefault();if(true===ocsOffCanvasSidebars._touchmove){return}if(ocsOffCanvasSidebars._checkDisableOver(prefix+"-"+id)){controller.open(prefix+"-"+id)}});$document.on("touchend click","."+prefix+"-close-"+id,function(e){e.stopPropagation();e.preventDefault();if(true===ocsOffCanvasSidebars._touchmove){return}controller.close(prefix+"-"+id)})});$document.on("touchend click","."+prefix+"-close-any",function(e){if(ocsOffCanvasSidebars._getSetting("site_close",false)){e.preventDefault();e.stopPropagation();controller.close()}});$("a").not("."+prefix+"-trigger").on("touchend click",function(){if(!$(this).parents("."+prefix+"-trigger").length){controller.close()}});$(controller.events).on("opening",function(){$("[canvas]").addClass(prefix+"-close-any");$html.addClass("ocs-sidebar-active");if(ocsOffCanvasSidebars._getSetting("scroll_lock",false)){$html.addClass("ocs-scroll-lock")}});$(controller.events).on("closing",function(){$("[canvas]").removeClass(prefix+"-close-any");$html.removeClass("ocs-sidebar-active ocs-scroll-lock")});var disableOver=function(){var prefix=ocsOffCanvasSidebars.css_prefix;sidebarElements.each(function(){var id=$(this).attr("ocs-sidebar-id");if(!ocsOffCanvasSidebars._checkDisableOver(prefix+"-"+id)){if(controller.isActiveSlidebar(prefix+"-"+id)){controller.close()}if(ocsOffCanvasSidebars._getSetting("hide_control_classes",prefix+"-"+id)){$("."+prefix+"-toggle-"+id).hide()}}else{$("."+prefix+"-toggle-"+id).show()}})};disableOver();$window.on("resize",disableOver);$("#"+prefix+"-site").on("scroll touchmove mousewheel DOMMouseScroll",function(e){if($html.hasClass("ocs-scroll-lock")){e.preventDefault();e.stopPropagation();return false}});sidebarElements.on("scroll touchmove mousewheel DOMMouseScroll",function(e){if($html.hasClass("ocs-scroll-lock")){var $this=$(this);if(0>e.originalEvent.deltaY){return 0<$this.scrollTop()}else{return $this.scrollTop()+$this.innerHeight()<$this[0].scrollHeight}}});$window.on("resize",function(){ocsOffCanvasSidebars.container.css("min-height",$window.innerHeight()-parseInt($html.css("margin-top"),10))}).trigger("resize")};ocsOffCanvasSidebars.getFixedElements=function(){return $("#"+ocsOffCanvasSidebars.css_prefix+"-site *").filter(function(){return"fixed"===$(this).css("position")})};ocsOffCanvasSidebars.cssCompat=function(elem,prop,value){var data={};data["-webkit-"+prop]=value;data["-moz-"+prop]=value;data["-o-"+prop]=value;data[prop]=value;$(elem).css(data)};if($("#"+ocsOffCanvasSidebars.css_prefix+"-site").length&&"undefined"!==typeof slidebars){ocsOffCanvasSidebars.init()}})(jQuery); \ No newline at end of file From d28dd939fa1b01bcca99498d3b560b1ceeb78a9d Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Wed, 6 Sep 2017 01:55:01 +0200 Subject: [PATCH 119/124] Min PHP version readme tag --- readme.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.txt b/readme.txt index 2aac0e9..abb4e35 100644 --- a/readme.txt +++ b/readme.txt @@ -4,6 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=YGPLM Tags: genesis, off-canvas, menus, widgets, sidebars, slidebars, jQuery, app, mobile, tablet, responsive Requires at least: 4.1 Tested up to: 4.8 +Requires PHP: 5.2.4 Stable tag: 0.4 Add off-canvas sidebars containing widgets, menus or other content using the Slidebars jQuery plugin. From 0787852d3cec5bfe48caf70b2fef9195bff35ecb Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Wed, 6 Sep 2017 03:25:33 +0200 Subject: [PATCH 120/124] Enhance ocs triggers + codestyle --- js/off-canvas-sidebars.js | 40 +++++++++++++++++++---------------- js/off-canvas-sidebars.min.js | 2 +- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/js/off-canvas-sidebars.js b/js/off-canvas-sidebars.js index ec2c5e5..758a993 100644 --- a/js/off-canvas-sidebars.js +++ b/js/off-canvas-sidebars.js @@ -10,14 +10,14 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { var ocsOffCanvasSidebars = { - "site_close": true, - "disable_over": false, - "hide_control_classes": false, - "scroll_lock": false, - "legacy_css": false, - "css_prefix": 'ocs', - "sidebars": {}, - "_debug": false + site_close: true, + disable_over: false, + hide_control_classes: false, + scroll_lock: false, + legacy_css: false, + css_prefix: 'ocs', + sidebars: {}, + _debug: false }; } @@ -40,8 +40,8 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { * Validate the disable_over setting ( using _getSetting() ). * Internal function, do not overwrite. * @since 0.3 - * @param {string} sidebarId The sidebar ID. - * @return {bool} disableOver status. + * @param {string} sidebarId The sidebar ID. + * @return {boolean} disableOver status. */ ocsOffCanvasSidebars._checkDisableOver = function( sidebarId ) { var check = true; @@ -60,11 +60,11 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { * Internal function, do not overwrite. * * @since 0.3 - * @param {string} key The setting key to look for. - * @param {string|bool|null} sidebarId The sidebar ID. - * Pass `false` to check for an active slidebar. - * Pass `null` or no value for only the global setting. - * @return {string|bool} The setting or false. + * @param {string} key The setting key to look for. + * @param {string|boolean|null} sidebarId The sidebar ID. + * Pass `false` to check for an active slidebar. + * Pass `null` or no value for only the global setting. + * @return {string|boolean} The setting or false. */ ocsOffCanvasSidebars._getSetting = function( key, sidebarId ) { var overwrite, setting; @@ -150,7 +150,7 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { ocsOffCanvasSidebars.container = $( '[canvas=container]' ); - $window.trigger( 'ocs_loaded', this ); + $window.trigger( 'ocs_before', this ); // Slidebars constructor. ocsOffCanvasSidebars.slidebarsController = new slidebars(); @@ -165,6 +165,8 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { $html.addClass('ocs-legacy'); } + $window.trigger( 'ocs_loaded', this ); + // Initialize slidebars. ocsOffCanvasSidebars.slidebarsController.init(); @@ -268,6 +270,8 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { if ( 'function' === typeof ocsOffCanvasSidebars.setupTriggers ) { ocsOffCanvasSidebars.setupTriggers(); } + + $window.trigger( 'ocs_after', this ); }; /** @@ -459,9 +463,9 @@ if ( 'undefined' === typeof ocsOffCanvasSidebars ) { * @fixme Fix for reveal and shift styles when page does not have enough height. * @since 0.4 */ - $window.on( 'resize', function() { + $window.on( 'load resize', function() { ocsOffCanvasSidebars.container.css( 'min-height', $window.innerHeight() - parseInt( $html.css('margin-top'), 10 ) ); - } ).trigger( 'resize' ); + } ); }; diff --git a/js/off-canvas-sidebars.min.js b/js/off-canvas-sidebars.min.js index b3645ee..de3853d 100644 --- a/js/off-canvas-sidebars.min.js +++ b/js/off-canvas-sidebars.min.js @@ -7,4 +7,4 @@ * @global ocsOffCanvasSidebars * @preserve */ -if("undefined"===typeof ocsOffCanvasSidebars){var ocsOffCanvasSidebars={site_close:true,disable_over:false,hide_control_classes:false,scroll_lock:false,legacy_css:false,fixed_elements:"",css_prefix:"ocs",sidebars:{},_debug:false}}(function($){var $document=$(document);var $window=$(window);var $html=$("html");var $body=$("body");ocsOffCanvasSidebars.slidebarsController=false;ocsOffCanvasSidebars.useAttributeSettings=false;ocsOffCanvasSidebars.container=false;ocsOffCanvasSidebars._touchmove=false;ocsOffCanvasSidebars._toolbar=$body.hasClass("admin-bar");ocsOffCanvasSidebars.init=function(){if(ocsOffCanvasSidebars.fixed_elements){$(ocsOffCanvasSidebars.fixed_elements).each(function(){var $this=$(this);if(!$this.parents("[canvas]")){$this.attr("canvas",1)}else{$this.attr("canvas-inner",1)}})}ocsOffCanvasSidebars._checkDisableOver=function(sidebarId){var check=true;var disableOver=parseInt(ocsOffCanvasSidebars._getSetting("disable_over",sidebarId));if(disableOver&&!isNaN(disableOver)){if($window.width()>disableOver){check=false}}return check};ocsOffCanvasSidebars._getSetting=function(key,sidebarId){var overwrite,setting;var prefix=ocsOffCanvasSidebars.css_prefix;if("undefined"!==typeof sidebarId){if(!sidebarId&&null!==sidebarId){sidebarId=ocsOffCanvasSidebars.slidebarsController.getActiveSlidebar()}}if(sidebarId){if(!$.isEmptyObject(ocsOffCanvasSidebars.sidebars)&&!ocsOffCanvasSidebars.useAttributeSettings){sidebarId=sidebarId.replace(prefix+"-","");if(ocsOffCanvasSidebars.sidebars[sidebarId].overwrite_global_settings){setting=ocsOffCanvasSidebars.sidebars[sidebarId][key];if(setting){return setting}else{return false}}}else{var sidebarElement=$("#"+sidebarId);overwrite=sidebarElement.attr("ocs-overwrite_global_settings");if(overwrite){setting=sidebarElement.attr("ocs-"+key);if("undefined"!==typeof setting){return setting}else{return false}}}}if(ocsOffCanvasSidebars.hasOwnProperty(key)&&!ocsOffCanvasSidebars.useAttributeSettings){return ocsOffCanvasSidebars[key]}else{setting=$("#"+prefix+"-site").attr("ocs-"+key);if("undefined"!==typeof setting){return setting}}return false};ocsOffCanvasSidebars._getTranslateAxis=function(obj,axis){obj=$(obj);var transformMatrix=obj.css("-webkit-transform")||obj.css("-moz-transform")||obj.css("-ms-transform")||obj.css("-o-transform")||obj.css("transform");if(transformMatrix){var matrix=transformMatrix.replace(/[^0-9\-.,]/g,"").split(",");var val=false;switch(axis){case"x":val=matrix[12]||matrix[4];break;case"y":val=matrix[13]||matrix[5];break;case"z":val=matrix[14]||matrix[6];break}return parseFloat(val)}else{return 0}};ocsOffCanvasSidebars.container=$("[canvas=container]");$window.trigger("ocs_loaded",this);ocsOffCanvasSidebars.slidebarsController=new slidebars;if(false===ocsOffCanvasSidebars.slidebarsController){return}if(ocsOffCanvasSidebars.legacy_css){ocsOffCanvasSidebars.slidebarsController.legacy=true;$html.addClass("ocs-legacy")}ocsOffCanvasSidebars.slidebarsController.init();$html.addClass("ocs-initialized");$window.trigger("ocs_initialized",this);if(ocsOffCanvasSidebars._toolbar){$window.on("load resize",function(){var bodyOffset=$body.offset();$("."+ocsOffCanvasSidebars.css_prefix+"-slidebar").each(function(){if($(this).hasClass("ocs-location-top")){$(this).css("margin-top",parseInt($(this).css("margin-top").replace("px",""))+bodyOffset.top+"px")}else if($(this).hasClass("ocs-location-left")||$(this).hasClass("ocs-location-right")){$(this).css("margin-top",bodyOffset.top+"px")}})})}$(ocsOffCanvasSidebars.slidebarsController.events).on("opening opened closing closed",function(e,sidebar_id){var slidebar=ocsOffCanvasSidebars.slidebarsController.getSlidebar(sidebar_id);var duration=parseFloat(slidebar.element.css("transitionDuration"))*1e3;if("top"===slidebar.side||"bottom"===slidebar.side){var elements=ocsOffCanvasSidebars.getFixedElements();elements.attr({"canvas-fixed":"fixed"});if(ocsOffCanvasSidebars.legacy_css&&"top"===slidebar.side&&("overlay"!==slidebar.style&&"reveal"!==slidebar.style)){var offset;offset=parseInt(slidebar.element.css("margin-top").replace("px","").replace("-",""));if(ocsOffCanvasSidebars._toolbar){var bodyOffset=$body.offset();offset+=bodyOffset.top}elements.each(function(){var $this=$(this);if("opening"===e.type){ocsOffCanvasSidebars.cssCompat($this,"transition","top "+duration+"ms");$this.css("top",parseInt($this.css("top").replace("px",""))+offset+"px")}else if("closing"===e.type){$this.css("top",parseInt($this.css("top").replace("px",""))-offset+"px");setTimeout(function(){ocsOffCanvasSidebars.cssCompat($this,"transition","")},duration)}})}else{elements.each(function(){var $this=$(this);if("opening"===e.type||"closing"===e.type){ocsOffCanvasSidebars.cssCompat($this,"transition","transform "+duration+"ms")}else if("opened"===e.type||"closed"===e.type){ocsOffCanvasSidebars.cssCompat($this,"transition","")}})}$window.trigger("slidebar_event",[e.type,slidebar])}});$document.on("touchmove",function(){ocsOffCanvasSidebars._touchmove=true});$document.on("touchstart",function(){ocsOffCanvasSidebars._touchmove=false});if("function"===typeof ocsOffCanvasSidebars.setupTriggers){ocsOffCanvasSidebars.setupTriggers()}};ocsOffCanvasSidebars.setSidebarDefaultSettings=function(sidebarId){if("undefined"===typeof ocsOffCanvasSidebars.sidebars[sidebarId]){ocsOffCanvasSidebars.sidebars[sidebarId]={overwrite_global_settings:false,site_close:ocsOffCanvasSidebars.site_close,disable_over:ocsOffCanvasSidebars.disable_over,hide_control_classes:ocsOffCanvasSidebars.hide_control_classes,scroll_lock:ocsOffCanvasSidebars.scroll_lock}}};ocsOffCanvasSidebars.setupTriggers=function(){var controller=ocsOffCanvasSidebars.slidebarsController,prefix=ocsOffCanvasSidebars.css_prefix,sidebarElements=$("."+prefix+"-slidebar");sidebarElements.each(function(){var id=$(this).attr("ocs-sidebar-id");ocsOffCanvasSidebars.setSidebarDefaultSettings(id);$document.on("touchend click","."+prefix+"-toggle-"+id,function(e){e.stopPropagation();e.preventDefault();if(true===ocsOffCanvasSidebars._touchmove){return}if(ocsOffCanvasSidebars._checkDisableOver(prefix+"-"+id)){controller.toggle(prefix+"-"+id)}});$document.on("touchend click","."+prefix+"-open-"+id,function(e){e.stopPropagation();e.preventDefault();if(true===ocsOffCanvasSidebars._touchmove){return}if(ocsOffCanvasSidebars._checkDisableOver(prefix+"-"+id)){controller.open(prefix+"-"+id)}});$document.on("touchend click","."+prefix+"-close-"+id,function(e){e.stopPropagation();e.preventDefault();if(true===ocsOffCanvasSidebars._touchmove){return}controller.close(prefix+"-"+id)})});$document.on("touchend click","."+prefix+"-close-any",function(e){if(ocsOffCanvasSidebars._getSetting("site_close",false)){e.preventDefault();e.stopPropagation();controller.close()}});$("a").not("."+prefix+"-trigger").on("touchend click",function(){if(!$(this).parents("."+prefix+"-trigger").length){controller.close()}});$(controller.events).on("opening",function(){$("[canvas]").addClass(prefix+"-close-any");$html.addClass("ocs-sidebar-active");if(ocsOffCanvasSidebars._getSetting("scroll_lock",false)){$html.addClass("ocs-scroll-lock")}});$(controller.events).on("closing",function(){$("[canvas]").removeClass(prefix+"-close-any");$html.removeClass("ocs-sidebar-active ocs-scroll-lock")});var disableOver=function(){var prefix=ocsOffCanvasSidebars.css_prefix;sidebarElements.each(function(){var id=$(this).attr("ocs-sidebar-id");if(!ocsOffCanvasSidebars._checkDisableOver(prefix+"-"+id)){if(controller.isActiveSlidebar(prefix+"-"+id)){controller.close()}if(ocsOffCanvasSidebars._getSetting("hide_control_classes",prefix+"-"+id)){$("."+prefix+"-toggle-"+id).hide()}}else{$("."+prefix+"-toggle-"+id).show()}})};disableOver();$window.on("resize",disableOver);$("#"+prefix+"-site").on("scroll touchmove mousewheel DOMMouseScroll",function(e){if($html.hasClass("ocs-scroll-lock")){e.preventDefault();e.stopPropagation();return false}});sidebarElements.on("scroll touchmove mousewheel DOMMouseScroll",function(e){if($html.hasClass("ocs-scroll-lock")){var $this=$(this);if(0>e.originalEvent.deltaY){return 0<$this.scrollTop()}else{return $this.scrollTop()+$this.innerHeight()<$this[0].scrollHeight}}});$window.on("resize",function(){ocsOffCanvasSidebars.container.css("min-height",$window.innerHeight()-parseInt($html.css("margin-top"),10))}).trigger("resize")};ocsOffCanvasSidebars.getFixedElements=function(){return $("#"+ocsOffCanvasSidebars.css_prefix+"-site *").filter(function(){return"fixed"===$(this).css("position")})};ocsOffCanvasSidebars.cssCompat=function(elem,prop,value){var data={};data["-webkit-"+prop]=value;data["-moz-"+prop]=value;data["-o-"+prop]=value;data[prop]=value;$(elem).css(data)};if($("#"+ocsOffCanvasSidebars.css_prefix+"-site").length&&"undefined"!==typeof slidebars){ocsOffCanvasSidebars.init()}})(jQuery); \ No newline at end of file +if("undefined"===typeof ocsOffCanvasSidebars){var ocsOffCanvasSidebars={site_close:true,disable_over:false,hide_control_classes:false,scroll_lock:false,legacy_css:false,css_prefix:"ocs",sidebars:{},_debug:false}}(function($){var $document=$(document);var $window=$(window);var $html=$("html");var $body=$("body");ocsOffCanvasSidebars.slidebarsController=false;ocsOffCanvasSidebars.useAttributeSettings=false;ocsOffCanvasSidebars.container=false;ocsOffCanvasSidebars._touchmove=false;ocsOffCanvasSidebars._toolbar=$body.hasClass("admin-bar");ocsOffCanvasSidebars.init=function(){ocsOffCanvasSidebars._checkDisableOver=function(sidebarId){var check=true;var disableOver=parseInt(ocsOffCanvasSidebars._getSetting("disable_over",sidebarId));if(disableOver&&!isNaN(disableOver)){if($window.width()>disableOver){check=false}}return check};ocsOffCanvasSidebars._getSetting=function(key,sidebarId){var overwrite,setting;var prefix=ocsOffCanvasSidebars.css_prefix;if("undefined"!==typeof sidebarId){if(!sidebarId&&null!==sidebarId){sidebarId=ocsOffCanvasSidebars.slidebarsController.getActiveSlidebar()}}if(sidebarId){if(!$.isEmptyObject(ocsOffCanvasSidebars.sidebars)&&!ocsOffCanvasSidebars.useAttributeSettings){sidebarId=sidebarId.replace(prefix+"-","");if(ocsOffCanvasSidebars.sidebars[sidebarId].overwrite_global_settings){setting=ocsOffCanvasSidebars.sidebars[sidebarId][key];if(setting){return setting}else{return false}}}else{var sidebarElement=$("#"+sidebarId);overwrite=sidebarElement.attr("ocs-overwrite_global_settings");if(overwrite){setting=sidebarElement.attr("ocs-"+key);if("undefined"!==typeof setting){return setting}else{return false}}}}if(ocsOffCanvasSidebars.hasOwnProperty(key)&&!ocsOffCanvasSidebars.useAttributeSettings){return ocsOffCanvasSidebars[key]}else{setting=$("#"+prefix+"-site").attr("ocs-"+key);if("undefined"!==typeof setting){return setting}}return false};ocsOffCanvasSidebars._getTranslateAxis=function(obj,axis){obj=$(obj);var transformMatrix=obj.css("-webkit-transform")||obj.css("-moz-transform")||obj.css("-ms-transform")||obj.css("-o-transform")||obj.css("transform");if(transformMatrix){var matrix=transformMatrix.replace(/[^0-9\-.,]/g,"").split(",");var val=false;switch(axis){case"x":val=matrix[12]||matrix[4];break;case"y":val=matrix[13]||matrix[5];break;case"z":val=matrix[14]||matrix[6];break}return parseFloat(val)}else{return 0}};ocsOffCanvasSidebars.container=$("[canvas=container]");$window.trigger("ocs_before",this);ocsOffCanvasSidebars.slidebarsController=new slidebars;if(false===ocsOffCanvasSidebars.slidebarsController){return}if(ocsOffCanvasSidebars.legacy_css){ocsOffCanvasSidebars.slidebarsController.legacy=true;$html.addClass("ocs-legacy")}$window.trigger("ocs_loaded",this);ocsOffCanvasSidebars.slidebarsController.init();$html.addClass("ocs-initialized");$window.trigger("ocs_initialized",this);if(ocsOffCanvasSidebars._toolbar){$window.on("load resize",function(){var bodyOffset=$body.offset();$("."+ocsOffCanvasSidebars.css_prefix+"-slidebar").each(function(){if($(this).hasClass("ocs-location-top")){$(this).css("margin-top",parseInt($(this).css("margin-top").replace("px",""))+bodyOffset.top+"px")}else if($(this).hasClass("ocs-location-left")||$(this).hasClass("ocs-location-right")){$(this).css("margin-top",bodyOffset.top+"px")}})})}$(ocsOffCanvasSidebars.slidebarsController.events).on("opening opened closing closed",function(e,sidebar_id){var slidebar=ocsOffCanvasSidebars.slidebarsController.getSlidebar(sidebar_id);var duration=parseFloat(slidebar.element.css("transitionDuration"))*1e3;if("top"===slidebar.side||"bottom"===slidebar.side){var elements=ocsOffCanvasSidebars.getFixedElements();elements.attr({"canvas-fixed":"fixed"});if(ocsOffCanvasSidebars.legacy_css&&"top"===slidebar.side&&("overlay"!==slidebar.style&&"reveal"!==slidebar.style)){var offset;offset=parseInt(slidebar.element.css("margin-top").replace("px","").replace("-",""));if(ocsOffCanvasSidebars._toolbar){var bodyOffset=$body.offset();offset+=bodyOffset.top}elements.each(function(){var $this=$(this);if("opening"===e.type){ocsOffCanvasSidebars.cssCompat($this,"transition","top "+duration+"ms");$this.css("top",parseInt($this.css("top").replace("px",""))+offset+"px")}else if("closing"===e.type){$this.css("top",parseInt($this.css("top").replace("px",""))-offset+"px");setTimeout(function(){ocsOffCanvasSidebars.cssCompat($this,"transition","")},duration)}})}else{elements.each(function(){var $this=$(this);if("opening"===e.type||"closing"===e.type){ocsOffCanvasSidebars.cssCompat($this,"transition","transform "+duration+"ms")}else if("opened"===e.type||"closed"===e.type){ocsOffCanvasSidebars.cssCompat($this,"transition","")}})}$window.trigger("slidebar_event",[e.type,slidebar])}});$document.on("touchmove",function(){ocsOffCanvasSidebars._touchmove=true});$document.on("touchstart",function(){ocsOffCanvasSidebars._touchmove=false});if("function"===typeof ocsOffCanvasSidebars.setupTriggers){ocsOffCanvasSidebars.setupTriggers()}$window.trigger("ocs_after",this)};ocsOffCanvasSidebars.setSidebarDefaultSettings=function(sidebarId){if("undefined"===typeof ocsOffCanvasSidebars.sidebars[sidebarId]){ocsOffCanvasSidebars.sidebars[sidebarId]={overwrite_global_settings:false,site_close:ocsOffCanvasSidebars.site_close,disable_over:ocsOffCanvasSidebars.disable_over,hide_control_classes:ocsOffCanvasSidebars.hide_control_classes,scroll_lock:ocsOffCanvasSidebars.scroll_lock}}};ocsOffCanvasSidebars.setupTriggers=function(){var controller=ocsOffCanvasSidebars.slidebarsController,prefix=ocsOffCanvasSidebars.css_prefix,sidebarElements=$("."+prefix+"-slidebar");sidebarElements.each(function(){var id=$(this).attr("ocs-sidebar-id");ocsOffCanvasSidebars.setSidebarDefaultSettings(id);$document.on("touchend click","."+prefix+"-toggle-"+id,function(e){e.stopPropagation();e.preventDefault();if(true===ocsOffCanvasSidebars._touchmove){return}if(ocsOffCanvasSidebars._checkDisableOver(prefix+"-"+id)){controller.toggle(prefix+"-"+id)}});$document.on("touchend click","."+prefix+"-open-"+id,function(e){e.stopPropagation();e.preventDefault();if(true===ocsOffCanvasSidebars._touchmove){return}if(ocsOffCanvasSidebars._checkDisableOver(prefix+"-"+id)){controller.open(prefix+"-"+id)}});$document.on("touchend click","."+prefix+"-close-"+id,function(e){e.stopPropagation();e.preventDefault();if(true===ocsOffCanvasSidebars._touchmove){return}controller.close(prefix+"-"+id)})});$document.on("touchend click","."+prefix+"-close-any",function(e){if(ocsOffCanvasSidebars._getSetting("site_close",false)){e.preventDefault();e.stopPropagation();controller.close()}});$("a").not("."+prefix+"-trigger").on("touchend click",function(){if(!$(this).parents("."+prefix+"-trigger").length){controller.close()}});$(controller.events).on("opening",function(){$("[canvas]").addClass(prefix+"-close-any");$html.addClass("ocs-sidebar-active");if(ocsOffCanvasSidebars._getSetting("scroll_lock",false)){$html.addClass("ocs-scroll-lock")}});$(controller.events).on("closing",function(){$("[canvas]").removeClass(prefix+"-close-any");$html.removeClass("ocs-sidebar-active ocs-scroll-lock")});var disableOver=function(){var prefix=ocsOffCanvasSidebars.css_prefix;sidebarElements.each(function(){var id=$(this).attr("ocs-sidebar-id");if(!ocsOffCanvasSidebars._checkDisableOver(prefix+"-"+id)){if(controller.isActiveSlidebar(prefix+"-"+id)){controller.close()}if(ocsOffCanvasSidebars._getSetting("hide_control_classes",prefix+"-"+id)){$("."+prefix+"-toggle-"+id).hide()}}else{$("."+prefix+"-toggle-"+id).show()}})};disableOver();$window.on("resize",disableOver);$("#"+prefix+"-site").on("scroll touchmove mousewheel DOMMouseScroll",function(e){if($html.hasClass("ocs-scroll-lock")){e.preventDefault();e.stopPropagation();return false}});sidebarElements.on("scroll touchmove mousewheel DOMMouseScroll",function(e){if($html.hasClass("ocs-scroll-lock")){var $this=$(this);if(0>e.originalEvent.deltaY){return 0<$this.scrollTop()}else{return $this.scrollTop()+$this.innerHeight()<$this[0].scrollHeight}}});$window.on("load resize",function(){ocsOffCanvasSidebars.container.css("min-height",$window.innerHeight()-parseInt($html.css("margin-top"),10))})};ocsOffCanvasSidebars.getFixedElements=function(){return $("#"+ocsOffCanvasSidebars.css_prefix+"-site *").filter(function(){return"fixed"===$(this).css("position")})};ocsOffCanvasSidebars.cssCompat=function(elem,prop,value){var data={};data["-webkit-"+prop]=value;data["-moz-"+prop]=value;data["-o-"+prop]=value;data[prop]=value;$(elem).css(data)};if($("#"+ocsOffCanvasSidebars.css_prefix+"-site").length&&"undefined"!==typeof slidebars){ocsOffCanvasSidebars.init()}})(jQuery); \ No newline at end of file From 42bac3867f3235b1f3f4f68dcaa22489f0f4b925 Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Wed, 6 Sep 2017 03:25:46 +0200 Subject: [PATCH 121/124] Fix shortcode generator sidebar ID key --- includes/class-settings.php | 4 ++-- js/off-canvas-sidebars-settings.js | 6 +++--- js/off-canvas-sidebars-settings.min.js | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/includes/class-settings.php b/includes/class-settings.php index 168c88d..e840b5f 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -1066,7 +1066,7 @@ private function shortcode_tab() {

    :

    - +
    select_option( array( - 'name' => 'sidebar', + 'name' => 'id', 'label' => __( 'Sidebar ID', 'off-canvas-sidebars' ), 'description' => __( '(Required) The off-canvas sidebar ID', 'off-canvas-sidebars' ), 'options' => $sidebar_select, diff --git a/js/off-canvas-sidebars-settings.js b/js/off-canvas-sidebars-settings.js index 41d9df7..0b8f7b3 100644 --- a/js/off-canvas-sidebars-settings.js +++ b/js/off-canvas-sidebars-settings.js @@ -223,7 +223,7 @@ if ( 'undefined' === typeof ocsOffCanvasSidebarsSettings ) { if ( 'ocs-shortcode' === tab.val() ) { - var fields = [ 'sidebar', 'text', 'action', 'element', 'class', 'attr', 'nested' ]; + var fields = [ 'id', 'text', 'action', 'element', 'class', 'attr', 'nested' ]; for ( var i = 0, l = fields.length; i < l; i++ ) { $( '#off_canvas_sidebars_options_' + fields[ i ] ).on( 'change keyup', function() { @@ -298,8 +298,8 @@ if ( 'undefined' === typeof ocsOffCanvasSidebarsSettings ) { singleton = false, html = ''; - if ( field_data.sidebar.val() ) { - classes += ' ' + prefix + '-' + action + '-' + field_data.sidebar.val(); + if ( field_data.id.val() ) { + classes += ' ' + prefix + '-' + action + '-' + field_data.id.val(); } if ( field_data.class.val() ) { classes += ' ' + field_data.class.val(); diff --git a/js/off-canvas-sidebars-settings.min.js b/js/off-canvas-sidebars-settings.min.js index 3a6d279..721db1b 100644 --- a/js/off-canvas-sidebars-settings.min.js +++ b/js/off-canvas-sidebars-settings.min.js @@ -7,4 +7,4 @@ * @global ocsOffCanvasSidebarsSettings * @preserve */ -if("undefined"===typeof ocsOffCanvasSidebarsSettings){var ocsOffCanvasSidebarsSettings={general_key:"off_canvas_sidebars_options",plugin_key:"off-canvas-sidebars-settings",css_prefix:"ocs",__required_fields_not_set:"Some required fields are not set!"}}(function($){var $document=$(document);ocsOffCanvasSidebarsSettings.init=function(){var tab=$("#ocs_tab");var postbox=$(".postbox");$(".if-js-closed").removeClass("if-js-closed").addClass("closed");postboxes.add_postbox_toggles(ocsOffCanvasSidebarsSettings.plugin_key);if("ocs-sidebars"===tab.val()){postbox.each(function(){var prefix="off_canvas_sidebars_options_sidebars_",sidebar_id=$(this).attr("id").replace("section_sidebar_",""),sidebar_prefix=prefix+sidebar_id;ocs_show_hide_options_radio("."+sidebar_prefix+"_background_color_type","."+sidebar_prefix+"_background_color_wrapper","color",false);ocs_show_hide_options_radio("."+sidebar_prefix+"_location","#"+sidebar_prefix+"_style_reveal, #"+sidebar_prefix+"_style_shift",["left","right"],"label");ocs_show_hide_options("."+sidebar_prefix+"_overwrite_global_settings","."+sidebar_prefix+"_site_close","tr");ocs_show_hide_options("."+sidebar_prefix+"_overwrite_global_settings","."+sidebar_prefix+"_disable_over","tr");ocs_show_hide_options("."+sidebar_prefix+"_overwrite_global_settings","."+sidebar_prefix+"_hide_control_classes","tr");ocs_show_hide_options("."+sidebar_prefix+"_overwrite_global_settings","."+sidebar_prefix+"_scroll_lock","tr")})}else{ocs_show_hide_options_radio(".off_canvas_sidebars_options_background_color_type",".off_canvas_sidebars_options_background_color_wrapper","color",false)}function ocs_show_hide_options(trigger,target,parent){if(parent){target=$(target).closest(parent)}if(!$(trigger).is(":checked")){$(target).slideUp("fast")}$(trigger).change(function(){if($(this).is(":checked")){$(target).slideDown("fast")}else{$(target).slideUp("fast")}})}function ocs_show_hide_options_radio(trigger,target,compare,parent){if(!$.isArray(compare)){compare=[compare]}if(parent){parent+=", "+parent+" + br";target=$(target).closest(parent)}$(trigger).change(function(){if(0<=$.inArray($(trigger+":checked").val(),compare)){$(target).slideDown("fast")}else{$(target).slideUp("fast")}}).trigger("change")}$("input.color-picker").wpColorPicker();$("input.required").each(function(){var $this=$(this);$this.on("change",function(){if(!$this.val()){$this.parents("tr").addClass("form-invalid")}else{$this.parents("tr").removeClass("form-invalid")}})});$("#"+ocsOffCanvasSidebarsSettings.general_key).submit(function(e){var valid=true;$("input.required",this).each(function(){if(!$(this).val()){$(this).trigger("change");valid=false}});if(!valid){e.preventDefault();alert(ocsOffCanvasSidebarsSettings.__required_fields_not_set)}});if("ocs-sidebars"===tab.val()){if($(".js-dynamic-id").length){postbox.each(function(){var sidebar=this;$(".js-dynamic-id",sidebar).text($("input.off_canvas_sidebars_options_sidebars_id",sidebar).val());$(".sidebar_classes").show();$("input.off_canvas_sidebars_options_sidebars_id",this).on("keyup",function(){$(".js-dynamic-id",sidebar).text($(this).val())})})}postbox.each(function(){var sidebar=this,$sidebar=$(sidebar);$sidebar.css({"border-left":"5px solid #eee"});if(!$("input.off_canvas_sidebars_options_sidebars_enable",sidebar).is(":checked")){if($sidebar.hasClass("closed")){$sidebar.css("opacity","0.75")}$sidebar.css("border-left-color","#ffb900")}else{$sidebar.css("border-left-color","#46b450")}$("input.off_canvas_sidebars_options_sidebars_enable",sidebar).on("change",function(){if(!$(this).is(":checked")){$sidebar.css("border-left-color","#ffb900");if($sidebar.hasClass("closed")){$sidebar.css("opacity","0.75")}else{$sidebar.css("opacity","")}}else{$sidebar.css("border-left-color","#46b450");$sidebar.css("opacity","")}});$sidebar.on("click",function(){if(!$("input.off_canvas_sidebars_options_sidebars_enable",sidebar).is(":checked")&&$sidebar.hasClass("closed")){$sidebar.css("opacity","0.75")}else{$sidebar.css("opacity","")}})});$document.on("change",".off_canvas_sidebars_options_sidebars_delete",function(){var $this=$(this),sidebar=$this.parents(".postbox"),$sidebar=$(sidebar);if($this.is(":checked")){var parent_row=$this.parents("tr");$("tr",sidebar).hide("fast",function(){$("tr",sidebar).each(function(){if($(this).is(parent_row)){$(this).show("fast")}})});$sidebar.css("opacity","0.5");$sidebar.css("border-left-color","#dc3232")}else{$sidebar.css("opacity","");$("tr",sidebar).show("fast");$("input.off_canvas_sidebars_options_sidebars_enable",sidebar).trigger("change")}})}if("ocs-shortcode"===tab.val()){var fields=["sidebar","text","action","element","class","attr","nested"];for(var i=0,l=fields.length;i"}else{html="<"+element+" "+attrObjectToHTML(attributes)+">"+field_data.text.val()+""}$("#ocs_shortcode_preview").html(html);$("#ocs_shortcode_html").val(html)}function attrHTMLToObject(attrString){var arr=attrString.trim().split('" '),atts={};for(var key in arr){if(arr.hasOwnProperty(key)){arr[key]=arr[key].split('="');if(arr[key][0].trim().length){atts[arr[key][0].trim()]=getAttr(attrString,arr[key][0],false)}}}return atts}function attrStringToObject(attrString){var arr=attrString.split(";"),atts={};for(var key in arr){if(arr.hasOwnProperty(key)){arr[key]=arr[key].split(":");if(arr[key][0].trim().length){var name=arr[key][0].trim();arr[key].splice(0,1);atts[name]=arr[key].join(":")}}}return atts}function attrObjectToHTML(attrObj){var atts=[];for(var name in attrObj){if(attrObj.hasOwnProperty(name)){atts.push(name+'="'+attrObj[name]+'"')}}return atts.join(" ")}function attrObjectToString(attrObj){var atts=[];for(var name in attrObj){if(attrObj.hasOwnProperty(name)){atts.push(name+":"+attrObj[name])}}return atts.join(";")}function getAttr(s,a,f){var n=new RegExp(a+'="([^"]+)"',"g").exec(s);if(true===f&&!n&&-1===s.indexOf(a+'="')){return false}return n?window.decodeURIComponent(n[1]).trim():""}};ocsOffCanvasSidebarsSettings.init()})(jQuery); \ No newline at end of file +if("undefined"===typeof ocsOffCanvasSidebarsSettings){var ocsOffCanvasSidebarsSettings={general_key:"off_canvas_sidebars_options",plugin_key:"off-canvas-sidebars-settings",css_prefix:"ocs",__required_fields_not_set:"Some required fields are not set!"}}(function($){var $document=$(document);ocsOffCanvasSidebarsSettings.init=function(){var tab=$("#ocs_tab");var postbox=$(".postbox");$(".if-js-closed").removeClass("if-js-closed").addClass("closed");postboxes.add_postbox_toggles(ocsOffCanvasSidebarsSettings.plugin_key);if("ocs-sidebars"===tab.val()){postbox.each(function(){var prefix="off_canvas_sidebars_options_sidebars_",sidebar_id=$(this).attr("id").replace("section_sidebar_",""),sidebar_prefix=prefix+sidebar_id;ocs_show_hide_options_radio("."+sidebar_prefix+"_background_color_type","."+sidebar_prefix+"_background_color_wrapper","color",false);ocs_show_hide_options_radio("."+sidebar_prefix+"_location","#"+sidebar_prefix+"_style_reveal, #"+sidebar_prefix+"_style_shift",["left","right"],"label");ocs_show_hide_options("."+sidebar_prefix+"_overwrite_global_settings","."+sidebar_prefix+"_site_close","tr");ocs_show_hide_options("."+sidebar_prefix+"_overwrite_global_settings","."+sidebar_prefix+"_disable_over","tr");ocs_show_hide_options("."+sidebar_prefix+"_overwrite_global_settings","."+sidebar_prefix+"_hide_control_classes","tr");ocs_show_hide_options("."+sidebar_prefix+"_overwrite_global_settings","."+sidebar_prefix+"_scroll_lock","tr")})}else{ocs_show_hide_options_radio(".off_canvas_sidebars_options_background_color_type",".off_canvas_sidebars_options_background_color_wrapper","color",false)}function ocs_show_hide_options(trigger,target,parent){if(parent){target=$(target).closest(parent)}if(!$(trigger).is(":checked")){$(target).slideUp("fast")}$(trigger).change(function(){if($(this).is(":checked")){$(target).slideDown("fast")}else{$(target).slideUp("fast")}})}function ocs_show_hide_options_radio(trigger,target,compare,parent){if(!$.isArray(compare)){compare=[compare]}if(parent){parent+=", "+parent+" + br";target=$(target).closest(parent)}$(trigger).change(function(){if(0<=$.inArray($(trigger+":checked").val(),compare)){$(target).slideDown("fast")}else{$(target).slideUp("fast")}}).trigger("change")}$("input.color-picker").wpColorPicker();$("input.required").each(function(){var $this=$(this);$this.on("change",function(){if(!$this.val()){$this.parents("tr").addClass("form-invalid")}else{$this.parents("tr").removeClass("form-invalid")}})});$("#"+ocsOffCanvasSidebarsSettings.general_key).submit(function(e){var valid=true;$("input.required",this).each(function(){if(!$(this).val()){$(this).trigger("change");valid=false}});if(!valid){e.preventDefault();alert(ocsOffCanvasSidebarsSettings.__required_fields_not_set)}});if("ocs-sidebars"===tab.val()){if($(".js-dynamic-id").length){postbox.each(function(){var sidebar=this;$(".js-dynamic-id",sidebar).text($("input.off_canvas_sidebars_options_sidebars_id",sidebar).val());$(".sidebar_classes").show();$("input.off_canvas_sidebars_options_sidebars_id",this).on("keyup",function(){$(".js-dynamic-id",sidebar).text($(this).val())})})}postbox.each(function(){var sidebar=this,$sidebar=$(sidebar);$sidebar.css({"border-left":"5px solid #eee"});if(!$("input.off_canvas_sidebars_options_sidebars_enable",sidebar).is(":checked")){if($sidebar.hasClass("closed")){$sidebar.css("opacity","0.75")}$sidebar.css("border-left-color","#ffb900")}else{$sidebar.css("border-left-color","#46b450")}$("input.off_canvas_sidebars_options_sidebars_enable",sidebar).on("change",function(){if(!$(this).is(":checked")){$sidebar.css("border-left-color","#ffb900");if($sidebar.hasClass("closed")){$sidebar.css("opacity","0.75")}else{$sidebar.css("opacity","")}}else{$sidebar.css("border-left-color","#46b450");$sidebar.css("opacity","")}});$sidebar.on("click",function(){if(!$("input.off_canvas_sidebars_options_sidebars_enable",sidebar).is(":checked")&&$sidebar.hasClass("closed")){$sidebar.css("opacity","0.75")}else{$sidebar.css("opacity","")}})});$document.on("change",".off_canvas_sidebars_options_sidebars_delete",function(){var $this=$(this),sidebar=$this.parents(".postbox"),$sidebar=$(sidebar);if($this.is(":checked")){var parent_row=$this.parents("tr");$("tr",sidebar).hide("fast",function(){$("tr",sidebar).each(function(){if($(this).is(parent_row)){$(this).show("fast")}})});$sidebar.css("opacity","0.5");$sidebar.css("border-left-color","#dc3232")}else{$sidebar.css("opacity","");$("tr",sidebar).show("fast");$("input.off_canvas_sidebars_options_sidebars_enable",sidebar).trigger("change")}})}if("ocs-shortcode"===tab.val()){var fields=["id","text","action","element","class","attr","nested"];for(var i=0,l=fields.length;i"}else{html="<"+element+" "+attrObjectToHTML(attributes)+">"+field_data.text.val()+""}$("#ocs_shortcode_preview").html(html);$("#ocs_shortcode_html").val(html)}function attrHTMLToObject(attrString){var arr=attrString.trim().split('" '),atts={};for(var key in arr){if(arr.hasOwnProperty(key)){arr[key]=arr[key].split('="');if(arr[key][0].trim().length){atts[arr[key][0].trim()]=getAttr(attrString,arr[key][0],false)}}}return atts}function attrStringToObject(attrString){var arr=attrString.split(";"),atts={};for(var key in arr){if(arr.hasOwnProperty(key)){arr[key]=arr[key].split(":");if(arr[key][0].trim().length){var name=arr[key][0].trim();arr[key].splice(0,1);atts[name]=arr[key].join(":")}}}return atts}function attrObjectToHTML(attrObj){var atts=[];for(var name in attrObj){if(attrObj.hasOwnProperty(name)){atts.push(name+'="'+attrObj[name]+'"')}}return atts.join(" ")}function attrObjectToString(attrObj){var atts=[];for(var name in attrObj){if(attrObj.hasOwnProperty(name)){atts.push(name+":"+attrObj[name])}}return atts.join(";")}function getAttr(s,a,f){var n=new RegExp(a+'="([^"]+)"',"g").exec(s);if(true===f&&!n&&-1===s.indexOf(a+'="')){return false}return n?window.decodeURIComponent(n[1]).trim():""}};ocsOffCanvasSidebarsSettings.init()})(jQuery); \ No newline at end of file From f356837d90bdbb7857c25d22df9275304ba955b9 Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Wed, 6 Sep 2017 20:16:22 +0200 Subject: [PATCH 122/124] v0.4 --- off-canvas-sidebars.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/off-canvas-sidebars.php b/off-canvas-sidebars.php index 6c8ea0a..806dee4 100644 --- a/off-canvas-sidebars.php +++ b/off-canvas-sidebars.php @@ -3,7 +3,7 @@ * @author Jory Hogeveen * @package Off_Canvas_Sidebars * @since 0.1 - * @version 0.4-rc2 + * @version 0.4 * @licence GPL-2.0+ * @link https://github.com/JoryHogeveen/off-canvas-sidebars * @@ -11,7 +11,7 @@ * Plugin Name: Off-Canvas Sidebars * Description: Add off-canvas sidebars using the Slidebars jQuery plugin * Plugin URI: https://wordpress.org/plugins/off-canvas-sidebars/ - * Version: 0.4-rc2 + * Version: 0.4 * Author: Jory Hogeveen * Author URI: http://www.keraweb.nl * Text Domain: off-canvas-sidebars @@ -42,7 +42,7 @@ die(); } -define( 'OCS_PLUGIN_VERSION', '0.4-rc2' ); +define( 'OCS_PLUGIN_VERSION', '0.4' ); define( 'OCS_FILE', __FILE__ ); define( 'OCS_BASENAME', plugin_basename( OCS_FILE ) ); define( 'OCS_PLUGIN_DIR', plugin_dir_path( OCS_FILE ) ); From 00527b96ba6d11e838de22df20f3b6d099b91ff2 Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Wed, 6 Sep 2017 20:38:09 +0200 Subject: [PATCH 123/124] Update screenshots --- readme.txt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/readme.txt b/readme.txt index abb4e35..9f73f87 100644 --- a/readme.txt +++ b/readme.txt @@ -81,11 +81,12 @@ For more advanced customisations either: 1. Settings page 2. Sidebars settings page (sidebars closed) 3. Sidebars settings page (sidebar opened) -4. Control Widget -5. Menu item -6. Sidebar left (Push effect) -> image from Slidebars website -7. Sidebar left (Overlay effect) -> image from Slidebars website -8. Sidebar top (Push effect) -> image from Slidebars website +4. Shortcode generator page +5. Control Widget +6. Menu item +7. Sidebar left (Push effect) -> image from Slidebars website +8. Sidebar left (Overlay effect) -> image from Slidebars website +9. Sidebar top (Push effect) -> image from Slidebars website == Changelog == From c46f8f9a62a61bbd967b88d5f06517d13a64087b Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Wed, 6 Sep 2017 20:59:19 +0200 Subject: [PATCH 124/124] Fix readme FAQ titles --- readme.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readme.txt b/readme.txt index 9f73f87..efe68d8 100644 --- a/readme.txt +++ b/readme.txt @@ -59,16 +59,16 @@ Off-Canvas Sidebars won't work "out of the box" with most themes, please read th == Frequently Asked Questions == -1. Will this plugin work with any theme? += 1. Will this plugin work with any theme? = No, due to the difference in structure not all theme's are compatible. Though most themes can be *made* compatible with some modifications! -2. Can I add as many sidebars as I like? += 2. Can I add as many sidebars as I like? = Yes you can, keep in mind that the more sidebars you add the heaver the load is on the server (PHP) and browser (JS). -3. How do I change the CSS for the sidebars? += 3. How do I change the CSS for the sidebars? = This plugin only provides the framework that handles the off-canvas part. There are some settings that slightly change the display but this is very limited.