mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-07-06 01:49:29 +02:00
feat(messages): add directive messageTo, to show a icon link to send message
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
angular.module('core')
|
||||
.directive('messageTo', messageTo);
|
||||
|
||||
messageTo.$inject = ['$compile', '$translate'];
|
||||
|
||||
function messageTo($compile, $translate) {
|
||||
var directive = {
|
||||
restrict: 'A',
|
||||
link: link
|
||||
};
|
||||
|
||||
return directive;
|
||||
|
||||
function link(scope, element, attrs) {
|
||||
scope.$watch(attrs.messageTo, function (s) {
|
||||
var user = s;
|
||||
var to = user._id + '|' + user.username;
|
||||
var title = $translate.instant('MESSAGE_TO_ICON_TITLE');
|
||||
var e = $compile('<a href="#"><i class="glyphicon glyphicon-envelope" ng-click="$event.stopPropagation();" ui-sref="messages.send({to: \'' + to + '\'})"></i></a>')(scope);
|
||||
|
||||
e.attr('title', title);
|
||||
|
||||
if (attrs.toClass) {
|
||||
e.addClass(attrs.toClass);
|
||||
} else {
|
||||
e.css('font-size', '12px');
|
||||
e.css('margin-left', '10px');
|
||||
}
|
||||
|
||||
if (element[0].firstChild) {
|
||||
if (element[0].firstChild.nodeName === '#text') {
|
||||
angular.element(element[0].firstChild).after(e);
|
||||
}
|
||||
} else {
|
||||
angular.element(element[0]).append(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}());
|
||||
Reference in New Issue
Block a user