Skip to content

Commit caa96bb

Browse files
Use angular-notification-banner module
1 parent 126cc7a commit caa96bb

File tree

1 file changed

+97
-95
lines changed

1 file changed

+97
-95
lines changed

js/main.js

+97-95
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,101 @@
1-
WantedlyAngularApp.factory("notificationBanner", [
2-
'$rootScope', '$compile', function($rootScope, $compile) {
3-
var defaultContainer, defaultTemplate;
4-
defaultContainer = document.body;
5-
defaultTemplate = "<wt-notification-banner></wt-notification-banner>";
6-
return {
7-
notify: function(args) {
8-
var container, message, messageTemplate, scope, template, templateElement;
9-
if (typeof args !== 'object') {
10-
args = {
11-
message: args
12-
};
13-
}
14-
container = args.container ? args.container : defaultContainer;
15-
template = args.template ? args.template : defaultTemplate;
16-
message = args.message ? args.message : "";
17-
messageTemplate = args.messageTemplate ? args.messageTemplate : null;
18-
scope = args.scope ? args.scope.$new() : $rootScope.$new();
19-
scope.message = message;
20-
scope.messageTemplate = messageTemplate;
21-
scope.delay = args.delay;
22-
if (messageTemplate) {
23-
template = angular.element(template).append(messageTemplate);
24-
}
25-
templateElement = $compile(template)(scope);
26-
angular.element(container).append(templateElement);
27-
return true;
28-
}
29-
};
30-
}
31-
]);
32-
33-
WantedlyAngularApp.directive('wtNotificationBanner', [
34-
'$timeout', '$rootScope', function($timeout, $rootScope) {
35-
return {
36-
restrict: 'E',
37-
transclude: true,
38-
template: '<div class="wt-notification-banner"><div class="fa fa-remove"></div><div ng-show="!messageTemplate">{{ message }}</div><div ng-transclude></div></div>',
39-
link: function(scope, elems, attrs) {
40-
var ANIMATION_END_EVENT, FADEOUT_DELAY_DEFAULT, FADEOUT_DELAY_SLOW, canFadeout, cancelBannerListener, element, fadeout, fadeoutDelay, fadeoutTimer, init, startFadeoutTimer;
41-
FADEOUT_DELAY_DEFAULT = 5000;
42-
FADEOUT_DELAY_SLOW = 10000;
43-
ANIMATION_END_EVENT = 'mozAnimationEnd webkitAnimationEnd animationend';
44-
element = angular.element(elems);
45-
fadeoutTimer = null;
46-
cancelBannerListener = null;
47-
fadeoutDelay = FADEOUT_DELAY_DEFAULT;
48-
canFadeout = true;
49-
startFadeoutTimer = function() {
50-
return fadeoutTimer = $timeout(fadeout, scope.delay || fadeoutDelay);
51-
};
52-
fadeout = function() {
53-
cancelBannerListener();
54-
$timeout.cancel(fadeoutTimer);
55-
element.removeClass("animated fadeInRightBig");
56-
element.addClass("animated fadeOutUpBig");
57-
return element.on(ANIMATION_END_EVENT, function() {
58-
return element.remove();
59-
});
60-
};
61-
scope.remove = function() {
62-
fadeout();
63-
return true;
64-
};
65-
element.on('mouseenter', function() {
66-
return $timeout.cancel(fadeoutTimer);
67-
});
68-
element.on('mouseleave', function() {
69-
if (canFadeout) {
70-
return startFadeoutTimer();
1+
(function () {
2+
angular.module('angular-notification-banner', [])
3+
.factory("notificationBanner", [
4+
'$rootScope', '$compile', function($rootScope, $compile) {
5+
var defaultContainer, defaultTemplate;
6+
defaultContainer = document.body;
7+
defaultTemplate = "<wt-notification-banner></wt-notification-banner>";
8+
return {
9+
notify: function(args) {
10+
var container, message, messageTemplate, scope, template, templateElement;
11+
if (typeof args !== 'object') {
12+
args = {
13+
message: args
14+
};
15+
}
16+
container = args.container ? args.container : defaultContainer;
17+
template = args.template ? args.template : defaultTemplate;
18+
message = args.message ? args.message : "";
19+
messageTemplate = args.messageTemplate ? args.messageTemplate : null;
20+
scope = args.scope ? args.scope.$new() : $rootScope.$new();
21+
scope.message = message;
22+
scope.messageTemplate = messageTemplate;
23+
scope.delay = args.delay;
24+
if (messageTemplate) {
25+
template = angular.element(template).append(messageTemplate);
26+
}
27+
templateElement = $compile(template)(scope);
28+
angular.element(container).append(templateElement);
29+
return true;
7130
}
72-
});
73-
element.on('click', function(e) {
74-
var ref;
75-
if ((ref = e.target.nodeName.toLowerCase()) === "textarea" || ref === "input") {
76-
canFadeout = false;
77-
$timeout.cancel(fadeoutTimer);
78-
}
79-
if (e.target.nodeName.toLowerCase() === "a") {
80-
startFadeoutTimer();
31+
};
32+
}
33+
])
34+
.directive('wtNotificationBanner', [
35+
'$timeout', '$rootScope', function($timeout, $rootScope) {
36+
return {
37+
restrict: 'E',
38+
transclude: true,
39+
template: '<div class="wt-notification-banner"><div class="fa fa-remove"></div><div ng-show="!messageTemplate">{{ message }}</div><div ng-transclude></div></div>',
40+
link: function(scope, elems, attrs) {
41+
var ANIMATION_END_EVENT, FADEOUT_DELAY_DEFAULT, FADEOUT_DELAY_SLOW, canFadeout, cancelBannerListener, element, fadeout, fadeoutDelay, fadeoutTimer, init, startFadeoutTimer;
42+
FADEOUT_DELAY_DEFAULT = 5000;
43+
FADEOUT_DELAY_SLOW = 10000;
44+
ANIMATION_END_EVENT = 'mozAnimationEnd webkitAnimationEnd animationend';
45+
element = angular.element(elems);
46+
fadeoutTimer = null;
47+
cancelBannerListener = null;
48+
fadeoutDelay = FADEOUT_DELAY_DEFAULT;
49+
canFadeout = true;
50+
startFadeoutTimer = function() {
51+
return fadeoutTimer = $timeout(fadeout, scope.delay || fadeoutDelay);
52+
};
53+
fadeout = function() {
54+
cancelBannerListener();
55+
$timeout.cancel(fadeoutTimer);
56+
element.removeClass("animated fadeInRightBig");
57+
element.addClass("animated fadeOutUpBig");
58+
return element.on(ANIMATION_END_EVENT, function() {
59+
return element.remove();
60+
});
61+
};
62+
scope.remove = function() {
63+
fadeout();
64+
return true;
65+
};
66+
element.on('mouseenter', function() {
67+
return $timeout.cancel(fadeoutTimer);
68+
});
69+
element.on('mouseleave', function() {
70+
if (canFadeout) {
71+
return startFadeoutTimer();
72+
}
73+
});
74+
element.on('click', function(e) {
75+
var ref;
76+
if ((ref = e.target.nodeName.toLowerCase()) === "textarea" || ref === "input") {
77+
canFadeout = false;
78+
$timeout.cancel(fadeoutTimer);
79+
}
80+
if (e.target.nodeName.toLowerCase() === "a") {
81+
startFadeoutTimer();
82+
}
83+
return true;
84+
});
85+
scope.$on("wt-notification-banner:cancel", function() {
86+
return startFadeoutTimer();
87+
});
88+
init = function() {
89+
$rootScope.$emit("wt-notification-banner:open");
90+
cancelBannerListener = $rootScope.$on("wt-notification-banner:open", function() {
91+
return fadeout();
92+
});
93+
element.addClass("animated fadeInRightBig");
94+
return startFadeoutTimer();
95+
};
96+
return init();
8197
}
82-
return true;
83-
});
84-
scope.$on("wt-notification-banner:cancel", function() {
85-
return startFadeoutTimer();
86-
});
87-
init = function() {
88-
$rootScope.$emit("wt-notification-banner:open");
89-
cancelBannerListener = $rootScope.$on("wt-notification-banner:open", function() {
90-
return fadeout();
91-
});
92-
element.addClass("animated fadeInRightBig");
93-
return startFadeoutTimer();
9498
};
95-
return init();
9699
}
97-
};
98-
}
99-
]);
100+
]);
101+
} ());

0 commit comments

Comments
 (0)