2 * Copyright 2013 IBM Corp.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 RED.notify = (function() {
17 var currentNotifications = [];
19 return function(msg,type,fixed,timeout) {
20 if (currentNotifications.length > 4) {
21 var ll = currentNotifications.length;
22 for (var i = 0;ll > 4 && i<currentNotifications.length;i+=1) {
23 var notifiction = currentNotifications[i];
24 if (!notifiction.fixed) {
25 window.clearTimeout(notifiction.timeoutid);
31 var n = document.createElement("div");
32 n.id="red-notification-"+c;
33 n.className = "alert";
36 n.className = "alert alert-"+type;
38 n.style.display = "none";
40 $("#notifications").append(n);
42 n.close = (function() {
45 currentNotifications.splice(currentNotifications.indexOf(nn),1);
46 $(nn).slideUp(300, function() {
47 nn.parentNode.removeChild(nn);
52 n.timeoutid = window.setTimeout(n.close,timeout||3000);
54 currentNotifications.push(n);