From 3e4c5114a87e11e1d23354054f750bcc7ad0ea7e Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Fri, 28 Aug 2015 13:00:29 +0200 Subject: [PATCH] refactor umb editor navigation directive to follow angular style guide --- .../editor/umbeditornavigation.directive.js | 97 +++++++++++-------- 1 file changed, 54 insertions(+), 43 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditornavigation.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditornavigation.directive.js index b367e5abab..cceb3ac86f 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditornavigation.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditornavigation.directive.js @@ -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); + +})();