refactor umb editor navigation directive to follow angular style guide

This commit is contained in:
Mads Rasmussen
2015-08-28 13:00:29 +02:00
parent 906524529d
commit 3e4c5114a8

View File

@@ -1,53 +1,64 @@
angular.module("umbraco.directives")
.directive('umbEditorNavigation', function () {
return {
scope: {
navigation: "="
},
restrict: 'E',
replace: true,
templateUrl: 'views/components/editor/umb-editor-navigation.html',
link: function (scope, element, attrs, ctrl) {
(function() {
'use strict';
scope.showNavigation = true;
function EditorNavigationDirective() {
scope.clickNavigationItem = function(selectedItem) {
setItemToActive(selectedItem);
runItemAction(selectedItem);
};
function link(scope, el, attr, ctrl) {
function runItemAction(selectedItem) {
if(selectedItem.action) {
selectedItem.action(selectedItem);
}
}
scope.showNavigation = true;
function setItemToActive(selectedItem) {
// set all other views to inactive
if(selectedItem.view) {
scope.clickNavigationItem = function(selectedItem) {
setItemToActive(selectedItem);
runItemAction(selectedItem);
};
for (var index = 0; index < scope.navigation.length; index++) {
var item = scope.navigation[index];
item.active = false;
}
function runItemAction(selectedItem) {
if (selectedItem.action) {
selectedItem.action(selectedItem);
}
}
// set view to active
selectedItem.active = true;
function setItemToActive(selectedItem) {
// set all other views to inactive
if (selectedItem.view) {
}
}
for (var index = 0; index < scope.navigation.length; index++) {
var item = scope.navigation[index];
item.active = false;
}
function activate() {
// hide navigation if there is only 1 item
if(scope.navigation.length <= 1) {
scope.showNavigation = false;
}
}
activate();
// set view to active
selectedItem.active = true;
}
};
});
}
function activate() {
// hide navigation if there is only 1 item
if (scope.navigation.length <= 1) {
scope.showNavigation = false;
}
}
activate();
}
var directive = {
restrict: 'E',
replace: true,
templateUrl: 'views/components/editor/umb-editor-navigation.html',
scope: {
navigation: "="
},
link: link
};
return directive;
}
angular.module('umbraco.directives.html').directive('umbEditorNavigation', EditorNavigationDirective);
})();