Skip to content

Commit

Permalink
Add interval and timeout features
Browse files Browse the repository at this point in the history
Closes #38
  • Loading branch information
paltman committed Jul 22, 2013
1 parent 336b805 commit 67e9dd8
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions js/eldarion-ajax-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,38 @@
$this.closest(selector).remove();
};

Ajax.prototype.timeout = function (i, el) {
var $el = $(el),
timeout = $el.data('timeout'),
url = $el.data('url'),
method = $el.data('method');

if (!method) {
method = 'get';
}

window.setTimeout(Ajax.prototype._ajax, timeout, $el, url, method, null);
};

Ajax.prototype.interval = function (i, el) {
var $el = $(el),
interval = $el.data('interval'),
url = $el.data('url'),
method = $el.data('method');

if (!method) {
method = 'get';
}

window.setInterval(Ajax.prototype._ajax, interval, $el, url, method, null);
};

$(function () {
$('body').on('click', 'a.ajax', Ajax.prototype.click);
$('body').on('submit', 'form.ajax', Ajax.prototype.submit);
$('body').on('click', 'a[data-cancel-closest]', Ajax.prototype.cancel);

$('[data-timeout]').each(Ajax.prototype.timeout);
$('[data-interval]').each(Ajax.prototype.interval);
});
}(window.jQuery));

0 comments on commit 67e9dd8

Please sign in to comment.