SlideShare a Scribd company logo
1 of 50
Download to read offline
DYNAMIC USER INTERFACES
for Desktop and Mobile

Iliyan Peychev
Liferay Core Developer
Agenda
●
    Responsive design using JavaScript - AlloyUI Viewport

●
    Responsive design using CSS - Media Queries

●
    Dynamically retrieving data – Pjax and A.Plugin.ScrollInfo

●
    The future - CSS Flexible Box Layout Module
Responsive design using JavaScript
    AlloyUI Viewport allows you to adapt your layout based
    on the following size groups:
●
    320px - smart phones in portrait mode
●
    480px - smart phones in landscape mode
●
    720px - for tablets in portrait mode
●
    960px - for Desktop browsers
Overwriting the magic numbers
These are in "defaults.viewport" namespace so you can
                    overwrite them.
                                                          JavaScript
 var viewport = YUI.AUI.namespace('defaults.viewport');

 viewport.columns = {
     ...
 };
Supports greater than or less than the
              specified widths.
●
    It is also possible to target widths, greater than or less
    than the specified.
●
    If you have a device with 600x800px screen resolution,
    you can still target that device with the CSS classes.
How to use it
Just add "aui-viewport" module to the list of modules on
                      your page:
                                             JavaScript
AUI().use('aui-viewport', ...);
How does it work
 It adds a few classes to the HTML element depending on
                  the width of the window:

                                                             HTML

 <html class="aui-view-gt320 aui-view-gt480 aui-view-gt720 aui-
 view-gt960 aui-view-960">




Based on these classes, you may create selectors which
              match some devices only.
AUI Viewport example
      Order the navigation items in a row for tablets...

                                                      CSS

#navigation li {
    display: inline;
    float: left;
}
AUI Viewport example
            ...or in column mode for smart phones

                                                    CSS

.aui-view-lt720 #navigation li {
     display: block;
     float: none;
}
Target specific browsers

                                              CSS
/* Browsers on smartphones */
.touch.aui-view-lt720 {}

/* Webkit based tablets and smartphones */
.webkit.aui-view-lt960 {}

/* Smaller browser views on just Windows */
.win.aui-view-720 {}
Pros and cons
                              Pros
●
    Simple and powerful
●
    Will work on browsers which don't support Media Queries
                              Cons
●
    Will not work if JavaScript is disabled
●
    JavaScript blocks rendering process
Supported browsers



                     6+
Responsive Design using Media Queries
Responsive Design using Media Queries
Media Queries allow adapting the same content to a specific
                 range of output devices.
Responsive Design using Media Queries
Media Queries allow adapting the same content to a specific
                 range of output devices.
 CSS3 Media Queries extend the media queries we had in
       HTML4 [HTML401] and CSS2 [CSS21]:
‘aural’, ‘braille’, ‘handheld’, ‘print’, ‘projection’, ‘screen’, ‘tty’,
                                 ‘tv’
Loading CSS file only if needed
                                                          HTML
<link media="(min-width: 40.5em)" href="extensions.css"
rel="stylesheet" />




                                                          HTML
<link media="not screen and (color)" href="example.css"
rel="stylesheet" />
Example
        Apply a style sheet only in portrait orientation:

                                                            CSS

@media all and (orientation: portrait) {
….
}
A CSS pixel is not always a device pixel
  Web developers traditionally assumed a CSS pixel as a
                      device pixel.


 However, on high DPI devices (such as iPhone 4+) a CSS
     pixel may repsesent multiple pixels on screen.


If we set zoom magnifcation of 2x, then 1 CSS pixel would
 actually be represented by a 2×2 square of device pixels.
Resolving the situation
                                                             CSS
 @media
 only screen and ( -webkit-min-device-pixel-ratio: 2    ),
 only screen and ( min--moz-device-pixel-ratio: 2       ),
 only screen and ( -o-min-device-pixel-ratio:      2/1  ),
 only screen and ( min-device-pixel-ratio:        2     ),
 only screen and ( min-resolution:               192dpi ),
 only screen and ( min-resolution:               2dppx ) {

     /* Retina-specific stuff here */

 }


Opera requires fractions for the device-pixel-ratio
Param. Firefox 16 supports "min-resolution"
using the dppx unit.
Credits to css-tricks.com
Supported browsers



                     9+
Retrieving data
Retrieving data

 Pjax Utility
Pjax Utility
Progressively enhance normal links on a page.
Pjax Utility
       Progressively enhance normal links on a page.
In this way clicks result in the linked content being loaded via
                               Ajax.
How to use it
                  Plug the module to the content:

                                                    JavaScript
AUI().use('pjax', function (A) {
    new A.Pjax({container: '#content'});
});
Make the links Pjax-able
By default Pjax module will handle links which have ".yui3-
                       pjax" class.
 It is easy to customize this by overwriting "linkSelector"
                  attribute of Pjax module.
How does it work
●
    By default the Pjax instance listens to clicks on any link on
    the page that has a “yui3-pjax” class.
●
    When a “yui3-pjax” link is clicked, its URL will be loaded
    via Ajax and the loaded content will be inserted into the
    “#content” div, replacing its existing contents.
●
    When the Pjax Utility makes an Ajax request to the server,
    it adds a special X-PJAX HTTP header to the request.
A.Plugin.ScrollInfo

                   Useful when you want to:


●
    Implement infinite scrolling
●
    Lazy-load content
●
    Display data in the same way as native applications do it
How to use it
       Plug the module to a node (may be the page body):

var body = A.one('body');                                       JavaScript
body.plug(A.Plugin.ScrollInfo);

body.scrollInfo.on('scrollToBottom', function (event) {
    // Load more content when the user scrolls to the bottom of the page.
});
Provides useful information
Fires multiple events depending on the direction user scrolled the content:
●
    scrollToBottom – probably the most useful event
●
    scrollDown
●
    scrollLeft
●
    scrollRight
●
    scrollToLeft
●
    scrollToRight
●
    scrollToTop
●
    scrollUp
The future
The future

CSS Flexible Box Layout Module
CSS Flexible Box Layout Module
●
    CSS box model optimized for user interface design.
●
    Similar to block layout.
●
    Designed for laying out more complex applications and
    webpages.
●
    Contents can be laid out in any flow direction.
●
    Display order can be reversed.
●
    Can “flex” contents sizes to respond to the available
    space.
The “Holy Grail Layout”
                       <header>

     <nav>             <article>                <aside>

●   Topic 1      Dynamic User Interfaces        Speakers
●   Topic 2
●   Topic 3
●   Topic 4
●   Topic 5

              <footer> Liferay Symposium 2012
The “Holy Grail Layout” source code
<!DOCTYPE html>                                  HTML

<header>Example Header</header>

<div id="main">

    <article>Dynamic User Interfaces</article>

    <nav>Topics</nav>

    <aside>Speakers</aside>

</div>

<footer>Liferay Symposium 2012</footer>
The “Holy Grail Layout”
                           <header>

     <nav>                 <article>               <aside>

●   Topic 1         Dynamic User Interfaces        Speakers
●   Topic 2
●   Topic 3
●   Topic 4
●   Topic 5

                 <footer> Liferay Symposium 2012


                          CSS
#main { display: flex; }
nav { order: 1; width: 200px; }
article { order: 2; flex: 1; }
aside { order: 3; width: 200px; }
What about mobile?
    Just restore document order and set the width to auto

@media screen and (max-width: 600px) {               CSS
  #main {
       flex-direction: column;
  }

    article {
         flex: none;
    }

    article, nav, aside {
         order: 0;
         width: auto;
    }
}
The “Holy Grail Layout” mobile view
                <header>

                 <article>

           Dynamic User Interfaces

                 <nav>
                 Topic 1

                 <aside>

                Speakers
        <footer> Liferay Symposium 2012
Creating a header
  Use “margin-left: auto” to separate flex items in “groups”.
 .header {                                              CSS
     display: flex;
 }

 .header .login {
     margin-left: auto;
 }

The result:
 Products Services Partners                           Sign In
Switching from row to column is
                 easy
●   The contents of a flex container can be laid out in any
    direction and in any order.
●   This functionality is exposed through the 'flex-direction',
    'flex-wrap', and 'order' properties.
●   Keep in mind this affects only the visual rendering and it
    will leave the speech order and navigation based on the
    source order.
Center content vertically
.container {                                     CSS
    align-items: center;
    justify-content: center;
    display: flex;
}




                   Item 1      Item 2   Item 3
Reverse the order (row-reverse)
                                                CSS
.container {
    flex-direction: row-reverse;
    ...
}



                   Item 3     Item 2   Item 1
Reverse the order (column-reverse)
                                      CSS
.container {
    flex-direction: column-reverse;
    ...
}


                             Item 3

                             Item 2

                             Item 1
Multi-line flex container
Breaks its flex items across multiple lines. The cross size of each line is
   the minimum size necessary to contain the flex items on the line.

                                                                  CSS
.container { display: flex; width: 400px; }

.multi-line .item { width: 100px;}




 Item 1     Item 2     Item 3

 Item 4     Item 5
Multi-line auto flex container
Setting "flex: auto;" to the items will force them to absorb any free space
                                 remaining.

                                                                 CSS
.multi-line .item {
    flex: auto; /* or flex: 1 1 auto; */
    width: 100px;
}



  Item 1      Item 2        Item 3

  Item 4               Item 5
Supported browsers

                                                      10+

Notes:

Firefox Nightly (18.0a1, from 05.10.2012) requires to turn on
“layout.css.flexbox.enabled” in about:config

According to MSDN, IE10 will support the version from 22 March 2012
Summary
    Adapting the layout to the device the user is currently
    using:
●
    AlloyUI Viewport (JavaScript) and Media Queries (CSS)
Summary
    Adapting the layout to the device the user is currently
    using:
●
    AlloyUI Viewport (JavaScript) and Media Queries (CSS)
    Retrieving the data dynamically:
●
    Pjax Utility and ScrollInfo plugin
Summary
    Adapting the layout to the device the user is currently
    using:
●
    AlloyUI Viewport (JavaScript) and Media Queries (CSS)
    Retrieving the data dynamically:
●
    Pjax Utility and ScrollInfo plugin
    Looking at the future:
●
    Keep CSS Flexbox Layout in your radar and stay tuned :)
Questions?

Twitter   ipeychev
Google+ https://plus.google.com/101163834202763493709
email     iliyan.peychev@liferay.com

More Related Content

What's hot

HTML5 and the dawn of rich mobile web applications pt 2
HTML5 and the dawn of rich mobile web applications pt 2HTML5 and the dawn of rich mobile web applications pt 2
HTML5 and the dawn of rich mobile web applications pt 2
James Pearce
 
Devon 2011-f-1 반응형 웹 디자인
Devon 2011-f-1  반응형 웹 디자인Devon 2011-f-1  반응형 웹 디자인
Devon 2011-f-1 반응형 웹 디자인
Daum DNA
 
Wordcamp Thessaloniki 2011 The Nextweb
Wordcamp Thessaloniki 2011 The NextwebWordcamp Thessaloniki 2011 The Nextweb
Wordcamp Thessaloniki 2011 The Nextweb
George Kanellopoulos
 

What's hot (20)

HTML5 - A Whirlwind tour
HTML5 - A Whirlwind tourHTML5 - A Whirlwind tour
HTML5 - A Whirlwind tour
 
Html5 more than just html5 v final
Html5  more than just html5 v finalHtml5  more than just html5 v final
Html5 more than just html5 v final
 
Dive into HTML5: SVG and Canvas
Dive into HTML5: SVG and CanvasDive into HTML5: SVG and Canvas
Dive into HTML5: SVG and Canvas
 
CSS3: Using media queries to improve the web site experience
CSS3: Using media queries to improve the web site experienceCSS3: Using media queries to improve the web site experience
CSS3: Using media queries to improve the web site experience
 
Using Web Standards to create Interactive Data Visualizations for the Web
Using Web Standards to create Interactive Data Visualizations for the WebUsing Web Standards to create Interactive Data Visualizations for the Web
Using Web Standards to create Interactive Data Visualizations for the Web
 
Writing an extensible web testing framework ready for the cloud slide share
Writing an extensible web testing framework ready for the cloud   slide shareWriting an extensible web testing framework ready for the cloud   slide share
Writing an extensible web testing framework ready for the cloud slide share
 
2022 HTML5: The future is now
2022 HTML5: The future is now2022 HTML5: The future is now
2022 HTML5: The future is now
 
AspNetWhitePaper
AspNetWhitePaperAspNetWhitePaper
AspNetWhitePaper
 
Intro to CSS3
Intro to CSS3Intro to CSS3
Intro to CSS3
 
Building Performance - ein Frontend-Build-Prozess für Java mit Maven
Building Performance - ein Frontend-Build-Prozess für Java mit MavenBuilding Performance - ein Frontend-Build-Prozess für Java mit Maven
Building Performance - ein Frontend-Build-Prozess für Java mit Maven
 
A Snapshot of the Mobile HTML5 Revolution
A Snapshot of the Mobile HTML5 RevolutionA Snapshot of the Mobile HTML5 Revolution
A Snapshot of the Mobile HTML5 Revolution
 
HTML5 and the dawn of rich mobile web applications pt 2
HTML5 and the dawn of rich mobile web applications pt 2HTML5 and the dawn of rich mobile web applications pt 2
HTML5 and the dawn of rich mobile web applications pt 2
 
Word camp nextweb
Word camp nextwebWord camp nextweb
Word camp nextweb
 
Building Cross Platform Mobile Web Apps
Building Cross Platform Mobile Web AppsBuilding Cross Platform Mobile Web Apps
Building Cross Platform Mobile Web Apps
 
[SF HTML5] Responsive Cross-Device Development with Web Standards (2013)
[SF HTML5] Responsive Cross-Device Development with Web Standards (2013)[SF HTML5] Responsive Cross-Device Development with Web Standards (2013)
[SF HTML5] Responsive Cross-Device Development with Web Standards (2013)
 
Svcc 2013-css3-and-mobile
Svcc 2013-css3-and-mobileSvcc 2013-css3-and-mobile
Svcc 2013-css3-and-mobile
 
Building high performing web pages
Building high performing web pagesBuilding high performing web pages
Building high performing web pages
 
Devon 2011-f-1 반응형 웹 디자인
Devon 2011-f-1  반응형 웹 디자인Devon 2011-f-1  반응형 웹 디자인
Devon 2011-f-1 반응형 웹 디자인
 
Drupal 7 - The Top 40 Core Modules and What They Mean for You
Drupal 7 - The Top 40 Core Modules and What They Mean for YouDrupal 7 - The Top 40 Core Modules and What They Mean for You
Drupal 7 - The Top 40 Core Modules and What They Mean for You
 
Wordcamp Thessaloniki 2011 The Nextweb
Wordcamp Thessaloniki 2011 The NextwebWordcamp Thessaloniki 2011 The Nextweb
Wordcamp Thessaloniki 2011 The Nextweb
 

Similar to Dynamic User Interfaces for Desktop and Mobile

The specs behind the sex, mobile-friendly layout beyond the desktop
The specs behind the sex, mobile-friendly layout beyond the desktopThe specs behind the sex, mobile-friendly layout beyond the desktop
The specs behind the sex, mobile-friendly layout beyond the desktop
betabeers
 

Similar to Dynamic User Interfaces for Desktop and Mobile (20)

Responsive layouts by Maqbool
Responsive layouts by MaqboolResponsive layouts by Maqbool
Responsive layouts by Maqbool
 
Html5
Html5Html5
Html5
 
Great Responsive-ability Web Design
Great Responsive-ability Web DesignGreat Responsive-ability Web Design
Great Responsive-ability Web Design
 
Html5
Html5Html5
Html5
 
Responsive Web Designed for your communication and marketing needs
Responsive Web Designed for your communication and marketing needsResponsive Web Designed for your communication and marketing needs
Responsive Web Designed for your communication and marketing needs
 
Responsive Websites
Responsive WebsitesResponsive Websites
Responsive Websites
 
Css responsive
Css responsiveCss responsive
Css responsive
 
Presentation about html5 css3
Presentation about html5 css3Presentation about html5 css3
Presentation about html5 css3
 
Developing JavaScript Widgets
Developing JavaScript WidgetsDeveloping JavaScript Widgets
Developing JavaScript Widgets
 
Html 5 mobile - nitty gritty
Html 5 mobile - nitty grittyHtml 5 mobile - nitty gritty
Html 5 mobile - nitty gritty
 
Responsive content
Responsive contentResponsive content
Responsive content
 
Html5
Html5Html5
Html5
 
Responsive websites. Toolbox
Responsive websites. ToolboxResponsive websites. Toolbox
Responsive websites. Toolbox
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
 
Developing JavaScript Widgets
Developing JavaScript WidgetsDeveloping JavaScript Widgets
Developing JavaScript Widgets
 
Create Responsive Website Design with Bootstrap 3
Create Responsive Website Design with Bootstrap 3Create Responsive Website Design with Bootstrap 3
Create Responsive Website Design with Bootstrap 3
 
Pinkoi Mobile Web
Pinkoi Mobile WebPinkoi Mobile Web
Pinkoi Mobile Web
 
Miha Lesjak Mobilizing The Web with Web Runtime
Miha Lesjak Mobilizing The Web with Web RuntimeMiha Lesjak Mobilizing The Web with Web Runtime
Miha Lesjak Mobilizing The Web with Web Runtime
 
Responsive Web Design: Clever Tips and Techniques
Responsive Web Design: Clever Tips and TechniquesResponsive Web Design: Clever Tips and Techniques
Responsive Web Design: Clever Tips and Techniques
 
The specs behind the sex, mobile-friendly layout beyond the desktop
The specs behind the sex, mobile-friendly layout beyond the desktopThe specs behind the sex, mobile-friendly layout beyond the desktop
The specs behind the sex, mobile-friendly layout beyond the desktop
 

More from peychevi

Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor
Implementing AutoComplete for Freemarker and Velocity languages in ACE EditorImplementing AutoComplete for Freemarker and Velocity languages in ACE Editor
Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor
peychevi
 

More from peychevi (7)

Client Extensions 101 - DEVCON 2023
Client Extensions 101 - DEVCON 2023Client Extensions 101 - DEVCON 2023
Client Extensions 101 - DEVCON 2023
 
Extending Kubernetes with Operators
Extending Kubernetes with OperatorsExtending Kubernetes with Operators
Extending Kubernetes with Operators
 
Best practices for creating modular Web applications
Best practices for creating modular Web applicationsBest practices for creating modular Web applications
Best practices for creating modular Web applications
 
Modern Web Developement
Modern Web DevelopementModern Web Developement
Modern Web Developement
 
Creating a WYSIWYG Editor with React
Creating a WYSIWYG Editor with ReactCreating a WYSIWYG Editor with React
Creating a WYSIWYG Editor with React
 
HTTP/2 and QUICK protocols. Optimizing the Web stack for HTTP/2 era
HTTP/2 and QUICK protocols. Optimizing the Web stack for HTTP/2 eraHTTP/2 and QUICK protocols. Optimizing the Web stack for HTTP/2 era
HTTP/2 and QUICK protocols. Optimizing the Web stack for HTTP/2 era
 
Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor
Implementing AutoComplete for Freemarker and Velocity languages in ACE EditorImplementing AutoComplete for Freemarker and Velocity languages in ACE Editor
Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

Dynamic User Interfaces for Desktop and Mobile

  • 1. DYNAMIC USER INTERFACES for Desktop and Mobile Iliyan Peychev Liferay Core Developer
  • 2. Agenda ● Responsive design using JavaScript - AlloyUI Viewport ● Responsive design using CSS - Media Queries ● Dynamically retrieving data – Pjax and A.Plugin.ScrollInfo ● The future - CSS Flexible Box Layout Module
  • 3. Responsive design using JavaScript AlloyUI Viewport allows you to adapt your layout based on the following size groups: ● 320px - smart phones in portrait mode ● 480px - smart phones in landscape mode ● 720px - for tablets in portrait mode ● 960px - for Desktop browsers
  • 4. Overwriting the magic numbers These are in "defaults.viewport" namespace so you can overwrite them. JavaScript var viewport = YUI.AUI.namespace('defaults.viewport'); viewport.columns = { ... };
  • 5. Supports greater than or less than the specified widths. ● It is also possible to target widths, greater than or less than the specified. ● If you have a device with 600x800px screen resolution, you can still target that device with the CSS classes.
  • 6. How to use it Just add "aui-viewport" module to the list of modules on your page: JavaScript AUI().use('aui-viewport', ...);
  • 7. How does it work It adds a few classes to the HTML element depending on the width of the window: HTML <html class="aui-view-gt320 aui-view-gt480 aui-view-gt720 aui- view-gt960 aui-view-960"> Based on these classes, you may create selectors which match some devices only.
  • 8. AUI Viewport example Order the navigation items in a row for tablets... CSS #navigation li { display: inline; float: left; }
  • 9. AUI Viewport example ...or in column mode for smart phones CSS .aui-view-lt720 #navigation li { display: block; float: none; }
  • 10. Target specific browsers CSS /* Browsers on smartphones */ .touch.aui-view-lt720 {} /* Webkit based tablets and smartphones */ .webkit.aui-view-lt960 {} /* Smaller browser views on just Windows */ .win.aui-view-720 {}
  • 11. Pros and cons Pros ● Simple and powerful ● Will work on browsers which don't support Media Queries Cons ● Will not work if JavaScript is disabled ● JavaScript blocks rendering process
  • 13. Responsive Design using Media Queries
  • 14. Responsive Design using Media Queries Media Queries allow adapting the same content to a specific range of output devices.
  • 15. Responsive Design using Media Queries Media Queries allow adapting the same content to a specific range of output devices. CSS3 Media Queries extend the media queries we had in HTML4 [HTML401] and CSS2 [CSS21]: ‘aural’, ‘braille’, ‘handheld’, ‘print’, ‘projection’, ‘screen’, ‘tty’, ‘tv’
  • 16. Loading CSS file only if needed HTML <link media="(min-width: 40.5em)" href="extensions.css" rel="stylesheet" /> HTML <link media="not screen and (color)" href="example.css" rel="stylesheet" />
  • 17. Example Apply a style sheet only in portrait orientation: CSS @media all and (orientation: portrait) { …. }
  • 18. A CSS pixel is not always a device pixel Web developers traditionally assumed a CSS pixel as a device pixel. However, on high DPI devices (such as iPhone 4+) a CSS pixel may repsesent multiple pixels on screen. If we set zoom magnifcation of 2x, then 1 CSS pixel would actually be represented by a 2×2 square of device pixels.
  • 19. Resolving the situation CSS @media only screen and ( -webkit-min-device-pixel-ratio: 2 ), only screen and ( min--moz-device-pixel-ratio: 2 ), only screen and ( -o-min-device-pixel-ratio: 2/1 ), only screen and ( min-device-pixel-ratio: 2 ), only screen and ( min-resolution: 192dpi ), only screen and ( min-resolution: 2dppx ) { /* Retina-specific stuff here */ } Opera requires fractions for the device-pixel-ratio Param. Firefox 16 supports "min-resolution" using the dppx unit. Credits to css-tricks.com
  • 23. Pjax Utility Progressively enhance normal links on a page.
  • 24. Pjax Utility Progressively enhance normal links on a page. In this way clicks result in the linked content being loaded via Ajax.
  • 25. How to use it Plug the module to the content: JavaScript AUI().use('pjax', function (A) { new A.Pjax({container: '#content'}); });
  • 26. Make the links Pjax-able By default Pjax module will handle links which have ".yui3- pjax" class. It is easy to customize this by overwriting "linkSelector" attribute of Pjax module.
  • 27. How does it work ● By default the Pjax instance listens to clicks on any link on the page that has a “yui3-pjax” class. ● When a “yui3-pjax” link is clicked, its URL will be loaded via Ajax and the loaded content will be inserted into the “#content” div, replacing its existing contents. ● When the Pjax Utility makes an Ajax request to the server, it adds a special X-PJAX HTTP header to the request.
  • 28. A.Plugin.ScrollInfo Useful when you want to: ● Implement infinite scrolling ● Lazy-load content ● Display data in the same way as native applications do it
  • 29. How to use it Plug the module to a node (may be the page body): var body = A.one('body'); JavaScript body.plug(A.Plugin.ScrollInfo); body.scrollInfo.on('scrollToBottom', function (event) { // Load more content when the user scrolls to the bottom of the page. });
  • 30. Provides useful information Fires multiple events depending on the direction user scrolled the content: ● scrollToBottom – probably the most useful event ● scrollDown ● scrollLeft ● scrollRight ● scrollToLeft ● scrollToRight ● scrollToTop ● scrollUp
  • 32. The future CSS Flexible Box Layout Module
  • 33. CSS Flexible Box Layout Module ● CSS box model optimized for user interface design. ● Similar to block layout. ● Designed for laying out more complex applications and webpages. ● Contents can be laid out in any flow direction. ● Display order can be reversed. ● Can “flex” contents sizes to respond to the available space.
  • 34. The “Holy Grail Layout” <header> <nav> <article> <aside> ● Topic 1 Dynamic User Interfaces Speakers ● Topic 2 ● Topic 3 ● Topic 4 ● Topic 5 <footer> Liferay Symposium 2012
  • 35. The “Holy Grail Layout” source code <!DOCTYPE html> HTML <header>Example Header</header> <div id="main"> <article>Dynamic User Interfaces</article> <nav>Topics</nav> <aside>Speakers</aside> </div> <footer>Liferay Symposium 2012</footer>
  • 36. The “Holy Grail Layout” <header> <nav> <article> <aside> ● Topic 1 Dynamic User Interfaces Speakers ● Topic 2 ● Topic 3 ● Topic 4 ● Topic 5 <footer> Liferay Symposium 2012 CSS #main { display: flex; } nav { order: 1; width: 200px; } article { order: 2; flex: 1; } aside { order: 3; width: 200px; }
  • 37. What about mobile? Just restore document order and set the width to auto @media screen and (max-width: 600px) { CSS #main { flex-direction: column; } article { flex: none; } article, nav, aside { order: 0; width: auto; } }
  • 38. The “Holy Grail Layout” mobile view <header> <article> Dynamic User Interfaces <nav> Topic 1 <aside> Speakers <footer> Liferay Symposium 2012
  • 39. Creating a header Use “margin-left: auto” to separate flex items in “groups”. .header { CSS display: flex; } .header .login { margin-left: auto; } The result: Products Services Partners Sign In
  • 40. Switching from row to column is easy ● The contents of a flex container can be laid out in any direction and in any order. ● This functionality is exposed through the 'flex-direction', 'flex-wrap', and 'order' properties. ● Keep in mind this affects only the visual rendering and it will leave the speech order and navigation based on the source order.
  • 41. Center content vertically .container { CSS align-items: center; justify-content: center; display: flex; } Item 1 Item 2 Item 3
  • 42. Reverse the order (row-reverse) CSS .container { flex-direction: row-reverse; ... } Item 3 Item 2 Item 1
  • 43. Reverse the order (column-reverse) CSS .container { flex-direction: column-reverse; ... } Item 3 Item 2 Item 1
  • 44. Multi-line flex container Breaks its flex items across multiple lines. The cross size of each line is the minimum size necessary to contain the flex items on the line. CSS .container { display: flex; width: 400px; } .multi-line .item { width: 100px;} Item 1 Item 2 Item 3 Item 4 Item 5
  • 45. Multi-line auto flex container Setting "flex: auto;" to the items will force them to absorb any free space remaining. CSS .multi-line .item { flex: auto; /* or flex: 1 1 auto; */ width: 100px; } Item 1 Item 2 Item 3 Item 4 Item 5
  • 46. Supported browsers 10+ Notes: Firefox Nightly (18.0a1, from 05.10.2012) requires to turn on “layout.css.flexbox.enabled” in about:config According to MSDN, IE10 will support the version from 22 March 2012
  • 47. Summary Adapting the layout to the device the user is currently using: ● AlloyUI Viewport (JavaScript) and Media Queries (CSS)
  • 48. Summary Adapting the layout to the device the user is currently using: ● AlloyUI Viewport (JavaScript) and Media Queries (CSS) Retrieving the data dynamically: ● Pjax Utility and ScrollInfo plugin
  • 49. Summary Adapting the layout to the device the user is currently using: ● AlloyUI Viewport (JavaScript) and Media Queries (CSS) Retrieving the data dynamically: ● Pjax Utility and ScrollInfo plugin Looking at the future: ● Keep CSS Flexbox Layout in your radar and stay tuned :)
  • 50. Questions? Twitter ipeychev Google+ https://plus.google.com/101163834202763493709 email iliyan.peychev@liferay.com