Skip to content

Commit

Permalink
[ticket/10271] Added ability for exceptions to phpbb.ajaxify.
Browse files Browse the repository at this point in the history
Also made it easy for additional options to be added in the future.

PHPBB3-10271
  • Loading branch information
callumacrae authored and p committed Dec 24, 2011
1 parent 16edb77 commit 8247e10
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion phpBB/styles/prosilver/template/viewtopic_body.html
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ <h3 <!-- IF postrow.S_FIRST_ROW -->class="first"<!-- ENDIF -->><!-- IF postrow.P
<!-- INCLUDE jumpbox.html -->

<!-- IF S_TOPIC_MOD -->
<form method="post" action="{S_MOD_ACTION}">
<form method="post" action="{S_MOD_ACTION}" id="quickmodform">
<fieldset class="quickmod">
<label for="quick-mod-select">{L_QUICK_MOD}:</label> {S_TOPIC_MOD} <input type="submit" value="{L_GO}" class="button2" />
{S_FORM_TOKEN}
Expand Down
17 changes: 15 additions & 2 deletions phpBB/styles/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ phpbb.confirm = function(msg, callback) {
/**
* Makes a link use AJAX instead of loading an entire page.
*
* @param string condition The element to capture.
* @param object options Options, if a string will be the selector.
* @param bool/function refresh If we are sent back a refresh, should it be
* acted upon? This can either be true / false / a function.
* @param function callback Callback.
*/
phpbb.ajaxify = function(selector, refresh, callback) {
phpbb.ajaxify = function(options, refresh, callback) {

//private function to handle refreshes
function handle_refresh(data, refresh, div)
Expand All @@ -109,9 +109,20 @@ phpbb.ajaxify = function(selector, refresh, callback) {
}, data.time * 1000);
}

var selector = (typeof options === 'string') ? options : options.selector;

var is_form = $(selector).is('form');
$(selector + ((is_form) ? ' input:submit' : '')).click(function() {
var act, data, path, that = this;

if (typeof options.exception !== 'undefined')
{
if (options.exception(this))
{
return true;
}
}

function return_handler(res)
{
res = JSON.parse(res);
Expand Down Expand Up @@ -209,3 +220,5 @@ phpbb.ajaxify('.rightside a[href*="mark="]'); //captures topics and forums
phpbb.ajaxify('.mcp_approve', false, function(el, act) {
$(el).parents((act === 'approve') ? '.rules' : '.post').remove_anim();
});

phpbb.ajaxify('#quickmodform');

0 comments on commit 8247e10

Please sign in to comment.