lib/assets/javascripts/up/navigation.js.coffee in upjs-rails-0.7.1 vs lib/assets/javascripts/up/navigation.js.coffee in upjs-rails-0.7.2
- old
+ new
@@ -15,11 +15,11 @@
u = up.util
CLASS_ACTIVE = 'up-active'
CLASS_CURRENT = 'up-current'
- SELECTORS_SECTION = ['a', '[up-href]']
+ SELECTORS_SECTION = ['a', '[up-href]', '[up-alias]']
SELECTOR_SECTION = SELECTORS_SECTION.join(', ')
SELECTOR_SECTION_INSTANT = ("#{selector}[up-instant]" for selector in SELECTORS_SECTION).join(', ')
SELECTOR_ACTIVE = ".#{CLASS_ACTIVE}"
normalizeUrl = (url) ->
@@ -29,28 +29,37 @@
stripTrailingSlash: true
)
sectionUrls = ($section) ->
urls = []
- for attr in ['up-href', 'href']
- if url = u.presentAttr($section, attr)
- url = normalizeUrl(url)
- urls.push(url)
- urls
+ for attr in ['href', 'up-href']
+ if value = u.presentAttr($section, attr)
+ urls.push(value)
+ if aliases = u.presentAttr($section, 'up-alias')
+ values = aliases.split(' ')
+ urls = urls.concat(values)
+ urls.map normalizeUrl
locationChanged = ->
currentUrls = u.stringSet [
normalizeUrl(up.browser.url()),
normalizeUrl(up.modal.source()),
normalizeUrl(up.popup.source())
]
+
+ console.log("current urls",
+ normalizeUrl(up.browser.url()),
+ normalizeUrl(up.modal.source()),
+ normalizeUrl(up.popup.source())
+ )
u.each $(SELECTOR_SECTION), (section) ->
$section = $(section)
# if $section is marked up with up-follow,
# the actual link might be a child element.
urls = sectionUrls($section)
+ console.log("urls %o", urls)
if currentUrls.includesAny(urls)
$section.addClass(CLASS_CURRENT)
else
$section.removeClass(CLASS_CURRENT)
@@ -128,9 +137,10 @@
A link matches the current location (and is marked as `.up-current`) if it matches either:
- the link's `href` attribute
- the link's [`up-href`](/up.link#turn-any-element-into-a-link) attribute
+ - a space-separated list of URLs in the link's `up-alias` attribute
@method [up-current]
@ujs
###
up.bus.on 'fragment:ready', ->