Skip to content
podefr edited this page Apr 4, 2012 · 1 revision

Olives comes with built-in plugins. But you can extend Olives funcitonalities by creating your own. Actually, a plugin is just an object. Any object can be a plugin, there are only two things to know:

###Creating your own plugin

A plugin is an object. You can literally create it {}, use Object.create, or a constructor function.

var myPlugin = {
  // This method will be available through a data- call
  // The first parameter will be the dom node. (1st thing to know)
  myMethod : function (node, param) {
    // The this object will always be the plugin (2nd thing to know)
    this.log(node.innerHTML + " " + param);
  },
 
  log: function (txt) {
    console.log(txt);
  }
}
<!-- When the UI will be rendered, it will console.log Hello world -->
<button data-myPlugin="myMethod:world">Hello</button>