Skip to content

Latest commit

History

35 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

bs-layer

A lightweight sliding layer system for jQuery and Bootstrap 5.
Supports stacking multiple layers, custom AJAX content, animation, and full keyboard support.

Features

  • Stackable sliding layers (like modals, but multi-level)
  • Smooth open/close animations
  • AJAX content loading support
  • Close all layers with a single call, stacked "top-down"
  • Callback support for all key events
  • Full Bootstrap 5 compatibility
  • Easily extensible with custom logic

Installation

Install with Composer (Bootstrap 5, Bootstrap-Icons & jQuery must be present):

composer require twbs/bootstrap twbs/bootstrap-icons components/jquery

Or include JS/CSS manually:

<linkhref="vendor/twbs/bootstrap-icons/font/bootstrap-icons.min.css" rel="stylesheet"><linkrel="stylesheet" href="vendor/twbs/bootstrap/dist/css/bootstrap.min.css"><scriptsrc="vendor/components/jquery/jquery.min.js"></script><scriptsrc="vendor/twbs/bootstrap/dist/js/bootstrap.bundle.min.js"></script><scriptsrc="dist/bs-layer.js"></script>

Getting Started

HTML Example:

<aid="layerLogin" data-url="login.html" href="#" class="btn btn-primary">
Open layer
</a>

JavaScript Usage:

// Initialize a layer triggerconstlayerLogin=$('#layerLogin').bsLayer({name: 'login-layer',// url: 'login.html',onPostBody: function($content){// Callback after content loaded}});// You can send your own events to the layer$.bsLayer.customEvent('login-layer','event-name', ...params);// Or close all layers with once$.bsLayer.closeAll();

API

Global Configuration

Global configuration options control the technical behavior and default appearance of all layers.
They are set on the $.bsLayer.config object and can be changed at runtime using $.bsLayer.setConfig().

These settings affect AJAX requests, default breakpoints, animation speed, stacking order, and icon classes.
Changes to the global config apply to all subsequently created layers unless overridden per-layer.

See the table below for all available global configuration options:

OptionTypeDefault / ExampleDescription
ajax.methodstring'GET'HTTP method used for AJAX requests (usually 'GET' or 'POST')
ajax.contentTypestring'application/x-www-form-urlencoded; charset=UTF-8'Content-Type for AJAX submissions
fullWidthBreakpointnumber576Below this window width (px), layers use 100% of width (Bootstrap 'sm' breakpoint)
firstLayerWithInPercentnumber0.80Percentage (e.g. 0.8 = 80%) of window width for first layer
distanceBetweenLayersnumber100Distance in px between stacked layers
animationDurationnumber600Show/hide animation duration in milliseconds
zIndexStartnumber1050z-index for bottom-most layer; each additional layer is placed higher
parentstring'body'CSS selector: Where layers are appended in the DOM
icons.closestring'bi bi-x-lg'Icon class for the close (X) button (Bootstrap Icons)
icons.refreshstring'bi bi-arrow-clockwise'Icon class for refresh button
icons.maximizestring'bi bi-arrows-angle-expand'Icon class for maximize button
icons.minimizestring'bi bi-arrows-angle-contract'Icon class for minimize button
onErrorfunctionfunction($message) {}Global error handler; called on AJAX or layer errors

Usage Example:

// Example: Centrally adjust global configuration for all layers$.bsLayer.setConfig({fullWidthBreakpoint: 768,// Default is 576, here changed to 768 pxanimationDuration: 400,// Layer animation now lasts 400 msicons: {close: 'bi bi-x',maximize: 'bi bi-fullscreen',minimize: 'bi bi-fullscreen-exit',refresh: 'bi bi-arrow-clockwise'}});// Optional: Overwrite the global onError callback function$.bsLayer.onError=function($msg){// Custom error handlingalert('Layer error: '+$msg);};

Layer Settings

Layer settings define the configuration and behavior of individual layers.
They can be passed when initializing a layer via $(selector).bsLayer(options) or set as data- attributes on the layer trigger element.

These settings control properties such as title, width, styles, AJAX URL, refreshability, closing/maximizing, and all event callbacks.
Any setting not explicitly defined will fall back to the global defaults.

See the table below for all available settings you can use per layer:

OptionTypeDefault / ExampleDescription
namestring'layer01'Unique layer name or identifier
titlestring/HTMLundefinedOptional: Layer title (can be string or HTML)
widthnumber/stringundefinedOptional: Width in px or as CSS string
bgStyleobject{ classes: 'text-dark', css: {...} }Style for background and text color (see below)
↳ classesstring'text-dark'Additional CSS classes for the layer
↳ cssobject{ background: ..., boxShadow: ..., ... }Inline CSS styles for the layer background
backdropbool/stringtrueShow backdrop: true, false, or 'static'
urlstring | Function (Promise)undefinedURL für AJAX-Inhalte oder Funktion/Promise für asynchronen Content. Falls eine Funktion verwendet wird, bekommt sie ein params-Objekt übergeben (die von queryParams zurückgegebenen/erweiterten Parameter). Die Funktion muss ein Promise zurückgeben, welches mit dem gewünschten Content (HTML/String oder Daten) aufgelöst wird.
closeablebooltrueShow close (X) button in header
expandablebooltrueAllow layer to be maximized
queryParamsfunction(params) => paramsModify AJAX query parameters
onAllfunctionfunction(eventName, ...args) {}Callback for all triggered events
onPostBodyfunctionfunction($content) {}After content is loaded
onShowfunctionfunction() {}Before layer is shown
onShownfunctionfunction() {}After layer is fully visible
onHidefunctionfunction() {}Before layer is hidden
onHiddenfunctionfunction() {}After layer is fully hidden
onRefreshfunctionfunction($content) {}When the layer is refreshed
onCustomEventfunctionfunction(eventName, ...params) {}For user-defined custom events

Usage Example:

$('#btnLayerExample').bsLayer({ajax: {method: 'POST'},name: 'example-layer',title: 'My Example Layer',width: 600,backdrop: true,url: 'example-content.php',refreshable: true,closeable: true,expandable: false,queryParams: function(params){params.userId=123;returnparams;},onShown: function($content){console.log('Layer wurde angezeigt');},onAll: function(eventName, ...args){console.log('Event:',eventName,args);}});// You can also supply a function to the `url` option that returns a Promise. This allows you to load dynamic content asynchronously, for example via an API call or any custom logic.// The function can be defined either as an `async` function or as a regular function returning a Promise. The most important point is that the return value is a Promise that resolves with the HTML/string content.$('#btnLayerExample').bsLayer({name: 'promise-layer',title: 'Async Content Layer',width: 600,backdrop: true,queryParams(params){// You can dynamically modify or extend parameters hereparams.id=1;params.token='demo-123';// Example: add extra parameterreturnparams;},// `url` as a Promise function: receives params and can use themurl: asyncfunction(params){// Example: use params for dynamic content or API callreturnnewPromise(function(resolve,reject){setTimeout(function(){// You can use params.id, params.token, etc. as neededresolve(`<div class="p-4"> <h3>Async loaded content 🚀</h3> <p>This content was loaded via Promise!</p> <div>Params: <code>${JSON.stringify(params)}</code></div> </div>`);},1000);});},refreshable: true,onShown: function($content){console.log('Async layer shown');}});

Plugin Methods

These instance methods can be called on any jQuery element that has been initialized as a layer trigger:

MethodParametersDescription
setTitletitleDynamically sets the layer’s title (as string or HTML) for the current trigger.
show...argsProgrammatically opens/displays the layer (simulates a click on the trigger element).
refreshoptions = {}Reloads or refreshes the layer content, e.g. via AJAX, using supplied options if any.
closenoneCloses/hides the layer that belongs to the current trigger element.

Usage Example:

$('#myLayerBtn').bsLayer('setTitle','New Title');$('#myLayerBtn').bsLayer('show');$('#myLayerBtn').bsLayer('refresh');$('#myLayerBtn').bsLayer('close');

License

Proprietary
See composer.json for author information.# bs-layerSlideMenu

About

A lightweight sliding layer system for jQuery and Bootstrap 5. Supports stacking multiple layers, custom AJAX content, animation, and full keyboard support.

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors