Notification = {} Notification.NoticationController = function(oHtmlElement, sEvent, fCondition, ajaxRequest) { // alert(oHtmlElement); this.htmlElement = oHtmlElement; this.event = sEvent; this.condition = fCondition; this.ajaxRequest = ajaxRequest; this._interval = null; this.notificationDisplayer = null; } Notification.NoticationController.prototype.init = function(){ this.htmlElement.notification = this; this.htmlElement.callBack = this.callBack; //this.htmlElement.addEventListener(this.event, function(){ $(this.htmlElement).on(this.event, function(){ //this = input HTML if (this.notification.condition()) { if (!this.notification.ajaxRequest.getReturned()) { var tempHtmlElement = this; this.notification.ajaxRequest.execute(this.notification.getRequestCallBack(this.notification)); } else { if (this.notification.notificationDisplayer.displayedNotification != this.notification) { this.notification.postCallBack(); } } } }); } Notification.NoticationController.prototype.getRequestCallBack=function(elem) { return function (text) { elem.notificationDisplayer.clearContent(); elem.notificationDisplayer.addContent(text); elem.notificationDisplayer.displayedNotification = this; elem.notificationDisplayer.pop(); } } Notification.NoticationController.prototype.callBack = function(oHtmlElement){ if (oHtmlElement.notification.ajaxRequest.getReturned()) { clearInterval(oHtmlElement.notification._interval); oHtmlElement.notification.postCallBack(); } } Notification.NoticationController.prototype.postCallBack = function(){ this.notificationDisplayer.clearContent(); this.notificationDisplayer.addContent(this.ajaxRequest.getReturnedText()); this.notificationDisplayer.displayedNotification = this; this.notificationDisplayer.pop(); } function checkInterval(oHtmlElement) { oHtmlElement.notification.callBack(oHtmlElement); }