GithubHelp home page GithubHelp logo

browserify-widget's Introduction

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.

browserify-widget's People

Contributors

maxgfeller avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.