kis-js/docs/core.js.html

209 lines
4.3 KiB
HTML

<!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 &amp;&amp; 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 &amp;&amp; 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 &amp;&amp; (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>