messengerjs-rails 1.3.0 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7374d68cabdcace25d776f6365c5d32fc55aded4
|
4
|
+
data.tar.gz: ce917a8985a695c88f76c4bc41ba29ab2eef8186
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eef311d7058a266cee1705bad5e1ca87967b23efc32f437d1396c8eaf5b2ad59938432f4a8e6e1b76c0eca64b2cb4870361e8f351e36ab04eff8588a0376a21d
|
7
|
+
data.tar.gz: 1c75980f0c1622c40eb5ed15629e78c80efe15a9484a4f3957b57bc91268bbbf03c2ec3e6d1060726a544e38d40a549f4055aa7626f833037e3036e970f4c24e
|
data/README.md
CHANGED
@@ -16,7 +16,7 @@ messengerjs-rails is a Rails (3.1 and above) wrapper for [Messenger](http://gith
|
|
16
16
|
|
17
17
|
[Demo and Usage](http://hubspot.github.com/messenger)
|
18
18
|
|
19
|
-
##
|
19
|
+
## Requirement/Dependency:
|
20
20
|
|
21
21
|
1. jQuery
|
22
22
|
|
@@ -26,19 +26,25 @@ messengerjs-rails is a Rails (3.1 and above) wrapper for [Messenger](http://gith
|
|
26
26
|
|
27
27
|
Add the following to your gemfile:
|
28
28
|
|
29
|
-
gem
|
29
|
+
gem "messengerjs-rails", "~> 1.3.0"
|
30
30
|
|
31
|
-
Add the following directive to your application.coffee / application.js:
|
31
|
+
Add the following directive to your application.coffee / application.js:
|
32
32
|
|
33
|
+
//= require jquery-rails
|
34
|
+
*
|
35
|
+
*
|
33
36
|
//= require messenger
|
34
37
|
//= require messenger-theme-future
|
35
38
|
|
36
|
-
Add the following directive to your application.scss / application.css. There are four themes provided (future, air, block and ice), change
|
39
|
+
Add the following directive to your application.scss / application.css. There are four themes/styles provided (future, air, block and ice), change required stylesheet as needed.
|
37
40
|
|
38
41
|
*= require messenger
|
39
|
-
|
40
|
-
|
42
|
+
*= require messenger-spinner
|
43
|
+
*= require messenger-theme-future
|
41
44
|
|
45
|
+
## Todos
|
46
|
+
|
47
|
+
1. Provide a Rails Middleware for replacing conventional flash messages.
|
42
48
|
|
43
49
|
## Versioning
|
44
50
|
|
@@ -51,6 +57,6 @@ Feel free to open an issue ticket if you find something that could be improved.
|
|
51
57
|
|
52
58
|
## Acknowledgements
|
53
59
|
|
54
|
-
Special thanks to [HubSpot](http://dev.hubspot.com/) and all Messenger
|
60
|
+
Special thanks to [HubSpot](http://dev.hubspot.com/) and all Messenger contributors.
|
55
61
|
|
56
|
-
Copyright
|
62
|
+
Copyright Ben Song(zbin.song@gmail.com), released under the MIT License.
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module MessengerJS
|
5
|
+
|
6
|
+
class Middleware
|
7
|
+
|
8
|
+
KEY = 'action_dispatch.request.flash_hash'.freeze
|
9
|
+
|
10
|
+
def initialize(app, options = {})
|
11
|
+
@app = app
|
12
|
+
@options = {
|
13
|
+
|
14
|
+
}.merge(options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
@env = env
|
19
|
+
@status, @headers, @response = @app.call(env)
|
20
|
+
|
21
|
+
session = Request::Session.find(env) || {}
|
22
|
+
flash_hash = env[KEY]
|
23
|
+
|
24
|
+
insert_messenger_to_response
|
25
|
+
|
26
|
+
[@status, @headers, @response]
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def insert_messenger_to_response
|
34
|
+
@response.each do |response_part|
|
35
|
+
if is_regular_requests? && is_html_response?
|
36
|
+
|
37
|
+
elsif is_turbolink_request? && is_html_response?
|
38
|
+
|
39
|
+
elsif is_ajax_request? && is_html_response?
|
40
|
+
|
41
|
+
elsif is_ajax_request? && is_javascript_response?
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def is_regular_request?
|
49
|
+
!(is_ajax_request? || is_turbolink_request?)
|
50
|
+
end
|
51
|
+
|
52
|
+
def is_turbolink_request?
|
53
|
+
@env.has_key?("HTTP_X_XHR_REFERER")
|
54
|
+
end
|
55
|
+
|
56
|
+
def is_ajax_request?
|
57
|
+
@env.has_key?("HTTP_X_REQUESTED_WITH") && @env["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest"
|
58
|
+
end
|
59
|
+
|
60
|
+
def is_html_response?
|
61
|
+
@headers["Content-Type"].include?("text/html") if @headers.has_key?("Content-Type")
|
62
|
+
end
|
63
|
+
|
64
|
+
def is_javascript_response?
|
65
|
+
@headers["Content-Type"].include?("text/javascript") if @headers.has_key?("Content-Type")
|
66
|
+
end
|
67
|
+
|
68
|
+
def render_messenger_scripts
|
69
|
+
<<-EOT
|
70
|
+
<!-- start Messenger -->
|
71
|
+
<script type="text/javascript">
|
72
|
+
|
73
|
+
</script>
|
74
|
+
<!-- end Messenger -->
|
75
|
+
EOT
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/*! messenger 1.3.
|
1
|
+
/*! messenger 1.3.3 */
|
2
2
|
/*
|
3
3
|
* This file begins the output concatenated into messenger.js
|
4
4
|
*
|
@@ -299,7 +299,7 @@ window.Messenger.Events = (function() {
|
|
299
299
|
})();
|
300
300
|
|
301
301
|
(function() {
|
302
|
-
var $, ActionMessenger, BaseView, Events, RetryingMessage, _, _Message, _Messenger, _ref, _ref1,
|
302
|
+
var $, ActionMessenger, BaseView, Events, RetryingMessage, _, _Message, _Messenger, _ref, _ref1, _ref2,
|
303
303
|
__hasProp = {}.hasOwnProperty,
|
304
304
|
__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; },
|
305
305
|
__slice = [].slice,
|
@@ -307,9 +307,9 @@ window.Messenger.Events = (function() {
|
|
307
307
|
|
308
308
|
$ = jQuery;
|
309
309
|
|
310
|
-
_ = _ != null ?
|
310
|
+
_ = (_ref = window._) != null ? _ref : window.Messenger._;
|
311
311
|
|
312
|
-
Events = (
|
312
|
+
Events = (_ref1 = typeof Backbone !== "undefined" && Backbone !== null ? Backbone.Events : void 0) != null ? _ref1 : window.Messenger.Events;
|
313
313
|
|
314
314
|
BaseView = (function() {
|
315
315
|
|
@@ -426,7 +426,7 @@ window.Messenger.Events = (function() {
|
|
426
426
|
};
|
427
427
|
|
428
428
|
_Message.prototype.update = function(opts) {
|
429
|
-
var
|
429
|
+
var _ref2,
|
430
430
|
_this = this;
|
431
431
|
if (_.isString(opts)) {
|
432
432
|
opts = {
|
@@ -436,7 +436,7 @@ window.Messenger.Events = (function() {
|
|
436
436
|
$.extend(this.options, opts);
|
437
437
|
this.lastUpdate = new Date();
|
438
438
|
this.rendered = false;
|
439
|
-
this.events = (
|
439
|
+
this.events = (_ref2 = this.options.events) != null ? _ref2 : {};
|
440
440
|
this.render();
|
441
441
|
this.actionsToEvents();
|
442
442
|
this.delegateEvents();
|
@@ -487,18 +487,18 @@ window.Messenger.Events = (function() {
|
|
487
487
|
};
|
488
488
|
|
489
489
|
_Message.prototype.actionsToEvents = function() {
|
490
|
-
var act, name,
|
490
|
+
var act, name, _ref2, _results,
|
491
491
|
_this = this;
|
492
|
-
|
492
|
+
_ref2 = this.options.actions;
|
493
493
|
_results = [];
|
494
|
-
for (name in
|
495
|
-
act =
|
494
|
+
for (name in _ref2) {
|
495
|
+
act = _ref2[name];
|
496
496
|
_results.push(this.events["click [data-action=\"" + name + "\"] a"] = (function(act) {
|
497
497
|
return function(e) {
|
498
498
|
e.preventDefault();
|
499
499
|
e.stopPropagation();
|
500
500
|
_this.trigger("action:" + name, act, e);
|
501
|
-
return act.action(e);
|
501
|
+
return act.action.call(_this, e, _this);
|
502
502
|
};
|
503
503
|
})(act));
|
504
504
|
}
|
@@ -506,11 +506,11 @@ window.Messenger.Events = (function() {
|
|
506
506
|
};
|
507
507
|
|
508
508
|
_Message.prototype.checkClickable = function() {
|
509
|
-
var evt, name,
|
510
|
-
|
509
|
+
var evt, name, _ref2, _results;
|
510
|
+
_ref2 = this.events;
|
511
511
|
_results = [];
|
512
|
-
for (name in
|
513
|
-
evt =
|
512
|
+
for (name in _ref2) {
|
513
|
+
evt = _ref2[name];
|
514
514
|
if (name === 'click') {
|
515
515
|
_results.push(this.$message.addClass('messenger-clickable'));
|
516
516
|
} else {
|
@@ -521,20 +521,20 @@ window.Messenger.Events = (function() {
|
|
521
521
|
};
|
522
522
|
|
523
523
|
_Message.prototype.undelegateEvents = function() {
|
524
|
-
var
|
524
|
+
var _ref2;
|
525
525
|
_Message.__super__.undelegateEvents.apply(this, arguments);
|
526
|
-
return (
|
526
|
+
return (_ref2 = this.$message) != null ? _ref2.removeClass('messenger-clickable') : void 0;
|
527
527
|
};
|
528
528
|
|
529
529
|
_Message.prototype.parseActions = function() {
|
530
|
-
var act, actions, n_act, name,
|
530
|
+
var act, actions, n_act, name, _ref2, _ref3;
|
531
531
|
actions = [];
|
532
|
-
|
533
|
-
for (name in
|
534
|
-
act =
|
532
|
+
_ref2 = this.options.actions;
|
533
|
+
for (name in _ref2) {
|
534
|
+
act = _ref2[name];
|
535
535
|
n_act = $.extend({}, act);
|
536
536
|
n_act.name = name;
|
537
|
-
if ((
|
537
|
+
if ((_ref3 = n_act.label) == null) {
|
538
538
|
n_act.label = name;
|
539
539
|
}
|
540
540
|
actions.push(n_act);
|
@@ -543,7 +543,7 @@ window.Messenger.Events = (function() {
|
|
543
543
|
};
|
544
544
|
|
545
545
|
_Message.prototype.template = function(opts) {
|
546
|
-
var $action, $actions, $cancel, $link, $message, $text, action, _i, _len,
|
546
|
+
var $action, $actions, $cancel, $link, $message, $text, action, _i, _len, _ref2,
|
547
547
|
_this = this;
|
548
548
|
$message = $("<div class='messenger-message message alert " + opts.type + " message-" + opts.type + " alert-" + opts.type + "'>");
|
549
549
|
if (opts.showCloseButton) {
|
@@ -559,9 +559,9 @@ window.Messenger.Events = (function() {
|
|
559
559
|
if (opts.actions.length) {
|
560
560
|
$actions = $('<div class="messenger-actions">');
|
561
561
|
}
|
562
|
-
|
563
|
-
for (_i = 0, _len =
|
564
|
-
action =
|
562
|
+
_ref2 = opts.actions;
|
563
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
564
|
+
action = _ref2[_i];
|
565
565
|
$action = $('<span>');
|
566
566
|
$action.attr('data-action', "" + action.name);
|
567
567
|
$link = $('<a>');
|
@@ -619,24 +619,24 @@ window.Messenger.Events = (function() {
|
|
619
619
|
};
|
620
620
|
|
621
621
|
RetryingMessage.prototype.clearTimers = function() {
|
622
|
-
var name, timer,
|
623
|
-
|
624
|
-
for (name in
|
625
|
-
timer =
|
622
|
+
var name, timer, _ref2, _ref3;
|
623
|
+
_ref2 = this._timers;
|
624
|
+
for (name in _ref2) {
|
625
|
+
timer = _ref2[name];
|
626
626
|
clearTimeout(timer);
|
627
627
|
}
|
628
628
|
this._timers = {};
|
629
|
-
return (
|
629
|
+
return (_ref3 = this.$message) != null ? _ref3.removeClass('messenger-retry-soon messenger-retry-later') : void 0;
|
630
630
|
};
|
631
631
|
|
632
632
|
RetryingMessage.prototype.render = function() {
|
633
|
-
var action, name,
|
633
|
+
var action, name, _ref2, _results;
|
634
634
|
RetryingMessage.__super__.render.apply(this, arguments);
|
635
635
|
this.clearTimers();
|
636
|
-
|
636
|
+
_ref2 = this.options.actions;
|
637
637
|
_results = [];
|
638
|
-
for (name in
|
639
|
-
action =
|
638
|
+
for (name in _ref2) {
|
639
|
+
action = _ref2[name];
|
640
640
|
if (action.auto) {
|
641
641
|
_results.push(this.startCountdown(name, action));
|
642
642
|
} else {
|
@@ -676,13 +676,13 @@ window.Messenger.Events = (function() {
|
|
676
676
|
};
|
677
677
|
|
678
678
|
RetryingMessage.prototype.startCountdown = function(name, action) {
|
679
|
-
var $phrase, remaining, tick,
|
679
|
+
var $phrase, remaining, tick, _ref2,
|
680
680
|
_this = this;
|
681
681
|
if (this._timers[name] != null) {
|
682
682
|
return;
|
683
683
|
}
|
684
684
|
$phrase = this.$message.find("[data-action='" + name + "'] .messenger-phrase");
|
685
|
-
remaining = (
|
685
|
+
remaining = (_ref2 = action.delay) != null ? _ref2 : 3;
|
686
686
|
if (remaining <= 10) {
|
687
687
|
this.$message.removeClass('messenger-retry-later');
|
688
688
|
this.$message.addClass('messenger-retry-soon');
|
@@ -765,13 +765,13 @@ window.Messenger.Events = (function() {
|
|
765
765
|
};
|
766
766
|
|
767
767
|
_Messenger.prototype._enforceIdConstraint = function(msg) {
|
768
|
-
var entry, _i, _len, _msg,
|
768
|
+
var entry, _i, _len, _msg, _ref2;
|
769
769
|
if (msg.options.id == null) {
|
770
770
|
return;
|
771
771
|
}
|
772
|
-
|
773
|
-
for (_i = 0, _len =
|
774
|
-
entry =
|
772
|
+
_ref2 = this.history;
|
773
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
774
|
+
entry = _ref2[_i];
|
775
775
|
_msg = entry.msg;
|
776
776
|
if ((_msg.options.id != null) && _msg.options.id === msg.options.id && msg !== _msg) {
|
777
777
|
if (msg.options.singleton) {
|
@@ -785,13 +785,13 @@ window.Messenger.Events = (function() {
|
|
785
785
|
};
|
786
786
|
|
787
787
|
_Messenger.prototype.newMessage = function(opts) {
|
788
|
-
var msg,
|
788
|
+
var msg, _ref2, _ref3, _ref4,
|
789
789
|
_this = this;
|
790
790
|
if (opts == null) {
|
791
791
|
opts = {};
|
792
792
|
}
|
793
793
|
opts.messenger = this;
|
794
|
-
_Message = (
|
794
|
+
_Message = (_ref2 = (_ref3 = Messenger.themes[(_ref4 = opts.theme) != null ? _ref4 : this.options.theme]) != null ? _ref3.Message : void 0) != null ? _ref2 : RetryingMessage;
|
795
795
|
msg = new _Message(opts);
|
796
796
|
msg.on('show', function() {
|
797
797
|
if (opts.scrollTo && _this.$el.css('position') !== 'fixed') {
|
@@ -803,36 +803,36 @@ window.Messenger.Events = (function() {
|
|
803
803
|
};
|
804
804
|
|
805
805
|
_Messenger.prototype.updateMessageSlotClasses = function() {
|
806
|
-
var anyShown, last, rec, willBeFirst, _i, _len,
|
806
|
+
var anyShown, last, rec, willBeFirst, _i, _len, _ref2;
|
807
807
|
willBeFirst = true;
|
808
808
|
last = null;
|
809
809
|
anyShown = false;
|
810
|
-
|
811
|
-
for (_i = 0, _len =
|
812
|
-
rec =
|
813
|
-
rec.$slot.removeClass('first last shown');
|
810
|
+
_ref2 = this.history;
|
811
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
812
|
+
rec = _ref2[_i];
|
813
|
+
rec.$slot.removeClass('messenger-first messenger-last messenger-shown');
|
814
814
|
if (rec.msg.shown && rec.msg.rendered) {
|
815
|
-
rec.$slot.addClass('shown');
|
815
|
+
rec.$slot.addClass('messenger-shown');
|
816
816
|
anyShown = true;
|
817
817
|
last = rec;
|
818
818
|
if (willBeFirst) {
|
819
819
|
willBeFirst = false;
|
820
|
-
rec.$slot.addClass('first');
|
820
|
+
rec.$slot.addClass('messenger-first');
|
821
821
|
}
|
822
822
|
}
|
823
823
|
}
|
824
824
|
if (last != null) {
|
825
|
-
last.$slot.addClass('last');
|
825
|
+
last.$slot.addClass('messenger-last');
|
826
826
|
}
|
827
827
|
return this.$el["" + (anyShown ? 'remove' : 'add') + "Class"]('messenger-empty');
|
828
828
|
};
|
829
829
|
|
830
830
|
_Messenger.prototype.hideAll = function() {
|
831
|
-
var rec, _i, _len,
|
832
|
-
|
831
|
+
var rec, _i, _len, _ref2, _results;
|
832
|
+
_ref2 = this.history;
|
833
833
|
_results = [];
|
834
|
-
for (_i = 0, _len =
|
835
|
-
rec =
|
834
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
835
|
+
rec = _ref2[_i];
|
836
836
|
_results.push(rec.msg.hide());
|
837
837
|
}
|
838
838
|
return _results;
|
@@ -916,18 +916,18 @@ window.Messenger.Events = (function() {
|
|
916
916
|
}
|
917
917
|
};
|
918
918
|
|
919
|
-
ActionMessenger.prototype.
|
919
|
+
ActionMessenger.prototype._getHandlerResponse = function(returnVal) {
|
920
920
|
if (returnVal === false) {
|
921
921
|
return false;
|
922
922
|
}
|
923
|
-
if (returnVal === true || !(returnVal != null)
|
924
|
-
return
|
923
|
+
if (returnVal === true || !(returnVal != null)) {
|
924
|
+
return true;
|
925
925
|
}
|
926
926
|
return returnVal;
|
927
927
|
};
|
928
928
|
|
929
929
|
ActionMessenger.prototype._parseEvents = function(events) {
|
930
|
-
var desc, firstSpace, func, label, out, type,
|
930
|
+
var desc, firstSpace, func, label, out, type, _ref2;
|
931
931
|
if (events == null) {
|
932
932
|
events = {};
|
933
933
|
}
|
@@ -937,7 +937,7 @@ window.Messenger.Events = (function() {
|
|
937
937
|
firstSpace = label.indexOf(' ');
|
938
938
|
type = label.substring(0, firstSpace);
|
939
939
|
desc = label.substring(firstSpace + 1);
|
940
|
-
if ((
|
940
|
+
if ((_ref2 = out[type]) == null) {
|
941
941
|
out[type] = {};
|
942
942
|
}
|
943
943
|
out[type][desc] = func;
|
@@ -965,7 +965,7 @@ window.Messenger.Events = (function() {
|
|
965
965
|
};
|
966
966
|
|
967
967
|
ActionMessenger.prototype.run = function() {
|
968
|
-
var args, attr, events, m_opts, msg, opts, promiseAttrs, _i, _len,
|
968
|
+
var args, attr, events, getMessageText, handler, handlers, m_opts, msg, old, opts, promiseAttrs, type, _i, _len, _ref2, _ref3,
|
969
969
|
_this = this;
|
970
970
|
m_opts = arguments[0], opts = arguments[1], args = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
|
971
971
|
if (opts == null) {
|
@@ -973,25 +973,32 @@ window.Messenger.Events = (function() {
|
|
973
973
|
}
|
974
974
|
m_opts = $.extend(true, {}, this.messageDefaults, this.doDefaults, m_opts != null ? m_opts : {});
|
975
975
|
events = this._parseEvents(m_opts.events);
|
976
|
-
|
976
|
+
getMessageText = function(type, xhr) {
|
977
|
+
var message;
|
978
|
+
message = m_opts[type + 'Message'];
|
979
|
+
if (_.isFunction(message)) {
|
980
|
+
return message.call(_this, type, xhr);
|
981
|
+
}
|
982
|
+
return message;
|
983
|
+
};
|
984
|
+
msg = (_ref2 = m_opts.messageInstance) != null ? _ref2 : this.newMessage(m_opts);
|
977
985
|
if (m_opts.id != null) {
|
978
986
|
msg.options.id = m_opts.id;
|
979
987
|
}
|
980
988
|
if (m_opts.progressMessage != null) {
|
981
989
|
msg.update($.extend({}, m_opts, {
|
982
|
-
message:
|
990
|
+
message: getMessageText('progress', null),
|
983
991
|
type: 'info'
|
984
992
|
}));
|
985
993
|
}
|
994
|
+
handlers = {};
|
986
995
|
_.each(['error', 'success'], function(type) {
|
987
|
-
|
988
|
-
|
989
|
-
opts[type] = opts[type]._originalHandler;
|
990
|
-
}
|
991
|
-
old = (_ref3 = opts[type]) != null ? _ref3 : function() {};
|
992
|
-
opts[type] = function() {
|
993
|
-
var data, msgOpts, msgText, r, reason, resp, xhr, _ref10, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;
|
996
|
+
return handlers[type] = function() {
|
997
|
+
var data, defaultOpts, handlerResp, msgOpts, reason, resp, responseOpts, xhr, _base, _ref10, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;
|
994
998
|
resp = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
999
|
+
if ((_ref3 = opts[type]) != null ? _ref3._originalHandler : void 0) {
|
1000
|
+
opts[type] = opts[type]._originalHandler;
|
1001
|
+
}
|
995
1002
|
_ref4 = _this._normalizeResponse.apply(_this, resp), reason = _ref4[0], data = _ref4[1], xhr = _ref4[2];
|
996
1003
|
if (type === 'success' && !(msg.errorCount != null) && m_opts.showSuccessWithoutError === false) {
|
997
1004
|
m_opts['successMessage'] = null;
|
@@ -1002,7 +1009,13 @@ window.Messenger.Events = (function() {
|
|
1002
1009
|
}
|
1003
1010
|
m_opts.errorCount += 1;
|
1004
1011
|
}
|
1005
|
-
|
1012
|
+
handlerResp = m_opts.returnsPromise ? resp[0] : typeof (_base = opts[type])._originalHandler === "function" ? _base._originalHandler.apply(_base, resp) : void 0;
|
1013
|
+
responseOpts = _this._getHandlerResponse(handlerResp);
|
1014
|
+
if (_.isString(responseOpts)) {
|
1015
|
+
responseOpts = {
|
1016
|
+
message: responseOpts
|
1017
|
+
};
|
1018
|
+
}
|
1006
1019
|
if (type === 'error' && ((xhr != null ? xhr.status : void 0) === 0 || reason === 'abort')) {
|
1007
1020
|
msg.hide();
|
1008
1021
|
return;
|
@@ -1011,12 +1024,13 @@ window.Messenger.Events = (function() {
|
|
1011
1024
|
msg.hide();
|
1012
1025
|
return;
|
1013
1026
|
}
|
1014
|
-
|
1015
|
-
message:
|
1027
|
+
defaultOpts = {
|
1028
|
+
message: getMessageText(type, xhr),
|
1016
1029
|
type: type,
|
1017
1030
|
events: (_ref7 = events[type]) != null ? _ref7 : {},
|
1018
1031
|
hideOnNavigate: type === 'success'
|
1019
|
-
}
|
1032
|
+
};
|
1033
|
+
msgOpts = $.extend({}, m_opts, defaultOpts, responseOpts);
|
1020
1034
|
if (typeof ((_ref8 = msgOpts.retry) != null ? _ref8.allow : void 0) === 'number') {
|
1021
1035
|
msgOpts.retry.allow--;
|
1022
1036
|
}
|
@@ -1060,23 +1074,33 @@ window.Messenger.Events = (function() {
|
|
1060
1074
|
delete m_opts._retryActions;
|
1061
1075
|
}
|
1062
1076
|
msg.update(msgOpts);
|
1063
|
-
if (
|
1064
|
-
|
1077
|
+
if (responseOpts && msgOpts.message) {
|
1078
|
+
Messenger();
|
1065
1079
|
return msg.show();
|
1066
1080
|
} else {
|
1067
1081
|
return msg.hide();
|
1068
1082
|
}
|
1069
1083
|
};
|
1070
|
-
return opts[type]._originalHandler = old;
|
1071
1084
|
});
|
1085
|
+
if (!m_opts.returnsPromise) {
|
1086
|
+
for (type in handlers) {
|
1087
|
+
handler = handlers[type];
|
1088
|
+
old = opts[type];
|
1089
|
+
opts[type] = handler;
|
1090
|
+
opts[type]._originalHandler = old;
|
1091
|
+
}
|
1092
|
+
}
|
1072
1093
|
msg._actionInstance = m_opts.action.apply(m_opts, [opts].concat(__slice.call(args)));
|
1094
|
+
if (m_opts.returnsPromise) {
|
1095
|
+
msg._actionInstance.then(handlers.success, handlers.error);
|
1096
|
+
}
|
1073
1097
|
promiseAttrs = ['done', 'progress', 'fail', 'state', 'then'];
|
1074
1098
|
for (_i = 0, _len = promiseAttrs.length; _i < _len; _i++) {
|
1075
1099
|
attr = promiseAttrs[_i];
|
1076
1100
|
if (msg[attr] != null) {
|
1077
1101
|
delete msg[attr];
|
1078
1102
|
}
|
1079
|
-
msg[attr] = (
|
1103
|
+
msg[attr] = (_ref3 = msg._actionInstance) != null ? _ref3[attr] : void 0;
|
1080
1104
|
}
|
1081
1105
|
return msg;
|
1082
1106
|
};
|
@@ -1090,12 +1114,20 @@ window.Messenger.Events = (function() {
|
|
1090
1114
|
return this.run.apply(this, [m_opts].concat(__slice.call(args)));
|
1091
1115
|
};
|
1092
1116
|
|
1117
|
+
ActionMessenger.prototype.expectPromise = function(action, m_opts) {
|
1118
|
+
m_opts = _.extend({}, m_opts, {
|
1119
|
+
action: action,
|
1120
|
+
returnsPromise: true
|
1121
|
+
});
|
1122
|
+
return this.run(m_opts);
|
1123
|
+
};
|
1124
|
+
|
1093
1125
|
return ActionMessenger;
|
1094
1126
|
|
1095
1127
|
})(_Messenger);
|
1096
1128
|
|
1097
1129
|
$.fn.messenger = function() {
|
1098
|
-
var $el, args, func, instance, opts,
|
1130
|
+
var $el, args, func, instance, opts, _ref2, _ref3, _ref4;
|
1099
1131
|
func = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
1100
1132
|
if (func == null) {
|
1101
1133
|
func = {};
|
@@ -1104,7 +1136,7 @@ window.Messenger.Events = (function() {
|
|
1104
1136
|
if (!(func != null) || !_.isString(func)) {
|
1105
1137
|
opts = func;
|
1106
1138
|
if (!($el.data('messenger') != null)) {
|
1107
|
-
_Messenger = (
|
1139
|
+
_Messenger = (_ref2 = (_ref3 = Messenger.themes[opts.theme]) != null ? _ref3.Messenger : void 0) != null ? _ref2 : ActionMessenger;
|
1108
1140
|
$el.data('messenger', instance = new _Messenger($.extend({
|
1109
1141
|
el: $el
|
1110
1142
|
}, opts)));
|
@@ -1112,7 +1144,7 @@ window.Messenger.Events = (function() {
|
|
1112
1144
|
}
|
1113
1145
|
return $el.data('messenger');
|
1114
1146
|
} else {
|
1115
|
-
return (
|
1147
|
+
return (_ref4 = $el.data('messenger'))[func].apply(_ref4, args);
|
1116
1148
|
}
|
1117
1149
|
};
|
1118
1150
|
|
@@ -1163,7 +1195,7 @@ window.Messenger.Events = (function() {
|
|
1163
1195
|
$.extend(Messenger, {
|
1164
1196
|
Message: RetryingMessage,
|
1165
1197
|
Messenger: ActionMessenger,
|
1166
|
-
themes: (
|
1198
|
+
themes: (_ref2 = Messenger.themes) != null ? _ref2 : {}
|
1167
1199
|
});
|
1168
1200
|
|
1169
1201
|
$.globalMessenger = window.Messenger = Messenger;
|
@@ -453,7 +453,7 @@ ul.messenger-theme-future .messenger-message.alert-info .messenger-message-inner
|
|
453
453
|
background-color: #61c4b8;
|
454
454
|
}
|
455
455
|
/* line 127, ../../src/sass/messenger-theme-future.sass */
|
456
|
-
ul.messenger-theme-future .messenger-message-slot.last .messenger-message {
|
456
|
+
ul.messenger-theme-future .messenger-message-slot.messenger-last .messenger-message {
|
457
457
|
-webkit-border-radius: 4px 4px 0px 0px;
|
458
458
|
-moz-border-radius: 4px 4px 0px 0px;
|
459
459
|
-ms-border-radius: 4px 4px 0px 0px;
|
@@ -461,7 +461,7 @@ ul.messenger-theme-future .messenger-message-slot.last .messenger-message {
|
|
461
461
|
border-radius: 4px 4px 0px 0px;
|
462
462
|
}
|
463
463
|
/* line 130, ../../src/sass/messenger-theme-future.sass */
|
464
|
-
ul.messenger-theme-future .messenger-message-slot.first .messenger-message {
|
464
|
+
ul.messenger-theme-future .messenger-message-slot.messenger-first .messenger-message {
|
465
465
|
-webkit-border-radius: 0px 0px 4px 4px;
|
466
466
|
-moz-border-radius: 0px 0px 4px 4px;
|
467
467
|
-ms-border-radius: 0px 0px 4px 4px;
|
@@ -472,7 +472,7 @@ ul.messenger-theme-future .messenger-message-slot.first .messenger-message {
|
|
472
472
|
box-shadow: inset 0px 1px rgba(255, 255, 255, 0.13), inset 48px 0px 0px rgba(0, 0, 0, 0.3), inset 46px 0px 0px rgba(255, 255, 255, 0.07);
|
473
473
|
}
|
474
474
|
/* line 134, ../../src/sass/messenger-theme-future.sass */
|
475
|
-
ul.messenger-theme-future .messenger-message-slot.first.last .messenger-message {
|
475
|
+
ul.messenger-theme-future .messenger-message-slot.messenger-first.messenger-last .messenger-message {
|
476
476
|
-webkit-box-shadow: inset 48px 0px 0px rgba(0, 0, 0, 0.3), inset 46px 0px 0px rgba(255, 255, 255, 0.07);
|
477
477
|
-moz-box-shadow: inset 48px 0px 0px rgba(0, 0, 0, 0.3), inset 46px 0px 0px rgba(255, 255, 255, 0.07);
|
478
478
|
box-shadow: inset 48px 0px 0px rgba(0, 0, 0, 0.3), inset 46px 0px 0px rgba(255, 255, 255, 0.07);
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: messengerjs-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
5
|
-
prerelease:
|
4
|
+
version: 1.3.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Ben Song
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-06-07 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: Injects Messenger javascript and stylesheets into your asset pipeline.
|
15
14
|
email: zbin.song@gmail.com
|
@@ -17,6 +16,7 @@ executables: []
|
|
17
16
|
extensions: []
|
18
17
|
extra_rdoc_files: []
|
19
18
|
files:
|
19
|
+
- lib/messengerjs-rails/middleware.rb
|
20
20
|
- lib/messengerjs-rails/version.rb
|
21
21
|
- lib/messengerjs-rails.rb
|
22
22
|
- vendor/assets/javascripts/messenger-theme-future.js
|
@@ -31,26 +31,25 @@ files:
|
|
31
31
|
- README.md
|
32
32
|
homepage: https://github.com/benjis/messengerjs-rails/
|
33
33
|
licenses: []
|
34
|
+
metadata: {}
|
34
35
|
post_install_message:
|
35
36
|
rdoc_options: []
|
36
37
|
require_paths:
|
37
38
|
- lib
|
38
39
|
required_ruby_version: !ruby/object:Gem::Requirement
|
39
40
|
requirements:
|
40
|
-
- -
|
41
|
+
- - '>='
|
41
42
|
- !ruby/object:Gem::Version
|
42
43
|
version: '0'
|
43
|
-
none: false
|
44
44
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- -
|
46
|
+
- - '>='
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '0'
|
49
|
-
none: false
|
50
49
|
requirements: []
|
51
50
|
rubyforge_project:
|
52
|
-
rubygems_version:
|
51
|
+
rubygems_version: 2.0.3
|
53
52
|
signing_key:
|
54
|
-
specification_version:
|
53
|
+
specification_version: 4
|
55
54
|
summary: Messenger js on Rails
|
56
55
|
test_files: []
|