Commands - OwlTechnology/CommandPalette.js GitHub Wiki

When you add a command to the palette it instantly becomes searchable and run able from the palette.

##Adding Functions

Functions can be added to the palette as a command by doing the following after the palette is instantiated.
In this example we are using an anonymous function to alert "Hello" on the screen when a user submits "Hello" in the palette.

palette.on('Hello', function(){
     alert('hello'); //Alert hello on the screen
});

You can also use predefined functions.

function Hello(){
     alert('Hello');
}
palette.on('Hello', Hello);

##Adding Objects

Objects can be added to a command in place of a function. All methods of that object will automatically be mapped as sub commands. For example.

function Github(){

}
Github.prototype.push(){
     alert('push');
}
Github.prototype.commit(){
    alert('commit');
}

var bitbucket = {
   push: function(){
     alert('push')
   },
   commit: function(){
     alert('commit');
   }
}
var github = new Github();
palette.on('GitHub', github);
palette.on('BitBucket', bitbucket);

This will produce a command called "GitHub" with sub commands called "push" and "commit". Bitbucket will also do the same. This allows you to build object oriented processes without running out of naming conventions.

##Adding multiple actions Don't want to write out a command each time you need to add one? Me neither.
Just package up all your action names, functions and objects in a json and it's all added in one go.

palette.onAll({
     "Github": github,
     "BitBucket": bitbucket,
     "Hello": function(){
          alert('hello');
     }
});
⚠️ **GitHub.com Fallback** ⚠️