vendor/assets/javascripts/messenger.js in messengerjs-rails-1.4.1 vs vendor/assets/javascripts/messenger.js in messengerjs-rails-1.5.0

- old
+ new

@@ -1,319 +1,319 @@ -/*! messenger 1.4.1 */ +/*! messenger 1.5.0 */ /* * This file begins the output concatenated into messenger.js * * It establishes the Messenger object while preserving whatever it was before * (for noConflict), and making it a callable function. */ -(function(){ - var _prevMessenger = window.Messenger; - var localMessenger; +(function () { + var _prevMessenger = window.Messenger; + var localMessenger; - localMessenger = window.Messenger = function(){ - return localMessenger._call.apply(this, arguments); - } + localMessenger = window.Messenger = function () { + return localMessenger._call.apply(this, arguments); + } - window.Messenger.noConflict = function(){ - window.Messenger = _prevMessenger; + window.Messenger.noConflict = function () { + window.Messenger = _prevMessenger; - return localMessenger; - } + return localMessenger; + } })(); /* * This file contains shims for when Underscore and Backbone * are not included. * * Portions taken from Underscore.js and Backbone.js * Both of which are Copyright (c) 2009-2013 Jeremy Ashkenas, DocumentCloud */ -window.Messenger._ = (function() { - if (window._) - return window._ +window.Messenger._ = (function () { + if (window._) + return window._ - var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype; + var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype; - // Create quick reference variables for speed access to core prototypes. - var push = ArrayProto.push, - slice = ArrayProto.slice, - concat = ArrayProto.concat, - toString = ObjProto.toString, - hasOwnProperty = ObjProto.hasOwnProperty; + // Create quick reference variables for speed access to core prototypes. + var push = ArrayProto.push, + slice = ArrayProto.slice, + concat = ArrayProto.concat, + toString = ObjProto.toString, + hasOwnProperty = ObjProto.hasOwnProperty; - // All **ECMAScript 5** native function implementations that we hope to use - // are declared here. - var - nativeForEach = ArrayProto.forEach, - nativeMap = ArrayProto.map, - nativeReduce = ArrayProto.reduce, - nativeReduceRight = ArrayProto.reduceRight, - nativeFilter = ArrayProto.filter, - nativeEvery = ArrayProto.every, - nativeSome = ArrayProto.some, - nativeIndexOf = ArrayProto.indexOf, - nativeLastIndexOf = ArrayProto.lastIndexOf, - nativeIsArray = Array.isArray, - nativeKeys = Object.keys, - nativeBind = FuncProto.bind; + // All **ECMAScript 5** native function implementations that we hope to use + // are declared here. + var + nativeForEach = ArrayProto.forEach, + nativeMap = ArrayProto.map, + nativeReduce = ArrayProto.reduce, + nativeReduceRight = ArrayProto.reduceRight, + nativeFilter = ArrayProto.filter, + nativeEvery = ArrayProto.every, + nativeSome = ArrayProto.some, + nativeIndexOf = ArrayProto.indexOf, + nativeLastIndexOf = ArrayProto.lastIndexOf, + nativeIsArray = Array.isArray, + nativeKeys = Object.keys, + nativeBind = FuncProto.bind; - // Create a safe reference to the Underscore object for use below. - var _ = {}; + // Create a safe reference to the Underscore object for use below. + var _ = {}; - // Establish the object that gets returned to break out of a loop iteration. - var breaker = {}; - - var each = _.each = _.forEach = function(obj, iterator, context) { - if (obj == null) return; - if (nativeForEach && obj.forEach === nativeForEach) { - obj.forEach(iterator, context); - } else if (obj.length === +obj.length) { - for (var i = 0, l = obj.length; i < l; i++) { - if (iterator.call(context, obj[i], i, obj) === breaker) return; - } - } else { - for (var key in obj) { - if (_.has(obj, key)) { - if (iterator.call(context, obj[key], key, obj) === breaker) return; - } - } + // Establish the object that gets returned to break out of a loop iteration. + var breaker = {}; + + var each = _.each = _.forEach = function (obj, iterator, context) { + if (obj == null) return; + if (nativeForEach && obj.forEach === nativeForEach) { + obj.forEach(iterator, context); + } else if (obj.length === +obj.length) { + for (var i = 0, l = obj.length; i < l; i++) { + if (iterator.call(context, obj[i], i, obj) === breaker) return; + } + } else { + for (var key in obj) { + if (_.has(obj, key)) { + if (iterator.call(context, obj[key], key, obj) === breaker) return; } - }; + } + } + }; - _.result = function(object, property) { - if (object == null) return null; - var value = object[property]; - return _.isFunction(value) ? value.call(object) : value; - }; + _.result = function (object, property) { + if (object == null) return null; + var value = object[property]; + return _.isFunction(value) ? value.call(object) : value; + }; - _.once = function(func) { - var ran = false, memo; - return function() { - if (ran) return memo; - ran = true; - memo = func.apply(this, arguments); - func = null; - return memo; - }; + _.once = function (func) { + var ran = false, memo; + return function () { + if (ran) return memo; + ran = true; + memo = func.apply(this, arguments); + func = null; + return memo; }; + }; - var idCounter = 0; - _.uniqueId = function(prefix) { - var id = ++idCounter + ''; - return prefix ? prefix + id : id; - }; + var idCounter = 0; + _.uniqueId = function (prefix) { + var id = ++idCounter + ''; + return prefix ? prefix + id : id; + }; - _.filter = _.select = function(obj, iterator, context) { - var results = []; - if (obj == null) return results; - if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context); - each(obj, function(value, index, list) { - if (iterator.call(context, value, index, list)) results[results.length] = value; - }); - return results; - }; - - // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp. - each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) { - _['is' + name] = function(obj) { - return toString.call(obj) == '[object ' + name + ']'; - }; + _.filter = _.select = function (obj, iterator, context) { + var results = []; + if (obj == null) return results; + if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context); + each(obj, function (value, index, list) { + if (iterator.call(context, value, index, list)) results[results.length] = value; }); + return results; + }; - _.defaults = function(obj) { - each(slice.call(arguments, 1), function(source) { - if (source) { - for (var prop in source) { - if (obj[prop] == null) obj[prop] = source[prop]; - } - } - }); - return obj; + // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp. + each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function (name) { + _['is' + name] = function (obj) { + return toString.call(obj) == '[object ' + name + ']'; }; + }); - _.extend = function(obj) { - each(slice.call(arguments, 1), function(source) { - if (source) { - for (var prop in source) { - obj[prop] = source[prop]; - } - } - }); - return obj; - }; + _.defaults = function (obj) { + each(slice.call(arguments, 1), function (source) { + if (source) { + for (var prop in source) { + if (obj[prop] == null) obj[prop] = source[prop]; + } + } + }); + return obj; + }; - _.keys = nativeKeys || function(obj) { - if (obj !== Object(obj)) throw new TypeError('Invalid object'); - var keys = []; - for (var key in obj) if (_.has(obj, key)) keys[keys.length] = key; - return keys; - }; + _.extend = function (obj) { + each(slice.call(arguments, 1), function (source) { + if (source) { + for (var prop in source) { + obj[prop] = source[prop]; + } + } + }); + return obj; + }; - _.bind = function(func, context) { - if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1)); - var args = slice.call(arguments, 2); - return function() { - return func.apply(context, args.concat(slice.call(arguments))); - }; - }; + _.keys = nativeKeys || function (obj) { + if (obj !== Object(obj)) throw new TypeError('Invalid object'); + var keys = []; + for (var key in obj) if (_.has(obj, key)) keys[keys.length] = key; + return keys; + }; - _.isObject = function(obj) { - return obj === Object(obj); + _.bind = function (func, context) { + if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1)); + var args = slice.call(arguments, 2); + return function () { + return func.apply(context, args.concat(slice.call(arguments))); }; + }; - return _; + _.isObject = function (obj) { + return obj === Object(obj); + }; + + return _; })(); -window.Messenger.Events = (function() { - if (window.Backbone && Backbone.Events) { - return Backbone.Events; - } +window.Messenger.Events = (function () { + if (window.Backbone && Backbone.Events) { + return Backbone.Events; + } - var eventsShim = function() { - var eventSplitter = /\s+/; + var eventsShim = function () { + var eventSplitter = /\s+/; - var eventsApi = function(obj, action, name, rest) { - if (!name) return true; - if (typeof name === 'object') { - for (var key in name) { - obj[action].apply(obj, [key, name[key]].concat(rest)); - } - } else if (eventSplitter.test(name)) { - var names = name.split(eventSplitter); - for (var i = 0, l = names.length; i < l; i++) { - obj[action].apply(obj, [names[i]].concat(rest)); - } - } else { - return true; - } - }; + var eventsApi = function (obj, action, name, rest) { + if (!name) return true; + if (typeof name === 'object') { + for (var key in name) { + obj[action].apply(obj, [key, name[key]].concat(rest)); + } + } else if (eventSplitter.test(name)) { + var names = name.split(eventSplitter); + for (var i = 0, l = names.length; i < l; i++) { + obj[action].apply(obj, [names[i]].concat(rest)); + } + } else { + return true; + } + }; - var triggerEvents = function(events, args) { - var ev, i = -1, l = events.length; - switch (args.length) { - case 0: while (++i < l) (ev = events[i]).callback.call(ev.ctx); - return; - case 1: while (++i < l) (ev = events[i]).callback.call(ev.ctx, args[0]); - return; - case 2: while (++i < l) (ev = events[i]).callback.call(ev.ctx, args[0], args[1]); - return; - case 3: while (++i < l) (ev = events[i]).callback.call(ev.ctx, args[0], args[1], args[2]); - return; - default: while (++i < l) (ev = events[i]).callback.apply(ev.ctx, args); - } - }; + var triggerEvents = function (events, args) { + var ev, i = -1, l = events.length; + switch (args.length) { + case 0: while (++i < l) (ev = events[i]).callback.call(ev.ctx); + return; + case 1: while (++i < l) (ev = events[i]).callback.call(ev.ctx, args[0]); + return; + case 2: while (++i < l) (ev = events[i]).callback.call(ev.ctx, args[0], args[1]); + return; + case 3: while (++i < l) (ev = events[i]).callback.call(ev.ctx, args[0], args[1], args[2]); + return; + default: while (++i < l) (ev = events[i]).callback.apply(ev.ctx, args); + } + }; - var Events = { + var Events = { - on: function(name, callback, context) { - if (!(eventsApi(this, 'on', name, [callback, context]) && callback)) return this; - this._events || (this._events = {}); - var list = this._events[name] || (this._events[name] = []); - list.push({callback: callback, context: context, ctx: context || this}); - return this; - }, + on: function (name, callback, context) { + if (!(eventsApi(this, 'on', name, [callback, context]) && callback)) return this; + this._events || (this._events = {}); + var list = this._events[name] || (this._events[name] = []); + list.push({ callback: callback, context: context, ctx: context || this }); + return this; + }, - once: function(name, callback, context) { - if (!(eventsApi(this, 'once', name, [callback, context]) && callback)) return this; - var self = this; - var once = _.once(function() { - self.off(name, once); - callback.apply(this, arguments); - }); - once._callback = callback; - this.on(name, once, context); - return this; - }, + once: function (name, callback, context) { + if (!(eventsApi(this, 'once', name, [callback, context]) && callback)) return this; + var self = this; + var once = _.once(function () { + self.off(name, once); + callback.apply(this, arguments); + }); + once._callback = callback; + this.on(name, once, context); + return this; + }, - off: function(name, callback, context) { - var list, ev, events, names, i, l, j, k; - if (!this._events || !eventsApi(this, 'off', name, [callback, context])) return this; - if (!name && !callback && !context) { - this._events = {}; - return this; - } + off: function (name, callback, context) { + var list, ev, events, names, i, l, j, k; + if (!this._events || !eventsApi(this, 'off', name, [callback, context])) return this; + if (!name && !callback && !context) { + this._events = {}; + return this; + } - names = name ? [name] : _.keys(this._events); - for (i = 0, l = names.length; i < l; i++) { - name = names[i]; - if (list = this._events[name]) { - events = []; - if (callback || context) { - for (j = 0, k = list.length; j < k; j++) { - ev = list[j]; - if ((callback && callback !== ev.callback && - callback !== ev.callback._callback) || - (context && context !== ev.context)) { - events.push(ev); - } - } - } - this._events[name] = events; - } + names = name ? [name] : _.keys(this._events); + for (i = 0, l = names.length; i < l; i++) { + name = names[i]; + if (list = this._events[name]) { + events = []; + if (callback || context) { + for (j = 0, k = list.length; j < k; j++) { + ev = list[j]; + if ((callback && callback !== ev.callback && + callback !== ev.callback._callback) || + (context && context !== ev.context)) { + events.push(ev); } + } + } + this._events[name] = events; + } + } - return this; - }, + return this; + }, - trigger: function(name) { - if (!this._events) return this; - var args = Array.prototype.slice.call(arguments, 1); - if (!eventsApi(this, 'trigger', name, args)) return this; - var events = this._events[name]; - var allEvents = this._events.all; - if (events) triggerEvents(events, args); - if (allEvents) triggerEvents(allEvents, arguments); - return this; - }, + trigger: function (name) { + if (!this._events) return this; + var args = Array.prototype.slice.call(arguments, 1); + if (!eventsApi(this, 'trigger', name, args)) return this; + var events = this._events[name]; + var allEvents = this._events.all; + if (events) triggerEvents(events, args); + if (allEvents) triggerEvents(allEvents, arguments); + return this; + }, - listenTo: function(obj, name, callback) { - var listeners = this._listeners || (this._listeners = {}); - var id = obj._listenerId || (obj._listenerId = _.uniqueId('l')); - listeners[id] = obj; - obj.on(name, typeof name === 'object' ? this : callback, this); - return this; - }, + listenTo: function (obj, name, callback) { + var listeners = this._listeners || (this._listeners = {}); + var id = obj._listenerId || (obj._listenerId = _.uniqueId('l')); + listeners[id] = obj; + obj.on(name, typeof name === 'object' ? this : callback, this); + return this; + }, - stopListening: function(obj, name, callback) { - var listeners = this._listeners; - if (!listeners) return; - if (obj) { - obj.off(name, typeof name === 'object' ? this : callback, this); - if (!name && !callback) delete listeners[obj._listenerId]; - } else { - if (typeof name === 'object') callback = this; - for (var id in listeners) { - listeners[id].off(name, callback, this); - } - this._listeners = {}; - } - return this; - } - }; - - Events.bind = Events.on; - Events.unbind = Events.off; - return Events; + stopListening: function (obj, name, callback) { + var listeners = this._listeners; + if (!listeners) return; + if (obj) { + obj.off(name, typeof name === 'object' ? this : callback, this); + if (!name && !callback) delete listeners[obj._listenerId]; + } else { + if (typeof name === 'object') callback = this; + for (var id in listeners) { + listeners[id].off(name, callback, this); + } + this._listeners = {}; + } + return this; + } }; - return eventsShim(); + + Events.bind = Events.on; + Events.unbind = Events.off; + return Events; + }; + return eventsShim(); })(); -(function() { +(function () { var $, ActionMessenger, BaseView, Events, RetryingMessage, _, _Message, _Messenger, _ref, _ref1, _ref2, __hasProp = {}.hasOwnProperty, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + __extends = function (child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, __slice = [].slice, - __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; + __indexOf = [].indexOf || function (item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; $ = jQuery; _ = (_ref = window._) != null ? _ref : window.Messenger._; Events = (_ref1 = typeof Backbone !== "undefined" && Backbone !== null ? Backbone.Events : void 0) != null ? _ref1 : window.Messenger.Events; - BaseView = (function() { + BaseView = (function () { function BaseView(options) { $.extend(this, Events); if (_.isObject(options)) { if (options.el) { @@ -322,16 +322,16 @@ this.model = options.model; } this.initialize.apply(this, arguments); } - BaseView.prototype.setElement = function(el) { + BaseView.prototype.setElement = function (el) { this.$el = $(el); return this.el = this.$el[0]; }; - BaseView.prototype.delegateEvents = function(events) { + BaseView.prototype.delegateEvents = function (events) { var delegateEventSplitter, eventName, key, match, method, selector, _results; if (!(events || (events = _.result(this, "events")))) { return; } this.undelegateEvents(); @@ -357,11 +357,11 @@ } } return _results; }; - BaseView.prototype.jqon = function(eventName, selector, method) { + BaseView.prototype.jqon = function (eventName, selector, method) { var _ref2; if (this.$el.on != null) { return (_ref2 = this.$el).on.apply(_ref2, arguments); } else { if (!(method != null)) { @@ -374,58 +374,59 @@ return this.$el.bind(eventName, method); } } }; - BaseView.prototype.jqoff = function(eventName) { + BaseView.prototype.jqoff = function (eventName) { var _ref2; if (this.$el.off != null) { return (_ref2 = this.$el).off.apply(_ref2, arguments); } else { this.$el.undelegate(); return this.$el.unbind(eventName); } }; - BaseView.prototype.undelegateEvents = function() { + BaseView.prototype.undelegateEvents = function () { return this.jqoff(".delegateEvents" + this.cid); }; - BaseView.prototype.remove = function() { + BaseView.prototype.remove = function () { this.undelegateEvents(); return this.$el.remove(); }; return BaseView; })(); - _Message = (function(_super) { + _Message = (function (_super) { __extends(_Message, _super); function _Message() { return _Message.__super__.constructor.apply(this, arguments); } _Message.prototype.defaults = { hideAfter: 10, scroll: true, - closeButtonText: "&times;" + closeButtonText: "&times;", + escapeText: false }; - _Message.prototype.initialize = function(opts) { + _Message.prototype.initialize = function (opts) { if (opts == null) { opts = {}; } this.shown = false; this.rendered = false; this.messenger = opts.messenger; return this.options = $.extend({}, this.options, opts, this.defaults); }; - _Message.prototype.show = function() { + _Message.prototype.show = function () { var wasShown; if (!this.rendered) { this.render(); } this.$message.removeClass('messenger-hidden'); @@ -434,11 +435,11 @@ if (!wasShown) { return this.trigger('show'); } }; - _Message.prototype.hide = function() { + _Message.prototype.hide = function () { var wasShown; if (!this.rendered) { return; } this.$message.addClass('messenger-hidden'); @@ -447,15 +448,15 @@ if (wasShown) { return this.trigger('hide'); } }; - _Message.prototype.cancel = function() { + _Message.prototype.cancel = function () { return this.hide(); }; - _Message.prototype.update = function(opts) { + _Message.prototype.update = function (opts) { var _ref2, _this = this; if (_.isString(opts)) { opts = { message: opts @@ -472,30 +473,30 @@ if (this.options.hideAfter) { this.$message.addClass('messenger-will-hide-after'); if (this._hideTimeout != null) { clearTimeout(this._hideTimeout); } - this._hideTimeout = setTimeout(function() { + this._hideTimeout = setTimeout(function () { return _this.hide(); }, this.options.hideAfter * 1000); } else { this.$message.removeClass('messenger-will-hide-after'); } if (this.options.hideOnNavigate) { this.$message.addClass('messenger-will-hide-on-navigate'); if ((typeof Backbone !== "undefined" && Backbone !== null ? Backbone.history : void 0) != null) { - Backbone.history.on('route', function() { + Backbone.history.on('route', function () { return _this.hide(); }); } } else { this.$message.removeClass('messenger-will-hide-on-navigate'); } return this.trigger('update', this); }; - _Message.prototype.scrollTo = function() { + _Message.prototype.scrollTo = function () { if (!this.options.scroll) { return; } return $.scrollTo(this.$el, { duration: 400, @@ -504,38 +505,38 @@ top: -20 } }); }; - _Message.prototype.timeSinceUpdate = function() { + _Message.prototype.timeSinceUpdate = function () { if (this.lastUpdate) { return (new Date) - this.lastUpdate; } else { return null; } }; - _Message.prototype.actionsToEvents = function() { + _Message.prototype.actionsToEvents = function () { var act, name, _ref2, _results, _this = this; _ref2 = this.options.actions; _results = []; for (name in _ref2) { act = _ref2[name]; - _results.push(this.events["click [data-action=\"" + name + "\"] a"] = (function(act) { - return function(e) { + _results.push(this.events["click [data-action=\"" + name + "\"] a"] = (function (act) { + return function (e) { e.preventDefault(); e.stopPropagation(); _this.trigger("action:" + name, act, e); return act.action.call(_this, e, _this); }; })(act)); } return _results; }; - _Message.prototype.checkClickable = function() { + _Message.prototype.checkClickable = function () { var evt, name, _ref2, _results; _ref2 = this.events; _results = []; for (name in _ref2) { evt = _ref2[name]; @@ -546,17 +547,17 @@ } } return _results; }; - _Message.prototype.undelegateEvents = function() { + _Message.prototype.undelegateEvents = function () { var _ref2; _Message.__super__.undelegateEvents.apply(this, arguments); return (_ref2 = this.$message) != null ? _ref2.removeClass('messenger-clickable') : void 0; }; - _Message.prototype.parseActions = function() { + _Message.prototype.parseActions = function () { var act, actions, n_act, name, _ref2, _ref3; actions = []; _ref2 = this.options.actions; for (name in _ref2) { act = _ref2[name]; @@ -568,24 +569,32 @@ actions.push(n_act); } return actions; }; - _Message.prototype.template = function(opts) { + _Message.prototype.template = function (opts) { var $action, $actions, $cancel, $link, $message, $text, action, _i, _len, _ref2, _this = this; $message = $("<div class='messenger-message message alert " + opts.type + " message-" + opts.type + " alert-" + opts.type + "'>"); if (opts.showCloseButton) { $cancel = $('<button type="button" class="messenger-close" data-dismiss="alert">'); $cancel.html(opts.closeButtonText); - $cancel.click(function() { + $cancel.click(function () { + var _base; _this.cancel(); + if (typeof (_base = _this.options).onClickClose === "function") { + _base.onClickClose(); + } return true; }); $message.append($cancel); } - $text = $("<div class=\"messenger-message-inner\">" + opts.message + "</div>"); + if (opts.escapeText) { + $text = $('<div class="messenger-message-inner"></div>').text(opts.message); + } else { + $text = $("<div class=\"messenger-message-inner\">" + opts.message + "</div>"); + } $message.append($text); if (opts.actions.length) { $actions = $('<div class="messenger-actions">'); } _ref2 = opts.actions; @@ -601,11 +610,11 @@ } $message.append($actions); return $message; }; - _Message.prototype.render = function() { + _Message.prototype.render = function () { var opts; if (this.rendered) { return; } if (!this._hasSlot) { @@ -624,43 +633,43 @@ return _Message; })(BaseView); - RetryingMessage = (function(_super) { + RetryingMessage = (function (_super) { __extends(RetryingMessage, _super); function RetryingMessage() { return RetryingMessage.__super__.constructor.apply(this, arguments); } - RetryingMessage.prototype.initialize = function() { + RetryingMessage.prototype.initialize = function () { RetryingMessage.__super__.initialize.apply(this, arguments); return this._timers = {}; }; - RetryingMessage.prototype.cancel = function() { + RetryingMessage.prototype.cancel = function () { this.clearTimers(); this.hide(); if ((this._actionInstance != null) && (this._actionInstance.abort != null)) { return this._actionInstance.abort(); } }; - RetryingMessage.prototype.clearTimers = function() { + RetryingMessage.prototype.clearTimers = function () { var name, timer, _ref2, _ref3; _ref2 = this._timers; for (name in _ref2) { timer = _ref2[name]; clearTimeout(timer); } this._timers = {}; return (_ref3 = this.$message) != null ? _ref3.removeClass('messenger-retry-soon messenger-retry-later') : void 0; }; - RetryingMessage.prototype.render = function() { + RetryingMessage.prototype.render = function () { var action, name, _ref2, _results; RetryingMessage.__super__.render.apply(this, arguments); this.clearTimers(); _ref2 = this.options.actions; _results = []; @@ -673,19 +682,19 @@ } } return _results; }; - RetryingMessage.prototype.renderPhrase = function(action, time) { + RetryingMessage.prototype.renderPhrase = function (action, time) { var phrase; phrase = action.phrase.replace('TIME', this.formatTime(time)); return phrase; }; - RetryingMessage.prototype.formatTime = function(time) { + RetryingMessage.prototype.formatTime = function (time) { var pluralize; - pluralize = function(num, str) { + pluralize = function (num, str) { num = Math.floor(num); if (num !== 1) { str = str + 's'; } return 'in ' + num + ' ' + str; @@ -702,11 +711,11 @@ } time /= 60; return pluralize(time, 'hour'); }; - RetryingMessage.prototype.startCountdown = function(name, action) { + RetryingMessage.prototype.startCountdown = function (name, action) { var $phrase, remaining, tick, _ref2, _this = this; if (this._timers[name] != null) { return; } @@ -717,11 +726,11 @@ this.$message.addClass('messenger-retry-soon'); } else { this.$message.removeClass('messenger-retry-soon'); this.$message.addClass('messenger-retry-later'); } - tick = function() { + tick = function () { var delta; $phrase.text(_this.renderPhrase(action, remaining)); if (remaining > 0) { delta = Math.min(remaining, 1); remaining -= delta; @@ -737,11 +746,11 @@ return RetryingMessage; })(_Message); - _Messenger = (function(_super) { + _Messenger = (function (_super) { __extends(_Messenger, _super); function _Messenger() { return _Messenger.__super__.constructor.apply(this, arguments); @@ -753,49 +762,49 @@ _Messenger.prototype.messageDefaults = { type: 'info' }; - _Messenger.prototype.initialize = function(options) { + _Messenger.prototype.initialize = function (options) { this.options = options != null ? options : {}; this.history = []; return this.messageDefaults = $.extend({}, this.messageDefaults, this.options.messageDefaults); }; - _Messenger.prototype.render = function() { + _Messenger.prototype.render = function () { return this.updateMessageSlotClasses(); }; - _Messenger.prototype.findById = function(id) { - return _.filter(this.history, function(rec) { + _Messenger.prototype.findById = function (id) { + return _.filter(this.history, function (rec) { return rec.msg.options.id === id; }); }; - _Messenger.prototype._reserveMessageSlot = function(msg) { + _Messenger.prototype._reserveMessageSlot = function (msg) { var $slot, dmsg, _this = this; $slot = $('<li>'); $slot.addClass('messenger-message-slot'); this.$el.prepend($slot); this.history.push({ msg: msg, $slot: $slot }); this._enforceIdConstraint(msg); - msg.on('update', function() { + msg.on('update', function () { return _this._enforceIdConstraint(msg); }); while (this.options.maxMessages && this.history.length > this.options.maxMessages) { dmsg = this.history.shift(); dmsg.msg.remove(); dmsg.$slot.remove(); } return $slot; }; - _Messenger.prototype._enforceIdConstraint = function(msg) { + _Messenger.prototype._enforceIdConstraint = function (msg) { var entry, _i, _len, _msg, _ref2; if (msg.options.id == null) { return; } _ref2 = this.history; @@ -811,29 +820,29 @@ } } } }; - _Messenger.prototype.newMessage = function(opts) { + _Messenger.prototype.newMessage = function (opts) { var msg, _ref2, _ref3, _ref4, _this = this; if (opts == null) { opts = {}; } opts.messenger = this; _Message = (_ref2 = (_ref3 = Messenger.themes[(_ref4 = opts.theme) != null ? _ref4 : this.options.theme]) != null ? _ref3.Message : void 0) != null ? _ref2 : RetryingMessage; msg = new _Message(opts); - msg.on('show', function() { + msg.on('show', function () { if (opts.scrollTo && _this.$el.css('position') !== 'fixed') { return msg.scrollTo(); } }); msg.on('hide show render', this.updateMessageSlotClasses, this); return msg; }; - _Messenger.prototype.updateMessageSlotClasses = function() { + _Messenger.prototype.updateMessageSlotClasses = function () { var anyShown, last, rec, willBeFirst, _i, _len, _ref2; willBeFirst = true; last = null; anyShown = false; _ref2 = this.history; @@ -854,22 +863,22 @@ last.$slot.addClass('messenger-last'); } return this.$el["" + (anyShown ? 'remove' : 'add') + "Class"]('messenger-empty'); }; - _Messenger.prototype.hideAll = function() { + _Messenger.prototype.hideAll = function () { var rec, _i, _len, _ref2, _results; _ref2 = this.history; _results = []; for (_i = 0, _len = _ref2.length; _i < _len; _i++) { rec = _ref2[_i]; _results.push(rec.msg.hide()); } return _results; }; - _Messenger.prototype.post = function(opts) { + _Messenger.prototype.post = function (opts) { var msg; if (_.isString(opts)) { opts = { message: opts }; @@ -882,11 +891,11 @@ return _Messenger; })(BaseView); - ActionMessenger = (function(_super) { + ActionMessenger = (function (_super) { __extends(ActionMessenger, _super); function ActionMessenger() { return ActionMessenger.__super__.constructor.apply(this, arguments); @@ -902,11 +911,11 @@ allow: true }, action: $.ajax }; - ActionMessenger.prototype.hookBackboneAjax = function(msgr_opts) { + ActionMessenger.prototype.hookBackboneAjax = function (msgr_opts) { var _ajax, _this = this; if (msgr_opts == null) { msgr_opts = {}; } @@ -917,11 +926,11 @@ id: 'BACKBONE_ACTION', errorMessage: false, successMessage: "Request completed successfully.", showSuccessWithoutError: false }); - _ajax = function(options) { + _ajax = function (options) { var sync_msgr_opts; sync_msgr_opts = _.extend({}, msgr_opts, options.messenger); return _this["do"](sync_msgr_opts, options); }; if (Backbone.ajax != null) { @@ -932,32 +941,32 @@ msgr_opts.action = Backbone.ajax; } _ajax._withoutMessenger = Backbone.ajax; return Backbone.ajax = _ajax; } else { - return Backbone.sync = _.wrap(Backbone.sync, function() { + return Backbone.sync = _.wrap(Backbone.sync, function () { var args, _old_ajax, _old_sync; _old_sync = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; _old_ajax = $.ajax; $.ajax = _ajax; _old_sync.call.apply(_old_sync, [this].concat(__slice.call(args))); return $.ajax = _old_ajax; }); } }; - ActionMessenger.prototype._getHandlerResponse = function(returnVal) { + ActionMessenger.prototype._getHandlerResponse = function (returnVal) { if (returnVal === false) { return false; } if (returnVal === true || !(returnVal != null)) { return true; } return returnVal; }; - ActionMessenger.prototype._parseEvents = function(events) { + ActionMessenger.prototype._parseEvents = function (events) { var desc, firstSpace, func, label, out, type, _ref2; if (events == null) { events = {}; } out = {}; @@ -972,11 +981,11 @@ out[type][desc] = func; } return out; }; - ActionMessenger.prototype._normalizeResponse = function() { + ActionMessenger.prototype._normalizeResponse = function () { var data, elem, resp, type, xhr, _i, _len; resp = 1 <= arguments.length ? __slice.call(arguments, 0) : []; type = null; xhr = null; data = null; @@ -991,20 +1000,20 @@ } } return [type, data, xhr]; }; - ActionMessenger.prototype.run = function() { + ActionMessenger.prototype.run = function () { var args, events, getMessageText, handler, handlers, m_opts, msg, old, opts, type, _ref2, _this = this; m_opts = arguments[0], opts = arguments[1], args = 3 <= arguments.length ? __slice.call(arguments, 2) : []; if (opts == null) { opts = {}; } m_opts = $.extend(true, {}, this.messageDefaults, this.doDefaults, m_opts != null ? m_opts : {}); events = this._parseEvents(m_opts.events); - getMessageText = function(type, xhr) { + getMessageText = function (type, xhr) { var message; message = m_opts[type + 'Message']; if (_.isFunction(message)) { return message.call(_this, type, xhr); } @@ -1019,14 +1028,14 @@ message: getMessageText('progress', null), type: 'info' })); } handlers = {}; - _.each(['error', 'success'], function(type) { + _.each(['error', 'success'], function (type) { var originalHandler; originalHandler = opts[type]; - return handlers[type] = function() { + return handlers[type] = function () { var data, defaultOpts, handlerResp, msgOpts, reason, resp, responseOpts, xhr, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9; resp = 1 <= arguments.length ? __slice.call(arguments, 0) : []; _ref3 = _this._normalizeResponse.apply(_this, resp), reason = _ref3[0], data = _ref3[1], xhr = _ref3[2]; if (type === 'success' && !(msg.errorCount != null) && m_opts.showSuccessWithoutError === false) { m_opts['successMessage'] = null; @@ -1081,19 +1090,19 @@ retry: { label: 'retry now', phrase: 'Retrying TIME', auto: msgOpts.retry.auto, delay: msgOpts.retry.delay, - action: function() { + action: function () { msgOpts.messageInstance = msg; - return setTimeout(function() { + return setTimeout(function () { return _this["do"].apply(_this, [msgOpts, opts].concat(__slice.call(args))); }, 0); } }, cancel: { - action: function() { + action: function () { return msg.cancel(); } } }; } else if (msgOpts._retryActions) { @@ -1126,26 +1135,26 @@ return msg; }; ActionMessenger.prototype["do"] = ActionMessenger.prototype.run; - ActionMessenger.prototype.ajax = function() { + ActionMessenger.prototype.ajax = function () { var args, m_opts; m_opts = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; m_opts.action = $.ajax; return this.run.apply(this, [m_opts].concat(__slice.call(args))); }; - ActionMessenger.prototype.expectPromise = function(action, m_opts) { + ActionMessenger.prototype.expectPromise = function (action, m_opts) { m_opts = _.extend({}, m_opts, { action: action, returnsPromise: true }); return this.run(m_opts); }; - ActionMessenger.prototype.error = function(m_opts) { + ActionMessenger.prototype.error = function (m_opts) { if (m_opts == null) { m_opts = {}; } if (typeof m_opts === 'string') { m_opts = { @@ -1154,11 +1163,11 @@ } m_opts.type = 'error'; return this.post(m_opts); }; - ActionMessenger.prototype.info = function(m_opts) { + ActionMessenger.prototype.info = function (m_opts) { if (m_opts == null) { m_opts = {}; } if (typeof m_opts === 'string') { m_opts = { @@ -1167,11 +1176,11 @@ } m_opts.type = 'info'; return this.post(m_opts); }; - ActionMessenger.prototype.success = function(m_opts) { + ActionMessenger.prototype.success = function (m_opts) { if (m_opts == null) { m_opts = {}; } if (typeof m_opts === 'string') { m_opts = { @@ -1184,11 +1193,11 @@ return ActionMessenger; })(_Messenger); - $.fn.messenger = function() { + $.fn.messenger = function () { var $el, args, func, instance, opts, _ref2, _ref3, _ref4; func = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; if (func == null) { func = {}; } @@ -1206,11 +1215,11 @@ } else { return (_ref4 = $el.data('messenger'))[func].apply(_ref4, args); } }; - window.Messenger._call = function(opts) { + window.Messenger._call = function (opts) { var $el, $parent, choosen_loc, chosen_loc, classes, defaultOpts, inst, loc, locations, _i, _len; defaultOpts = { extraClasses: 'messenger-fixed messenger-on-bottom messenger-on-right', theme: 'future', maxMessages: 9, @@ -1258,6 +1267,6 @@ themes: (_ref2 = Messenger.themes) != null ? _ref2 : {} }); $.globalMessenger = window.Messenger = Messenger; -}).call(this); +}).call(this); \ No newline at end of file