mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-20 12:55:26 +02:00
Starting to add Timeline notifications.
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
module.exports = angular.module('stf.timeline-message', [
|
||||
|
||||
])
|
||||
.directive('timelineMessage', require('./timeline-message-directive'))
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
*/
|
||||
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user