@ -1,4 +1,4 @@
/*! messenger 1.3. 1 2013-05-14 */
/*! messenger 1.3. 2 */
/ *
* This file begins the output concatenated into messenger . js
*
@ -498,7 +498,7 @@ window.Messenger.Events = (function() {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
_this . trigger ( "action:" + name , act , e ) ;
return act . action ( e) ;
return act . action .call (_this, e, _this ) ;
} ;
} ) ( act ) ) ;
}
@ -810,19 +810,19 @@ window.Messenger.Events = (function() {
_ref2 = this . history ;
for ( _i = 0 , _len = _ref2 . length ; _i < _len ; _i ++ ) {
rec = _ref2 [ _i ] ;
rec . $slot . removeClass ( ' first last shown') ;
rec . $slot . removeClass ( ' messenger- first messenger- last messenger- shown') ;
if ( rec . msg . shown && rec . msg . rendered ) {
rec . $slot . addClass ( ' shown') ;
rec . $slot . addClass ( ' messenger- shown') ;
anyShown = true ;
last = rec ;
if ( willBeFirst ) {
willBeFirst = false ;
rec . $slot . addClass ( ' first') ;
rec . $slot . addClass ( ' messenger- first') ;
}
}
}
if ( last != null ) {
last . $slot . addClass ( ' last') ;
last . $slot . addClass ( ' messenger- last') ;
}
return this . $el [ "" + ( anyShown ? 'remove' : 'add' ) + "Class" ] ( 'messenger-empty' ) ;
} ;
@ -916,12 +916,12 @@ window.Messenger.Events = (function() {
}
} ;
ActionMessenger . prototype . _get Messag e = function ( returnVal , def ) {
ActionMessenger . prototype . _get HandlerRespons e = function ( returnVal ) {
if ( returnVal === false ) {
return false ;
}
if ( returnVal === true || ! ( returnVal != null ) || typeof returnVal !== 'string' ) {
return def ;
if ( returnVal === true || ! ( returnVal != null ) ) {
return true ;
}
return returnVal ;
} ;
@ -965,7 +965,7 @@ window.Messenger.Events = (function() {
} ;
ActionMessenger . prototype . run = function ( ) {
var args , attr , events , m_opts , msg , o pts, promiseAttrs , _i , _len , _ref2 , _ref3 ,
var args , attr , events , getMessageText, handler , handlers , m_opts , msg , o ld, o pts, promiseAttrs , type , _i , _len , _ref2 , _ref3 ,
_this = this ;
m _opts = arguments [ 0 ] , opts = arguments [ 1 ] , args = 3 <= arguments . length ? _ _slice . call ( arguments , 2 ) : [ ] ;
if ( opts == null ) {
@ -973,54 +973,69 @@ window.Messenger.Events = (function() {
}
m _opts = $ . extend ( true , { } , this . messageDefaults , this . doDefaults , m _opts != null ? m _opts : { } ) ;
events = this . _parseEvents ( m _opts . events ) ;
getMessageText = function ( type , xhr ) {
var message ;
message = m _opts [ type + 'Message' ] ;
if ( _ . isFunction ( message ) ) {
return message . call ( _this , type , xhr ) ;
}
return message ;
} ;
msg = ( _ref2 = m _opts . messageInstance ) != null ? _ref2 : this . newMessage ( m _opts ) ;
if ( m _opts . id != null ) {
msg . options . id = m _opts . id ;
}
if ( m _opts . progressMessage != null ) {
msg . update ( $ . extend ( { } , m _opts , {
message : m _opts . progressMessage ,
message : getMessageText( 'progress' , null ) ,
type : 'info'
} ) ) ;
}
handlers = { } ;
_ . each ( [ 'error' , 'success' ] , function ( type ) {
var old, _ref3, _ref4 ;
var _ref3;
if ( ( _ref3 = opts [ type ] ) != null ? _ref3 . _originalHandler : void 0 ) {
opts [ type ] = opts [ type ] . _originalHandler ;
}
old = ( _ref4 = opts [ type ] ) != null ? _ref4 : function ( ) { } ;
opts [ type ] = function ( ) {
var data , msgOpts , msgText , r , reason , resp , xhr , _ref10 , _ref11 , _ref5 , _ref6 , _ref7 , _ref8 , _ref9 ;
return handlers [ type ] = function ( ) {
var data , defaultOpts , handlerResp , msgOpts , reason , resp , responseOpts , xhr , _base , _ref10 , _ref4 , _ref5 , _ref6 , _ref7 , _ref8 , _ref9 ;
resp = 1 <= arguments . length ? _ _slice . call ( arguments , 0 ) : [ ] ;
_ref 5 = _this . _normalizeResponse . apply ( _this , resp ) , reason = _ref 5[ 0 ] , data = _ref5 [ 1 ] , xhr = _ref5 [ 2 ] ;
_ref 4 = _this . _normalizeResponse . apply ( _this , resp ) , reason = _ref 4[ 0 ] , data = _ref4 [ 1 ] , xhr = _ref4 [ 2 ] ;
if ( type === 'success' && ! ( msg . errorCount != null ) && m _opts . showSuccessWithoutError === false ) {
m _opts [ 'successMessage' ] = null ;
}
if ( type === 'error' ) {
if ( ( _ref 6 = m _opts . errorCount ) == null ) {
if ( ( _ref 5 = m _opts . errorCount ) == null ) {
m _opts . errorCount = 0 ;
}
m _opts . errorCount += 1 ;
}
msgText = _this . _getMessage ( r = old . apply ( null , resp ) , m _opts [ type + 'Message' ] ) ;
handlerResp = m _opts . returnsPromise ? resp [ 0 ] : typeof ( _base = opts [ type ] ) . _originalHandler === "function" ? _base . _originalHandler . apply ( _base , resp ) : void 0 ;
responseOpts = _this . _getHandlerResponse ( handlerResp ) ;
if ( _ . isString ( responseOpts ) ) {
responseOpts = {
message : responseOpts
} ;
}
if ( type === 'error' && ( ( xhr != null ? xhr . status : void 0 ) === 0 || reason === 'abort' ) ) {
msg . hide ( ) ;
return ;
}
if ( type === 'error' && ( ( m _opts . ignoredErrorCodes != null ) && ( _ref7 = xhr != null ? xhr . status : void 0 , _ _indexOf . call ( m _opts . ignoredErrorCodes , _ref7 ) >= 0 ) ) ) {
if ( type === 'error' && ( ( m _opts . ignoredErrorCodes != null ) && ( _ref 6 = xhr != null ? xhr . status : void 0 , _ _indexOf . call ( m _opts . ignoredErrorCodes , _ref 6 ) >= 0 ) ) ) {
msg . hide ( ) ;
return ;
}
msgOpts = $ . extend ( { } , m _opts , {
message : msgText ,
defaultOpts = {
message : getMessageText( type , xhr ) ,
type : type ,
events : ( _ref 8 = events [ type ] ) != null ? _ref 8 : { } ,
events : ( _ref 7 = events [ type ] ) != null ? _ref 7 : { } ,
hideOnNavigate : type === 'success'
} ) ;
if ( typeof ( ( _ref9 = msgOpts . retry ) != null ? _ref9 . allow : void 0 ) === 'number' ) {
} ;
msgOpts = $ . extend ( { } , m _opts , defaultOpts , responseOpts ) ;
if ( typeof ( ( _ref8 = msgOpts . retry ) != null ? _ref8 . allow : void 0 ) === 'number' ) {
msgOpts . retry . allow -- ;
}
if ( type === 'error' && ( xhr != null ? xhr . status : void 0 ) >= 500 && ( ( _ref 10 = msgOpts . retry ) != null ? _ref 10 . allow : void 0 ) ) {
if ( type === 'error' && ( xhr != null ? xhr . status : void 0 ) >= 500 && ( ( _ref 9 = msgOpts . retry ) != null ? _ref 9 . allow : void 0 ) ) {
if ( msgOpts . retry . delay == null ) {
if ( msgOpts . errorCount < 4 ) {
msgOpts . retry . delay = 10 ;
@ -1029,7 +1044,7 @@ window.Messenger.Events = (function() {
}
}
if ( msgOpts . hideAfter ) {
if ( ( _ref1 1 = msgOpts . _hideAfter ) == null ) {
if ( ( _ref1 0 = msgOpts . _hideAfter ) == null ) {
msgOpts . _hideAfter = msgOpts . hideAfter ;
}
msgOpts . hideAfter = msgOpts . _hideAfter + msgOpts . retry . delay ;
@ -1060,16 +1075,26 @@ window.Messenger.Events = (function() {
delete m _opts . _retryActions ;
}
msg . update ( msgOpts ) ;
if ( msgText ) {
if ( responseOpts && msgOpts . message ) {
$ . globalMessenger ( ) ;
return msg . show ( ) ;
} else {
return msg . hide ( ) ;
}
} ;
return opts [ type ] . _originalHandler = old ;
} ) ;
if ( ! m _opts . returnsPromise ) {
for ( type in handlers ) {
handler = handlers [ type ] ;
old = opts [ type ] ;
opts [ type ] = handler ;
opts [ type ] . _originalHandler = old ;
}
}
msg . _actionInstance = m _opts . action . apply ( m _opts , [ opts ] . concat ( _ _slice . call ( args ) ) ) ;
if ( m _opts . returnsPromise ) {
msg . _actionInstance . then ( handlers . success , handlers . error ) ;
}
promiseAttrs = [ 'done' , 'progress' , 'fail' , 'state' , 'then' ] ;
for ( _i = 0 , _len = promiseAttrs . length ; _i < _len ; _i ++ ) {
attr = promiseAttrs [ _i ] ;
@ -1090,6 +1115,14 @@ window.Messenger.Events = (function() {
return this . run . apply ( this , [ m _opts ] . concat ( _ _slice . call ( args ) ) ) ;
} ;
ActionMessenger . prototype . expectPromise = function ( action , m _opts ) {
m _opts = _ . extend ( { } , m _opts , {
action : action ,
returnsPromise : true
} ) ;
return this . run ( m _opts ) ;
} ;
return ActionMessenger ;
} ) ( _Messenger ) ;