mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
use a directive to handle recursive behavior
This commit is contained in:
@@ -1,24 +1,40 @@
|
|||||||
<li> <input type="checkbox" ng-model="node.expanded" ng-click="toggleCategory(node)" />
|
<li>
|
||||||
|
<input type="checkbox" ng-model="node.expanded"
|
||||||
|
ng-click="toggleCategory(node)" />
|
||||||
<label ng-click="categoryClick({id: node.id})"
|
<label ng-click="categoryClick({id: node.id})"
|
||||||
ng-class="{selected: (node.id == selectedId && selectedType == 'category'), unread: unreadCount({category:node})}">{{formatCategoryName({category:node})}}
|
ng-class="{selected: (node.id == selectedId && selectedType == 'category'), unread: unreadCount({category:node})}">{{formatCategoryName({category:node})}}
|
||||||
</label>
|
</label>
|
||||||
<ul>
|
<ul>
|
||||||
<li ng-repeat="feed in node.feeds" ng-mouseenter="hovered=feed" ng-mouseleave="hovered=null" ng-class="{error: feed.message && feed.errorCount > 10}">
|
<recursive>
|
||||||
|
<category ng-repeat="child in node.children"
|
||||||
|
node="child" feed-click="feedClick({id:id})"
|
||||||
|
category-click="categoryClick({id:id})" selected-type="selectedType"
|
||||||
|
selected-id="selectedId"
|
||||||
|
format-category-name="formatCategoryName({category:category})"
|
||||||
|
format-feed-name="formatFeedName({feed:feed})"
|
||||||
|
unread-count="unreadCount({category:category})">
|
||||||
|
</category>
|
||||||
|
</recursive>
|
||||||
|
<li ng-repeat="feed in node.feeds" ng-mouseenter="hovered=feed"
|
||||||
|
ng-mouseleave="hovered=null"
|
||||||
|
ng-class="{error: feed.message && feed.errorCount > 10}">
|
||||||
<div class="dropdown pull-right">
|
<div class="dropdown pull-right">
|
||||||
<a dropdown-toggle class="pull-right"><i ng-show="hovered==feed" class="icon icon-chevron-down"></i> </a>
|
<a dropdown-toggle class="pull-right">
|
||||||
|
<i ng-show="hovered==feed" class="icon icon-chevron-down"></i>
|
||||||
|
</a>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
<li>
|
<li>
|
||||||
<a ng-click="rename(feed)">Rename</a>
|
<a ng-click="rename(feed)">Rename</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a ng-click="unsubscribe(feed)">Unsubscribe</a>
|
<a ng-click="unsubscribe(feed)">Unsubscribe</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<a ng-click="feedClick({id: feed.id})" class="feed-link"
|
<a ng-click="feedClick({id: feed.id})" class="feed-link"
|
||||||
ng-class="{selected: (feed.id == selectedId && selectedType == 'feed'), unread: feed.unread }">
|
ng-class="{selected: (feed.id == selectedId && selectedType == 'feed'), unread: feed.unread }">
|
||||||
<favicon url="feed.feedUrl" />
|
<favicon url="feed.feedUrl" />
|
||||||
{{formatFeedName({feed:feed})}}
|
{{formatFeedName({feed:feed})}}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -117,17 +117,17 @@ module.controller('CategoryTreeCtrl', function($scope, $timeout, $stateParams,
|
|||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
};
|
};
|
||||||
|
|
||||||
var rootUnreadCount = function() {
|
var rootUnreadCount = function() {
|
||||||
return $scope.unreadCount($scope.SubscriptionService.subscriptions);
|
return $scope.unreadCount($scope.SubscriptionService.subscriptions);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.$watch(rootUnreadCount, function(value) {
|
$scope.$watch(rootUnreadCount, function(value) {
|
||||||
var label = 'CommaFeed';
|
var label = 'CommaFeed';
|
||||||
if (value > 0) {
|
if (value > 0) {
|
||||||
label = value + ' - ' + label;
|
label = value + ' - ' + label;
|
||||||
}
|
}
|
||||||
$window.document.title = label;
|
$window.document.title = label;
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.formatCategoryName = function(category) {
|
$scope.formatCategoryName = function(category) {
|
||||||
@@ -349,7 +349,7 @@ module.controller('FeedListCtrl', function($scope, $stateParams, $http, $route,
|
|||||||
} else {
|
} else {
|
||||||
$scope.isOpen = !$scope.isOpen;
|
$scope.isOpen = !$scope.isOpen;
|
||||||
}
|
}
|
||||||
if($scope.isOpen) {
|
if ($scope.isOpen) {
|
||||||
$scope.mark(entry, true);
|
$scope.mark(entry, true);
|
||||||
}
|
}
|
||||||
$scope.current = entry;
|
$scope.current = entry;
|
||||||
@@ -423,7 +423,7 @@ module.controller('FeedListCtrl', function($scope, $stateParams, $http, $route,
|
|||||||
openPreviousEntry(e);
|
openPreviousEntry(e);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.$on('markAll', function(event, args) {
|
$scope.$on('markAll', function(event, args) {
|
||||||
EntryService.mark({
|
EntryService.mark({
|
||||||
type : $scope.selectedType,
|
type : $scope.selectedType,
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ module.directive('scrollTo', function($timeout) {
|
|||||||
restrict : 'A',
|
restrict : 'A',
|
||||||
link : function(scope, element, attrs) {
|
link : function(scope, element, attrs) {
|
||||||
scope.$watch(attrs.scrollTo, function(value) {
|
scope.$watch(attrs.scrollTo, function(value) {
|
||||||
if (!value)
|
if (!value)
|
||||||
return;
|
return;
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
var docTop = $(window).scrollTop();
|
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) {
|
module.directive('category', function($compile) {
|
||||||
return {
|
return {
|
||||||
scope : {
|
scope : {
|
||||||
@@ -67,16 +86,6 @@ module.directive('category', function($compile) {
|
|||||||
restrict : 'E',
|
restrict : 'E',
|
||||||
replace : true,
|
replace : true,
|
||||||
templateUrl : 'directives/category.html',
|
templateUrl : 'directives/category.html',
|
||||||
link : function(scope, element) {
|
|
||||||
var ul = element.find('ul');
|
|
||||||
var html = '<category ng-repeat="child in node.children" node="child" feed-click="feedClick({id:id})" ';
|
|
||||||
html = html + 'category-click="categoryClick({id:id})" selected-type="selectedType" selected-id="selectedId" ';
|
|
||||||
html = html + 'format-category-name="formatCategoryName({category:category})" format-feed-name="formatFeedName({feed:feed})" ';
|
|
||||||
html = html + 'unread-count="unreadCount({category:category})">';
|
|
||||||
html = html + '</category>';
|
|
||||||
ul.prepend(html);
|
|
||||||
$compile(ul.contents())(scope);
|
|
||||||
},
|
|
||||||
controller : function($scope, $dialog, SubscriptionService) {
|
controller : function($scope, $dialog, SubscriptionService) {
|
||||||
$scope.unsubscribe = function(subscription) {
|
$scope.unsubscribe = function(subscription) {
|
||||||
var title = 'Unsubscribe';
|
var title = 'Unsubscribe';
|
||||||
|
|||||||
Reference in New Issue
Block a user