• Stars
    star
    141
  • Rank 251,984 (Top 6 %)
  • Language
    JavaScript
  • Created over 14 years ago
  • Updated almost 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JavaScript widget toolkit, for the creation and distribution of third-party web widgets.

Sqwidget

Sqwidget is a framework for adding components to a page in a way that ensures they are self contained and namespaced. It is great for buliding third party widgets.

A typical embed code looks like the following:

<div data-sqwidget data-sqwidget-url="//example.com/my-widget"></div>
<script src="//example.com/sqwidget.js"></script>

Features

  1. Easy configurations and customisations: An embed code can have any number of optional parameters that are passed to the constructer your widget.
  2. Sandboxed JavaScript: All your JS is completely sandboxed from the rest of page not allowing you to leak any globals by default. It uses RequireJS to call your widget.
  3. Widgets are RequireJS modules.
  4. Yeoman Generator: A Yeoman generator allows you to scaffold your widget very quickly. The scaffold includes some libraries that we've found great for building high-performance widgets:
    1. RactiveJS
    2. Lodash
    3. RequireJS

The only hard dependency is RequireJS, since sqwidget expects to find a RequireJS module to initialise.

Getting Started

The easiest way to get started with using Sqwidget in your project is to use the Yeoman generator that builds a project layout for you.

First, install Yeoman using:

$ npm install -g yo

Next, install the sqwidget-generator:

$ npm install -g generator-sqwidget

Finally, initiate your project in a new directory where you want to create your widget:

$ mkdir my-awesome-project
$ cd my-awesome-project
$ yo sqwidget

This will create your project for you and install all the dependencies. See your widget in action by doing:

$ grunt

The Basic Widget

At the minimum, your widget will have a src/main.js which is a RequireJS module. This module should return a function that accepts one options parameter (object).

Example:

define([], function() {
    return function(options) {
        // DOM element to append your content is available at options.el
        // Config params are available at options.config
    };
});

Configuration and Custom Parameters

The embed code can also accept any number of parameters like:

<div data-sqwidget data-sqwidget-url="//example.com/my-widget"
    data-sqwidget-title="My Title" data-sqwidget-user="johndoe"
    data-sqwidget-age="20"></div>

All parameters that begin with data-sqwidget- will be passed to the function called in your widget during initialisation.

In this case, the options object from above will have a config object that looks like:

options = {
    el: <DOM NODE>,
    config = {
        "title": "My Title",
        "user": "johndoe",
        "age": "20"
    },
    ...

Development

Building sqwidget

npm install grunt-cli -g
npm install bower -g
bower install
npm install
grunt test

More Repositories

1

cleanslate

An extreme CSS reset stylesheet, for aggressively resetting the styling of an element and its children. Composed exclusively of CSS !important rules.
CSS
608
star
2

pablo

Pablo is a lightweight, expressive JavaScript SVG library. Pablo creates interactive drawings with SVG (Scalable Vector Graphics), giving access to all of SVG's granularity and power.
JavaScript
409
star
3

tim

A tiny, secure JavaScript micro-templating script.
JavaScript
250
star
4

sandie

Create a new JavaScript context within the browser. This allows external scripts to be loaded and arbitrary JavaScript to be executed without affecting the global scope. Potential conflicts between scripts are avoided via the sandbox of a 'sourceless' iframe document.
JavaScript
73
star
5

appleofmyiframe

JavaScript library for creating & manipulating 'sourceless' iframe documents (i.e. those without an external document src); jQuery plugin.
JavaScript
58
star
6

nitelite

A low-level Lightbox plugin for jQuery.
JavaScript
18
star
7

important

css !important manipulator (jQuery plugin)
JavaScript
13
star
8

cmd.js

A lightweight, asynchronous flow controller / file loader
JavaScript
11
star
9

mishmash

An assortment of little JavaScript functions, snippets and jQuery plugins. Stuff that doesn't warrant its own repository, but is too big or important for a gist.
JavaScript
10
star
10

theywriteforyou

Data journalism mashup, showing the number of articles by MPs in British newspapers.
JavaScript
9
star
11

sqweeze

A command line web asset optimisation and packaging tool.
Ruby
5
star
12

js1k

1KB JavaScript apps ~ #1: Phi
JavaScript
5
star
13

carboncopies

Carbon matching game for the Rewired State "Carbon & Energy Hack Day"
PHP
5
star
14

revolutionaries

@sciencehackday hack - an explorer of the evolution of great scientific inventors, thinkers and their discoveries
JavaScript
5
star
15

planetjs

Planet websites (RSS/Atom feed aggregator), in JavaScript
JavaScript
4
star
16

promisespromises

JavaScript
4
star
17

localbusiness

An experiment in visualising council payments data
JavaScript
2
star
18

allsizes

AllSizes is a (Greasemonkey) UserScript for Flickr, to give better access to Flickr photos: HTML for the various sizes, URLs, downloads.
JavaScript
2
star
19

adobe-prices

Data visualisation of Adobe's software prices across different countries
JavaScript
1
star
20

10ktrees

JavaScript
1
star
21

jasonpeewee

JavaScript
1
star