Просмотр исходного кода

Added examples to test tablet functionality

piniphone 13 лет назад
Родитель
Сommit
2a7d87944c

+ 8 - 2
example/navigation.tablet2.html

@@ -33,6 +33,11 @@
             </ul>
         </article>
     </aside>
+    <aside id="menu2" data-transition="left">
+        <header data-title="My mailbox 2"></header>
+        <article id="menu_article" class="active list scroll">aaaa
+        </article>
+    </aside>
 
     <!-- ===================================================================================== -->
     <!-- ===================================================================================== -->
@@ -80,7 +85,7 @@
         </footer>
     </section>
 
-    <section id="mail2">
+    <section id="mail2" data-aside="menu" data-transition="slide">
         <header data-title="First mail">
             <nav class="left">
                 <button data-view-section="back">BaCk</button>
@@ -90,7 +95,8 @@
             mail 1
         </article>
     </section>
-    <section id="mail">
+
+    <section id="mail" data-aside="menu" data-transition="slide">
         <header data-title="Second mail">
             <nav class="left">
                 <button data-view-section="back">BaCk</button>

+ 130 - 0
example/navigation.tablet3.html

@@ -0,0 +1,130 @@
+<!doctype html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <title>Lungo Flexbox - SDK</title>
+    <meta name="description" content="">
+    <meta name="author" content="Javier Jiménez Villar (@soyjavi)">
+    <meta name="HandheldFriendly" content="True">
+    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
+    <meta name="apple-mobile-web-app-capable" content="yes">
+    <meta name="apple-mobile-web-app-status-bar-style" content="black">
+    <meta name="format-detection" content="telephone=no">
+    <meta http-equiv="cleartype" content="on">
+
+    <!-- Main Stylesheet -->
+    <link rel="stylesheet" href="components/lungo.brownie/lungo.css">
+    <link rel="stylesheet" href="components/lungo.brownie/lungo.theme.css">
+    <link rel="stylesheet" href="components/lungo.icon/lungo.icon.css">
+
+</head>
+
+<body>
+
+    <aside id="aside1" data-transition="left">
+        <header data-title="Aside 1"></header>
+        <article id="aside1_article" class="active list scroll">
+            <ul>
+                <li data-view-section="s1" data-icon="plus">Section 1</li>
+                <li data-view-section="s2" data-icon="plus">Section 2</li>
+                <li data-view-section="s3" data-icon="plus">Section 3</li>
+            </ul>
+        </article>
+    </aside>
+
+    <aside id="aside2" data-transition="left">
+        <header data-title="Aside 2"></header>
+        <article id="aside2_article" class="active list scroll">
+            <ul>
+                <li data-view-section="s3" data-icon="plus">Section 3</li>
+                <li data-view-section="s4" data-icon="plus">Section 4</li>
+            </ul>
+        </article>
+    </aside>
+
+    <!-- ===================================================================================== -->
+    <!-- ===================================================================================== -->
+
+    <section id="s1" data-transition="slide" data-aside="aside1" data-children="s2 s3">
+        <header data-title="S1">
+            <nav class="left">
+                <button data-icon="list" data-view-aside="aside1"></button>
+            </nav>
+        </header>
+        <article id="incoming" class="list scroll">
+            aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa
+            <button data-view-section="s2">S2 go!</button>
+            <button data-view-section="s3">S3 go!</button>
+            <button data-view-section="s4">S4 go!</button>
+        </article>
+    </section>
+
+    <section id="s2" data-transition="slide" data-aside="aside1">
+        <header data-title="S2">
+            <nav class="left">
+                <button data-view-section="back">BaCk</button>
+            </nav>
+        </header>
+        <article id="art_2">
+            bbbbbb bbbbbbbbbb bbbb bbbb
+        </article>
+    </section>
+
+    <section id="s3" data-transition="slide" data-aside="aside1">
+        <header data-title="S3">
+            <nav class="left">
+                <button data-view-section="back">BaCk</button>
+            </nav>
+        </header>
+        <article id="art_3">
+            cccc c cccccccc cccc c cccccccc cccc c cccccccc
+        </article>
+    </section>
+
+    <section id="s4" data-transition="slide" data-aside="aside2" data-children="s5">
+        <header data-title="S4">
+            <nav class="left">
+                <button data-view-section="back">BaCk</button>
+            </nav>
+        </header>
+        <article id="art_4">
+            dddd d dddddddd dddd d dddddddd dddd d dddddddd
+            <button data-view-section="s5">S5 go!</button>
+        </article>
+    </section>
+
+    <section id="s5" data-transition="slide" data-aside="aside2" data-children="s6">
+        <header data-title="S5">
+            <nav class="left">
+                <button data-view-section="back">BaCk</button>
+            </nav>
+        </header>
+        <article id="art_5">
+            eee eeee eeee eeeee eeeeee
+            <button data-view-section="s6">S5 go!</button>
+        </article>
+    </section>
+
+    <section id="s6" data-transition="slide" data-aside="aside2">
+        <header data-title="S6">
+            <nav class="left">
+                <button data-view-section="back">BaCk</button>
+            </nav>
+        </header>
+        <article id="art_6">
+            eee eeee eeee eeeee eeeeee
+        </article>
+    </section>
+
+    <script src="components/quojs/quo.js"></script>
+    <script src="components/lungo.brownie/lungo.debug.js"></script>
+    <script>
+        Lungo.init({
+            name: 'Flexbox',
+            version: '2.2',
+            history: false
+        });
+        $$("[data-router=back]").tap(function(event) { Lungo.Router.back(); });
+    </script>
+</body>
+</html>

+ 131 - 0
example/navigation.tablet4.html

@@ -0,0 +1,131 @@
+<!doctype html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <title>Lungo Flexbox - SDK</title>
+    <meta name="description" content="">
+    <meta name="author" content="Javier Jiménez Villar (@soyjavi)">
+    <meta name="HandheldFriendly" content="True">
+    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
+    <meta name="apple-mobile-web-app-capable" content="yes">
+    <meta name="apple-mobile-web-app-status-bar-style" content="black">
+    <meta name="format-detection" content="telephone=no">
+    <meta http-equiv="cleartype" content="on">
+
+    <!-- Main Stylesheet -->
+    <link rel="stylesheet" href="components/lungo.brownie/lungo.css">
+    <link rel="stylesheet" href="components/lungo.brownie/lungo.theme.css">
+    <link rel="stylesheet" href="components/lungo.icon/lungo.icon.css">
+
+</head>
+
+<body>
+
+    <aside id="aside1" data-transition="left">
+        <header data-title="Aside 1"></header>
+        <article id="aside1_article" class="active list scroll">
+            <ul>
+                <li data-view-section="s1" data-icon="plus">Section 1</li>
+                <li data-view-section="s2" data-icon="plus">Section 2</li>
+                <li data-view-section="s3" data-icon="plus">Section 3</li>
+            </ul>
+        </article>
+    </aside>
+<!--
+    <aside id="aside2" data-transition="left">
+        <header data-title="Aside 2"></header>
+        <article id="aside2_article" class="active list scroll">
+            <ul>
+                <li data-view-section="s3" data-icon="plus">Section 3</li>
+                <li data-view-section="s4" data-icon="plus">Section 4</li>
+            </ul>
+        </article>
+    </aside>
+ -->
+    <!-- ===================================================================================== -->
+    <!-- ===================================================================================== -->
+
+    <section id="s1" data-transition="slide" data-aside="aside1">
+        <header data-title="S1">
+            <nav class="left">
+                <button data-icon="list" data-view-aside="aside1"></button>
+            </nav>
+        </header>
+        <article id="incoming" class="list scroll">
+            aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa
+            <button data-view-section="s2">S2 go!</button>
+            <button data-view-section="s3">S3 go!</button>
+            <button data-view-section="s4">S4 go!</button>
+        </article>
+    </section>
+
+    <section id="s2" data-transition="slide" data-aside="aside1">
+        <header data-title="S2">
+            <nav class="left">
+                <button data-view-section="back">BaCk</button>
+            </nav>
+        </header>
+        <article id="art_2">
+            bbbbbb bbbbbbbbbb bbbb bbbb
+        </article>
+    </section>
+
+<!--
+    <section id="s3" data-transition="slide" data-aside="aside1">
+        <header data-title="S3">
+            <nav class="left">
+                <button data-view-section="back">BaCk</button>
+            </nav>
+        </header>
+        <article id="art_3">
+            cccc c cccccccc cccc c cccccccc cccc c cccccccc
+        </article>
+    </section>
+
+    <section id="s4" data-transition="slide" data-aside="aside2" data-children="s5">
+        <header data-title="S4">
+            <nav class="left">
+                <button data-view-section="back">BaCk</button>
+            </nav>
+        </header>
+        <article id="art_4">
+            dddd d dddddddd dddd d dddddddd dddd d dddddddd
+            <button data-view-section="s5">S5 go!</button>
+        </article>
+    </section>
+
+    <section id="s5" data-transition="slide" data-aside="aside2" data-children="s6">
+        <header data-title="S5">
+            <nav class="left">
+                <button data-view-section="back">BaCk</button>
+            </nav>
+        </header>
+        <article id="art_5">
+            eee eeee eeee eeeee eeeeee
+            <button data-view-section="s6">S5 go!</button>
+        </article>
+    </section>
+
+    <section id="s6" data-transition="slide" data-aside="aside2">
+        <header data-title="S6">
+            <nav class="left">
+                <button data-view-section="back">BaCk</button>
+            </nav>
+        </header>
+        <article id="art_6">
+            eee eeee eeee eeeee eeeeee
+        </article>
+    </section> -->
+
+    <script src="components/quojs/quo.js"></script>
+    <script src="components/lungo.brownie/lungo.debug.js"></script>
+    <script>
+        Lungo.init({
+            name: 'Flexbox',
+            version: '2.2',
+            history: false
+        });
+        $$("[data-router=back]").tap(function(event) { Lungo.Router.back(); });
+    </script>
+</body>
+</html>

+ 15 - 11
src/modules/Lungo.Aside.coffee

@@ -19,20 +19,24 @@ Lungo.Aside = do (lng = Lungo) ->
   ###
   show = (aside_id, animate_section = true, fromX = 0) ->
     aside = lng.dom("##{aside_id}")
-    if aside.length
-      lng.Element.Cache.aside = aside
-      aside_transition = aside.data(C.TRANSITION.ATTR) or "left"
-      aside.addClass(C.CLASS.SHOW)
-      if lng.DEVICE is C.DEVICE.PHONE
-        if fromX then _phoneCustomAnimation fromX, false
-        else lng.Element.Cache.section.data("aside-#{aside_transition}", "show")
-      else
-        aside_section = lng.dom("[data-aside=#{aside_id}]")
-        if aside_section.data("children")
-          if aside_section.attr("id") isnt lng.Element.Cache.section.attr("id")
+    if aside.length and not _alreadyOpen(aside_id)
+        console.error 'Current aside --> ', aside
+        lng.Element.Cache.aside = aside
+        if lng.DEVICE is C.DEVICE.PHONE
+          aside_transition = aside.data(C.TRANSITION.ATTR) or "left"
+          aside.addClass(C.CLASS.SHOW)
+          if fromX then _phoneCustomAnimation fromX, false
+          else lng.Element.Cache.section.data("aside-#{aside_transition}", "show")
+        else
+          aside.addClass(C.CLASS.SHOW)
+          aside_section = lng.dom("[data-aside=#{aside_id}][data-children].#{C.CLASS.SHOW}")
+          if aside_section.attr("id") isnt lng.Element.Cache.section?.attr("id")
             lng.Element.Cache.section.addClass "shadowing"
           aside_section.removeClass("aside").addClass "asideShowing"
 
+  _alreadyOpen = (aside_id) ->
+    return lng.Element.Cache.aside?.attr("id") is aside_id
+
   showFix = (aside_id) ->
     aside = lng.dom("##{aside_id}")
     if aside.length

+ 96 - 33
src/modules/Lungo.Router.Tablet.coffee

@@ -1,11 +1,9 @@
 ###
-Handles the <sections> and <articles> to show
+Handles the <sections> and <articles> to show on a tablet device
 
 @namespace Lungo
 @class Router
 
-@author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
-@author Guillermo Pascual <pasku@tapquo.com> || @pasku1
 @author Ignacio Olalde <ina@tapquo.com> || @piniphone
 ###
 
@@ -16,6 +14,8 @@ Lungo.RouterTablet = do (lng = Lungo) ->
   HASHTAG             = "#"
   _history            = []
   _animating          = false
+  _callbackSection    = undefined
+  _fromCallback       = false
 
   ###
   Navigate to a <section>.
@@ -34,6 +34,7 @@ Lungo.RouterTablet = do (lng = Lungo) ->
         do _url unless Lungo.Config.history is false
         do _updateNavigationElements
     # else do lng.Aside.hide
+    # console.error "Forward -->", _history
 
   ###
   Return to previous section.
@@ -49,6 +50,7 @@ Lungo.RouterTablet = do (lng = Lungo) ->
       _show future, current, true, animating
       do _url unless Lungo.Config.history is false
       do _updateNavigationElements
+    # console.error "Backward -->", _history
 
   ###
   Displays the <article> in a particular <section>.
@@ -84,15 +86,15 @@ Lungo.RouterTablet = do (lng = Lungo) ->
     if direction
       section.removeClass C.CLASS.SHOW if direction is "out" or direction is "back-out"
       section.removeAttr "data-#{C.ATTRIBUTE.DIRECTION}"
-    if section.hasClass("asideHidding")
-      section.removeClass("asideHidding").removeClass("aside")
-    if section.hasClass("asideShowing")
-      section.removeClass("asideShowing").addClass("aside")
-    if section.hasClass("shadowing")
-      section.removeClass("shadowing").addClass("shadow")
-    if section.hasClass("unshadowing")
-      section.removeClass("unshadowing").removeClass("shadow")
-
+      if _callbackSection?
+        _fromCallback = true
+        _show _callbackSection, undefined
+        _callbackSection = undefined
+
+    if section.hasClass("asideHidding") then section.removeClass("asideHidding").removeClass("aside")
+    if section.hasClass("asideShowing") then section.removeClass("asideShowing").addClass("aside")
+    if section.hasClass("shadowing")    then section.removeClass("shadowing").addClass("shadow")
+    if section.hasClass("unshadowing")  then section.removeClass("unshadowing").removeClass("shadow")
     _animating = false
 
   ###
@@ -112,28 +114,89 @@ Lungo.RouterTablet = do (lng = Lungo) ->
   ###
   Private methods
   ###
-  _show = (future, current, backward, animating = true) ->
-    if not backward and not _sameSection() then back false
-    if current?
-      if backward
-        if animating then current.data(C.ATTRIBUTE.DIRECTION, "back-out")
-        else current.removeClass("show")
-      else
-        future.addClass(C.CLASS.SHOW)
-        future.data(C.ATTRIBUTE.DIRECTION, "in") if future.data(C.TRANSITION.ATTR)
-
-    lng.Section.show current, future
-    do _checkAside if animating
-
-
-  _checkAside = ->
-    aside_id = lng.Element.Cache.section?.data("aside")
-    if aside_id and not lng.Element.Cache.section.data("children")
-      lng.Aside.showFix aside_id
+  _show = (future, current, backward=false) ->
+    unless current? then _showFuture(future)
     else
-      # is_other_aside = aside_id isnt lng.Element.Cache.aside?.attr("id")
-      lng.Aside.hide (-> lng.Aside.show aside_id)
-
+      if backward then _showBackward(current, future)
+      else _showForward(current, future)
+      lng.Section.show(current, future)
+    _fromCallback = false
+
+  _showFuture = (future, animating=false) ->
+    current = undefined
+    lng.Section.show(current, future)
+    if not animating and not _fromCallback then future.addClass(C.CLASS.SHOW)
+    else _applyDirection(future, "in")
+    _checkAside(current, future)
+
+  _showForward = (current, future) ->
+    asideHandled = false
+    if _isChild(current, future) then _applyDirection(future, "in")
+    else
+      do _removeLast
+      parent_id = _parentId(future)
+      hideSelector = "section.#{C.CLASS.SHOW}"
+      if parent_id then hideSelector += ":not(##{parent_id})"
+      elements = lng.dom(hideSelector)
+      if lng.Element.Cache.aside
+        do lng.Aside.hide
+        elements.removeClass C.CLASS.SHOW
+        _showFuture future, true
+        asideHandled = true
+      else
+        _applyDirection(elements, "back-out")
+        _callbackSection = future
+
+    if not asideHandled and not _fromCallback
+      _checkAside(current, future)
+
+  _showBackward = (current, future) ->
+    _applyDirection(current, "back-out")
+    showSections = lng.dom("section.#{C.CLASS.SHOW}:not(##{current.attr('id')})")
+    if showSections.length is 1 and showSections.first().data("children")?
+      lng.Aside.hide (-> lng.Aside.show showSections.first().data("aside"))
+    _callbackSection = future
+
+  _visibleParent = (section) ->
+    return lng.dom("section[data-children~=#{section.attr('id')}].#{C.CLASS.SHOW}")
+
+  _checkAside = (current, target) ->
+    aside_id = target.data("aside")
+    unless aside_id then do lng.Aside.hide
+    else if current?
+      do lng.Aside.hide unless lng.Element.Cache.aside?.hasClass("box")
+    else if target.data("children") and lng.dom("section.#{C.CLASS.SHOW}").length is 1
+      lng.Aside.show(aside_id)
+    else if not target.data("children")
+      unless _parentId target
+        lng.Aside.showFix(aside_id)
+
+  _targetIsChildren = (current, target) ->
+    children = current?.data("children")
+    return false unless children
+    target_id = target.attr "id"
+    return children.indexOf(target_id) isnt -1
+
+  _parentId = (section) ->
+    parent = lng.dom("[data-children~=#{section.attr('id')}]")
+    if parent.length then return parent.attr("id")
+    return null
+
+  _isChild = (current, future) ->
+    children = current.data("children")
+    return false unless children
+    target_id = future.attr "id"
+    return children.indexOf(target_id) isnt -1
+
+  _applyDirection = (section, direction) ->
+    isForward = direction.indexOf("in") >= 0
+    apply = false
+    if isForward
+      unless section.hasClass(C.CLASS.SHOW) then apply = true
+    else apply = true
+    if apply
+      section.addClass(C.CLASS.SHOW)
+      section.data(C.ATTRIBUTE.DIRECTION, direction) if section.data(C.TRANSITION.ATTR)
 
   _sameSection = ->
     if not event or not lng.Element.Cache.section then return true

+ 4 - 21
src/modules/Lungo.Section.coffee

@@ -11,8 +11,8 @@ Lungo.Section = do (lng = Lungo) ->
 
   C = lng.Constants
 
-  show = (current, target, backward=false) ->
-    if lng.DEVICE is C.DEVICE.PHONE then _phone target else _tablet current, target, backward
+  show = (current, target) ->
+    if lng.DEVICE is C.DEVICE.PHONE then _phone target else _tablet current, target
     lng.Element.Cache.section = target
 
     active_article = target.find "#{C.ELEMENT.ARTICLE}.#{C.CLASS.ACTIVE}"
@@ -29,25 +29,8 @@ Lungo.Section = do (lng = Lungo) ->
   _phone = (target) ->
     target.addClass(C.CLASS.SHOW)
 
-  _tablet = (current, target, backward) ->
-    target.addClass(C.CLASS.SHOW)
-    if not _targetIsChildren target
-      same_aside = _targetHasSameAside target
-      # console.error "Same aside --> ", same_aside
-      current?.removeClass(C.CLASS.SHOW)
-      lng.Element.Cache.aside?.removeClass("show").removeClass("box")
-      lng.Element.Cache.aside = undefined
-
-  _targetIsChildren = (target) ->
-    children = lng.Element.Cache.section?.data("children")
-    return false unless children
-    target_id = target.attr "id"
-    return children.indexOf(target_id) isnt -1
-
-  _targetHasSameAside = (target) ->
-    current_aside_id = lng.Element.Cache.aside?.attr("id")
-    return false unless current_aside_id
-    return current_aside_id is target.data("aside")
+  _tablet = (current, target) -> @
+
 
 
   show: show

+ 23 - 7
src/stylesheets/lungo.animation.slide.styl

@@ -1,9 +1,7 @@
 @import "__init.styl"
 
-SCALE = .8
-
-section
-  &[data-transition="slide"]
+body[data-device="phone"]
+  & > section[data-transition="slide"]
     &[data-direction="in"]
       z-index: 2
       vendor(animation-name, slideIn)
@@ -17,18 +15,36 @@ section
       z-index: 2
       vendor(animation-name, slideBackOut)
 
+SCALE = .8
 @keyframes slideIn
   from { transform: translateX(100%) }
   to   { transform: translateX(0) }
-
 @keyframes slideOut
   from { transform: scale(1) }
   to   { transform: scale(SCALE) }
-
 @keyframes slideBackOut
   from { transform: translateX(0) }
   to   { transform: translateX(100%) }
-
 @keyframes slideBackIn
   from { transform: scale(SCALE) }
   to   { transform: scale(1) }
+
+
+//============================================================
+// Tablet
+body[data-device="tablet"]
+  & > section[data-transition="slide"]
+    &[data-direction="in"]
+      z-index: 2
+      vendor(animation-name, slideInTablet)
+    &[data-direction="back-out"]
+      z-index: 2
+      vendor(animation-name, slideBackOutTablet)
+
+@keyframes slideInTablet
+  from { transform: translateX(100%); opacity: 0 }
+  to   { transform: translateX(0); opacity: 1 }
+@keyframes slideBackOutTablet
+  from { transform: translateX(0); opacity: 1 }
+  to   { transform: translateX(100%); opacity: 0 }
+