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

jqueryp

v1.0.3

Published

Quickly create new jQuery plugins and chain together jQuery plugin requires.

Downloads

5

Readme

jqueryp

Quickly create new jQuery plugins and chain together jQuery plugin requires.

Getting Started

In the browser

Download the production version (vanilla or requirejs) or the development version (vanilla or requirejs).

Additionally, the chaining mechanism is available sans $.exportModule (production and development).

In your web page:

<script src="dist/jqueryp.min.js"></script>
<script>
$.exportModule('cornify', Cornifier);
$('div').cornify();
</script>

Documentation

jqueryp writes itself a method directly on the jQuery object. It can be accessed via $.exportModule or jQuery.exportModule.

/**
 * Function to easily add new jQuery plugins via a constructor function
 * @param {String} moduleName Name of the module
 * @param {Function} module Constructor function to bind under $()[moduleName]
 */

require.js extras

If you are using require.js, you will need to require(['jqueryp!'], function ($) { /* ... */ }); to access $.exportModule. The trailing ! is an artifact of jqueryp being a plugin.

The initial intent of jqueryp was to chain together requires of multiple jQuery plugin and still wind up with jQuery in the end. As a result, you can load in the jQuery plugins autocomplete, expand, modal via

require(['jqueryp!autocomplete!expand!ui'], function ($) {
  // Do stuff with $.fn.autocomplete
  // Do stuff with $.fn.expand
  // Do stuff with $.fn.modal
});

Examples

Setting up a new jQuery plugin

// Create a Toggle class
function Toggle(elt) {
  var $elt = $(elt),
      that = this;

  this.$elt = $elt;

  // When the element is clicked, toggle it
  $elt.on('click', function () {
    that.toggle();
  });
}
Toggle.prototype = {
  'toggle': function () {
    var $item = this.$item;

    // Toggle the class
    $item.toggleClass('is-selected');

    // Fire an event
    $item.trigger('toggle.toggle');
  }
};

// Export the Toggle class to $.fn
$.exportModule('toggle', Toggle);

Play around with click binding by constructor

// Enable toggling of table rows
var $rows = $('tr');
$rows.toggle();

// Click the first row
var $firstRow = $rows.first();
$firstRow.click();

// Assert the first row has the class 'is-selected'
$firstRow.hasClass('is-selected'); // true
$rows.last().hasClass('is-selected'); // false

Manually call prototyped methods

// Calling 'toggle' method of Toggle class
var $pseudoCheckboxes = $('.pseudo-checkbox');
$pseudoCheckboxes.toggle('toggle');

// The checkboxes are now checked
$pseudoCheckboxes.hasClass('is-selected'); // true

// Clicking them will uncheck them (as set up by constructor)
$pseudoCheckboxes.click();
$pseudoCheckboxes.hasClass('is-selected'); // false

require.js flavor allows for slick chaining of plugin dependencies

require(['jqueryp!autocomplete!expand!ui'], function ($) {
  $('input[type="text"]').autocomplete();
  $('.container-tall').expand();
  $('.modal').modal();
});

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

Also, please don't edit files in the "dist" or "stage" subdirectories as they are generated via grunt. You'll find source code in the "lib" subdirectory!

PhantomJS

While grunt can run the included unit tests via PhantomJS, this shouldn't be considered a substitute for the real thing. Please be sure to test the test/*.html unit test file(s) in actual browsers.

See the Why does grunt complain that PhantomJS isn't installed? guide in the Grunt FAQ for help with installing or troubleshooting PhantomJS.

License

Copyright (c) 2012 Ensighten Licensed under the MIT license.