/*! 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;
localmessenger = window.messenger = function(){
return localmessenger._call.apply(this, arguments);
}
window.messenger.noconflict = function(){
window.messenger = _prevmessenger;
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._
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;
// 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 _ = {};
// 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;
};
_.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;
};
_.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 + ']';
};
});
_.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;
};
_.extend = function(obj) {
each(slice.call(arguments, 1), function(source) {
if (source) {
for (var prop in source) {
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;
};
_.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)));
};
};
_.isobject = function(obj) {
return obj === object(obj);
};
return _;
})();
window.messenger.events = (function() {
if (window.backbone && backbone.events) {
return backbone.events;
}
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 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 = {
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;
},
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;
}
}
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;
},
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;
};
return eventsshim();
})();
(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; },
__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; };
$ = 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() {
function baseview(options) {
$.extend(this, events);
if (_.isobject(options)) {
if (options.el) {
this.setelement(options.el);
}
this.model = options.model;
}
this.initialize.apply(this, arguments);
}
baseview.prototype.setelement = function(el) {
this.$el = $(el);
return this.el = this.$el[0];
};
baseview.prototype.delegateevents = function(events) {
var delegateeventsplitter, eventname, key, match, method, selector, _results;
if (!(events || (events = _.result(this, "events")))) {
return;
}
this.undelegateevents();
delegateeventsplitter = /^(\s+)\s*(.*)$/;
_results = [];
for (key in events) {
method = events[key];
if (!_.isfunction(method)) {
method = this[events[key]];
}
if (!method) {
throw new error("method \"" + events[key] + "\" does not exist");
}
match = key.match(delegateeventsplitter);
eventname = match[1];
selector = match[2];
method = _.bind(method, this);
eventname += ".delegateevents" + this.cid;
if (selector === '') {
_results.push(this.jqon(eventname, method));
} else {
_results.push(this.jqon(eventname, selector, method));
}
}
return _results;
};
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)) {
method = selector;
selector = void 0;
}
if (selector != null) {
return this.$el.delegate(selector, eventname, method);
} else {
return this.$el.bind(eventname, method);
}
}
};
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() {
return this.jqoff(".delegateevents" + this.cid);
};
baseview.prototype.remove = function() {
this.undelegateevents();
return this.$el.remove();
};
return baseview;
})();
_message = (function(_super) {
__extends(_message, _super);
function _message() {
return _message.__super__.constructor.apply(this, arguments);
}
_message.prototype.defaults = {
hideafter: 10,
scroll: true,
closebuttontext: "×",
escapetext: false
};
_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() {
var wasshown;
if (!this.rendered) {
this.render();
}
this.$message.removeclass('messenger-hidden');
wasshown = this.shown;
this.shown = true;
if (!wasshown) {
return this.trigger('show');
}
};
_message.prototype.hide = function() {
var wasshown;
if (!this.rendered) {
return;
}
this.$message.addclass('messenger-hidden');
wasshown = this.shown;
this.shown = false;
if (wasshown) {
return this.trigger('hide');
}
};
_message.prototype.cancel = function() {
return this.hide();
};
_message.prototype.update = function(opts) {
var _ref2,
_this = this;
if (_.isstring(opts)) {
opts = {
message: opts
};
}
$.extend(this.options, opts);
this.lastupdate = new date();
this.rendered = false;
this.events = (_ref2 = this.options.events) != null ? _ref2 : {};
this.render();
this.actionstoevents();
this.delegateevents();
this.checkclickable();
if (this.options.hideafter) {
this.$message.addclass('messenger-will-hide-after');
if (this._hidetimeout != null) {
cleartimeout(this._hidetimeout);
}
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() {
return _this.hide();
});
}
} else {
this.$message.removeclass('messenger-will-hide-on-navigate');
}
return this.trigger('update', this);
};
_message.prototype.scrollto = function() {
if (!this.options.scroll) {
return;
}
return $.scrollto(this.$el, {
duration: 400,
offset: {
left: 0,
top: -20
}
});
};
_message.prototype.timesinceupdate = function() {
if (this.lastupdate) {
return (new date) - this.lastupdate;
} else {
return null;
}
};
_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) {
e.preventdefault();
e.stoppropagation();
_this.trigger("action:" + name, act, e);
return act.action.call(_this, e, _this);
};
})(act));
}
return _results;
};
_message.prototype.checkclickable = function() {
var evt, name, _ref2, _results;
_ref2 = this.events;
_results = [];
for (name in _ref2) {
evt = _ref2[name];
if (name === 'click') {
_results.push(this.$message.addclass('messenger-clickable'));
} else {
_results.push(void 0);
}
}
return _results;
};
_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() {
var act, actions, n_act, name, _ref2, _ref3;
actions = [];
_ref2 = this.options.actions;
for (name in _ref2) {
act = _ref2[name];
n_act = $.extend({}, act);
n_act.name = name;
if ((_ref3 = n_act.label) == null) {
n_act.label = name;
}
actions.push(n_act);
}
return actions;
};
_message.prototype.template = function(opts) {
var $action, $actions, $cancel, $link, $message, $text, action, _i, _len, _ref2,
_this = this;
$message = $("
");
if (opts.showclosebutton) {
$cancel = $('