Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
js-offcanvas
Advanced tools
jQuery accessible Offcanvas plugin, using ARIA
npm install js-offcanvas
yarn add js-offcanvas
Include the .css
and .js
files in your site.
<script src="js-offcanvas.pkgd.min.js"></script>
<link href="js-offcanvas.css" rel="stylesheet">
<script src="https://unpkg.com/js-offcanvas@1.2.8/dist/_js/js-offcanvas.pkgd.min.js"></script>
<link href="https://unpkg.com/js-offcanvas@1.2.8/dist/_css/prefixed/js-offcanvas.css" rel="stylesheet">
Offcanvas works on a container element with no styles applied.
<div class="c-offcanvas-content-wrap">
<a href="#offCanvas" id="triggerButton">Menu</a>
<!-- Your Main Content goes here -->
</div>
<aside id="offCanvas"></aside>
$('#offCanvas').offcanvas({
modifiers: 'left, overlay', // default options
triggerButton: '#triggerButton' // btn to open offcanvas
});
Include the CSS-Class js-offcanvas-trigger
and data-offcanvas-trigger="id-of-your-offcanvas"
<a class="js-offcanvas-trigger"
data-offcanvas-trigger="off-canvas-id"
href="#off-canvas">Menu</a>
Include the CSS-Class js-offcanvas
and data-offcanvas-options="{options}"
<aside class="js-offcanvas"
data-offcanvas-options='{"modifiers": "left,overlay"}'
id="off-canvas-id">...</aside>
// you have to trigger enhance
$( function(){
$(document).trigger("enhance");
});
$('#offCanvas').offcanvas({
role: "dialog",
modifiers: "left,overlay",
baseClass: "c-offcanvas",
modalClass: "c-offcanvas-bg",
contentClass: "c-offcanvas-content-wrap",
closeButtonClass: "js-offcanvas-close",
bodyModifierClass: "has-offcanvas",
supportNoTransitionsClass: "support-no-transitions",
resize: false,
triggerButton: '#triggerButton' ,
modal: true,
onOpen: function() {},
onClose: function() {},
onInit: function() {}
})
.on( "create.offcanvas", function( e ){ } )
.on( "open.offcanvas", function( e ){ } )
.on( "opening.offcanvas", function( e ){ } )
.on( "close.offcanvas", function( e ){ } )
.on( "closing.offcanvas", function( e ){ } )
.on( "resizing.offcanvas", function( e ){ } );
Set instance options by passing a valid object at initialization, or to the public defaults method. Custom options for a specific instance can also be set by attaching a data-offcanvas-options attribute to the target elment. This attribute should contain the properly formatted JSON object representing the custom options.
data-offcanvas-options='{ "modifiers": "left,overlay",... }'
Name | Default | Type |
---|---|---|
modifiers | "left,overlay" | string |
baseClass | "c-offcanvas" | string |
modalClass | "c-offcanvas-bg" | string |
contentClass | "c-offcanvas-content-wrap" | string |
closeButtonClass | "js-offcanvas-close" | string |
role | "dialog" | string |
bodyModifierClass | "has-offcanvas" | string |
supportNoTransitionsClass | "support-no-transitions" | string |
resize | false | boolean |
triggerButton | null | string |
onInit | null | function |
onOpen | null | function |
onClose | null | function |
The offcanvas API offers a couple of methods to control the offcanvas and are publicly available to all active instances.
var dataOffcanvas = $('#off-canvas').data('offcanvas-component');
open
dataOffcanvas.open();
close
dataOffcanvas.close();
toggle
dataOffcanvas.toggle();
onInit
Fires an event when offcanvas is initialized.
dataOffcanvas.onInit = function() {
console.log(this);
};
onOpen
Fires an event when offcanvas is opened.
dataOffcanvas.onOpen = function() {
console.log('Callback onOpen');
};
onClose
Fires an event when offcanvas is closed.
dataOffcanvas.onClose = function() {
console.log(this);
};
jQuery.offcanvas fires several events. Simply listen for them with the jQuery.on function. All events are namespaced with offcanvas.
beforecreate
Fires an event before the offcanvas is initialized.
$( document ).on( "beforecreate.offcanvas", function( e ){
var dataOffcanvas = $( e.target ).data('offcanvas-component');
console.log(dataOffcanvas);
dataOffcanvas.onInit = function() {
console.log(this);
};
} );
create
Fired once the Plugin is initialized.
$( document ).on( "create.offcanvas", function( e ){ } );
open
Fired when the open
method is called.
$( document ).on( "open.offcanvas", function( e ){ } );
close
Fired when the close
method is called.
$( document ).on( "close.offcanvas", function( e ){ } );
resizing
Fired when the window is resized.
$( document ).on( "resizing.offcanvas", function( e ){ } );
clicked
Fired when the trigger-btn is clicked.
$( document ).on( "clicked.offcanvas-trigger", function( e ){
var dataBtnText = $( e.target ).text();
console.log(e.type + '.' + e.namespace + ': ' + dataBtnText);
} );
Licensed under the MIT license.
FAQs
jQuery Accesible Offcanvas Panels
The npm package js-offcanvas receives a total of 3,097 weekly downloads. As such, js-offcanvas popularity was classified as popular.
We found that js-offcanvas demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.