var Message = Class.create({ type: 0, text: "", initialize: function(type, text){ if (typeof type != "undefined") this.type = type; if (typeof text != "undefined") this.text = text; }, GetType: function(){ return (typeof(this.type) == "undefined" ? "Unknown type" : Message.Types[this.type]); }, GetText: function(){ return this.text; }, toString: function(){ return ("Message:\ntype=" + this.GetType() + "\ntext=" + this.GetText()); }, Serialize: function(serializer){ serializer.BeginType("Message"); serializer.Serialize(Number(this.type)); serializer.Serialize(String(this.text)); serializer.EndType("Message"); }, Restore: function(restorer) { restorer.BeginType("Message"); this.type = restorer.Restore(); this.text = restorer.Restore(); restorer.EndType("Message"); } }); var MessageList = Class.create({ initialize: function(){ this.messages_ = new Array(); }, GetMessages: function(){ return this.messages_; }, AddMessage: function(msg){ this.messages_.push(msg); }, Clear: function(){ this.messages_.clear(); }, Serialize: function(serializer){ serializer.BeginType("list"); this.messages_.invoke("Serialize", serializer); serializer.EndType("list"); }, Restore: function(restorer){ this.messages_.clear(); restorer.BeginType("list"); while (restorer.GetType() == "Message") this.messages_.push(restorer.Restore()); restorer.EndType("list"); }, toString: function(){ return this.messages_.invoke("toString").join(", "); } }); Message.Types = ["MESSAGE", "WARNING", "EXCEPTION"]; var Herald = Class.create({ messages: [], visible: false, htmlCreated: false, container: null, parentType: "none", Show: function(){ if (!this.container) return; var contentsWidth = Element.getWidth(this.container); var documentWidth = Element.getWidth(document.body); Element.setStyle(this.container, { "left": Math.max(.5 * (documentWidth - contentsWidth), 0) + "px", "visibility": "inherit" }); }, Hide: function(){ if (!this.container) return; Element.setStyle(this.container, {"visibility": "hidden"}); }, Append: function(heraldContainer){ document.body.appendChild(heraldContainer); }, initialize: function(params){ if (typeof(params) == "undefined") return; if (typeof(params.parentContainer) != "undefined"){ var parentContainer = $(params.parentContainer); if (!parentContainer) return; this.parentType = "element"; this.Append = function(heraldContainer){ parentContainer.appendChild(heraldContainer); }; this.Show = function(){ Element.setStyle(parentContainer, {"display": ""}); }; this.Hide = function(){ Element.setStyle(parentContainer, {"display": "none"}); }; return; } if (typeof(params.Append) == "function" && typeof(params.Show) == "function" && typeof(params.Hide) == "function"){ this.parentType = "object"; this.Append = params.Append.bind(params); this.Show = params.Show.bind(params); this.Hide = params.Hide.bind(params); } }, addMessage: function(message){ var li = new Element("li"); // alert(message.type + " " + message.GetType()) li.appendChild(new Element("input", {"type": "button", "class": message.GetType()})); li.appendChild(document.createTextNode(message.GetText())); this.createHTML(); this.container.appendChild(li); this.messages.push({"message": message, "htmlNodes": [li]}); this.show(true); if(message.sound) { // var sound=new Element("audio", {"id": this.ID()+"_sound", "src": "/SOS.mp3"}); // sound.addEventListener("canplay", function(){ //alert("canplay!") //sound.play(); // }); // sound.autoplay=true; // if(sound.canPlayType) { // check for HTML5 audio support // var files=String(message.sound).split(';'); // for(var i=0; i