Build your own plugin

A List.js plugin is basically a function/class which returns a object on initialization.

A basic example plugin

The plugin code list.awesomething.js

function ListAwesomething() {
  options = options || {};
  return {
    init: function(list) {
      // This method is called on initialization
    },
    name: options.name || "awesomething",
    customMethod: function() {
      return "cowabunga";
    }
  };
};

Using the plugin

<script src="list.js"></script>
<script src="list.awesomething.js"></script>
<script>
  var myList = new List('my-list', {
    plugins: ListAwesomething()
  });

  myList.awesomething.customMethod(); // cowabunga
</script>

Requirements / Specifications

  • A plugin namned Awesome Thing have to be in a JavaScript file namned list.awesomething.js (no dash, camelcase or anything) and the function/class have to be namned ListAwesomeThing (camelcase but no dash anything else).
  • The plugin object must contain an init method.
  • The plugin object must contain an name attribute that defaults to the plugin name.

Live example

Check this out!

<% locals.mediaTempleTerm = "plugin" %>