Small (tiny) framework for Javascript. I wondered why I always called jQuery when I used relativly little of the functionality. So I created fw. If you need more than this, use jQuery :).
a string or an object.
If a string is passed it looks for two special chars the value is wrapped in: * "[selector]" : this will return an array even if only one result is found. * "" : this will return a new element of the specified type.
If there are no special chars it will use the selector and return an array for multiple results or a single dom element for a single result.
If an object is passed in it will attach all the functions to the object, this is only neccesary if you are working with an object that doesn't inherit from the Element object, such as XML or other elements.
- A single dom element
- An group of dom elements
- An object with new functions attached.
object to search and a selector string
This function is used by fw() and by Element.prototype.find(). Seperated for use on non Element objects, such as XML, and to reduce duplication of code.
This also normalizes a return from querySelectorAll into a real array, instead of the weird thing that is used because I like arrays.
This will use the querySelectorAll function on the _this object, so the fw() function uses it against document, whereas Element.prototype.find uses it agains the instance of the Element.
- A single dom element
- An group of dom elements
- An object with new functions attached.
a url to a script file.
This loads a script into the page without a reload
Nothing
two objects
This preforms a shallow merge of two objects.
for example
var obj1 = {
a: "a",
b: "b",
c: "c",
d: {
sub1: "sub1",
sub2: "sub2"
}
}
var obj2 = {
a: "1",
d: {
sub3: "sub3"
}
}
would return this:
{
a: "1",
b: "b",
c: "c",
d: {
sub3: "sub3"
}
}
the combined object.
####accepts a name and arguments
this publishes a custom event to be consumed by the subscribers, The arguments object is passed along to the subscribers.
true or false based on success.
a name and a function
this would accept a push from the "name" publish and pass the arguments to the function.
A token that is used to unsubscribe
a token (this comes from the subscribe function)
This will unsubscribe a function that has been subscribed to a publish
a true or false on successful unsubscribe.
event
preforms a stopPropogation (cross browser)
event
preforms a preventDefault (cross browser)
event
preforms a stopPropogation and preventDefault (cross browser)
event
This finds a key code note: currently the keypress is correct for every key and keyup and keydown are a little odd
an object {code: keyCode, char: character}
options object: { type: "GET or POST", url: "the url to ajax", data: "the data (not complete)", success: callback function for onSuccess, failure: callback function for onFailure, complete: callback function for onComplete }
This will preform a basic ajax call, will return a string of the file content.
an object: { val: string trimed to the inside of the body tag, raw: raw string, status: status code, statusText: status text (most likely an invaluable "ok") }
options object: { url: jsonp url, success: callback function for onSuccess }
this does this: 1.takes the jsonp service, 2.creates a function on window with a generated key, 3.defines a function with the key 3.calls fw.loadScript, 4.when loaded the function is called, calling your success callback 5.destroys the created function
xml string
converts the xml string to an XML document object.
xml document object
fw.xmlToJson ###Accepts xml document object, or xml string
Converts a xml string object (using fw.stringToXml) to json or takes an xml document object and converts to json
JS Object
length and AlphaNumeric flag
Produces a string, alpha or alphanumeric, of the specified length
string