diff options
author | Igor Wiedler <igor@wiedler.ch> | 2012-02-15 19:32:53 +0100 |
---|---|---|
committer | Igor Wiedler <igor@wiedler.ch> | 2012-03-31 02:09:26 +0200 |
commit | de82608e6ffa5e2bc12654197b7d7bd580563ddc (patch) | |
tree | 67dcccf95b56dab2f27e28631f2155a75e1bb03c /phpBB/assets | |
parent | 4848d6c9e839c287de736cf3badac42e859eaa69 (diff) | |
download | forums-de82608e6ffa5e2bc12654197b7d7bd580563ddc.tar forums-de82608e6ffa5e2bc12654197b7d7bd580563ddc.tar.gz forums-de82608e6ffa5e2bc12654197b7d7bd580563ddc.tar.bz2 forums-de82608e6ffa5e2bc12654197b7d7bd580563ddc.tar.xz forums-de82608e6ffa5e2bc12654197b7d7bd580563ddc.zip |
[feature/ajax] Refactor phpbb.ajaxify event callback
PHPBB3-10270
Diffstat (limited to 'phpBB/assets')
-rw-r--r-- | phpBB/assets/javascript/core.js | 56 |
1 files changed, 25 insertions, 31 deletions
diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 4300e7056f..b42870f466 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -249,7 +249,7 @@ phpbb.ajaxify = function(options) { event_name = is_form ? 'submit' : 'click'; elements.bind(event_name, function() { - var action, data, path, that = this, $this = $(this); + var action, method, data, that = this, $this = $(this); if (!$this.attr('data-ajax')) { @@ -333,45 +333,39 @@ phpbb.ajaxify = function(options) { // If the element is a form, POST must be used and some extra data must // be taken from the form. var run_filter = (typeof options.filter === 'function'); + if (is_form) { - action = /action\[([a-z]+)\]/.exec(this.name); - data = decodeURI($this.closest('form').serialize()); - path = $this.closest('form').attr('action').replace('&', '&'); - - if (action) - { - action = action[1]; - data += '&action=' + action; - } - else - { - data += '&' + this.name + '=' + this.value; - } - - // If filter function returns true, cancel the AJAX functionality, - // and return true (meaning that the HTTP request will be sent normally). - if (run_filter && options.filter.call($this.parents('form')[0], action, data)) - { - return true; - } - phpbb.loading_alert(); - $.post(path, data, return_handler); + action = $this.attr('action').replace('&', '&'); + data = $this.serializeArray(); + method = $this.attr('method'); } else { - // If filter function returns true, cancel the AJAX functionality, - // and return true (meaning that the HTTP request will be sent normally). - if (run_filter && options.filter.call(this)) - { - return true; - } - phpbb.loading_alert(); - $.get(this.href, return_handler); + action = this.href; + data = null; + method = 'GET'; + } + + // If filter function returns true, cancel the AJAX functionality, + // and return true (meaning that the HTTP request will be sent normally). + if (run_filter && options.filter.call(this, data)) + { + return true; } + phpbb.loading_alert(); + + $.ajax({ + url: action, + type: method, + data: data, + success: return_handler + }); + return false; }); + return this; } |