|
|
@@ -21,17 +21,15 @@ Lungo.Router = do (lng = Lungo) ->
|
|
|
@param {string} Id of the <section>
|
|
|
###
|
|
|
section = (section_id) ->
|
|
|
- outPage = lng.Element.Cache.section
|
|
|
- if _notCurrentTarget(outPage, section_id)
|
|
|
+ current = lng.Element.Cache.section
|
|
|
+ if _notCurrentTarget(current, section_id)
|
|
|
query = C.ELEMENT.SECTION + HASHTAG + section_id
|
|
|
- inPage = if outPage then outPage.siblings(query) else lng.dom(query)
|
|
|
- if inPage.length
|
|
|
- if lng.DEVICE is C.DEVICE.PHONE and outPage?
|
|
|
- transition = inPage.data(C.ATTRIBUTE.TRANSITION)
|
|
|
- _setAnimation inPage, "#{transition}In", "active"
|
|
|
- _setAnimation outPage, "#{transition}Out", ""
|
|
|
-
|
|
|
- lng.Section.show outPage, inPage
|
|
|
+ future = if current then current.siblings(query) else lng.dom(query)
|
|
|
+ if future.length
|
|
|
+ if lng.DEVICE is C.DEVICE.PHONE and current?
|
|
|
+ _setSectionDirections future, current
|
|
|
+
|
|
|
+ lng.Section.show current, future
|
|
|
lng.Router.step section_id
|
|
|
do _url unless Lungo.Config.history is false
|
|
|
do _updateNavigationElements
|
|
|
@@ -43,22 +41,19 @@ Lungo.Router = do (lng = Lungo) ->
|
|
|
###
|
|
|
back = ->
|
|
|
do _removeLast
|
|
|
- outPage = lng.Element.Cache.section
|
|
|
+ current = lng.Element.Cache.section
|
|
|
query = C.ELEMENT.SECTION + HASHTAG + history()
|
|
|
- inPage = outPage.siblings(query)
|
|
|
+ future = current.siblings(query)
|
|
|
if lng.DEVICE is C.DEVICE.PHONE
|
|
|
do lng.Aside.hide
|
|
|
- transition = outPage.data(C.ATTRIBUTE.TRANSITION)
|
|
|
- _setAnimation inPage, "#{transition}InBack", "active"
|
|
|
- _setAnimation outPage, "#{transition}OutBack", ""
|
|
|
- if inPage.hasClass("aside") then lng.Aside.toggle()
|
|
|
+ _setSectionDirections future, current, true
|
|
|
+ if future.hasClass("aside") then lng.Aside.toggle()
|
|
|
|
|
|
- lng.Section.show outPage, inPage
|
|
|
+ lng.Section.show current, future
|
|
|
do _url unless Lungo.Config.history is false
|
|
|
do _updateNavigationElements
|
|
|
|
|
|
|
|
|
-
|
|
|
###
|
|
|
Displays the <article> in a particular <section>.
|
|
|
@method article
|
|
|
@@ -99,9 +94,12 @@ Lungo.Router = do (lng = Lungo) ->
|
|
|
###
|
|
|
_notCurrentTarget = (current, id) -> current?.attr(C.ATTRIBUTE.ID) isnt id
|
|
|
|
|
|
- _setAnimation = (section, animation, state) ->
|
|
|
- section.data(C.ATTRIBUTE.STATE, state).data(C.ATTRIBUTE.ANIMATION, animation)
|
|
|
- section.addClass("show").addClass(animation)
|
|
|
+ _setSectionDirections = (future, current, isBack=false) ->
|
|
|
+ dirPrefix = if isBack then "back-" else ""
|
|
|
+ future.addClass(C.CLASS.SHOW)
|
|
|
+ future.data(C.ATTRIBUTE.DIRECTION, "#{dirPrefix}in") if future.data(C.TRANSITION.ATTR)
|
|
|
+ if current.data(C.TRANSITION.ATTR) then current.data(C.ATTRIBUTE.DIRECTION, "#{dirPrefix}out")
|
|
|
+ else current.removeClass(C.CLASS.SHOW)
|
|
|
|
|
|
_url = ->
|
|
|
_hashed_url = ""
|
|
|
@@ -111,136 +109,17 @@ Lungo.Router = do (lng = Lungo) ->
|
|
|
|
|
|
_updateNavigationElements = ->
|
|
|
article_id = lng.Element.Cache.article.attr C.ATTRIBUTE.ID
|
|
|
-
|
|
|
- lng.dom(C.QUERY.ARTICLE_ROUTER).removeClass(C.CLASS.ACTIVE).filter("[data-view-article=#{article_id}]").addClass(C.CLASS.ACTIVE)
|
|
|
-
|
|
|
+ # Active visual signal for elements
|
|
|
+ links = lng.dom(C.QUERY.ARTICLE_ROUTER).removeClass(C.CLASS.ACTIVE)
|
|
|
+ links.filter("[data-view-article=#{article_id}]").addClass(C.CLASS.ACTIVE)
|
|
|
+ # Hide/Show elements in current article
|
|
|
nav = lng.Element.Cache.section.find(C.QUERY.ARTICLE_REFERENCE).addClass C.CLASS.HIDE
|
|
|
nav.filter("[data-article*='#{article_id}']").removeClass C.CLASS.HIDE
|
|
|
|
|
|
_removeLast = -> _history.length -= 1
|
|
|
|
|
|
-
|
|
|
section : section
|
|
|
back : back
|
|
|
article : article
|
|
|
history : history
|
|
|
step : step
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-# Lungo.Router = do(lng = Lungo) ->
|
|
|
-# C = lng.Constants
|
|
|
-# HASHTAG = "#"
|
|
|
-# _history = []
|
|
|
-
|
|
|
-
|
|
|
-# ###
|
|
|
-# Navigate to a <section>.
|
|
|
-# @method section
|
|
|
-# @param {string} Id of the <section>
|
|
|
-# ###
|
|
|
-# section = (section_id) ->
|
|
|
-# current = lng.Element.Cache.section
|
|
|
-# if _notCurrentTarget(current, section_id)
|
|
|
-# query = C.ELEMENT.SECTION + HASHTAG + section_id
|
|
|
-# target = if current then current.siblings(query) else lng.dom(query)
|
|
|
-# if target.length > 0
|
|
|
-# if lng.DEVICE is C.DEVICE.PHONE and current?
|
|
|
-# current.siblings("#{C.ELEMENT.SECTION}.#{C.CLASS.LAST}").removeClass C.CLASS.LAST
|
|
|
-# lng.Section.defineTransition target, current
|
|
|
-# current.removeClass(C.CLASS.SHOW).addClass(C.CLASS.HIDE).addClass(C.CLASS.LAST)
|
|
|
-
|
|
|
-# lng.Section.show current, target
|
|
|
-# lng.Router.step section_id
|
|
|
-# do _url if Lungo.Config.history
|
|
|
-# do _updateNavigationElements
|
|
|
-
|
|
|
-
|
|
|
-# ###
|
|
|
-# Return to previous section.
|
|
|
-# @method back
|
|
|
-# ###
|
|
|
-# back = ->
|
|
|
-# _removeLast()
|
|
|
-# current = lng.Element.Cache.section
|
|
|
-# query = C.ELEMENT.SECTION + HASHTAG + history()
|
|
|
-# target = current.siblings(query)
|
|
|
-# if lng.DEVICE is C.DEVICE.PHONE
|
|
|
-# lng.Aside.hide()
|
|
|
-# lng.Section.assignTransition target, target.data C.TRANSITION.ORIGIN
|
|
|
-# current.removeClass(C.CLASS.SHOW).addClass(C.CLASS.HIDING)
|
|
|
-# setTimeout (->
|
|
|
-# current.removeClass(C.CLASS.HIDING)
|
|
|
-# ), C.TRANSITION.DURATION
|
|
|
-# if target.hasClass("aside") then lng.Aside.toggle()
|
|
|
-
|
|
|
-# lng.Section.show current, target
|
|
|
-# do _url if Lungo.Config.history?
|
|
|
-# do _updateNavigationElements
|
|
|
-
|
|
|
-
|
|
|
-# ###
|
|
|
-# Displays the <article> in a particular <section>.
|
|
|
-# @method article
|
|
|
-# @param {string} <section> Id
|
|
|
-# @param {string} <article> Id
|
|
|
-# ###
|
|
|
-# article = (section_id, article_id, element) ->
|
|
|
-# if _notCurrentTarget(lng.Element.Cache.article, article_id)
|
|
|
-# lng.Router.section section_id
|
|
|
-# target = lng.Element.Cache.section.find "##{article_id}"
|
|
|
-# if target.length > 0
|
|
|
-# lng.Element.Cache.article.removeClass(C.CLASS.ACTIVE).trigger C.TRIGGER.UNLOAD
|
|
|
-# lng.Element.Cache.article = target.addClass(C.CLASS.ACTIVE).trigger(C.TRIGGER.LOAD)
|
|
|
-
|
|
|
-# if element?.data(C.ATTRIBUTE.TITLE)?
|
|
|
-# lng.Element.Cache.section.find(C.QUERY.TITLE).text element.data(C.ATTRIBUTE.TITLE)
|
|
|
-# do _url if Lungo.Config.history
|
|
|
-# do _updateNavigationElements
|
|
|
-
|
|
|
-
|
|
|
-# ###
|
|
|
-# Create a new element to the browsing history based on the current section id.
|
|
|
-# @method step
|
|
|
-# @param {string} Id of the section
|
|
|
-# ###
|
|
|
-# step = (section_id) -> _history.push section_id if section_id isnt history()
|
|
|
-
|
|
|
-# ###
|
|
|
-# Returns the current browsing history section id.
|
|
|
-# @method history
|
|
|
-# @return {string} Current section id
|
|
|
-# ###
|
|
|
-# history = -> _history[_history.length - 1]
|
|
|
-
|
|
|
-
|
|
|
-# ###
|
|
|
-# Private methods
|
|
|
-# ###
|
|
|
-# _notCurrentTarget = (current, id) -> current?.attr(C.ATTRIBUTE.ID) isnt id
|
|
|
-
|
|
|
-# _url = ->
|
|
|
-# _hashed_url = ""
|
|
|
-# _hashed_url += "#{section}/" for section in _history
|
|
|
-# _hashed_url += lng.Element.Cache.article.attr "id"
|
|
|
-# setTimeout (-> window.location.hash = _hashed_url), 0
|
|
|
-
|
|
|
-# _updateNavigationElements = ->
|
|
|
-# article_id = lng.Element.Cache.article.attr C.ATTRIBUTE.ID
|
|
|
-
|
|
|
-# lng.dom(C.QUERY.ARTICLE_ROUTER).removeClass(C.CLASS.ACTIVE).filter("[data-view-article=#{article_id}]").addClass(C.CLASS.ACTIVE)
|
|
|
-
|
|
|
-# nav = lng.Element.Cache.section.find(C.QUERY.ARTICLE_REFERENCE).addClass C.CLASS.HIDE
|
|
|
-# nav.filter("[data-article*='#{article_id}']").removeClass C.CLASS.HIDE
|
|
|
-
|
|
|
-# _removeLast = -> _history.length -= 1
|
|
|
-
|
|
|
-
|
|
|
-# section : section
|
|
|
-# back : back
|
|
|
-# article : article
|
|
|
-# history : history
|
|
|
-# step : step
|