More code cleanup, better test coverage, and doc cleanup

This commit is contained in:
Timothy Warren 2014-09-17 09:31:12 -04:00
parent 3ef9e89ab6
commit 3c99e243d3
29 changed files with 1381 additions and 390 deletions

4
.gitignore vendored
View File

@ -2,4 +2,6 @@ kis-custom.js
kis-custom-min.js
combine-build.php
test.html
.*
config.json
docs.conf
.*

View File

@ -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/)

View File

@ -313,7 +313,7 @@ selector
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="DOM.js.html">modules/DOM.js</a>, <a href="DOM.js.html#line256">line 256</a>
<a href="DOM.js.html">modules/DOM.js</a>, <a href="DOM.js.html#line258">line 258</a>
</li></ul></dd>
@ -340,7 +340,7 @@ selector
<h5>Example</h5>
<pre class="prettyprint"><code>$_("ul").dom.append("&amp;lt;li&amp;gt;&amp;lt;/li&amp;gt;") adds an li element to the end of the selected ul element</code></pre>
<pre class="prettyprint"><code>$_("ul").dom.append("&lt;li>&lt;/li>"); // Adds an li element to the end of the selected ul element</code></pre>
</dd>
@ -720,6 +720,13 @@ multiple key/value pairs.
<h5>Examples</h5>
<pre class="prettyprint"><code>$_('#foo').dom.css('border', 0);</code></pre>
<pre class="prettyprint"><code>$_('#foo').dom.css({background:'#000', color:'#fff'});</code></pre>
</dd>
@ -899,7 +906,7 @@ multiple key/value pairs.
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="DOM.js.html">modules/DOM.js</a>, <a href="DOM.js.html#line281">line 281</a>
<a href="DOM.js.html">modules/DOM.js</a>, <a href="DOM.js.html#line284">line 284</a>
</li></ul></dd>
@ -1036,7 +1043,7 @@ multiple key/value pairs.
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="DOM.js.html">modules/DOM.js</a>, <a href="DOM.js.html#line269">line 269</a>
<a href="DOM.js.html">modules/DOM.js</a>, <a href="DOM.js.html#line271">line 271</a>
</li></ul></dd>
@ -1061,6 +1068,11 @@ multiple key/value pairs.
<h5>Example</h5>
<pre class="prettyprint"><code>$_("ul").dom.append("&lt;li>&lt;/li>"); // Adds an li element to the beginning of the selected ul element</code></pre>
</dd>
@ -1493,7 +1505,7 @@ otherwise it will return the value of the current element
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Fri Sep 12 2014 16:11:50 GMT-0400 (EDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Tue Sep 16 2014 16:57:40 GMT-0400 (EDT)
</footer>
<script> prettyPrint(); </script>

View File

@ -242,7 +242,7 @@ event and selector
<h5>Example</h5>
<pre class="prettyprint"><code>Eg. $_("#selector").event.add("click", do_something());</code></pre>
<pre class="prettyprint"><code>$_("#selector").event.add("click", do_something());</code></pre>
</dd>
@ -427,7 +427,7 @@ event and selector
<h5>Example</h5>
<pre class="prettyprint"><code>Eg. var event = $_("#selector").event.create('foo', {});</code></pre>
<pre class="prettyprint"><code>var event = $_("#selector").event.create('foo', {});</code></pre>
</dd>
@ -597,7 +597,7 @@ event and selector
<h5>Example</h5>
<pre class="prettyprint"><code>Eg. $_("#parent").delegate(".button", "click", do_something());</code></pre>
<pre class="prettyprint"><code>$_("#parent").delegate(".button", "click", do_something());</code></pre>
</dd>
@ -767,7 +767,7 @@ event and selector
<h5>Example</h5>
<pre class="prettyprint"><code>Eg. $_.event.live(".button", "click", do_something());</code></pre>
<pre class="prettyprint"><code>$_.event.live(".button", "click", do_something());</code></pre>
</dd>
@ -914,7 +914,7 @@ event and selector
<h5>Example</h5>
<pre class="prettyprint"><code>Eg. $_("#selector").event.remove("click", do_something());</code></pre>
<pre class="prettyprint"><code>$_("#selector").event.remove("click", do_something());</code></pre>
</dd>
@ -1056,7 +1056,7 @@ event and selector
<h5>Example</h5>
<pre class="prettyprint"><code>Eg. $_("#my_id").trigger('click');</code></pre>
<pre class="prettyprint"><code>$_("#my_id").trigger('click');</code></pre>
</dd>
@ -1083,7 +1083,7 @@ event and selector
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Fri Sep 12 2014 16:11:50 GMT-0400 (EDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Tue Sep 16 2014 16:57:40 GMT-0400 (EDT)
</footer>
<script> prettyPrint(); </script>

View File

@ -66,7 +66,7 @@ Constructor function</div>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="core.js.html">core.js</a>, <a href="core.js.html#line14">line 14</a>
<a href="core.js.html">core.js</a>, <a href="core.js.html#line20">line 20</a>
</li></ul></dd>
@ -108,6 +108,66 @@ Constructor function</div>
<h3 class="subsection-title">Members</h3>
<dl>
<dt>
<h4 class="name" id="el"><span class="type-signature">(static) </span>el<span class="type-signature"></span></h4>
</dt>
<dd>
<div class="description">
Current selector object
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="core.js.html">core.js</a>, <a href="core.js.html#line11">line 11</a>
</li></ul></dd>
</dl>
</dd>
</dl>
<h3 class="subsection-title">Methods</h3>
@ -247,7 +307,7 @@ Constructor function</div>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="core.js.html">core.js</a>, <a href="core.js.html#line68">line 68</a>
<a href="core.js.html">core.js</a>, <a href="core.js.html#line74">line 74</a>
</li></ul></dd>
@ -290,6 +350,230 @@ Constructor function</div>
</dd>
<dt>
<h4 class="name" id="delete"><span class="type-signature">(static) </span>delete<span class="signature">(url, data, success_callback, error_callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
</dt>
<dd>
<div class="description">
Sends a DELETE type ajax request
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>url</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last">The url to post to</td>
</tr>
<tr>
<td class="name"><code>data</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
</td>
<td class="description last">delete parameters to send</td>
</tr>
<tr>
<td class="name"><code>success_callback</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="attributes">
</td>
<td class="description last">callback called on success</td>
</tr>
<tr>
<td class="name"><code>error_callback</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last">callback called if there is an error</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ajax.js.html">modules/ajax.js</a>, <a href="ajax.js.html#line136">line 136</a>
</li></ul></dd>
</dl>
</dd>
@ -384,7 +668,7 @@ Constructor function</div>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="core.js.html">core.js</a>, <a href="core.js.html#line105">line 105</a>
<a href="core.js.html">core.js</a>, <a href="core.js.html#line114">line 114</a>
</li></ul></dd>
@ -409,6 +693,158 @@ Constructor function</div>
<h5>Example</h5>
<pre class="prettyprint"><code>$_('form input').each(function(item) { alert(item) });</code></pre>
</dd>
<dt>
<h4 class="name" id="ext"><span class="type-signature">(static) </span>ext<span class="signature">(name, obj)</span><span class="type-signature"></span></h4>
</dt>
<dd>
<div class="description">
Adds the property `obj` to the $_ object, calling it `name`
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>name</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">name of the module</td>
</tr>
<tr>
<td class="name"><code>obj</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last">the object to add</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="core.js.html">core.js</a>, <a href="core.js.html#line99">line 99</a>
</li></ul></dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>$_.ext('foo', {});</code></pre>
</dd>
@ -608,7 +1044,7 @@ Constructor function</div>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ajax.js.html">modules/ajax.js</a>, <a href="ajax.js.html#line96">line 96</a>
<a href="ajax.js.html">modules/ajax.js</a>, <a href="ajax.js.html#line94">line 94</a>
</li></ul></dd>
@ -832,7 +1268,7 @@ Constructor function</div>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ajax.js.html">modules/ajax.js</a>, <a href="ajax.js.html#line111">line 111</a>
<a href="ajax.js.html">modules/ajax.js</a>, <a href="ajax.js.html#line108">line 108</a>
</li></ul></dd>
@ -857,6 +1293,372 @@ Constructor function</div>
</dd>
<dt>
<h4 class="name" id="put"><span class="type-signature">(static) </span>put<span class="signature">(url, data, success_callback, error_callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
</dt>
<dd>
<div class="description">
Sends a PUT type ajax request
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>url</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last">The url to post to</td>
</tr>
<tr>
<td class="name"><code>data</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
</td>
<td class="description last">PUT parameters to send</td>
</tr>
<tr>
<td class="name"><code>success_callback</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="attributes">
</td>
<td class="description last">callback called on success</td>
</tr>
<tr>
<td class="name"><code>error_callback</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last">callback called if there is an error</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ajax.js.html">modules/ajax.js</a>, <a href="ajax.js.html#line122">line 122</a>
</li></ul></dd>
</dl>
</dd>
<dt>
<h4 class="name" id="type"><span class="type-signature">(static) </span>type<span class="signature">(obj)</span><span class="type-signature"> &rarr; {string}</span></h4>
</dt>
<dd>
<div class="description">
Retrieves the type of the passed variable
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>obj</code></td>
<td class="type">
<span class="param-type">*</span>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="core.js.html">core.js</a>, <a href="core.js.html#line134">line 134</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">string</span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>$_.type([]); // Returns 'array'</code></pre>
</dd>
</dl>
@ -881,7 +1683,7 @@ Constructor function</div>
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Fri Sep 12 2014 16:11:50 GMT-0400 (EDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Tue Sep 16 2014 16:57:40 GMT-0400 (EDT)
</footer>
<script> prettyPrint(); </script>

View File

@ -848,7 +848,7 @@ and JSON-encodes the value if not a string
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Fri Sep 12 2014 16:11:50 GMT-0400 (EDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Tue Sep 16 2014 16:57:40 GMT-0400 (EDT)
</footer>
<script> prettyPrint(); </script>

View File

@ -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("&amp;lt;li&amp;gt;&amp;lt;/li&amp;gt;") adds an li element to the end of the selected ul element
* @example $_("ul").dom.append("&lt;li>&lt;/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("&lt;li>&lt;/li>"); // Adds an li element to the beginning of the selected ul element
* @name prepend
* @memberOf $_.dom
* @function
@ -345,7 +348,7 @@
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Fri Sep 12 2014 16:11:50 GMT-0400 (EDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Tue Sep 16 2014 16:57:40 GMT-0400 (EDT)
</footer>
<script> prettyPrint(); </script>

View File

@ -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');
});
}());
</code></pre>
@ -166,7 +190,7 @@
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Fri Sep 12 2014 16:11:50 GMT-0400 (EDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Tue Sep 16 2014 16:57:40 GMT-0400 (EDT)
</footer>
<script> prettyPrint(); </script>

View File

@ -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 &amp;&amp; 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 &amp;&amp; (obj !== this)}).call(obj))
{
@ -169,8 +182,8 @@
//Set global variables
$_ = window.$_ = window.$_ || $_;
$_.$ = $;
}());
</code></pre>
$_.type = type;
}());</code></pre>
</article>
</section>
@ -186,7 +199,7 @@
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Fri Sep 12 2014 16:11:50 GMT-0400 (EDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Tue Sep 16 2014 16:57:40 GMT-0400 (EDT)
</footer>
<script> prettyPrint(); </script>

View File

@ -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 @@
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Fri Sep 12 2014 16:11:50 GMT-0400 (EDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Tue Sep 16 2014 16:57:40 GMT-0400 (EDT)
</footer>
<script> prettyPrint(); </script>

View File

@ -81,6 +81,8 @@
@ -89,20 +91,30 @@
<dl>
<dt>
<h4 class="name" id="data[undefined]"><span class="type-signature"></span>data[undefined]<span class="type-signature"></span></h4>
<h4 class="name" id="el"><span class="type-signature"></span>el<span class="type-signature"> :Object</span></h4>
</dt>
<dd>
<div class="description">
Ajax
$_
Module for making ajax requests
Constructor function
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">Object</span>
</li>
</ul>
<dl class="details">
@ -127,7 +139,7 @@ Module for making ajax requests
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ajax.js.html">modules/ajax.js</a>, <a href="ajax.js.html#line84">line 84</a>
<a href="core.js.html">core.js</a>, <a href="core.js.html#line14">line 14</a>
</li></ul></dd>
@ -162,13 +174,13 @@ Module for making ajax requests
</div>
<nav>
<h2><a href="index.html">Index</a></h2><h3>Namespaces</h3><ul><li><a href="$_.html">$_</a></li><li><a href="$_.dom.html">dom</a></li><li><a href="$_.event.html">event</a></li><li><a href="$_.store.html">store</a></li></ul><h3>Global</h3><ul><li><a href="global.html#data[undefined]">data[undefined]</a></li></ul>
<h2><a href="index.html">Index</a></h2><h3>Namespaces</h3><ul><li><a href="$_.dom.html">dom</a></li><li><a href="$_.event.html">event</a></li><li><a href="$_.store.html">store</a></li></ul><h3>Global</h3><ul><li><a href="global.html#el">el</a></li></ul>
</nav>
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha5</a> on Wed Sep 10 2014 00:23:43 GMT-0400 (EDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Tue Sep 16 2014 15:49:39 GMT-0400 (EDT)
</footer>
<script> prettyPrint(); </script>

View File

@ -40,96 +40,48 @@
<section>
<article><h1>Keep It Simple JS Library</h1><p>A Minimal, Modular Javascript library for Modern browsers.</p>
<p>Aims to be fast, small, and easily split into individual modules.</p>
<p>You can create your own library by adding and removing modules from the
src directory, and running the &quot;combine.php&quot; script. This will output a
&quot;kis-custom.js&quot; file. (Be careful, as the script will overwrite any &quot;kis-custom.js&quot;
file that already exists).</p>
<p>Browser support: IE10+, Latest versions of Firefox, Chrome, Safari, Opera</p>
<h2>Basic Use:</h2><ul>
<li>Function: <code>$_(selector).module.function(params);</code></li>
</ul>
<h3>Core Methods</h3><p><strong>properties:</strong></p>
<ul>
<li>el: The html object returned by the selector function.</li>
</ul>
<p><strong>functions:</strong></p>
<ul>
<li><p>each: For applying changes to every item matched by a selector</p>
<p> $_(selector).each(callback);</p>
<p> Example :</p>
<pre class="prettyprint source"><code> $_(&quot;.foo&quot;).each(function(e){
$_(e).dom.text(value);
}):</code></pre></li>
<li><p>ext: For extending the library, adds this.el to the object or function supplied</p>
<p> $_.ext(&quot;name&quot;, functionOrObject);</p>
<p> Example:</p>
<pre class="prettyprint source"><code> $_.ext(&quot;zip&quot;, function(){ ... }); // Adds 'zip' function to $_.</code></pre></li>
<li><p>type: For getting the type of a variable</p>
<pre class="prettyprint source"><code> $_.type(var);</code></pre></li>
</ul>
<p>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</p>
<p><a href="http://github.timshomepage.net/kis-js/docs/">http://github.timshomepage.net/kis-js/docs/</a></p>
<h4>Lite Versions</h4><p>There are two lite versions:</p>
<pre class="prettyprint source"><code>1. Lite - Includes only the ajax and events modules
2. Lite-dom - Includes ajax, events, and dom modules</code></pre></article>
</section>
<section>
<header>
<h2>
polyfill.js
</h2>
</header>
<article>
<div class="container-overview">
<div class="description">polyfill.js</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="polyfill.js.html">polyfill.js</a>, <a href="polyfill.js.html#line1">line 1</a>
</li></ul></dd>
</dl>
</div>
</article>
</section>
</div>
<nav>
@ -139,7 +91,7 @@
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Fri Sep 12 2014 16:11:50 GMT-0400 (EDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Tue Sep 16 2014 16:57:40 GMT-0400 (EDT)
</footer>
<script> prettyPrint(); </script>

View File

@ -44,7 +44,7 @@
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Fri Sep 12 2014 16:11:50 GMT-0400 (EDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Tue Sep 16 2014 14:44:55 GMT-0400 (EDT)
</footer>
<script> prettyPrint(); </script>

View File

@ -157,7 +157,7 @@
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Fri Sep 12 2014 16:11:50 GMT-0400 (EDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Tue Sep 16 2014 16:57:40 GMT-0400 (EDT)
</footer>
<script> prettyPrint(); </script>

View File

@ -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("&lt;li&gt;&lt;/li&gt;") 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
@ -431,6 +443,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
@ -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);
}
};

18
kis-lite-dom-min.js vendored
View File

@ -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<e;f++)d(b,a[f],c,g)};h=function(b,a,c,g){d(b,c,function(c){var d,e;e=$_.$(a,b);for(d in e)c.target==e[d]&&(g.call(e[d],c),c.stopPropagation())},!0)};$_.ext("event",{create:function(b,a){a=a||{};var c=document.createEvent("CustomEvent");c.initCustomEvent(b,!0,!0,a);return c},add:function(b,a){$_.each(function(c){d(c,b,a,
!0)})},remove:function(b,a){$_.each(function(c){d(c,b,a,!1)})},live:function(b,a,c){h(document.documentElement,b,a,c)},delegate:function(b,a,c){$_.each(function(g){h(g,b,a,c)})},trigger:function(b){return this.el.dispatchEvent(b)}})})();
(function(e){function d(a,c,b){var d;a.hasAttribute(c)&&(d=a.getAttribute(c));if(d===e&&(b===e||null===b))return null;if(b===e)return d;b!==e&&null!==b?a.setAttribute(c,b):null===b&&a.removeAttribute(c);return b!==e?b:d}function h(a){return String(a).replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function b(a,c,b){c=h(c);if(b===e&&a.style[c]!==e)return a.style[c];if(a.style[c]!==e)return a.style[c]=b,null}$_.ext("dom",{addClass:function(a){$_.each(function(c){c.classList.add(a)})},
removeClass:function(a){$_.each(function(c){c.classList.remove(a)})},hide:function(){this.css("display","none")},show:function(a){a===e&&(a="block");this.css("display",a)},attr:function(a,c){var b=this.el;if(1<b.length&&c===e)return null;if(1<b.length&&c!==e)$_.each(function(b){return d(b,a,c)});else return d(b,a,c)},text:function(a){var b,d,f;f=this.el;d=a!==e?!0:!1;b=f.textContent;return d?f.textContent=a:b},css:function(a,c){if("object"===$_.type(a))Object.keys(a).forEach(function(c){$_.each(function(d){b(d,
c,a[c])})});else if(c===e&&"object"!==$_.type(a))return b(this.el,a);$_.each(function(d){b(d,a,c)})},append:function(a){this.el.insertAdjacentHTML("beforeend",a)},prepend:function(a){this.el.insertAdjacentHTML("afterbegin",a)},html:function(a){a!==e&&(this.el.innerHTML=a);return this.el.innerHTML}})})();
(function(g){var f,d=function(a,b){f=a===g?d.el!==g?d.el:document.documentElement:c(a,b);d.prototype.el=f;var e=Object.create(d),h;for(h in e)"object"===typeof e[h]&&(e[h].el=f);e.el=f;return e},c=function(a,b){var e;if("string"!=typeof a||a===g)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};d.ext=function(a,b){b.el=f;d[a]=b};d.ext("each",function(a){f.length!==g&&f!==window?
[].forEach.call(f,a):a.call(f,f)});d=window.$_=window.$_||d;d.$=c;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()}})();
(function(g){var f={_do:function(d,c,a,b,e){var h=new XMLHttpRequest;a===g&&(a=function(){});"GET"===e&&(d+=d.match(/\?/)?this._serialize(c):"?"+this._serialize(c));h.open(e,d);h.onreadystatechange=function(){4===h.readyState&&(200===h.status?a.call(h.responseText,h.responseText):b!==g&&b.call(h.status,h.status))};"GET"!==e?(h.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),h.send(this._serialize(c))):h.send(null)},_serialize:function(d){var c,a,b=[];for(c in d)d.hasOwnProperty(c)&&
"function"!==$_.type(d[c])&&(a=d[c].toString(),c=encodeURIComponent(c),a=encodeURIComponent(a),b.push(c+"="+a));return b.join("&")}};$_.ext("get",function(d,c,a,b){f._do(d,c,a,b,"GET")});$_.ext("post",function(d,c,a,b){f._do(d,c,a,b,"POST")});$_.ext("put",function(d,c,a,b){f._do(d,c,a,b,"PUT")});$_.ext("delete",function(d,c,a,b){f._do(d,c,a,b,"DELETE")})})();
(function(g){var f,d;f=function(c,a,b,e){var h,d;if(a.match(/^([\w\-]+)$/))!0===e?c.addEventListener(a,b,!1):c.removeEventListener(a,b,!1);else for(a=a.split(" "),d=a.length,h=0;h<d;h++)f(c,a[h],b,e)};d=function(c,a,b,e){f(c,b,function(b){var d,f;f=$_.$(a,c);for(d in f)b.target==f[d]&&(e.call(f[d],b),b.stopPropagation())},!0)};$_.ext("event",{create:function(c,a){a=a||{};var b=document.createEvent("CustomEvent");b.initCustomEvent(c,!0,!0,a);return b},add:function(c,a){$_.each(function(b){f(b,c,a,
!0)})},remove:function(c,a){$_.each(function(b){f(b,c,a,!1)})},live:function(c,a,b){d(document.documentElement,c,a,b)},delegate:function(c,a,b){$_.each(function(e){d(e,c,a,b)})},trigger:function(c){return this.el.dispatchEvent(c)}})})();
(function(g){function f(a,b,e){var c;a.hasAttribute(b)&&(c=a.getAttribute(b));if(c===g&&(e===g||null===e))return null;if(e===g)return c;e!==g&&null!==e?a.setAttribute(b,e):null===e&&a.removeAttribute(b);return e!==g?e:c}function d(a){return String(a).replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function c(a,b,c){b=d(b);if(c===g&&a.style[b]!==g)return a.style[b];if(a.style[b]!==g)return a.style[b]=c,null}$_.ext("dom",{addClass:function(a){$_.each(function(b){b.classList.add(a)})},
removeClass:function(a){$_.each(function(b){b.classList.remove(a)})},hide:function(){this.css("display","none")},show:function(a){a===g&&(a="block");this.css("display",a)},attr:function(a,b){var c=this.el;if(1<c.length&&b===g)return null;if(1<c.length&&b!==g)$_.each(function(c){return f(c,a,b)});else return f(c,a,b)},text:function(a){var b,c,d;d=this.el;c=a!==g?!0:!1;b=d.textContent;return c?d.textContent=a:b},css:function(a,b){if("object"===$_.type(a))Object.keys(a).forEach(function(b){$_.each(function(d){c(d,
b,a[b])})});else if(b===g&&"object"!==$_.type(a))return c(this.el,a);$_.each(function(d){c(d,a,b)})},append:function(a){this.el.insertAdjacentHTML("beforeend",a)},prepend:function(a){this.el.insertAdjacentHTML("afterbegin",a)},html:function(a){a!==g&&(this.el.innerHTML=a);return this.el.innerHTML}})})();

View File

@ -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
*/
// --------------------------------------------------------------------------
@ -164,7 +174,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();
@ -177,8 +187,6 @@
success_callback = function (){};
}
type = (isPost) ? "POST" : "GET";
if (type === "GET")
{
url += (url.match(/\?/))
@ -207,7 +215,7 @@
}
};
if (type === "POST")
if (type !== "GET")
{
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.send(this._serialize(data));
@ -252,8 +260,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
@ -261,14 +268,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
@ -276,7 +282,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');
});
}());
@ -363,7 +397,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}
@ -371,12 +405,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
@ -385,7 +419,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
*/
@ -401,7 +435,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
*/
@ -417,7 +451,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
@ -432,7 +466,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
@ -449,14 +483,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);
}
};
@ -691,6 +724,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
@ -724,7 +759,7 @@
/**
* Adds to the innerHTML of the current element, after the last child.
*
* @example $_("ul").dom.append("&lt;li&gt;&lt;/li&gt;") 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
@ -737,6 +772,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

12
kis-lite-min.js vendored
View File

@ -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<g;f++)c(b,a[f],d,e)};g=function(b,a,d,e){c(b,d,function(c){var d,g;g=$_.$(a,b);for(d in g)c.target==g[d]&&(e.call(g[d],c),c.stopPropagation())},!0)};$_.ext("event",{create:function(b,a){a=a||{};var c=document.createEvent("CustomEvent");c.initCustomEvent(b,!0,!0,a);return c},add:function(b,a){$_.each(function(d){c(d,b,a,
!0)})},remove:function(b,a){$_.each(function(d){c(d,b,a,!1)})},live:function(b,a,c){g(document.documentElement,b,a,c)},delegate:function(b,a,c){$_.each(function(e){g(e,b,a,c)})},trigger:function(b){return this.el.dispatchEvent(b)}})})();
(function(h){var d,b=function(a,e){d=a===h?b.el!==h?b.el:document.documentElement:c(a,e);b.prototype.el=d;var g=Object.create(b),f;for(f in g)"object"===typeof g[f]&&(g[f].el=d);g.el=d;return g},c=function(a,c){var b;if("string"!=typeof a||a===h)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};b.ext=function(a,c){c.el=d;b[a]=c};b.ext("each",function(a){d.length!==h&&d!==window?
[].forEach.call(d,a):a.call(d,d)});b=window.$_=window.$_||b;b.$=c;b.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()}})();
(function(h){var d={_do:function(b,c,a,e,d){var f=new XMLHttpRequest;a===h&&(a=function(){});"GET"===d&&(b+=b.match(/\?/)?this._serialize(c):"?"+this._serialize(c));f.open(d,b);f.onreadystatechange=function(){4===f.readyState&&(200===f.status?a.call(f.responseText,f.responseText):e!==h&&e.call(f.status,f.status))};"GET"!==d?(f.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),f.send(this._serialize(c))):f.send(null)},_serialize:function(b){var c,a,e=[];for(c in b)b.hasOwnProperty(c)&&
"function"!==$_.type(b[c])&&(a=b[c].toString(),c=encodeURIComponent(c),a=encodeURIComponent(a),e.push(c+"="+a));return e.join("&")}};$_.ext("get",function(b,c,a,e){d._do(b,c,a,e,"GET")});$_.ext("post",function(b,c,a,e){d._do(b,c,a,e,"POST")});$_.ext("put",function(b,c,a,e){d._do(b,c,a,e,"PUT")});$_.ext("delete",function(b,c,a,e){d._do(b,c,a,e,"DELETE")})})();
(function(h){var d,b;d=function(c,a,b,g){var f,h;if(a.match(/^([\w\-]+)$/))!0===g?c.addEventListener(a,b,!1):c.removeEventListener(a,b,!1);else for(a=a.split(" "),h=a.length,f=0;f<h;f++)d(c,a[f],b,g)};b=function(c,a,b,g){d(c,b,function(b){var e,d;d=$_.$(a,c);for(e in d)b.target==d[e]&&(g.call(d[e],b),b.stopPropagation())},!0)};$_.ext("event",{create:function(c,a){a=a||{};var b=document.createEvent("CustomEvent");b.initCustomEvent(c,!0,!0,a);return b},add:function(b,a){$_.each(function(e){d(e,b,a,
!0)})},remove:function(b,a){$_.each(function(e){d(e,b,a,!1)})},live:function(c,a,d){b(document.documentElement,c,a,d)},delegate:function(c,a,d){$_.each(function(g){b(g,c,a,d)})},trigger:function(b){return this.el.dispatchEvent(b)}})})();

View File

@ -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
*/
// --------------------------------------------------------------------------
@ -164,7 +174,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();
@ -177,8 +187,6 @@
success_callback = function (){};
}
type = (isPost) ? "POST" : "GET";
if (type === "GET")
{
url += (url.match(/\?/))
@ -207,7 +215,7 @@
}
};
if (type === "POST")
if (type !== "GET")
{
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.send(this._serialize(data));
@ -252,8 +260,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
@ -261,14 +268,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
@ -276,7 +282,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');
});
}());
@ -363,7 +397,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}
@ -371,12 +405,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
@ -385,7 +419,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
*/
@ -401,7 +435,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
*/
@ -417,7 +451,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
@ -432,7 +466,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
@ -449,14 +483,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);
}
};

18
kis-min.js vendored
View File

@ -1,9 +1,9 @@
(function(e){var c,n,k;c=function(p,h){k=p===e?c.el!==e?c.el:document.documentElement:n(p,h);c.prototype.el=k;var f=Object.create(c),m;for(m in f)"object"===typeof f[m]&&(f[m].el=k);f.el=k;return f};n=function(c,h){var f;if("string"!=typeof c||c===e)return c;h=null!=h&&1===h.nodeType?h:document;if(c.match(/^#([\w\-]+$)/))return document.getElementById(c.split("#")[1]);f=h.querySelectorAll(c);return 1===f.length?f[0]:f};c.ext=function(e,h){h.el=k;c[e]=h};c.ext("each",function(c){k.length!==e&&k!==
window?[].forEach.call(k,c):c.call(k,k)});c.type=function(c){return function(){return c&&c!==this}.call(c)?(typeof c).toLowerCase():{}.toString.call(c).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()};c=window.$_=window.$_||c;c.$=n})();
(function(e,c){function n(a,b,d){var l;a.hasAttribute(b)&&(l=a.getAttribute(b));if(l===c&&(d===c||null===d))return null;if(d===c)return l;d!==c&&null!==d?a.setAttribute(b,d):null===d&&a.removeAttribute(b);return d!==c?d:l}function k(a){return String(a).replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function p(a,b,d){b=k(b);if(d===c&&a.style[b]!==c)return a.style[b];if(a.style[b]!==c)return a.style[b]=d,null}e.ext("dom",{addClass:function(a){e.each(function(b){b.classList.add(a)})},
removeClass:function(a){e.each(function(b){b.classList.remove(a)})},hide:function(){this.css("display","none")},show:function(a){a===c&&(a="block");this.css("display",a)},attr:function(a,b){var d=this.el;if(1<d.length&&b===c)return null;if(1<d.length&&b!==c)e.each(function(d){return n(d,a,b)});else return n(d,a,b)},text:function(a){var b,d,l;l=this.el;d=a!==c?!0:!1;b=l.textContent;return d?l.textContent=a:b},css:function(a,b){if("object"===e.type(a))Object.keys(a).forEach(function(b){e.each(function(c){p(c,
b,a[b])})});else if(b===c&&"object"!==e.type(a))return p(this.el,a);e.each(function(d){p(d,a,b)})},append:function(a){this.el.insertAdjacentHTML("beforeend",a)},prepend:function(a){this.el.insertAdjacentHTML("afterbegin",a)},html:function(a){a!==c&&(this.el.innerHTML=a);return this.el.innerHTML}});var h={_do:function(a,b,d,l,e){var g=new XMLHttpRequest;d===c&&(d=function(){});e=e?"POST":"GET";"GET"===e&&(a+=a.match(/\?/)?this._serialize(b):"?"+this._serialize(b));g.open(e,a);g.onreadystatechange=
function(){4===g.readyState&&(200===g.status?d.call(g.responseText,g.responseText):l!==c&&l.call(g.status,g.status))};"POST"===e?(g.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),g.send(this._serialize(b))):g.send(null)},_serialize:function(a){var b,d,c=[];for(b in a)a.hasOwnProperty(b)&&"function"!==e.type(a[b])&&(d=a[b].toString(),b=encodeURIComponent(b),d=encodeURIComponent(d),c.push(b+"="+d));return c.join("&")}};e.ext("get",function(a,b,d,c){h._do(a,b,d,c,!1)});e.ext("post",
function(a,b,d,c){h._do(a,b,d,c,!0)});var f,m;f=function(a,b,d,c){var e,g;if(b.match(/^([\w\-]+)$/))!0===c?a.addEventListener(b,d,!1):a.removeEventListener(b,d,!1);else for(b=b.split(" "),g=b.length,e=0;e<g;e++)f(a,b[e],d,c)};m=function(a,b,d,c){f(a,d,function(d){var g,f;f=e.$(b,a);for(g in f)d.target==f[g]&&(c.call(f[g],d),d.stopPropagation())},!0)};e.ext("event",{create:function(a,b){b=b||{};var d=document.createEvent("CustomEvent");d.initCustomEvent(a,!0,!0,b);return d},add:function(a,b){e.each(function(d){f(d,
a,b,!0)})},remove:function(a,b){e.each(function(d){f(d,a,b,!1)})},live:function(a,b,d){m(document.documentElement,a,b,d)},delegate:function(a,b,d){e.each(function(c){m(c,a,b,d)})},trigger:function(a){return this.el.dispatchEvent(a)}});var q=localStorage,r=sessionStorage;e.ext("store",{get:function(a,b){var d=b?r.getItem(a):q.getItem(a);return JSON.parse(d)},set:function(a,b,d){b=JSON.stringify(b);d?r.setItem(a,b):q.setItem(a,b)},remove:function(a,b){b?r.removeItem(a):q.removeItem(a)},getAll:function(a){var b,
d={},c,e;e=a?q:r;b=e.length;for(a=0;a<b;a++)c=e.key(a),d[c]=e.getItem(c);return d},clear:function(a){a?r.clear():q.clear()}})})($_);
(function(e){var d,k=function(m,h){d=m===e?k.el!==e?k.el:document.documentElement:r(m,h);k.prototype.el=d;var f=Object.create(k),n;for(n in f)"object"===typeof f[n]&&(f[n].el=d);f.el=d;return f},r=function(d,h){var f;if("string"!=typeof d||d===e)return d;h=null!=h&&1===h.nodeType?h:document;if(d.match(/^#([\w\-]+$)/))return document.getElementById(d.split("#")[1]);f=h.querySelectorAll(d);return 1===f.length?f[0]:f};k.ext=function(e,h){h.el=d;k[e]=h};k.ext("each",function(m){d.length!==e&&d!==window?
[].forEach.call(d,m):m.call(d,d)});k=window.$_=window.$_||k;k.$=r;k.type=function(d){return function(){return d&&d!==this}.call(d)?(typeof d).toLowerCase():{}.toString.call(d).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()}})();
(function(e,d){function k(a,b,c){var l;a.hasAttribute(b)&&(l=a.getAttribute(b));if(l===d&&(c===d||null===c))return null;if(c===d)return l;c!==d&&null!==c?a.setAttribute(b,c):null===c&&a.removeAttribute(b);return c!==d?c:l}function r(a){return String(a).replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function m(a,b,c){b=r(b);if(c===d&&a.style[b]!==d)return a.style[b];if(a.style[b]!==d)return a.style[b]=c,null}e.ext("dom",{addClass:function(a){e.each(function(b){b.classList.add(a)})},
removeClass:function(a){e.each(function(b){b.classList.remove(a)})},hide:function(){this.css("display","none")},show:function(a){a===d&&(a="block");this.css("display",a)},attr:function(a,b){var c=this.el;if(1<c.length&&b===d)return null;if(1<c.length&&b!==d)e.each(function(c){return k(c,a,b)});else return k(c,a,b)},text:function(a){var b,c,l;l=this.el;c=a!==d?!0:!1;b=l.textContent;return c?l.textContent=a:b},css:function(a,b){if("object"===e.type(a))Object.keys(a).forEach(function(b){e.each(function(d){m(d,
b,a[b])})});else if(b===d&&"object"!==e.type(a))return m(this.el,a);e.each(function(c){m(c,a,b)})},append:function(a){this.el.insertAdjacentHTML("beforeend",a)},prepend:function(a){this.el.insertAdjacentHTML("afterbegin",a)},html:function(a){a!==d&&(this.el.innerHTML=a);return this.el.innerHTML}});var h={_do:function(a,b,c,l,e){var g=new XMLHttpRequest;c===d&&(c=function(){});"GET"===e&&(a+=a.match(/\?/)?this._serialize(b):"?"+this._serialize(b));g.open(e,a);g.onreadystatechange=function(){4===g.readyState&&
(200===g.status?c.call(g.responseText,g.responseText):l!==d&&l.call(g.status,g.status))};"GET"!==e?(g.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),g.send(this._serialize(b))):g.send(null)},_serialize:function(a){var b,c,d=[];for(b in a)a.hasOwnProperty(b)&&"function"!==e.type(a[b])&&(c=a[b].toString(),b=encodeURIComponent(b),c=encodeURIComponent(c),d.push(b+"="+c));return d.join("&")}};e.ext("get",function(a,b,c,d){h._do(a,b,c,d,"GET")});e.ext("post",function(a,b,c,d){h._do(a,
b,c,d,"POST")});e.ext("put",function(a,b,c,d){h._do(a,b,c,d,"PUT")});e.ext("delete",function(a,b,c,d){h._do(a,b,c,d,"DELETE")});var f,n;f=function(a,b,c,d){var e,g;if(b.match(/^([\w\-]+)$/))!0===d?a.addEventListener(b,c,!1):a.removeEventListener(b,c,!1);else for(b=b.split(" "),g=b.length,e=0;e<g;e++)f(a,b[e],c,d)};n=function(a,b,c,d){f(a,c,function(c){var g,f;f=e.$(b,a);for(g in f)c.target==f[g]&&(d.call(f[g],c),c.stopPropagation())},!0)};e.ext("event",{create:function(a,b){b=b||{};var c=document.createEvent("CustomEvent");
c.initCustomEvent(a,!0,!0,b);return c},add:function(a,b){e.each(function(c){f(c,a,b,!0)})},remove:function(a,b){e.each(function(c){f(c,a,b,!1)})},live:function(a,b,c){n(document.documentElement,a,b,c)},delegate:function(a,b,c){e.each(function(d){n(d,a,b,c)})},trigger:function(a){return this.el.dispatchEvent(a)}});var p=localStorage,q=sessionStorage;e.ext("store",{get:function(a,b){var c=b?q.getItem(a):p.getItem(a);return JSON.parse(c)},set:function(a,b,c){b=JSON.stringify(b);c?q.setItem(a,b):p.setItem(a,
b)},remove:function(a,b){b?q.removeItem(a):p.removeItem(a)},getAll:function(a){var b,c={},d,e;e=a?p:q;b=e.length;for(a=0;a<b;a++)d=e.key(a),c[d]=e.getItem(d);return c},clear:function(a){a?q.clear():p.clear()}})})($_);

View File

@ -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,4 +155,5 @@
//Set global variables
$_ = window.$_ = window.$_ || $_;
$_.$ = $;
}());
$_.type = type;
}());

View File

@ -223,6 +223,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
@ -256,7 +258,7 @@
/**
* Adds to the innerHTML of the current element, after the last child.
*
* @example $_("ul").dom.append("&lt;li&gt;&lt;/li&gt;") 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
@ -269,6 +271,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

View File

@ -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');
});
}());

View File

@ -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);
}
};

View File

@ -1,4 +0,0 @@
/**
* A module of various browser polyfills
* @file polyfill.js
*/

View File

@ -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);
}

View File

@ -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();
});
});
}());

View File

@ -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");

View File

@ -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);
});
}());