![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Bean is a small, slick, cross-platform, framework-agnostic event utility designed for desktop, mobile, and touch-based browsers. In its simplest form - it works like this:
bean.add(element, 'click', function (e) {
console.log('hello');
});
Bean has four methods, each packing quite a punch.
add()
remove()
clone()
fire()
bean.add()
lets you attach event listeners to both elements and objects.
{1} element {DOM Element} an HTML DOM element
{2} event type(s) {String} an event (or multiple events) to listen to
{3} handler {Function} the callback function
{2,3} handlers {Object} a list of event keys with callback functions as the values
{4,n} optional args
// simple
bean.add(element, 'click', handler);
// optional arguments passed to handler
bean.add(element, 'click', function(e, o1, o2) {
console.log(o1, o2);
}, 'fat', 'ded');
// multiple events
bean.add(element, 'keydown keyup', handler);
// multiple handlers
bean.add(element, {
click: function (e) {},
mouseover: function (e) {},
'focus blur': function (e) {}
});
// event delegated events
bean.add(element, '.content p', 'click', handler, queryEngine);
(note: to use event delegation with a selector, you must pass bean.add a reference to a selector engine like qwery or sizzle) Developers working on Mobile Webkit applications like iPhone or Android, you may wish to simply provide the following query selector with Bean:
bean.add(element, '.content p', 'click', fn, function (selector) {
return document.querySelectorAll(selector);
});
Or alternatively, you can pass an array of elements (this actually cuts down on selector engine work, and is a more performant means of delegation if you know your DOM won't be changing:
bean.add(element, [el, el2, el3], 'click', handler);
//or
bean.add(element, $('.myClass'), 'click', handler);
(note: the focus, blur, and submit events will not delegate)
bean.add(element, 'click.fat', fn);
bean.add(element, 'click.ded', fn);
bean.add(element, 'click', fn);
//later...
bean.fire(element, 'click.ded');
bean.remove(element, 'click.fat');
//alternatively you can specify mutliple remove or fire handlers at once
bean.fire(element, 'click.ded.fat');
bean.remove(element, 'click.fat.ded');
bean.remove()
is how you get rid of listeners once you no longer want them. It's also a good idea to call remove on elements before you remove elements from your dom (this gives bean a chance to clean up some things and prevents memory leaks)
// remove a single event handlers
bean.remove(element, 'click', handler);
// remove all click handlers
bean.remove(element, 'click');
// remove multiple events
bean.remove(element, 'mousedown mouseup');
// remove all events
bean.remove(element);
bean.clone()
is a method for cloning events from one element to another.
// clone all events at once by doing this:
bean.clone(toElement, fromElement);
// clone events of a specific type
bean.clone(toElement, fromElement, 'click');
bean.fire()
gives you the ability to trigger events.
// fire a single event on an element
bean.fire(element, 'click');
// fire multiple types
bean.fire(element, 'mousedown mouseup');
Bean uses methods similar to Dean Edward's event model to ensure custom events behave like real events, rather than just callbacks.
For all intents and purposes, you can just think of them as native events, which will bubble up, and everything else you would expect...
use them like this:
bean.add(element, 'partytime', handler);
bean.fire(element, 'partytime');
Bean provides you with two custom DOM events, mouseenter
and mouseleave
. They are essentially just helpers for making your mouseover/mouseout lives a bit easier.
use them like regular events:
bean.add(element, 'mouseenter', handler);
Good news, everything you can do in bean with an element, you can also do with an object! This is particularly useful for working with classes or plugins.
var inst = new Klass();
bean.add(klass, 'complete', handler);
//later on...
bean.fire(inst, 'complete');
Bean passes our tests in all the following browsers. If you've found bugs in these browsers or others please let us know!
One of the great things about Bean is that it fixes a number of distinguishable browser differences and also provides proper cross-platform support for certain special events.
// normalized browser event model for default behavior and propagation
bean.add(el, 'click', function (e) {
e.preventDefault();
e.stopPropagation();
});
// DOMContentLoaded
bean.add(document, 'DOMContentLoaded', fn);
// mousewheel
bean.add(el, 'mousewheel', fn);
// mobile
bean.add(window, 'orientationchange', fn);
// touch events
bean.add(el, 'touchstart touchmove touchend touchcancel', fn);
// gestures
bean.add(el, 'gesturestart gesturechange gestureend', fn);
Bean uses JSHint to keep some house rules as well as UglifyJS for its compression. For those interested in building Bean yourself. Run make in the root of the project.
point your browser at bean/tests/index.html
If you use bean with ender it's API is greatly extended through it's Bridge file. This extension aims to give bean the look and feel of jQuery, but at the tiny size of bean.
Here's the run down of the method alias's added...
ADD EVENTS
$(element).on('click', fn);
$(element).addListener('click', fn);
$(element).bind('click', fn);
$(element).listen('click', fn);
REMOVE EVENTS
$(element).unbind('click');
$(element).unlisten('click');
$(element).removeListener('click');
DELEGATE EVENTS
$(element).delegate('.foo', fn);
$(element).undelegate('.foo');
CLONE EVENTS
$(element).cloneEvents('.foo', fn);
SPECIAL EVENTS
$(element).hover(enterfn, leavefn);
$(element).blur(fn);
$(element).change(fn);
$(element).click(fn);
$(element).dblclick(fn);
$(element).focusin(fn);
$(element).focusout(fn);
$(element).keydown(fn);
$(element).keypress(fn);
$(element).keyup(fn);
$(element).mousedown(fn);
$(element).mouseenter(fn);
$(element).mouseleave(fn);
$(element).mouseout(fn);
$(element).mouseover(fn);
$(element).mouseup(fn);
$(element).mousemove(fn);
$(element).resize(fn);
$(element).scroll(fn);
$(element).select(fn);
$(element).submit(fn);
$(element).unload(fn);
FAQs
A small, fast, framework-agnostic event manager
The npm package bean receives a total of 0 weekly downloads. As such, bean popularity was classified as not popular.
We found that bean demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.