
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
jquery-bridget
Advanced tools
Bridget makes a jQuery plugin out of a constructor :factory:
It's based off of the jQuery UI widget factory. Used for Masonry, Isotope, Packery, Flickity, Infinite Scroll, and Draggabilly.
A plugin constructor uses Prototypal pattern. It needs to have a ._init()
method used for its main logic.
// plugin constructor
// accepts two argments, element and options object
function NiceGreeter( element, options ) {
this.element = $( element );
this.options = $.extend( true, {}, this.options, options );
this._init();
}
// defaults for plugin options
NiceGreeter.prototype.options = {
greeting: 'hello',
recipient: 'world'
};
// main plugin logic
NiceGreeter.prototype._init = function() {
var message = this.getMessage();
this.element.text( message );
};
// getter method
NiceGreeter.prototype.getMessage = function() {
return this.options.greeting + ' ' + this.options.recipient;
};
Bridget can make this constructor work as a jQuery plugin. The namespace
is the plugin method - $elem.namespace()
.
// convert constructor to jQuery plugin
jQueryBridget( 'niceGreeter', NiceGreeter );
// optional: pass in jQuery variable
jQueryBridget( 'niceGreeter', NiceGreeter, jQuery );
// now the constructor can be used as a jQuery plugin
var $elem = $('#elem');
$elem.niceGreeter();
// >> h1 text will be 'hello world'
// set options
$elem.niceGreeter({
greeting: 'bonjour',
recipient: 'mon ami'
});
// >> text will be 'bonjour mon ami'
// access constructor instance via .data()
var myGreeter = $elem.data('niceGreeter');
Getter methods can still be used. For jQuery objects with multiple elements, getter methods will return the value of the first element.
Install with npm npm install jquery-bridget
Install with Yarn yarn add jquery-bridget
Bridget is released under the MIT license.
FAQs
Bridget makes jQuery widgets
The npm package jquery-bridget receives a total of 5,770 weekly downloads. As such, jquery-bridget popularity was classified as popular.
We found that jquery-bridget 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
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.