Compare commits
111 Commits
Author | SHA1 | Date |
---|---|---|
Timothy Warren | 3c99e243d3 | |
Timothy Warren | 3ef9e89ab6 | |
Timothy Warren | 8e9d93a525 | |
Timothy Warren | 14b8a6c981 | |
Timothy Warren | 517fe203e7 | |
Timothy Warren | 67991ae40d | |
Timothy Warren | 35bdf75408 | |
Timothy Warren | c861483d75 | |
Timothy Warren | 8193bbab38 | |
Timothy Warren | 5dc517f24e | |
Timothy Warren | 6829ad10f7 | |
Timothy Warren | 1dad460368 | |
Timothy Warren | 3ed6b229f6 | |
Timothy Warren | da02feb2d2 | |
Timothy Warren | 3f3956a345 | |
Timothy Warren | e3f79c3fa2 | |
Timothy Warren | 000b462b17 | |
Timothy Warren | 08f1e03f23 | |
Timothy Warren | 6cfd535f19 | |
Timothy Warren | 5381e70fe7 | |
Timothy Warren | 5395f4773f | |
Timothy Warren | 5ef4e7f837 | |
Timothy Warren | 9aa6a96b88 | |
Timothy Warren | ed64186a58 | |
Timothy Warren | 04e8f2e3c7 | |
Timothy Warren | 51dccdeaf9 | |
Timothy Warren | 647e3f3d3d | |
Timothy Warren | b5c203aa15 | |
Timothy Warren | b45707675c | |
Timothy Warren | 1a8addc49c | |
Timothy Warren | 6b2fab7b46 | |
Timothy Warren | 19ab4751e4 | |
Timothy Warren | a0d09416cb | |
Timothy Warren | 5757986aa8 | |
Timothy Warren | d62d9ff127 | |
Timothy Warren | 6d990b65bb | |
Timothy Warren | 095f93ebb2 | |
Timothy Warren | e635925a6d | |
Na7coldwater | c83ea1ce89 | |
Timothy Warren | b6f16a4758 | |
Timothy Warren | 7b73be9de7 | |
Timothy Warren | f98323aeec | |
Timothy Warren | f03c9431dd | |
Timothy Warren | 057e8c1dd7 | |
Timothy Warren | 69fb63a983 | |
Timothy Warren | 9205532e79 | |
Timothy Warren | 40534cd87c | |
Timothy Warren | 905f9431f3 | |
Timothy Warren | b13b012a25 | |
Timothy Warren | a26a04f1a7 | |
Timothy Warren | 59bfb68a4e | |
Timothy Warren | 090212cd9d | |
Timothy Warren | ecb538787b | |
Timothy Warren | 53522e24df | |
Timothy Warren | fe829d75cd | |
Timothy Warren | 8bc99c465b | |
Timothy Warren | fa3fb5686f | |
Timothy Warren | d64b83d2e5 | |
Timothy Warren | 8969cd31cb | |
Timothy Warren | d1f1af40ae | |
Timothy Warren | 2cefaa19aa | |
Timothy Warren | 3d241c2f8b | |
Timothy Warren | ab99f79b2c | |
Timothy Warren | 21ffcb19c9 | |
Timothy Warren | f1bd4d92ee | |
Timothy Warren | b43960338a | |
Timothy Warren | 90bceb4fe9 | |
Timothy Warren | 1237ea511e | |
Timothy Warren | 69ee39623d | |
Timothy Warren | db76e16393 | |
Timothy Warren | c15fff3b4b | |
Timothy Warren | 5206f6f259 | |
Timothy Warren | 1a007356d0 | |
Timothy Warren | 06fa41aa0c | |
Timothy Warren | 038a579554 | |
Timothy Warren | 5529d98054 | |
Timothy Warren | 980410b901 | |
Timothy Warren | 19de9f1409 | |
Timothy Warren | c1528a0b8b | |
Timothy Warren | da22f46b89 | |
Timothy Warren | 1c014459df | |
Timothy Warren | f8350e516a | |
Timothy Warren | 84d05b4cf8 | |
Timothy Warren | 5f8b289e22 | |
Timothy Warren | 1b5d20b31d | |
Timothy Warren | a297c25815 | |
Timothy Warren | 20ca5e272b | |
Timothy Warren | ac1bd247b9 | |
Timothy Warren | 9174ceb6dd | |
Timothy Warren | 492f7bb2ed | |
Timothy Warren | d75001d5bd | |
Preston Skupinski | 593ddc96df | |
Timothy Warren | bbd65b2cb7 | |
Timothy Warren | 226c4c38c4 | |
Timothy Warren | 457ccf07a4 | |
Timothy Warren | afde37c6e3 | |
Nate B | f7bf984d68 | |
Nate B | 4c1bfea9e9 | |
Timothy Warren | 14be928463 | |
Timothy Warren | 1f7181d4be | |
Timothy Warren | 32db8c04c6 | |
Timothy Warren | f3963925a3 | |
Timothy Warren | 9014a081ab | |
Timothy Warren | a3f270ba95 | |
Timothy Warren | badaf25867 | |
Timothy Warren | ea52ed6bf2 | |
Timothy Warren | 167f5fafdf | |
Timothy Warren | 02947a1192 | |
Timothy Warren | f2f7fb1343 | |
Timothy Warren | aa3db3521e | |
Timothy Warren | bcde2120a4 |
|
@ -0,0 +1,7 @@
|
|||
kis-custom.js
|
||||
kis-custom-min.js
|
||||
combine-build.php
|
||||
test.html
|
||||
config.json
|
||||
docs.conf
|
||||
.*
|
|
@ -4,112 +4,62 @@ A Minimal, Modular Javascript library for Modern browsers.
|
|||
|
||||
Aims to be fast, small, and easily split into individual modules.
|
||||
|
||||
Browser support: IE8+, Latest versions of Firefox, Chrome, Safari, Opera
|
||||
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: ##
|
||||
|
||||
* Selector: `var x = $(selector);`
|
||||
* 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/](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
|
||||
|
||||
* Function: `$_.module.function(params);`
|
||||
|
||||
## Modules: ##
|
||||
|
||||
**Ajax**: simple, jQuery-like ajax functions
|
||||
|
||||
functions:
|
||||
|
||||
* Get:
|
||||
Use:
|
||||
$_.get(url, data_object, callback);
|
||||
|
||||
* Post:
|
||||
Use:
|
||||
$_.post(url, data_object, callback);
|
||||
|
||||
**QS**: querystring parsing and serialization for hashbang strings, and pushState urls
|
||||
|
||||
functions:
|
||||
|
||||
* Parse:
|
||||
Use:
|
||||
$_.qs.parse(hb);
|
||||
|
||||
* Set: This function will set the hash url if browser doesn't have history.pushState
|
||||
Use:
|
||||
$_.qs.set(key, value);
|
||||
|
||||
* Get: Retrieves the value of the key in the url string
|
||||
Use:
|
||||
$_.qs.get(key);
|
||||
|
||||
**Store**: localstorage wrapper with automatic data serialization
|
||||
|
||||
functions:
|
||||
|
||||
* Get:
|
||||
Use:
|
||||
$_.store.get(key);
|
||||
|
||||
* Set
|
||||
Use:
|
||||
$_.store.set(key, value);
|
||||
|
||||
* getALL: Retreives all localstorage data in raw form
|
||||
Use:
|
||||
$_.store.getAll();
|
||||
|
||||
|
||||
**Event**: wrapper for applying events to DOM objects
|
||||
|
||||
functions:
|
||||
|
||||
*Add:
|
||||
Use:
|
||||
$_.event.add(selector, event, callback);
|
||||
|
||||
*Remove
|
||||
Use:
|
||||
$_.event.remove(selector, event, callback);
|
||||
|
||||
**DOM**: Dom manipulation module
|
||||
|
||||
function:
|
||||
|
||||
*addClass:
|
||||
Use:
|
||||
$_.dom.addClass(selector, className);
|
||||
|
||||
*RemoveClass:
|
||||
Use:
|
||||
$_.dom.removeClass(selector, className);
|
||||
|
||||
*each: For applying changes to every item matched by a selector
|
||||
Use:
|
||||
$_.dom.each(selector, callback);
|
||||
|
||||
Example : $_.dom.each(".foo", function(e){
|
||||
$_.dom.text(e, value);
|
||||
}):
|
||||
|
||||
*show: For setting dom elements as visible. Type defaults as "block", can be set with optional second parameter.
|
||||
Use:
|
||||
$_.dom.show(selector, [type]);
|
||||
|
||||
*hide: Hides the elements matching the selector
|
||||
Use:
|
||||
$_.dom.hide(selector);
|
||||
|
||||
*attr: Gets, sets, or removes an attribute from a selector.
|
||||
Use:
|
||||
Set: $_.dom.attr(selector, attributeName, attributeValue);
|
||||
Get: $_.dom.attr(selector, attributeName);
|
||||
Remove: $_.dom.attr(selector, attributeName, null);
|
||||
|
||||
*text: Gets or sets the text in between an element's tags
|
||||
Use:
|
||||
Set: $_.dom.text(selector, text);
|
||||
Get: $_.dom.text(selector);
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Combine.php
|
||||
*
|
||||
* This script combines modules into one continuous source file.
|
||||
*/
|
||||
|
||||
//The name of the source folder
|
||||
$folder = "src";
|
||||
$src_folder = "{$folder}/modules";
|
||||
|
||||
//The divider added between the contents of merged files
|
||||
$divider = "\n// --------------------------------------------------------------------------\n\n";
|
||||
|
||||
$files = array();
|
||||
|
||||
//Get all the source files
|
||||
if($dir = opendir($src_folder))
|
||||
{
|
||||
while(($file = readdir($dir)) !== FALSE)
|
||||
{
|
||||
//Don't grab . and ..
|
||||
if($file !== "." && $file !== "..")
|
||||
{
|
||||
$files[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
closedir($dir);
|
||||
}
|
||||
|
||||
//Start with the core
|
||||
$new_file = file_get_contents("{$folder}/core.js") . "\n";
|
||||
|
||||
//Add polyfills
|
||||
$new_file .= $divider;
|
||||
$new_file .= file_get_contents("{$folder}/polyfill.js") . "\n";
|
||||
|
||||
|
||||
//Add the modules
|
||||
foreach($files as $f)
|
||||
{
|
||||
$farray = file($src_folder."/".$f, FILE_IGNORE_NEW_LINES);
|
||||
|
||||
$flen = count($farray);
|
||||
|
||||
$module = implode("\n", $farray);
|
||||
|
||||
$new_file .= $divider.$module."\n";
|
||||
|
||||
}
|
||||
|
||||
//Output the full file
|
||||
file_put_contents("kis-custom.js", $new_file);
|
||||
|
||||
//Get a much-minified version from Google's closure compiler
|
||||
$ch = curl_init('http://closure-compiler.appspot.com/compile');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, 'output_info=compiled_code&output_format=text&compilation_level=SIMPLE_OPTIMIZATIONS&js_code=' . urlencode($new_file));
|
||||
$output = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
file_put_contents("kis-custom-min.js", $output);
|
||||
|
||||
|
||||
//Display the output on-screen too
|
||||
echo '<pre style="-moz-tab-size:4;">'.htmlspecialchars($new_file).'</pre>';
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,857 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>JSDoc: Namespace: store</title>
|
||||
|
||||
<script src="scripts/prettify/prettify.js"> </script>
|
||||
<script src="scripts/prettify/lang-css.js"> </script>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
||||
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="main">
|
||||
|
||||
<h1 class="page-title">Namespace: store</h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section>
|
||||
|
||||
<header>
|
||||
<h2>
|
||||
<span class="ancestors"><a href="$_.html">$_</a>.</span>
|
||||
|
||||
store
|
||||
</h2>
|
||||
|
||||
</header>
|
||||
|
||||
<article>
|
||||
<div class="container-overview">
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="description">Wrapper for localstorage / sessionstorage data serialization.
|
||||
Each method has a boolean parameter, that when set as true switches the method
|
||||
to use sessionStorage rather than the default localStorage.</div>
|
||||
|
||||
|
||||
|
||||
<dl class="details">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="store.js.html">modules/store.js</a>, <a href="store.js.html#line14">line 14</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3 class="subsection-title">Methods</h3>
|
||||
|
||||
<dl>
|
||||
|
||||
<dt>
|
||||
<h4 class="name" id="clear"><span class="type-signature">(static) </span>clear<span class="signature">(session)</span><span class="type-signature"></span></h4>
|
||||
|
||||
|
||||
</dt>
|
||||
<dd>
|
||||
|
||||
|
||||
<div class="description">
|
||||
Removes all values from the same domain storage
|
||||
</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>session</code></td>
|
||||
|
||||
|
||||
<td class="type">
|
||||
|
||||
|
||||
<span class="param-type">bool</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="store.js.html">modules/store.js</a>, <a href="store.js.html#line102">line 102</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
|
||||
|
||||
|
||||
<dt>
|
||||
<h4 class="name" id="get"><span class="type-signature">(static) </span>get<span class="signature">(key, session)</span><span class="type-signature"> → {Object}</span></h4>
|
||||
|
||||
|
||||
</dt>
|
||||
<dd>
|
||||
|
||||
|
||||
<div class="description">
|
||||
Retrieves and deserializes a value from localstorage,
|
||||
based on the specified key
|
||||
</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>key</code></td>
|
||||
|
||||
|
||||
<td class="type">
|
||||
|
||||
|
||||
<span class="param-type">string</span>
|
||||
|
||||
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<td class="description last"></td>
|
||||
</tr>
|
||||
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="name"><code>session</code></td>
|
||||
|
||||
|
||||
<td class="type">
|
||||
|
||||
|
||||
<span class="param-type">bool</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="store.js.html">modules/store.js</a>, <a href="store.js.html#line24">line 24</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h5>Returns:</h5>
|
||||
|
||||
|
||||
|
||||
|
||||
<dl>
|
||||
<dt>
|
||||
Type
|
||||
</dt>
|
||||
<dd>
|
||||
|
||||
<span class="param-type">Object</span>
|
||||
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
|
||||
|
||||
|
||||
<dt>
|
||||
<h4 class="name" id="getAll"><span class="type-signature">(static) </span>getAll<span class="signature">(session)</span><span class="type-signature"> → {Object}</span></h4>
|
||||
|
||||
|
||||
</dt>
|
||||
<dd>
|
||||
|
||||
|
||||
<div class="description">
|
||||
Returns an object of all the raw values in storage
|
||||
</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>session</code></td>
|
||||
|
||||
|
||||
<td class="type">
|
||||
|
||||
|
||||
<span class="param-type">bool</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="store.js.html">modules/store.js</a>, <a href="store.js.html#line72">line 72</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h5>Returns:</h5>
|
||||
|
||||
|
||||
|
||||
|
||||
<dl>
|
||||
<dt>
|
||||
Type
|
||||
</dt>
|
||||
<dd>
|
||||
|
||||
<span class="param-type">Object</span>
|
||||
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
|
||||
|
||||
|
||||
<dt>
|
||||
<h4 class="name" id="remove"><span class="type-signature">(static) </span>remove<span class="signature">(key, session)</span><span class="type-signature"></span></h4>
|
||||
|
||||
|
||||
</dt>
|
||||
<dd>
|
||||
|
||||
|
||||
<div class="description">
|
||||
Removes the specified item from storage
|
||||
</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>key</code></td>
|
||||
|
||||
|
||||
<td class="type">
|
||||
|
||||
|
||||
<span class="param-type">string</span>
|
||||
|
||||
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<td class="description last"></td>
|
||||
</tr>
|
||||
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="name"><code>session</code></td>
|
||||
|
||||
|
||||
<td class="type">
|
||||
|
||||
|
||||
<span class="param-type">bool</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="store.js.html">modules/store.js</a>, <a href="store.js.html#line59">line 59</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
|
||||
|
||||
|
||||
<dt>
|
||||
<h4 class="name" id="set"><span class="type-signature">(static) </span>set<span class="signature">(key, value, session)</span><span class="type-signature"></span></h4>
|
||||
|
||||
|
||||
</dt>
|
||||
<dd>
|
||||
|
||||
|
||||
<div class="description">
|
||||
Puts a value into localstorage at the specified key,
|
||||
and JSON-encodes the value if not a string
|
||||
</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>key</code></td>
|
||||
|
||||
|
||||
<td class="type">
|
||||
|
||||
|
||||
<span class="param-type">string</span>
|
||||
|
||||
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<td class="description last"></td>
|
||||
</tr>
|
||||
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="name"><code>value</code></td>
|
||||
|
||||
|
||||
<td class="type">
|
||||
|
||||
|
||||
<span class="param-type">mixed</span>
|
||||
|
||||
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<td class="description last"></td>
|
||||
</tr>
|
||||
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="name"><code>session</code></td>
|
||||
|
||||
|
||||
<td class="type">
|
||||
|
||||
|
||||
<span class="param-type">bool</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="store.js.html">modules/store.js</a>, <a href="store.js.html#line41">line 41</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
</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>
|
||||
</nav>
|
||||
|
||||
<br clear="both">
|
||||
|
||||
<footer>
|
||||
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>
|
||||
<script src="scripts/linenumber.js"> </script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,357 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>JSDoc: Source: modules/DOM.js</title>
|
||||
|
||||
<script src="scripts/prettify/prettify.js"> </script>
|
||||
<script src="scripts/prettify/lang-css.js"> </script>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
||||
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="main">
|
||||
|
||||
<h1 class="page-title">Source: modules/DOM.js</h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section>
|
||||
<article>
|
||||
<pre class="prettyprint source linenums"><code>/**
|
||||
* DOM
|
||||
*
|
||||
* Dom manipulation module
|
||||
*/
|
||||
(function (undefined){
|
||||
|
||||
"use strict";
|
||||
|
||||
var d;
|
||||
|
||||
//Private function for getting/setting attributes/properties
|
||||
function _attr(sel, name, value)
|
||||
{
|
||||
var oldVal;
|
||||
|
||||
//Get the value of the attribute, if it exists
|
||||
if (sel.hasAttribute(name))
|
||||
{
|
||||
oldVal = sel.getAttribute(name);
|
||||
}
|
||||
|
||||
//Well, I guess that attribute doesn't exist
|
||||
if (oldVal === undefined && (value === undefined || value === null))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
//No value to set? Return the current value
|
||||
if (value === undefined)
|
||||
{
|
||||
return oldVal;
|
||||
}
|
||||
|
||||
//Determine what to do with the attribute
|
||||
if (value !== undefined && value !== null)
|
||||
{
|
||||
sel.setAttribute(name, value);
|
||||
}
|
||||
else if (value === null)
|
||||
{
|
||||
sel.removeAttribute(name);
|
||||
}
|
||||
|
||||
return (value !== undefined) ? value : oldVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change css property name to it's
|
||||
* javascript camel case equivalent
|
||||
*/
|
||||
function _toCamel(s)
|
||||
{
|
||||
return String(s).replace(/(\-[a-z])/g, function($1){
|
||||
return $1.toUpperCase().replace('-','');
|
||||
});
|
||||
}
|
||||
|
||||
function _css(sel, prop, val)
|
||||
{
|
||||
//Camel-case
|
||||
prop = _toCamel(prop);
|
||||
|
||||
//If you don't define a value, try returning the existing value
|
||||
if(val === undefined && sel.style[prop] !== undefined)
|
||||
{
|
||||
return sel.style[prop];
|
||||
}
|
||||
|
||||
// Let's set a value instead
|
||||
if(sel.style[prop] !== undefined)
|
||||
{
|
||||
sel.style[prop] = val;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* DOM
|
||||
*
|
||||
* Dom manipulation module
|
||||
* @namespace
|
||||
* @memberOf $_
|
||||
* @name dom
|
||||
*/
|
||||
d = {
|
||||
/**
|
||||
* Adds a class to the element(s) specified by the current
|
||||
* selector
|
||||
*
|
||||
* @name addClass
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {string} class
|
||||
*/
|
||||
addClass: function (c)
|
||||
{
|
||||
$_.each(function (e){
|
||||
e.classList.add(c);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Removes a class from the element(s) specified by the current
|
||||
* selector
|
||||
*
|
||||
* @name removeClass
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {string} class
|
||||
*/
|
||||
removeClass: function (c)
|
||||
{
|
||||
$_.each(function (e){
|
||||
e.classList.remove(c);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Hides the element(s) specified by the current selector
|
||||
*
|
||||
* @name hide
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
*/
|
||||
hide: function ()
|
||||
{
|
||||
this.css('display', 'none');
|
||||
},
|
||||
/**
|
||||
* Shows the element(s) specified by the current selector.
|
||||
* if type is specified, the element will have it's style
|
||||
* property set to "display:[your type]". If type is not
|
||||
* specified, the element is set to "display:block".
|
||||
*
|
||||
* @name show
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {string} [type]
|
||||
*/
|
||||
show: function (type)
|
||||
{
|
||||
if (type === undefined)
|
||||
{
|
||||
type = "block";
|
||||
}
|
||||
|
||||
this.css("display", type);
|
||||
},
|
||||
/**
|
||||
* Sets attributes on element(s) specified by the current
|
||||
* selector, or, if name is not specified, returns the
|
||||
* value of the attribute of the element specified by the
|
||||
* current selector.
|
||||
*
|
||||
* @name attr
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {string} name
|
||||
* @param {?string}[value]
|
||||
* @return {?string}
|
||||
*/
|
||||
attr: function (name, value)
|
||||
{
|
||||
var sel = this.el;
|
||||
|
||||
//Make sure you don't try to get a bunch of elements
|
||||
if (sel.length > 1 && value === undefined)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if (sel.length > 1 && value !== undefined) //You can set a bunch, though
|
||||
{
|
||||
$_.each(function (e){
|
||||
return _attr(e, name, value);
|
||||
});
|
||||
}
|
||||
else //Normal behavior
|
||||
{
|
||||
return _attr(sel, name, value);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Sets or retrieves the text content of the element
|
||||
* specified by the current selector. If a value is
|
||||
* passed, it will set that value on the current element,
|
||||
* otherwise it will return the value of the current element
|
||||
*
|
||||
* @name text
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {?string} [value]
|
||||
* @return {?string}
|
||||
*/
|
||||
text: function (value)
|
||||
{
|
||||
var oldValue, set, sel;
|
||||
|
||||
sel = this.el;
|
||||
|
||||
set = (value !== undefined) ? true : false;
|
||||
|
||||
oldValue = sel.textContent;
|
||||
|
||||
if(set)
|
||||
{
|
||||
sel.textContent = value;
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return oldValue;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Sets or retrieves a css property of the element
|
||||
* specified by the current selector. If a value is
|
||||
* passed, it will set that value on the current element,
|
||||
* otherwise it will return the value of the css property
|
||||
* on the current element.
|
||||
*
|
||||
* 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
|
||||
* @param {(string|Object)} property
|
||||
* @param {?string} [value]
|
||||
* @return {?string}
|
||||
*/
|
||||
css: function (prop, val)
|
||||
{
|
||||
var prop_key = null;
|
||||
|
||||
// If passed an object, recurse!
|
||||
if($_.type(prop) === 'object')
|
||||
{
|
||||
Object.keys(prop).forEach(function(prop_key) {
|
||||
$_.each(function (e){
|
||||
_css(e, prop_key, prop[prop_key]);
|
||||
});
|
||||
});
|
||||
}
|
||||
//Return the current value if a value is not set
|
||||
else if(val === undefined && $_.type(prop) !== 'object')
|
||||
{
|
||||
return _css(this.el, prop);
|
||||
}
|
||||
|
||||
$_.each(function (e){
|
||||
_css(e, prop, val);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 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
|
||||
* @name append
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {string} htm
|
||||
*/
|
||||
append: function(htm)
|
||||
{
|
||||
this.el.insertAdjacentHTML('beforeend', htm);
|
||||
},
|
||||
/**
|
||||
* 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
|
||||
* @param {string} htm
|
||||
*/
|
||||
prepend: function(htm)
|
||||
{
|
||||
this.el.insertAdjacentHTML('afterbegin', htm);
|
||||
},
|
||||
/**
|
||||
* Sets or gets the innerHTML propery of the element(s) passed
|
||||
*
|
||||
* @name html
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {?string} [htm]
|
||||
* @return {?string}
|
||||
*/
|
||||
html: function(htm)
|
||||
{
|
||||
|
||||
if(htm !== undefined)
|
||||
{
|
||||
this.el.innerHTML = htm;
|
||||
}
|
||||
|
||||
//If the parameter is undefined, just return the current value
|
||||
return this.el.innerHTML;
|
||||
}
|
||||
};
|
||||
|
||||
$_.ext('dom', d);
|
||||
|
||||
}());</code></pre>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
</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>
|
||||
</nav>
|
||||
|
||||
<br clear="both">
|
||||
|
||||
<footer>
|
||||
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>
|
||||
<script src="scripts/linenumber.js"> </script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,199 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>JSDoc: Source: modules/ajax.js</title>
|
||||
|
||||
<script src="scripts/prettify/prettify.js"> </script>
|
||||
<script src="scripts/prettify/lang-css.js"> </script>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
||||
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="main">
|
||||
|
||||
<h1 class="page-title">Source: modules/ajax.js</h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section>
|
||||
<article>
|
||||
<pre class="prettyprint source linenums"><code>/**
|
||||
* Ajax
|
||||
*
|
||||
* Module for making ajax requests
|
||||
*/
|
||||
(function (undefined){
|
||||
|
||||
"use strict";
|
||||
|
||||
var ajax = {
|
||||
_do: function (url, data, success_callback, error_callback, type)
|
||||
{
|
||||
var type,
|
||||
request = new XMLHttpRequest();
|
||||
|
||||
if (success_callback === undefined)
|
||||
{
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
success_callback = function (){};
|
||||
}
|
||||
|
||||
if (type === "GET")
|
||||
{
|
||||
url += (url.match(/\?/))
|
||||
? this._serialize(data)
|
||||
: "?" + this._serialize(data);
|
||||
}
|
||||
|
||||
request.open(type, url);
|
||||
|
||||
request.onreadystatechange = function ()
|
||||
{
|
||||
if (request.readyState === 4)
|
||||
{
|
||||
if (request.status === 200)
|
||||
{
|
||||
success_callback.call(request.responseText, request.responseText);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (error_callback !== undefined)
|
||||
{
|
||||
error_callback.call(request.status, request.status);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
if (type !== "GET")
|
||||
{
|
||||
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
request.send(this._serialize(data));
|
||||
}
|
||||
else
|
||||
{
|
||||
request.send(null);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Url encoding for non-get requests
|
||||
*
|
||||
* @param data
|
||||
* @returns {string}
|
||||
* @private
|
||||
*/
|
||||
_serialize: function (data)
|
||||
{
|
||||
var name,
|
||||
value,
|
||||
pairs = [];
|
||||
|
||||
for (name in data)
|
||||
{
|
||||
if ( ! data.hasOwnProperty(name) || $_.type(data[name]) === "function")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
value = data[name].toString();
|
||||
|
||||
name = encodeURIComponent(name);
|
||||
value = encodeURIComponent(value);
|
||||
|
||||
pairs.push(name + "=" + value);
|
||||
}
|
||||
|
||||
return pairs.join("&");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends a GET type ajax request
|
||||
*
|
||||
* @function get
|
||||
* @memberOf $_
|
||||
* @param {string} url - The url to retrieve
|
||||
* @param {Object} data - get parameters to send
|
||||
* @param {function} success_callback - callback called on success
|
||||
* @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, 'GET');
|
||||
});
|
||||
|
||||
/**
|
||||
* Sends a POST type ajax request
|
||||
*
|
||||
* @function post
|
||||
* @memberOf $_
|
||||
* @param {string} url - The url to post to
|
||||
* @param {Object} data - post parameters to send
|
||||
* @param {function} success_callback - callback called on success
|
||||
* @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, '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>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
</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>
|
||||
</nav>
|
||||
|
||||
<br clear="both">
|
||||
|
||||
<footer>
|
||||
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>
|
||||
<script src="scripts/linenumber.js"> </script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,208 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>JSDoc: Source: core.js</title>
|
||||
|
||||
<script src="scripts/prettify/prettify.js"> </script>
|
||||
<script src="scripts/prettify/lang-css.js"> </script>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
||||
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="main">
|
||||
|
||||
<h1 class="page-title">Source: core.js</h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section>
|
||||
<article>
|
||||
<pre class="prettyprint source linenums"><code>/**
|
||||
Kis JS Keep It Simple JS Library
|
||||
Copyright Timothy J. Warren
|
||||
License Public Domain
|
||||
Version 0.9.0
|
||||
*/
|
||||
(function (undefined){
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Current selector object
|
||||
*
|
||||
* @memberOf $_
|
||||
* @name el
|
||||
*/
|
||||
var sel;
|
||||
|
||||
|
||||
/**
|
||||
* $_
|
||||
*
|
||||
* Constructor function
|
||||
*
|
||||
* @constructor
|
||||
* @namespace $_
|
||||
* @param {string} selector - The dom selector string
|
||||
* @param {Object} [context] - Context of the dom selector string
|
||||
* @return {Object}
|
||||
*/
|
||||
var $_ = function(s, context)
|
||||
{
|
||||
// Have documentElement be default selector, just in case
|
||||
if (s === undefined)
|
||||
{
|
||||
// Defines a "global" selector for that instance
|
||||
sel = ($_.el !== undefined)
|
||||
? $_.el
|
||||
: document.documentElement;
|
||||
}
|
||||
else
|
||||
{
|
||||
sel = $(s, context);
|
||||
}
|
||||
|
||||
// Add the selector to the prototype
|
||||
$_.prototype.el = sel;
|
||||
|
||||
// Use the $_ object as it's own prototype
|
||||
var self = Object.create($_);
|
||||
|
||||
// Give sel to each extension.
|
||||
for(var i in self)
|
||||
{
|
||||
if(typeof self[i] === "object")
|
||||
{
|
||||
self[i].el = sel;
|
||||
}
|
||||
}
|
||||
|
||||
self.el = sel;
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
/**
|
||||
* Simple DOM selector function
|
||||
*
|
||||
* @memberOf $_
|
||||
* @param {string} selector
|
||||
* @param {Object} [context]
|
||||
* @return {Object}
|
||||
*/
|
||||
var $ = function (selector, context)
|
||||
{
|
||||
var elements;
|
||||
|
||||
if (typeof selector != "string" || selector === undefined){ return selector;}
|
||||
|
||||
//Check for a context of a specific element, otherwise, just run on the document
|
||||
context = (context != null && context.nodeType === 1)
|
||||
? context
|
||||
: document;
|
||||
|
||||
//Pick the quickest method for each kind of selector
|
||||
if (selector.match(/^#([\w\-]+$)/))
|
||||
{
|
||||
return document.getElementById(selector.split('#')[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
elements = context.querySelectorAll(selector);
|
||||
}
|
||||
|
||||
//Return the single object if applicable
|
||||
return (elements.length === 1) ? elements[0] : elements;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
$_.ext = function(name, obj)
|
||||
{
|
||||
obj.el = sel;
|
||||
$_[name] = obj;
|
||||
};
|
||||
|
||||
/**
|
||||
* Iterates over a $_ object, applying a callback to each item
|
||||
*
|
||||
* @memberOf $_
|
||||
* @function each
|
||||
* @example $_('form input').each(function(item) { alert(item) });
|
||||
* @param {function} callback - iteration callback
|
||||
*/
|
||||
$_.ext('each', function(callback)
|
||||
{
|
||||
if(sel.length !== undefined && sel !== window)
|
||||
{
|
||||
[].forEach.call(sel, callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
callback.call(sel, sel);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Retrieves the type of the passed variable
|
||||
*
|
||||
* @memberOf $_
|
||||
* @function type
|
||||
* @example $_.type([]); // Returns 'array'
|
||||
* @param {*} obj
|
||||
* @return {string}
|
||||
*/
|
||||
var type = function(obj)
|
||||
{
|
||||
if((function() {return obj && (obj !== this)}).call(obj))
|
||||
{
|
||||
//fallback on 'typeof' for truthy primitive values
|
||||
return (typeof obj).toLowerCase();
|
||||
}
|
||||
|
||||
//Strip x from [object x] and return
|
||||
return ({}).toString.call(obj).match(/\s([a-z|A-Z]+)/)[1].toLowerCase();
|
||||
};
|
||||
|
||||
//Set global variables
|
||||
$_ = window.$_ = window.$_ || $_;
|
||||
$_.$ = $;
|
||||
$_.type = type;
|
||||
}());</code></pre>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
</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>
|
||||
</nav>
|
||||
|
||||
<br clear="both">
|
||||
|
||||
<footer>
|
||||
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>
|
||||
<script src="scripts/linenumber.js"> </script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,228 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>JSDoc: Source: modules/event.js</title>
|
||||
|
||||
<script src="scripts/prettify/prettify.js"> </script>
|
||||
<script src="scripts/prettify/lang-css.js"> </script>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
||||
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="main">
|
||||
|
||||
<h1 class="page-title">Source: modules/event.js</h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section>
|
||||
<article>
|
||||
<pre class="prettyprint source linenums"><code>/**
|
||||
* Event
|
||||
*
|
||||
* Event api wrapper
|
||||
* @todo Add method for triggering events
|
||||
*/
|
||||
(function (undefined){
|
||||
|
||||
"use strict";
|
||||
|
||||
var _add_remove, e, _attach_delegate;
|
||||
|
||||
_add_remove = function (sel, event, callback, add)
|
||||
{
|
||||
var i, len;
|
||||
|
||||
// Multiple events? Run recursively!
|
||||
if ( ! event.match(/^([\w\-]+)$/))
|
||||
{
|
||||
event = event.split(" ");
|
||||
|
||||
len = event.length;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
_add_remove(sel, event[i], callback, add);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Bind the event
|
||||
(add === true)
|
||||
? sel.addEventListener(event, callback, false)
|
||||
: sel.removeEventListener(event, callback, false);
|
||||
};
|
||||
|
||||
_attach_delegate = function(sel, target, event, callback)
|
||||
{
|
||||
// attach the listener to the parent object
|
||||
_add_remove(sel, event, function(e){
|
||||
|
||||
var elem, t;
|
||||
|
||||
// Get the live version of the target selector
|
||||
t = $_.$(target, sel);
|
||||
|
||||
// Check each element to see if it matches the target
|
||||
for(elem in t)
|
||||
{
|
||||
// Fire target callback when event bubbles from target
|
||||
if(e.target == t[elem])
|
||||
{
|
||||
// Trigger the event callback
|
||||
callback.call(t[elem], e);
|
||||
|
||||
// Stop event propegation
|
||||
e.stopPropagation();
|
||||
}
|
||||
}
|
||||
|
||||
}, true);
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Event Listener module
|
||||
*
|
||||
* @namespace
|
||||
* @name event
|
||||
* @memberOf $_
|
||||
*/
|
||||
e = {
|
||||
/**
|
||||
* Create a custom event
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name create
|
||||
* @function
|
||||
* @example var event = $_("#selector").event.create('foo', {});
|
||||
* @param {string} name
|
||||
* @param {object} [data]
|
||||
* @return {Object}
|
||||
*/
|
||||
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;
|
||||
},
|
||||
/**
|
||||
* Adds an event that returns a callback when triggered on the selected
|
||||
* event and selector
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name add
|
||||
* @function
|
||||
* @example $_("#selector").event.add("click", do_something());
|
||||
* @param {string} event
|
||||
* @param {function} callback
|
||||
*/
|
||||
add: function (event, callback)
|
||||
{
|
||||
$_.each(function(e){
|
||||
_add_remove(e, event, callback, true);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Removes an event bound the the specified selector, event type, and callback
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name remove
|
||||
* @function
|
||||
* @example $_("#selector").event.remove("click", do_something());
|
||||
* @param {string} event
|
||||
* @param {string} callback
|
||||
*/
|
||||
remove: function (event, callback)
|
||||
{
|
||||
$_.each(function(e){
|
||||
_add_remove(e, event, callback, false);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Binds a persistent event to the document
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name live
|
||||
* @function
|
||||
* @example $_.event.live(".button", "click", do_something());
|
||||
* @param {string} target
|
||||
* @param {string} event
|
||||
* @param {function} callback
|
||||
*/
|
||||
live: function (target, event, callback)
|
||||
{
|
||||
_attach_delegate(document.documentElement, target, event, callback);
|
||||
},
|
||||
/**
|
||||
* Binds an event to a parent object
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name delegate
|
||||
* @function
|
||||
* @example $_("#parent").delegate(".button", "click", do_something());
|
||||
* @param {string} target
|
||||
* @param {string} event
|
||||
* @param {function} callback
|
||||
*/
|
||||
delegate: function (target, event, callback)
|
||||
{
|
||||
$_.each(function(e){
|
||||
_attach_delegate(e, target, event, callback);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Trigger an event to fire
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name trigger
|
||||
* @function
|
||||
* @example $_("#my_id").trigger('click');
|
||||
* @param {object} event
|
||||
* @return {boolean}
|
||||
*/
|
||||
trigger: function(event)
|
||||
{
|
||||
return this.el.dispatchEvent(event);
|
||||
}
|
||||
};
|
||||
|
||||
$_.ext('event', e);
|
||||
|
||||
}());</code></pre>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
</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>
|
||||
</nav>
|
||||
|
||||
<br clear="both">
|
||||
|
||||
<footer>
|
||||
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>
|
||||
<script src="scripts/linenumber.js"> </script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,189 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>JSDoc: Global</title>
|
||||
|
||||
<script src="scripts/prettify/prettify.js"> </script>
|
||||
<script src="scripts/prettify/lang-css.js"> </script>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
||||
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="main">
|
||||
|
||||
<h1 class="page-title">Global</h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section>
|
||||
|
||||
<header>
|
||||
<h2>
|
||||
|
||||
</h2>
|
||||
|
||||
</header>
|
||||
|
||||
<article>
|
||||
<div class="container-overview">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="details">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3 class="subsection-title">Members</h3>
|
||||
|
||||
<dl>
|
||||
|
||||
<dt>
|
||||
<h4 class="name" id="el"><span class="type-signature"></span>el<span class="type-signature"> :Object</span></h4>
|
||||
|
||||
|
||||
</dt>
|
||||
<dd>
|
||||
|
||||
<div class="description">
|
||||
$_
|
||||
|
||||
Constructor function
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<h5>Type:</h5>
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
<span class="param-type">Object</span>
|
||||
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
<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#line14">line 14</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<nav>
|
||||
<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-alpha9</a> on Tue Sep 16 2014 15:49:39 GMT-0400 (EDT)
|
||||
</footer>
|
||||
|
||||
<script> prettyPrint(); </script>
|
||||
<script src="scripts/linenumber.js"> </script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,100 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>JSDoc: Index</title>
|
||||
|
||||
<script src="scripts/prettify/prettify.js"> </script>
|
||||
<script src="scripts/prettify/lang-css.js"> </script>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
||||
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="main">
|
||||
|
||||
<h1 class="page-title">Index</h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3> </h3>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<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 "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).</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> $_(".foo").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("name", functionOrObject);</p>
|
||||
<p> Example:</p>
|
||||
<pre class="prettyprint source"><code> $_.ext("zip", 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>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</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>
|
||||
</nav>
|
||||
|
||||
<br clear="both">
|
||||
|
||||
<footer>
|
||||
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>
|
||||
<script src="scripts/linenumber.js"> </script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,53 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>JSDoc: Source: polyfill.js</title>
|
||||
|
||||
<script src="scripts/prettify/prettify.js"> </script>
|
||||
<script src="scripts/prettify/lang-css.js"> </script>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
||||
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="main">
|
||||
|
||||
<h1 class="page-title">Source: polyfill.js</h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section>
|
||||
<article>
|
||||
<pre class="prettyprint source linenums"><code>/**
|
||||
* A module of various browser polyfills
|
||||
* @file polyfill.js
|
||||
*/</code></pre>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
</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>
|
||||
</nav>
|
||||
|
||||
<br clear="both">
|
||||
|
||||
<footer>
|
||||
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>
|
||||
<script src="scripts/linenumber.js"> </script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,162 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>JSDoc: Source: modules/promise.js</title>
|
||||
|
||||
<script src="scripts/prettify/prettify.js"> </script>
|
||||
<script src="scripts/prettify/lang-css.js"> </script>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
||||
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="main">
|
||||
|
||||
<h1 class="page-title">Source: modules/promise.js</h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section>
|
||||
<article>
|
||||
<pre class="prettyprint source linenums"><code>/**
|
||||
* Module for polyfilling promises
|
||||
*/
|
||||
(function(w, undefined) {
|
||||
|
||||
if (typeof Promise === "undefined")
|
||||
{
|
||||
/**
|
||||
* Promise constructor
|
||||
*
|
||||
* @constructor
|
||||
* @namespace
|
||||
* @param function fn
|
||||
*/
|
||||
w.Promise = function(fn)
|
||||
{
|
||||
var state = 'pending';
|
||||
var value;
|
||||
var deferred = null;
|
||||
|
||||
function resolve(newValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (newValue && typeof newValue.then === 'function')
|
||||
{
|
||||
newValue.then(resolve);
|
||||
return;
|
||||
}
|
||||
|
||||
state = 'resolved';
|
||||
value = newValue;
|
||||
|
||||
if (deferred)
|
||||
{
|
||||
handle(deferred);
|
||||
}
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
reject(e);
|
||||
}
|
||||
}
|
||||
|
||||
function reject(reason)
|
||||
{
|
||||
state = 'rejected';
|
||||
value = reason;
|
||||
|
||||
if (deferred)
|
||||
{
|
||||
handle(deferred);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function handle(handler)
|
||||
{
|
||||
if (state === 'pending')
|
||||
{
|
||||
deferred = onResolved;
|
||||
return;
|
||||
}
|
||||
|
||||
var handlerCallback;
|
||||
|
||||
setTimeout(function() {
|
||||
handlerCallback = (state === 'resolved')
|
||||
? handler.onResolved
|
||||
: handler.onRejected;
|
||||
|
||||
|
||||
if ( ! handlerCallback)
|
||||
{
|
||||
|
||||
(state === 'resolved')
|
||||
? handler.resolve(value)
|
||||
: handler.reject(value);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ret = handlerCallback(value);
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
handler.reject(e);
|
||||
return;
|
||||
}
|
||||
|
||||
handler.resolve(ret);
|
||||
}, 1);
|
||||
}
|
||||
|
||||
this.then = function(onResolved, onRejected) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
handle({
|
||||
onResolved: onResolved,
|
||||
onRejected: onRejected,
|
||||
resolve: resolve,
|
||||
reject: reject
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
fn(resolve, reject);
|
||||
}
|
||||
}
|
||||
|
||||
})(window);
|
||||
</code></pre>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
</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><li><a href="w.Promise.html">Promise</a></li></ul><h3>Global</h3><ul><li><a href="global.html#data[undefined]">data[undefined]</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 Fri Sep 05 2014 11:37:54 GMT-0400 (EDT)
|
||||
</footer>
|
||||
|
||||
<script> prettyPrint(); </script>
|
||||
<script src="scripts/linenumber.js"> </script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,25 @@
|
|||
/*global document */
|
||||
(function() {
|
||||
var source = document.getElementsByClassName('prettyprint source linenums');
|
||||
var i = 0;
|
||||
var lineNumber = 0;
|
||||
var lineId;
|
||||
var lines;
|
||||
var totalLines;
|
||||
var anchorHash;
|
||||
|
||||
if (source && source[0]) {
|
||||
anchorHash = document.location.hash.substring(1);
|
||||
lines = source[0].getElementsByTagName('li');
|
||||
totalLines = lines.length;
|
||||
|
||||
for (; i < totalLines; i++) {
|
||||
lineNumber++;
|
||||
lineId = 'line' + lineNumber;
|
||||
lines[i].id = lineId;
|
||||
if (lineId === anchorHash) {
|
||||
lines[i].className += ' selected';
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
|
@ -0,0 +1,202 @@
|
|||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1,2 @@
|
|||
PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n"]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com",
|
||||
/^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]);
|
|
@ -0,0 +1,28 @@
|
|||
var q=null;window.PR_SHOULD_USE_CONTINUATION=!0;
|
||||
(function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a=
|
||||
[],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c<i;++c){var j=f[c];if(/\\[bdsw]/i.test(j))a.push(j);else{var j=m(j),d;c+2<i&&"-"===f[c+1]?(d=m(f[c+2]),c+=2):d=j;b.push([j,d]);d<65||j>122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;c<b.length;++c)i=b[c],i[0]<=j[1]+1?j[1]=Math.max(j[1],i[1]):f.push(j=i);b=["["];o&&b.push("^");b.push.apply(b,a);for(c=0;c<
|
||||
f.length;++c)i=f[c],b.push(e(i[0])),i[1]>i[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c<b;++c){var j=f[c];j==="("?++i:"\\"===j.charAt(0)&&(j=+j.substring(1))&&j<=i&&(d[j]=-1)}for(c=1;c<d.length;++c)-1===d[c]&&(d[c]=++t);for(i=c=0;c<b;++c)j=f[c],j==="("?(++i,d[i]===void 0&&(f[c]="(?:")):"\\"===j.charAt(0)&&
|
||||
(j=+j.substring(1))&&j<=i&&(f[c]="\\"+d[i]);for(i=c=0;c<b;++c)"^"===f[c]&&"^"!==f[c+1]&&(f[c]="");if(a.ignoreCase&&s)for(c=0;c<b;++c)j=f[c],a=j.charAt(0),j.length>=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p<d;++p){var g=a[p];if(g.ignoreCase)l=!0;else if(/[a-z]/i.test(g.source.replace(/\\u[\da-f]{4}|\\x[\da-f]{2}|\\[^UXux]/gi,""))){s=!0;l=!1;break}}for(var r=
|
||||
{b:8,t:9,n:10,v:11,f:12,r:13},n=[],p=0,d=a.length;p<d;++p){g=a[p];if(g.global||g.multiline)throw Error(""+g);n.push("(?:"+y(g)+")")}return RegExp(n.join("|"),l?"gi":"g")}function M(a){function m(a){switch(a.nodeType){case 1:if(e.test(a.className))break;for(var g=a.firstChild;g;g=g.nextSibling)m(g);g=a.nodeName;if("BR"===g||"LI"===g)h[s]="\n",t[s<<1]=y++,t[s++<<1|1]=a;break;case 3:case 4:g=a.nodeValue,g.length&&(g=p?g.replace(/\r\n?/g,"\n"):g.replace(/[\t\n\r ]+/g," "),h[s]=g,t[s<<1]=y,y+=g.length,
|
||||
t[s++<<1|1]=a)}}var e=/(?:^|\s)nocode(?:\s|$)/,h=[],y=0,t=[],s=0,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=document.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);m(a);return{a:h.join("").replace(/\n$/,""),c:t}}function B(a,m,e,h){m&&(a={a:m,d:a},e(a),h.push.apply(h,a.e))}function x(a,m){function e(a){for(var l=a.d,p=[l,"pln"],d=0,g=a.a.match(y)||[],r={},n=0,z=g.length;n<z;++n){var f=g[n],b=r[f],o=void 0,c;if(typeof b===
|
||||
"string")c=!1;else{var i=h[f.charAt(0)];if(i)o=f.match(i[1]),b=i[0];else{for(c=0;c<t;++c)if(i=m[c],o=f.match(i[1])){b=i[0];break}o||(b="pln")}if((c=b.length>=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m),
|
||||
l=[],p={},d=0,g=e.length;d<g;++d){var r=e[d],n=r[3];if(n)for(var k=n.length;--k>=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/,
|
||||
q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/,
|
||||
q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g,
|
||||
"");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a),
|
||||
a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e}
|
||||
for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g<d.length;++g)e(d[g]);m===(m|0)&&d[0].setAttribute("value",
|
||||
m);var r=s.createElement("OL");r.className="linenums";for(var n=Math.max(0,m-1|0)||0,g=0,z=d.length;g<z;++g)l=d[g],l.className="L"+(g+n)%10,l.firstChild||l.appendChild(s.createTextNode("\xa0")),r.appendChild(l);a.appendChild(r)}function k(a,m){for(var e=m.length;--e>=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*</.test(m)?"default-markup":"default-code";return A[a]}function E(a){var m=
|
||||
a.g;try{var e=M(a.h),h=e.a;a.a=h;a.c=e.c;a.d=0;C(m,h)(a);var k=/\bMSIE\b/.test(navigator.userAgent),m=/\n/g,t=a.a,s=t.length,e=0,l=a.c,p=l.length,h=0,d=a.e,g=d.length,a=0;d[g]=s;var r,n;for(n=r=0;n<g;)d[n]!==d[n+2]?(d[r++]=d[n++],d[r++]=d[n++]):n+=2;g=r;for(n=r=0;n<g;){for(var z=d[n],f=d[n+1],b=n+2;b+2<=g&&d[b+1]===f;)b+=2;d[r++]=z;d[r++]=f;n=b}for(d.length=r;h<p;){var o=l[h+2]||s,c=d[a+2]||s,b=Math.min(o,c),i=l[h+1],j;if(i.nodeType!==1&&(j=t.substring(e,b))){k&&(j=j.replace(m,"\r"));i.nodeValue=
|
||||
j;var u=i.ownerDocument,v=u.createElement("SPAN");v.className=d[a+1];var x=i.parentNode;x.replaceChild(v,i);v.appendChild(i);e<o&&(l[h+1]=i=u.createTextNode(t.substring(b,o)),x.insertBefore(i,v.nextSibling))}e=b;e>=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"],
|
||||
"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"],
|
||||
H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"],
|
||||
J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+
|
||||
I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^<?]+/],["dec",/^<!\w[^>]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^<xmp\b[^>]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^<script\b[^>]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^<style\b[^>]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),
|
||||
["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css",
|
||||
/^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}),
|
||||
["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes",
|
||||
hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p<h.length&&l.now()<e;p++){var n=h[p],k=n.className;if(k.indexOf("prettyprint")>=0){var k=k.match(g),f,b;if(b=
|
||||
!k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p<h.length?setTimeout(m,
|
||||
250):a&&a()}for(var e=[document.getElementsByTagName("pre"),document.getElementsByTagName("code"),document.getElementsByTagName("xmp")],h=[],k=0;k<e.length;++k)for(var t=0,s=e[k].length;t<s;++t)h.push(e[k][t]);var e=q,l=Date;l.now||(l={now:function(){return+new Date}});var p=0,d,g=/\blang(?:uage)?-([\w.]+)(?!\S)/;m()};window.PR={createSimpleLexer:x,registerLangHandler:k,sourceDecorator:u,PR_ATTRIB_NAME:"atn",PR_ATTRIB_VALUE:"atv",PR_COMMENT:"com",PR_DECLARATION:"dec",PR_KEYWORD:"kwd",PR_LITERAL:"lit",
|
||||
PR_NOCODE:"nocode",PR_PLAIN:"pln",PR_PUNCTUATION:"pun",PR_SOURCE:"src",PR_STRING:"str",PR_TAG:"tag",PR_TYPE:"typ"}})();
|
|
@ -0,0 +1,166 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>JSDoc: Source: modules/store.js</title>
|
||||
|
||||
<script src="scripts/prettify/prettify.js"> </script>
|
||||
<script src="scripts/prettify/lang-css.js"> </script>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
||||
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="main">
|
||||
|
||||
<h1 class="page-title">Source: modules/store.js</h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section>
|
||||
<article>
|
||||
<pre class="prettyprint source linenums"><code>/**
|
||||
* Store
|
||||
*
|
||||
* Wrapper for local / sessionstorage
|
||||
*/
|
||||
(function (undefined){
|
||||
|
||||
"use strict";
|
||||
|
||||
//Shortcuts for wrapper
|
||||
var l = localStorage,
|
||||
s = sessionStorage;
|
||||
|
||||
/**
|
||||
* Wrapper for localstorage / sessionstorage data serialization.
|
||||
* Each method has a boolean parameter, that when set as true switches the method
|
||||
* to use sessionStorage rather than the default localStorage.
|
||||
*
|
||||
* @name store
|
||||
* @namespace
|
||||
* @memberOf $_
|
||||
*/
|
||||
var store = {
|
||||
/**
|
||||
* Retrieves and deserializes a value from localstorage,
|
||||
* based on the specified key
|
||||
*
|
||||
* @param {string} key
|
||||
* @param {bool} session
|
||||
* @name get
|
||||
* @memberOf $_.store
|
||||
* @function
|
||||
* @return {Object}
|
||||
*/
|
||||
get: function (key, sess)
|
||||
{
|
||||
var val = (sess) ? s.getItem(key) : l.getItem(key);
|
||||
|
||||
return JSON.parse(val);
|
||||
},
|
||||
/**
|
||||
* Puts a value into localstorage at the specified key,
|
||||
* and JSON-encodes the value if not a string
|
||||
*
|
||||
* @param {string} key
|
||||
* @param {mixed} value
|
||||
* @param {bool} session
|
||||
* @name set
|
||||
* @memberOf $_.store
|
||||
* @function
|
||||
*/
|
||||
set: function (key, value, sess)
|
||||
{
|
||||
// Localstorage generally only accepts strings
|
||||
value = JSON.stringify(value);
|
||||
|
||||
(sess) ? s.setItem(key, value) : l.setItem(key, value);
|
||||
},
|
||||
/**
|
||||
* Removes the specified item from storage
|
||||
*
|
||||
* @param {string} key
|
||||
* @param {bool} session
|
||||
* @name remove
|
||||
* @memberOf $_.store
|
||||
* @function
|
||||
*/
|
||||
remove: function (key, sess)
|
||||
{
|
||||
(sess) ? s.removeItem(key) : l.removeItem(key);
|
||||
},
|
||||
/**
|
||||
* Returns an object of all the raw values in storage
|
||||
*
|
||||
* @param {bool} session
|
||||
* @name getAll
|
||||
* @memberOf $_.store
|
||||
* @function
|
||||
* @return {Object}
|
||||
*/
|
||||
getAll: function (sess)
|
||||
{
|
||||
var i,
|
||||
len,
|
||||
data = {},
|
||||
k,
|
||||
o;
|
||||
|
||||
//Reference to session/localstorage
|
||||
o = (sess) ? l : s;
|
||||
|
||||
len = o.length;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
k = o.key(i);
|
||||
data[k] = o.getItem(k);
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
/**
|
||||
* Removes all values from the same domain storage
|
||||
*
|
||||
* @param {bool} session
|
||||
* @name clear
|
||||
* @memberOf $_.store
|
||||
* @function
|
||||
*/
|
||||
clear: function(sess)
|
||||
{
|
||||
(sess) ? s.clear() : l.clear();
|
||||
}
|
||||
};
|
||||
|
||||
$_.ext('store', store);
|
||||
}());</code></pre>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
</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>
|
||||
</nav>
|
||||
|
||||
<br clear="both">
|
||||
|
||||
<footer>
|
||||
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>
|
||||
<script src="scripts/linenumber.js"> </script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,333 @@
|
|||
html
|
||||
{
|
||||
overflow: auto;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
body
|
||||
{
|
||||
font: 14px "DejaVu Sans Condensed", "Liberation Sans", "Nimbus Sans L", Tahoma, Geneva, "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||
line-height: 130%;
|
||||
color: #000;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #444;
|
||||
}
|
||||
|
||||
a:visited {
|
||||
color: #444;
|
||||
}
|
||||
|
||||
a:active {
|
||||
color: #444;
|
||||
}
|
||||
|
||||
header
|
||||
{
|
||||
display: block;
|
||||
padding: 6px 4px;
|
||||
}
|
||||
|
||||
.class-description {
|
||||
font-style: italic;
|
||||
font-family: Palatino, 'Palatino Linotype', serif;
|
||||
font-size: 130%;
|
||||
line-height: 140%;
|
||||
margin-bottom: 1em;
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
||||
#main {
|
||||
float: left;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
section
|
||||
{
|
||||
display: block;
|
||||
|
||||
background-color: #fff;
|
||||
padding: 12px 24px;
|
||||
border-bottom: 1px solid #ccc;
|
||||
margin-right: 240px;
|
||||
}
|
||||
|
||||
.variation {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.signature-attributes {
|
||||
font-size: 60%;
|
||||
color: #aaa;
|
||||
font-style: italic;
|
||||
font-weight: lighter;
|
||||
}
|
||||
|
||||
nav
|
||||
{
|
||||
display: block;
|
||||
float: left;
|
||||
margin-left: -230px;
|
||||
margin-top: 28px;
|
||||
width: 220px;
|
||||
border-left: 1px solid #ccc;
|
||||
padding-left: 9px;
|
||||
}
|
||||
|
||||
nav ul {
|
||||
font-family: 'Lucida Grande', 'Lucida Sans Unicode', arial, sans-serif;
|
||||
font-size: 100%;
|
||||
line-height: 17px;
|
||||
padding:0;
|
||||
margin:0;
|
||||
list-style-type:none;
|
||||
}
|
||||
|
||||
nav h2 a, nav h2 a:visited {
|
||||
color: #A35A00;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
nav h3 {
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
nav li {
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
nav a {
|
||||
color: #5C5954;
|
||||
}
|
||||
|
||||
nav a:visited {
|
||||
color: #5C5954;
|
||||
}
|
||||
|
||||
nav a:active {
|
||||
color: #5C5954;
|
||||
}
|
||||
|
||||
footer {
|
||||
display: block;
|
||||
padding: 6px;
|
||||
margin-top: 12px;
|
||||
font-style: italic;
|
||||
font-size: 90%;
|
||||
}
|
||||
|
||||
h1
|
||||
{
|
||||
font-size: 200%;
|
||||
font-weight: bold;
|
||||
letter-spacing: -0.01em;
|
||||
margin: 6px 0 9px 0;
|
||||
}
|
||||
|
||||
h2
|
||||
{
|
||||
font-size: 170%;
|
||||
font-weight: bold;
|
||||
letter-spacing: -0.01em;
|
||||
margin: 6px 0 3px 0;
|
||||
}
|
||||
|
||||
h3
|
||||
{
|
||||
font-size: 150%;
|
||||
font-weight: bold;
|
||||
letter-spacing: -0.01em;
|
||||
margin-top: 16px;
|
||||
margin: 6px 0 3px 0;
|
||||
}
|
||||
|
||||
h4
|
||||
{
|
||||
font-size: 130%;
|
||||
font-weight: bold;
|
||||
letter-spacing: -0.01em;
|
||||
margin-top: 16px;
|
||||
margin: 18px 0 3px 0;
|
||||
color: #A35A00;
|
||||
}
|
||||
|
||||
h5, .container-overview .subsection-title
|
||||
{
|
||||
font-size: 120%;
|
||||
font-weight: bold;
|
||||
letter-spacing: -0.01em;
|
||||
margin: 8px 0 3px -16px;
|
||||
}
|
||||
|
||||
h6
|
||||
{
|
||||
font-size: 100%;
|
||||
letter-spacing: -0.01em;
|
||||
margin: 6px 0 3px 0;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.ancestors { color: #999; }
|
||||
.ancestors a
|
||||
{
|
||||
color: #999 !important;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.important
|
||||
{
|
||||
font-weight: bold;
|
||||
color: #950B02;
|
||||
}
|
||||
|
||||
.yes-def {
|
||||
text-indent: -1000px;
|
||||
}
|
||||
|
||||
.type-signature {
|
||||
color: #aaa;
|
||||
}
|
||||
|
||||
.name, .signature {
|
||||
font-family: Consolas, "Lucida Console", Monaco, monospace;
|
||||
}
|
||||
|
||||
.details { margin-top: 14px; border-left: 2px solid #DDD; }
|
||||
.details dt { width:100px; float:left; padding-left: 10px; padding-top: 6px; }
|
||||
.details dd { margin-left: 50px; }
|
||||
.details ul { margin: 0; }
|
||||
.details ul { list-style-type: none; }
|
||||
.details li { margin-left: 30px; padding-top: 6px; }
|
||||
.details pre.prettyprint { margin: 0 }
|
||||
.details .object-value { padding-top: 0; }
|
||||
|
||||
.description {
|
||||
margin-bottom: 1em;
|
||||
margin-left: -16px;
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
||||
.code-caption
|
||||
{
|
||||
font-style: italic;
|
||||
font-family: Palatino, 'Palatino Linotype', serif;
|
||||
font-size: 107%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.prettyprint
|
||||
{
|
||||
border: 1px solid #ddd;
|
||||
width: 80%;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.prettyprint.source {
|
||||
width: inherit;
|
||||
}
|
||||
|
||||
.prettyprint code
|
||||
{
|
||||
font-family: Consolas, 'Lucida Console', Monaco, monospace;
|
||||
font-size: 100%;
|
||||
line-height: 18px;
|
||||
display: block;
|
||||
padding: 4px 12px;
|
||||
margin: 0;
|
||||
background-color: #fff;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.prettyprint code span.line
|
||||
{
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.prettyprint.linenums
|
||||
{
|
||||
padding-left: 70px;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.prettyprint.linenums ol
|
||||
{
|
||||
padding-left: 0;
|
||||
}
|
||||
|
||||
.prettyprint.linenums li
|
||||
{
|
||||
border-left: 3px #ddd solid;
|
||||
}
|
||||
|
||||
.prettyprint.linenums li.selected,
|
||||
.prettyprint.linenums li.selected *
|
||||
{
|
||||
background-color: lightyellow;
|
||||
}
|
||||
|
||||
.prettyprint.linenums li *
|
||||
{
|
||||
-webkit-user-select: text;
|
||||
-moz-user-select: text;
|
||||
-ms-user-select: text;
|
||||
user-select: text;
|
||||
}
|
||||
|
||||
.params, .props
|
||||
{
|
||||
border-spacing: 0;
|
||||
border: 0;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.params .name, .props .name, .name code {
|
||||
color: #A35A00;
|
||||
font-family: Consolas, 'Lucida Console', Monaco, monospace;
|
||||
font-size: 100%;
|
||||
}
|
||||
|
||||
.params td, .params th, .props td, .props th
|
||||
{
|
||||
border: 1px solid #ddd;
|
||||
margin: 0px;
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
padding: 4px 6px;
|
||||
display: table-cell;
|
||||
}
|
||||
|
||||
.params thead tr, .props thead tr
|
||||
{
|
||||
background-color: #ddd;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.params .params thead tr, .props .props thead tr
|
||||
{
|
||||
background-color: #fff;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.params th, .props th { border-right: 1px solid #aaa; }
|
||||
.params thead .last, .props thead .last { border-right: 1px solid #ddd; }
|
||||
|
||||
.params td.description > p:first-child
|
||||
{
|
||||
margin-top: 0;
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
.params td.description > p:last-child
|
||||
{
|
||||
margin-bottom: 0;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
.disabled {
|
||||
color: #454545;
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
/* JSDoc prettify.js theme */
|
||||
|
||||
/* plain text */
|
||||
.pln {
|
||||
color: #000000;
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* string content */
|
||||
.str {
|
||||
color: #006400;
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* a keyword */
|
||||
.kwd {
|
||||
color: #000000;
|
||||
font-weight: bold;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* a comment */
|
||||
.com {
|
||||
font-weight: normal;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
/* a type name */
|
||||
.typ {
|
||||
color: #000000;
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* a literal value */
|
||||
.lit {
|
||||
color: #006400;
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* punctuation */
|
||||
.pun {
|
||||
color: #000000;
|
||||
font-weight: bold;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* lisp open bracket */
|
||||
.opn {
|
||||
color: #000000;
|
||||
font-weight: bold;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* lisp close bracket */
|
||||
.clo {
|
||||
color: #000000;
|
||||
font-weight: bold;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* a markup tag name */
|
||||
.tag {
|
||||
color: #006400;
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* a markup attribute name */
|
||||
.atn {
|
||||
color: #006400;
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* a markup attribute value */
|
||||
.atv {
|
||||
color: #006400;
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* a declaration */
|
||||
.dec {
|
||||
color: #000000;
|
||||
font-weight: bold;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* a variable name */
|
||||
.var {
|
||||
color: #000000;
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* a function name */
|
||||
.fun {
|
||||
color: #000000;
|
||||
font-weight: bold;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* Specify class=linenums on a pre to get line numbering */
|
||||
ol.linenums {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
/* Tomorrow Theme */
|
||||
/* Original theme - https://github.com/chriskempson/tomorrow-theme */
|
||||
/* Pretty printing styles. Used with prettify.js. */
|
||||
/* SPAN elements with the classes below are added by prettyprint. */
|
||||
/* plain text */
|
||||
.pln {
|
||||
color: #4d4d4c; }
|
||||
|
||||
@media screen {
|
||||
/* string content */
|
||||
.str {
|
||||
color: #718c00; }
|
||||
|
||||
/* a keyword */
|
||||
.kwd {
|
||||
color: #8959a8; }
|
||||
|
||||
/* a comment */
|
||||
.com {
|
||||
color: #8e908c; }
|
||||
|
||||
/* a type name */
|
||||
.typ {
|
||||
color: #4271ae; }
|
||||
|
||||
/* a literal value */
|
||||
.lit {
|
||||
color: #f5871f; }
|
||||
|
||||
/* punctuation */
|
||||
.pun {
|
||||
color: #4d4d4c; }
|
||||
|
||||
/* lisp open bracket */
|
||||
.opn {
|
||||
color: #4d4d4c; }
|
||||
|
||||
/* lisp close bracket */
|
||||
.clo {
|
||||
color: #4d4d4c; }
|
||||
|
||||
/* a markup tag name */
|
||||
.tag {
|
||||
color: #c82829; }
|
||||
|
||||
/* a markup attribute name */
|
||||
.atn {
|
||||
color: #f5871f; }
|
||||
|
||||
/* a markup attribute value */
|
||||
.atv {
|
||||
color: #3e999f; }
|
||||
|
||||
/* a declaration */
|
||||
.dec {
|
||||
color: #f5871f; }
|
||||
|
||||
/* a variable name */
|
||||
.var {
|
||||
color: #c82829; }
|
||||
|
||||
/* a function name */
|
||||
.fun {
|
||||
color: #4271ae; } }
|
||||
/* Use higher contrast and text-weight for printable form. */
|
||||
@media print, projection {
|
||||
.str {
|
||||
color: #060; }
|
||||
|
||||
.kwd {
|
||||
color: #006;
|
||||
font-weight: bold; }
|
||||
|
||||
.com {
|
||||
color: #600;
|
||||
font-style: italic; }
|
||||
|
||||
.typ {
|
||||
color: #404;
|
||||
font-weight: bold; }
|
||||
|
||||
.lit {
|
||||
color: #044; }
|
||||
|
||||
.pun, .opn, .clo {
|
||||
color: #440; }
|
||||
|
||||
.tag {
|
||||
color: #006;
|
||||
font-weight: bold; }
|
||||
|
||||
.atn {
|
||||
color: #404; }
|
||||
|
||||
.atv {
|
||||
color: #060; } }
|
||||
/* Style */
|
||||
/*
|
||||
pre.prettyprint {
|
||||
background: white;
|
||||
font-family: Menlo, Monaco, Consolas, monospace;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
border: 1px solid #ccc;
|
||||
padding: 10px; }
|
||||
*/
|
||||
|
||||
/* Specify class=linenums on a pre to get line numbering */
|
||||
ol.linenums {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0; }
|
||||
|
||||
/* IE indents via margin-left */
|
||||
li.L0,
|
||||
li.L1,
|
||||
li.L2,
|
||||
li.L3,
|
||||
li.L4,
|
||||
li.L5,
|
||||
li.L6,
|
||||
li.L7,
|
||||
li.L8,
|
||||
li.L9 {
|
||||
/* */ }
|
||||
|
||||
/* Alternate shading for lines */
|
||||
li.L1,
|
||||
li.L3,
|
||||
li.L5,
|
||||
li.L7,
|
||||
li.L9 {
|
||||
/* */ }
|
|
@ -0,0 +1,122 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>JSDoc: Namespace: Promise</title>
|
||||
|
||||
<script src="scripts/prettify/prettify.js"> </script>
|
||||
<script src="scripts/prettify/lang-css.js"> </script>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
||||
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="main">
|
||||
|
||||
<h1 class="page-title">Namespace: Promise</h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section>
|
||||
|
||||
<header>
|
||||
<h2>
|
||||
Promise
|
||||
</h2>
|
||||
|
||||
</header>
|
||||
|
||||
<article>
|
||||
<div class="container-overview">
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="description">Promise constructor</div>
|
||||
|
||||
|
||||
|
||||
<dl class="details">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="promise.js.html">modules/promise.js</a>, <a href="promise.js.html#line15">line 15</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
</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><li><a href="w.Promise.html">Promise</a></li></ul><h3>Global</h3><ul><li><a href="global.html#data[undefined]">data[undefined]</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 Fri Sep 05 2014 11:37:54 GMT-0400 (EDT)
|
||||
</footer>
|
||||
|
||||
<script> prettyPrint(); </script>
|
||||
<script src="scripts/linenumber.js"> </script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,929 @@
|
|||
/**
|
||||
Kis JS Keep It Simple JS Library
|
||||
Copyright Timothy J. Warren
|
||||
License Public Domain
|
||||
Version 0.9.0
|
||||
*/
|
||||
(function (undefined){
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Current selector object
|
||||
*
|
||||
* @memberOf $_
|
||||
* @name el
|
||||
*/
|
||||
var sel;
|
||||
|
||||
|
||||
/**
|
||||
* $_
|
||||
*
|
||||
* Constructor function
|
||||
*
|
||||
* @constructor
|
||||
* @namespace $_
|
||||
* @param {string} selector - The dom selector string
|
||||
* @param {Object} [context] - Context of the dom selector string
|
||||
* @return {Object}
|
||||
*/
|
||||
var $_ = function(s, context)
|
||||
{
|
||||
// Have documentElement be default selector, just in case
|
||||
if (s === undefined)
|
||||
{
|
||||
// Defines a "global" selector for that instance
|
||||
sel = ($_.el !== undefined)
|
||||
? $_.el
|
||||
: document.documentElement;
|
||||
}
|
||||
else
|
||||
{
|
||||
sel = $(s, context);
|
||||
}
|
||||
|
||||
// Add the selector to the prototype
|
||||
$_.prototype.el = sel;
|
||||
|
||||
// Use the $_ object as it's own prototype
|
||||
var self = Object.create($_);
|
||||
|
||||
// Give sel to each extension.
|
||||
for(var i in self)
|
||||
{
|
||||
if(typeof self[i] === "object")
|
||||
{
|
||||
self[i].el = sel;
|
||||
}
|
||||
}
|
||||
|
||||
self.el = sel;
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
/**
|
||||
* Simple DOM selector function
|
||||
*
|
||||
* @memberOf $_
|
||||
* @param {string} selector
|
||||
* @param {Object} [context]
|
||||
* @return {Object}
|
||||
*/
|
||||
var $ = function (selector, context)
|
||||
{
|
||||
var elements;
|
||||
|
||||
if (typeof selector != "string" || selector === undefined){ return selector;}
|
||||
|
||||
//Check for a context of a specific element, otherwise, just run on the document
|
||||
context = (context != null && context.nodeType === 1)
|
||||
? context
|
||||
: document;
|
||||
|
||||
//Pick the quickest method for each kind of selector
|
||||
if (selector.match(/^#([\w\-]+$)/))
|
||||
{
|
||||
return document.getElementById(selector.split('#')[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
elements = context.querySelectorAll(selector);
|
||||
}
|
||||
|
||||
//Return the single object if applicable
|
||||
return (elements.length === 1) ? elements[0] : elements;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
$_.ext = function(name, obj)
|
||||
{
|
||||
obj.el = sel;
|
||||
$_[name] = obj;
|
||||
};
|
||||
|
||||
/**
|
||||
* Iterates over a $_ object, applying a callback to each item
|
||||
*
|
||||
* @memberOf $_
|
||||
* @function each
|
||||
* @example $_('form input').each(function(item) { alert(item) });
|
||||
* @param {function} callback - iteration callback
|
||||
*/
|
||||
$_.ext('each', function(callback)
|
||||
{
|
||||
if(sel.length !== undefined && sel !== window)
|
||||
{
|
||||
[].forEach.call(sel, callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
callback.call(sel, sel);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Retrieves the type of the passed variable
|
||||
*
|
||||
* @memberOf $_
|
||||
* @function type
|
||||
* @example $_.type([]); // Returns 'array'
|
||||
* @param {*} obj
|
||||
* @return {string}
|
||||
*/
|
||||
var type = function(obj)
|
||||
{
|
||||
if((function() {return obj && (obj !== this)}).call(obj))
|
||||
{
|
||||
//fallback on 'typeof' for truthy primitive values
|
||||
return (typeof obj).toLowerCase();
|
||||
}
|
||||
|
||||
//Strip x from [object x] and return
|
||||
return ({}).toString.call(obj).match(/\s([a-z|A-Z]+)/)[1].toLowerCase();
|
||||
};
|
||||
|
||||
//Set global variables
|
||||
$_ = window.$_ = window.$_ || $_;
|
||||
$_.$ = $;
|
||||
$_.type = type;
|
||||
}());
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
|
||||
(function ($_, undefined){
|
||||
|
||||
"use strict"
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* DOM
|
||||
*
|
||||
* Dom manipulation module
|
||||
*/
|
||||
|
||||
|
||||
var d;
|
||||
|
||||
//Private function for getting/setting attributes/properties
|
||||
function _attr(sel, name, value)
|
||||
{
|
||||
var oldVal;
|
||||
|
||||
//Get the value of the attribute, if it exists
|
||||
if (sel.hasAttribute(name))
|
||||
{
|
||||
oldVal = sel.getAttribute(name);
|
||||
}
|
||||
|
||||
//Well, I guess that attribute doesn't exist
|
||||
if (oldVal === undefined && (value === undefined || value === null))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
//No value to set? Return the current value
|
||||
if (value === undefined)
|
||||
{
|
||||
return oldVal;
|
||||
}
|
||||
|
||||
//Determine what to do with the attribute
|
||||
if (value !== undefined && value !== null)
|
||||
{
|
||||
sel.setAttribute(name, value);
|
||||
}
|
||||
else if (value === null)
|
||||
{
|
||||
sel.removeAttribute(name);
|
||||
}
|
||||
|
||||
return (value !== undefined) ? value : oldVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change css property name to it's
|
||||
* javascript camel case equivalent
|
||||
*/
|
||||
function _toCamel(s)
|
||||
{
|
||||
return String(s).replace(/(\-[a-z])/g, function($1){
|
||||
return $1.toUpperCase().replace('-','');
|
||||
});
|
||||
}
|
||||
|
||||
function _css(sel, prop, val)
|
||||
{
|
||||
//Camel-case
|
||||
prop = _toCamel(prop);
|
||||
|
||||
//If you don't define a value, try returning the existing value
|
||||
if(val === undefined && sel.style[prop] !== undefined)
|
||||
{
|
||||
return sel.style[prop];
|
||||
}
|
||||
|
||||
// Let's set a value instead
|
||||
if(sel.style[prop] !== undefined)
|
||||
{
|
||||
sel.style[prop] = val;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* DOM
|
||||
*
|
||||
* Dom manipulation module
|
||||
* @namespace
|
||||
* @memberOf $_
|
||||
* @name dom
|
||||
*/
|
||||
d = {
|
||||
/**
|
||||
* Adds a class to the element(s) specified by the current
|
||||
* selector
|
||||
*
|
||||
* @name addClass
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {string} class
|
||||
*/
|
||||
addClass: function (c)
|
||||
{
|
||||
$_.each(function (e){
|
||||
e.classList.add(c);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Removes a class from the element(s) specified by the current
|
||||
* selector
|
||||
*
|
||||
* @name removeClass
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {string} class
|
||||
*/
|
||||
removeClass: function (c)
|
||||
{
|
||||
$_.each(function (e){
|
||||
e.classList.remove(c);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Hides the element(s) specified by the current selector
|
||||
*
|
||||
* @name hide
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
*/
|
||||
hide: function ()
|
||||
{
|
||||
this.css('display', 'none');
|
||||
},
|
||||
/**
|
||||
* Shows the element(s) specified by the current selector.
|
||||
* if type is specified, the element will have it's style
|
||||
* property set to "display:[your type]". If type is not
|
||||
* specified, the element is set to "display:block".
|
||||
*
|
||||
* @name show
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {string} [type]
|
||||
*/
|
||||
show: function (type)
|
||||
{
|
||||
if (type === undefined)
|
||||
{
|
||||
type = "block";
|
||||
}
|
||||
|
||||
this.css("display", type);
|
||||
},
|
||||
/**
|
||||
* Sets attributes on element(s) specified by the current
|
||||
* selector, or, if name is not specified, returns the
|
||||
* value of the attribute of the element specified by the
|
||||
* current selector.
|
||||
*
|
||||
* @name attr
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {string} name
|
||||
* @param {?string}[value]
|
||||
* @return {?string}
|
||||
*/
|
||||
attr: function (name, value)
|
||||
{
|
||||
var sel = this.el;
|
||||
|
||||
//Make sure you don't try to get a bunch of elements
|
||||
if (sel.length > 1 && value === undefined)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if (sel.length > 1 && value !== undefined) //You can set a bunch, though
|
||||
{
|
||||
$_.each(function (e){
|
||||
return _attr(e, name, value);
|
||||
});
|
||||
}
|
||||
else //Normal behavior
|
||||
{
|
||||
return _attr(sel, name, value);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Sets or retrieves the text content of the element
|
||||
* specified by the current selector. If a value is
|
||||
* passed, it will set that value on the current element,
|
||||
* otherwise it will return the value of the current element
|
||||
*
|
||||
* @name text
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {?string} [value]
|
||||
* @return {?string}
|
||||
*/
|
||||
text: function (value)
|
||||
{
|
||||
var oldValue, set, sel;
|
||||
|
||||
sel = this.el;
|
||||
|
||||
set = (value !== undefined) ? true : false;
|
||||
|
||||
oldValue = sel.textContent;
|
||||
|
||||
if(set)
|
||||
{
|
||||
sel.textContent = value;
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return oldValue;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Sets or retrieves a css property of the element
|
||||
* specified by the current selector. If a value is
|
||||
* passed, it will set that value on the current element,
|
||||
* otherwise it will return the value of the css property
|
||||
* on the current element.
|
||||
*
|
||||
* 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
|
||||
* @param {(string|Object)} property
|
||||
* @param {?string} [value]
|
||||
* @return {?string}
|
||||
*/
|
||||
css: function (prop, val)
|
||||
{
|
||||
var prop_key = null;
|
||||
|
||||
// If passed an object, recurse!
|
||||
if($_.type(prop) === 'object')
|
||||
{
|
||||
Object.keys(prop).forEach(function(prop_key) {
|
||||
$_.each(function (e){
|
||||
_css(e, prop_key, prop[prop_key]);
|
||||
});
|
||||
});
|
||||
}
|
||||
//Return the current value if a value is not set
|
||||
else if(val === undefined && $_.type(prop) !== 'object')
|
||||
{
|
||||
return _css(this.el, prop);
|
||||
}
|
||||
|
||||
$_.each(function (e){
|
||||
_css(e, prop, val);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 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
|
||||
* @name append
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {string} htm
|
||||
*/
|
||||
append: function(htm)
|
||||
{
|
||||
this.el.insertAdjacentHTML('beforeend', htm);
|
||||
},
|
||||
/**
|
||||
* 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
|
||||
* @param {string} htm
|
||||
*/
|
||||
prepend: function(htm)
|
||||
{
|
||||
this.el.insertAdjacentHTML('afterbegin', htm);
|
||||
},
|
||||
/**
|
||||
* Sets or gets the innerHTML propery of the element(s) passed
|
||||
*
|
||||
* @name html
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {?string} [htm]
|
||||
* @return {?string}
|
||||
*/
|
||||
html: function(htm)
|
||||
{
|
||||
|
||||
if(htm !== undefined)
|
||||
{
|
||||
this.el.innerHTML = htm;
|
||||
}
|
||||
|
||||
//If the parameter is undefined, just return the current value
|
||||
return this.el.innerHTML;
|
||||
}
|
||||
};
|
||||
|
||||
$_.ext('dom', d);
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Ajax
|
||||
*
|
||||
* Module for making ajax requests
|
||||
*/
|
||||
|
||||
|
||||
var ajax = {
|
||||
_do: function (url, data, success_callback, error_callback, type)
|
||||
{
|
||||
var type,
|
||||
request = new XMLHttpRequest();
|
||||
|
||||
if (success_callback === undefined)
|
||||
{
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
success_callback = function (){};
|
||||
}
|
||||
|
||||
if (type === "GET")
|
||||
{
|
||||
url += (url.match(/\?/))
|
||||
? this._serialize(data)
|
||||
: "?" + this._serialize(data);
|
||||
}
|
||||
|
||||
request.open(type, url);
|
||||
|
||||
request.onreadystatechange = function ()
|
||||
{
|
||||
if (request.readyState === 4)
|
||||
{
|
||||
if (request.status === 200)
|
||||
{
|
||||
success_callback.call(request.responseText, request.responseText);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (error_callback !== undefined)
|
||||
{
|
||||
error_callback.call(request.status, request.status);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
if (type !== "GET")
|
||||
{
|
||||
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
request.send(this._serialize(data));
|
||||
}
|
||||
else
|
||||
{
|
||||
request.send(null);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Url encoding for non-get requests
|
||||
*
|
||||
* @param data
|
||||
* @returns {string}
|
||||
* @private
|
||||
*/
|
||||
_serialize: function (data)
|
||||
{
|
||||
var name,
|
||||
value,
|
||||
pairs = [];
|
||||
|
||||
for (name in data)
|
||||
{
|
||||
if ( ! data.hasOwnProperty(name) || $_.type(data[name]) === "function")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
value = data[name].toString();
|
||||
|
||||
name = encodeURIComponent(name);
|
||||
value = encodeURIComponent(value);
|
||||
|
||||
pairs.push(name + "=" + value);
|
||||
}
|
||||
|
||||
return pairs.join("&");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends a GET type ajax request
|
||||
*
|
||||
* @function get
|
||||
* @memberOf $_
|
||||
* @param {string} url - The url to retrieve
|
||||
* @param {Object} data - get parameters to send
|
||||
* @param {function} success_callback - callback called on success
|
||||
* @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, 'GET');
|
||||
});
|
||||
|
||||
/**
|
||||
* Sends a POST type ajax request
|
||||
*
|
||||
* @function post
|
||||
* @memberOf $_
|
||||
* @param {string} url - The url to post to
|
||||
* @param {Object} data - post parameters to send
|
||||
* @param {function} success_callback - callback called on success
|
||||
* @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, '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');
|
||||
});
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Event
|
||||
*
|
||||
* Event api wrapper
|
||||
* @todo Add method for triggering events
|
||||
*/
|
||||
|
||||
|
||||
var _add_remove, e, _attach_delegate;
|
||||
|
||||
_add_remove = function (sel, event, callback, add)
|
||||
{
|
||||
var i, len;
|
||||
|
||||
// Multiple events? Run recursively!
|
||||
if ( ! event.match(/^([\w\-]+)$/))
|
||||
{
|
||||
event = event.split(" ");
|
||||
|
||||
len = event.length;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
_add_remove(sel, event[i], callback, add);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Bind the event
|
||||
(add === true)
|
||||
? sel.addEventListener(event, callback, false)
|
||||
: sel.removeEventListener(event, callback, false);
|
||||
};
|
||||
|
||||
_attach_delegate = function(sel, target, event, callback)
|
||||
{
|
||||
// attach the listener to the parent object
|
||||
_add_remove(sel, event, function(e){
|
||||
|
||||
var elem, t;
|
||||
|
||||
// Get the live version of the target selector
|
||||
t = $_.$(target, sel);
|
||||
|
||||
// Check each element to see if it matches the target
|
||||
for(elem in t)
|
||||
{
|
||||
// Fire target callback when event bubbles from target
|
||||
if(e.target == t[elem])
|
||||
{
|
||||
// Trigger the event callback
|
||||
callback.call(t[elem], e);
|
||||
|
||||
// Stop event propegation
|
||||
e.stopPropagation();
|
||||
}
|
||||
}
|
||||
|
||||
}, true);
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Event Listener module
|
||||
*
|
||||
* @namespace
|
||||
* @name event
|
||||
* @memberOf $_
|
||||
*/
|
||||
e = {
|
||||
/**
|
||||
* Create a custom event
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name create
|
||||
* @function
|
||||
* @example var event = $_("#selector").event.create('foo', {});
|
||||
* @param {string} name
|
||||
* @param {object} [data]
|
||||
* @return {Object}
|
||||
*/
|
||||
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;
|
||||
},
|
||||
/**
|
||||
* Adds an event that returns a callback when triggered on the selected
|
||||
* event and selector
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name add
|
||||
* @function
|
||||
* @example $_("#selector").event.add("click", do_something());
|
||||
* @param {string} event
|
||||
* @param {function} callback
|
||||
*/
|
||||
add: function (event, callback)
|
||||
{
|
||||
$_.each(function(e){
|
||||
_add_remove(e, event, callback, true);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Removes an event bound the the specified selector, event type, and callback
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name remove
|
||||
* @function
|
||||
* @example $_("#selector").event.remove("click", do_something());
|
||||
* @param {string} event
|
||||
* @param {string} callback
|
||||
*/
|
||||
remove: function (event, callback)
|
||||
{
|
||||
$_.each(function(e){
|
||||
_add_remove(e, event, callback, false);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Binds a persistent event to the document
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name live
|
||||
* @function
|
||||
* @example $_.event.live(".button", "click", do_something());
|
||||
* @param {string} target
|
||||
* @param {string} event
|
||||
* @param {function} callback
|
||||
*/
|
||||
live: function (target, event, callback)
|
||||
{
|
||||
_attach_delegate(document.documentElement, target, event, callback);
|
||||
},
|
||||
/**
|
||||
* Binds an event to a parent object
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name delegate
|
||||
* @function
|
||||
* @example $_("#parent").delegate(".button", "click", do_something());
|
||||
* @param {string} target
|
||||
* @param {string} event
|
||||
* @param {function} callback
|
||||
*/
|
||||
delegate: function (target, event, callback)
|
||||
{
|
||||
$_.each(function(e){
|
||||
_attach_delegate(e, target, event, callback);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Trigger an event to fire
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name trigger
|
||||
* @function
|
||||
* @example $_("#my_id").trigger('click');
|
||||
* @param {object} event
|
||||
* @return {boolean}
|
||||
*/
|
||||
trigger: function(event)
|
||||
{
|
||||
return this.el.dispatchEvent(event);
|
||||
}
|
||||
};
|
||||
|
||||
$_.ext('event', e);
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Store
|
||||
*
|
||||
* Wrapper for local / sessionstorage
|
||||
*/
|
||||
|
||||
|
||||
//Shortcuts for wrapper
|
||||
var l = localStorage,
|
||||
s = sessionStorage;
|
||||
|
||||
/**
|
||||
* Wrapper for localstorage / sessionstorage data serialization.
|
||||
* Each method has a boolean parameter, that when set as true switches the method
|
||||
* to use sessionStorage rather than the default localStorage.
|
||||
*
|
||||
* @name store
|
||||
* @namespace
|
||||
* @memberOf $_
|
||||
*/
|
||||
var store = {
|
||||
/**
|
||||
* Retrieves and deserializes a value from localstorage,
|
||||
* based on the specified key
|
||||
*
|
||||
* @param {string} key
|
||||
* @param {bool} session
|
||||
* @name get
|
||||
* @memberOf $_.store
|
||||
* @function
|
||||
* @return {Object}
|
||||
*/
|
||||
get: function (key, sess)
|
||||
{
|
||||
var val = (sess) ? s.getItem(key) : l.getItem(key);
|
||||
|
||||
return JSON.parse(val);
|
||||
},
|
||||
/**
|
||||
* Puts a value into localstorage at the specified key,
|
||||
* and JSON-encodes the value if not a string
|
||||
*
|
||||
* @param {string} key
|
||||
* @param {mixed} value
|
||||
* @param {bool} session
|
||||
* @name set
|
||||
* @memberOf $_.store
|
||||
* @function
|
||||
*/
|
||||
set: function (key, value, sess)
|
||||
{
|
||||
// Localstorage generally only accepts strings
|
||||
value = JSON.stringify(value);
|
||||
|
||||
(sess) ? s.setItem(key, value) : l.setItem(key, value);
|
||||
},
|
||||
/**
|
||||
* Removes the specified item from storage
|
||||
*
|
||||
* @param {string} key
|
||||
* @param {bool} session
|
||||
* @name remove
|
||||
* @memberOf $_.store
|
||||
* @function
|
||||
*/
|
||||
remove: function (key, sess)
|
||||
{
|
||||
(sess) ? s.removeItem(key) : l.removeItem(key);
|
||||
},
|
||||
/**
|
||||
* Returns an object of all the raw values in storage
|
||||
*
|
||||
* @param {bool} session
|
||||
* @name getAll
|
||||
* @memberOf $_.store
|
||||
* @function
|
||||
* @return {Object}
|
||||
*/
|
||||
getAll: function (sess)
|
||||
{
|
||||
var i,
|
||||
len,
|
||||
data = {},
|
||||
k,
|
||||
o;
|
||||
|
||||
//Reference to session/localstorage
|
||||
o = (sess) ? l : s;
|
||||
|
||||
len = o.length;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
k = o.key(i);
|
||||
data[k] = o.getItem(k);
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
/**
|
||||
* Removes all values from the same domain storage
|
||||
*
|
||||
* @param {bool} session
|
||||
* @name clear
|
||||
* @memberOf $_.store
|
||||
* @function
|
||||
*/
|
||||
clear: function(sess)
|
||||
{
|
||||
(sess) ? s.clear() : l.clear();
|
||||
}
|
||||
};
|
||||
|
||||
$_.ext('store', store);
|
||||
|
||||
}($_));
|
|
@ -0,0 +1,9 @@
|
|||
(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}})})();
|
|
@ -0,0 +1,809 @@
|
|||
/**
|
||||
Kis JS Keep It Simple JS Library
|
||||
Copyright Timothy J. Warren
|
||||
License Public Domain
|
||||
Version 0.9.0
|
||||
*/
|
||||
(function (undefined){
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Current selector object
|
||||
*
|
||||
* @memberOf $_
|
||||
* @name el
|
||||
*/
|
||||
var sel;
|
||||
|
||||
|
||||
/**
|
||||
* $_
|
||||
*
|
||||
* Constructor function
|
||||
*
|
||||
* @constructor
|
||||
* @namespace $_
|
||||
* @param {string} selector - The dom selector string
|
||||
* @param {Object} [context] - Context of the dom selector string
|
||||
* @return {Object}
|
||||
*/
|
||||
var $_ = function(s, context)
|
||||
{
|
||||
// Have documentElement be default selector, just in case
|
||||
if (s === undefined)
|
||||
{
|
||||
// Defines a "global" selector for that instance
|
||||
sel = ($_.el !== undefined)
|
||||
? $_.el
|
||||
: document.documentElement;
|
||||
}
|
||||
else
|
||||
{
|
||||
sel = $(s, context);
|
||||
}
|
||||
|
||||
// Add the selector to the prototype
|
||||
$_.prototype.el = sel;
|
||||
|
||||
// Use the $_ object as it's own prototype
|
||||
var self = Object.create($_);
|
||||
|
||||
// Give sel to each extension.
|
||||
for(var i in self)
|
||||
{
|
||||
if(typeof self[i] === "object")
|
||||
{
|
||||
self[i].el = sel;
|
||||
}
|
||||
}
|
||||
|
||||
self.el = sel;
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
/**
|
||||
* Simple DOM selector function
|
||||
*
|
||||
* @memberOf $_
|
||||
* @param {string} selector
|
||||
* @param {Object} [context]
|
||||
* @return {Object}
|
||||
*/
|
||||
var $ = function (selector, context)
|
||||
{
|
||||
var elements;
|
||||
|
||||
if (typeof selector != "string" || selector === undefined){ return selector;}
|
||||
|
||||
//Check for a context of a specific element, otherwise, just run on the document
|
||||
context = (context != null && context.nodeType === 1)
|
||||
? context
|
||||
: document;
|
||||
|
||||
//Pick the quickest method for each kind of selector
|
||||
if (selector.match(/^#([\w\-]+$)/))
|
||||
{
|
||||
return document.getElementById(selector.split('#')[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
elements = context.querySelectorAll(selector);
|
||||
}
|
||||
|
||||
//Return the single object if applicable
|
||||
return (elements.length === 1) ? elements[0] : elements;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
$_.ext = function(name, obj)
|
||||
{
|
||||
obj.el = sel;
|
||||
$_[name] = obj;
|
||||
};
|
||||
|
||||
/**
|
||||
* Iterates over a $_ object, applying a callback to each item
|
||||
*
|
||||
* @memberOf $_
|
||||
* @function each
|
||||
* @example $_('form input').each(function(item) { alert(item) });
|
||||
* @param {function} callback - iteration callback
|
||||
*/
|
||||
$_.ext('each', function(callback)
|
||||
{
|
||||
if(sel.length !== undefined && sel !== window)
|
||||
{
|
||||
[].forEach.call(sel, callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
callback.call(sel, sel);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Retrieves the type of the passed variable
|
||||
*
|
||||
* @memberOf $_
|
||||
* @function type
|
||||
* @example $_.type([]); // Returns 'array'
|
||||
* @param {*} obj
|
||||
* @return {string}
|
||||
*/
|
||||
var type = function(obj)
|
||||
{
|
||||
if((function() {return obj && (obj !== this)}).call(obj))
|
||||
{
|
||||
//fallback on 'typeof' for truthy primitive values
|
||||
return (typeof obj).toLowerCase();
|
||||
}
|
||||
|
||||
//Strip x from [object x] and return
|
||||
return ({}).toString.call(obj).match(/\s([a-z|A-Z]+)/)[1].toLowerCase();
|
||||
};
|
||||
|
||||
//Set global variables
|
||||
$_ = window.$_ = window.$_ || $_;
|
||||
$_.$ = $;
|
||||
$_.type = type;
|
||||
}());
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Ajax
|
||||
*
|
||||
* Module for making ajax requests
|
||||
*/
|
||||
(function (undefined){
|
||||
|
||||
"use strict";
|
||||
|
||||
var ajax = {
|
||||
_do: function (url, data, success_callback, error_callback, type)
|
||||
{
|
||||
var type,
|
||||
request = new XMLHttpRequest();
|
||||
|
||||
if (success_callback === undefined)
|
||||
{
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
success_callback = function (){};
|
||||
}
|
||||
|
||||
if (type === "GET")
|
||||
{
|
||||
url += (url.match(/\?/))
|
||||
? this._serialize(data)
|
||||
: "?" + this._serialize(data);
|
||||
}
|
||||
|
||||
request.open(type, url);
|
||||
|
||||
request.onreadystatechange = function ()
|
||||
{
|
||||
if (request.readyState === 4)
|
||||
{
|
||||
if (request.status === 200)
|
||||
{
|
||||
success_callback.call(request.responseText, request.responseText);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (error_callback !== undefined)
|
||||
{
|
||||
error_callback.call(request.status, request.status);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
if (type !== "GET")
|
||||
{
|
||||
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
request.send(this._serialize(data));
|
||||
}
|
||||
else
|
||||
{
|
||||
request.send(null);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Url encoding for non-get requests
|
||||
*
|
||||
* @param data
|
||||
* @returns {string}
|
||||
* @private
|
||||
*/
|
||||
_serialize: function (data)
|
||||
{
|
||||
var name,
|
||||
value,
|
||||
pairs = [];
|
||||
|
||||
for (name in data)
|
||||
{
|
||||
if ( ! data.hasOwnProperty(name) || $_.type(data[name]) === "function")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
value = data[name].toString();
|
||||
|
||||
name = encodeURIComponent(name);
|
||||
value = encodeURIComponent(value);
|
||||
|
||||
pairs.push(name + "=" + value);
|
||||
}
|
||||
|
||||
return pairs.join("&");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends a GET type ajax request
|
||||
*
|
||||
* @function get
|
||||
* @memberOf $_
|
||||
* @param {string} url - The url to retrieve
|
||||
* @param {Object} data - get parameters to send
|
||||
* @param {function} success_callback - callback called on success
|
||||
* @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, 'GET');
|
||||
});
|
||||
|
||||
/**
|
||||
* Sends a POST type ajax request
|
||||
*
|
||||
* @function post
|
||||
* @memberOf $_
|
||||
* @param {string} url - The url to post to
|
||||
* @param {Object} data - post parameters to send
|
||||
* @param {function} success_callback - callback called on success
|
||||
* @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, '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');
|
||||
});
|
||||
}());
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Event
|
||||
*
|
||||
* Event api wrapper
|
||||
* @todo Add method for triggering events
|
||||
*/
|
||||
(function (undefined){
|
||||
|
||||
"use strict";
|
||||
|
||||
var _add_remove, e, _attach_delegate;
|
||||
|
||||
_add_remove = function (sel, event, callback, add)
|
||||
{
|
||||
var i, len;
|
||||
|
||||
// Multiple events? Run recursively!
|
||||
if ( ! event.match(/^([\w\-]+)$/))
|
||||
{
|
||||
event = event.split(" ");
|
||||
|
||||
len = event.length;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
_add_remove(sel, event[i], callback, add);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Bind the event
|
||||
(add === true)
|
||||
? sel.addEventListener(event, callback, false)
|
||||
: sel.removeEventListener(event, callback, false);
|
||||
};
|
||||
|
||||
_attach_delegate = function(sel, target, event, callback)
|
||||
{
|
||||
// attach the listener to the parent object
|
||||
_add_remove(sel, event, function(e){
|
||||
|
||||
var elem, t;
|
||||
|
||||
// Get the live version of the target selector
|
||||
t = $_.$(target, sel);
|
||||
|
||||
// Check each element to see if it matches the target
|
||||
for(elem in t)
|
||||
{
|
||||
// Fire target callback when event bubbles from target
|
||||
if(e.target == t[elem])
|
||||
{
|
||||
// Trigger the event callback
|
||||
callback.call(t[elem], e);
|
||||
|
||||
// Stop event propegation
|
||||
e.stopPropagation();
|
||||
}
|
||||
}
|
||||
|
||||
}, true);
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Event Listener module
|
||||
*
|
||||
* @namespace
|
||||
* @name event
|
||||
* @memberOf $_
|
||||
*/
|
||||
e = {
|
||||
/**
|
||||
* Create a custom event
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name create
|
||||
* @function
|
||||
* @example var event = $_("#selector").event.create('foo', {});
|
||||
* @param {string} name
|
||||
* @param {object} [data]
|
||||
* @return {Object}
|
||||
*/
|
||||
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;
|
||||
},
|
||||
/**
|
||||
* Adds an event that returns a callback when triggered on the selected
|
||||
* event and selector
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name add
|
||||
* @function
|
||||
* @example $_("#selector").event.add("click", do_something());
|
||||
* @param {string} event
|
||||
* @param {function} callback
|
||||
*/
|
||||
add: function (event, callback)
|
||||
{
|
||||
$_.each(function(e){
|
||||
_add_remove(e, event, callback, true);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Removes an event bound the the specified selector, event type, and callback
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name remove
|
||||
* @function
|
||||
* @example $_("#selector").event.remove("click", do_something());
|
||||
* @param {string} event
|
||||
* @param {string} callback
|
||||
*/
|
||||
remove: function (event, callback)
|
||||
{
|
||||
$_.each(function(e){
|
||||
_add_remove(e, event, callback, false);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Binds a persistent event to the document
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name live
|
||||
* @function
|
||||
* @example $_.event.live(".button", "click", do_something());
|
||||
* @param {string} target
|
||||
* @param {string} event
|
||||
* @param {function} callback
|
||||
*/
|
||||
live: function (target, event, callback)
|
||||
{
|
||||
_attach_delegate(document.documentElement, target, event, callback);
|
||||
},
|
||||
/**
|
||||
* Binds an event to a parent object
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name delegate
|
||||
* @function
|
||||
* @example $_("#parent").delegate(".button", "click", do_something());
|
||||
* @param {string} target
|
||||
* @param {string} event
|
||||
* @param {function} callback
|
||||
*/
|
||||
delegate: function (target, event, callback)
|
||||
{
|
||||
$_.each(function(e){
|
||||
_attach_delegate(e, target, event, callback);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Trigger an event to fire
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name trigger
|
||||
* @function
|
||||
* @example $_("#my_id").trigger('click');
|
||||
* @param {object} event
|
||||
* @return {boolean}
|
||||
*/
|
||||
trigger: function(event)
|
||||
{
|
||||
return this.el.dispatchEvent(event);
|
||||
}
|
||||
};
|
||||
|
||||
$_.ext('event', e);
|
||||
|
||||
}());
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* DOM
|
||||
*
|
||||
* Dom manipulation module
|
||||
*/
|
||||
(function (undefined){
|
||||
|
||||
"use strict";
|
||||
|
||||
var d;
|
||||
|
||||
//Private function for getting/setting attributes/properties
|
||||
function _attr(sel, name, value)
|
||||
{
|
||||
var oldVal;
|
||||
|
||||
//Get the value of the attribute, if it exists
|
||||
if (sel.hasAttribute(name))
|
||||
{
|
||||
oldVal = sel.getAttribute(name);
|
||||
}
|
||||
|
||||
//Well, I guess that attribute doesn't exist
|
||||
if (oldVal === undefined && (value === undefined || value === null))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
//No value to set? Return the current value
|
||||
if (value === undefined)
|
||||
{
|
||||
return oldVal;
|
||||
}
|
||||
|
||||
//Determine what to do with the attribute
|
||||
if (value !== undefined && value !== null)
|
||||
{
|
||||
sel.setAttribute(name, value);
|
||||
}
|
||||
else if (value === null)
|
||||
{
|
||||
sel.removeAttribute(name);
|
||||
}
|
||||
|
||||
return (value !== undefined) ? value : oldVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change css property name to it's
|
||||
* javascript camel case equivalent
|
||||
*/
|
||||
function _toCamel(s)
|
||||
{
|
||||
return String(s).replace(/(\-[a-z])/g, function($1){
|
||||
return $1.toUpperCase().replace('-','');
|
||||
});
|
||||
}
|
||||
|
||||
function _css(sel, prop, val)
|
||||
{
|
||||
//Camel-case
|
||||
prop = _toCamel(prop);
|
||||
|
||||
//If you don't define a value, try returning the existing value
|
||||
if(val === undefined && sel.style[prop] !== undefined)
|
||||
{
|
||||
return sel.style[prop];
|
||||
}
|
||||
|
||||
// Let's set a value instead
|
||||
if(sel.style[prop] !== undefined)
|
||||
{
|
||||
sel.style[prop] = val;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* DOM
|
||||
*
|
||||
* Dom manipulation module
|
||||
* @namespace
|
||||
* @memberOf $_
|
||||
* @name dom
|
||||
*/
|
||||
d = {
|
||||
/**
|
||||
* Adds a class to the element(s) specified by the current
|
||||
* selector
|
||||
*
|
||||
* @name addClass
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {string} class
|
||||
*/
|
||||
addClass: function (c)
|
||||
{
|
||||
$_.each(function (e){
|
||||
e.classList.add(c);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Removes a class from the element(s) specified by the current
|
||||
* selector
|
||||
*
|
||||
* @name removeClass
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {string} class
|
||||
*/
|
||||
removeClass: function (c)
|
||||
{
|
||||
$_.each(function (e){
|
||||
e.classList.remove(c);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Hides the element(s) specified by the current selector
|
||||
*
|
||||
* @name hide
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
*/
|
||||
hide: function ()
|
||||
{
|
||||
this.css('display', 'none');
|
||||
},
|
||||
/**
|
||||
* Shows the element(s) specified by the current selector.
|
||||
* if type is specified, the element will have it's style
|
||||
* property set to "display:[your type]". If type is not
|
||||
* specified, the element is set to "display:block".
|
||||
*
|
||||
* @name show
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {string} [type]
|
||||
*/
|
||||
show: function (type)
|
||||
{
|
||||
if (type === undefined)
|
||||
{
|
||||
type = "block";
|
||||
}
|
||||
|
||||
this.css("display", type);
|
||||
},
|
||||
/**
|
||||
* Sets attributes on element(s) specified by the current
|
||||
* selector, or, if name is not specified, returns the
|
||||
* value of the attribute of the element specified by the
|
||||
* current selector.
|
||||
*
|
||||
* @name attr
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {string} name
|
||||
* @param {?string}[value]
|
||||
* @return {?string}
|
||||
*/
|
||||
attr: function (name, value)
|
||||
{
|
||||
var sel = this.el;
|
||||
|
||||
//Make sure you don't try to get a bunch of elements
|
||||
if (sel.length > 1 && value === undefined)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if (sel.length > 1 && value !== undefined) //You can set a bunch, though
|
||||
{
|
||||
$_.each(function (e){
|
||||
return _attr(e, name, value);
|
||||
});
|
||||
}
|
||||
else //Normal behavior
|
||||
{
|
||||
return _attr(sel, name, value);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Sets or retrieves the text content of the element
|
||||
* specified by the current selector. If a value is
|
||||
* passed, it will set that value on the current element,
|
||||
* otherwise it will return the value of the current element
|
||||
*
|
||||
* @name text
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {?string} [value]
|
||||
* @return {?string}
|
||||
*/
|
||||
text: function (value)
|
||||
{
|
||||
var oldValue, set, sel;
|
||||
|
||||
sel = this.el;
|
||||
|
||||
set = (value !== undefined) ? true : false;
|
||||
|
||||
oldValue = sel.textContent;
|
||||
|
||||
if(set)
|
||||
{
|
||||
sel.textContent = value;
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return oldValue;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Sets or retrieves a css property of the element
|
||||
* specified by the current selector. If a value is
|
||||
* passed, it will set that value on the current element,
|
||||
* otherwise it will return the value of the css property
|
||||
* on the current element.
|
||||
*
|
||||
* 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
|
||||
* @param {(string|Object)} property
|
||||
* @param {?string} [value]
|
||||
* @return {?string}
|
||||
*/
|
||||
css: function (prop, val)
|
||||
{
|
||||
var prop_key = null;
|
||||
|
||||
// If passed an object, recurse!
|
||||
if($_.type(prop) === 'object')
|
||||
{
|
||||
Object.keys(prop).forEach(function(prop_key) {
|
||||
$_.each(function (e){
|
||||
_css(e, prop_key, prop[prop_key]);
|
||||
});
|
||||
});
|
||||
}
|
||||
//Return the current value if a value is not set
|
||||
else if(val === undefined && $_.type(prop) !== 'object')
|
||||
{
|
||||
return _css(this.el, prop);
|
||||
}
|
||||
|
||||
$_.each(function (e){
|
||||
_css(e, prop, val);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 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
|
||||
* @name append
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {string} htm
|
||||
*/
|
||||
append: function(htm)
|
||||
{
|
||||
this.el.insertAdjacentHTML('beforeend', htm);
|
||||
},
|
||||
/**
|
||||
* 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
|
||||
* @param {string} htm
|
||||
*/
|
||||
prepend: function(htm)
|
||||
{
|
||||
this.el.insertAdjacentHTML('afterbegin', htm);
|
||||
},
|
||||
/**
|
||||
* Sets or gets the innerHTML propery of the element(s) passed
|
||||
*
|
||||
* @name html
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {?string} [htm]
|
||||
* @return {?string}
|
||||
*/
|
||||
html: function(htm)
|
||||
{
|
||||
|
||||
if(htm !== undefined)
|
||||
{
|
||||
this.el.innerHTML = htm;
|
||||
}
|
||||
|
||||
//If the parameter is undefined, just return the current value
|
||||
return this.el.innerHTML;
|
||||
}
|
||||
};
|
||||
|
||||
$_.ext('dom', d);
|
||||
|
||||
}());
|
|
@ -0,0 +1,6 @@
|
|||
(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)}})})();
|
|
@ -0,0 +1,498 @@
|
|||
/**
|
||||
Kis JS Keep It Simple JS Library
|
||||
Copyright Timothy J. Warren
|
||||
License Public Domain
|
||||
Version 0.9.0
|
||||
*/
|
||||
(function (undefined){
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Current selector object
|
||||
*
|
||||
* @memberOf $_
|
||||
* @name el
|
||||
*/
|
||||
var sel;
|
||||
|
||||
|
||||
/**
|
||||
* $_
|
||||
*
|
||||
* Constructor function
|
||||
*
|
||||
* @constructor
|
||||
* @namespace $_
|
||||
* @param {string} selector - The dom selector string
|
||||
* @param {Object} [context] - Context of the dom selector string
|
||||
* @return {Object}
|
||||
*/
|
||||
var $_ = function(s, context)
|
||||
{
|
||||
// Have documentElement be default selector, just in case
|
||||
if (s === undefined)
|
||||
{
|
||||
// Defines a "global" selector for that instance
|
||||
sel = ($_.el !== undefined)
|
||||
? $_.el
|
||||
: document.documentElement;
|
||||
}
|
||||
else
|
||||
{
|
||||
sel = $(s, context);
|
||||
}
|
||||
|
||||
// Add the selector to the prototype
|
||||
$_.prototype.el = sel;
|
||||
|
||||
// Use the $_ object as it's own prototype
|
||||
var self = Object.create($_);
|
||||
|
||||
// Give sel to each extension.
|
||||
for(var i in self)
|
||||
{
|
||||
if(typeof self[i] === "object")
|
||||
{
|
||||
self[i].el = sel;
|
||||
}
|
||||
}
|
||||
|
||||
self.el = sel;
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
/**
|
||||
* Simple DOM selector function
|
||||
*
|
||||
* @memberOf $_
|
||||
* @param {string} selector
|
||||
* @param {Object} [context]
|
||||
* @return {Object}
|
||||
*/
|
||||
var $ = function (selector, context)
|
||||
{
|
||||
var elements;
|
||||
|
||||
if (typeof selector != "string" || selector === undefined){ return selector;}
|
||||
|
||||
//Check for a context of a specific element, otherwise, just run on the document
|
||||
context = (context != null && context.nodeType === 1)
|
||||
? context
|
||||
: document;
|
||||
|
||||
//Pick the quickest method for each kind of selector
|
||||
if (selector.match(/^#([\w\-]+$)/))
|
||||
{
|
||||
return document.getElementById(selector.split('#')[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
elements = context.querySelectorAll(selector);
|
||||
}
|
||||
|
||||
//Return the single object if applicable
|
||||
return (elements.length === 1) ? elements[0] : elements;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
$_.ext = function(name, obj)
|
||||
{
|
||||
obj.el = sel;
|
||||
$_[name] = obj;
|
||||
};
|
||||
|
||||
/**
|
||||
* Iterates over a $_ object, applying a callback to each item
|
||||
*
|
||||
* @memberOf $_
|
||||
* @function each
|
||||
* @example $_('form input').each(function(item) { alert(item) });
|
||||
* @param {function} callback - iteration callback
|
||||
*/
|
||||
$_.ext('each', function(callback)
|
||||
{
|
||||
if(sel.length !== undefined && sel !== window)
|
||||
{
|
||||
[].forEach.call(sel, callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
callback.call(sel, sel);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Retrieves the type of the passed variable
|
||||
*
|
||||
* @memberOf $_
|
||||
* @function type
|
||||
* @example $_.type([]); // Returns 'array'
|
||||
* @param {*} obj
|
||||
* @return {string}
|
||||
*/
|
||||
var type = function(obj)
|
||||
{
|
||||
if((function() {return obj && (obj !== this)}).call(obj))
|
||||
{
|
||||
//fallback on 'typeof' for truthy primitive values
|
||||
return (typeof obj).toLowerCase();
|
||||
}
|
||||
|
||||
//Strip x from [object x] and return
|
||||
return ({}).toString.call(obj).match(/\s([a-z|A-Z]+)/)[1].toLowerCase();
|
||||
};
|
||||
|
||||
//Set global variables
|
||||
$_ = window.$_ = window.$_ || $_;
|
||||
$_.$ = $;
|
||||
$_.type = type;
|
||||
}());
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Ajax
|
||||
*
|
||||
* Module for making ajax requests
|
||||
*/
|
||||
(function (undefined){
|
||||
|
||||
"use strict";
|
||||
|
||||
var ajax = {
|
||||
_do: function (url, data, success_callback, error_callback, type)
|
||||
{
|
||||
var type,
|
||||
request = new XMLHttpRequest();
|
||||
|
||||
if (success_callback === undefined)
|
||||
{
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
success_callback = function (){};
|
||||
}
|
||||
|
||||
if (type === "GET")
|
||||
{
|
||||
url += (url.match(/\?/))
|
||||
? this._serialize(data)
|
||||
: "?" + this._serialize(data);
|
||||
}
|
||||
|
||||
request.open(type, url);
|
||||
|
||||
request.onreadystatechange = function ()
|
||||
{
|
||||
if (request.readyState === 4)
|
||||
{
|
||||
if (request.status === 200)
|
||||
{
|
||||
success_callback.call(request.responseText, request.responseText);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (error_callback !== undefined)
|
||||
{
|
||||
error_callback.call(request.status, request.status);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
if (type !== "GET")
|
||||
{
|
||||
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
request.send(this._serialize(data));
|
||||
}
|
||||
else
|
||||
{
|
||||
request.send(null);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Url encoding for non-get requests
|
||||
*
|
||||
* @param data
|
||||
* @returns {string}
|
||||
* @private
|
||||
*/
|
||||
_serialize: function (data)
|
||||
{
|
||||
var name,
|
||||
value,
|
||||
pairs = [];
|
||||
|
||||
for (name in data)
|
||||
{
|
||||
if ( ! data.hasOwnProperty(name) || $_.type(data[name]) === "function")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
value = data[name].toString();
|
||||
|
||||
name = encodeURIComponent(name);
|
||||
value = encodeURIComponent(value);
|
||||
|
||||
pairs.push(name + "=" + value);
|
||||
}
|
||||
|
||||
return pairs.join("&");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends a GET type ajax request
|
||||
*
|
||||
* @function get
|
||||
* @memberOf $_
|
||||
* @param {string} url - The url to retrieve
|
||||
* @param {Object} data - get parameters to send
|
||||
* @param {function} success_callback - callback called on success
|
||||
* @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, 'GET');
|
||||
});
|
||||
|
||||
/**
|
||||
* Sends a POST type ajax request
|
||||
*
|
||||
* @function post
|
||||
* @memberOf $_
|
||||
* @param {string} url - The url to post to
|
||||
* @param {Object} data - post parameters to send
|
||||
* @param {function} success_callback - callback called on success
|
||||
* @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, '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');
|
||||
});
|
||||
}());
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Event
|
||||
*
|
||||
* Event api wrapper
|
||||
* @todo Add method for triggering events
|
||||
*/
|
||||
(function (undefined){
|
||||
|
||||
"use strict";
|
||||
|
||||
var _add_remove, e, _attach_delegate;
|
||||
|
||||
_add_remove = function (sel, event, callback, add)
|
||||
{
|
||||
var i, len;
|
||||
|
||||
// Multiple events? Run recursively!
|
||||
if ( ! event.match(/^([\w\-]+)$/))
|
||||
{
|
||||
event = event.split(" ");
|
||||
|
||||
len = event.length;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
_add_remove(sel, event[i], callback, add);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Bind the event
|
||||
(add === true)
|
||||
? sel.addEventListener(event, callback, false)
|
||||
: sel.removeEventListener(event, callback, false);
|
||||
};
|
||||
|
||||
_attach_delegate = function(sel, target, event, callback)
|
||||
{
|
||||
// attach the listener to the parent object
|
||||
_add_remove(sel, event, function(e){
|
||||
|
||||
var elem, t;
|
||||
|
||||
// Get the live version of the target selector
|
||||
t = $_.$(target, sel);
|
||||
|
||||
// Check each element to see if it matches the target
|
||||
for(elem in t)
|
||||
{
|
||||
// Fire target callback when event bubbles from target
|
||||
if(e.target == t[elem])
|
||||
{
|
||||
// Trigger the event callback
|
||||
callback.call(t[elem], e);
|
||||
|
||||
// Stop event propegation
|
||||
e.stopPropagation();
|
||||
}
|
||||
}
|
||||
|
||||
}, true);
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Event Listener module
|
||||
*
|
||||
* @namespace
|
||||
* @name event
|
||||
* @memberOf $_
|
||||
*/
|
||||
e = {
|
||||
/**
|
||||
* Create a custom event
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name create
|
||||
* @function
|
||||
* @example var event = $_("#selector").event.create('foo', {});
|
||||
* @param {string} name
|
||||
* @param {object} [data]
|
||||
* @return {Object}
|
||||
*/
|
||||
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;
|
||||
},
|
||||
/**
|
||||
* Adds an event that returns a callback when triggered on the selected
|
||||
* event and selector
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name add
|
||||
* @function
|
||||
* @example $_("#selector").event.add("click", do_something());
|
||||
* @param {string} event
|
||||
* @param {function} callback
|
||||
*/
|
||||
add: function (event, callback)
|
||||
{
|
||||
$_.each(function(e){
|
||||
_add_remove(e, event, callback, true);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Removes an event bound the the specified selector, event type, and callback
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name remove
|
||||
* @function
|
||||
* @example $_("#selector").event.remove("click", do_something());
|
||||
* @param {string} event
|
||||
* @param {string} callback
|
||||
*/
|
||||
remove: function (event, callback)
|
||||
{
|
||||
$_.each(function(e){
|
||||
_add_remove(e, event, callback, false);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Binds a persistent event to the document
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name live
|
||||
* @function
|
||||
* @example $_.event.live(".button", "click", do_something());
|
||||
* @param {string} target
|
||||
* @param {string} event
|
||||
* @param {function} callback
|
||||
*/
|
||||
live: function (target, event, callback)
|
||||
{
|
||||
_attach_delegate(document.documentElement, target, event, callback);
|
||||
},
|
||||
/**
|
||||
* Binds an event to a parent object
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name delegate
|
||||
* @function
|
||||
* @example $_("#parent").delegate(".button", "click", do_something());
|
||||
* @param {string} target
|
||||
* @param {string} event
|
||||
* @param {function} callback
|
||||
*/
|
||||
delegate: function (target, event, callback)
|
||||
{
|
||||
$_.each(function(e){
|
||||
_attach_delegate(e, target, event, callback);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Trigger an event to fire
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name trigger
|
||||
* @function
|
||||
* @example $_("#my_id").trigger('click');
|
||||
* @param {object} event
|
||||
* @return {boolean}
|
||||
*/
|
||||
trigger: function(event)
|
||||
{
|
||||
return this.el.dispatchEvent(event);
|
||||
}
|
||||
};
|
||||
|
||||
$_.ext('event', e);
|
||||
|
||||
}());
|
|
@ -0,0 +1,9 @@
|
|||
(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()}})})($_);
|
728
kis.js
728
kis.js
|
@ -1,728 +0,0 @@
|
|||
/**
|
||||
Kis JS Keep It Simple JS Library
|
||||
Copyright Timothy J. Warren
|
||||
License Public Domain
|
||||
Version 0.1.0
|
||||
*/
|
||||
|
||||
(function (){
|
||||
|
||||
"use strict";
|
||||
|
||||
// Property name for expandos on DOM objects
|
||||
var kis_expando = "KIS_0_1_0";
|
||||
|
||||
//Browser requirements check
|
||||
if (!document.querySelectorAll)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var $_, $;
|
||||
|
||||
$_ = {};
|
||||
|
||||
$_ = window.$_ = window.$_ || $_;
|
||||
|
||||
if(typeof window.console === "undefined")
|
||||
{
|
||||
window.console = {
|
||||
log:function(){}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* $
|
||||
*
|
||||
* Simple DOM selector function
|
||||
*/
|
||||
$ = function (a)
|
||||
{
|
||||
var x;
|
||||
if (typeof a !== "string"){ return a;}
|
||||
|
||||
//Pick the quickest method for each kind of selector
|
||||
if(a.match(/^#([\w\-]+$)/))
|
||||
{
|
||||
return document.getElementById(a.split('#')[1]);
|
||||
}
|
||||
else if(a.match(/^([\w\-]+)$/))
|
||||
{
|
||||
x = document.getElementsByTagName(a);
|
||||
}
|
||||
else
|
||||
{
|
||||
x = document.querySelectorAll(a);
|
||||
}
|
||||
|
||||
return (x.length === 1) ? x[0] : x;
|
||||
};
|
||||
|
||||
window.$ = $;
|
||||
|
||||
/**
|
||||
* Ajax
|
||||
*
|
||||
* Object for making ajax requests
|
||||
*/
|
||||
(function (){
|
||||
|
||||
var ajax = {
|
||||
_do: function (url, data, callback, isPost)
|
||||
{
|
||||
if (typeof callback === "undefined")
|
||||
{
|
||||
callback = function (){};
|
||||
}
|
||||
|
||||
var request = (typeof window.XMLHttpRequest !== "undefined")
|
||||
? new XMLHttpRequest()
|
||||
: false;
|
||||
|
||||
var type = (isPost) ? "POST" : "GET";
|
||||
|
||||
url += (type === "GET") ? "?" + this._serialize(data, true) : '';
|
||||
|
||||
request.open(type, url);
|
||||
|
||||
request.onreadystatechange = function ()
|
||||
{
|
||||
if (request.readyState === 4)
|
||||
{
|
||||
callback(request.responseText);
|
||||
}
|
||||
};
|
||||
|
||||
if (type === "POST")
|
||||
{
|
||||
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
request.send(this._serialize(data));
|
||||
}
|
||||
else
|
||||
{
|
||||
request.send(null);
|
||||
}
|
||||
},
|
||||
_serialize: function (data, encode)
|
||||
{
|
||||
var pairs = [];
|
||||
|
||||
for (var name in data)
|
||||
{
|
||||
if (!data.hasOwnProperty(name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (typeof data[name] === "function")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var value = data[name].toString();
|
||||
|
||||
if (encode === true)
|
||||
{
|
||||
name = encodeURIComponent(name.replace(" ", "+"));
|
||||
value = encodeURIComponent(value.replace(" ", "+"));
|
||||
}
|
||||
|
||||
pairs.push(name + "=" + value);
|
||||
}
|
||||
|
||||
return pairs.join("&");
|
||||
}
|
||||
};
|
||||
|
||||
$_.get = function (url, data, callback)
|
||||
{
|
||||
ajax._do(url, data, callback, false);
|
||||
};
|
||||
|
||||
$_.post = function (url, data, callback)
|
||||
{
|
||||
ajax._do(url, data, callback, true);
|
||||
};
|
||||
}());
|
||||
|
||||
/**
|
||||
* Qs
|
||||
*
|
||||
* Object for encoding and decoding querystrings and hashbang strings
|
||||
*/
|
||||
(function (){
|
||||
|
||||
$_.hb = (history.pushState) ? false : true;
|
||||
|
||||
var qs = {
|
||||
parse: function (hb)
|
||||
{
|
||||
hb = hb || $_.hb;
|
||||
|
||||
var h, i, hString, pairs, pLen, data, y;
|
||||
|
||||
data = {};
|
||||
|
||||
if (hb === true)
|
||||
{
|
||||
h = location.hash.split('#!/');
|
||||
hString = (h.length > 1) ? h[1] : '';
|
||||
}
|
||||
else if (hb === false || hb === undefined)
|
||||
{
|
||||
hString = window.location.search.substring(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
pairs = hString.split('&');
|
||||
|
||||
pLen = pairs.length;
|
||||
|
||||
for (i = 0; i < pLen; i++)
|
||||
{
|
||||
y = pairs[i].split('=');
|
||||
|
||||
if (y.length < 2)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
data[y[0]] = y[1];
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
set: function (key, value, hb)
|
||||
{
|
||||
hb = hb || $_.hb;
|
||||
var pairs = this.parse(hb);
|
||||
|
||||
if (key !== undefined && value !== undefined)
|
||||
{
|
||||
pairs[key] = value;
|
||||
}
|
||||
|
||||
var vars = [];
|
||||
|
||||
for (var x in pairs)
|
||||
{
|
||||
if (pairs.hasOwnProperty(x))
|
||||
{
|
||||
vars.push(x + '=' + pairs[x]);
|
||||
}
|
||||
}
|
||||
|
||||
var qs = vars.join('&');
|
||||
|
||||
if (hb === true)
|
||||
{
|
||||
qs = '!/' + qs;
|
||||
location.hash = qs;
|
||||
}
|
||||
|
||||
return qs;
|
||||
},
|
||||
get: function (key, hb)
|
||||
{
|
||||
hb = hb || $_.hb;
|
||||
var pairs = this.parse(hb);
|
||||
return (pairs[key]) ? pairs[key] : '';
|
||||
}
|
||||
};
|
||||
|
||||
$_.qs = qs;
|
||||
|
||||
}());
|
||||
|
||||
/**
|
||||
* Store object
|
||||
*
|
||||
* Wrapper for localstorage data serialization
|
||||
*/
|
||||
(function (){
|
||||
var store = {
|
||||
get: function (key)
|
||||
{
|
||||
return JSON.parse(localStorage.getItem(key));
|
||||
},
|
||||
set: function (key, value)
|
||||
{
|
||||
if (typeof value !== "string")
|
||||
{
|
||||
value = JSON.stringify(value);
|
||||
}
|
||||
localStorage.setItem(key, value);
|
||||
},
|
||||
getAll: function ()
|
||||
{
|
||||
var i,
|
||||
len,
|
||||
data;
|
||||
len = localStorage.length;
|
||||
data = {};
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
var name = localStorage.key(i);
|
||||
var value = localStorage.getItem(name);
|
||||
data[name] = value;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
};
|
||||
|
||||
$_.store = store;
|
||||
}());
|
||||
|
||||
/**
|
||||
* Event object
|
||||
*
|
||||
* Event api wrapper
|
||||
*/
|
||||
(function (){
|
||||
|
||||
var attach, remove, add_remove, e;
|
||||
|
||||
// Define the proper attach and remove functions
|
||||
// based on browser support
|
||||
if(typeof document.addEventListener !== "undefined")
|
||||
{
|
||||
attach = function (sel, event, callback)
|
||||
{
|
||||
if (typeof sel.addEventListener === "function")
|
||||
{
|
||||
sel.addEventListener(event, callback, false);
|
||||
}
|
||||
};
|
||||
remove = function (sel, event, callback)
|
||||
{
|
||||
if (typeof sel.removeEventListener === "function")
|
||||
{
|
||||
sel.removeEventListener(event, callback, false);
|
||||
}
|
||||
};
|
||||
}
|
||||
//typeof function doesn't work in IE where attachEvent is available: brute force it
|
||||
else if(typeof document.attachEvent !== "undefined")
|
||||
{
|
||||
attach = function (sel, event, callback)
|
||||
{
|
||||
function listener () {
|
||||
// Internet Explorer fails to correctly set the 'this' object
|
||||
// for event listeners, so we need to set it ourselves.
|
||||
callback.apply(sel, arguments);
|
||||
}
|
||||
|
||||
var i, len;
|
||||
|
||||
if (typeof sel.attachEvent !== "undefined")
|
||||
{
|
||||
remove(sel, event, callback); // Make sure we don't have duplicate listeners
|
||||
|
||||
sel.attachEvent("on" + event, listener);
|
||||
// Store our listener so we can remove it later
|
||||
var expando = sel[kis_expando] = sel[kis_expando] || {};
|
||||
expando.listeners = expando.listeners || {};
|
||||
expando.listeners[event] = expando.listeners[event] || [];
|
||||
expando.listeners[event].push({
|
||||
callback: callback,
|
||||
listener: listener
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log("Failed to attach event:"+event+" on "+sel);
|
||||
}
|
||||
};
|
||||
remove = function (sel, event, callback)
|
||||
{
|
||||
if(typeof sel.detachEvent !== "undefined")
|
||||
{
|
||||
var expando = sel[kis_expando];
|
||||
if (expando && expando.listeners
|
||||
&& expando.listeners[event])
|
||||
{
|
||||
var listeners = expando.listeners[event];
|
||||
var len = listeners.length
|
||||
for (var i=0; i<len; i++)
|
||||
{
|
||||
if (listeners[i].callback === callback)
|
||||
{
|
||||
sel.detachEvent("on" + event, listeners[i].listener);
|
||||
listeners.splice(i, 1);
|
||||
if(listeners.length === 0)
|
||||
{
|
||||
delete expando.listeners[event];
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
add_remove = function (sel, event, callback, add)
|
||||
{
|
||||
var i, len, selx;
|
||||
|
||||
if (typeof sel === "undefined")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//Get the DOM object if you give me a selector string
|
||||
sel = $(sel);
|
||||
|
||||
//Multiple events? Run recursively!
|
||||
if (!event.match(/^([\w\-]+)$/))
|
||||
{
|
||||
event = event.split(" ");
|
||||
|
||||
len = event.length;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
add_remove(sel, event[i], callback, add);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//Check for multiple DOM objects
|
||||
if (sel.length > 1)
|
||||
{
|
||||
len = sel.length;
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
selx = (sel.item(i)) ? sel.item(i) : sel[i];
|
||||
|
||||
//Call recursively
|
||||
add_remove(selx, event, callback, add);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
(add === true)
|
||||
? attach(sel, event, callback)
|
||||
: remove(sel, event, callback);
|
||||
}
|
||||
};
|
||||
|
||||
e = {
|
||||
add: function (sel, event, callback)
|
||||
{
|
||||
add_remove(sel, event, callback, true);
|
||||
},
|
||||
remove: function (sel, event, callback)
|
||||
{
|
||||
add_remove(sel, event, callback, false);
|
||||
}
|
||||
};
|
||||
|
||||
$_.event = e;
|
||||
|
||||
}());
|
||||
|
||||
/**
|
||||
* Dom manipulation object
|
||||
*
|
||||
*/
|
||||
(function (){
|
||||
var d;
|
||||
|
||||
//Private function for getting/setting attributes
|
||||
function _attr(sel, name, value)
|
||||
{
|
||||
var oldVal, doAttr, i;
|
||||
|
||||
if(sel.length > 1)
|
||||
{
|
||||
var len = sel.length;
|
||||
for(i=0;i<len;i++)
|
||||
{
|
||||
_attr(sel[i], name, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Get the value of the attribute, if it exists
|
||||
if (typeof sel.hasAttribute !== "undefined")
|
||||
{
|
||||
if (sel.hasAttribute(name))
|
||||
{
|
||||
oldVal = sel.getAttribute(name);
|
||||
}
|
||||
|
||||
doAttr = true;
|
||||
}
|
||||
else if (typeof sel[name] !== "undefined")
|
||||
{
|
||||
oldVal = sel[name];
|
||||
doAttr = false;
|
||||
}
|
||||
else if (name === "class" && typeof sel.className !== "undefined") //className attribute
|
||||
{
|
||||
name = "className";
|
||||
oldVal = sel.className;
|
||||
doAttr = false;
|
||||
}
|
||||
|
||||
//Well, I guess that attribute doesn't exist
|
||||
if (typeof oldVal === "undefined" && (typeof value === "undefined" || value === null))
|
||||
{
|
||||
console.log(value);
|
||||
console.log(sel);
|
||||
console.log("Element does not have the selected attribute");
|
||||
return;
|
||||
}
|
||||
|
||||
//No value to set? Return the current value
|
||||
if (typeof value === "undefined")
|
||||
{
|
||||
return oldVal;
|
||||
}
|
||||
|
||||
//Determine what to do with the attribute
|
||||
if (typeof value !== "undefined" && value !== null)
|
||||
{
|
||||
(doAttr === true)
|
||||
? sel.setAttribute(name, value)
|
||||
: sel[name] = value;
|
||||
}
|
||||
else if (value === null)
|
||||
{
|
||||
(doAttr === true)
|
||||
? sel.removeAttribute(name)
|
||||
: sel[name] = null;
|
||||
}
|
||||
|
||||
return (typeof value !== "undefined") ? value : oldVal;
|
||||
}
|
||||
|
||||
// Private function for class manipulation
|
||||
function _class(sel, c, add)
|
||||
{
|
||||
var ec, cs, len, i, classInd;
|
||||
|
||||
//We can do this the easy way
|
||||
if (sel.classList)
|
||||
{
|
||||
if (add === true)
|
||||
{
|
||||
sel.classList.add(c);
|
||||
return;
|
||||
}
|
||||
else if (add === false)
|
||||
{
|
||||
sel.classList.remove(c);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else //Or the hard way
|
||||
{
|
||||
//No class attribute? Set an empty string
|
||||
ec = sel.className;//_attr(sel, "class");
|
||||
ec = (typeof ec === "string") ? ec : '';
|
||||
|
||||
//Convert class attribute string into array
|
||||
if (typeof ec === "string")
|
||||
{
|
||||
cs = (ec !== '') ? ec.split(" ") : [];
|
||||
|
||||
len = cs.length;
|
||||
classInd = false;
|
||||
|
||||
//Check for the class in the array
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (cs[i] === c)
|
||||
{
|
||||
classInd = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Add or remove from class array
|
||||
if (add === true)
|
||||
{
|
||||
//Only add the class if isn't already there
|
||||
if (classInd === false)
|
||||
{
|
||||
cs.push(c);
|
||||
}
|
||||
}
|
||||
else if (add === false)
|
||||
{
|
||||
//Make sure the class you want to remove exists
|
||||
if (classInd !== false)
|
||||
{
|
||||
cs.splice(classInd, 1);
|
||||
}
|
||||
}
|
||||
|
||||
var cName = (cs.length > 1) ? cs.join(" ") : cs[0];
|
||||
|
||||
if (typeof sel.className !== "undefined")
|
||||
{
|
||||
sel.className = cName;
|
||||
}
|
||||
else if (typeof sel.setAttribute !== "undefined")
|
||||
{
|
||||
sel.setAttribute('class', cName);
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log(sel);
|
||||
}
|
||||
|
||||
return cName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
d = {
|
||||
each: function (sel, callback)
|
||||
{
|
||||
sel = $(sel);
|
||||
|
||||
if(!sel.length)
|
||||
{
|
||||
// sel is a DOM Element
|
||||
callback(sel);
|
||||
}
|
||||
else
|
||||
{
|
||||
var len = sel.length;
|
||||
|
||||
if (len === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (len === 1)
|
||||
{
|
||||
return callback(sel);
|
||||
}
|
||||
|
||||
var selx;
|
||||
for (var x = 0; x < sel.length; x++)
|
||||
{
|
||||
selx = (sel.item(x)) ? sel.item(x) : sel[x];
|
||||
callback(selx);
|
||||
}
|
||||
}
|
||||
},
|
||||
addClass: function (sel, c)
|
||||
{
|
||||
sel = $(sel);
|
||||
|
||||
this.each(sel, function (e){
|
||||
_class(e, c, true);
|
||||
});
|
||||
},
|
||||
removeClass: function (sel, c)
|
||||
{
|
||||
sel = $(sel);
|
||||
|
||||
this.each(sel, function (e){
|
||||
_class(e, c, false);
|
||||
});
|
||||
},
|
||||
hide: function (sel)
|
||||
{
|
||||
sel = $(sel);
|
||||
|
||||
if (sel.length > 1)
|
||||
{
|
||||
this.each(sel, function (e){
|
||||
e.style.display = "none";
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sel.style)
|
||||
{
|
||||
sel.style.display = "none";
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
show: function (sel, type)
|
||||
{
|
||||
sel = $(sel);
|
||||
|
||||
if (typeof type === "undefined")
|
||||
{
|
||||
type = "block";
|
||||
}
|
||||
|
||||
if (sel.length > 1)
|
||||
{
|
||||
this.each(sel, function (e){
|
||||
e.style.display = type;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
sel.style.display = type;
|
||||
}
|
||||
},
|
||||
attr: function (sel, name, value)
|
||||
{
|
||||
sel = $(sel);
|
||||
|
||||
//Make sure you don't try to get a bunch of elements
|
||||
if (sel.length > 1 && typeof value === "undefined")
|
||||
{
|
||||
console.log(sel);
|
||||
console.log("Must be a singular element");
|
||||
return;
|
||||
}
|
||||
else if (sel.length > 1 && typeof value !== "undefined") //You can set a bunch, though
|
||||
{
|
||||
this.each(sel, function (e){
|
||||
_attr(e, name, value);
|
||||
});
|
||||
}
|
||||
else //Normal behavior
|
||||
{
|
||||
return _attr(sel, name, value);
|
||||
}
|
||||
},
|
||||
text: function(sel, value)
|
||||
{
|
||||
var oldValue, set, type;
|
||||
|
||||
sel = $(sel);
|
||||
|
||||
set = (typeof value !== "undefined") ? true : false;
|
||||
|
||||
type = (typeof sel.innerText !== "undefined")
|
||||
? "innerText"
|
||||
: (typeof sel.textContent !== "undefined")
|
||||
? "textContent"
|
||||
: "innerHTML";
|
||||
|
||||
oldValue = sel[type];
|
||||
|
||||
if(set)
|
||||
{
|
||||
sel[type] = value;
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return oldValue;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$_.dom = d;
|
||||
}());
|
||||
|
||||
}());
|
|
@ -0,0 +1,159 @@
|
|||
/**
|
||||
Kis JS Keep It Simple JS Library
|
||||
Copyright Timothy J. Warren
|
||||
License Public Domain
|
||||
Version 0.9.0
|
||||
*/
|
||||
(function (undefined){
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Current selector object
|
||||
*
|
||||
* @memberOf $_
|
||||
* @name el
|
||||
*/
|
||||
var sel;
|
||||
|
||||
|
||||
/**
|
||||
* $_
|
||||
*
|
||||
* Constructor function
|
||||
*
|
||||
* @constructor
|
||||
* @namespace $_
|
||||
* @param {string} selector - The dom selector string
|
||||
* @param {Object} [context] - Context of the dom selector string
|
||||
* @return {Object}
|
||||
*/
|
||||
var $_ = function(s, context)
|
||||
{
|
||||
// Have documentElement be default selector, just in case
|
||||
if (s === undefined)
|
||||
{
|
||||
// Defines a "global" selector for that instance
|
||||
sel = ($_.el !== undefined)
|
||||
? $_.el
|
||||
: document.documentElement;
|
||||
}
|
||||
else
|
||||
{
|
||||
sel = $(s, context);
|
||||
}
|
||||
|
||||
// Add the selector to the prototype
|
||||
$_.prototype.el = sel;
|
||||
|
||||
// Use the $_ object as it's own prototype
|
||||
var self = Object.create($_);
|
||||
|
||||
// Give sel to each extension.
|
||||
for(var i in self)
|
||||
{
|
||||
if(typeof self[i] === "object")
|
||||
{
|
||||
self[i].el = sel;
|
||||
}
|
||||
}
|
||||
|
||||
self.el = sel;
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
/**
|
||||
* Simple DOM selector function
|
||||
*
|
||||
* @memberOf $_
|
||||
* @param {string} selector
|
||||
* @param {Object} [context]
|
||||
* @return {Object}
|
||||
*/
|
||||
var $ = function (selector, context)
|
||||
{
|
||||
var elements;
|
||||
|
||||
if (typeof selector != "string" || selector === undefined){ return selector;}
|
||||
|
||||
//Check for a context of a specific element, otherwise, just run on the document
|
||||
context = (context != null && context.nodeType === 1)
|
||||
? context
|
||||
: document;
|
||||
|
||||
//Pick the quickest method for each kind of selector
|
||||
if (selector.match(/^#([\w\-]+$)/))
|
||||
{
|
||||
return document.getElementById(selector.split('#')[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
elements = context.querySelectorAll(selector);
|
||||
}
|
||||
|
||||
//Return the single object if applicable
|
||||
return (elements.length === 1) ? elements[0] : elements;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
$_.ext = function(name, obj)
|
||||
{
|
||||
obj.el = sel;
|
||||
$_[name] = obj;
|
||||
};
|
||||
|
||||
/**
|
||||
* Iterates over a $_ object, applying a callback to each item
|
||||
*
|
||||
* @memberOf $_
|
||||
* @function each
|
||||
* @example $_('form input').each(function(item) { alert(item) });
|
||||
* @param {function} callback - iteration callback
|
||||
*/
|
||||
$_.ext('each', function(callback)
|
||||
{
|
||||
if(sel.length !== undefined && sel !== window)
|
||||
{
|
||||
[].forEach.call(sel, callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
callback.call(sel, sel);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Retrieves the type of the passed variable
|
||||
*
|
||||
* @memberOf $_
|
||||
* @function type
|
||||
* @example $_.type([]); // Returns 'array'
|
||||
* @param {*} obj
|
||||
* @return {string}
|
||||
*/
|
||||
var type = function(obj)
|
||||
{
|
||||
if((function() {return obj && (obj !== this)}).call(obj))
|
||||
{
|
||||
//fallback on 'typeof' for truthy primitive values
|
||||
return (typeof obj).toLowerCase();
|
||||
}
|
||||
|
||||
//Strip x from [object x] and return
|
||||
return ({}).toString.call(obj).match(/\s([a-z|A-Z]+)/)[1].toLowerCase();
|
||||
};
|
||||
|
||||
//Set global variables
|
||||
$_ = window.$_ = window.$_ || $_;
|
||||
$_.$ = $;
|
||||
$_.type = type;
|
||||
}());
|
|
@ -0,0 +1,308 @@
|
|||
/**
|
||||
* DOM
|
||||
*
|
||||
* Dom manipulation module
|
||||
*/
|
||||
(function (undefined){
|
||||
|
||||
"use strict";
|
||||
|
||||
var d;
|
||||
|
||||
//Private function for getting/setting attributes/properties
|
||||
function _attr(sel, name, value)
|
||||
{
|
||||
var oldVal;
|
||||
|
||||
//Get the value of the attribute, if it exists
|
||||
if (sel.hasAttribute(name))
|
||||
{
|
||||
oldVal = sel.getAttribute(name);
|
||||
}
|
||||
|
||||
//Well, I guess that attribute doesn't exist
|
||||
if (oldVal === undefined && (value === undefined || value === null))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
//No value to set? Return the current value
|
||||
if (value === undefined)
|
||||
{
|
||||
return oldVal;
|
||||
}
|
||||
|
||||
//Determine what to do with the attribute
|
||||
if (value !== undefined && value !== null)
|
||||
{
|
||||
sel.setAttribute(name, value);
|
||||
}
|
||||
else if (value === null)
|
||||
{
|
||||
sel.removeAttribute(name);
|
||||
}
|
||||
|
||||
return (value !== undefined) ? value : oldVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change css property name to it's
|
||||
* javascript camel case equivalent
|
||||
*/
|
||||
function _toCamel(s)
|
||||
{
|
||||
return String(s).replace(/(\-[a-z])/g, function($1){
|
||||
return $1.toUpperCase().replace('-','');
|
||||
});
|
||||
}
|
||||
|
||||
function _css(sel, prop, val)
|
||||
{
|
||||
//Camel-case
|
||||
prop = _toCamel(prop);
|
||||
|
||||
//If you don't define a value, try returning the existing value
|
||||
if(val === undefined && sel.style[prop] !== undefined)
|
||||
{
|
||||
return sel.style[prop];
|
||||
}
|
||||
|
||||
// Let's set a value instead
|
||||
if(sel.style[prop] !== undefined)
|
||||
{
|
||||
sel.style[prop] = val;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* DOM
|
||||
*
|
||||
* Dom manipulation module
|
||||
* @namespace
|
||||
* @memberOf $_
|
||||
* @name dom
|
||||
*/
|
||||
d = {
|
||||
/**
|
||||
* Adds a class to the element(s) specified by the current
|
||||
* selector
|
||||
*
|
||||
* @name addClass
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {string} class
|
||||
*/
|
||||
addClass: function (c)
|
||||
{
|
||||
$_.each(function (e){
|
||||
e.classList.add(c);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Removes a class from the element(s) specified by the current
|
||||
* selector
|
||||
*
|
||||
* @name removeClass
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {string} class
|
||||
*/
|
||||
removeClass: function (c)
|
||||
{
|
||||
$_.each(function (e){
|
||||
e.classList.remove(c);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Hides the element(s) specified by the current selector
|
||||
*
|
||||
* @name hide
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
*/
|
||||
hide: function ()
|
||||
{
|
||||
this.css('display', 'none');
|
||||
},
|
||||
/**
|
||||
* Shows the element(s) specified by the current selector.
|
||||
* if type is specified, the element will have it's style
|
||||
* property set to "display:[your type]". If type is not
|
||||
* specified, the element is set to "display:block".
|
||||
*
|
||||
* @name show
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {string} [type]
|
||||
*/
|
||||
show: function (type)
|
||||
{
|
||||
if (type === undefined)
|
||||
{
|
||||
type = "block";
|
||||
}
|
||||
|
||||
this.css("display", type);
|
||||
},
|
||||
/**
|
||||
* Sets attributes on element(s) specified by the current
|
||||
* selector, or, if name is not specified, returns the
|
||||
* value of the attribute of the element specified by the
|
||||
* current selector.
|
||||
*
|
||||
* @name attr
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {string} name
|
||||
* @param {?string}[value]
|
||||
* @return {?string}
|
||||
*/
|
||||
attr: function (name, value)
|
||||
{
|
||||
var sel = this.el;
|
||||
|
||||
//Make sure you don't try to get a bunch of elements
|
||||
if (sel.length > 1 && value === undefined)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if (sel.length > 1 && value !== undefined) //You can set a bunch, though
|
||||
{
|
||||
$_.each(function (e){
|
||||
return _attr(e, name, value);
|
||||
});
|
||||
}
|
||||
else //Normal behavior
|
||||
{
|
||||
return _attr(sel, name, value);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Sets or retrieves the text content of the element
|
||||
* specified by the current selector. If a value is
|
||||
* passed, it will set that value on the current element,
|
||||
* otherwise it will return the value of the current element
|
||||
*
|
||||
* @name text
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {?string} [value]
|
||||
* @return {?string}
|
||||
*/
|
||||
text: function (value)
|
||||
{
|
||||
var oldValue, set, sel;
|
||||
|
||||
sel = this.el;
|
||||
|
||||
set = (value !== undefined) ? true : false;
|
||||
|
||||
oldValue = sel.textContent;
|
||||
|
||||
if(set)
|
||||
{
|
||||
sel.textContent = value;
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return oldValue;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Sets or retrieves a css property of the element
|
||||
* specified by the current selector. If a value is
|
||||
* passed, it will set that value on the current element,
|
||||
* otherwise it will return the value of the css property
|
||||
* on the current element.
|
||||
*
|
||||
* 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
|
||||
* @param {(string|Object)} property
|
||||
* @param {?string} [value]
|
||||
* @return {?string}
|
||||
*/
|
||||
css: function (prop, val)
|
||||
{
|
||||
var prop_key = null;
|
||||
|
||||
// If passed an object, recurse!
|
||||
if($_.type(prop) === 'object')
|
||||
{
|
||||
Object.keys(prop).forEach(function(prop_key) {
|
||||
$_.each(function (e){
|
||||
_css(e, prop_key, prop[prop_key]);
|
||||
});
|
||||
});
|
||||
}
|
||||
//Return the current value if a value is not set
|
||||
else if(val === undefined && $_.type(prop) !== 'object')
|
||||
{
|
||||
return _css(this.el, prop);
|
||||
}
|
||||
|
||||
$_.each(function (e){
|
||||
_css(e, prop, val);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 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
|
||||
* @name append
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {string} htm
|
||||
*/
|
||||
append: function(htm)
|
||||
{
|
||||
this.el.insertAdjacentHTML('beforeend', htm);
|
||||
},
|
||||
/**
|
||||
* 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
|
||||
* @param {string} htm
|
||||
*/
|
||||
prepend: function(htm)
|
||||
{
|
||||
this.el.insertAdjacentHTML('afterbegin', htm);
|
||||
},
|
||||
/**
|
||||
* Sets or gets the innerHTML propery of the element(s) passed
|
||||
*
|
||||
* @name html
|
||||
* @memberOf $_.dom
|
||||
* @function
|
||||
* @param {?string} [htm]
|
||||
* @return {?string}
|
||||
*/
|
||||
html: function(htm)
|
||||
{
|
||||
|
||||
if(htm !== undefined)
|
||||
{
|
||||
this.el.innerHTML = htm;
|
||||
}
|
||||
|
||||
//If the parameter is undefined, just return the current value
|
||||
return this.el.innerHTML;
|
||||
}
|
||||
};
|
||||
|
||||
$_.ext('dom', d);
|
||||
|
||||
}());
|
|
@ -0,0 +1,149 @@
|
|||
/**
|
||||
* Ajax
|
||||
*
|
||||
* Module for making ajax requests
|
||||
*/
|
||||
(function (undefined){
|
||||
|
||||
"use strict";
|
||||
|
||||
var ajax = {
|
||||
_do: function (url, data, success_callback, error_callback, type)
|
||||
{
|
||||
var type,
|
||||
request = new XMLHttpRequest();
|
||||
|
||||
if (success_callback === undefined)
|
||||
{
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
success_callback = function (){};
|
||||
}
|
||||
|
||||
if (type === "GET")
|
||||
{
|
||||
url += (url.match(/\?/))
|
||||
? this._serialize(data)
|
||||
: "?" + this._serialize(data);
|
||||
}
|
||||
|
||||
request.open(type, url);
|
||||
|
||||
request.onreadystatechange = function ()
|
||||
{
|
||||
if (request.readyState === 4)
|
||||
{
|
||||
if (request.status === 200)
|
||||
{
|
||||
success_callback.call(request.responseText, request.responseText);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (error_callback !== undefined)
|
||||
{
|
||||
error_callback.call(request.status, request.status);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
if (type !== "GET")
|
||||
{
|
||||
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
request.send(this._serialize(data));
|
||||
}
|
||||
else
|
||||
{
|
||||
request.send(null);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Url encoding for non-get requests
|
||||
*
|
||||
* @param data
|
||||
* @returns {string}
|
||||
* @private
|
||||
*/
|
||||
_serialize: function (data)
|
||||
{
|
||||
var name,
|
||||
value,
|
||||
pairs = [];
|
||||
|
||||
for (name in data)
|
||||
{
|
||||
if ( ! data.hasOwnProperty(name) || $_.type(data[name]) === "function")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
value = data[name].toString();
|
||||
|
||||
name = encodeURIComponent(name);
|
||||
value = encodeURIComponent(value);
|
||||
|
||||
pairs.push(name + "=" + value);
|
||||
}
|
||||
|
||||
return pairs.join("&");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends a GET type ajax request
|
||||
*
|
||||
* @function get
|
||||
* @memberOf $_
|
||||
* @param {string} url - The url to retrieve
|
||||
* @param {Object} data - get parameters to send
|
||||
* @param {function} success_callback - callback called on success
|
||||
* @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, 'GET');
|
||||
});
|
||||
|
||||
/**
|
||||
* Sends a POST type ajax request
|
||||
*
|
||||
* @function post
|
||||
* @memberOf $_
|
||||
* @param {string} url - The url to post to
|
||||
* @param {Object} data - post parameters to send
|
||||
* @param {function} success_callback - callback called on success
|
||||
* @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, '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');
|
||||
});
|
||||
}());
|
|
@ -0,0 +1,179 @@
|
|||
/**
|
||||
* Event
|
||||
*
|
||||
* Event api wrapper
|
||||
* @todo Add method for triggering events
|
||||
*/
|
||||
(function (undefined){
|
||||
|
||||
"use strict";
|
||||
|
||||
var _add_remove, e, _attach_delegate;
|
||||
|
||||
_add_remove = function (sel, event, callback, add)
|
||||
{
|
||||
var i, len;
|
||||
|
||||
// Multiple events? Run recursively!
|
||||
if ( ! event.match(/^([\w\-]+)$/))
|
||||
{
|
||||
event = event.split(" ");
|
||||
|
||||
len = event.length;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
_add_remove(sel, event[i], callback, add);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Bind the event
|
||||
(add === true)
|
||||
? sel.addEventListener(event, callback, false)
|
||||
: sel.removeEventListener(event, callback, false);
|
||||
};
|
||||
|
||||
_attach_delegate = function(sel, target, event, callback)
|
||||
{
|
||||
// attach the listener to the parent object
|
||||
_add_remove(sel, event, function(e){
|
||||
|
||||
var elem, t;
|
||||
|
||||
// Get the live version of the target selector
|
||||
t = $_.$(target, sel);
|
||||
|
||||
// Check each element to see if it matches the target
|
||||
for(elem in t)
|
||||
{
|
||||
// Fire target callback when event bubbles from target
|
||||
if(e.target == t[elem])
|
||||
{
|
||||
// Trigger the event callback
|
||||
callback.call(t[elem], e);
|
||||
|
||||
// Stop event propegation
|
||||
e.stopPropagation();
|
||||
}
|
||||
}
|
||||
|
||||
}, true);
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Event Listener module
|
||||
*
|
||||
* @namespace
|
||||
* @name event
|
||||
* @memberOf $_
|
||||
*/
|
||||
e = {
|
||||
/**
|
||||
* Create a custom event
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name create
|
||||
* @function
|
||||
* @example var event = $_("#selector").event.create('foo', {});
|
||||
* @param {string} name
|
||||
* @param {object} [data]
|
||||
* @return {Object}
|
||||
*/
|
||||
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;
|
||||
},
|
||||
/**
|
||||
* Adds an event that returns a callback when triggered on the selected
|
||||
* event and selector
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name add
|
||||
* @function
|
||||
* @example $_("#selector").event.add("click", do_something());
|
||||
* @param {string} event
|
||||
* @param {function} callback
|
||||
*/
|
||||
add: function (event, callback)
|
||||
{
|
||||
$_.each(function(e){
|
||||
_add_remove(e, event, callback, true);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Removes an event bound the the specified selector, event type, and callback
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name remove
|
||||
* @function
|
||||
* @example $_("#selector").event.remove("click", do_something());
|
||||
* @param {string} event
|
||||
* @param {string} callback
|
||||
*/
|
||||
remove: function (event, callback)
|
||||
{
|
||||
$_.each(function(e){
|
||||
_add_remove(e, event, callback, false);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Binds a persistent event to the document
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name live
|
||||
* @function
|
||||
* @example $_.event.live(".button", "click", do_something());
|
||||
* @param {string} target
|
||||
* @param {string} event
|
||||
* @param {function} callback
|
||||
*/
|
||||
live: function (target, event, callback)
|
||||
{
|
||||
_attach_delegate(document.documentElement, target, event, callback);
|
||||
},
|
||||
/**
|
||||
* Binds an event to a parent object
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name delegate
|
||||
* @function
|
||||
* @example $_("#parent").delegate(".button", "click", do_something());
|
||||
* @param {string} target
|
||||
* @param {string} event
|
||||
* @param {function} callback
|
||||
*/
|
||||
delegate: function (target, event, callback)
|
||||
{
|
||||
$_.each(function(e){
|
||||
_attach_delegate(e, target, event, callback);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Trigger an event to fire
|
||||
*
|
||||
* @memberOf $_.event
|
||||
* @name trigger
|
||||
* @function
|
||||
* @example $_("#my_id").trigger('click');
|
||||
* @param {object} event
|
||||
* @return {boolean}
|
||||
*/
|
||||
trigger: function(event)
|
||||
{
|
||||
return this.el.dispatchEvent(event);
|
||||
}
|
||||
};
|
||||
|
||||
$_.ext('event', e);
|
||||
|
||||
}());
|
|
@ -0,0 +1,117 @@
|
|||
/**
|
||||
* Store
|
||||
*
|
||||
* Wrapper for local / sessionstorage
|
||||
*/
|
||||
(function (undefined){
|
||||
|
||||
"use strict";
|
||||
|
||||
//Shortcuts for wrapper
|
||||
var l = localStorage,
|
||||
s = sessionStorage;
|
||||
|
||||
/**
|
||||
* Wrapper for localstorage / sessionstorage data serialization.
|
||||
* Each method has a boolean parameter, that when set as true switches the method
|
||||
* to use sessionStorage rather than the default localStorage.
|
||||
*
|
||||
* @name store
|
||||
* @namespace
|
||||
* @memberOf $_
|
||||
*/
|
||||
var store = {
|
||||
/**
|
||||
* Retrieves and deserializes a value from localstorage,
|
||||
* based on the specified key
|
||||
*
|
||||
* @param {string} key
|
||||
* @param {bool} session
|
||||
* @name get
|
||||
* @memberOf $_.store
|
||||
* @function
|
||||
* @return {Object}
|
||||
*/
|
||||
get: function (key, sess)
|
||||
{
|
||||
var val = (sess) ? s.getItem(key) : l.getItem(key);
|
||||
|
||||
return JSON.parse(val);
|
||||
},
|
||||
/**
|
||||
* Puts a value into localstorage at the specified key,
|
||||
* and JSON-encodes the value if not a string
|
||||
*
|
||||
* @param {string} key
|
||||
* @param {mixed} value
|
||||
* @param {bool} session
|
||||
* @name set
|
||||
* @memberOf $_.store
|
||||
* @function
|
||||
*/
|
||||
set: function (key, value, sess)
|
||||
{
|
||||
// Localstorage generally only accepts strings
|
||||
value = JSON.stringify(value);
|
||||
|
||||
(sess) ? s.setItem(key, value) : l.setItem(key, value);
|
||||
},
|
||||
/**
|
||||
* Removes the specified item from storage
|
||||
*
|
||||
* @param {string} key
|
||||
* @param {bool} session
|
||||
* @name remove
|
||||
* @memberOf $_.store
|
||||
* @function
|
||||
*/
|
||||
remove: function (key, sess)
|
||||
{
|
||||
(sess) ? s.removeItem(key) : l.removeItem(key);
|
||||
},
|
||||
/**
|
||||
* Returns an object of all the raw values in storage
|
||||
*
|
||||
* @param {bool} session
|
||||
* @name getAll
|
||||
* @memberOf $_.store
|
||||
* @function
|
||||
* @return {Object}
|
||||
*/
|
||||
getAll: function (sess)
|
||||
{
|
||||
var i,
|
||||
len,
|
||||
data = {},
|
||||
k,
|
||||
o;
|
||||
|
||||
//Reference to session/localstorage
|
||||
o = (sess) ? l : s;
|
||||
|
||||
len = o.length;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
k = o.key(i);
|
||||
data[k] = o.getItem(k);
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
/**
|
||||
* Removes all values from the same domain storage
|
||||
*
|
||||
* @param {bool} session
|
||||
* @name clear
|
||||
* @memberOf $_.store
|
||||
* @function
|
||||
*/
|
||||
clear: function(sess)
|
||||
{
|
||||
(sess) ? s.clear() : l.clear();
|
||||
}
|
||||
};
|
||||
|
||||
$_.ext('store', store);
|
||||
}());
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
$verb = strtolower($_SERVER['REQUEST_METHOD']);
|
||||
|
||||
// Send request method if nothing else is specified
|
||||
if (empty($_GET))
|
||||
{
|
||||
echo $verb;
|
||||
}
|
||||
else if (isset($_GET['data']))
|
||||
{
|
||||
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);
|
||||
}
|
||||
else if (isset($_GET['bad']))
|
||||
{
|
||||
http_response_code('401');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,37 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
||||
<link rel="stylesheet" href="qunit/qunit.css" type="text/css" />
|
||||
<title>Kis-js test suite</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture"></div>
|
||||
<section hidden="hidden">
|
||||
<span id="testSpan"></span>
|
||||
<article id="r14">
|
||||
This is important text!
|
||||
</article>
|
||||
<aside id="classChild">
|
||||
<p class="child"></p>
|
||||
<span class="child"></span>
|
||||
<div class="nephew"></div>
|
||||
</aside>
|
||||
</section>
|
||||
<script src="qunit/qunit.js"></script>
|
||||
<script src='../src/core.js' data-cover></script>
|
||||
<script src='../src/polyfill.js'></script>
|
||||
<script src='../src/modules/ajax.js' data-cover></script>
|
||||
<script src='../src/modules/event.js' data-cover></script>
|
||||
<script src='../src/modules/DOM.js' data-cover></script>
|
||||
<script src='../src/modules/store.js' data-cover></script>
|
||||
<script src="blanket.js"></script>
|
||||
<script src="qunit/test_funcs.js"></script>
|
||||
<script src="tests/core.js"></script>
|
||||
<script src="tests/ajax.js"></script>
|
||||
<script src="tests/event.js"></script>
|
||||
<script src="tests/dom.js"></script>
|
||||
<script src="tests/store.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,244 @@
|
|||
/**
|
||||
* QUnit v1.12.0 - A JavaScript Unit Testing Framework
|
||||
*
|
||||
* http://qunitjs.com
|
||||
*
|
||||
* Copyright 2012 jQuery Foundation and other contributors
|
||||
* Released under the MIT license.
|
||||
* http://jquery.org/license
|
||||
*/
|
||||
|
||||
/** Font Family and Sizes */
|
||||
|
||||
#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult {
|
||||
font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif;
|
||||
}
|
||||
|
||||
#qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
|
||||
#qunit-tests { font-size: smaller; }
|
||||
|
||||
|
||||
/** Resets */
|
||||
|
||||
#qunit-tests, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
|
||||
/** Header */
|
||||
|
||||
#qunit-header {
|
||||
padding: 0.5em 0 0.5em 1em;
|
||||
|
||||
color: #8699a4;
|
||||
background-color: #0d3349;
|
||||
|
||||
font-size: 1.5em;
|
||||
line-height: 1em;
|
||||
font-weight: normal;
|
||||
|
||||
border-radius: 5px 5px 0 0;
|
||||
-moz-border-radius: 5px 5px 0 0;
|
||||
-webkit-border-top-right-radius: 5px;
|
||||
-webkit-border-top-left-radius: 5px;
|
||||
}
|
||||
|
||||
#qunit-header a {
|
||||
text-decoration: none;
|
||||
color: #c2ccd1;
|
||||
}
|
||||
|
||||
#qunit-header a:hover,
|
||||
#qunit-header a:focus {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
#qunit-testrunner-toolbar label {
|
||||
display: inline-block;
|
||||
padding: 0 .5em 0 .1em;
|
||||
}
|
||||
|
||||
#qunit-banner {
|
||||
height: 5px;
|
||||
}
|
||||
|
||||
#qunit-testrunner-toolbar {
|
||||
padding: 0.5em 0 0.5em 2em;
|
||||
color: #5E740B;
|
||||
background-color: #eee;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#qunit-userAgent {
|
||||
padding: 0.5em 0 0.5em 2.5em;
|
||||
background-color: #2b81af;
|
||||
color: #fff;
|
||||
text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
|
||||
}
|
||||
|
||||
#qunit-modulefilter-container {
|
||||
float: right;
|
||||
}
|
||||
|
||||
/** Tests: Pass/Fail */
|
||||
|
||||
#qunit-tests {
|
||||
list-style-position: inside;
|
||||
}
|
||||
|
||||
#qunit-tests li {
|
||||
padding: 0.4em 0.5em 0.4em 2.5em;
|
||||
border-bottom: 1px solid #fff;
|
||||
list-style-position: inside;
|
||||
}
|
||||
|
||||
#qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#qunit-tests li strong {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#qunit-tests li a {
|
||||
padding: 0.5em;
|
||||
color: #c2ccd1;
|
||||
text-decoration: none;
|
||||
}
|
||||
#qunit-tests li a:hover,
|
||||
#qunit-tests li a:focus {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
#qunit-tests li .runtime {
|
||||
float: right;
|
||||
font-size: smaller;
|
||||
}
|
||||
|
||||
.qunit-assert-list {
|
||||
margin-top: 0.5em;
|
||||
padding: 0.5em;
|
||||
|
||||
background-color: #fff;
|
||||
|
||||
border-radius: 5px;
|
||||
-moz-border-radius: 5px;
|
||||
-webkit-border-radius: 5px;
|
||||
}
|
||||
|
||||
.qunit-collapsed {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#qunit-tests table {
|
||||
border-collapse: collapse;
|
||||
margin-top: .2em;
|
||||
}
|
||||
|
||||
#qunit-tests th {
|
||||
text-align: right;
|
||||
vertical-align: top;
|
||||
padding: 0 .5em 0 0;
|
||||
}
|
||||
|
||||
#qunit-tests td {
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
#qunit-tests pre {
|
||||
margin: 0;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
#qunit-tests del {
|
||||
background-color: #e0f2be;
|
||||
color: #374e0c;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#qunit-tests ins {
|
||||
background-color: #ffcaca;
|
||||
color: #500;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/*** Test Counts */
|
||||
|
||||
#qunit-tests b.counts { color: black; }
|
||||
#qunit-tests b.passed { color: #5E740B; }
|
||||
#qunit-tests b.failed { color: #710909; }
|
||||
|
||||
#qunit-tests li li {
|
||||
padding: 5px;
|
||||
background-color: #fff;
|
||||
border-bottom: none;
|
||||
list-style-position: inside;
|
||||
}
|
||||
|
||||
/*** Passing Styles */
|
||||
|
||||
#qunit-tests li li.pass {
|
||||
color: #3c510c;
|
||||
background-color: #fff;
|
||||
border-left: 10px solid #C6E746;
|
||||
}
|
||||
|
||||
#qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
|
||||
#qunit-tests .pass .test-name { color: #366097; }
|
||||
|
||||
#qunit-tests .pass .test-actual,
|
||||
#qunit-tests .pass .test-expected { color: #999999; }
|
||||
|
||||
#qunit-banner.qunit-pass { background-color: #C6E746; }
|
||||
|
||||
/*** Failing Styles */
|
||||
|
||||
#qunit-tests li li.fail {
|
||||
color: #710909;
|
||||
background-color: #fff;
|
||||
border-left: 10px solid #EE5757;
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
#qunit-tests > li:last-child {
|
||||
border-radius: 0 0 5px 5px;
|
||||
-moz-border-radius: 0 0 5px 5px;
|
||||
-webkit-border-bottom-right-radius: 5px;
|
||||
-webkit-border-bottom-left-radius: 5px;
|
||||
}
|
||||
|
||||
#qunit-tests .fail { color: #000000; background-color: #EE5757; }
|
||||
#qunit-tests .fail .test-name,
|
||||
#qunit-tests .fail .module-name { color: #000000; }
|
||||
|
||||
#qunit-tests .fail .test-actual { color: #EE5757; }
|
||||
#qunit-tests .fail .test-expected { color: green; }
|
||||
|
||||
#qunit-banner.qunit-fail { background-color: #EE5757; }
|
||||
|
||||
|
||||
/** Result */
|
||||
|
||||
#qunit-testresult {
|
||||
padding: 0.5em 0.5em 0.5em 2.5em;
|
||||
|
||||
color: #2b81af;
|
||||
background-color: #D2E0E6;
|
||||
|
||||
border-bottom: 1px solid white;
|
||||
}
|
||||
#qunit-testresult .module-name {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/** Fixture */
|
||||
|
||||
#qunit-fixture {
|
||||
position: absolute;
|
||||
top: -10000px;
|
||||
left: -10000px;
|
||||
width: 1000px;
|
||||
height: 1000px;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,60 @@
|
|||
// Query selector function
|
||||
var $ = function(a)
|
||||
{
|
||||
|
||||
var x = document.querySelectorAll(a);
|
||||
|
||||
//Return the single object if applicable
|
||||
return (x.length === 1) ? x[0] : x;
|
||||
}
|
||||
|
||||
//Object equivalence function
|
||||
var is_clone = function(o1, o2)
|
||||
{
|
||||
var n,
|
||||
flag=true;
|
||||
|
||||
for(n in o1)
|
||||
{
|
||||
//Do a shallow compare -- first level only
|
||||
if($_.type(o1[n]) === "object")
|
||||
{
|
||||
if($_.type(o2[n]) !== "object")
|
||||
{
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(o1[n] !== o2[n])
|
||||
{
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(n in o2)
|
||||
{
|
||||
//Do a shallow compare -- first level only
|
||||
if($_.type(o1[n]) === "object")
|
||||
{
|
||||
if($_.type(o2[n]) !== "object")
|
||||
{
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(o2[n] !== o1[n])
|
||||
{
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
(function(){
|
||||
"use strict";
|
||||
|
||||
module("ajax");
|
||||
|
||||
test("Methods defined", function(){
|
||||
expect(2);
|
||||
ok($_.get, "AJAX get method");
|
||||
ok($_.post, "AJAX post method");
|
||||
});
|
||||
|
||||
asyncTest("GET", function() {
|
||||
$_.get("ajax.php", {}, function(res) {
|
||||
ok(res, "Get Response recieved");
|
||||
equal(res, 'get', "Appropriate request type");
|
||||
start();
|
||||
}, function(res) {
|
||||
ok(false, "Response failed");
|
||||
});
|
||||
});
|
||||
|
||||
asyncTest("POST", function() {
|
||||
$_.post("ajax.php", {}, function(res) {
|
||||
ok(res, "Post Response recieved");
|
||||
equal(res, 'post', "Appropriate request type");
|
||||
start();
|
||||
}, function(res) {
|
||||
ok(false, "Post Response failed");
|
||||
});
|
||||
});
|
||||
|
||||
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");
|
||||
equal(res, 401, "Passed value is error code");
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
|
@ -0,0 +1,88 @@
|
|||
(function(){
|
||||
|
||||
"use strict";
|
||||
|
||||
module("core");
|
||||
|
||||
test("Basic requirements", function(){
|
||||
expect(8);
|
||||
ok(document.querySelectorAll, "querySelectorAll");
|
||||
ok(document.getElementById, "getElementById");
|
||||
ok(document.getElementsByTagName, "getElementsByTagName");
|
||||
ok(String.prototype.trim, "String.trim()");
|
||||
ok(JSON.parse, "JSON.parse()");
|
||||
ok(JSON.stringify, "JSON.stringify()");
|
||||
strictEqual(typeof $_, "function", "Global var");
|
||||
strictEqual(typeof $_(), "object");
|
||||
});
|
||||
|
||||
test("Type Checking", function(){
|
||||
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");
|
||||
ok($_.store, "Local Storage module");
|
||||
ok($_().dom, "Dom manipulation module");
|
||||
ok($_.get, "Ajaz module");
|
||||
});
|
||||
}());
|
|
@ -0,0 +1,133 @@
|
|||
(function(){
|
||||
|
||||
"use strict";
|
||||
|
||||
module("dom");
|
||||
|
||||
test("Add/Remove Class", function() {
|
||||
expect(4);
|
||||
var $test = $_("#testSpan");
|
||||
var ele = $test.el;
|
||||
|
||||
$test.dom.addClass("coolClass");
|
||||
equal(ele.className, "coolClass");
|
||||
|
||||
$test.dom.addClass("anotherClass");
|
||||
equal(ele.className, "coolClass anotherClass");
|
||||
|
||||
$test.dom.removeClass("coolClass");
|
||||
equal(ele.className, "anotherClass");
|
||||
|
||||
$test.dom.removeClass("anotherClass");
|
||||
ok(ele.className === undefined || ele.className === "", "testSpan.className is empty");
|
||||
});
|
||||
|
||||
test("Show/Hide", function(){
|
||||
expect(3);
|
||||
|
||||
var $test = $_(".nephew");
|
||||
var ele = $test.el;
|
||||
|
||||
$test.dom.hide();
|
||||
equal(ele.style.display, "none", "Element hidden with display:none");
|
||||
|
||||
$test.dom.show();
|
||||
equal(ele.style.display, "block", "Element shown with display:block");
|
||||
|
||||
$test.dom.hide();
|
||||
$test.dom.show('inline-block');
|
||||
|
||||
equal(ele.style.display, "inline-block", "Element shown with custom display type");
|
||||
});
|
||||
|
||||
test("Text", function(){
|
||||
expect(3);
|
||||
|
||||
var $test = $_("article#r14");
|
||||
var ele = $_("article#r14").el;
|
||||
var text = (typeof ele.innerText !== "undefined") ? ele.innerText : ele.textContent;
|
||||
|
||||
equal($test.el, $("article#r14"), "Selector property is correct");
|
||||
equal($test.dom.text().trim(), text.trim(), "Getting text");
|
||||
equal($test.dom.text(""), "", "Setting text");
|
||||
});
|
||||
|
||||
test("Attr", function(){
|
||||
expect(4);
|
||||
|
||||
var $test = $_("section");
|
||||
var ele = $test.el;
|
||||
|
||||
$test.dom.attr("id", "testing");
|
||||
|
||||
equal($test.dom.attr('id'), "testing", "Getting attribute");
|
||||
equal(ele.id, "testing", "Setting attribute");
|
||||
|
||||
equal($_("div").dom.attr('id'), null, "Trying to get an attribute for multiple elements");
|
||||
|
||||
$test.dom.attr('id', null);
|
||||
equal($test.dom.attr('id'), null, "Non-existent attribute");
|
||||
|
||||
});
|
||||
|
||||
test("CSS", function(){
|
||||
expect(4);
|
||||
|
||||
var $test = $_("section[hidden='hidden']");
|
||||
var ele = $test.el;
|
||||
|
||||
$test.dom.css("display", "block");
|
||||
equal(ele.style.display, "block", "Setting CSS");
|
||||
equal($test.dom.css("display"), "block", "Getting CSS");
|
||||
|
||||
// Multiple styles
|
||||
$test.dom.css({
|
||||
'border-color':'rgb(0, 0, 0)',
|
||||
'border-radius':'5px'
|
||||
});
|
||||
equal(ele.style.borderColor, 'rgb(0, 0, 0)', 'Setting multiple css values 1');
|
||||
equal(ele.style.borderRadius, '5px', 'Setting multiple css values 2');
|
||||
});
|
||||
|
||||
test("html", function(){
|
||||
expect(2);
|
||||
|
||||
var orig_html = "This is important text!";
|
||||
var test_html = '<a href="mailto:tim@timshomepage.net">send tim an email</a>';
|
||||
|
||||
document.getElementById('r14').innerHTML = orig_html;
|
||||
|
||||
|
||||
equal($_('#r14').dom.html().trim(), "This is important text!", "Gets html");
|
||||
equal($_('#r14').dom.html(test_html).toLowerCase(), test_html, "Sets html");
|
||||
});
|
||||
|
||||
test("append", function(){
|
||||
|
||||
expect(1);
|
||||
|
||||
//Remove the text from this element…so we can add to it
|
||||
$_("#r14").dom.html("<ul><li>Test</li></ul>");
|
||||
|
||||
var html = "<ul><li>Test</li><li>This is a test item</li></ul>";
|
||||
|
||||
$_("#r14 ul").dom.append('<li>This is a test item</li>');
|
||||
|
||||
ok($('#r14').innerHTML.toLowerCase(), html.toLowerCase(), "Append adds a child to the end of the selected element");
|
||||
});
|
||||
|
||||
test("prepend", function(){
|
||||
|
||||
expect(1);
|
||||
|
||||
var html = '<ul><li>Test2</li><li>Test</li><li>This is a test item</li></ul>';
|
||||
|
||||
$_("#r14 ul").dom.prepend('<li>Test2</li>');
|
||||
|
||||
ok($('#r14').innerHTML.toLowerCase(), html.toLowerCase(), "Prepend adds a child to the beginning of the selected element");
|
||||
|
||||
//Clean up the html
|
||||
$_("#r14").dom.html("");
|
||||
});
|
||||
|
||||
}());
|
|
@ -0,0 +1,81 @@
|
|||
(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");
|
||||
ok($_.event.add, "Add Method Exists");
|
||||
ok($_.event.remove, "Remove Method Exists");
|
||||
ok($_.event.live, "Live Method Exists");
|
||||
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();
|
||||
};
|
||||
|
||||
$_.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();
|
||||
};
|
||||
|
||||
$_("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);
|
||||
$_('#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);
|
||||
$_('#qunit').event.trigger(this.bar);
|
||||
|
||||
// Remove the events
|
||||
$_("#qunit").event.remove('foo bar', callback);
|
||||
});
|
||||
}());
|
|
@ -0,0 +1,118 @@
|
|||
(function (){
|
||||
//"use strict";
|
||||
|
||||
module("store");
|
||||
|
||||
//Test data
|
||||
var test_obj = {
|
||||
test:'value',
|
||||
t:3,
|
||||
x:[0,5,3]
|
||||
};
|
||||
var t = JSON.stringify(test_obj);
|
||||
|
||||
test("Clear", function(){
|
||||
expect(2);
|
||||
|
||||
//Setup
|
||||
localStorage.clear();
|
||||
localStorage.setItem("test", "value");
|
||||
|
||||
sessionStorage.clear();
|
||||
sessionStorage.setItem("test", "value");
|
||||
|
||||
//Clear localStorage
|
||||
$_.store.clear();
|
||||
equal(localStorage.length, 0, "No items in localStorage");
|
||||
|
||||
//Clear sessionStorage
|
||||
$_.store.clear(true);
|
||||
equal(sessionStorage.length, 0, "No items in sessionStorage");
|
||||
|
||||
});
|
||||
|
||||
test("Set", function(){
|
||||
expect(2);
|
||||
|
||||
$_.store.set('test', test_obj);
|
||||
strictEqual(localStorage.getItem('test'), t, "Set object in localStorage");
|
||||
|
||||
$_.store.set('test', test_obj, true);
|
||||
strictEqual(sessionStorage.getItem('test'), t, "Set object in sessionStorage");
|
||||
|
||||
});
|
||||
|
||||
test("Get", function(){
|
||||
expect(2);
|
||||
|
||||
//Test data
|
||||
var test_obj = {
|
||||
test:'value',
|
||||
t:3,
|
||||
x:[0,5,3]
|
||||
};
|
||||
var t = JSON.stringify(test_obj);
|
||||
var t_prime = JSON.parse(t);
|
||||
|
||||
//This is tricky because test_obj != JSON.parse(JSON.stringify(test_obj))
|
||||
|
||||
|
||||
equal(JSON.stringify($_.store.get('test')), t, "Gets and parses object from localStorage");
|
||||
equal(JSON.stringify($_.store.get('test', true)), t, "Gets and parses object from localStorage");
|
||||
|
||||
});
|
||||
|
||||
test("Remove", function(){
|
||||
expect(2);
|
||||
|
||||
$_.store.remove('test');
|
||||
equal(localStorage["test"], null, "Removes from localStorage");
|
||||
|
||||
$_.store.remove('test', true);
|
||||
equal(sessionStorage["test"], null, "Removes from sessionStorage");
|
||||
});
|
||||
|
||||
test("Get All", function(){
|
||||
expect(2);
|
||||
|
||||
//Make sure storage is clean
|
||||
localStorage.clear();
|
||||
sessionStorage.clear();
|
||||
|
||||
var foo = {
|
||||
a: [0,5,6]
|
||||
};
|
||||
|
||||
var bar = {
|
||||
x: {
|
||||
b: 2
|
||||
},
|
||||
y: "baz"
|
||||
};
|
||||
|
||||
var comb = {
|
||||
foo: JSON.stringify(foo),
|
||||
bar: JSON.stringify(bar),
|
||||
q: "What is the question?"
|
||||
};
|
||||
|
||||
$_.store.set('foo', foo);
|
||||
$_.store.set('bar', bar);
|
||||
localStorage.setItem('q', "What is the question?");
|
||||
|
||||
$_.store.set('foo', foo, true);
|
||||
$_.store.set('bar', bar, true);
|
||||
sessionStorage.setItem('q', "What is the question?");
|
||||
|
||||
var all_local = $_.store.getAll();
|
||||
var all_session = $_.store.getAll(true);
|
||||
|
||||
|
||||
|
||||
//comb = comb;
|
||||
|
||||
equal(is_clone(all_local, comb), true, "Gets all items from localStorage");
|
||||
equal(is_clone(all_session, comb), true, "Gets all items from sessionStorage");
|
||||
});
|
||||
|
||||
}());
|
Loading…
Reference in New Issue