Files
commafeed/src/main/webapp/js/directives.js

212 lines
5.2 KiB
JavaScript
Raw Normal View History

2013-03-21 16:22:58 +01:00
var module = angular.module('commafeed.directives', []);
2013-04-09 11:33:15 +02:00
module.directive('favicon', function() {
return {
restrict : 'E',
scope : {
url : '='
},
replace : true,
2013-04-09 15:02:36 +02:00
template : '<img ng-src="favicon?url={{url}}" class="favicon"></img>'
2013-04-09 12:03:03 +02:00
};
2013-04-09 11:33:15 +02:00
});
module.directive('ngBlur', function() {
2013-04-01 14:30:40 +02:00
return {
restrict : 'A',
link : function(scope, elm, attrs) {
elm.bind('blur', function() {
scope.$apply(attrs.ngBlur);
});
}
};
2013-03-30 20:51:51 +01:00
});
2013-04-22 20:58:18 -05:00
module.directive('scrollTo', ['$timeout', function($timeout) {
2013-03-29 09:11:10 +01:00
return {
restrict : 'A',
link : function(scope, element, attrs) {
scope.$watch(attrs.scrollTo, function(value) {
if (!value)
2013-04-07 07:08:59 +02:00
return;
$timeout(function() {
var docTop = $(window).scrollTop();
2013-04-07 12:01:50 +02:00
var docBottom = docTop + $(window).height();
var elemTop = $(element).offset().top;
var elemBottom = elemTop + $(element).height();
if ((elemTop > docTop) && (elemBottom < docBottom)) {
// element is entirely visible
return;
} else {
var offset = parseInt(attrs.scrollToOffset, 10);
var scrollTop = $(element).offset().top + offset;
$('html, body').animate({
scrollTop : scrollTop
}, 0);
}
2013-04-07 07:08:59 +02:00
});
2013-03-29 09:11:10 +01:00
});
}
};
2013-04-22 20:58:18 -05:00
}]);
2013-03-29 09:11:10 +01:00
2013-04-22 20:58:18 -05:00
module.directive('recursive', ['$compile', 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;
}));
};
}
};
2013-04-22 20:58:18 -05:00
}]);
2013-04-22 20:58:18 -05:00
module.directive('category', ['$compile', function($compile) {
2013-03-21 16:22:58 +01:00
return {
2013-03-27 12:13:56 +01:00
scope : {
node : '=',
selectedType : '=',
selectedId : '=',
feedClick : '&',
categoryClick : '&',
2013-04-09 10:39:02 +02:00
unreadCount : '&',
2013-03-27 12:13:56 +01:00
formatCategoryName : '&',
formatFeedName : '&'
2013-03-21 16:22:58 +01:00
},
restrict : 'E',
2013-03-27 12:13:56 +01:00
replace : true,
templateUrl : 'directives/category.html',
2013-04-18 12:50:44 +02:00
controller : function($scope, $dialog, FeedService, CategoryService,
SettingsService) {
$scope.settingsService = SettingsService;
2013-03-27 12:13:56 +01:00
$scope.unsubscribe = function(subscription) {
2013-03-24 16:39:45 +01:00
var title = 'Unsubscribe';
2013-03-27 12:13:56 +01:00
var msg = 'Unsubscribe from ' + subscription.name + ' ?';
var btns = [ {
result : 'cancel',
label : 'Cancel'
}, {
result : 'ok',
label : 'OK',
cssClass : 'btn-primary'
} ];
$dialog.messageBox(title, msg, btns).open().then(
function(result) {
if (result == 'ok') {
2013-04-18 12:50:44 +02:00
var data = {
id : subscription.id
};
FeedService.unsubscribe(data, function() {
CategoryService.init();
});
2013-03-27 12:13:56 +01:00
}
});
2013-03-28 10:39:03 +01:00
};
2013-04-10 22:02:18 +02:00
$scope.renameFeed = function(feed) {
2013-04-01 15:28:25 +02:00
var name = window.prompt('Rename feed : ', feed.name);
2013-04-01 14:30:40 +02:00
if (name && name != feed.name) {
feed.name = name;
2013-04-18 12:50:44 +02:00
FeedService.rename({
2013-04-01 14:30:40 +02:00
id : feed.id,
name : name
});
}
2013-04-01 15:28:25 +02:00
};
2013-04-01 14:30:40 +02:00
2013-04-10 22:02:18 +02:00
$scope.renameCategory = function(category) {
var name = window.prompt('Rename category: ', category.name);
if (name && name != category.name) {
category.name = name;
2013-04-18 12:50:44 +02:00
CategoryService.rename({
2013-04-10 22:02:18 +02:00
id : category.id,
name : name
});
}
};
$scope.deleteCategory = function(category) {
var title = 'Delete category';
var msg = 'Delete category ' + category.name + ' ?';
var btns = [ {
result : 'cancel',
label : 'Cancel'
}, {
result : 'ok',
label : 'OK',
cssClass : 'btn-primary'
} ];
$dialog.messageBox(title, msg, btns).open().then(
function(result) {
if (result == 'ok') {
2013-04-18 12:50:44 +02:00
CategoryService.remove({
2013-04-10 22:02:18 +02:00
id : category.id
}, function() {
2013-04-18 12:50:44 +02:00
CategoryService.init();
2013-04-10 22:02:18 +02:00
});
}
});
};
2013-03-28 10:39:03 +01:00
$scope.toggleCategory = function(category) {
category.expanded = !category.expanded;
2013-04-18 12:50:44 +02:00
if (category.id == 'all') {
return;
}
CategoryService.collapse({
2013-03-28 10:39:03 +01:00
id : category.id,
collapse : !category.expanded
});
};
2013-03-27 12:13:56 +01:00
}
2013-03-21 16:22:58 +01:00
};
2013-04-22 20:58:18 -05:00
}]);
2013-03-23 23:14:14 +01:00
2013-03-27 13:59:57 +01:00
module.directive('spinner', function() {
return {
scope : {
2013-03-31 11:30:52 +02:00
shown : '='
2013-03-27 13:59:57 +01:00
},
restrict : 'A',
link : function($scope, element) {
element.addClass('spinner');
var opts = {
lines : 11, // The number of lines to draw
length : 5, // The length of each line
width : 3, // The line thickness
radius : 8, // The radius of the inner circle
corners : 1, // Corner roundness (0..1)
rotate : 0, // The rotation offset
color : '#000', // #rgb or #rrggbb
speed : 1.3, // Rounds per second
trail : 60, // Afterglow percentage
shadow : false, // Whether to render a shadow
hwaccel : true, // Whether to use hardware acceleration
zIndex : 2e9, // The z-index (defaults to 2000000000)
2013-03-29 10:44:41 +01:00
top : 'auto', // Top position relative to parent in px
2013-03-27 13:59:57 +01:00
left : 'auto' // Left position relative to parent in px
};
var spinner = new Spinner(opts);
$scope.$watch('shown', function(shown) {
if (shown) {
spinner.spin();
element.append(spinner.el);
} else {
spinner.stop();
}
});
}
2013-03-31 11:30:52 +02:00
};
2013-03-21 16:22:58 +01:00
});