diff --git a/.gitignore b/.gitignore
index bc88642..476d211 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,4 +2,6 @@ kis-custom.js
kis-custom-min.js
combine-build.php
test.html
-.*
\ No newline at end of file
+config.json
+docs.conf
+.*
diff --git a/README.md b/README.md
index 499c6d0..d08c4a0 100755
--- a/README.md
+++ b/README.md
@@ -25,31 +25,28 @@ Browser support: IE10+, Latest versions of Firefox, Chrome, Safari, Opera
* each: For applying changes to every item matched by a selector
- $_(selector).each(callback);
+ $_(selector).each(callback);
Example :
- $_(".foo").each(function(e){
+ $_(".foo").each(function(e){
$_(e).dom.text(value);
}):
* ext: For extending the library, adds this.el to the object or function supplied
-
- $_.ext("name", functionOrObject);
-
+ $_.ext("name", functionOrObject);
Example:
- $_.ext("zip", function(){ //function });
- Adds 'zip' function to $_.
+ $_.ext("zip", function(){ ... }); // Adds 'zip' function to $_.
* type: For getting the type of a variable
$_.type(var);
-Have a look at the /docs folder included with the library for documentation on the included modules. The development version of the documentation is avaliable at
+Have a look at the right sidebar of the docs included with the library for documentation on the included modules. The development version of the documentation is avaliable at
[http://github.timshomepage.net/kis-js/docs/](http://github.timshomepage.net/kis-js/docs/)
diff --git a/docs/$_.dom.html b/docs/$_.dom.html
index 21888a3..fc12ad9 100644
--- a/docs/$_.dom.html
+++ b/docs/$_.dom.html
@@ -313,7 +313,7 @@ selector
Source:
@@ -340,7 +340,7 @@ selector
Example
- $_("ul").dom.append("<li></li>") adds an li element to the end of the selected ul element
+ $_("ul").dom.append("<li></li>"); // Adds an li element to the end of the selected ul element
@@ -720,6 +720,13 @@ multiple key/value pairs.
+ Examples
+
+ $_('#foo').dom.css('border', 0);
+
+ $_('#foo').dom.css({background:'#000', color:'#fff'});
+
+
@@ -899,7 +906,7 @@ multiple key/value pairs.
Source:
@@ -1036,7 +1043,7 @@ multiple key/value pairs.
Source:
@@ -1061,6 +1068,11 @@ multiple key/value pairs.
+ Example
+
+ $_("ul").dom.append("<li></li>"); // Adds an li element to the beginning of the selected ul element
+
+
@@ -1493,7 +1505,7 @@ otherwise it will return the value of the current element
- Documentation generated by JSDoc 3.3.0-alpha9 on Fri Sep 12 2014 16:11:50 GMT-0400 (EDT)
+ Documentation generated by JSDoc 3.3.0-alpha9 on Tue Sep 16 2014 16:57:40 GMT-0400 (EDT)
diff --git a/docs/$_.event.html b/docs/$_.event.html
index 5f298e9..100a1ac 100644
--- a/docs/$_.event.html
+++ b/docs/$_.event.html
@@ -242,7 +242,7 @@ event and selector
Example
- Eg. $_("#selector").event.add("click", do_something());
+ $_("#selector").event.add("click", do_something());
@@ -427,7 +427,7 @@ event and selector
Example
- Eg. var event = $_("#selector").event.create('foo', {});
+ var event = $_("#selector").event.create('foo', {});
@@ -597,7 +597,7 @@ event and selector
Example
- Eg. $_("#parent").delegate(".button", "click", do_something());
+ $_("#parent").delegate(".button", "click", do_something());
@@ -767,7 +767,7 @@ event and selector
Example
- Eg. $_.event.live(".button", "click", do_something());
+ $_.event.live(".button", "click", do_something());
@@ -914,7 +914,7 @@ event and selector
Example
- Eg. $_("#selector").event.remove("click", do_something());
+ $_("#selector").event.remove("click", do_something());
@@ -1056,7 +1056,7 @@ event and selector
Example
- Eg. $_("#my_id").trigger('click');
+ $_("#my_id").trigger('click');
@@ -1083,7 +1083,7 @@ event and selector
- Documentation generated by JSDoc 3.3.0-alpha9 on Fri Sep 12 2014 16:11:50 GMT-0400 (EDT)
+ Documentation generated by JSDoc 3.3.0-alpha9 on Tue Sep 16 2014 16:57:40 GMT-0400 (EDT)
diff --git a/docs/$_.html b/docs/$_.html
index 7a2fd1d..90cc87d 100644
--- a/docs/$_.html
+++ b/docs/$_.html
@@ -66,7 +66,7 @@ Constructor function
Source:
@@ -108,6 +108,66 @@ Constructor function
+ Members
+
+
+
+
+ (static) el
+
+
+
+
+
+
+ Current selector object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Methods
@@ -247,7 +307,7 @@ Constructor function
Source:
@@ -290,6 +350,230 @@ Constructor function
+
+
+
+
+
+ (static) delete(url, data, success_callback, error_callbackopt )
+
+
+
+
+
+
+
+ Sends a DELETE type ajax request
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+ Attributes
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ url
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ The url to post to
+
+
+
+
+
+
+ data
+
+
+
+
+
+Object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ delete parameters to send
+
+
+
+
+
+
+ success_callback
+
+
+
+
+
+function
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ callback called on success
+
+
+
+
+
+
+ error_callback
+
+
+
+
+
+function
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+ callback called if there is an error
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -384,7 +668,7 @@ Constructor function
Source:
@@ -409,6 +693,158 @@ Constructor function
+ Example
+
+ $_('form input').each(function(item) { alert(item) });
+
+
+
+
+
+
+
+ (static) ext(name, obj)
+
+
+
+
+
+
+
+ Adds the property `obj` to the $_ object, calling it `name`
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ name
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+ name of the module
+
+
+
+
+
+
+ obj
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+ the object to add
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Example
+
+ $_.ext('foo', {});
+
+
@@ -608,7 +1044,7 @@ Constructor function
Source:
@@ -832,7 +1268,7 @@ Constructor function
Source:
@@ -857,6 +1293,372 @@ Constructor function
+
+
+
+
+
+ (static) put(url, data, success_callback, error_callbackopt )
+
+
+
+
+
+
+
+ Sends a PUT type ajax request
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+ Attributes
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ url
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ The url to post to
+
+
+
+
+
+
+ data
+
+
+
+
+
+Object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ PUT parameters to send
+
+
+
+
+
+
+ success_callback
+
+
+
+
+
+function
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ callback called on success
+
+
+
+
+
+
+ error_callback
+
+
+
+
+
+function
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+
+ callback called if there is an error
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ (static) type(obj) → {string}
+
+
+
+
+
+
+
+ Retrieves the type of the passed variable
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ obj
+
+
+
+
+
+*
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+
+
+
+ Type
+
+
+
+string
+
+
+
+
+
+
+
+
+ Example
+
+ $_.type([]); // Returns 'array'
+
+
@@ -881,7 +1683,7 @@ Constructor function
- Documentation generated by JSDoc 3.3.0-alpha9 on Fri Sep 12 2014 16:11:50 GMT-0400 (EDT)
+ Documentation generated by JSDoc 3.3.0-alpha9 on Tue Sep 16 2014 16:57:40 GMT-0400 (EDT)
diff --git a/docs/$_.store.html b/docs/$_.store.html
index f31f2a5..992ae4d 100644
--- a/docs/$_.store.html
+++ b/docs/$_.store.html
@@ -848,7 +848,7 @@ and JSON-encodes the value if not a string
- Documentation generated by JSDoc 3.3.0-alpha9 on Fri Sep 12 2014 16:11:50 GMT-0400 (EDT)
+ Documentation generated by JSDoc 3.3.0-alpha9 on Tue Sep 16 2014 16:57:40 GMT-0400 (EDT)
diff --git a/docs/DOM.js.html b/docs/DOM.js.html
index 6c1548d..9ffab0a 100644
--- a/docs/DOM.js.html
+++ b/docs/DOM.js.html
@@ -250,6 +250,8 @@
* Accepts either key/value arguments, or an object with
* multiple key/value pairs.
*
+ * @example $_('#foo').dom.css('border', 0);
+ * @example $_('#foo').dom.css({background:'#000', color:'#fff'});
* @name css
* @memberOf $_.dom
* @function
@@ -283,7 +285,7 @@
/**
* Adds to the innerHTML of the current element, after the last child.
*
- * @example $_("ul").dom.append("<li></li>") adds an li element to the end of the selected ul element
+ * @example $_("ul").dom.append("<li></li>"); // Adds an li element to the end of the selected ul element
* @name append
* @memberOf $_.dom
* @function
@@ -296,6 +298,7 @@
/**
* Adds to the innerHTML of the selected element, before the current children
*
+ * @example $_("ul").dom.append("<li></li>"); // Adds an li element to the beginning of the selected ul element
* @name prepend
* @memberOf $_.dom
* @function
@@ -345,7 +348,7 @@
- Documentation generated by JSDoc 3.3.0-alpha9 on Fri Sep 12 2014 16:11:50 GMT-0400 (EDT)
+ Documentation generated by JSDoc 3.3.0-alpha9 on Tue Sep 16 2014 16:57:40 GMT-0400 (EDT)
diff --git a/docs/ajax.js.html b/docs/ajax.js.html
index 0a305b3..59dd5a0 100644
--- a/docs/ajax.js.html
+++ b/docs/ajax.js.html
@@ -35,7 +35,7 @@
"use strict";
var ajax = {
- _do: function (url, data, success_callback, error_callback, isPost)
+ _do: function (url, data, success_callback, error_callback, type)
{
var type,
request = new XMLHttpRequest();
@@ -48,8 +48,6 @@
success_callback = function (){};
}
- type = (isPost) ? "POST" : "GET";
-
if (type === "GET")
{
url += (url.match(/\?/))
@@ -78,7 +76,7 @@
}
};
- if (type === "POST")
+ if (type !== "GET")
{
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.send(this._serialize(data));
@@ -123,8 +121,7 @@
/**
* Sends a GET type ajax request
*
- * @name get
- * @function
+ * @function get
* @memberOf $_
* @param {string} url - The url to retrieve
* @param {Object} data - get parameters to send
@@ -132,14 +129,13 @@
* @param {function} [error_callback] - callback called if there is an error
*/
$_.ext('get', function (url, data, success_callback, error_callback){
- ajax._do(url, data, success_callback, error_callback, false);
+ ajax._do(url, data, success_callback, error_callback, 'GET');
});
/**
* Sends a POST type ajax request
*
- * @name post
- * @function
+ * @function post
* @memberOf $_
* @param {string} url - The url to post to
* @param {Object} data - post parameters to send
@@ -147,7 +143,35 @@
* @param {function} [error_callback] - callback called if there is an error
*/
$_.ext('post', function (url, data, success_callback, error_callback){
- ajax._do(url, data, success_callback, error_callback, true);
+ ajax._do(url, data, success_callback, error_callback, 'POST');
+ });
+
+ /**
+ * Sends a PUT type ajax request
+ *
+ * @function put
+ * @memberOf $_
+ * @param {string} url - The url to post to
+ * @param {Object} data - PUT parameters to send
+ * @param {function} success_callback - callback called on success
+ * @param {function} [error_callback] - callback called if there is an error
+ */
+ $_.ext('put', function (url, data, success_callback, error_callback){
+ ajax._do(url, data, success_callback, error_callback, 'PUT');
+ });
+
+ /**
+ * Sends a DELETE type ajax request
+ *
+ * @function delete
+ * @memberOf $_
+ * @param {string} url - The url to post to
+ * @param {Object} data - delete parameters to send
+ * @param {function} success_callback - callback called on success
+ * @param {function} [error_callback] - callback called if there is an error
+ */
+ $_.ext('delete', function (url, data, success_callback, error_callback){
+ ajax._do(url, data, success_callback, error_callback, 'DELETE');
});
}());
@@ -166,7 +190,7 @@
- Documentation generated by JSDoc 3.3.0-alpha9 on Fri Sep 12 2014 16:11:50 GMT-0400 (EDT)
+ Documentation generated by JSDoc 3.3.0-alpha9 on Tue Sep 16 2014 16:57:40 GMT-0400 (EDT)
diff --git a/docs/core.js.html b/docs/core.js.html
index 6b45804..a4e13ae 100644
--- a/docs/core.js.html
+++ b/docs/core.js.html
@@ -29,13 +29,19 @@
Kis JS Keep It Simple JS Library
Copyright Timothy J. Warren
License Public Domain
- Version 0.8.0
+ Version 0.9.0
*/
(function (undefined){
"use strict";
- var $_, $, sel;
+ /**
+ * Current selector object
+ *
+ * @memberOf $_
+ * @name el
+ */
+ var sel;
/**
@@ -49,7 +55,7 @@
* @param {Object} [context] - Context of the dom selector string
* @return {Object}
*/
- $_ = function(s, context)
+ var $_ = function(s, context)
{
// Have documentElement be default selector, just in case
if (s === undefined)
@@ -92,7 +98,7 @@
* @param {Object} [context]
* @return {Object}
*/
- $ = function (selector, context)
+ var $ = function (selector, context)
{
var elements;
@@ -120,6 +126,9 @@
/**
* Adds the property `obj` to the $_ object, calling it `name`
*
+ * @memberOf $_
+ * @function ext
+ * @example $_.ext('foo', {});
* @param {string} name - name of the module
* @param {object} obj - the object to add
*/
@@ -132,11 +141,12 @@
/**
* Iterates over a $_ object, applying a callback to each item
*
- * @name $_.each
- * @function
+ * @memberOf $_
+ * @function each
+ * @example $_('form input').each(function(item) { alert(item) });
* @param {function} callback - iteration callback
*/
- $_.ext('each', function (callback)
+ $_.ext('each', function(callback)
{
if(sel.length !== undefined && sel !== window)
{
@@ -151,10 +161,13 @@
/**
* Retrieves the type of the passed variable
*
+ * @memberOf $_
+ * @function type
+ * @example $_.type([]); // Returns 'array'
* @param {*} obj
* @return {string}
*/
- $_.type = function(obj)
+ var type = function(obj)
{
if((function() {return obj && (obj !== this)}).call(obj))
{
@@ -169,8 +182,8 @@
//Set global variables
$_ = window.$_ = window.$_ || $_;
$_.$ = $;
-}());
-
+ $_.type = type;
+}());
@@ -186,7 +199,7 @@
- Documentation generated by JSDoc 3.3.0-alpha9 on Fri Sep 12 2014 16:11:50 GMT-0400 (EDT)
+ Documentation generated by JSDoc 3.3.0-alpha9 on Tue Sep 16 2014 16:57:40 GMT-0400 (EDT)
diff --git a/docs/event.js.html b/docs/event.js.html
index 30c5d82..58c48cb 100644
--- a/docs/event.js.html
+++ b/docs/event.js.html
@@ -105,7 +105,7 @@
* @memberOf $_.event
* @name create
* @function
- * @example Eg. var event = $_("#selector").event.create('foo', {});
+ * @example var event = $_("#selector").event.create('foo', {});
* @param {string} name
* @param {object} [data]
* @return {Object}
@@ -113,12 +113,12 @@
create: function(name, data)
{
data = data || {};
-
- // Okay, I guess we have to do this the hard way... :(
- var e = document.createEvent('CustomEvent');
- e.initCustomEvent(name, true, true, data);
- return e;
+ // Okay, I guess we have to do this the hard way... :(
+ var e = document.createEvent('CustomEvent');
+ e.initCustomEvent(name, true, true, data);
+
+ return e;
},
/**
* Adds an event that returns a callback when triggered on the selected
@@ -127,7 +127,7 @@
* @memberOf $_.event
* @name add
* @function
- * @example Eg. $_("#selector").event.add("click", do_something());
+ * @example $_("#selector").event.add("click", do_something());
* @param {string} event
* @param {function} callback
*/
@@ -143,7 +143,7 @@
* @memberOf $_.event
* @name remove
* @function
- * @example Eg. $_("#selector").event.remove("click", do_something());
+ * @example $_("#selector").event.remove("click", do_something());
* @param {string} event
* @param {string} callback
*/
@@ -159,7 +159,7 @@
* @memberOf $_.event
* @name live
* @function
- * @example Eg. $_.event.live(".button", "click", do_something());
+ * @example $_.event.live(".button", "click", do_something());
* @param {string} target
* @param {string} event
* @param {function} callback
@@ -174,7 +174,7 @@
* @memberOf $_.event
* @name delegate
* @function
- * @example Eg. $_("#parent").delegate(".button", "click", do_something());
+ * @example $_("#parent").delegate(".button", "click", do_something());
* @param {string} target
* @param {string} event
* @param {function} callback
@@ -191,14 +191,13 @@
* @memberOf $_.event
* @name trigger
* @function
- * @example Eg. $_("#my_id").trigger('click');
+ * @example $_("#my_id").trigger('click');
* @param {object} event
* @return {boolean}
*/
trigger: function(event)
{
- var target = this.el;
- return target.dispatchEvent(event);
+ return this.el.dispatchEvent(event);
}
};
@@ -220,7 +219,7 @@
- Documentation generated by JSDoc 3.3.0-alpha9 on Fri Sep 12 2014 16:11:50 GMT-0400 (EDT)
+ Documentation generated by JSDoc 3.3.0-alpha9 on Tue Sep 16 2014 16:57:40 GMT-0400 (EDT)
diff --git a/docs/global.html b/docs/global.html
index 54090dc..3702bb5 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -81,6 +81,8 @@
+
+
@@ -89,20 +91,30 @@
- data[undefined]
+ el :Object
- Ajax
+ $_
-Module for making ajax requests
+Constructor function
+ Type:
+
+
@@ -127,7 +139,7 @@ Module for making ajax requests
Source:
@@ -162,13 +174,13 @@ Module for making ajax requests
- Namespaces Global
+ Namespaces Global
- Documentation generated by JSDoc 3.3.0-alpha5 on Wed Sep 10 2014 00:23:43 GMT-0400 (EDT)
+ Documentation generated by JSDoc 3.3.0-alpha9 on Tue Sep 16 2014 15:49:39 GMT-0400 (EDT)
diff --git a/docs/index.html b/docs/index.html
index 69f35f9..883dbb0 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -40,96 +40,48 @@
+
+ Keep It Simple JS Library A Minimal, Modular Javascript library for Modern browsers.
+Aims to be fast, small, and easily split into individual modules.
+You can create your own library by adding and removing modules from the
+src directory, and running the "combine.php" script. This will output a
+"kis-custom.js" file. (Be careful, as the script will overwrite any "kis-custom.js"
+file that already exists).
+Browser support: IE10+, Latest versions of Firefox, Chrome, Safari, Opera
+Basic Use:
+Function: $_(selector).module.function(params);
+
+Core Methods properties:
+
+el: The html object returned by the selector function.
+
+functions:
+
+each: For applying changes to every item matched by a selector
+ $_(selector).each(callback);
+ Example :
+ $_(".foo").each(function(e){
+ $_(e).dom.text(value);
+ }):
+ext: For extending the library, adds this.el to the object or function supplied
+ $_.ext("name", functionOrObject);
+ Example:
+ $_.ext("zip", function(){ ... }); // Adds 'zip' function to $_.
+type: For getting the type of a variable
+ $_.type(var);
+
+Have a look at the right sidebar of the docs included with the library for documentation on the included modules. The development version of the documentation is avaliable at
+http://github.timshomepage.net/kis-js/docs/
+Lite Versions There are two lite versions:
+1. Lite - Includes only the ajax and events modules
+2. Lite-dom - Includes ajax, events, and dom modules
+
-
-
-
-
-
-
-
-
-
-
-
-
polyfill.js
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -139,7 +91,7 @@
- Documentation generated by JSDoc 3.3.0-alpha9 on Fri Sep 12 2014 16:11:50 GMT-0400 (EDT)
+ Documentation generated by JSDoc 3.3.0-alpha9 on Tue Sep 16 2014 16:57:40 GMT-0400 (EDT)
diff --git a/docs/polyfill.js.html b/docs/polyfill.js.html
index e89f141..88073da 100644
--- a/docs/polyfill.js.html
+++ b/docs/polyfill.js.html
@@ -44,7 +44,7 @@
- Documentation generated by JSDoc 3.3.0-alpha9 on Fri Sep 12 2014 16:11:50 GMT-0400 (EDT)
+ Documentation generated by JSDoc 3.3.0-alpha9 on Tue Sep 16 2014 14:44:55 GMT-0400 (EDT)
diff --git a/docs/store.js.html b/docs/store.js.html
index d2186e8..9a6dfc6 100644
--- a/docs/store.js.html
+++ b/docs/store.js.html
@@ -157,7 +157,7 @@
- Documentation generated by JSDoc 3.3.0-alpha9 on Fri Sep 12 2014 16:11:50 GMT-0400 (EDT)
+ Documentation generated by JSDoc 3.3.0-alpha9 on Tue Sep 16 2014 16:57:40 GMT-0400 (EDT)
diff --git a/kis-all.js b/kis-all.js
index a97e1ec..6b357ec 100755
--- a/kis-all.js
+++ b/kis-all.js
@@ -2,13 +2,19 @@
Kis JS Keep It Simple JS Library
Copyright Timothy J. Warren
License Public Domain
- Version 0.8.0
+ Version 0.9.0
*/
(function (undefined){
"use strict";
- var $_, $, sel;
+ /**
+ * Current selector object
+ *
+ * @memberOf $_
+ * @name el
+ */
+ var sel;
/**
@@ -22,7 +28,7 @@
* @param {Object} [context] - Context of the dom selector string
* @return {Object}
*/
- $_ = function(s, context)
+ var $_ = function(s, context)
{
// Have documentElement be default selector, just in case
if (s === undefined)
@@ -65,7 +71,7 @@
* @param {Object} [context]
* @return {Object}
*/
- $ = function (selector, context)
+ var $ = function (selector, context)
{
var elements;
@@ -93,6 +99,9 @@
/**
* Adds the property `obj` to the $_ object, calling it `name`
*
+ * @memberOf $_
+ * @function ext
+ * @example $_.ext('foo', {});
* @param {string} name - name of the module
* @param {object} obj - the object to add
*/
@@ -105,11 +114,12 @@
/**
* Iterates over a $_ object, applying a callback to each item
*
- * @name $_.each
- * @function
+ * @memberOf $_
+ * @function each
+ * @example $_('form input').each(function(item) { alert(item) });
* @param {function} callback - iteration callback
*/
- $_.ext('each', function (callback)
+ $_.ext('each', function(callback)
{
if(sel.length !== undefined && sel !== window)
{
@@ -124,10 +134,13 @@
/**
* Retrieves the type of the passed variable
*
+ * @memberOf $_
+ * @function type
+ * @example $_.type([]); // Returns 'array'
* @param {*} obj
* @return {string}
*/
- $_.type = function(obj)
+ var type = function(obj)
{
if((function() {return obj && (obj !== this)}).call(obj))
{
@@ -142,15 +155,12 @@
//Set global variables
$_ = window.$_ = window.$_ || $_;
$_.$ = $;
+ $_.type = type;
}());
-
// --------------------------------------------------------------------------
-/**
- * A module of various browser polyfills
- * @file polyfill.js
- */
+
// --------------------------------------------------------------------------
@@ -385,6 +395,8 @@
* Accepts either key/value arguments, or an object with
* multiple key/value pairs.
*
+ * @example $_('#foo').dom.css('border', 0);
+ * @example $_('#foo').dom.css({background:'#000', color:'#fff'});
* @name css
* @memberOf $_.dom
* @function
@@ -418,7 +430,7 @@
/**
* Adds to the innerHTML of the current element, after the last child.
*
- * @example $_("ul").dom.append("<li></li>") adds an li element to the end of the selected ul element
+ * @example $_("ul").dom.append(" "); // Adds an li element to the end of the selected ul element
* @name append
* @memberOf $_.dom
* @function
@@ -431,6 +443,7 @@
/**
* Adds to the innerHTML of the selected element, before the current children
*
+ * @example $_("ul").dom.append(" "); // Adds an li element to the beginning of the selected ul element
* @name prepend
* @memberOf $_.dom
* @function
@@ -476,7 +489,7 @@
var ajax = {
- _do: function (url, data, success_callback, error_callback, isPost)
+ _do: function (url, data, success_callback, error_callback, type)
{
var type,
request = new XMLHttpRequest();
@@ -489,8 +502,6 @@
success_callback = function (){};
}
- type = (isPost) ? "POST" : "GET";
-
if (type === "GET")
{
url += (url.match(/\?/))
@@ -519,7 +530,7 @@
}
};
- if (type === "POST")
+ if (type !== "GET")
{
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.send(this._serialize(data));
@@ -564,8 +575,7 @@
/**
* Sends a GET type ajax request
*
- * @name get
- * @function
+ * @function get
* @memberOf $_
* @param {string} url - The url to retrieve
* @param {Object} data - get parameters to send
@@ -573,14 +583,13 @@
* @param {function} [error_callback] - callback called if there is an error
*/
$_.ext('get', function (url, data, success_callback, error_callback){
- ajax._do(url, data, success_callback, error_callback, false);
+ ajax._do(url, data, success_callback, error_callback, 'GET');
});
/**
* Sends a POST type ajax request
*
- * @name post
- * @function
+ * @function post
* @memberOf $_
* @param {string} url - The url to post to
* @param {Object} data - post parameters to send
@@ -588,7 +597,35 @@
* @param {function} [error_callback] - callback called if there is an error
*/
$_.ext('post', function (url, data, success_callback, error_callback){
- ajax._do(url, data, success_callback, error_callback, true);
+ ajax._do(url, data, success_callback, error_callback, 'POST');
+ });
+
+ /**
+ * Sends a PUT type ajax request
+ *
+ * @function put
+ * @memberOf $_
+ * @param {string} url - The url to post to
+ * @param {Object} data - PUT parameters to send
+ * @param {function} success_callback - callback called on success
+ * @param {function} [error_callback] - callback called if there is an error
+ */
+ $_.ext('put', function (url, data, success_callback, error_callback){
+ ajax._do(url, data, success_callback, error_callback, 'PUT');
+ });
+
+ /**
+ * Sends a DELETE type ajax request
+ *
+ * @function delete
+ * @memberOf $_
+ * @param {string} url - The url to post to
+ * @param {Object} data - delete parameters to send
+ * @param {function} success_callback - callback called on success
+ * @param {function} [error_callback] - callback called if there is an error
+ */
+ $_.ext('delete', function (url, data, success_callback, error_callback){
+ ajax._do(url, data, success_callback, error_callback, 'DELETE');
});
@@ -672,7 +709,7 @@
* @memberOf $_.event
* @name create
* @function
- * @example Eg. var event = $_("#selector").event.create('foo', {});
+ * @example var event = $_("#selector").event.create('foo', {});
* @param {string} name
* @param {object} [data]
* @return {Object}
@@ -680,12 +717,12 @@
create: function(name, data)
{
data = data || {};
-
- // Okay, I guess we have to do this the hard way... :(
- var e = document.createEvent('CustomEvent');
- e.initCustomEvent(name, true, true, data);
- return e;
+ // Okay, I guess we have to do this the hard way... :(
+ var e = document.createEvent('CustomEvent');
+ e.initCustomEvent(name, true, true, data);
+
+ return e;
},
/**
* Adds an event that returns a callback when triggered on the selected
@@ -694,7 +731,7 @@
* @memberOf $_.event
* @name add
* @function
- * @example Eg. $_("#selector").event.add("click", do_something());
+ * @example $_("#selector").event.add("click", do_something());
* @param {string} event
* @param {function} callback
*/
@@ -710,7 +747,7 @@
* @memberOf $_.event
* @name remove
* @function
- * @example Eg. $_("#selector").event.remove("click", do_something());
+ * @example $_("#selector").event.remove("click", do_something());
* @param {string} event
* @param {string} callback
*/
@@ -726,7 +763,7 @@
* @memberOf $_.event
* @name live
* @function
- * @example Eg. $_.event.live(".button", "click", do_something());
+ * @example $_.event.live(".button", "click", do_something());
* @param {string} target
* @param {string} event
* @param {function} callback
@@ -741,7 +778,7 @@
* @memberOf $_.event
* @name delegate
* @function
- * @example Eg. $_("#parent").delegate(".button", "click", do_something());
+ * @example $_("#parent").delegate(".button", "click", do_something());
* @param {string} target
* @param {string} event
* @param {function} callback
@@ -758,14 +795,13 @@
* @memberOf $_.event
* @name trigger
* @function
- * @example Eg. $_("#my_id").trigger('click');
+ * @example $_("#my_id").trigger('click');
* @param {object} event
* @return {boolean}
*/
trigger: function(event)
{
- var target = this.el;
- return target.dispatchEvent(event);
+ return this.el.dispatchEvent(event);
}
};
diff --git a/kis-lite-dom-min.js b/kis-lite-dom-min.js
index aafdbec..cee2888 100755
--- a/kis-lite-dom-min.js
+++ b/kis-lite-dom-min.js
@@ -1,9 +1,9 @@
-(function(e){var d,h,b;d=function(a,c){b=a===e?d.el!==e?d.el:document.documentElement:h(a,c);d.prototype.el=b;var g=Object.create(d),f;for(f in g)"object"===typeof g[f]&&(g[f].el=b);g.el=b;return g};h=function(a,c){var b;if("string"!=typeof a||a===e)return a;c=null!=c&&1===c.nodeType?c:document;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);b=c.querySelectorAll(a);return 1===b.length?b[0]:b};d.ext=function(a,c){c.el=b;d[a]=c};d.ext("each",function(a){b.length!==e&&b!==
-window?[].forEach.call(b,a):a.call(b,b)});d.type=function(a){return function(){return a&&a!==this}.call(a)?(typeof a).toLowerCase():{}.toString.call(a).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()};d=window.$_=window.$_||d;d.$=h})();
-(function(e){var d={_do:function(d,b,a,c,g){var f=new XMLHttpRequest;a===e&&(a=function(){});g=g?"POST":"GET";"GET"===g&&(d+=d.match(/\?/)?this._serialize(b):"?"+this._serialize(b));f.open(g,d);f.onreadystatechange=function(){4===f.readyState&&(200===f.status?a.call(f.responseText,f.responseText):c!==e&&c.call(f.status,f.status))};"POST"===g?(f.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),f.send(this._serialize(b))):f.send(null)},_serialize:function(d){var b,a,c=[];for(b in d)d.hasOwnProperty(b)&&
-"function"!==$_.type(d[b])&&(a=d[b].toString(),b=encodeURIComponent(b),a=encodeURIComponent(a),c.push(b+"="+a));return c.join("&")}};$_.ext("get",function(e,b,a,c){d._do(e,b,a,c,!1)});$_.ext("post",function(e,b,a,c){d._do(e,b,a,c,!0)})})();
-(function(e){var d,h;d=function(b,a,c,g){var f,e;if(a.match(/^([\w\-]+)$/))!0===g?b.addEventListener(a,c,!1):b.removeEventListener(a,c,!1);else for(a=a.split(" "),e=a.length,f=0;f"); // Adds an li element to the end of the selected ul element
* @name append
* @memberOf $_.dom
* @function
@@ -737,6 +772,7 @@
/**
* Adds to the innerHTML of the selected element, before the current children
*
+ * @example $_("ul").dom.append(" "); // Adds an li element to the beginning of the selected ul element
* @name prepend
* @memberOf $_.dom
* @function
diff --git a/kis-lite-min.js b/kis-lite-min.js
index d43d291..32c3b5e 100755
--- a/kis-lite-min.js
+++ b/kis-lite-min.js
@@ -1,6 +1,6 @@
-(function(h){var c,g,b;c=function(a,d){b=a===h?c.el!==h?c.el:document.documentElement:g(a,d);c.prototype.el=b;var e=Object.create(c),f;for(f in e)"object"===typeof e[f]&&(e[f].el=b);e.el=b;return e};g=function(a,b){var e;if("string"!=typeof a||a===h)return a;b=null!=b&&1===b.nodeType?b:document;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);e=b.querySelectorAll(a);return 1===e.length?e[0]:e};c.ext=function(a,d){d.el=b;c[a]=d};c.ext("each",function(a){b.length!==h&&b!==
-window?[].forEach.call(b,a):a.call(b,b)});c.type=function(a){return function(){return a&&a!==this}.call(a)?(typeof a).toLowerCase():{}.toString.call(a).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()};c=window.$_=window.$_||c;c.$=g})();
-(function(h){var c={_do:function(c,b,a,d,e){var f=new XMLHttpRequest;a===h&&(a=function(){});e=e?"POST":"GET";"GET"===e&&(c+=c.match(/\?/)?this._serialize(b):"?"+this._serialize(b));f.open(e,c);f.onreadystatechange=function(){4===f.readyState&&(200===f.status?a.call(f.responseText,f.responseText):d!==h&&d.call(f.status,f.status))};"POST"===e?(f.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),f.send(this._serialize(b))):f.send(null)},_serialize:function(c){var b,a,d=[];for(b in c)c.hasOwnProperty(b)&&
-"function"!==$_.type(c[b])&&(a=c[b].toString(),b=encodeURIComponent(b),a=encodeURIComponent(a),d.push(b+"="+a));return d.join("&")}};$_.ext("get",function(g,b,a,d){c._do(g,b,a,d,!1)});$_.ext("post",function(g,b,a,d){c._do(g,b,a,d,!0)})})();
-(function(h){var c,g;c=function(b,a,d,e){var f,g;if(a.match(/^([\w\-]+)$/))!0===e?b.addEventListener(a,d,!1):b.removeEventListener(a,d,!1);else for(a=a.split(" "),g=a.length,f=0;f"); // Adds an li element to the end of the selected ul element
* @name append
* @memberOf $_.dom
* @function
@@ -269,6 +271,7 @@
/**
* Adds to the innerHTML of the selected element, before the current children
*
+ * @example $_("ul").dom.append(" "); // Adds an li element to the beginning of the selected ul element
* @name prepend
* @memberOf $_.dom
* @function
diff --git a/src/modules/ajax.js b/src/modules/ajax.js
index 7cb4549..3bf4697 100755
--- a/src/modules/ajax.js
+++ b/src/modules/ajax.js
@@ -8,7 +8,7 @@
"use strict";
var ajax = {
- _do: function (url, data, success_callback, error_callback, isPost)
+ _do: function (url, data, success_callback, error_callback, type)
{
var type,
request = new XMLHttpRequest();
@@ -21,8 +21,6 @@
success_callback = function (){};
}
- type = (isPost) ? "POST" : "GET";
-
if (type === "GET")
{
url += (url.match(/\?/))
@@ -51,7 +49,7 @@
}
};
- if (type === "POST")
+ if (type !== "GET")
{
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.send(this._serialize(data));
@@ -96,8 +94,7 @@
/**
* Sends a GET type ajax request
*
- * @name get
- * @function
+ * @function get
* @memberOf $_
* @param {string} url - The url to retrieve
* @param {Object} data - get parameters to send
@@ -105,14 +102,13 @@
* @param {function} [error_callback] - callback called if there is an error
*/
$_.ext('get', function (url, data, success_callback, error_callback){
- ajax._do(url, data, success_callback, error_callback, false);
+ ajax._do(url, data, success_callback, error_callback, 'GET');
});
/**
* Sends a POST type ajax request
*
- * @name post
- * @function
+ * @function post
* @memberOf $_
* @param {string} url - The url to post to
* @param {Object} data - post parameters to send
@@ -120,6 +116,34 @@
* @param {function} [error_callback] - callback called if there is an error
*/
$_.ext('post', function (url, data, success_callback, error_callback){
- ajax._do(url, data, success_callback, error_callback, true);
+ ajax._do(url, data, success_callback, error_callback, 'POST');
+ });
+
+ /**
+ * Sends a PUT type ajax request
+ *
+ * @function put
+ * @memberOf $_
+ * @param {string} url - The url to post to
+ * @param {Object} data - PUT parameters to send
+ * @param {function} success_callback - callback called on success
+ * @param {function} [error_callback] - callback called if there is an error
+ */
+ $_.ext('put', function (url, data, success_callback, error_callback){
+ ajax._do(url, data, success_callback, error_callback, 'PUT');
+ });
+
+ /**
+ * Sends a DELETE type ajax request
+ *
+ * @function delete
+ * @memberOf $_
+ * @param {string} url - The url to post to
+ * @param {Object} data - delete parameters to send
+ * @param {function} success_callback - callback called on success
+ * @param {function} [error_callback] - callback called if there is an error
+ */
+ $_.ext('delete', function (url, data, success_callback, error_callback){
+ ajax._do(url, data, success_callback, error_callback, 'DELETE');
});
}());
diff --git a/src/modules/event.js b/src/modules/event.js
index 2e91dc5..7a3b339 100755
--- a/src/modules/event.js
+++ b/src/modules/event.js
@@ -78,7 +78,7 @@
* @memberOf $_.event
* @name create
* @function
- * @example Eg. var event = $_("#selector").event.create('foo', {});
+ * @example var event = $_("#selector").event.create('foo', {});
* @param {string} name
* @param {object} [data]
* @return {Object}
@@ -86,12 +86,12 @@
create: function(name, data)
{
data = data || {};
-
- // Okay, I guess we have to do this the hard way... :(
- var e = document.createEvent('CustomEvent');
- e.initCustomEvent(name, true, true, data);
- return e;
+ // Okay, I guess we have to do this the hard way... :(
+ var e = document.createEvent('CustomEvent');
+ e.initCustomEvent(name, true, true, data);
+
+ return e;
},
/**
* Adds an event that returns a callback when triggered on the selected
@@ -100,7 +100,7 @@
* @memberOf $_.event
* @name add
* @function
- * @example Eg. $_("#selector").event.add("click", do_something());
+ * @example $_("#selector").event.add("click", do_something());
* @param {string} event
* @param {function} callback
*/
@@ -116,7 +116,7 @@
* @memberOf $_.event
* @name remove
* @function
- * @example Eg. $_("#selector").event.remove("click", do_something());
+ * @example $_("#selector").event.remove("click", do_something());
* @param {string} event
* @param {string} callback
*/
@@ -132,7 +132,7 @@
* @memberOf $_.event
* @name live
* @function
- * @example Eg. $_.event.live(".button", "click", do_something());
+ * @example $_.event.live(".button", "click", do_something());
* @param {string} target
* @param {string} event
* @param {function} callback
@@ -147,7 +147,7 @@
* @memberOf $_.event
* @name delegate
* @function
- * @example Eg. $_("#parent").delegate(".button", "click", do_something());
+ * @example $_("#parent").delegate(".button", "click", do_something());
* @param {string} target
* @param {string} event
* @param {function} callback
@@ -164,14 +164,13 @@
* @memberOf $_.event
* @name trigger
* @function
- * @example Eg. $_("#my_id").trigger('click');
+ * @example $_("#my_id").trigger('click');
* @param {object} event
* @return {boolean}
*/
trigger: function(event)
{
- var target = this.el;
- return target.dispatchEvent(event);
+ return this.el.dispatchEvent(event);
}
};
diff --git a/src/polyfill.js b/src/polyfill.js
index 6c76d71..e69de29 100755
--- a/src/polyfill.js
+++ b/src/polyfill.js
@@ -1,4 +0,0 @@
-/**
- * A module of various browser polyfills
- * @file polyfill.js
- */
\ No newline at end of file
diff --git a/tests/ajax.php b/tests/ajax.php
index c0d0fd1..23b3bb1 100755
--- a/tests/ajax.php
+++ b/tests/ajax.php
@@ -3,25 +3,27 @@
$verb = strtolower($_SERVER['REQUEST_METHOD']);
// Send request method if nothing else is specified
-if (empty($_GET))
+if (empty($_GET))
{
echo $verb;
}
else if (isset($_GET['data']))
{
- $var =& $_GET;
-
switch($verb)
{
case "get":
$var =& $_GET;
break;
-
+
case "post":
$var =& $_POST;
break;
+
+ default:
+ parse_str(file_get_contents('php://input'), $var);
+ break;
}
-
+
header('Content-type: application/json');
echo json_encode($var);
}
diff --git a/tests/tests/ajax.js b/tests/tests/ajax.js
index 3411870..e1ef6a4 100755
--- a/tests/tests/ajax.js
+++ b/tests/tests/ajax.js
@@ -1,16 +1,15 @@
(function(){
"use strict";
-
+
module("ajax");
-
+
test("Methods defined", function(){
expect(2);
ok($_.get, "AJAX get method");
ok($_.post, "AJAX post method");
});
-
- asyncTest("Get", function() {
-
+
+ asyncTest("GET", function() {
$_.get("ajax.php", {}, function(res) {
ok(res, "Get Response recieved");
equal(res, 'get', "Appropriate request type");
@@ -18,11 +17,9 @@
}, function(res) {
ok(false, "Response failed");
});
-
});
-
- asyncTest("Post", function() {
-
+
+ asyncTest("POST", function() {
$_.post("ajax.php", {}, function(res) {
ok(res, "Post Response recieved");
equal(res, 'post', "Appropriate request type");
@@ -30,17 +27,44 @@
}, function(res) {
ok(false, "Post Response failed");
});
-
});
-
- asyncTest("Post with data", function() {
+
+ asyncTest("PUT", function() {
+ $_.put("ajax.php", {}, function(res) {
+ ok(res, "PUT Response recieved");
+ equal(res, 'put', "Appropriate request type");
+ start();
+ }, function(res) {
+ ok(false, "PUT Response failed");
+ });
+ });
+
+ asyncTest("DELETE", function() {
+ $_.delete("ajax.php", {}, function(res) {
+ ok(res, "DELETE Response recieved");
+ equal(res, 'delete', "Appropriate request type");
+ start();
+ }, function(res) {
+ ok(false, "DELETE Response failed");
+ });
+ });
+
+ asyncTest("POST with data", function() {
$_.post("ajax.php?data", {foo:'data', bar:function(){}}, function(res) {
ok(res, "Data post Response received");
equal(res, '{"foo":"data"}', "JSON received");
start();
});
});
-
+
+ asyncTest("PUT with data", function() {
+ $_.put("ajax.php?data", {bar:'data'}, function(res) {
+ ok(res, "Data post Response received");
+ equal(res, '{"bar":"data"}', "JSON received");
+ start();
+ });
+ });
+
asyncTest("Bad request", function() {
$_.get("ajax.php?bad", {}, undefined, function(res) {
ok(res, "Bad response");
@@ -48,5 +72,5 @@
start();
});
});
-
+
}());
\ No newline at end of file
diff --git a/tests/tests/core.js b/tests/tests/core.js
index 8377471..ae3f857 100755
--- a/tests/tests/core.js
+++ b/tests/tests/core.js
@@ -3,7 +3,7 @@
"use strict";
module("core");
-
+
test("Basic requirements", function(){
expect(8);
ok(document.querySelectorAll, "querySelectorAll");
@@ -15,67 +15,69 @@
strictEqual(typeof $_, "function", "Global var");
strictEqual(typeof $_(), "object");
});
-
+
test("Type Checking", function(){
- equal($_.type(5), "number", "Number type");
+ equal($_.type(7), "number", "Number type");
equal($_.type("abc"), "string", "String type");
equal($_.type({}), "object", "Object type");
equal($_.type([0,1,2]), "array", "Array type");
equal($_.type(/x/), "regexp", "Regex type");
equal($_.type(function(){}), "function", "Function type");
equal($_.type(true), "boolean", "Boolean type");
+ strictEqual($_.type($_), "function", "$_ returns function");
+ strictEqual($_.type($_()), "object", "$_() returns object");
});
-
+
test("Unique Selectors", function(){
expect(1);
notStrictEqual($_("div").el, $_("aside").el, "Unique Query Objects - see Issue #5");
});
-
+
test("Extend function", function(){
var o = $_("ol");
expect(4);
ok(o.ext, "Extend function exists");
-
+
$_.ext('test', {});
strictEqual(typeof o.test, "object", "Extend function adds to $_");
strictEqual(is_clone(o.test.el, $_("ol").el), true, "Extend function adds selector to passed object");
strictEqual(is_clone(o.test.el, o.el), true, "Selector is the same on parent and child object");
-
+
o = null;
});
-
+
test("Selector tests", function(){
var i=0;
$_("div").each(function(e){
equal(e, $_("div").el[i], ".each function has current selector");
i++;
});
-
+
strictEqual($_().el, window.document.documentElement, "Empty selector is set to documentElement");
strictEqual($_('#qunit').el, document.getElementById('qunit'), "Id selector equivalence")
-
+
strictEqual(is_clone($_('#qunit').el, $_.$('#qunit')), true, "El attribute is same as direct selector");
strictEqual(is_clone($_('div').el, $_.$('div')), true, "El attribute is same as direct selector");
-
+
});
-
+
asyncTest("Iterator tests", function() {
$_('#qunit').each(function(el) {
equal(el, $_.$('#qunit'));
start();
});
-
+
$_('foo').each(function(el) {
equal(el, undefined);
});
});
-
+
test("Array.isArray", function(){
expect(2);
strictEqual(Array.isArray([1, 2, 3]), true, "Array.isArray returns true on an array");
strictEqual(Array.isArray({arr:[1,2,3]}), false, "Array.isArray returns false on a non-array");
});
-
+
test("Sub-modules", function(){
expect(4);
ok($_().event, "Event module");
diff --git a/tests/tests/event.js b/tests/tests/event.js
index df1e447..ea4f4d1 100755
--- a/tests/tests/event.js
+++ b/tests/tests/event.js
@@ -1,19 +1,19 @@
(function(){
"use strict";
-
+
module("events", {
setup: function() {
this.foo = $_.event.create('foo');
ok(this.foo, "Event foo created");
-
+
this.bar = $_.event.create('bar');
ok(this.bar, "Event bar created");
},
teardown: function() {
-
+
}
});
-
+
test("Events defined", function(){
expect(8);
ok($_.event.create, "Create Method Exists");
@@ -23,53 +23,59 @@
ok($_.event.delegate, "Delegate Method Exists");
ok($_.event.trigger, "Trigger Method Exists");
});
-
+
asyncTest("Adding/Triggering Event Listener", function() {
expect(5);
-
+
var callback = function(e) {
ok(e, "Event was added");
ok(e, "Event was triggered");
+
start();
};
-
- $_("#qunit").event.add('foo', callback);
- var x = $_("#qunit").event.trigger(this.foo);
+
+ $_.event.add('foo', callback);
+ var x = $_.event.trigger(this.foo);
ok(x, "Event was not canceled");
});
-
+
asyncTest("Delegated Event", function() {
+ expect(4);
+
var callback = function(e) {
ok(e, "Delegated event was triggered");
start();
- }
-
- $_.event.delegate('.nephew', 'foo', callback);
- var x = $_.event.trigger(this.foo);
+ };
+
+ $_("section[hidden]").event.delegate('#classChild', 'foo', callback);
+ var x = $_('.nephew').event.trigger(this.foo);
ok(x, "Event was not canceled");
-
});
-
+
asyncTest("Live Event", function() {
+ expect(4);
+
var callback = function(e) {
ok(e, "Live event was triggered");
start();
- }
-
+ };
+
$_.event.live('.child', 'foo', callback);
- $_.event.trigger(this.foo);
+ $_('#classChild').event.trigger(this.foo);
});
-
+
asyncTest("Multiple Events", function() {
+ expect(3);
+
var callback = function(e) {
ok(e, "An event was triggered");
start();
- }
-
+ };
+
$_("#qunit").event.add('foo bar', callback);
-
- $_.event.trigger(this.bar);
-
+ $_('#qunit').event.trigger(this.bar);
+
+ // Remove the events
+ $_("#qunit").event.remove('foo bar', callback);
});
-
}());
\ No newline at end of file