2016-07-02 02:11:17 +02:00
|
|
|
define(function(){
|
|
|
|
return function(el,controller){
|
2016-07-04 18:03:22 +02:00
|
|
|
var fallback = true;
|
|
|
|
if (!("Notification" in window)){
|
|
|
|
} else if(Notification.permission === 'granted') {
|
|
|
|
fallback = false;
|
|
|
|
} else if(Notification.permission !== 'denied') {
|
|
|
|
Notification.requestPermission(function (permission) {
|
|
|
|
fallback = (permission !== "granted");
|
|
|
|
});
|
|
|
|
}
|
2016-07-02 02:11:17 +02:00
|
|
|
|
2016-07-04 18:03:22 +02:00
|
|
|
if(fallback){
|
|
|
|
var main = document.createElement("div"),
|
|
|
|
text = document.createElement("span"),
|
|
|
|
link = document.createElement("a");
|
|
|
|
main.classList.add("popup");
|
2016-07-02 02:11:17 +02:00
|
|
|
|
2016-07-04 18:03:22 +02:00
|
|
|
main.appendChild(text);
|
2016-07-02 02:11:17 +02:00
|
|
|
|
2016-07-04 18:03:22 +02:00
|
|
|
link.textContent = "Edit";
|
|
|
|
main.appendChild(link);
|
2016-07-02 02:11:17 +02:00
|
|
|
|
2016-07-04 18:03:22 +02:00
|
|
|
el.appendChild(main);
|
2016-07-02 02:11:17 +02:00
|
|
|
|
2016-07-04 18:03:22 +02:00
|
|
|
var timer;
|
|
|
|
}
|
2016-07-02 02:11:17 +02:00
|
|
|
return {
|
|
|
|
storageNotifyNew: function(key,data){
|
2016-07-04 18:03:22 +02:00
|
|
|
var str = "New Node '"+key+"'!";
|
|
|
|
console.log("notify:",str);
|
|
|
|
if(fallback){
|
|
|
|
main.classList.add("show");
|
|
|
|
text.textContent = str;
|
|
|
|
clearTimeout(timer);
|
|
|
|
timer = setTimeout(function(){
|
|
|
|
main.classList.remove("show");
|
|
|
|
}, 5000);
|
|
|
|
link.onclick = function(){
|
|
|
|
window.location.href = "#map/"+key;
|
|
|
|
controller.render(key);
|
|
|
|
main.classList.remove("show");
|
|
|
|
};
|
|
|
|
}else{
|
|
|
|
var notification = new Notification(str);
|
|
|
|
notification.onclick = function(){
|
|
|
|
window.location.href = "#map/"+key;
|
|
|
|
controller.render(key);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
saved: function(key){
|
|
|
|
var str = "Node '"+key+"' saved!";
|
|
|
|
console.log("notify:",str);
|
|
|
|
if(fallback){
|
|
|
|
main.classList.add("show");
|
|
|
|
text.textContent = str;
|
|
|
|
clearTimeout(timer);
|
|
|
|
timer = setTimeout(function(){
|
|
|
|
main.classList.remove("show");
|
|
|
|
}, 500);
|
|
|
|
link.style = "display:none;";
|
|
|
|
}else{
|
|
|
|
var notification = new Notification(str);
|
|
|
|
}
|
2016-07-02 02:11:17 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|