Book Image

jQuery Mobile First Look

Book Image

jQuery Mobile First Look

Overview of this book

Table of Contents (17 chapters)
jQuery Mobile First Look
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

List of properties and methods


The jQuery Mobile framework has some exposed variables and methods we can configure and use in our applications. Here is a list of them and their functioning. Please note we've already had a look at many of them in the preceding chapters, and these are reported here for easier reference only.

$.mobile options

The following options can be accessed using $.mobile.[optionName]:

Variable

Type

Default value

activePageClass (Class used for "active" button state, from CSS framework).

String

ui-page-active

ajaxEnabled (Automatically handle clicks and form submissions through Ajax, when the destination page is internal).

Boolean

true

defaultTransition (Set default page transition – dialog transition cannot be changed and is 'pop').

String

slide

gradeA (Support conditions that must be met in order to proceed – default is a function checking for media query support or IE 7+).

Function

 

hashListeningEnabled (Automatically load and show pages based on location.hash).

Boolean

true

keyCode (Assigns key codes. There is no reason to change this, but it may come in use in certain applications).

Object

 

loadingMessage (Set the text that appears on page loading).

String

loading

nonHistorySelectors (Anchor links with a data-rel, or pages with a data-role, that match these selectors will be untrackable in history).

String

dialog

normalizeRegex (Compile the namespace normalization regex once).

string

/-([a-z])/g

ns (Namespace used framework-wide for data-attributes).

String

""

pageLoadErrorMessage (Error message that appears when an AJAX page request fails).

String

Error Loading Page

subPageUrlKey (Define the URL parameter used for referencing widget-generated sub-pages (that is, example.html?ui-page=pageid)).

String

ui-page

$.mobile methods

The following methods can be called with $.mobile.[methodname]:

  • addResolutionBreakPoints (int|array values): Add width breakpoints to the min/max width classes that are added to the HTML element. Pass any number or array of numbers to add to the resolution classes.

  • base.reset (string href): Set the generated BASE element's href attribute to a new page's base path.

  • base.set (): Set the generated BASE element's href attribute to a new page's base path.

  • browser.ie (): On-UA-based IE version check which allows for inclusion of IE 6+, including Windows Mobile 7.

  • changePage (string|array|obj to[, string transition[, bool reverse=false[, bool changeHash=true]]]): Programmatically change from one page to another using a transition effect if specified or $.mobile.defaultTransition). Contrary to default behavior, you can specify a reverse transition (reverse=true) and make sure not to update hash to the page's URL when page change is complete (changeHash=false).

  • The to argument is required and can be a string (URL), a jQuery object ($('#jqobj')), an object for sending form data, or an array specifying two page references ([from, to]) for transitioning from a known page (from) to a new one (to).

  • nsNormalize (string prop): Takes a data attribute property (prop), prepends the namespace, then camel cases the attribute string.

  • pageLoading ([bool Done=false]): Shows the page loading message if loading is not done.

  • silentScroll ([int yPos=0]): Scrolls to a particular Y position without triggering scroll event listeners.

  • url.getPrev (): Gets the previous page (in history) reference.

$.mobile.path methods

The following methods can be called using $.mobile.path.[methodName]:

  • clean (string url): Returns a URL path with the window's location protocol/hostname/pathname removed.

  • getFilePath (string path): Returns the substring of a filepath before the sub-page key, for making a server request.

  • hasProtocol (string url): Checks whether a URL has a different protocol (that is, ftp, mailto).

  • isExternal (string url): Checks whether a URL is external or under the same domain.

  • isEmbeddedPage (string url): Checks whether a URL refers to a page already in the DOM.

  • isRelative (string url): Checks whether a URL is relative.

  • makeAbsolute (string url): Prefixes a relative URL with the current path.

  • setOrigin (): Sets the path.origin property to the currently viewed URL path.

  • stripHash (string url): Returns the URL without an initial '#'.

$.mobile.path properties

The following property can be accessed using $.mobile.path.[propertyName]:

Property

Type

origin (location pathname from initial directory request.)

string

$.mobile.urlHistory methods

The following methods can be called using $.mobile.urlHistory.[methodName]:

  • clearForward () : Wipes URLs ahead of active index.

  • GetActive (): Gets the active page reference (not URL!).

  • getNext (): Gets the next page (in history) reference – if any.

$.mobile.urlHistory properties

The following properties can be accessed using $.mobile.urlHistory.[propertyname]:

Property

Type

activeIndex (Index of the active page in the stack)

int

stack (array of pages that are visited during a single page load. Each has a URL and optional transition)

array

$.support tests

A handful of properties and methods are available to use for testing whether the mobile browser/platform supports features jQuery Mobile makes use of. The following properties return either true or false if the corresponding feature is (respectively) supported or not:

  • $.support.boxShadow

  • $.support.cssPseudoElement

  • $.support.cssTransitions

  • $.support.dynamicBaseTag

  • $.support.eventCapture

  • $.support.mediaquery

  • $.support.orientation

  • $.support.pushState

  • $.support.scrollTop

  • $.support.touch

Button plugin

Button elements are covered in Chapters 6, Mobile Clicking: Buttons and Chapter 7, Mobile Clicking: Buttons.

The following options can be modified to match your own liking from the mobileinit event: $.mobile.button.prototype.options.[optionName]:

Option

Type

Default value

corners

Bool

true

icon

String

Null

iconpos

String (i.e. topleft)

Null

iconshadow

Bool

true

inline

Bool

Null

shadow

Bool

true

theme

String (i.e. 'a', 'b')

null

To disable a #button element: $('#button').button ('disable').

To enable a #button element: $('#button').button ('enable').

Check and radio boxes plugin

Checkboxes and radio buttons are covered in Chapter 7, Mobile Clicking: Buttons.

The following option can be modified to match your own liking from the mobileinit event: $.mobile.checkboxradio.prototype.options.[optionName]:

Option

Type

Default value

theme

String (i.e. 'a', 'b')

null

To disable a #radio element: $('#radio').checkboxradio ('disable') to enable a #radio element: $('#radio').checkboxradio ('enable').

If you make any changes to this kind of elements and/or their labels, you may want to refresh in order to update changes with $('#radio').checkboxradio ('refresh');

Collapsible plugin

Collapsible blocks are covered in Chapter 4.

The following options can be modified to match your own liking from the mobileinit event: $.mobile.collapsible.prototype.options.[optionName].

Option

Type

Default value

expandCueText

String

' click to expand contents'

collapseCueText

String

' click to collapse contents'

collapsed

Bool

false

heading

String

'>:header,>legend'

iconTheme

String

'd'

theme

String (i.e. 'a', 'b')

null

Dialog plugin

Dialogs are covered in Chapter 2, Organizing Content: Pages and Dialogs.

To close a #dialog element: $('#dialog').dialog ('close').

If you don't know the ID of the dialog you want to close, you can close it with $('.ui-dialog').dialog('close').

List view plugin

List views are covered in Chapter 8, Organizing Information: List Views.

The following options can be modified to match your own liking from the mobileinit event: $.mobile.listview.prototype.options.[optionName]:

Option

Type

Default value

countTheme

String (i.e. 'a', 'b')

'c'

dividerTheme

String (i.e. 'a', 'b')

'b'

headerTheme

String (i.e. 'a', 'b')

'b'

inset

Bool

false

splitIcon

String (i.e. 'a', 'b')

'arrow-r'

splitTheme

String (i.e. 'a', 'b')

'b'

theme

String (i.e. 'a', 'b')

'c'

We can access the refresh method with $('#listview').listview ('refresh').

Navbar plugin

Navigation bars are covered in Chapter 2, Organizing Content: Pages and Dialogs.

The following options can be modified to match your own liking from the mobileinit event: $.mobile.navbar.prototype.options.[optionName]:

Option

Type

Default value

iconpos

String (i.e. 'left')

'top'

grid

Bool

null

Page plugin

Pages are covered in Chapter 2, Organizing Content: Pages and Dialogs.

The following options can be modified to match your own liking from the mobileinit event: $.mobile.page.prototype.options.[optionName]:

Option

Type

Default value

addBackBtn

Bool

true

backBtnText

String

'Back'

degradeInputs

Object

 

keepNative

Bool

null

In the degradeInput object, we can choose whether we want the following elements to be degraded or not (they are all default to false, and range to "number"): color, date, datetime, datetime-local, email, month, number, range, search, tel, time, url, week.

Select plugin

Select menus are covered in Chapter 7, Mobile Clicking: Buttons.

The following options can be modified to match your own liking from the mobileinit event: $.mobile.select.prototype.options.[optionName]:

Option

Type

Default value

corners

Bool

true

closeText

String

'Close'

disabled

Bool

false

hidePlaceHolderMenuItems

Bool

true

icon

String

'arrow-d'

iconpos

String (i.e. left)

'right'

iconshadow

Bool

true

inline

Bool

null

menuPageTheme

String

'b'

nativeMenu

Bool

false

overlayTheme

String

'a'

shadow

Bool

true

theme

String (i.e. 'a', 'b')

null

You can programmatically open and close the menu of a #select element with $('#select').select ('open') and $('#select').select ('close').

Selects can be enabled/disabled using $('#select').select ('enable')/$('#select').select ('disable').

To update changes, use $('#select').select ('refresh').

Slider plugin

Slider elements are covered in Chapter 7, Mobile Clicking: Buttons.

The following options can be modified to match your own liking from the mobileinit event: $.mobile.slider.prototype.options.[optionName].

Option

Type

Default value

disabled

Bool

false

theme

String (i.e. 'a', 'b')

null

trackTheme

Bool

null

Sliders can be enabled ('enable'), disabled ('disable'), and updated ('refresh'): $('#slider').slider ('disable');

Text input plugin

Text inputs are covered in Chapter 7, Mobile Clicking: Buttons.

The following options can be modified to match your own liking from the mobileinit event: $.mobile.textinput.prototype.options.[optionName]:

Option

Type

Default value

theme

String (i.e. 'a', 'b')

null

Input elements (#text) can be enabled and disabled using the textinput plugin: $('#text').textinput ('enable').

JqmData: Whenever we need to check, or programmatically set or remove, a data attribute, we need to make use of the mobile-friendly versions of the data methods.

  • $.jqmData

  • $.jqmHasData

  • $.jqmRemoveData

These can be called either as a standalone function: $.jqmRemoveData (element, property) or directly on an element: $('#element').jqmRemoveData (property).

Please note these functions take care of adding the (eventual) namespace (ns) to the data attribute, so if our namespace is myns- and we need to modify a mydata data, the core $.data function will be passed the value myns-mydata.

data-* attributes: The following data attributes can be specified in the markup:

Attribute

Value(s)

Notes

Element(s)

data-role

button

Button element

 

collapsible

Collapsible element

content

Sub page element

controlgroup

Radio, checkbox or button parent element

fieldcontain

Fieldset element

footer

Sub page element

header

Sub page element

list-divider

Sub Listview element

listview

Listview element

navbar

Navigation bar element

page

Page element

slider

Slider element

none

Leave element untouched by jQuery Mobile

data-theme

a, b, c, d, e

Set theme

All

data-icon

See icon list below

Set button icon

Buttons

data-iconpos

bottomleft (default)topright

Place the icon accordingly

Elements with an icon

notext

Remove text (icon only)

data-collapsed

true

Collapsed by default

Collapsible block

data-type

horizontal

Show options horizontally

Control group

data-position

fixed

Stay at top/bottom

Headers

Footers

inline

Normal HTML behavior (default)

fullscreen

Only visible on screen tap

data-ajax

false

Same as rel=external

Links

data-direction

reverse

Reverse transition (without going back in history)

Links

data-rel

back

Mimic back button behavior

Links

dialog

Open link as a dialog

data-transition

fadeflippopslideslideupslidedown

Transition effect

Links

data-dividertheme

a, b, c, d, e

Set divider theme

List dividers

data-filter

true

Make a list filterable

Listviews

data-filter-placeholder

Default: "Filter items..."

Set input's placeholder text

Listviews

data-inset

true

Apply inset appearance to a listview

Listviews

data-split-icon

See icon list below

Set split icon

Listviews

data-split-theme

a, b, c, d, e

Set split theme

Listviews

data-placeholder

true

Option which serves as a placeholder in a select menu

Menu element

data-add-back-btn

true

Show back button (disabled by default)

Nav bars

data-back-btn-text

Default: "Back"

Configure back button text

Nav bars

data-url

Page location identifier

Pages

 

data-native-menu

false

Use custom menu on a specific select element

Select menus

Icons: The data-icon attribute accepts the following icons (apart from the custom ones):

Icon name

Icon

alert

arrow-d

arrow-l

arrow-r

arrow-u

back

check

delete

forward

gear

grid

home

info

minus

plus

refresh

search

star