From f442fb573ad9aa706954ee898a22beb6909413b7 Mon Sep 17 00:00:00 2001 From: Athou Date: Wed, 10 Apr 2013 12:07:46 +0200 Subject: [PATCH] use a directive to handle recursive behavior --- src/main/webapp/directives/category.html | 46 ++++++++++++++++-------- src/main/webapp/js/controllers.js | 10 +++--- src/main/webapp/js/directives.js | 31 ++++++++++------ 3 files changed, 56 insertions(+), 31 deletions(-) diff --git a/src/main/webapp/directives/category.html b/src/main/webapp/directives/category.html index c5494d68..70609384 100644 --- a/src/main/webapp/directives/category.html +++ b/src/main/webapp/directives/category.html @@ -1,24 +1,40 @@ -
  • +
  • + + + + + {{formatFeedName({feed:feed})}}
  • diff --git a/src/main/webapp/js/controllers.js b/src/main/webapp/js/controllers.js index 1e87ad86..b571b9d2 100644 --- a/src/main/webapp/js/controllers.js +++ b/src/main/webapp/js/controllers.js @@ -117,17 +117,17 @@ module.controller('CategoryTreeCtrl', function($scope, $timeout, $stateParams, } return count; }; - + var rootUnreadCount = function() { return $scope.unreadCount($scope.SubscriptionService.subscriptions); }; - + $scope.$watch(rootUnreadCount, function(value) { var label = 'CommaFeed'; if (value > 0) { label = value + ' - ' + label; } - $window.document.title = label; + $window.document.title = label; }); $scope.formatCategoryName = function(category) { @@ -349,7 +349,7 @@ module.controller('FeedListCtrl', function($scope, $stateParams, $http, $route, } else { $scope.isOpen = !$scope.isOpen; } - if($scope.isOpen) { + if ($scope.isOpen) { $scope.mark(entry, true); } $scope.current = entry; @@ -423,7 +423,7 @@ module.controller('FeedListCtrl', function($scope, $stateParams, $http, $route, openPreviousEntry(e); }); }); - + $scope.$on('markAll', function(event, args) { EntryService.mark({ type : $scope.selectedType, diff --git a/src/main/webapp/js/directives.js b/src/main/webapp/js/directives.js index aacf401a..f7af89ec 100644 --- a/src/main/webapp/js/directives.js +++ b/src/main/webapp/js/directives.js @@ -27,7 +27,7 @@ module.directive('scrollTo', function($timeout) { restrict : 'A', link : function(scope, element, attrs) { scope.$watch(attrs.scrollTo, function(value) { - if (!value) + if (!value) return; $timeout(function() { var docTop = $(window).scrollTop(); @@ -52,6 +52,25 @@ module.directive('scrollTo', function($timeout) { }; }); +module.directive('recursive', function($compile) { + return { + restrict : 'E', + priority : 100000, + compile : function(tElement, tAttr) { + var contents = tElement.contents().remove(); + var compiledContents; + return function(scope, iElement, iAttr) { + if (!compiledContents) { + compiledContents = $compile(contents); + } + iElement.append(compiledContents(scope, function(clone) { + return clone; + })); + }; + } + }; +}); + module.directive('category', function($compile) { return { scope : { @@ -67,16 +86,6 @@ module.directive('category', function($compile) { restrict : 'E', replace : true, templateUrl : 'directives/category.html', - link : function(scope, element) { - var ul = element.find('ul'); - var html = ''; - html = html + ''; - ul.prepend(html); - $compile(ul.contents())(scope); - }, controller : function($scope, $dialog, SubscriptionService) { $scope.unsubscribe = function(subscription) { var title = 'Unsubscribe';