MediaWiki:Gadget-extJsNotif.js

/** * Exemple, just launch it into your debugger. * var notif = new JsNotice($("#editpage-copywarn2 ul")[0]); * notif.addError("Error", "I can't find my phone !", false, false); * notif.addInfo("Tips", "You're just in front of your computeur.", false, false); * notif.addWarning("Attention", "If i'm wrong, it might be better to see all of that if you're placed in front of your computeur !", true, true); * notif.addSuccess("Good", "You've just realeased all messages XD!", true, false); */

function JsNotice(elem){ this.followedList = elem; if(!$(this.followedList).hasClass("jsnotice")){ $(this.followedList).addClass("jsnotice"); } }

JsNotice.prototype = { /**    * Add an information notice to the list * @param {string} title - Notice title * @param {string} content - Notice content * @param {boolean} showDate - Display the timestamp at the bottom * @param {boolean} fixed - Disable the possibility to close the notice */   addInfo: function (title, content, showDate, fixed){ this.addNotice("info", title, content, showDate, fixed); },   /**     * Add an success notice to the list * @param {string} title - Notice title * @param {string} content - Notice content * @param {boolean} showDate - Display the timestamp at the bottom * @param {boolean} fixed - Disable the possibility to close the notice */   addSuccess: function (title, content, showDate, fixed){ this.addNotice("success", title, content, showDate, fixed); },   /**     * Add an warning notice to the list * @param {string} title - Notice title * @param {string} content - Notice content * @param {boolean} showDate - Display the timestamp at the bottom * @param {boolean} fixed - Disable the possibility to close the notice */   addWarning: function (title, content, showDate, fixed){ this.addNotice("warning", title, content, showDate, fixed); },   /**     * Add an error notice to the list * @param {string} title - Notice title * @param {string} content - Notice content * @param {boolean} showDate - Display the timestamp at the bottom * @param {boolean} fixed - Disable the possibility to close the notice */   addError: function (title, content, showDate, fixed){ this.addNotice("error", title, content, showDate, fixed); },   /**     * Add a notice to the list * @param {string} type - Type of the notice ["info", "success", "warning", "error"] * @param {string} title - Notice title * @param {string} content - Notice content * @param {boolean} showDate - Display the timestamp at the bottom * @param {boolean} fixed - Disable the possibility to close the notice */   addNotice: function(type, title, content, showDate, fixed){ if(typeof type == "string" && typeof title == "string" && typeof content == "string" && typeof fixed == "boolean" && typeof showDate == "boolean"){ var typeList = ["info", "success", "warning", "error"]; if(typeList.indexOf(type) == -1){ throw "Uncorrect type of notice! Please check the documentation above the function."; }

var appendice = ''; if(!fixed){ appendice += '&times; '; }           var icon = ""; switch (type){ case "success": icon = "&#10004; "; break; case "error": icon = "&#10008; "; break; case "warning": icon = "&#10071; "; break; }           appendice += ' ' + icon + title + ' : '; appendice += ' '; appendice += content; if(showDate){ appendice += ' ' + new Date + ' '; }           appendice += ' '; appendice += ''; appendice = $(appendice).hide.fadeIn; $( this.followedList ).append(appendice); }else{ throw "Uncorrect variable format! Please check documentation."; }   } };