From 4cce3c6f1bc9a89d26fd3ed574448ccba6860155 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Fri, 28 Aug 2015 13:02:53 +0200 Subject: [PATCH] refactor umb editor sub views directive to follow angular style guide --- .../editor/umbeditorsubviews.directive.js | 69 +++++++++++-------- 1 file changed, 40 insertions(+), 29 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorsubviews.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorsubviews.directive.js index 64b80412f5..db0dad8de7 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorsubviews.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorsubviews.directive.js @@ -1,37 +1,48 @@ -angular.module("umbraco.directives") - .directive('umbEditorSubViews', function () { - return { - restrict: 'E', - replace: true, - templateUrl: 'views/components/editor/umb-editor-sub-views.html', - scope: { - subViews: "=", - model: "=" - }, - link: function (scope, element, attrs, ctrl) { +(function() { + 'use strict'; - scope.activeView = {}; + function EditorSubViewsDirective() { - // set toolbar from selected navigation item - function setActiveView(items) { + function link(scope, el, attr, ctrl) { - for (var index = 0; index < items.length; index++) { + scope.activeView = {}; - var item = items[index]; + // set toolbar from selected navigation item + function setActiveView(items) { - if(item.active && item.view) { - scope.activeView = item; - } - } - } + for (var index = 0; index < items.length; index++) { - // watch for navigation changes - scope.$watch('subViews', function(newValue, oldValue) { - if (newValue) { - setActiveView(newValue); - } - },true); + var item = items[index]; + if (item.active && item.view) { + scope.activeView = item; + } } - }; - }); \ No newline at end of file + } + + // watch for navigation changes + scope.$watch('subViews', function(newValue, oldValue) { + if (newValue) { + setActiveView(newValue); + } + }, true); + + } + + var directive = { + restrict: 'E', + replace: true, + templateUrl: 'views/components/editor/umb-editor-sub-views.html', + scope: { + subViews: "=", + model: "=" + }, + link: link + }; + + return directive; + } + + angular.module('umbraco.directives').directive('umbEditorSubViews', EditorSubViewsDirective); + +})();