Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chrisbaldwinj/combinator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

combinator

Combinator is a small javascript library for application shortcuts. Combinator was written with the end user in mind, simple practice and simple syntax.

##Table of Contents

####Learn the basics:


####Latest Changes


####Downloads


####Support


#Learning The Basics

Setting Up

Setting up Combinator is very easy, first select which Combinator file you want, there are four. We have unminified Combinator with notes, minified Combinator, unminified Debugging Combinator, and minified Debugging Combinator. We separated the Debugging Combinator from the normal Combinator to save space for our users. Once you have the file you want, add it to the head of your document.

<head>
  <script src="directory/combinator.js"></script>
</head>

Then you can create and add another file for creating your shortcuts (combinators) and listen for them. By creating a separate document you simple save yourself hassle of debugging your own mistakes.

<script>
  commands.register("ctrl+x",{
    title:"Overwrite",
    exec:function(sequence) {
      //this = e of keydown event
      sequence("b",function(e){
        //e is the e of keydown event here
        //this is the object commands.cmd["ctrl+x"];
        console.log("Hello World");
      },document);
    },
    repeat: true,
    input: true,
    once: false,
    ignoreClass: null
  });
  
  //start the commands listener
  commands.listen();
</script>

Syntax

Register

combinator.register(keys,options);

keys is a pattern of keys to match against for example ctrl+x and must be a string format. options there are a set of options you must know to understand combinator.

exec The exec (execute) property is the main function that will be executed when your combinator is pressed. It takes one argument which is a sequence to listen for after.

Example:

exec:function(sequence) {
  sequence("a",function(e){
    //this = this command that is running so it returns the object
    console.log(e.target);
  },document);
}

sequence(key,callback[,target]);

sequence argument/function takes three properties, a key to listen for, a callback function, then a target that you want this key to be listened to on. Default target is document. For example if you were listening to the main command on document and you wanted to wait for a key in a textarea you could do as follows:

Example different listening targets:

"ctrl+b": {
  title:"mainListener",
  exec:function(sequence) {
    sequence("x",function(e){
      console.log(e);
    },document.getElementById("ourTextarea");
  }
}
...

combinator.listen(document);

This would be when you press ctrl+b in the document area and then pressed x while inside the element <textarea id="ourTextarea"></textarea> the developer console would then log the event object.

Listen

combinator.listen(target)

listen takes one argument, this is the target element you want to listen to. Default is document

Release

combinator.release(keys);

You MUST release a combinator set if you plan on overwriting it, we don't allow overwrites because this helps incase you forget some of your combinator sets.

Record

combinator.record(function[,target]);

Record is best used by caching the action in a variable, it returns an object so you can stop listening later on.

Example

  var recorder = combinator.record(function(keyLiteral, event){
    console.log(keyLiteral); //Enter
    console.log(event.which); // 13
  });
  recorder.stop();

keyLiteral is the literal translation in english of the key pressed. Some keys may be confusing such as the numerical keys, they will only return 0-9 and not it's alternative key i.e !@#$%^&*()

event is the event object returned on the keydown event.

fetch combinator.fetch(keys); Just like register this must be a pattern of keys to match against in string format, and must exists as a combinator set.

reset combinator.reset(keys); Just like register and fetch this must be a pattern of keys to match against in string format, and must exists as a combinator set.

trigger combinator.trigger(keys); Just like register,fetch, and reset this must be a pattern of keys to match against in string format, and must exists as a combinator set.

cmd combinator.cmd This property of combinator is very useful, you can grab your combinator sets like this, or you can also set them like this as well.

Example

combinator.cmd = {
    "ctrl+x":{
        title:"Overwrite",
        exec:function(sequence) {
            //this = e of keydown event
            sequence("b",function(e){
                //e is the e of keydown event here
                //this is the object commands.cmd["ctrl+x"];
                console.log("Hello World");
           },document);
        },
        repeat: true,
        input: true,
        once: false,
        ignoreClass: false
    }
};

Debugging If you have the Debugging Combinator you'll then get an extra property attached to combinator.

Example:

combinator.debug = true;

This turns debugging messages on through out the code helping you incase something is ary.


#Latest Changes

  • Added record functionality for ease of access to the user.
  • Fixed minor issues.

####Change Log


#Downloads

#Support

About

Combinator is a small javascript library for application shortcuts. Combinator was written with the end user in mind, simple practice and simple syntax.

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors