Skip to content

Latest commit

 

History

History
70 lines (59 loc) · 1.83 KB

js-extend.md

File metadata and controls

70 lines (59 loc) · 1.83 KB

$.createEvent()

This function allows you to create custom events and assign event handlers to them using the default jQuery on() method.

This example of creating a custom event is taken from custom-events

$.createEvent("enterkey", function (element, callback) {
    var $element = $(element);
    $element.on("keyup", function(e) {
        var code = (e.keyCode ? e.keyCode : e.which);
        if (code == 13) {
            callback();
        }
    });    
});

Here is an example of using the above custom event

$("input").on("enterkey", function(event) {
    console.log("enter key pressed : " + $(this).val());
});

debug

This allows you to add debug logging to your code and enable and disable it at any time through the browser console. (It means you can add debug code to your scripts and it won't be shown until you enable it.)

Also, when debugging is enabled all AJAX requests will be logged so you can inspect the data that was sent.

debug.enabled

Set or get whether to show debug messages or not

// get
console.log(debug.enabled);

// set
debug.enabled = true;

debug.dir()

As per console.dir() but only shown if debug is enabled

debug.dir(obj);

debug.error()

As per console.error() but only shown if debug is enabled

debug.error("An error occured in function x : " + arguments);

debug.log()

As per console.log() but only shown if debug is enabled

debug.log("Debug logging information");

debug.warn()

As per console.warn() but only shown if debug is enabled

debug.warn("This is a warning message.  You'll probably ignore it.");

queryString

Access values in the query string, similar to server-side languages.

console.log(queryString("name"));