Skip to content

Instantly share code, notes, and snippets.

@gartmeier
Last active November 23, 2018 09:58
Show Gist options
  • Save gartmeier/3dc02db0d6ae206957d2c9b6a8f2a29d to your computer and use it in GitHub Desktop.
Save gartmeier/3dc02db0d6ae206957d2c9b6a8f2a29d to your computer and use it in GitHub Desktop.
$(function() {
$.fireEvent = function(name, data) {
var deferred = $.Deferred(),
callback = 'cb' + Math.random().toString(36).substring(7);
if (data) {
data.callBackFunc = callback;
data.callBack = callback;
data.source = $.fireEvent.defaults.source;
}
window[callback] = function(data) {
try {
data = JSON.parse(data);
} catch (e) {
console.error('couldn\'t parse response');
}
deferred.resolve(data);
delete window[callback];
};
if ($.fireEvent.defaults.timeout) {
setTimeout(function() {
deferred.reject('timeout');
delete window[callback];
}, $.fireEvent.defaults.timeout);
}
Ti.App.fireEvent(name, data);
return deferred;
};
$.fireEvent.defaults = {
source: 'modal',
timeout: 500
};
});
@gartmeier
Copy link
Author

gartmeier commented Nov 16, 2018

Example:

$.fireEvent('searchPitcherFile', {keywords: 'System:HasFilters', rangeCheck: true})
    .done(console.info)
    .fail(console.error);
    .always(console.log);

@digi604
Copy link

digi604 commented Nov 23, 2018

noice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment