var MessageController = Backbone.Model.extend({ options: {}, container: {}, initialize: function(options) { var that = this; $.extend(true, that.options, options); }, addContainer: function(name, container) { var that = this; var id = 'messageContainer-' + name; var c = $('
'); $(container).append(c); that.container[name] = c; }, addMessage: function(containerName, text, type, time, show) { var that = this; if (that.options.enable) { var m = $(''); $(that.container[containerName]).append(m); if (show == undefined) { show = 'slow'; } $(m).show(show); that._addRemoveTimer(m, time); return m; } else { return null; } }, changeMessage: function(message, text, type, time) { var that = this; if (that.options.enable) { $(message).text(text); $(message).removeClass('message-type-info'); $(message).removeClass('message-type-loading'); $(message).removeClass('message-type-warning'); $(message).addClass('message-type-' + type); that._addRemoveTimer(message, time); } }, _addRemoveTimer: function(m, time) { if (parseInt(time) > 0) { var timefunc = function() { $(m).hide(400, function() { $(m).remove(); }); }; setTimeout(timefunc, time); } } });