Last active
May 3, 2016 20:25
-
-
Save baruchvlz/a8075884dd262e569f918f7e43149da4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
div(id="breadcrumbs") | |
span(ng-repeat="breadcrumb in breadcrumbs") | |
#[button(ui-sref="{{breadcrumb.path}}", class="link") {{breadcrumb.name}}]/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = [`$rootScope`, `$state`, `$compile`, | |
($rootScope, $state, $compile) => { | |
return { | |
restrict: `E`, | |
link: (scope, ele, attr) => { | |
const createBreadCrumbObject = array => { | |
let newArray = [] | |
const pushObj = (name, path) => { | |
return { | |
name: name, | |
path: path | |
} | |
} | |
const checkForQuery = string => { | |
var stringArr = string.split('') | |
if(stringArr.indexOf('?') !== -1){ | |
return string.replace(/\?(.*)/, '') | |
} | |
return string | |
} | |
for(let i = 0; i < array.length; i++){ | |
array[i] = checkForQuery(array[i]) | |
if(i === 0){ | |
newArray.push(pushObj(array[i], array[i])) | |
} | |
else{ | |
let pathStr = `` | |
for(let j = 0; j < i; j++){ | |
if (pathStr.length === 0) | |
pathStr = `${newArray[j].path}.${array[j+1]}` | |
else | |
pathStr = `${pathStr}.${array[j+1]}` | |
} | |
newArray.push(pushObj(array[i], pathStr)) | |
} | |
} | |
return newArray | |
} | |
$rootScope.$on(`$stateChangeSuccess`, | |
(event, toState, toParams, fromState, fromParams) => { | |
let url = toState.name.split(`.`) | |
scope.breadcrumbs = createBreadCrumbObject(url) | |
} | |
) | |
}, | |
templateUrl: `./../../templates/directives/breadcrumbs.html` | |
} | |
}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment