lib/assets/javascripts/up/navigation.js.coffee in upjs-rails-0.8.0 vs lib/assets/javascripts/up/navigation.js.coffee in upjs-rails-0.8.1

- old
+ new

@@ -13,12 +13,30 @@ ### up.navigation = (-> u = up.util + ###* + Sets default options for this module. + + @method up.navigation.defaults + @param {Number} [options.currentClass] + The class to set on [links that point the current location](#up-current). + ### + config = u.config + currentClass: 'up-current' + + reset = -> + config.reset() + + currentClass = -> + klass = config.currentClass + unless u.contains(klass, 'up-current') + klass += ' up-current' + klass + CLASS_ACTIVE = 'up-active' - CLASS_CURRENT = 'up-current' 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}" @@ -65,20 +83,22 @@ normalizeUrl(up.browser.url()), normalizeUrl(up.modal.source()), normalizeUrl(up.popup.source()) ]) + klass = currentClass() + 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) if currentUrls.matchesAny(urls) - $section.addClass(CLASS_CURRENT) + $section.addClass(klass) else - $section.removeClass(CLASS_CURRENT) + $section.removeClass(klass) ###* Links that are currently loading are assigned the `up-active` class automatically. Style `.up-active` in your CSS to improve the perceived responsiveness of your user interface. @@ -183,7 +203,12 @@ # this changes which URLs we consider currents. # Also modals and popups restore their previous history # once they close. if $fragment.is('.up-modal, .up-popup') locationChanged() + + # The framework is reset between tests + up.bus.on 'framework:reset', reset + + defaults: config.update )()