diff --git a/docs/files.html b/docs/files.html index f33872d..72cfddf 100755 --- a/docs/files.html +++ b/docs/files.html @@ -1 +1 @@ -JsDoc Reference - File Index
 
Project Outline
 
$_
$(string, object)
ext(string, object)
each(function)
type(mixed)
get(string, object, function, function)
post(string, object, function, function)
addClass(string)
removeClass(string)
show(string)
attr(string, string)
text(string)
css(string, string)
append(string)
prepend(string)
html(string)
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string, function)
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
getAll(bool)
clear(bool)
object_keys(object)
array_combine(array/object, array/object)
object_merge(object)
str_trans(string, mixed, string)
«
Kis JS Docs

File Index

core.js../kis-js/src/modules/event.js
ajax.js../kis-js/src/modules/event.js
DOM.js../kis-js/src/modules/event.js
event.js../kis-js/src/modules/event.js
store.js../kis-js/src/modules/event.js
util.js../kis-js/src/modules/event.js
\ No newline at end of file +JsDoc Reference - File Index
 
Project Outline
 
$_
$(string, object)
ext(string, object)
each(function)
type(mixed)
get(string, object, function, function)
post(string, object, function, function)
addClass(string)
removeClass(string)
show(string)
attr(string, string)
text(string)
css(string, string)
append(string)
prepend(string)
html(string)
create(string, object)
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string, function)
trigger(string, object)
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
getAll(bool)
clear(bool)
«
Kis JS Docs

File Index

core.js../kis-js/src/modules/event.js
ajax.js../kis-js/src/modules/event.js
DOM.js../kis-js/src/modules/event.js
event.js../kis-js/src/modules/event.js
store.js../kis-js/src/modules/event.js
\ No newline at end of file diff --git a/docs/index.html b/docs/index.html index c60c2bc..cbec70e 100755 --- a/docs/index.html +++ b/docs/index.html @@ -1 +1 @@ -JsDoc Reference - Index
 
Project Outline
 
$_
$(string, object)
ext(string, object)
each(function)
type(mixed)
get(string, object, function, function)
post(string, object, function, function)
addClass(string)
removeClass(string)
show(string)
attr(string, string)
text(string)
css(string, string)
append(string)
prepend(string)
html(string)
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string, function)
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
getAll(bool)
clear(bool)
object_keys(object)
array_combine(array/object, array/object)
object_merge(object)
str_trans(string, mixed, string)
«
Kis JS Docs

Class Index

_global_

Global namespace.

\ No newline at end of file +JsDoc Reference - Index
 
Project Outline
 
$_
$(string, object)
ext(string, object)
each(function)
type(mixed)
get(string, object, function, function)
post(string, object, function, function)
addClass(string)
removeClass(string)
show(string)
attr(string, string)
text(string)
css(string, string)
append(string)
prepend(string)
html(string)
create(string, object)
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string, function)
trigger(string, object)
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
getAll(bool)
clear(bool)
«
Kis JS Docs

Class Index

_global_

Global namespace.

\ No newline at end of file diff --git a/docs/symbols/$_.dom.html b/docs/symbols/$_.dom.html index 43d0537..f1e7fe6 100755 --- a/docs/symbols/$_.dom.html +++ b/docs/symbols/$_.dom.html @@ -1 +1 @@ -JsDoc Reference - $_.dom
 
Project Outline
 
$_
$(string, object)
ext(string, object)
each(function)
type(mixed)
get(string, object, function, function)
post(string, object, function, function)
addClass(string)
removeClass(string)
show(string)
attr(string, string)
text(string)
css(string, string)
append(string)
prepend(string)
html(string)
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string, function)
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
getAll(bool)
clear(bool)
object_keys(object)
array_combine(array/object, array/object)
object_merge(object)
str_trans(string, mixed, string)
«
Kis JS Docs

Module $_.dom

Defined in: DOM.js.

Method Summary
addClass(string)Adds a class to the element(s) specified by the current selector
removeClass(string)Removes a class from the element(s) specified by the current selector
hide()Hides the element(s) specified by the current selector
show(string)Shows the element(s) specified by the current selector.
attr(string, string)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.
text(string)Sets or retrieves the text content of the element specified by the current selector.
css(string, string)Sets or retrieves a css property of the element specified by the current selector.
append(string)Adds to the innerHTML of the current element, after the last child.
prepend(string)Adds to the innerHTML of the selected element, before the current children
html(string)Sets or gets the innerHTML propery of the element(s) passed
Method Detail
$_.dom.addClass(string)
Adds a class to the element(s) specified by the current selector
Parameters:
string class
$_.dom.removeClass(string)
Removes a class from the element(s) specified by the current selector
Parameters:
string class
$_.dom.hide()
Hides the element(s) specified by the current selector
$_.dom.show(string)
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".
Parameters:
string?, Default: type
$_.dom.attr(string, string): string
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.
Parameters:
string name
string?, Default: value
Returns:
string
$_.dom.text(string): string
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
Parameters:
string?, Default: value
Returns:
string
$_.dom.css(string, string): string
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
Parameters:
string property
string?, Default: value
Returns:
string
$_.dom.append(string)
Adds to the innerHTML of the current element, after the last child.
$_("ul").dom.append("<li></li>") adds an li element to the end of the selected ul element
Parameters:
string htm
$_.dom.prepend(string)
Adds to the innerHTML of the selected element, before the current children
Parameters:
string htm
$_.dom.html(string): string
Sets or gets the innerHTML propery of the element(s) passed
Parameters:
string?, Default: htm
Returns:
string
\ No newline at end of file +JsDoc Reference - $_.dom
 
Project Outline
 
$_
$(string, object)
ext(string, object)
each(function)
type(mixed)
get(string, object, function, function)
post(string, object, function, function)
addClass(string)
removeClass(string)
show(string)
attr(string, string)
text(string)
css(string, string)
append(string)
prepend(string)
html(string)
create(string, object)
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string, function)
trigger(string, object)
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
getAll(bool)
clear(bool)
«
Kis JS Docs

Module $_.dom

Defined in: DOM.js.

Method Summary
addClass(string)Adds a class to the element(s) specified by the current selector
removeClass(string)Removes a class from the element(s) specified by the current selector
hide()Hides the element(s) specified by the current selector
show(string)Shows the element(s) specified by the current selector.
attr(string, string)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.
text(string)Sets or retrieves the text content of the element specified by the current selector.
css(string, string)Sets or retrieves a css property of the element specified by the current selector.
append(string)Adds to the innerHTML of the current element, after the last child.
prepend(string)Adds to the innerHTML of the selected element, before the current children
html(string)Sets or gets the innerHTML propery of the element(s) passed
Method Detail
$_.dom.addClass(string)
Adds a class to the element(s) specified by the current selector
Parameters:
string class
$_.dom.removeClass(string)
Removes a class from the element(s) specified by the current selector
Parameters:
string class
$_.dom.hide()
Hides the element(s) specified by the current selector
$_.dom.show(string)
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".
Parameters:
string?, Default: type
$_.dom.attr(string, string): string
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.
Parameters:
string name
string?, Default: value
Returns:
string
$_.dom.text(string): string
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
Parameters:
string?, Default: value
Returns:
string
$_.dom.css(string, string): string
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
Parameters:
string property
string?, Default: value
Returns:
string
$_.dom.append(string)
Adds to the innerHTML of the current element, after the last child.
$_("ul").dom.append("<li></li>") adds an li element to the end of the selected ul element
Parameters:
string htm
$_.dom.prepend(string)
Adds to the innerHTML of the selected element, before the current children
Parameters:
string htm
$_.dom.html(string): string
Sets or gets the innerHTML propery of the element(s) passed
Parameters:
string?, Default: htm
Returns:
string
\ No newline at end of file diff --git a/docs/symbols/$_.event.html b/docs/symbols/$_.event.html index 4f7aa5f..04ca5bf 100755 --- a/docs/symbols/$_.event.html +++ b/docs/symbols/$_.event.html @@ -1 +1 @@ -JsDoc Reference - $_.event
 
Project Outline
 
$_
$(string, object)
ext(string, object)
each(function)
type(mixed)
get(string, object, function, function)
post(string, object, function, function)
addClass(string)
removeClass(string)
show(string)
attr(string, string)
text(string)
css(string, string)
append(string)
prepend(string)
html(string)
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string, function)
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
getAll(bool)
clear(bool)
object_keys(object)
array_combine(array/object, array/object)
object_merge(object)
str_trans(string, mixed, string)
«
Kis JS Docs

Module $_.event

Defined in: event.js.

Method Summary
add(string, function)Adds an event that returns a callback when triggered on the selected event and selector
remove(string, string)Removes an event bound the the specified selector, event type, and callback
live(string, string, function)Binds a persistent event to the document
delegate(string, string, function)Binds an event to a parent object
Method Detail
$_.event.add(string, function)
Adds an event that returns a callback when triggered on the selected event and selector
Eg. $_("#selector").event.add("click", do_something());
Parameters:
string event
function callback
$_.event.remove(string, string)
Removes an event bound the the specified selector, event type, and callback
Eg. $_("#selector").event.remove("click", do_something());
Parameters:
string event
string callback
$_.event.live(string, string, function)
Binds a persistent event to the document
Eg. $_.event.live(".button", "click", do_something());
Parameters:
string target
string event
function callback
$_.event.delegate(string, string, function)
Binds an event to a parent object
Eg. $_("#parent").delegate(".button", "click", do_something());
Parameters:
string target
string event_type
function callback
\ No newline at end of file +JsDoc Reference - $_.event
 
Project Outline
 
$_
$(string, object)
ext(string, object)
each(function)
type(mixed)
get(string, object, function, function)
post(string, object, function, function)
addClass(string)
removeClass(string)
show(string)
attr(string, string)
text(string)
css(string, string)
append(string)
prepend(string)
html(string)
create(string, object)
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string, function)
trigger(string, object)
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
getAll(bool)
clear(bool)
«
Kis JS Docs

Module $_.event

Defined in: event.js.

Method Summary
create(string, object)Create a custom event
add(string, function)Adds an event that returns a callback when triggered on the selected event and selector
remove(string, string)Removes an event bound the the specified selector, event type, and callback
live(string, string, function)Binds a persistent event to the document
delegate(string, string, function)Binds an event to a parent object
trigger(string, object)Trigger an event to fire
Method Detail
$_.event.create(string, object)
Create a custom event
Eg. var event = $_("#selector").event.create('foo', {});
Parameters:
string name
object?, Default: data
Returns:
object
$_.event.add(string, function)
Adds an event that returns a callback when triggered on the selected event and selector
Eg. $_("#selector").event.add("click", do_something());
Parameters:
string event
function callback
$_.event.remove(string, string)
Removes an event bound the the specified selector, event type, and callback
Eg. $_("#selector").event.remove("click", do_something());
Parameters:
string event
string callback
$_.event.live(string, string, function)
Binds a persistent event to the document
Eg. $_.event.live(".button", "click", do_something());
Parameters:
string target
string event
function callback
$_.event.delegate(string, string, function)
Binds an event to a parent object
Eg. $_("#parent").delegate(".button", "click", do_something());
Parameters:
string target
string event_type
function callback
$_.event.trigger(string, object)
Trigger an event to fire
Eg. $_("#my_id").trigger('click');
Parameters:
string target
object event
Returns:
bool
\ No newline at end of file diff --git a/docs/symbols/$_.html b/docs/symbols/$_.html index c466a45..48cbe5b 100755 --- a/docs/symbols/$_.html +++ b/docs/symbols/$_.html @@ -1 +1 @@ -JsDoc Reference - $_
 
Project Outline
 
$_
$(string, object)
ext(string, object)
each(function)
type(mixed)
get(string, object, function, function)
post(string, object, function, function)
addClass(string)
removeClass(string)
show(string)
attr(string, string)
text(string)
css(string, string)
append(string)
prepend(string)
html(string)
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string, function)
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
getAll(bool)
clear(bool)
object_keys(object)
array_combine(array/object, array/object)
object_merge(object)
str_trans(string, mixed, string)
«
Kis JS Docs

Module $_

Defined in: core.js.

Field Summary
domDOM Dom manipulation module
storeWrapper for localstorage / sessionstorage data serialization.
utilString and object manipulation utilities
eventEvent Listener module
Method Summary
$(string, object)Simple DOM selector function
ext(string, object)Adds the property `obj` to the $_ object, calling it `name`
each(function)Iterates over a $_ object, applying a callback to each item
type(mixed)Retrieves the type of the passed variable
get(string, object, function, function)Sends a GET type ajax request
post(string, object, function, function)Sends a POST type ajax request
Field Detail
$_.dom
DOM Dom manipulation module

Defined in: DOM.js.

$_.store
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.

Defined in: store.js.

$_.util
String and object manipulation utilities

Defined in: util.js.

$_.event
Event Listener module

Defined in: event.js.

Method Detail
$_.$(string, object): object
Simple DOM selector function
Parameters:
string selector
object context
Returns:
object
$_.ext(string, object)
Adds the property `obj` to the $_ object, calling it `name`
Parameters:
string name
object obj
$_.each(function)
Iterates over a $_ object, applying a callback to each item
Parameters:
function callback
$_.type(mixed): string
Retrieves the type of the passed variable
Parameters:
mixed obj
Returns:
string
$_.get(string, object, function, function)
Sends a GET type ajax request

Defined in: ajax.js.

Parameters:
string url
object data
function success_callback
function error_callback
$_.post(string, object, function, function)
Sends a POST type ajax request

Defined in: ajax.js.

Parameters:
string url
object data
function success_callback
function error_callback
\ No newline at end of file +JsDoc Reference - $_
 
Project Outline
 
$_
$(string, object)
ext(string, object)
each(function)
type(mixed)
get(string, object, function, function)
post(string, object, function, function)
addClass(string)
removeClass(string)
show(string)
attr(string, string)
text(string)
css(string, string)
append(string)
prepend(string)
html(string)
create(string, object)
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string, function)
trigger(string, object)
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
getAll(bool)
clear(bool)
«
Kis JS Docs

Module $_

Defined in: core.js.

Field Summary
domDOM Dom manipulation module
storeWrapper for localstorage / sessionstorage data serialization.
eventEvent Listener module
Method Summary
$(string, object)Simple DOM selector function
ext(string, object)Adds the property `obj` to the $_ object, calling it `name`
each(function)Iterates over a $_ object, applying a callback to each item
type(mixed)Retrieves the type of the passed variable
get(string, object, function, function)Sends a GET type ajax request
post(string, object, function, function)Sends a POST type ajax request
Field Detail
$_.dom
DOM Dom manipulation module

Defined in: DOM.js.

$_.store
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.

Defined in: store.js.

$_.event
Event Listener module

Defined in: event.js.

Method Detail
$_.$(string, object): object
Simple DOM selector function
Parameters:
string selector
object context
Returns:
object
$_.ext(string, object)
Adds the property `obj` to the $_ object, calling it `name`
Parameters:
string name
object obj
$_.each(function)
Iterates over a $_ object, applying a callback to each item
Parameters:
function callback
$_.type(mixed): string
Retrieves the type of the passed variable
Parameters:
mixed obj
Returns:
string
$_.get(string, object, function, function)
Sends a GET type ajax request

Defined in: ajax.js.

Parameters:
string url
object data
function success_callback
function error_callback
$_.post(string, object, function, function)
Sends a POST type ajax request

Defined in: ajax.js.

Parameters:
string url
object data
function success_callback
function error_callback
\ No newline at end of file diff --git a/docs/symbols/$_.store.html b/docs/symbols/$_.store.html index 2ded851..d4f8050 100755 --- a/docs/symbols/$_.store.html +++ b/docs/symbols/$_.store.html @@ -1 +1 @@ -JsDoc Reference - $_.store
 
Project Outline
 
$_
$(string, object)
ext(string, object)
each(function)
type(mixed)
get(string, object, function, function)
post(string, object, function, function)
addClass(string)
removeClass(string)
show(string)
attr(string, string)
text(string)
css(string, string)
append(string)
prepend(string)
html(string)
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string, function)
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
getAll(bool)
clear(bool)
object_keys(object)
array_combine(array/object, array/object)
object_merge(object)
str_trans(string, mixed, string)
«
Kis JS Docs

Module $_.store

Defined in: store.js.

Method Summary
get(string, bool)Retrieves and deserializes a value from localstorage, based on the specified key
set(string, mixed, bool)Puts a value into localstorage at the specified key, and JSON-encodes the value if not a string
remove(string, bool)Removes the specified item from storage
getAll(bool)Returns an object of all the raw values in storage
clear(bool)Removes all values from the same domain storage
Method Detail
$_.store.get(string, bool): object
Retrieves and deserializes a value from localstorage, based on the specified key
Parameters:
string key
bool session
Returns:
object
$_.store.set(string, mixed, bool)
Puts a value into localstorage at the specified key, and JSON-encodes the value if not a string
Parameters:
string key
mixed value
bool session
$_.store.remove(string, bool)
Removes the specified item from storage
Parameters:
string key
bool session
$_.store.getAll(bool): object
Returns an object of all the raw values in storage
Parameters:
bool session
Returns:
object
$_.store.clear(bool)
Removes all values from the same domain storage
Parameters:
bool session
\ No newline at end of file +JsDoc Reference - $_.store
 
Project Outline
 
$_
$(string, object)
ext(string, object)
each(function)
type(mixed)
get(string, object, function, function)
post(string, object, function, function)
addClass(string)
removeClass(string)
show(string)
attr(string, string)
text(string)
css(string, string)
append(string)
prepend(string)
html(string)
create(string, object)
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string, function)
trigger(string, object)
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
getAll(bool)
clear(bool)
«
Kis JS Docs

Module $_.store

Defined in: store.js.

Method Summary
get(string, bool)Retrieves and deserializes a value from localstorage, based on the specified key
set(string, mixed, bool)Puts a value into localstorage at the specified key, and JSON-encodes the value if not a string
remove(string, bool)Removes the specified item from storage
getAll(bool)Returns an object of all the raw values in storage
clear(bool)Removes all values from the same domain storage
Method Detail
$_.store.get(string, bool): object
Retrieves and deserializes a value from localstorage, based on the specified key
Parameters:
string key
bool session
Returns:
object
$_.store.set(string, mixed, bool)
Puts a value into localstorage at the specified key, and JSON-encodes the value if not a string
Parameters:
string key
mixed value
bool session
$_.store.remove(string, bool)
Removes the specified item from storage
Parameters:
string key
bool session
$_.store.getAll(bool): object
Returns an object of all the raw values in storage
Parameters:
bool session
Returns:
object
$_.store.clear(bool)
Removes all values from the same domain storage
Parameters:
bool session
\ No newline at end of file diff --git a/docs/symbols/$_.util.html b/docs/symbols/$_.util.html index 3d9252a..6906765 100755 --- a/docs/symbols/$_.util.html +++ b/docs/symbols/$_.util.html @@ -1 +1 @@ -JsDoc Reference - $_.util
 
Project Outline
 
$_
$(string, object)
ext(string, object)
each(function)
type(mixed)
get(string, object, function, function)
post(string, object, function, function)
addClass(string)
removeClass(string)
show(string)
attr(string, string)
text(string)
css(string, string)
append(string)
prepend(string)
html(string)
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string, function)
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
getAll(bool)
clear(bool)
object_keys(object)
array_combine(array/object, array/object)
object_merge(object)
str_trans(string, mixed, string)
«
Kis JS Docs

Module $_.util

Defined in: util.js.

Method Summary
object_keys(object)Retrieve the keys, or member names of an object
object_values(object)Retrieves the values of an object, and returns them as an array
array_combine(array/object, array/object)Creates an object, with the property names of the first array, and the values of the second.
object_merge(object)Combines two or more objects/arrays.
str_trans(string, mixed, string)Replaces sections of strings in a greedy fashion, starting with the longest replace pairs first.
Method Detail
$_.util.object_keys(object): array
Retrieve the keys, or member names of an object
Parameters:
object
Returns:
array
$_.util.object_values(object): array
Retrieves the values of an object, and returns them as an array
Parameters:
object
Returns:
array
$_.util.array_combine(array/object, array/object): object
Creates an object, with the property names of the first array, and the values of the second. If objects are passed, the values of the object are used. If the arrays or objects passed are not the same size, the function will return false.
Parameters:
array/object keys
array/object vals
Returns:
object
$_.util.object_merge(object): object
Combines two or more objects/arrays. If the keys are numeric, the outputted object will have re-indexed keys. If a key/value pair exists in both objects, indentical values will be droped, but if a key exists with a different value, with the same key, the value in the second array will replace the value in the first
Parameters:
object [as many as you wish to combine]
Returns:
object
$_.util.str_trans(string, mixed, string): string
Replaces sections of strings in a greedy fashion, starting with the longest replace pairs first. Accepts one replace pair as two parameters, or an object, with from => to replacements as key/value pairs
Parameters:
string input_string
mixed from (string)/replace pairs (object)
string?, Default:
Returns:
string
\ No newline at end of file +JsDoc Reference - $_.util
 
Project Outline
 
$_
$(string, object)
ext(string, object)
each(function)
type(mixed)
get(string, object, function, function)
post(string, object, function, function)
addClass(string)
removeClass(string)
show(string)
attr(string, string)
text(string)
css(string, string)
append(string)
prepend(string)
html(string)
create(string, object)
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string, function)
trigger(string, object)
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
getAll(bool)
clear(bool)
object_keys(object)
array_combine(array/object, array/object)
object_merge(object)
str_trans(string, mixed, string)
«
Kis JS Docs

Module $_.util

Defined in: util.js.

Method Summary
object_keys(object)Retrieve the keys, or member names of an object
object_values(object)Retrieves the values of an object, and returns them as an array
array_combine(array/object, array/object)Creates an object, with the property names of the first array, and the values of the second.
object_merge(object)Combines two or more objects/arrays.
str_trans(string, mixed, string)Replaces sections of strings in a greedy fashion, starting with the longest replace pairs first.
Method Detail
$_.util.object_keys(object): array
Retrieve the keys, or member names of an object
Parameters:
object
Returns:
array
$_.util.object_values(object): array
Retrieves the values of an object, and returns them as an array
Parameters:
object
Returns:
array
$_.util.array_combine(array/object, array/object): object
Creates an object, with the property names of the first array, and the values of the second. If objects are passed, the values of the object are used. If the arrays or objects passed are not the same size, the function will return false.
Parameters:
array/object keys
array/object vals
Returns:
object
$_.util.object_merge(object): object
Combines two or more objects/arrays. If the keys are numeric, the outputted object will have re-indexed keys. If a key/value pair exists in both objects, indentical values will be droped, but if a key exists with a different value, with the same key, the value in the second array will replace the value in the first
Parameters:
object [as many as you wish to combine]
Returns:
object
$_.util.str_trans(string, mixed, string): string
Replaces sections of strings in a greedy fashion, starting with the longest replace pairs first. Accepts one replace pair as two parameters, or an object, with from => to replacements as key/value pairs
Parameters:
string input_string
mixed from (string)/replace pairs (object)
string?, Default:
Returns:
string
\ No newline at end of file diff --git a/docs/symbols/_global_.html b/docs/symbols/_global_.html index 25a4d62..4331c28 100755 --- a/docs/symbols/_global_.html +++ b/docs/symbols/_global_.html @@ -1 +1 @@ -JsDoc Reference - _global_
 
Project Outline
 
$_
$(string, object)
ext(string, object)
each(function)
type(mixed)
get(string, object, function, function)
post(string, object, function, function)
addClass(string)
removeClass(string)
show(string)
attr(string, string)
text(string)
css(string, string)
append(string)
prepend(string)
html(string)
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string, function)
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
getAll(bool)
clear(bool)
object_keys(object)
array_combine(array/object, array/object)
object_merge(object)
str_trans(string, mixed, string)
«
Kis JS Docs

Built-In Module _global_

\ No newline at end of file +JsDoc Reference - _global_
 
Project Outline
 
$_
$(string, object)
ext(string, object)
each(function)
type(mixed)
get(string, object, function, function)
post(string, object, function, function)
addClass(string)
removeClass(string)
show(string)
attr(string, string)
text(string)
css(string, string)
append(string)
prepend(string)
html(string)
create(string, object)
add(string, function)
remove(string, string)
live(string, string, function)
delegate(string, string, function)
trigger(string, object)
get(string, bool)
set(string, mixed, bool)
remove(string, bool)
getAll(bool)
clear(bool)
«
Kis JS Docs

Built-In Module _global_

\ No newline at end of file diff --git a/docs/symbols/src/kis-js_src_modules_DOM.js.html b/docs/symbols/src/kis-js_src_modules_DOM.js.html index 826a820..aa9f6a1 100755 --- a/docs/symbols/src/kis-js_src_modules_DOM.js.html +++ b/docs/symbols/src/kis-js_src_modules_DOM.js.html @@ -314,57 +314,43 @@ 307 */ 308 append: function(htm) 309 { -310 if(document.insertAdjacentHTML !== undefined) -311 { -312 this.el.insertAdjacentHTML('beforeend', htm); -313 } -314 else -315 { -316 this.el.innerHTML += htm; -317 } -318 }, -319 /** -320 * Adds to the innerHTML of the selected element, before the current children -321 * -322 * @name prepend -323 * @memberOf $_.dom -324 * @function -325 * @param string htm -326 */ -327 prepend: function(htm) -328 { -329 if(document.insertAdjacentHTML !== undefined) -330 { -331 this.el.insertAdjacentHTML('afterbegin', htm); -332 } -333 else -334 { -335 this.el.innerHTML = htm + this.el.innerHTML; -336 } -337 }, -338 /** -339 * Sets or gets the innerHTML propery of the element(s) passed -340 * -341 * @name html -342 * @memberOf $_.dom -343 * @function -344 * @param [string] htm -345 * @return string -346 * @type string -347 */ -348 html: function(htm) -349 { -350 -351 if(htm !== undefined) -352 { -353 this.el.innerHTML = htm; -354 } -355 -356 //If the parameter is undefined, just return the current value -357 return this.el.innerHTML; -358 } -359 }; -360 -361 $_.ext('dom', d); -362 -363 }()); \ No newline at end of file +310 this.el.insertAdjacentHTML('beforeend', htm); +311 }, +312 /** +313 * Adds to the innerHTML of the selected element, before the current children +314 * +315 * @name prepend +316 * @memberOf $_.dom +317 * @function +318 * @param string htm +319 */ +320 prepend: function(htm) +321 { +322 this.el.insertAdjacentHTML('afterbegin', htm); +323 }, +324 /** +325 * Sets or gets the innerHTML propery of the element(s) passed +326 * +327 * @name html +328 * @memberOf $_.dom +329 * @function +330 * @param [string] htm +331 * @return string +332 * @type string +333 */ +334 html: function(htm) +335 { +336 +337 if(htm !== undefined) +338 { +339 this.el.innerHTML = htm; +340 } +341 +342 //If the parameter is undefined, just return the current value +343 return this.el.innerHTML; +344 } +345 }; +346 +347 $_.ext('dom', d); +348 +349 }()); \ No newline at end of file diff --git a/docs/symbols/src/kis-js_src_modules_ajax.js.html b/docs/symbols/src/kis-js_src_modules_ajax.js.html index cf83346..c1897ce 100755 --- a/docs/symbols/src/kis-js_src_modules_ajax.js.html +++ b/docs/symbols/src/kis-js_src_modules_ajax.js.html @@ -76,7 +76,7 @@ 69 70 for (name in data) 71 { - 72 if ( ! data.hasOwnProperty(name) || typeof data[name] === "function") + 72 if ( ! data.hasOwnProperty(name) || $_.type(data[name]) === "function") 73 { 74 continue; 75 } diff --git a/docs/symbols/src/kis-js_src_modules_event.js.html b/docs/symbols/src/kis-js_src_modules_event.js.html index dfb669c..d825aee 100755 --- a/docs/symbols/src/kis-js_src_modules_event.js.html +++ b/docs/symbols/src/kis-js_src_modules_event.js.html @@ -21,136 +21,176 @@ 14 { 15 var i, len; 16 - 17 if(sel === undefined) - 18 { - 19 return null; - 20 } + 17 // Multiple events? Run recursively! + 18 if ( ! event.match(/^([\w\-]+)$/)) + 19 { + 20 event = event.split(" "); 21 - 22 // Multiple events? Run recursively! - 23 if ( ! event.match(/^([\w\-]+)$/)) - 24 { - 25 event = event.split(" "); - 26 - 27 len = event.length; + 22 len = event.length; + 23 + 24 for (i = 0; i < len; i++) + 25 { + 26 _add_remove(sel, event[i], callback, add); + 27 } 28 - 29 for (i = 0; i < len; i++) - 30 { - 31 _add_remove(sel, event[i], callback, add); - 32 } - 33 - 34 return; - 35 } - 36 - 37 // Bind the event - 38 (add === true) - 39 ? sel.addEventListener(event, callback, false) - 40 : sel.removeEventListener(event, callback, false); - 41 }; + 29 return; + 30 } + 31 + 32 // Bind the event + 33 (add === true) + 34 ? sel.addEventListener(event, callback, false) + 35 : sel.removeEventListener(event, callback, false); + 36 }; + 37 + 38 _attach_delegate = function(sel, target, event, callback) + 39 { + 40 // attach the listener to the parent object + 41 _add_remove(sel, event, function(e){ 42 - 43 _attach_delegate = function(sel, target, event, callback) - 44 { - 45 // attach the listener to the parent object - 46 _add_remove(sel, event, function(e){ + 43 var elem, t; + 44 + 45 // Get the live version of the target selector + 46 t = $_.$(target, sel); 47 - 48 var elem, t; - 49 - 50 // Get the live version of the target selector - 51 t = $_.$(target, sel); - 52 - 53 // Check each element to see if it matches the target - 54 for(elem in t) - 55 { - 56 // Fire target callback when event bubbles from target - 57 if(e.target == t[elem]) - 58 { - 59 // Trigger the event callback - 60 callback.call(t[elem], e); + 48 // Check each element to see if it matches the target + 49 for(elem in t) + 50 { + 51 // Fire target callback when event bubbles from target + 52 if(e.target == t[elem]) + 53 { + 54 // Trigger the event callback + 55 callback.call(t[elem], e); + 56 + 57 // Stop event propegation + 58 e.stopPropagation(); + 59 } + 60 } 61 - 62 // Stop event propegation - 63 e.stopPropagation(); - 64 } - 65 } + 62 }, true); + 63 }; + 64 + 65 // -------------------------------------------------------------------------- 66 - 67 }, true); - 68 }; - 69 - 70 // -------------------------------------------------------------------------- - 71 - 72 /** - 73 * Event Listener module - 74 * - 75 * @namespace - 76 * @name event - 77 * @memberOf $_ - 78 */ - 79 e = { - 80 /** - 81 * Adds an event that returns a callback when triggered on the selected - 82 * event and selector - 83 * - 84 * @memberOf $_.event - 85 * @name add - 86 * @function - 87 * @example Eg. $_("#selector").event.add("click", do_something()); - 88 * @param string event - 89 * @param function callback - 90 */ - 91 add: function (event, callback) - 92 { - 93 $_.each(function(e){ - 94 _add_remove(e, event, callback, true); - 95 }); - 96 }, - 97 /** - 98 * Removes an event bound the the specified selector, event type, and callback - 99 * -100 * @memberOf $_.event -101 * @name remove -102 * @function -103 * @example Eg. $_("#selector").event.remove("click", do_something()); -104 * @param string event -105 * @param string callback -106 */ -107 remove: function (event, callback) -108 { -109 $_.each(function(e){ -110 _add_remove(e, event, callback, false); -111 }); -112 }, -113 /** -114 * Binds a persistent event to the document -115 * -116 * @memberOf $_.event -117 * @name live -118 * @function -119 * @example Eg. $_.event.live(".button", "click", do_something()); -120 * @param string target -121 * @param string event -122 * @param function callback -123 */ -124 live: function (target, event, callback) -125 { -126 _attach_delegate(document.documentElement, target, event, callback); -127 }, -128 /** -129 * Binds an event to a parent object -130 * -131 * @memberOf $_.event -132 * @name delegate -133 * @function -134 * @example Eg. $_("#parent").delegate(".button", "click", do_something()); -135 * @param string target -136 * @param string event_type -137 * @param function callback -138 */ -139 delegate: function (target, event, callback) -140 { -141 $_.each(function(e){ -142 _attach_delegate(e, target, event, callback); -143 }); -144 } -145 }; -146 -147 $_.ext('event', e); -148 -149 }()); \ No newline at end of file + 67 /** + 68 * Event Listener module + 69 * + 70 * @namespace + 71 * @name event + 72 * @memberOf $_ + 73 */ + 74 e = { + 75 /** + 76 * Create a custom event + 77 * + 78 * @memberOf $_.event + 79 * @name create + 80 * @function + 81 * @example Eg. var event = $_("#selector").event.create('foo', {}); + 82 * @param string name + 83 * @param [object] data + 84 * @return object + 85 */ + 86 create: function(name, data) + 87 { + 88 // Do a terrible browser-sniffic hack because I don't know of a good + 89 // feature test + 90 if (/MSIE|Trident/i.test(navigator.userAgent)) + 91 { + 92 // Okay, I guess we have to do this the hard way... :( + 93 // Microsoft, your browser still sucks + 94 var e = document.createEvent('CustomEvent'); + 95 e.initCustomEvent(name, true, true, data); + 96 + 97 return e; + 98 } + 99 else +100 { +101 return new CustomEvent(name, data); +102 } +103 }, +104 /** +105 * Adds an event that returns a callback when triggered on the selected +106 * event and selector +107 * +108 * @memberOf $_.event +109 * @name add +110 * @function +111 * @example Eg. $_("#selector").event.add("click", do_something()); +112 * @param string event +113 * @param function callback +114 */ +115 add: function (event, callback) +116 { +117 $_.each(function(e){ +118 _add_remove(e, event, callback, true); +119 }); +120 }, +121 /** +122 * Removes an event bound the the specified selector, event type, and callback +123 * +124 * @memberOf $_.event +125 * @name remove +126 * @function +127 * @example Eg. $_("#selector").event.remove("click", do_something()); +128 * @param string event +129 * @param string callback +130 */ +131 remove: function (event, callback) +132 { +133 $_.each(function(e){ +134 _add_remove(e, event, callback, false); +135 }); +136 }, +137 /** +138 * Binds a persistent event to the document +139 * +140 * @memberOf $_.event +141 * @name live +142 * @function +143 * @example Eg. $_.event.live(".button", "click", do_something()); +144 * @param string target +145 * @param string event +146 * @param function callback +147 */ +148 live: function (target, event, callback) +149 { +150 _attach_delegate(document.documentElement, target, event, callback); +151 }, +152 /** +153 * Binds an event to a parent object +154 * +155 * @memberOf $_.event +156 * @name delegate +157 * @function +158 * @example Eg. $_("#parent").delegate(".button", "click", do_something()); +159 * @param string target +160 * @param string event_type +161 * @param function callback +162 */ +163 delegate: function (target, event, callback) +164 { +165 $_.each(function(e){ +166 _attach_delegate(e, target, event, callback); +167 }); +168 }, +169 /** +170 * Trigger an event to fire +171 * +172 * @memberOf $_.event +173 * @name trigger +174 * @function +175 * @example Eg. $_("#my_id").trigger('click'); +176 * @param string target +177 * @param object event +178 * @return bool +179 */ +180 trigger: function(event) +181 { +182 var target = this.el; +183 return target.dispatchEvent(event); +184 } +185 }; +186 +187 $_.ext('event', e); +188 +189 }()); \ No newline at end of file diff --git a/kis-all.js b/kis-all.js index 50fc61d..3a5ca58 100755 --- a/kis-all.js +++ b/kis-all.js @@ -497,14 +497,7 @@ if(typeof document!=="undefined"&&!("classList" in document.createElement("a"))) */ append: function(htm) { - if(document.insertAdjacentHTML !== undefined) - { - this.el.insertAdjacentHTML('beforeend', htm); - } - else - { - this.el.innerHTML += htm; - } + this.el.insertAdjacentHTML('beforeend', htm); }, /** * Adds to the innerHTML of the selected element, before the current children @@ -516,14 +509,7 @@ if(typeof document!=="undefined"&&!("classList" in document.createElement("a"))) */ prepend: function(htm) { - if(document.insertAdjacentHTML !== undefined) - { - this.el.insertAdjacentHTML('afterbegin', htm); - } - else - { - this.el.innerHTML = htm + this.el.innerHTML; - } + this.el.insertAdjacentHTML('afterbegin', htm); }, /** * Sets or gets the innerHTML propery of the element(s) passed @@ -623,7 +609,7 @@ if(typeof document!=="undefined"&&!("classList" in document.createElement("a"))) for (name in data) { - if ( ! data.hasOwnProperty(name) || typeof data[name] === "function") + if ( ! data.hasOwnProperty(name) || $_.type(data[name]) === "function") { continue; } @@ -687,11 +673,6 @@ if(typeof document!=="undefined"&&!("classList" in document.createElement("a"))) { var i, len; - if(sel === undefined) - { - return null; - } - // Multiple events? Run recursively! if ( ! event.match(/^([\w\-]+)$/)) { @@ -750,6 +731,35 @@ if(typeof document!=="undefined"&&!("classList" in document.createElement("a"))) * @memberOf $_ */ e = { + /** + * Create a custom event + * + * @memberOf $_.event + * @name create + * @function + * @example Eg. var event = $_("#selector").event.create('foo', {}); + * @param string name + * @param [object] data + * @return object + */ + create: function(name, data) + { + // Do a terrible browser-sniffic hack because I don't know of a good + // feature test + if (/MSIE|Trident/i.test(navigator.userAgent)) + { + // Okay, I guess we have to do this the hard way... :( + // Microsoft, your browser still sucks + var e = document.createEvent('CustomEvent'); + e.initCustomEvent(name, true, true, data); + + return e; + } + else + { + return new CustomEvent(name, data); + } + }, /** * Adds an event that returns a callback when triggered on the selected * event and selector @@ -814,6 +824,22 @@ if(typeof document!=="undefined"&&!("classList" in document.createElement("a"))) $_.each(function(e){ _attach_delegate(e, target, event, callback); }); + }, + /** + * Trigger an event to fire + * + * @memberOf $_.event + * @name trigger + * @function + * @example Eg. $_("#my_id").trigger('click'); + * @param string target + * @param object event + * @return bool + */ + trigger: function(event) + { + var target = this.el; + return target.dispatchEvent(event); } }; @@ -940,364 +966,4 @@ if(typeof document!=="undefined"&&!("classList" in document.createElement("a"))) $_.ext('store', store); - -// -------------------------------------------------------------------------- - -/** - * Util Object - * - * Various object and string manipulation functions - * Note: these are based on similar phpjs functions: http://phpjs.org - */ - - - var reverse_key_sort = function(o) - { - //Define some variables - var keys = [], - num_keys = 0, - new_o = {}, - i; - - //Extract the keys - keys = u.object_keys(o); - - //Sort the keys - keys.sort(function (b, a) { - var aFloat = parseFloat(a), - bFloat = parseFloat(b), - aNumeric = aFloat + '' === a, - bNumeric = bFloat + '' === b; - - if (aNumeric && bNumeric) - { - return aFloat > bFloat ? 1 : aFloat < bFloat ? -1 : 0; - } - else if (aNumeric && !bNumeric) - { - return 1; - } - else if (!aNumeric && bNumeric) - { - return -1; - } - - return a > b ? 1 : a < b ? -1 : 0; - }); - - // cache object/array size - num_keys = keys.length; - - // Recreate the object/array - for(i=0; i < num_keys; i++) - { - new_o[keys[i]] = o[keys[i]]; - } - - return new_o; - }, - - /** - * String and object manipulation utilities - * - * @namespace - * @name util - * @memberOf $_ - */ - u = { - /** - * Retrieve the keys, or member names of an object - * - * @name object_keys - * @memberOf $_.util - * @function - * @param object - * @return array - * @type array - */ - object_keys: function(o) - { - var keys = [], - k; - - for(k in o) - { - if(o.hasOwnProperty(k)) - { - keys.push(k); - } - } - - return keys; - }, - /** - * Retrieves the values of an object, and returns - * them as an array - * - * @name object_values - * @memberOf $_.util - * @function - * @param object - * @return array - * @type array - */ - object_values: function(o) - { - var vals = [], - prop; - - for(prop in o) - { - vals.push(o[prop]); - } - - return vals; - }, - /** - * Creates an object, with the property names of the first array, - * and the values of the second. If objects are passed, the values - * of the object are used. If the arrays or objects passed are - * not the same size, the function will return false. - * - * @name array_combine - * @memberOf $_.util - * @function - * @param array/object keys - * @param array/object vals - * @return object - * @type object - */ - array_combine: function(keys, vals) - { - var new_object = {}, - num_keys, - i = 0; - - // Extract the keys or values if needed - if($_.type(keys) !== "array") - { - keys = this.object_values(keys); - } - if($_.type(vals) !== "array") - { - vals = this.object_values(vals); - } - - // cache the number of keys - num_keys = keys.length; - - if(num_keys !== vals.length) - { - return false; - } - - // Create and return the new object - for(i = 0; i < num_keys; i++) - { - new_object[keys[i]] = vals[i]; - } - - return new_object; - }, - /** - * Combines two or more objects/arrays. If the keys are numeric, the outputted - * object will have re-indexed keys. If a key/value pair exists in both objects, - * indentical values will be droped, but if a key exists with a different value, - * with the same key, the value in the second array will replace the value in the - * first - * - * @name object_merge - * @memberOf $_.util - * @function - * @param object [as many as you wish to combine] - * @type object - * @return object - */ - object_merge: function() - { - var args = Array.prototype.slice.call(arguments), - arg_len = args.length, - new_obj = {}, - arg, - iarg_len = 0, - i, - j, - x, - is_array = true; - - // Check for an array in the arguments - for(i=0; i < arg_len; i++) - { - if($_.type(args[i]) !== "array") - { - is_array = false; - break; - } - } - - // If all the arguments are javascript arrays - if(is_array) - { - new_obj = []; - // Let javascript do all the work! - for(i=0; i< arg_len; i++) - { - new_obj = new_obj.contact(args[i]); - } - - // Return early - return new_obj; - } - - // No, there's at least one object - for(i=0, x=0; i < arg_len; i++) - { - arg = args[i]; - - // If the argument is an array, add the array items as - // numeric object properties - if ($_.type(arg) == "array") - { - for (j=0, iarg_len= arg.length; j < iarg_len; j++) - { - new_obj[x++] = arg[j]; - } - } - else - { - for (j in arg) - { - if(arg.hasOwnProperty(j)) - { - // If the key is numeric, add the property with - // a numeric key - if(parseInt(j, 10) + '' === j) - { - new_obj[x++] = arg[j]; - } - else - { - new_obj[j] = arg[j]; - } - } - } - } - } - - return new_obj; - }, - /** - * Replaces sections of strings in a greedy fashion, - * starting with the longest replace pairs first. Accepts - * one replace pair as two parameters, or an object, with - * from => to replacements as key/value pairs - * - * @name str_trans - * @memberOf $_.util - * @function - * @param string input_string - * @param mixed from (string)/replace pairs (object) - * @param [string] - * @return string - * @type string - */ - str_trans: function(str, from, to) - { - var froms = [], - tos = [], - ret = '', - match = false, - from_len = 0, - str_len = 0, - to_len = 0, - to_is_str = '', - from_is_str = '', - strx = '', - strw = '', - stry = '', - from_strx = '', - new_str = '', - f, - i, - j; - - //Replace pairs? add them to the internal arrays - if(typeof from === 'object') - { - // Sort the keys in descending order for better - // replacement functionality - from = reverse_key_sort(from); - - for(f in from) - { - if(from.hasOwnProperty(f)) - { - froms.push(f); - tos.push(from[f]); - } - } - - from = froms; - to = tos; - } - - //Go through the string, and replace characters as needed - str_len = str.length; - from_len = from.length; - to_len = to.length; - to_is_str = typeof to === 'string'; - from_is_str = typeof from === 'string'; - - for(i=0; i < str_len; i++) - { - match = false; - if(from_is_str) - { - strw = str.charAt(i-1); - strx = str.charAt(i); - stry = str.charAt(i+1); - for(j=0; j < from_len; j++) - { - if(strx == from.charAt(j)) - { - match = true; - break; - } - } - } - else - { - for(j=0; j < from_len; j++) - { - if(str.substr(i, from[j].length) == from[j]) - { - match = true; - - //Go past the current match - i = (i + from[j].length) -1; - break; - - } - } - } - - if(match) - { - new_str += (to_is_str) ? to.charAt(j) : to[j]; - } - else - { - new_str += str.charAt(i); - } - } - - return new_str; - - } - - }; - - //Add it to the $_ object - $_.ext('util', u); - }($_)); \ No newline at end of file diff --git a/kis-lite-dom-min.js b/kis-lite-dom-min.js index b6ac510..4a7353d 100755 --- a/kis-lite-dom-min.js +++ b/kis-lite-dom-min.js @@ -1,14 +1,13 @@ (function(d){var f,g,c;f=function(a){c=a===d?f.el!==d?f.el:document.documentElement:g(a);f.prototype.el=c;a=Object.create(f);for(var b in a)"object"===typeof a[b]&&(a[b].el=c);a.el=c;return a};g=function(a,b){var c;if("string"!=typeof a||a===d)return a;c=null!=b&&1===b.nodeType?b:document;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);c=c.querySelectorAll(a);return 1===c.length?c[0]:c};f.ext=function(a,b){b.el=c;f[a]=b};f.ext("each",function(a){c.length!==d&&c!==window? [].forEach.call(c,a):a.call(c,c)});f.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()};f=window.$_=window.$_||f;f.$=g})();"undefined"===typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g,"")});"undefined"===typeof Array.isArray&&(Array.isArray=function(d){return"[object Array]"===Object.prototype.toString.apply(d)}); (function(d){var f={_do:function(f,c,a,b,h){var e=new XMLHttpRequest;a===d&&(a=function(){});h=h?"POST":"GET";"GET"===h&&(f+=f.match(/\?/)?this._serialize(c):"?"+this._serialize(c));e.open(h,f);e.onreadystatechange=function(){4===e.readyState&&(200===e.status?a.call(e.responseText,e.responseText):b!==d&&b.call(e.status,e.status))};"POST"===h?(e.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),e.send(this._serialize(c))):e.send(null)},_serialize:function(d){var c,a,b=[];for(c in d)d.hasOwnProperty(c)&& -"function"!==typeof 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,!1)});$_.ext("post",function(d,c,a,b){f._do(d,c,a,b,!0)})})(); -(function(d){var f,g;f=function(c,a,b,h){var e,k;if(c===d)return null;if(a.match(/^([\w\-]+)$/))!0===h?c.addEventListener(a,b,!1):c.removeEventListener(a,b,!1);else for(a=a.split(" "),k=a.length,e=0;ee?1:ca?1:b bFloat ? 1 : aFloat < bFloat ? -1 : 0; - } - else if (aNumeric && !bNumeric) - { - return 1; - } - else if (!aNumeric && bNumeric) - { - return -1; - } - - return a > b ? 1 : a < b ? -1 : 0; - }); - - // cache object/array size - num_keys = keys.length; - - // Recreate the object/array - for(i=0; i < num_keys; i++) - { - new_o[keys[i]] = o[keys[i]]; - } - - return new_o; - }, - - /** - * String and object manipulation utilities - * - * @namespace - * @name util - * @memberOf $_ - */ - u = { - /** - * Retrieve the keys, or member names of an object - * - * @name object_keys - * @memberOf $_.util - * @function - * @param object - * @return array - * @type array - */ - object_keys: function(o) - { - var keys = [], - k; - - for(k in o) - { - if(o.hasOwnProperty(k)) - { - keys.push(k); - } - } - - return keys; - }, - /** - * Retrieves the values of an object, and returns - * them as an array - * - * @name object_values - * @memberOf $_.util - * @function - * @param object - * @return array - * @type array - */ - object_values: function(o) - { - var vals = [], - prop; - - for(prop in o) - { - vals.push(o[prop]); - } - - return vals; - }, - /** - * Creates an object, with the property names of the first array, - * and the values of the second. If objects are passed, the values - * of the object are used. If the arrays or objects passed are - * not the same size, the function will return false. - * - * @name array_combine - * @memberOf $_.util - * @function - * @param array/object keys - * @param array/object vals - * @return object - * @type object - */ - array_combine: function(keys, vals) - { - var new_object = {}, - num_keys, - i = 0; - - // Extract the keys or values if needed - if($_.type(keys) !== "array") - { - keys = this.object_values(keys); - } - if($_.type(vals) !== "array") - { - vals = this.object_values(vals); - } - - // cache the number of keys - num_keys = keys.length; - - if(num_keys !== vals.length) - { - return false; - } - - // Create and return the new object - for(i = 0; i < num_keys; i++) - { - new_object[keys[i]] = vals[i]; - } - - return new_object; - }, - /** - * Combines two or more objects/arrays. If the keys are numeric, the outputted - * object will have re-indexed keys. If a key/value pair exists in both objects, - * indentical values will be droped, but if a key exists with a different value, - * with the same key, the value in the second array will replace the value in the - * first - * - * @name object_merge - * @memberOf $_.util - * @function - * @param object [as many as you wish to combine] - * @type object - * @return object - */ - object_merge: function() - { - var args = Array.prototype.slice.call(arguments), - arg_len = args.length, - new_obj = {}, - arg, - iarg_len = 0, - i, - j, - x, - is_array = true; - - // Check for an array in the arguments - for(i=0; i < arg_len; i++) - { - if($_.type(args[i]) !== "array") - { - is_array = false; - break; - } - } - - // If all the arguments are javascript arrays - if(is_array) - { - new_obj = []; - // Let javascript do all the work! - for(i=0; i< arg_len; i++) - { - new_obj = new_obj.contact(args[i]); - } - - // Return early - return new_obj; - } - - // No, there's at least one object - for(i=0, x=0; i < arg_len; i++) - { - arg = args[i]; - - // If the argument is an array, add the array items as - // numeric object properties - if ($_.type(arg) == "array") - { - for (j=0, iarg_len= arg.length; j < iarg_len; j++) - { - new_obj[x++] = arg[j]; - } - } - else - { - for (j in arg) - { - if(arg.hasOwnProperty(j)) - { - // If the key is numeric, add the property with - // a numeric key - if(parseInt(j, 10) + '' === j) - { - new_obj[x++] = arg[j]; - } - else - { - new_obj[j] = arg[j]; - } - } - } - } - } - - return new_obj; - }, - /** - * Replaces sections of strings in a greedy fashion, - * starting with the longest replace pairs first. Accepts - * one replace pair as two parameters, or an object, with - * from => to replacements as key/value pairs - * - * @name str_trans - * @memberOf $_.util - * @function - * @param string input_string - * @param mixed from (string)/replace pairs (object) - * @param [string] - * @return string - * @type string - */ - str_trans: function(str, from, to) - { - var froms = [], - tos = [], - ret = '', - match = false, - from_len = 0, - str_len = 0, - to_len = 0, - to_is_str = '', - from_is_str = '', - strx = '', - strw = '', - stry = '', - from_strx = '', - new_str = '', - f, - i, - j; - - //Replace pairs? add them to the internal arrays - if(typeof from === 'object') - { - // Sort the keys in descending order for better - // replacement functionality - from = reverse_key_sort(from); - - for(f in from) - { - if(from.hasOwnProperty(f)) - { - froms.push(f); - tos.push(from[f]); - } - } - - from = froms; - to = tos; - } - - //Go through the string, and replace characters as needed - str_len = str.length; - from_len = from.length; - to_len = to.length; - to_is_str = typeof to === 'string'; - from_is_str = typeof from === 'string'; - - for(i=0; i < str_len; i++) - { - match = false; - if(from_is_str) - { - strw = str.charAt(i-1); - strx = str.charAt(i); - stry = str.charAt(i+1); - for(j=0; j < from_len; j++) - { - if(strx == from.charAt(j)) - { - match = true; - break; - } - } - } - else - { - for(j=0; j < from_len; j++) - { - if(str.substr(i, from[j].length) == from[j]) - { - match = true; - - //Go past the current match - i = (i + from[j].length) -1; - break; - - } - } - } - - if(match) - { - new_str += (to_is_str) ? to.charAt(j) : to[j]; - } - else - { - new_str += str.charAt(i); - } - } - - return new_str; - - } - - }; - - //Add it to the $_ object - $_.ext('util', u); -}()); \ No newline at end of file diff --git a/tests/ajax.php b/tests/ajax.php new file mode 100644 index 0000000..c0d0fd1 --- /dev/null +++ b/tests/ajax.php @@ -0,0 +1,37 @@ + - @@ -33,6 +32,5 @@ - \ No newline at end of file diff --git a/tests/tests/ajax.js b/tests/tests/ajax.js index d802013..3411870 100755 --- a/tests/tests/ajax.js +++ b/tests/tests/ajax.js @@ -9,4 +9,44 @@ 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("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("Bad request", function() { + $_.get("ajax.php?bad", {}, undefined, function(res) { + ok(res, "Bad response"); + equal(res, 401, "Passed value is error code"); + start(); + }); + }); + }()); \ No newline at end of file diff --git a/tests/tests/core.js b/tests/tests/core.js index 63441bc..3481fcf 100755 --- a/tests/tests/core.js +++ b/tests/tests/core.js @@ -82,6 +82,6 @@ ok($_().event, "Event module"); ok($_.store, "Local Storage module"); ok($_().dom, "Dom manipulation module"); - ok($_.util, "Utilities module"); + ok($_.get, "Ajaz module"); }); }()); \ No newline at end of file diff --git a/tests/tests/dom.js b/tests/tests/dom.js index 21a1fad..04974c5 100755 --- a/tests/tests/dom.js +++ b/tests/tests/dom.js @@ -53,7 +53,7 @@ }); test("Attr", function(){ - expect(2); + expect(3); var $test = $_("section"); var ele = $test.el; @@ -63,6 +63,8 @@ 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("CSS", function(){ diff --git a/tests/tests/event.js b/tests/tests/event.js index 98d788c..df1e447 100755 --- a/tests/tests/event.js +++ b/tests/tests/event.js @@ -1,18 +1,75 @@ (function(){ "use strict"; - module("events"); + 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(4); + 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"); }); - test("Adding Events", function() { - expect(0); + asyncTest("Adding/Triggering Event Listener", function() { + expect(5); + + var callback = function(e) { + ok(e, "Event was added"); + ok(e, "Event was triggered"); + start(); + }; + + $_("#qunit").event.add('foo', callback); + var x = $_("#qunit").event.trigger(this.foo); + ok(x, "Event was not canceled"); + }); + + asyncTest("Delegated Event", function() { + var callback = function(e) { + ok(e, "Delegated event was triggered"); + start(); + } + + $_.event.delegate('.nephew', 'foo', callback); + var x = $_.event.trigger(this.foo); + ok(x, "Event was not canceled"); + + }); + + asyncTest("Live Event", function() { + var callback = function(e) { + ok(e, "Live event was triggered"); + start(); + } + + $_.event.live('.child', 'foo', callback); + $_.event.trigger(this.foo); + }); + + asyncTest("Multiple Events", function() { + var callback = function(e) { + ok(e, "An event was triggered"); + start(); + } + + $_("#qunit").event.add('foo bar', callback); + + $_.event.trigger(this.bar); + }); }()); \ No newline at end of file diff --git a/tests/tests/util.js b/tests/tests/util.js deleted file mode 100755 index 2071e15..0000000 --- a/tests/tests/util.js +++ /dev/null @@ -1,150 +0,0 @@ -(function(){ - "use strict"; - - module("util"); - - test("Object keys", function(){ - expect(1); - - var test_o = { - "x": 2, - "a": 4, - "q": 3, - "r": 6 - }; - - var test_keys = ["x", "a", "q", "r"]; - - deepEqual($_.util.object_keys(test_o), test_keys, "Retrieves object keys correctly"); - - }); - - test("Object values", function(){ - expect(1); - - var test_o = { - "x": 2, - "a": 4, - "q": 3, - "r": 6, - "p": "q" - }; - - var test_values = [2,4,3,6,"q"]; - - deepEqual($_.util.object_values(test_o), test_values, "Retrieves object values correctly"); - - }); - - test("Array combine", function(){ - - expect(3); - - var keys_5 = ["a", "u", "i", "e", "o"]; - var keys_obj = { - "x": 2, - "a": 4, - "q": 3, - "r": 1, - "p": "q" - }; - - var vals_5 = [1, 5, 3, 2, 4]; - var vals_4 = [3, 6, 2, 7]; - - var obj_combined = { - 2:1, - 4:5, - 3:3, - 1:2, - "q":4 - }; - - var combined = { - "a":1, - "u":5, - "i":3, - "e":2, - "o":4 - }; - - - equal($_.util.array_combine(keys_5, vals_4), false, "Can't combine arrays of different sizes"); - deepEqual($_.util.array_combine(keys_obj, vals_5), obj_combined, "Combine with keys as object"); - deepEqual($_.util.array_combine(keys_5, vals_5), combined, "Properly combines arrays"); - - }); - - /*test("Reverse Key Sort", function(){ - expect(2); - - var test_o = { - "x": 2, - "a": 4, - "q": 3, - "r": 6 - }; - - var test_sorted = { - "x": 2, - "r": 6, - "q": 3, - "a": 4 - }; - - var test_array = [7, 2, 6, 3]; - var test_array_sorted = [3, 6, 2, 7]; - - deepEqual($_.util.reverse_key_sort(test_o), test_sorted, "Object sort"); - deepEqual($_.util.object_values($_.util.reverse_key_sort(test_array)), test_array_sorted, "Array Sort"); - });*/ - - test("Object Merge", function(){ - expect(2); - - var arr1 = { - "color": "red", - 0: 2, - 1: 4 - }, - arr2 = { - 0: "a", - 1: "b", - "color": "green", - "shape": "trapezoid", - 2: 4 - }, - res1 = { - "color": "green", - 0: 2, - 1: 4, - 2: "a", - 3: "b", - "shape": "trapezoid", - 4: 4 - }, - arr3 = [], - arr4 = { - 1:'value', - }, - res2 = {0:'value'}; - - deepEqual($_.util.object_merge(arr1, arr2), res1, "Merge objects with numeric and test keys"); - deepEqual($_.util.object_merge(arr3, arr4), res2, "Merged object has reordered keys"); - - }); - - test("String translate", function(){ - var test_str = "chotto", - test_replace = { - cho: 'ちょ', - to: 'と' - }, - test_res = "ちょtと", - $trans = {'hello' : 'hi', 'hi' : 'hello'}; - - equal($_.util.str_trans(test_str, test_replace), test_res, "Correctly replaces substrings from replace pairs"); - equal($_.util.str_trans("hi all, I said hello", $trans), 'hello all, I said hi', "Correctly replaces substrings from scalar pair"); - }); - -}()); \ No newline at end of file