npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jquery-qbit

v0.0.7

Published

A jQuery plugin that provides dynamic loading of Javascript and HTML bits into a web page.

Downloads

10

Readme

Qbit

A jQuery plugin that provides dynamic loading of Javascript and HTML bits into a web page. It is intended as a simple component loader for jQuery based applications.

Each Qbit compnent that is developed can be easily reused throughout an application or provided as a package to be downloaded and used in other applicatons.

Each Qbit consists of a bit of Javascript and may include a bit of HTML. The default path for the Qbits is in a directory named 'qbits' in the hosted web application's directory. And each Qbit will have a sub-directory named after the Qbit. I.E. a time and tzselect Qbit may have the following directory structure...

public_html/
+-- qbits/
    +-- time/
        +-- index.js
        +-- index.html
    +-- tzselect/
        +-- index.js
        +-- index.html

Requirements

  • jQuery

Install

Download the Qbit project.

Copy the qbit.js plugin source file to your HTML application directory.

Include script tags in your HTML to load the jQuery and Qbit libraries.

I.E.

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="js/qbit.js"></script>

Create the qbits directory in your hosted directory and copy the Qbits you plan on using into the qbits directory.

Usage

After the install is complete you then edit your web page and call the qbit plugin on selected elements with the name of the Qbit to load into the selected elements.

I.E. Here we load the example Qbit into every element with the class name 'example'...

<div class="example"></div> <span class="example"></span>

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="js/qbit.js"></script>
<script>
$(document).ready(function () {
  // load the example qbit into elements with the example class name
  $('.example').qbit('example');
});
</script>

A Qbit may accept additional parameters and/or arguments. See the documentation for the Qbit to get details on how to use the Qbit. The folllowing example loads the time Qbit into an element and passes a timezone argument...

<div id="current_time"></div>

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="js/qbit.js"></script>
<script>
$(document).ready(function () {
  // load the example qbit into elements with the example class name
  $('#current_time').qbit('time', { timeZone: "America/New_York" });
});
</script>

Developing Qbits

New Qbits can be created by creating a new sub-directory in the qbits path and naming the directory after the new Qbit. Then create the index.js and index.html files for the new Qbit in the directory.

The example Qbit is a good starting point to see how the index.js is developed. The example Qbit is the simplest type of Qbit and only loads the contents of the index.html into the selected elements...

// example Qbit
(function ($) {
  var defaults = {};

  // Qbit constructor
  var Qbit = function (element, jqbit) {
    // build settings from defaults and arguments passed to the jQuery qbit
    var settings = this.settings = $.extend({}, defaults, jqbit.args);

    // use jQuery qbit to load the Qbit HTML
    jqbit.loadHTML(function () {
      // actions to take after Qbit HTML is loaded
    });
  }

  // Qbit methods
  $.extend(Qbit.prototype, {
    // additional methods attached to new instances of this Qbit
  });

  // add Qbit qbit plugin list
  $.fn.qbit.addQbitToList('example', Qbit);
})(jQuery);

When the web page requests this Qbit the jQuery plugin will load the index.js if it has not yet been loaded, it then creates a new instance of the Qbit method from the index.js for each element, and then calls the Qbit constructor on each element while passing the element and a reference to the jQuery qbit plugin instance that is creating the Qbit.

In this example Qbit the constructor creates a settings object from the components defaults and any arguments passed by the jQuery qbit plugin. The constructor then uses the loadHTML() method from the jQuery qbit plugin to load the index.html that is associated with the example Qbit.

Each Qbit must include the Qbit constructor function and must call the $.fn.qbit.addQbitToList() method at the end of loading the index.js file to inform the jQuery qbit plugin that the Qbit is loaded and ready for use.