Skip to content

Instantly share code, notes, and snippets.

@badabingbreda
Last active June 30, 2018 20:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save badabingbreda/53e2b78c61b31b30695605dbbbc80348 to your computer and use it in GitHub Desktop.
Save badabingbreda/53e2b78c61b31b30695605dbbbc80348 to your computer and use it in GitHub Desktop.
Jquery Plugin to extend the Beaver Builder Editor Sidepanel and Topbar
/*! BeaverBuilder Add Panel Option for jQuery v1.00
* http://www.badabing.nl/jquery-plugins/beaverbuilder-paneloptions/
* Do not remove any of this notice (you're welcome to use this code in commercial projects)
* Copyright (c) 2016 Didou Schol www.badabing.nl
* Licensed under the MIT license */
( function ( $ ) {
$.extend ({
bbAddPanel: function ( options ) {
// DEFAULT OPTIONS
var settings = $.extend({
html: null, // the html to insert or button text
location: 'panel', // panel (to the left) | bar (top)
position: 'after', // after | before | insertafter ; determine where to add the html or button
target: null, // node(s) to add html/button, leave empty to have plugin sort it out
style: 'section', // section | button
class: '' // button class for delegate callback
}, options );
// return early when nothing to insert
if (settings.html == null || settings.location == '' ) {
return this;
}
if ( settings.location == 'panel' ) {
// if target not set in options base it on location
if ( !settings.target ) settings.target = 'div.fl-builder-panel-content';
} else if ( settings.location == 'bar' ) {
// if target not set in options base it on location
if ( !settings.target ) settings.target = 'div.fl-builder-bar-actions span:nth-last-of-type(2)';
// reset position to insert after
settings.position = 'insertafter';
}
// if style is set to button change the behavior and asume the html is the button text
if ( settings.style == 'button' ) {
settings.html = '<span class="'+ settings.class + ' fl-builder-button">' + settings.html + '</span>';
} else if (settings.style == 'section' ) {
settings.html = '<div class="fl-builder-panel-info fl-builder-blocks-section"><div class="fl-builder-blocks-section-title custom-section">' +
settings.html + '</div></div>';
}
if ( settings.position == 'after' ) {
$( settings.html ).appendTo( settings.target );
} else if (settings.position == 'before' ) {
$( settings.html ).prependTo( settings.target );
} else if (settings.position == 'insertafter' ) {
$ (settings.html ).insertAfter( settings.target );
}
return this;
}
});
} ( jQuery ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment