Socket
Socket
Sign inDemoInstall

browserify-widget

Package Overview
Dependencies
2
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    browserify-widget

Easily create html widgets with browserify


Version published
Maintainers
1
Install size
16.4 kB
Created

Readme

Source

browserify-widget

It makes it a bit easier to create html widgets with the help of browserify.

Usage

To create a widget you need this and the inherits module:

var Widget = require('browserify-widget');

var html = '<button id="like-button">Click to like</button><span class="text"></span>';

var events = {
    'like-button:click': function() {
        this.querySelector('.text').innerHTML = 'You like this!';
    }
}

var myWidget = Widget(html);
myWidget.addEvents(events);

You can avoid writing the html directly into your javascripts by using the brfs browserify transform.

API

The following functions are defined through browserify-widget:

.addEvents(events)

Register custom events. The keys are the css selector plus the event (without the 'on'), the value is the function which will be called when the event occurs on this element. The this of the to be called function is automatically set to the container element of the widget itself (remember: a widget can be rendered multiple times).

.addEvent(selector, fn)

Basically the same like .addEvents but with only one event.

.renderTo(el)

Render the widget into an existing DOM element. el can be an actual element or a selector.

.appendTo(el)

Appends the widget to a DOM element. el can be an actual element or a selector.

Keywords

FAQs

Last updated on 02 Jul 2014

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc