var directives = angular.module('core.directives', []);
directives.filter('countBadgeByLevel', function () {
return function (badges) {
// 5 levels
var levels = [0, 0, 0, 0, 0];
angular.forEach(badges, function (value, key) {
levels[value.level - 1]++;
});
return levels;
}
});
directives.filter('isodate', function () {
return function (date) {
return date.toISOString();
}
});
directives.filter('gz', function () {
return function (num) {
if (angular.isArray(num)) {
var out = [];
angular.forEach(num, function (x) {
if (x > 0) {
out.push(x);
}
});
return out;
}
else if (angular.isNumber(num)) {
return num > 0;
}
console.log("fail");
return undefined;
}
});
directives.directive('navbar', function () {
return {
restrict: 'E',
templateUrl: '/apps/core/navbar.html?noCache=' + noCache
};
});
directives.directive('badge', function () {
return {
restrict: 'E',
scope: {
badgeDetail: '=badgeDetail'
},
template: '' +
' {{badgeDetail.badge.name}}' +
' ' +
'' +
' awarded to ' +
'{{badgeDetail.person.name}}. ' +
'More'
}
});
directives.directive('badgeSpan', function () {
var template =
'' +
' {{badge.name}}' +
' ' +
'';
return {
restrict: 'E',
scope: {
badge: '=badge'
},
template: template
}
});
directives.directive('personLink', function () {
return {
restrict: 'E',
scope: {
person: '=person'
},
template: '{{person.name}}'
}
});
directives.directive('avatarXl', function () {
// TODO: set height="" and width=""
// TODO: do not return a useful url unless person.gravatar is set.
return {
restrict: 'E',
scope: {
person: '=person'
},
template: '' +
'' +
''
}
});
directives.directive('dogtagXl', function () {
return {
restrict: 'EACM',
scope: {
person: '=person'
},
templateUrl: '/apps/dogtag-xl.html'
}
});
directives.directive('pager', function () {
return {
restrict: 'A',
scope: {
pager: '=x',
colspan: '=colspan'
},
templateUrl: '/apps/core/pager.html'
}
});
directives.directive('spinner', function () {
return function($scope, element, attr) {
var opts = {
lines: 13, // The number of lines to draw
length: 7, // The length of each line
width: 4, // The line thickness
radius: 10, // The radius of the inner circle
corners: 1, // Corner roundness (0..1)
rotate: 0, // The rotation offset
color: '#000', // #rgb or #rrggbb
speed: 1, // Rounds per second
trail: 60, // Afterglow percentage
shadow: false, // Whether to render a shadow
hwaccel: false, // Whether to use hardware acceleration
className: attr.spinnerClass || 'spinner', // The CSS class to assign to the spinner
zIndex: 2e9, // The z-index (defaults to 2000000000)
top: attr.spinnerTop || 'auto', // Top position relative to parent in px
left: attr.spinnerLeft || 'auto' // Left position relative to parent in px
};
console.log("attr.spinnerTop =", attr.spinnerTop, "attr.spinnerLeft =", attr.spinnerLeft);
var target = element[0];
new Spinner(opts).spin(target);
return target;
}
});