<?php
/**
* Plugin Name: Beaver Builder Sticky Column
* Plugin URI: https://sitespot.dev/resource/beaver-builder-sticky-column/
* Description: A Beaver Builder plugin that allows you to keep a module or row visible on the screen as long as it remains within its parent column. Works with Beaver Themer too.
* Version: 1.5.4
* Author: Sitespot Dev
* Author URI: https://sitespot.dev
* License: GPL2
Beaver Builder Sticky Column is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
any later version.
Beaver Builder Sticky Column is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Beaver Builder Sticky Column. If not, see https://www.gnu.org/licenses/gpl-3.0.en.html.
*/
require 'plugin-update-checker/plugin-update-checker.php';
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
'https://sitespot.dev/wp-content/uploads/bt-updates/Beaver Builder Sticky Column.json',
__FILE__,
'bb-sticky-column'
);
if(! class_exists ( 'Bt_Sticky_Column') && class_exists('FLBuilder'))
{
class Bt_Sticky_Column{
function __construct(){
//filters
add_filter( 'fl_builder_register_settings_form' , array($this,'add_sticky_settings'), 20 , 2 );
add_filter( 'fl_builder_column_attributes' , array( $this,'add_column_attributes'), 10, 2);
add_filter( 'fl_builder_row_attributes' , array( $this,'add_column_attributes'), 10, 2);
add_filter( 'wp_enqueue_scripts' , array($this,'bt_sticky_column_scripts'), 20 , 2 );
}
function add_sticky_settings( $form, $slug ) {
if ( 'col' === $slug || 'row' === $slug ) {
if($slug == 'col')
$label = 'Sticky Column';
if($slug == 'row')
$label = 'Sticky Row';
$form[ 'tabs' ][ 'advanced' ][ 'sections' ][ 'visibility' ][ 'fields' ][ 'sticky' ] = [
'type' => 'select',
'label' => $label,
'default' => 'false',
'options' => array(
'false' => __( 'No', 'fl-builder' ),
'true' => __( 'Yes - Sticky', 'fl-builder' )
),
'toggle' => array(
'true' => array(
'fields' => array( 'topMargin' )
),
'false' => array()
)
];
$form[ 'tabs' ][ 'advanced' ][ 'sections' ][ 'visibility' ][ 'fields' ][ 'topMargin' ] = [
'type' => 'unit',
'label' => 'Sticky item margin from top of browser',
'default' => '50',
'description' => 'px',
];
}
/**
* Now we pass back the form to the filter
*/
return $form;
}
function add_column_attributes( $attrs, $column ) {
// if there is a data sticky attribute set, then add the atts to the page
if ( isset( $column->settings->sticky ) && 'true' == $column->settings->sticky) {
$attrs[ 'bt-sticky' ] = $column->settings->sticky;
$attrs[ 'bt-sticky-top-margin' ] = $column->settings->topMargin;
}
return $attrs;
}
//enqueue js
function bt_sticky_column_scripts() {
wp_enqueue_script( 'sticky_script', plugin_dir_url( __FILE__ ) . 'js/sticky-column.js', array('jquery') );
wp_enqueue_style( 'sticky_style', plugin_dir_url( __FILE__ ) . 'css/sticky-column.css' );
}
}
$btsc = new Bt_Sticky_Column();
}