(design of applications for mobile devices i) - vsb.czwiki.cs.vsb.cz/images/6/62/tamz-new-l4.pdf ·...

38
TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5 – UI

Upload: trinhhanh

Post on 04-Jun-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

TAMZ I(Design of Applications

for Mobile Devices I)

Lecture 4

jQuery MobileHTML5 – UI

Page 2: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

jQuery basics

Cheat sheet e.g.: http://oscarotero.com/jquery/Selector reference: http://www.w3schools.com/jquery/jquery_ref_selectors.asp

Page 3: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

Why are we discussing jQuery?

Lightweight library to simplify writing code in JavaScript and unify some concepts which require more complex use in standard JavaScriptWorks in all current major browsersFeatures of jQuery

Event handlingHTML/DOM manipulationCSS manipulationAJAXEffects and animationsBase for the jQuery Mobile framework…

Page 4: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

Basic Syntax of jQuery$(selector).action(arguments)

$ – indicates the jQuery framework use(selector) – a query indicating one or more HTML elements

Uses CSS selector syntax, Examples: $(document), $(this), $('*') – all , $("a"), $(".myclass"), $("#id1"), $("[attribute]"),$('[attribute="val"]'), $('[attribute1="val"][attribute2]') - both$("div, span") – <div> or <span>$("div > span") – <span> with parent <div>$("div + span") – <span> as the first sibling after <div>$("div ~ span") – all <span> elements sibling of <div>$("div span") – <span> with predecessor <div>

Attribute matches: [x o= y], o: ^ - starts with y, $ - ends with y, * - contains y as a substring, ~ - contains word y with spaces around, ! - does not have the attribute or y as valuePseudoselectors :inputType, :nav, :checked, :focus, :empty, :enabled, :disabled, :first, :last, :even, :odd, :visible, :hidden, :target, :parent, :contains(text), :has(element), :not(sel), …

action – what should be done with the element(s)

Page 5: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

Actions for Accessing HTML DOMFollowing actions can be used to get/set parts of the DOM:

Element content:html([cont]) – get 1st element's inner HTML or set it to conttext([cont]) – get combined text content or set it to contattr(name, [cont]) – get 1st attribute value or set it to cont

Properties and data and form element values:val([cont]) – get form item value(s) or set it (them) to contprop(name, [cont]) – get the first property or set it to contdata(name[, cont]) – get element's data-name attribute or set its cont. Checking for data presence: hasData(name)

Instead of cont, a function(index,currentcont) can be used.Use removeXXX(name) with Data, Val and Prop to erase it.

Following actions can be used to get info from DOM:index([e2]) – index of the 1st match in its siblings (or to e2)get([idx]) – get the DOM element from selector (@ index idx)each(function(idx, element)) – run function for each elementtoArray() – get array of DOM elements for the selector

Page 6: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

Actions for Accessing CSS/positionFollowing actions can be used to access UI information

Dimensions (similar to JavaScript DOM):height()/width() – element dimensions innerHeight()/innerWidth() – element dimensions + paddingouterHeight()/ outerWidth() – as above + margin + border

Offset against TL window corner or other parts of GUIoffset([coord]) – get or set the coordinates of elements relatively to the documentoffsetParent() – offset of the closest positioned ancestorposition() – coordinates of the 1st element rel. to its parentscrollLeft()/scrollTop() – scrollbar position for 1st element

Properties and data of CSScss(name[,cont]) – get CSS style property for the 1st element/set it to cont. Work with CSS classes: addClass(cl), removeClass(cl), hasClass(cl), toggleClass(cl) – disable ↔ enable classInstead of cont, a function(index,currentcont) can be used.

Page 7: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

Actions for working with ElementsCloning/copying element(s) (deep copy by default)

clone([withDataAndEvents ] [, deepWithDataAndEvents ])Inserting content

Around element: wrap() – around each, wrapAll() – around all elements (together), wrapInner() – around contentTo the end of the element(s): append(cont) – append content, sel1.appendTo(sel2) – append sel1 to sel2To the beginning of the element(s): prepend()/prependTo()Directly outside the element: after()/before() – content, insertAfter()/insertBefore() – supplied elements (see appendTo())

Removing elements from DOM: detach() – remove from DOM but keep for future use, empty() – remove child nodes, remove() – fully remove, unwrap() – remove parent element (opposite of wrap)Replacing: replaceWith(cont) – replace all elements with cont, new.replaceAll(old) – replace all matches of old with newDisplaying the content: show(), hide(), toggle()

Page 8: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

Working with document structure

Following filters are used for make the selector more precise. We may use them directly in selector (:nav earlier)

eq(index) → element on given index, slice(start[,end ]) → subset with index range, is(sel2) → true/false, not(sel2) → remove those matching sel2, has(descendant) → filtered set, filter(sel2) → filtered set, map(function(index, Element)) → pass each through function, first(), last()

Traversal: each(function(index, Element)), add(elements), end() – terminate previous traversal, addBack() – add previous set to current set, contents() - return children of element(s) Tree traversal: closest() – first ancestor matching for each element, find() – first descendant matching, children(), siblings()

parent(), parents() – all element's ancestors, parentsUntil(match)next() – first following sibling, nextAll() – all following siblings, nextUntil() – following siblings before condition is metprev(), prevAll(), prevUntil() - like next*, but for preceding siblings

Page 9: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

Event processingYou can register a handler or trigger following events

Browser Events: resize()/scroll() – GUI events Document Loading: ready() – execute code once document is fully loaded, holdReady() – delay ready() execution for now, load() – element fully loaded, unload() – page unloaded, left it

we will use different events in jQM, reflecting its lifecycle

General event handler (de)registrationbind()/unbind() – assign or remove event(s) at given element(s)on(events [,selector][, data ], handler(eventObject)) – register event handler executing each time the event occurs

e.g. $( "button" ).on( "click", notify );one(events [,selector][, data ], handler(eventObject)) – execute the handler only once and de-register it after the use.

e.g. $( "body" ).one( "click", "#foo", bar);off(events [,selector][,handler(eventObject)]) – deregister handlertrigger(event [,extraParameters ]) – trigger the event manually

triggerHandler() – like trigger(), but directly on the matched 1st element, default action is not performed.

Page 10: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

Event shortcuts

Several shortcuts exist for registering/triggering most common events (instead of on/trigger("xyz", …), we use xyz())

Formsfocus()/blur() – enter/leave the entry, focusin()/focusout() – works for parent elements as wellchange() – entry changedselect() – text selectedsubmit() – form submitted

Keyboard: keydown(), keypress(), keyup()Mouse

click(), dblclick()mousedown(), mouseup() mouseover(), mouseout()mouseenter(), mouseleave(), hover(hndl_ent, hndl_leave)mousemove()

Page 11: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

Event objectThe actual event object has following attributes/methods

Attributes:target – who initiated the event, currentTarget – where the event "bubbled", relatedTarget – other DOM element related to the event (e.g. some mouse events) type (e.g. click), timeStamp, data, namespace

$( "p" ).trigger( "test.something" ); → somethingwhich – key or button relevant to the eventresult – last returned result of event handler for the eventpageX, pageY – mouse event position relative to TL corner of the document

Methods:preventDefault() – prevent triggering of default action associated with the event (e.g. form submission)

isDefaultPrevented() – has preventDefault been used?stopPropagation() – ancestors will not receive the event,

stopImmediatePropagation() – also skips rest of handlersisPropagationStopped()/isImmediatePropagationStopped()

Page 12: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

jQuery core functionsShorthand used: array a, object o, collection (a or o)

$.each(collection, function(index, val)) – process all items$.extend([deep,] target_o, o1 [, … , on]) – merge objects$.merge(x,y) – merges two arrays into returned value$.inArray(val, a [, fromIdx]) – element index in a, or -1$.grep(a, funct(elem, index) [, invert_r]) – filters a with funct$.unique(a) – sorts arr. of DOM elements, drops duplicates $.now() – returns current time (number)$.parseHTML(data [,context] [,keepScripts]) – takes string with data, converts to DOM nodes in given context$.parseJSON() – converts JSON string to JS object$.parseXML() - converts string to XML document$.proxy(f, context) – returns new function for f with fixed ctxJS equivalents: $.trim(string), $.type(o) – extended typeof$.isArray(), $.isEmptyObject(), $.isFunction(), $.isNumeric(), $.isPlainObject() – created: new/{} , $.isWindow(), $.isXMLDoc()

Page 13: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

jQuery closing remarks

Actions on selectors may be chained, e.g.e.g. $("#menu li").css("border","2px solid silver") .filter(':odd').css("background-color","yellow") .end()

It is a good idea to distinguish jQuery variables from standard JavaScript ones, typically prefixing them with $

e.g. var $red = $(".redItems");

We have skipped the Callbacks, Deferred execution and AJAX parts of jQuery for now, they will be discussed in a separate lecture.

Page 14: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

HTML5

UI extensions

Examples e.g.: http://www.w3schools.com/html/html5_form_input_types.asp http://www.w3schools.com/html/html5_form_elements.asp

Resources: http://html5please.com/ http://caniuse.com/

Page 15: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

15

Form improvements

New elements:<datalist> element with pre-defined options for an input and user can enter his own as well<keygen> element with for public/private key pair generation<output> element for presenting results

New form element attributesautocomplete, novalidate

<input list="browsers">

<datalist id="browsers"> <option value="MSIE">

… <option value="Opera">

</datalist>

<form action="kg.asp" method="get">UID: <input type="text" name="uid">Encryption level: <keygen name="sec"><input type="submit"></form>

<output name="z" for="x y"></output>

Page 16: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

16

Input type improvements

New input types:colordate, datetime, timedatetime-local (no timezone)month, weekemailnumber, rangesearchtel, url

Syntactically “wrong” example: <input type="number" name="ex" step="2"min="1" max="10" value="3" form="form1" pattern="[0-9]+">

New input attributes:autocomplete, autofocusform, formtargetformaction, formenctype, formmethod, formnovalidateheight & width (only for image)list (datalist ID), placeholdermin, max & step (where applicable), pattern (regexp)multiple (email, file), required

Page 17: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

17

Gracefull degradation

Fallback in case that the browser does not support requested feature

All new HTML input types degrade to text Some elements provide fallback contentUnknown tags (without fallback)/attributes are ignored

Example – <datalist> element workaround<label for="source">How did you learn about VSB-TUO?</label><datalist id="sources"><select name="source"> <option>please choose...</option> <option value="advert">Advertisement</option> <option value="internet">Internet</option> <option>Other</option> </select>If other, please specify:</datalist><input id="source" name="source" list="sources">

Page 18: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

jQuery Mobile

UI extensions

Examples e.g.: http://www.w3schools.com/jquerymobile/ http://demos.jquerymobile.com/

Page 19: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

19

jQuery Mobile

Works (to a degree) on almost every platform with web browser (including desktop PCs)Progressive enhancement, graded support – jQM defines 3 grades to establish the functionality:

Grade A – full support with AJAX-based page transitions (iOS 3.2+, Android 2.1+, WP 7.5+, BlackBerry 6+, WebOS, FF Mobile 18, Opera Mobile 11.5+, MeeGo 1.2+/Tizen, Bada 2.0, Desktop: Chrome 16+, Safari 5+, FF 10+, IE 8+, Opera 10+) Grade B – enhanced experience without AJAX (BlackBerry 5, Opera Mini 7, Symbian^3, IE7)Grade C – basic HTML experience (IE < 7, IOS 3.x-, BlackBerry 4, Windows Mobile, old devices with HTML&JS support)

Page 20: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

20

jQuery Mobile properties

Web apps with look & feel as close to native as possiblePossibility to build native applications

Markup drivenTesting possible in many simulators & emulatorsMinimal code required to get up & runningPage elements defined in <div> tags

At least one data-role="page"Inside a page, at least (one) contentPage headers and footers data-role= "header"/ "footer"

Multiple pages in single HTML file, referencing through <a href="#pageid" …>

Page 21: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

21

New mobile events

Besides regular events, a set o specific events is created for jQM

Initialization (jQM finished loading): mobileinitTouch events: tap, taphold, swipe (swipeleft, swiperight)Screen: updatelayout, orientationchange Scroll: scrollstart, scrollstopPage-centred events – like any (mobile) platform, the jQM application (page) has its life-cycle, which has been highly simplified in 1.4 (many old events were moved to page container), with following page events remaining:

pagebeforecreate, pagecreatepagebeforechange, pagechangepageremove

Page 22: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

jQM page life cycle

pagebeforecreate

mobileinit

pagecreate

prepare GUI enhancements

pagebeforechange

pagechange

load page

load uncached/AJAX page

pagebeforechange

load cached page

page transition

pageremove

left dynamically-loaded external page DOMremoval

Page 23: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

New mobile JavaScript methods

Directly using $.mobile$.mobile.loading(x) – show (x is true) or hide loading indicator$.mobile.silentScroll(y) – scroll silently to position y (no event)URL manipulation methods

$.fn.jqmData(), $.fn.jqmRemoveData(), and $.fn.jqmHasData()$.fn.listview('refresh'), $.fn.selectmenu('refresh') …We can reference and change data attributes, dynamically create pages, etc.Most of the pre-1.4.0 functionality moved to pagecontainer widget:

Init: var x=$( ".selector" ).pagecontainer({ defaults: true });Methods: change(TO, options), getActivePage()load(URL, options)Events: beforeload → load → create → beforehide → beforeshow → beforetransition → transition → hide → showchangefailed, loadfailed Pagecont. events XXX accessible globally as pagecontainerXXX

Page 24: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

25

Code Examples

//transition to the "about us" page, pop transition$( ":mobile-pagecontainer" ).pagecontainer( "change", "ab/us.html",{transition: "pop"});

//transition to the "search results" page, using data from a form with an id of "search"$( ":mobile-pagecontainer" ).pagecontainer( "change","searchresults.php", { type: "post", data: $("form#search").serialize()});

$(document).one("#aboutPage", "pagecreate", function() { alert('Created "aboutPage" by jQuery Mobile!');});

//load the "about us" page into the DOM$( ":mobile-pagecontainer" ).pagecontainer( "load", "ab/us.html");

Page 25: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

26

AJAX Loading

Pages injected with a transition (where specified) on Grade A devices, otherwise loaded regularly.

Many transition templates, specified by (on later slide mentioned) data-transition

For loading into DOM without AJAX data-ajax="false"For linking to a non-mobile page on the same domain we use rel="external".

Links to different domains are detected automatically, and will trigger a regular load.

On page load failure, a jQM message is displayed instead of browser errorAJAX only works for pages in the same domain

Page 26: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

27

Additional GUI remarksRegular for elements are available

TextInputs, TextBoxes, Search boxes, Sliders (& Flip Switches), Control Groups (Checkboxes, Radiobuttons), Selects (i.e. popups), Collapsibles (Menus), Buttons Grouping of form elements where suitableSubmitting

Besides dialogs, we can also display popups, etc.You can't pass parameters between internal pages (but you can use plugins which implement this feature or share data with Storage, global variables, …)All elements can be themed through pre-defined themes, CSS3 (manually or generated through a ThemeRoller)

Page 27: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

jQuery Mobile – extra GUI

Besides the basic HTML form elements, already covered in the second lecture jQM offers several other features:

GridsLists (filterable)Collapsibles and their groups (accordions)Control groupsPopupsFlipswitches, range sliders Tabs, panelsTables with toggleable columns

Container for several fields with data-role="fieldcontain"Normal sized widgets can be made smaller by using data-mini="true"

Page 28: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

Page transitions (grade A devices)

Controlled by data-transition data attribute when changing page, opening dialog box, …

Reverse animation: data-direction="reverse"Transitions:

fadepopflipturnflowslide

slidefadeslideupslidedownnone

Page 29: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

Grids

Using class="ui-grid-X" (a-d), X+1 class="ui-block-Y" (a-e)<div class="ui-grid-a"> <div class="ui-block-a">A1</div> <div class="ui-block-b">B1</div> <div class="ui-block-a">A2</div> <div class="ui-block-b">B2</div></div>

By default the blocks of grid have the same width ui-grid-a: 50%, b: 33%, c: 25%, d: 20%

Multiple lines of blocks possible when repeating the classes (green/blue example above)Responsive design for small screens can be enabled by using class="ui-grid-X ui-responsive" instead

Page 30: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

ListsUse classic <ul> and <ol> tags with data-role="listview"

Read-only ones contain classic <li> itemsLinked contain <a href="…">…</a> inside of the <li>

Multiple <a> tags inside list item provide split buttonsBorder around the list view: data-inset="true" Filterable listview: data-filter="true" (to offer a hint, you can use data-filter-placeholder="…"

To start with hidden list: data-filter-reveal="true"

List item with data-role="list-divider" will insert a separatorOr you can use auto division with data-autodividers="true"

A <span class="ui-li-count">123</span> inside of the list item can be used to provide a count of results

<ul data-role="listview" data-inset="true" data-filter="true" data-autodividers="true" > <li>First <span class="ui-li-count">1</span></li> <li>Second</li></ul>

Page 31: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

CollapsiblesCollapsible will allow you to collapse/expand the content

Collapsible content: <div data-role="collapsible">…</div>The text in collapsed state is the content of the first <h1>-<h6> element inside of the collapsible.

For forms, use <legend> instead (and <fileldset> for content)Custom header rendering is also possible

By default + for expanding content and - for collapsingCan be changed, e.g. data-collapsed-icon="carat-d" and data-expanded-icon="carat-u"

Collapsed by default, opposite: data-collapsed="false"Dynamic collapsibles are also possible

Collapsible set (accordion) encloses several collapsiblesOnly one of them can be expanded at a time

<div data-role="collapsibleset">…</div>

Page 32: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

Control groups

Allow to group a set of buttons into a single blockAll buttons enclosed by <div data-role="controlgroup">Default control group is vertical, can be changed by using data-type="horizontal".Dynamic changes through JS also possibleIf used on <fieldset> instead of <div>, it can be used for radio buttons, checkboxes and selects

A horizontal layout is also possible:<form><fieldset data-role="controlgroup" data-type="horizontal"> <legend>Horizontal, mini sized:</legend> <input name="ch-h" id="ch-h-a" type="checkbox"> <label for="checkbox-h-6a">One</label>

… </fieldset></form>

Page 33: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

AJAX Loader

A link can show/hide AJAX loader iconclass="hide-page-loading-msg"/"show-page-loading-msg"use data-inline="true"

The loader can contain text (together with/instead of) icondata-textvisible="true" data-msgtext="My text loader" Disable loader icon: data-textonly="true"

We can even define loader as HTML code:data-html="<span class='ui-bar ui-shadow ui-overlay-d ui-corner-all'>…</span>"

Page 34: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

Popups

Will open a popup on some GUI element (typically by tapping it)

From simple text info to complicated formsContents of the popup inside of <div data-role="popup">Referenced by a GUI element using link to popup ID withdata-rel="popup"

e.g. <a href="#popupID" data-rel="popup">Show</a>Data transitions possible, popup is placed over the link

To change the position, we can use data-position-to"window" – centered on window, "origin", any other sel.

To create popup which can't be exited by ESC or clicking outside of it, we can use data-dismissible="false"To use a popup with arrow, we can specify data-arrow, by default "true", or specify arrow edges by -separated: l,t,r,b

Page 35: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

Flip switches, sliders, range sliders

Flipswitch – a two-state switch using classic checkbox or select GUI element, by default with On/Off text

To render as a flipswitch use data-role="flipswitch"To set the labels, we can use

data-on-text="Enabled" data-off-text="Disabled"

Sliders – based on HTML5 input type="range" min="-99" – minimal possible value max="99" – maximum possible valuestep=".5" – slider incrementvalue="0" – default valueRead-only sliders: disabled="disabled"2 sliders enclosed in <div data-role="rangeslider"> tag → Range slider (specifying min and max value)

Page 36: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

Tabs, Panels

Tabs display alternate content in individual tabsThe whole content is enclosed in <div data-role="tabs"> elementThe tabs are defined in a list (<ul>) inside inside of a div with data-role="listview", containing links to content Ids

use data-ajax="false" on these linksVertical tabs can be used e.g. with class="tablist-left"

Panels can be shown/hidden, may contain menu, settings, etc., accessible as link targets

Defined as <div> with data-role="panel" data-display – how to show the panel (overlay/reveal/push)data-position – where to place the panel (left/right)data-position-fixed="true" – display independently on scroll

Limit closing: data-swipe-close="false", data-dismissible="false"

Page 37: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

Customizable table columns

Toggle the columns to make them (in)visibleClassic table with data-mode="columntoggle" and idTo change the button label, we can also include thedata-column-btn-text="Which cols…" in the <table> tag

Reflow a table – <table id="…" data-role="table" data-mode="reflow" class="ui-responsive">Columns defined in <th> tag with data-priority='X'

The priority defines, when to display these columns by default (data-priority="critical" – always), default settings:

data-priority="1" – displays column at 320px (20em)…data-priority="6" – displays the column at 1,120px (70em)

Use <abbr title="Very long title">VLT</abbr> inside of <th> where needed

Page 38: (design Of Applications For Mobile Devices I) - Vsb.czwiki.cs.vsb.cz/images/6/62/TAMZ-new-L4.pdf · TAMZ I (Design of Applications for Mobile Devices I) Lecture 4 jQuery Mobile HTML5

Dynamic content updatesIf we add/manipulate dynamic content in DOM with JavaScript, change values, etc., it may not be redrawn or created properly. To fix this, we must use one of following methods:

Trigger updatelayout event – when showing/hiding contentTrigger create event on changed element's container (parent) to ensure the content is regenerated

e.g. $("#mycset").parent().trigger( "create" );Call refresh method on GUI element which got changed (listview, collapsibleset, checkboxradio, ...)

$( ".selector" ).listview( "refresh" ); sel.button( "refresh");$( ".selector" ).checkboxradio( "refresh" ); $( ".selector" ).collapsibleset( "refresh" );$( ".selector" ).listview( "refresh" );$( ".selector" ).[range]slider( "refresh" );$( ".selector" ).selectmenu( "refresh", force_rebuild );