Starting to add Timeline notifications.

This commit is contained in:
Gunther Brunner
2014-05-12 17:47:19 +09:00
parent 7f94b0beef
commit e4e5109533
14 changed files with 253 additions and 37 deletions

View File

@@ -0,0 +1,4 @@
module.exports = angular.module('stf.timeline-message', [
])
.directive('timelineMessage', require('./timeline-message-directive'))

View File

@@ -0,0 +1,41 @@
module.exports = function timelineMessageDirective(Timelines, $sce, $interpolate) {
var defaults = {
message: '',
type: 'info',
ttl: 5000
}
return {
restrict: 'AE',
replace: true,
template: '',
transclude: true,
link: function (scope, iElem, iAttrs, ctrls, transcludeFn) {
var options = angular.extend({}, defaults, scope.$eval(iAttrs.timelineMessage))
transcludeFn(function (elem, scope) {
var e,
html,
interpolateFn,
safeHtml;
// Create temporary wrapper element so we can grab the inner html
e = angular.element(document.createElement('div'))
e.append(elem)
html = e.html()
// Interpolate expressions in current scope
interpolateFn = $interpolate(html)
html = interpolateFn(scope)
// Tell Angular the HTML can be trusted so it can be used in ng-bind-html
safeHtml = $sce.trustAsHtml(html)
// Add notification
Timelines.add(safeHtml, options.type, options.ttl)
})
}
}
}

View File

@@ -0,0 +1,23 @@
describe('timelineMessage', function () {
beforeEach(module('stf.timeline-message'));
var scope, compile;
beforeEach(inject(function ($rootScope, $compile) {
scope = $rootScope.$new();
compile = $compile;
}));
it('should ...', function () {
/*
To test your directive, you need to create some html that would use your directive,
send that through compile() then compare the results.
var element = compile('<div timeline-message name="name">hi</div>')(scope);
expect(element.text()).toBe('hello, world');
*/
});
});