2013-12-20 16:31:41 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the Doodle3D project (http://doodle3d.com).
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013, Doodle3D
|
|
|
|
* This software is licensed under the terms of the GNU GPL v2 or later.
|
|
|
|
* See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
|
|
|
*/
|
|
|
|
|
2013-10-18 19:11:10 +02:00
|
|
|
function Message() {
|
2014-03-06 13:43:08 +01:00
|
|
|
|
2013-10-18 19:11:10 +02:00
|
|
|
Message.ERROR = "error";
|
|
|
|
Message.WARNING = "warning";
|
|
|
|
Message.NOTICE = "notice";
|
|
|
|
Message.INFO = "info";
|
2014-03-06 13:43:08 +01:00
|
|
|
|
2013-10-18 19:11:10 +02:00
|
|
|
this.mode = "";
|
2014-03-06 13:43:08 +01:00
|
|
|
|
2013-10-18 19:11:10 +02:00
|
|
|
this.$element;
|
2014-03-06 13:43:08 +01:00
|
|
|
|
2013-10-18 19:11:10 +02:00
|
|
|
var self = this;
|
2013-10-23 15:33:10 +02:00
|
|
|
var autoHideDelay = 5000;
|
2013-10-18 19:11:10 +02:00
|
|
|
var autohideTimeout;
|
2014-03-06 13:43:08 +01:00
|
|
|
|
2013-10-18 19:11:10 +02:00
|
|
|
this.init = function($element) {
|
|
|
|
this.$element = $element;
|
|
|
|
}
|
2014-03-06 13:43:08 +01:00
|
|
|
this.set = function(contents,mode,autoHide,disableEffect) {
|
|
|
|
console.log("Message:set: ",contents,mode,autoHide,disableEffect);
|
2013-12-19 17:33:06 +01:00
|
|
|
if(disableEffect) {
|
2014-03-06 13:43:08 +01:00
|
|
|
self.fill(contents,mode,autoHide)
|
2013-12-19 17:33:06 +01:00
|
|
|
} else{
|
|
|
|
self.hide(function() {
|
|
|
|
self.show();
|
2014-03-06 13:43:08 +01:00
|
|
|
self.fill(contents,mode,autoHide)
|
2013-12-19 17:33:06 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2014-03-06 13:43:08 +01:00
|
|
|
this.fill = function(contents,mode,autoHide) {
|
2013-12-19 17:33:06 +01:00
|
|
|
//console.log("Message:fill: ",text,mode,autoHide);
|
|
|
|
self.clear();
|
2014-03-06 13:43:08 +01:00
|
|
|
self.$element.html(contents);
|
2013-12-19 17:33:06 +01:00
|
|
|
self.$element.addClass(mode);
|
|
|
|
self.mode = mode;
|
|
|
|
clearTimeout(autohideTimeout);
|
|
|
|
if(autoHide) {
|
|
|
|
autohideTimeout = setTimeout(function(){ self.hide()},autoHideDelay);
|
|
|
|
}
|
2013-10-18 19:11:10 +02:00
|
|
|
}
|
|
|
|
this.clear = function($element) {
|
2014-03-06 13:43:08 +01:00
|
|
|
this.$element.html("");
|
2013-10-18 19:11:10 +02:00
|
|
|
this.$element.removeClass(this.mode);
|
|
|
|
}
|
2014-03-06 13:43:08 +01:00
|
|
|
|
2013-10-18 19:11:10 +02:00
|
|
|
this.show = function() {
|
|
|
|
this.$element.fadeIn(200);
|
|
|
|
}
|
|
|
|
this.hide = function(complete) {
|
|
|
|
this.$element.fadeOut(200,complete);
|
|
|
|
}
|
2013-12-20 16:31:41 +01:00
|
|
|
}
|