Skip to content
avoidwork edited this page Apr 24, 2012 · 1 revision

client

Client (Browser) properties and methods for HTTP interactions

if ($.client.ie && $.client.version < 10) alert("You should try Chrome or Firefox");

client.allows

Method

Quick way to see if a URI allows a specific command

@param  {String} uri     URI to query
@param  {String} command Command to query for
@return {Boolean} True if the command is allowed

Prototype

String.prototype.allows

Example

if (uri.allows("DELETE")) uri.del(function () {}, function () {});

client.android

Property

Boolean indicating if the Client is Google Android based

client.blackberry

Property

Boolean indicating if the Client is RIM BlackBerry based

client.chrome

Property

Boolean indicating if the Client is Google Chrome

client.css3

Property

Boolean indicating if the Client has CSS3 support

Modernizr offers robust feature detection, which exceeds this boolean

client.del

Method

Makes a DELETE request to a URI

@param  {String}   uri     URI to query
@param  {Function} success A handler function to execute when an appropriate response been received
@param  {Function} failure [Optional] A handler function to execute on error
@param  {Object}   headers [Optional] Custom request headers (can be used to set withCredentials)
@return {String} URI to query

Prototype

String.prototype.del

Events

afterXHR        Fires after the XmlHttpRequest response has been handled
afterDelete     Fires after the XmlHttpRequest response has been handled, type specific
beforeXHR       Fires before the XmlHttpRequest is made
beforeDelete    Fires before the XmlHttpRequest is made, type specific
failedDelete    Fires on error
progressDelete  Fires on progress
receivedDelete  Fires on XHR readystate 2, clears the timeout only!
timeoutDelete   Fires 30s after XmlHttpRequest is made

Example

uri.del(function () {}, function () {});

client.expire

Property

Garbage collection timeout for cached URI responses; takes effect after the next run

client.firefox

Property

Boolean indicating if the Client is Mozilla Firefox

client.get

Method

Makes a GET request to a URI

@param  {String}   uri     URI to query
@param  {Function} success A handler function to execute when an appropriate response been received
@param  {Function} failure [Optional] A handler function to execute on error
@param  {Object}   headers [Optional] Custom request headers (can be used to set withCredentials)
@return {String} URI to query

Prototype

String.prototype.get

Events

afterXHR     Fires after the XmlHttpRequest response has been handled
afterGet     Fires after the XmlHttpRequest response has been handled, type specific
beforeXHR    Fires before the XmlHttpRequest is made
beforeGet    Fires before the XmlHttpRequest is made, type specific
failedGet    Fires on error
progressGet  Fires on progress
receivedGet  Fires on XHR readystate 2, clears the timeout only!
timeoutGet   Fires 30s after XmlHttpRequest is made

Example

uri.get(function () {}, function () {}, {Accepts: "application/json"});

client.headers

Method

Makes a HEAD request to a URI

@param  {String}   uri     URI to query
@param  {Function} success A handler function to execute when an appropriate response been received
@param  {Function} failure [Optional] A handler function to execute on error
@return {String} URI to query

Prototype

String.prototype.headers

Events

afterXHR      Fires after the XmlHttpRequest response has been handled
afterHead     Fires after the XmlHttpRequest response has been handled, type specific
beforeXHR     Fires before the XmlHttpRequest is made
beforeHead    Fires before the XmlHttpRequest is made, type specific
failedHead    Fires on error
progressHead  Fires on progress
receivedHead  Fires on XHR readystate 2, clears the timeout only!
timeoutHead   Fires 30s after XmlHttpRequest is made

Example

uri.headers(function (arg) { $.log(arg); }, function () {}); // Attempts to write the HTTP Headers (Object) to the console

client.ie

Property

Boolean indicating if the Client is Microsoft Internet Explorer

client.ios

Property

Boolean indicating if the Client is Apple iOS based

client.jsonp

Method

Creates a JSONP request

@param  {String}   uri     URI to request
@param  {Function} success A handler function to execute when an appropriate response been received
@param  {Function} failure [Optional] A handler function to execute on error
@param  {Mixed}    args    Custom JSONP handler parameter name, default is "callback"; or custom headers for GET request (CORS)
@return {String} URI to query

Prototype

String.prototype.jsonp

Events

beforeJSONP     Fires before the SCRIPT is made
afterJSONP      Fires after the SCRIPT is received
failedJSONP     Fires on error
timeoutJSONP    Fires 30s after SCRIPT is made

Example

uri.jsonp(function () {}, function () {});

client.linux

Property

Boolean indicating if the Client is Linux based

client.mobile

Property

Boolean indicating if the Client is a Mobile Phone

client.opera

Property

Boolean indicating if the Client is Opera

client.options

Method

Makes an OPTIONS request to a URI

@param  {String}   uri     URI to query
@param  {Function} success A handler function to execute when an appropriate response been received
@param  {Function} failure [Optional] A handler function to execute on error
@return {String} URI to query

Prototype

String.prototype.options

Events

afterXHR         Fires after the XmlHttpRequest response has been handled
afterOptions     Fires after the XmlHttpRequest response has been handled, type specific
beforeXHR        Fires before the XmlHttpRequest is made
beforeOptions    Fires before the XmlHttpRequest is made, type specific
failedOptions    Fires on error
progressOptions  Fires on progress
receivedOptions  Fires on XHR readystate 2, clears the timeout only!
timeoutOptions   Fires 30s after XmlHttpRequest is made

Example

uri.options(function () {}, function () {}, $.json.encode({}));

client.osx

Property

Boolean indicating if the Client is Apple OSX based

client.permissions

Method

Returns the permission of the cached URI

@param  {String} uri URI to query
@return {Object} Contains an Array of available commands, the permission bit and a map

Prototype

String.prototype.permissions

Events

var uriPermissions = uri.permissions();

client.playbook

Property

Boolean indicating if the Client is HP Playbook based

client.post

Method

Makes a POST request to a URI

@param  {String}   uri     URI to query
@param  {Function} success A handler function to execute when an appropriate response been received
@param  {Function} failure [Optional] A handler function to execute on error
@param  {Mixed}    args    Data to send with the request
@param  {Object}   headers [Optional] Custom request headers (can be used to set withCredentials)
@return {String} URI to query

Prototype

String.prototype.post

Events

afterXHR      Fires after the XmlHttpRequest response has been handled
afterPost     Fires after the XmlHttpRequest response has been handled, type specific
beforeXHR     Fires before the XmlHttpRequest is made
beforePost    Fires before the XmlHttpRequest is made, type specific
failedPost    Fires on error
progressPost  Fires on progress
receivedPost  Fires on XHR readystate 2, clears the timeout only!
timeoutPost   Fires 30s after XmlHttpRequest is made

Example

uri.post(function () {}, function () {}, $.json.encode({}), {Accept: "application/json", "Content-Type": "application/json"});

client.put

Method

Makes a PUT request to a URI

@param  {String}   uri     URI to query
@param  {Function} success A handler function to execute when an appropriate response been received
@param  {Function} failure [Optional] A handler function to execute on error
@param  {Mixed}    args    Data to send with the request
@param  {Object}   headers [Optional] Custom request headers (can be used to set withCredentials)
@return {String} URI to query

Prototype

String.prototype.put

Events

afterXHR     Fires after the XmlHttpRequest response has been handled
afterPut     Fires after the XmlHttpRequest response has been handled, type specific
beforeXHR    Fires before the XmlHttpRequest is made
beforePut    Fires before the XmlHttpRequest is made, type specific
failedPut    Fires on error
progressPut  Fires on progress
receivedPut  Fires on XHR readystate 2, clears the timeout only!
timeoutPut   Fires 30s after XmlHttpRequest is made

Example

uri.put(function () {}, function () {}, $.json.encode({}), {Accept: "application/json", "Content-Type": "application/json"});

client.safari

Property

Boolean indicating if the Client is Apple Safari

client.size

Property

Returns the visible area of the View

@return {Object} Describes the View {x: ?, y: ?}

Example

alert("You can see " + $.client.size.y + "px vertically");

client.tablet

Property

Boolean indicating if the Client is a Tablet

client.version

Property

Integer indicating the primary version of the Client

client.webos

Property

Boolean indicating if the Client is webOS based

client.windows

Property

Boolean indicating if the Client is Microsoft Windows based