//General popup ~ singleton //dependencies: jquery 1.10+ var Modal = function(options){ var $popup = $(".modal"), $header = $popup.find(".header"), $content = $popup.find(".content"), $footer = $popup.find('footer'); this.options = { buttons: { "showOK" : false, "showCancel" : false } } options && $.extend(this.options, options); this.$header = $header.find(".header-text"); this.$content_header = $content.find(".question"); this.$content_text = $content.find(".text"); this.$content_other_html = $content.find(".other_html"); this.$footer = $footer.find(".footer-text"); Modal.prototype.setHeader = function(text){ //can be a type of content like ERROR, INFORMATION, QUESTION, etc this.$header.text(text); return this; } Modal.prototype.setContentHeader = function(qtext){ //can set a secondary header/title like , a question or something general this.$content_header.text(qtext); return this; } Modal.prototype.setContentText = function(text){ // can set a text for the content section, we can have some details for it this.$content_text.html(text); return this; } Modal.prototype.setOtherHtml = function(html){ //can set some html code like ajax loader, etc this.$content_other_html.html(html); return this; } Modal.prototype.setFooter = function(text){ //set the footer text this.$footer.text(text); return this; } Modal.prototype.getPopupReference = function(){ return $popup; } Modal.prototype.init = function(options){ console.log("Modal - Init"); if(options){ options.type && this.$header.text(options.type); options.content_head && this.$content_header.text(options.content_head); options.content_text && this.$content_text.text(options.content_text); options.footer && this.$footer.text(options.footer); } } Modal.prototype.addListener = function(method){ if(typeof method == "function") method(); } //clear elements and listeners Modal.prototype.clearEverything = function(){ this.$header.html(); this.$content_header.html(); this.$content_text.html(); this.$content_other_html.html(); this.$footer.html(); } if(arguments.callee._singletonInstance) return arguments.callee._singletonInstance; arguments.callee._singletonInstance = this; }