A jQuery'ish set of utility methods. There is very few methods available under this namespace, the ish('selector') will by far be the most commonly used method. You'll also find an extends method and an optional AJAX utility.
Example
(function($){
// now you can use the $ sign in place of ish just as you would using jQuery.
// Let's start by grabbing a reference to a DOM node with the selector engine
var $element = $('selector');
// now we'll add the attribute 'data-ish' with a property of 'true'
$element.attr('data-ish','true');
var obj1 = {a:'a'};
var obj2 = {a:'new a', b:'b'};
$.extend(obj1,obj2);
})(ish);
Properties
Methods
ajax(options)
Description:
Make an XHR request. The implementation is currently very basic, the response is not parsed as JSON or converted to a String, you will have to do that to the response manually when it's returned.
Parameters:
| Name | Type | Description | |||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| options |
|
Properties
|
Example:
var reqSuccess = function(data){
//success
console.log('success', data, req);
};
var reqError = function(statusText, status){
//error
console.log('There was an error. '+status+' : '+statusText, req);
};
var req = ish.ajax({
type:'JSON',
url: 'http://domain.com/ajaxhandler',
success: reqSuccess,
error: reqError,
data: {"JSON":"data"}
});
bindToObject(domNode, dataObject)
Description:
Whilst the ish.renderBind method renders values to the DOM, ish.bindToObject sets the values of the binds DOM attributes in the target object.
Parameters:
| Name | Type | Description |
|---|---|---|
| domNode |
|
An exisiting DOM Node. |
| dataObject |
|
An object whose values will be bound to the rendered HTML. |
Example:
var template = '<p ish-bind="textContent:text"></p>'
var node = ish.renderTemplate(template, {text:'text has been rendered'});
// you would usualy use ish.updateTemplate, this is just for exmaple
ish.renderBind(node, {text: 'text has been updated text'});
ish(selector, context, forceSelector)
Description:
Simple selector engine based on querySelectorAll. The usage and result is similar to jQuery(selector).
Parameters:
| Name | Type | Description |
|---|---|---|
| selector |
|
A CSS Selector compatible with document.querySelectorAll or a single |
| context |
|
Used to give a selector a search context. |
| forceSelector |
|
Set the ish('selector').selector paramter forcibly. |
Example:
ish('selector');
//filter the collection with some context of type Node || NodeList
ish('selector', Node);
ish('selector', NodeList);
renderBind(domNode, dataObject)
Description:
Render the values given in the dataObject to a single node.
Returns
Node
The rendered HTML template Node which can be inserted into the DOM.
Parameters:
| Name | Type | Description |
|---|---|---|
| domNode |
|
An exisiting DOM Node. |
| dataObject |
|
An object whose values will be bound to the rendered HTML. |
Example:
var template = '<p ish-bind="textContent:text"></p>'
var node = ish.renderTemplate(template, {text:'text has been rendered'});
// you would usualy use ish.updateTemplate, this is just for exmaple
ish.renderBind(node, {text: 'text has been updated text'});
renderTemplate(templateString, dataObject)
Description:
Render a template string with corresponding object data.
Returns
Node
The rendered HTML template Node which can be inserted into the DOM.
Parameters:
| Name | Type | Description |
|---|---|---|
| templateString |
|
A valid HTML template string. |
| dataObject |
|
An object whose values will be bound to the rendered HTML. |
Example:
var template = '<div><p ish-bind="textContent:text"></p></div>'
ish.renderTemplate(template, {text: 'Text has been rendered.'});
resolveObjectPath(object, pathString)
Description:
Resolves an Object path given in String format within the given Object.
Returns
Object
The resolved value.
Parameters:
| Name | Type | Description |
|---|---|---|
| object |
|
The object which contains the value you're attempting to resolve. |
| pathString |
|
The path of the value which you are attempting to resolve. |
Example:
var object = {
nested: {
value : 'a nested value',
array: [1,2,'third',4,5]
}
};
var value = ish.resolveObjectPath(object, 'nested.value'); // 'a nested value'
var arrayValue = ish.resolveObjectPath(object, 'nested.array[3]'); // 'third'
setPathByString(object, pathString, value)
Description:
Sets an the value of an Object path given in String format within the given Object.
Returns
Object
The resolved value.
Parameters:
| Name | Type | Description |
|---|---|---|
| object |
|
The object which contains the value you're attempting to set. |
| pathString |
|
The path of the value which you are attempting to set. |
| value |
|
The value you're attempting to set. |
Example:
var object = {
nested: {
value : 'a nested value',
array: [1,2,'third',4,5]
}
};
var value = ish.resolveObjectPath(object, 'nested.value'); // 'a nested value'
var arrayValue = ish.resolveObjectPath(object, 'nested.array[3]'); // 'third'
updateTemplate(updateNode, updateObject)
Description:
Update a template Node with a corresponding object data.
Returns
ish
Parameters:
| Name | Type | Description |
|---|---|---|
| updateNode |
|
The node to update, all child Node's will be updated. |
| updateObject |
|
An object whose values will be updated in the provided HTML. |
Example:
var template = '<div><p ish-bind="textContent:text"></p></div>';
var renderedTemplate = ish.renderTemplate();
ish.updateTemplate(renderedTemplate, {});
extend(object1, ,obectj2opt)
Description:
Accepts a series objects, merging the second parameter into the first recursively, if more than two objects are supplied the other objects are merged into the first in the order given.
Returns
Object
A merged Object.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
| object1 |
|
An |
|
| ,obectj2 |
|
<optional> |
A series of |
Example:
var obj1 = {a:'a',b:{ba:'ba',bb:'bb',bc:{bca:'bca'}},c:[1,2,3]};
var obj2 = {d:'d',b:{ba:'ba-change',bc:{bcb:'added'}},c:[4,5,6]};
ish.extend(obj1,obj2);