nw-page-nav-item.js 1.1 KB

1234567891011121314151617181920212223242526272829
  1. angular.module('NoteWrangler').directive('nwPageNavItem', function($location) {
  2. return {
  3. replace: true,
  4. restrict: "E",
  5. scope: {},
  6. transclude: true,
  7. templateUrl: '/templates/directives/nw-page-nav-item.html',
  8. link: function(scope, element, attrs, ctrl, transclude) {
  9. // Perform a manual transclude here so we can get the page name from the contents
  10. // of the pageNav item.
  11. transclude(function(clonedElement) {
  12. scope.pageName = clonedElement.text().toLowerCase();
  13. element.append(clonedElement);
  14. });
  15. // This regex finds the first part of a url ex:
  16. // /notes/2/edit returns notes
  17. //
  18. // \/([^\/]*)\/?
  19. // ^ Look for 0 or 1 of an escaped `/` to ensure we don't go past the first url item
  20. // ^ look for an unlimited number of all characters except for `/`, capture the result (the '^' within `[]` part excludes all following characters)
  21. // ^ escaped `/`
  22. scope.selected = function() {
  23. return $location.path().match(/\/([^\/]*)\/?/)[1];
  24. };
  25. }
  26. };
  27. });