jqMobi Javascript Frameworks Cheat Sheet
jqMobi is a Javascript framework targeted at HTML5 browsers
It is comprised of three parts: jqMobi (a blazingly fast query selector library that supports W3C queries),
jqUi (a UI/UX library for mobile applications in a webkit browser), and jqPlugins (plugins for mobile applications in a webkit browser).
jq.mobi.min.js - a blazingly fast query selector tool
that is optimized for HTML5 browsers
jq.web.min.js - plugins for mobile applications in a
webkit browser that can be used for AppMobi and
general mobile web development.
Consists of:
jq.alphatable, jq.carousel, jq.css3animate, jq.drawer,
jq.passwordBox, jq.swipeListener, jq.scroller, jq.selectBox, and
jq.template
jq.ui.min.js – UI/UX framework for building jqMobi
mobile apps targeted at the Webkit browser
comprised of css3animate, passwordBox, scroller, and selectBox
components of jqPlugins, plus:
Fixed header bar, Auto scrolling content panels, and
an optional navbar to segment your application
Download the jqMobi Frameworks
https://github.com/appmobi/jQ.Mobi
To use jqMobi in an application, Include the following script tag in your
html file:
<script type="text/javascript" charset="utf-8" src="jq.mobi.min.js"></script>
To use/include all jqPlugins in an application, include the following script
tag in your html file:
<script type="text/javascript" charset="utf-8" src="jq.web.min.js"></script>
You can also include individual plugins if desired, for example:
<script type="text/javascript" charset="utf-8" src="plugins/jq.scroller.js"></script>
To include jqUi in your application, add the script tag and link tag:
<script type="text/javascript" charset="utf-8" src="ui/jq.ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="jq.ui.css" />
jqMobi - Query selector library
To use jqMobi include thefollowing script tag in your html file:
<script src="jq.mobi.min.js"></script>
This creates two objects you can work with. It will NOT override a pre-existing $
object.
$("#main")
jq("#main")
Query Selector
W3C spec'ed queries are supported. The following can be done:
$("input[type='text']")
The following is NOT supported by the browsers:
$("input:text")
In some functions, an additional selector can be used. This can be a string, array, or
a jqMobi object. We currently do not support functions.
Syntax:
Basic call
$("#id").hide()
A Dom element, selector, list of nodes, or HTML string can be specified.
$("span").bind("click",function(){console.log("clicked");}); // -> find all
span elements and attach a click event
An HTML string can be passed and it will create the object for you.
var myDiv=$("<div id='foo'>") //Creates a div object and returns it
jqMobi Ajax calls
.get(url,callback) //Makes an Ajax request to the URL and executes the
callback funtion with the result
.post(url,data,callback,dataType) //Makes an Ajax POST request to the URL with
the data and executes the callback with the result. An optional dataType can
be passed in, as some webservices require the header
.getJSON(url,data,callback) //Makes an ajax request with the data and executes
callback function passing in a JSON object from the Ajax response into the
callback function.
If more access is needed, the following can be used:
.ajax {
type:'POST', //defaults to GET
url:'/api/getinfo', //defaults to window.location
contentType:'application/json', //defaults to application/x-www-form-
urlencoded
headers:{},
dataType:'application/json', //defaults to text/html
data:{username:foo}, //Can be a Key/Value pair string or object. If it's
an object, $.serialize is called to turn it into a Key/Value pair string
success:function(data){}, //function to call on successful Ajax request
error:function(data){}, //function to call when an error exists in the Ajax
request
}
If the url contains the pattern =? in it, a jsonP request will be made. These can
ONLY be GET requests
Plugins
jqMobi is built with the extendability to add plugins. To create a plugin, extend the
$.fn object by passing a reference of the main jqMobi object
(function($){
$.fn['foo']=function(){
alert("bar");
}
})(jq);
jqMobi API functions
.map(elements,callback) //Executes callback function on each element
.each(elements,callback) //Iterate through elements and execute callback
.extend(target,{params}) //Extends an object with additional arguments
.isArray(data) //Returns true/false if data is an array
.isFunction(data) //Returns true/false if data is a function
.isObject(param) //Returns true/false if param is an object
.ready(callback) // Callback executed when DOMContentLoaded happens
.find(selector) // Find all chidlren that match the given selector
.html(['new html']) // Get/Set the elements .innerHTML
.text(['new text']) // Get/Set the elements .innerTEXT
.css('property',['value']) //Get/Set the elements css property to value
.empty() //Sets the elements .innerHTML to an empty string
.hide() //Sets the elements display css attribute to "none"
.show() //Sets the elements display css attribute to "block"
.toggle() //Toggles the elements display css attribute
.val(["value"]) //Get/Set the elements value property
.attr("attribute",["value"]) //Get/Set the elements attribute
.removeAttr("attribute") //Removes the attribute from the elements
.remove() //Remove an element from the Dom
.addClass("className") //Adds the css clas name to the selected elements
.removeClass("className") //Removes a css class from the selected elements
.hasClass("className",[_element]) //Checks to see if an element has a class
.append(element,[insert]) //Appends an element to the selected elements
.prepend(element) //Prepends an element to the selected elements
.insertBefore(target) //Inserts a collection before the target (adjacent)
.insertAfter(target) //Inserts a collection after the target (adjacent)
.get([index]) //Get raw DOM element based on index. () returns first element
.offset() //Calculates the first elements offset on the screen
.parent(selector) //Returns the parent nodes based off selector
.children(selector) //Returns the children of the elements
.siblings(selector) //Returns the siblings of the elemnts
.closest(selector,[context]) //Returns the closest element based off selector
.filter(selector) //Filters the elements based off selector
.not(selector) //Return all matches that do NOT match the selector
.data(key,[value])//Gets/Sets a data-* attribute for the param
.end() //Rolls back the jqMobi elements when filters were applied
.clone() //Clones the nodes in the collection
.size() //Returns the number of elements in a collection
.serialize(grouping) //Serializes a form into a query string
.jsonP(options) //Execute a jsonP call, allowing cross domain scripting
.bind("event",function(){}) //Binds a function to the event listener
.unbind("event",[callback]) //Unbinds a function to the event listener
.one("event",callback) //Bind event to each element - only executes once
.delegate(selector,"event",callback) //Delegate an event bassed off selector
.undelegate(selector,"event",[callback]) //Unbind an event registered through
delegate
.on("event",selector,callback) //Similar to .delegate()
.off("event",selector,[callback]) //Removes event listeners for .on()
.trigger("event",data) //Trigger an event and pass in optional data
.proxy(callback,context) //Creates a proxy function so the ‘this’ context can
be changed in the function
jqMobi Helper calls
.param() //Serialize a JSON object into KVP for a querystring
.parseJSON(string) //Backwards compatability JSON parsing call. Uses the
browsers native JSON parser
.parseXML(string) //Parses a string and returns a XML document version
.uuid //Utility function to create a pseudo GUID
.Event(type,props) //Creates a custom event to be used internally
jqMobi OS detectors
$.os.webkit //True if webkit found in the user agent
$.os.android //True if anroid useragent
$.os.ipad //True if iPad useragent
$.os.iphone //Tru if iPhone user agent
$.os.webos //True if WebOS detected
$.os.touchpad //True if WebOS and Touchpad user agent
$.os.ios //True if iPad or iPhone
$.os.blackberry //True if Blackberry PlayBook or OS >=6