Skip to content

Commit f5e3b2a

Browse files
committed
Version 0.1.2
1 parent 4693883 commit f5e3b2a

15 files changed

+447
-170
lines changed

includes/off-canvas-sidebars-frontend.class.php

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,21 @@
55
* Front-end
66
* @author Jory Hogeveen <[email protected]>
77
* @package off-canvas-slidebars
8-
* @version 0.1
8+
* @version 0.1.2
99
*/
1010

1111
! defined( 'ABSPATH' ) and die( 'You shall not pass!' );
1212

1313
class OCS_Off_Canvas_Sidebars_Frontend {
1414

1515
private $general_settings = array();
16-
16+
private $version = false;
17+
1718
function __construct() {
1819
$this->load_plugin_data();
1920

2021
if ( $this->general_settings['enable_frontend'] == true ) {
21-
if ( get_template() == 'genesis' ) {
22-
$this->genesis_actions();
23-
} else {
24-
$this->default_actions();
25-
}
22+
$this->default_actions();
2623
}
2724

2825
// Dúh..
@@ -36,8 +33,9 @@ function __construct() {
3633
* Get plugin defaults
3734
*/
3835
function load_plugin_data() {
39-
global $off_canvas_sidebars;
36+
$off_canvas_sidebars = Off_Canvas_Sidebars();
4037
$this->general_settings = $off_canvas_sidebars->get_settings();
38+
$this->version = $off_canvas_sidebars->get_version();
4139
}
4240

4341
/**
@@ -47,25 +45,24 @@ function load_plugin_data() {
4745
* @return void
4846
*/
4947
function default_actions() {
50-
add_action( 'website_before', array( $this, 'before_site' ), 0.000000001 ); // enforce first addition
51-
add_action( 'website_after', array( $this, 'after_site' ), 999999999 ); // enforce last addition
48+
$before_hook = str_replace( array(' '), '', $this->general_settings['website_before_hook'] );
49+
$after_hook = str_replace( array(' '), '', $this->general_settings['website_after_hook'] );
50+
if ( get_template() == 'genesis' ) {
51+
$before_hook = 'genesis_before';
52+
$after_hook = 'genesis_after';
53+
}
54+
if ( empty( $before_hook ) || empty( $after_hook ) ) {
55+
$before_hook = 'website_before';
56+
$after_hook = 'website_after';
57+
}
58+
add_action( $before_hook, array( $this, 'before_site' ), 0.000000001 ); // enforce first addition
59+
add_action( $after_hook, array( $this, 'after_site' ), 999999999 ); // enforce last addition
5260

5361
/* EXPERIMENTAL */
5462
//add_action( 'wp_footer', array( $this, 'after_site' ), 0.000000001 ); // enforce first addition
5563
//add_action( 'wp_footer', array( $this, 'after_site_script' ), 99999 ); // enforce almnost last addition
5664
}
5765

58-
/**
59-
* Add genesis actions
60-
*
61-
* @since 0.1
62-
* @return void
63-
*/
64-
function genesis_actions() {
65-
add_action( 'genesis_before', array( $this, 'before_site' ), 0.000000001 ); // enforce first addition
66-
add_action( 'genesis_after', array( $this, 'after_site' ), 999999999 ); // enforce last addition
67-
}
68-
6966
/**
7067
* before_site action hook
7168
*
@@ -83,9 +80,9 @@ function before_site() {
8380
* @return void
8481
*/
8582
function after_site() {
86-
if ( get_template() == 'genesis' ) {
87-
echo '</div>';
88-
} // close #sb-site
83+
if ( $this->general_settings['frontend_type'] != 'jquery' ) {
84+
echo '</div>'; // close #sb-site
85+
}
8986
foreach ($this->general_settings['sidebars'] as $sidebar => $sidebar_data) {
9087
if ($sidebar_data['enable'] == 1) {
9188
$this->add_slidebar($sidebar);
@@ -174,6 +171,10 @@ function add_styles_scripts() {
174171
$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
175172
wp_enqueue_style( 'slidebars', OCS_PLUGIN_URL . 'slidebars/slidebars'.$suffix.'.css', array(), '0.10.3' );
176173
wp_enqueue_script( 'slidebars', OCS_PLUGIN_URL . 'slidebars/slidebars'.$suffix.'.js', array( 'jquery' ), '0.10.3' );
174+
175+
if ( $this->general_settings['compatibility_position_fixed'] == true ) {
176+
wp_enqueue_script( 'ocs-fixed-scrolltop', OCS_PLUGIN_URL . 'js/fixed-scrolltop.js', array( 'jquery' ), $this->version );
177+
}
177178
//wp_enqueue_style( 'off_canvas_slidebars_style', plugin_dir_url( __FILE__ ) . 'style.css', array(), $this->version );
178179
//wp_enqueue_script( 'off_canvas_slidebars_script', plugin_dir_url( __FILE__ ) . 'script.js', array( 'jquery' ), $this->version );
179180
}

includes/off-canvas-sidebars-menu-meta-box.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Menu Meta Box
66
* @author Jory Hogeveen <[email protected]>
77
* @package off-canvas-slidebars
8-
* @version 0.1
8+
* @version 0.1.2
99
*
1010
* Credits to the Polylang plugin
1111
*/
@@ -34,7 +34,7 @@ function __construct() {
3434
* Get plugin defaults
3535
*/
3636
function load_plugin_data() {
37-
global $off_canvas_sidebars;
37+
$off_canvas_sidebars = Off_Canvas_Sidebars();
3838
$this->general_settings = $off_canvas_sidebars->get_settings();
3939
$this->general_labels = $off_canvas_sidebars->get_general_labels();
4040
$this->general_key = $off_canvas_sidebars->get_general_key();

includes/off-canvas-sidebars-settings.class.php

Lines changed: 88 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Settings
66
* @author Jory Hogeveen <[email protected]>
77
* @package off-canvas-slidebars
8-
* @version 0.1
8+
* @version 0.1.2
99
*/
1010

1111
! defined( 'ABSPATH' ) and die( 'You shall not pass!' );
@@ -30,7 +30,7 @@ function __construct() {
3030
* Get plugin defaults
3131
*/
3232
function load_plugin_data() {
33-
global $off_canvas_sidebars;
33+
$off_canvas_sidebars = Off_Canvas_Sidebars();
3434
$this->general_settings = $off_canvas_sidebars->get_settings();
3535
$this->general_labels = $off_canvas_sidebars->get_general_labels();
3636
$this->general_key = $off_canvas_sidebars->get_general_key();
@@ -75,6 +75,13 @@ function register_general_settings() {
7575
'description' => sprintf( __( '<a href="%s" target="_blank">Read this to setup your theme for support!</a> (Themes based on the Genesis Framework are supported by default)', 'off-canvas-sidebars' ), 'https://wordpress.org/plugins/off-canvas-sidebars/installation/' )
7676
)
7777
);
78+
/*add_settings_field(
79+
'frontend_type',
80+
esc_attr__( 'Front-end type', 'off-canvas-sidebars' ),
81+
array( $this, 'frontend_type_option' ),
82+
$this->general_key,
83+
'section_general'
84+
);*/
7885
add_settings_field(
7986
'enabled_sidebars',
8087
esc_attr__( 'Enable Sidebars', 'off-canvas-sidebars' ),
@@ -121,6 +128,30 @@ function register_general_settings() {
121128
'section_general',
122129
array( 'name' => 'background_color', 'description' => __( 'Choose a background color for the site container. Default: <code>#ffffff</code>.', 'off-canvas-sidebars' ) )
123130
);
131+
add_settings_field(
132+
'website_before_hook',
133+
esc_attr__( '"website_before" hook name', 'off-canvas-sidebars' ),
134+
array( $this, 'text_option' ),
135+
$this->general_key,
136+
'section_general',
137+
array( 'name' => 'website_before_hook', 'placeholder' => 'website_before' )
138+
);
139+
add_settings_field(
140+
'website_after_hook',
141+
esc_attr__( '"website_after" hook name', 'off-canvas-sidebars' ),
142+
array( $this, 'text_option' ),
143+
$this->general_key,
144+
'section_general',
145+
array( 'name' => 'website_after_hook', 'placeholder' => 'website_after' )
146+
);
147+
add_settings_field(
148+
'compatibility_position_fixed',
149+
esc_attr__( 'Compatibility for fixed elements', 'off-canvas-sidebars' ),
150+
array( $this, 'checkbox_option' ),
151+
$this->general_key,
152+
'section_general',
153+
array( 'name' => 'compatibility_position_fixed', 'label' => '('.__( 'Experimental', 'off-canvas-sidebars' ).')' )
154+
);
124155
}
125156

126157
function register_sidebar_settings( $sidebar ) {
@@ -150,6 +181,20 @@ function register_sidebar_settings( $sidebar ) {
150181
);
151182
}
152183

184+
/*
185+
* Specific fields
186+
*/
187+
function frontend_type_option( $args ) {
188+
$prefixes = $this->get_option_prefixes( $args );
189+
$prefixName = $prefixes['prefixName'];
190+
$prefixValue = $prefixes['prefixValue'];
191+
$prefixId = $prefixes['prefixId'];
192+
?><fieldset>
193+
<label><input type="radio" name="<?php echo $prefixName.'[frontend_type]'; ?>" id="<?php echo $prefixId.'_style_action'; ?>" value="action" <?php checked( $prefixValue['frontend_type'], 'action' ); ?> /> <?php _e( 'Actions', 'off-canvas-sidebars' ); echo ' (' . __( 'default', 'off-canvas-sidebars' ) . ')'; ?></label><br />
194+
<label><input type="radio" name="<?php echo $prefixName.'[frontend_type]'; ?>" id="<?php echo $prefixId.'_style_jquery'; ?>" value="jquery" <?php checked( $prefixValue['frontend_type'], 'jquery' ); ?> /> <?php _e( 'jQuery', 'off-canvas-sidebars' ); echo ' (' . __( 'experimental', 'off-canvas-sidebars' ) . ')' ?></label>
195+
</fieldset><?php
196+
}
197+
153198
function enabled_sidebars_option() {
154199
?><fieldset><?php
155200
$prefixName = esc_attr( $this->general_key ).'[sidebars]';
@@ -197,6 +242,30 @@ function sidebar_style( $args ) {
197242
}
198243
}
199244

245+
/*
246+
* General fields
247+
*/
248+
function text_option( $args ) {
249+
$prefixes = $this->get_option_prefixes( $args );
250+
$prefixName = $prefixes['prefixName'];
251+
$prefixValue = $prefixes['prefixValue'];
252+
$prefixId = $prefixes['prefixId'];
253+
$placeholder = '';
254+
if ( isset( $args['placeholder'] ) ) {
255+
$placeholder = ' placeholder="'.$args['placeholder'].'"';
256+
}
257+
if ( isset( $args['name'] ) ) {
258+
?><fieldset>
259+
<?php if ( isset( $args['label'] ) ) { ?><label><?php } ?>
260+
<input type="text" name="<?php echo $prefixName.'['.$args['name'].']'; ?>" id="<?php echo $prefixId.'_'.$args['name']; ?>" value="<?php echo $prefixValue[$args['name']]; ?>"<?php echo $placeholder ?>/>
261+
<?php if ( isset( $args['label'] ) ) { echo $args['label'] ?></label><?php } ?>
262+
<?php if ( isset( $args['description'] ) ) { ?>
263+
<p class="description"><?php echo $args['description'] ?></p>
264+
<?php } ?>
265+
</fieldset><?php
266+
}
267+
}
268+
200269
function checkbox_option( $args ) {
201270
$prefixes = $this->get_option_prefixes( $args );
202271
$prefixName = $prefixes['prefixName'];
@@ -288,10 +357,11 @@ function validate_input( $input ) {
288357
$output['sidebars'][$key]['enable'] = ( ! empty( $input['sidebars'][$key]['enable'] ) ) ? strip_tags( $input['sidebars'][$key]['enable'] ) : '0';
289358
}
290359

291-
$output['enable_frontend'] = ( ! empty( $input['enable_frontend'] ) ) ? strip_tags( $input['enable_frontend'] ) : '0';
292-
$output['site_close'] = ( ! empty( $input['site_close'] ) ) ? strip_tags( $input['site_close'] ) : '0';
293-
$output['hide_control_classes'] = ( ! empty( $input['hide_control_classes'] ) ) ? strip_tags( $input['hide_control_classes'] ) : '0';
294-
$output['scroll_lock'] = ( ! empty( $input['scroll_lock'] ) ) ? strip_tags( $input['scroll_lock'] ) : '0';
360+
$output['enable_frontend'] = $this->validate_checkbox( $input['enable_frontend'] );
361+
$output['site_close'] = $this->validate_checkbox( $input['site_close'] ) ;
362+
$output['hide_control_classes'] = $this->validate_checkbox( $input['hide_control_classes'] ) ;
363+
$output['scroll_lock'] = $this->validate_checkbox( $input['scroll_lock'] ) ;
364+
$output['compatibility_position_fixed'] = $this->validate_checkbox( $input['compatibility_position_fixed'] ) ;
295365

296366
// Allow 3 level arrays
297367
foreach ( $input as $key => $value ) {
@@ -312,6 +382,18 @@ function validate_input( $input ) {
312382

313383
return $output;
314384
}
385+
386+
/**
387+
* Validates checkbox values, used by validate_input
388+
*
389+
* @since 0.1.2
390+
*
391+
* @param string $value
392+
* @return string $value
393+
*/
394+
function validate_checkbox($value) {
395+
return ( ! empty( $value ) ) ? strip_tags( $value ) : '0';
396+
}
315397

316398
/**
317399
* Create admin menu page

js/fixed-scrolltop.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* Off-Canvas Sidebars plugin fixed-scrolltop.js
3+
*
4+
* Compatibility for fixed elements with Slidebars
5+
* @author Jory Hogeveen <[email protected]>
6+
* @package off-canvas-slidebars
7+
* @version 0.1.2
8+
*/
9+
;( function ( $ ) {
10+
11+
$(window).load(function () {
12+
13+
if ($('#sb-site').css('transform') != 'none') {
14+
var curScrollTopElements = $('#sb-site *').filter(function(){ return $(this).css('position') === 'fixed' });
15+
ocsScrollTopFixed();
16+
$(window).on('scroll resize', function() {
17+
curScrollTopElements;
18+
var newScrollTopElements = $('#sb-site *').filter(function(){ return $(this).css('position') === 'fixed' });
19+
curScrollTopElements = curScrollTopElements.add(newScrollTopElements);
20+
ocsScrollTopFixed();
21+
});
22+
}
23+
24+
function ocsScrollTopFixed() {
25+
curScrollTopElements;
26+
if (curScrollTopElements.length > 0) {
27+
var scrollTop = $(window).scrollTop();
28+
var winHeight = $(window).height();
29+
var conOffset = $('#sb-site').offset();
30+
var conHeight = $('#sb-site').outerHeight();
31+
curScrollTopElements.each(function(){
32+
if ($(this).css('position') == 'fixed') {
33+
var top = $(this).css('top');
34+
var bottom = $(this).css('bottom');
35+
if ( top == 'auto' && bottom != 'auto' ) {
36+
var px = (scrollTop + winHeight) - (conOffset.top + conHeight);
37+
} else {
38+
var px = scrollTop - conOffset.top;
39+
}
40+
$(this).css('-webkit-transform', 'translateY('+px+'px)');
41+
$(this).css('-moz-transform', 'translateY('+px+'px)');
42+
} else {
43+
$(this).css({'-webkit-transform' : ''});
44+
$(this).css({'-moz-transform' : ''});
45+
}
46+
});
47+
}
48+
}
49+
50+
});
51+
52+
} ) ( jQuery );

js/fixed-scrolltop.min.js

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/nav-menu.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
* Menu Meta Box scripts
55
* @author Jory Hogeveen <[email protected]>
66
* @package off-canvas-slidebars
7-
* @version 0.1
7+
* @version 0.1.2
88
*
99
* Credits to the Polylang plugin
1010
*/
1111

12-
jQuery(document).ready(function($) {
12+
;jQuery(document).ready(function($) {
1313

1414
$("input[value='#off_canvas_control'][type=text]").parent().parent().parent().parent().each( function() {
1515
$(this).addClass('off-canvas-control');

js/nav-menu.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
445 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)