Index: trunk/extensions/AJAXPoll/resources/ajaxpoll.js |
— | — | @@ -1,22 +1,48 @@ |
2 | | -var ajaxpolltmp; |
| 2 | +var ajaxpollTmp; |
3 | 3 | |
4 | 4 | $(".ajaxpoll-answer-vote").live("mouseover", |
5 | 5 | function(){ |
6 | | - var sp=$(this).find("span"); |
7 | | - ajaxpolltmp=sp.html(); |
8 | | - sp.text(sp.attr("title")); |
9 | | - sp.attr("title",""); |
| 6 | + var sp=$(this).find("span"); |
| 7 | + ajaxpollTmp=sp.html(); |
| 8 | + sp.text(sp.attr("title")); |
| 9 | + sp.attr("title",""); |
10 | 10 | } |
11 | 11 | ); |
12 | 12 | |
13 | 13 | $(".ajaxpoll-answer-vote").live("mouseout", |
14 | 14 | function(){ |
15 | | - var sp=$(this).find("span"); |
16 | | - sp.attr("title",sp.text()); |
17 | | - sp.text(ajaxpolltmp); |
| 15 | + var sp=$(this).find("span"); |
| 16 | + sp.attr("title",sp.text()); |
| 17 | + sp.text(ajaxpollTmp); |
18 | 18 | } |
19 | 19 | ); |
20 | 20 | |
| 21 | +/* attach click handler */ |
| 22 | +$(".ajaxpoll-answer") |
| 23 | + .live("click", |
| 24 | + function(event){ |
| 25 | + event.preventDefault(); |
| 26 | + event.stopPropagation(); |
| 27 | + $this = $(this); |
| 28 | + var poll = $this.attr( "poll" ); |
| 29 | + var answer = $this.attr("answer"); |
| 30 | + $this |
| 31 | + .addClass("ajaxpoll-checkevent") |
| 32 | + .find("input").prop("checked",true); |
| 33 | + $( "#ajaxpoll-ajax-"+poll ) |
| 34 | + .html("Please wait, submitting your vote.") |
| 35 | + .css("display","block"); |
| 36 | + if (useAjax){ |
| 37 | + sajax_do_call( |
| 38 | + "AJAXPoll::submitVote", |
| 39 | + [poll,answer], |
| 40 | + $("#ajaxpoll-container-"+poll)[0] |
| 41 | + ) |
| 42 | + } else { |
| 43 | + $("#ajaxpoll-answer-id-"+poll).submit(); |
| 44 | + } |
| 45 | + } |
| 46 | + ) |
21 | 47 | |
22 | 48 | $(".ajaxpoll-answer-name:not(.ajaxpoll-answer-name-revoke) label").live("mouseover", |
23 | 49 | function(){ |
Index: trunk/extensions/AJAXPoll/AJAXPoll_body.php |
— | — | @@ -30,7 +30,7 @@ |
31 | 31 | |
32 | 32 | # The callback function for converting the input text to HTML output |
33 | 33 | static function AJAXPollRender( $input, $params = array(), Parser $parser ) { |
34 | | - global $wgUser, $wgOut, $wgTitle, $wgScriptPath, |
| 34 | + global $wgUser, $wgOut, $wgTitle, $wgScriptPath, $wgUseAjax, |
35 | 35 | $wgAJAXPollTrackingCategory; |
36 | 36 | |
37 | 37 | $parser->disableCache(); |
— | — | @@ -55,6 +55,16 @@ |
56 | 56 | $input = trim( strip_tags( $input->getText() ) ); |
57 | 57 | $lines = explode( "\n", trim( $input ) ); |
58 | 58 | |
| 59 | + // compatibility for non-ajax requests - just in case |
| 60 | + if ( !$wgUseAjax ) { |
| 61 | + $responseId = "ajaxpoll-post-id"; |
| 62 | + $responseAnswer = "ajaxpoll-post-answer-$id"; |
| 63 | + |
| 64 | + if ( isset( $_POST[$responseId] ) && isset( $_POST[$responseAnswer] ) && $_POST[$responseId] == $id ) { |
| 65 | + AJAXPoll::submitVote( $id, intval( $_POST[$responseAnswer] ) ); |
| 66 | + } |
| 67 | + } |
| 68 | + |
59 | 69 | $dbw = wfGetDB( DB_MASTER ); |
60 | 70 | $dbw->begin( __METHOD__ ); |
61 | 71 | |
— | — | @@ -146,6 +156,7 @@ |
147 | 157 | |
148 | 158 | public static function submitVote( $id, $answer ) { |
149 | 159 | global $wgUser,$wgOut; |
| 160 | + // echo "id: $id ans $answer<br/>"; |
150 | 161 | |
151 | 162 | $dbw = wfGetDB( DB_MASTER ); |
152 | 163 | |
— | — | @@ -292,7 +303,8 @@ |
293 | 304 | } |
294 | 305 | // HTML output has to be on one line thanks to a MediaWiki bug |
295 | 306 | // @see https://bugzilla.wikimedia.org/show_bug.cgi?id=1319 |
296 | | - $ret = '<div id="ajaxpoll-id-' . $id . '" class="ajaxpoll"> |
| 307 | + $ret = '<script>var useAjax='. ( !empty($wgUseAjax) ? "true" : "false" ) . ';</script> |
| 308 | +<div id="ajaxpoll-id-' . $id . '" class="ajaxpoll"> |
297 | 309 | <div id="ajaxpoll-ajax-' . $id . '" class="ajaxpoll-ajax"' . $attributes . '>' . $ajaxMessage . '</div> |
298 | 310 | <div class="ajaxpoll-question">' . strip_tags( $lines[0] ) . '</div>'; |
299 | 311 | |
— | — | @@ -343,25 +355,18 @@ |
344 | 356 | |
345 | 357 | if ( $wgUser->isAllowed( 'ajaxpoll-vote' ) ) { |
346 | 358 | |
347 | | - if ( $wgUseAjax ) { |
348 | | - $submitJS = "sajax_do_call(\"AJAXPoll::submitVote\",[\"" . $id . "\",\"" . $answer . "\"],$(\"#ajaxpoll-container-" . $id . "\")[0]);"; |
349 | | - } else { |
350 | | - $submitJS = "$(\"#ajaxpoll-answer-id-" . $id . "\").submit();"; |
351 | | - } |
352 | | - |
353 | | - |
354 | 359 | // HTML output has to be on one line thanks to a MediaWiki bug |
355 | 360 | // @see https://bugzilla.wikimedia.org/show_bug.cgi?id=1319 |
356 | 361 | |
357 | 362 | if ( $vote ) { |
358 | 363 | $ret .= " |
359 | | -<div id='ajaxpoll-answer-$xid' class='ajaxpoll-answer'><div class='ajaxpoll-answer-name'><label for='ajaxpoll-post-answer-$xid' onclick='$(\"#ajaxpoll-ajax-" . $xid . "\").html(\"" . wfMsg( 'ajaxpoll-submitting' ) . "\").css(\"display\",\"block\");$(this).addClass(\"ajaxpoll-checkevent\").prop(\"checked\",true);" . $submitJS . "'><input type='radio' id='ajaxpoll-post-answer-$xid' name='ajaxpoll-post-answer-$xid' value='" . $answer . "' " . ( $our ? 'checked=true ' : '' ) . "/>" . strip_tags( $lines[$i] ) . |
| 364 | +<div id='ajaxpoll-answer-$xid' class='ajaxpoll-answer' poll='$id' answer='$answer'><div class='ajaxpoll-answer-name'><label for='ajaxpoll-post-answer-$xid'><input type='radio' id='ajaxpoll-post-answer-$xid' name='ajaxpoll-post-answer-$id' value='" . $answer . "' " . ( $our ? 'checked=true ' : '' ) . "/>" . strip_tags( $lines[$i] ) . |
360 | 365 | "</label></div><div class='ajaxpoll-answer-vote" . ( $our ? ' ajaxpoll-our-vote' : '' ) ."'><span title='" . wfMsg( 'ajaxpoll-percent-votes', sprintf( $percent ) ) . "'>" . ( ( isset( $poll_result ) && !empty( $poll_result[$i + 1] ) ) ? $poll_result[$i + 1] : 0 ) . "</span><div style='width: " . $percent . "%;" . ( $percent == 0 ? ' border:0;' : '' ) . "'></div></div> |
361 | 366 | </div> |
362 | 367 | "; |
363 | 368 | } else { |
364 | 369 | $ret .= " |
365 | | -<div id='ajaxpoll-answer-$xid' class='ajaxpoll-answer'><div class='ajaxpoll-answer-name ajaxpoll-answer-name-revoke'><label for='ajaxpoll-post-answer-$xid' onclick='$(\"#ajaxpoll-ajax-" . $xid . "\").html(\"" . wfMsg( 'ajaxpoll-submitting' ) . "\").css(\"display\",\"block\");$(this).addClass(\"ajaxpoll-checkevent\").prop(\"checked\",true);" . $submitJS . "'><input type='radio' id='ajaxpoll-post-answer-$xid' name='ajaxpoll-post-answer-$xid' value='" . $answer . "' " . ( $our ? 'checked=true ' : '' ) . "/>" . strip_tags( $lines[$i] ) . |
| 370 | +<div id='ajaxpoll-answer-$xid' class='ajaxpoll-answer' poll='$id' answer='$answer'><div class='ajaxpoll-answer-name ajaxpoll-answer-name-revoke'><label for='ajaxpoll-post-answer-$xid'><input type='radio' id='ajaxpoll-post-answer-$xid' name='ajaxpoll-post-answer-$id' value='" . $answer . "' " . ( $our ? 'checked=true ' : '' ) . "/>" . strip_tags( $lines[$i] ) . |
366 | 371 | "</label></div> |
367 | 372 | </div> |
368 | 373 | "; |
— | — | @@ -370,7 +375,7 @@ |
371 | 376 | } else { |
372 | 377 | |
373 | 378 | $ret .= " |
374 | | -<div id='ajaxpoll-answer-" . $xid . "' class='ajaxpoll-answer'><div class='ajaxpoll-answer-name'><label for='ajaxpoll-post-answer-" . $xid . "' onclick='$(\"#ajaxpoll-ajax-" . $xid . "\").html(\"" . wfMsg( 'ajaxpoll-vote-permission' ) . "\").css(\"display\",\"block\");'><input disabled='disabled' type='radio' id='ajaxpoll-post-answer-" . $xid . "' name='ajaxpoll-post-answer-" . $xid . "' value='" . $answer . "'/>" . strip_tags( $lines[$i] ) . |
| 379 | +<div id='ajaxpoll-answer-" . $xid . "' class='ajaxpoll-answer' poll='$id' answer='$answer'><div class='ajaxpoll-answer-name'><label for='ajaxpoll-post-answer-" . $xid . "' onclick='$(\"#ajaxpoll-ajax-" . $xid . "\").html(\"" . wfMsg( 'ajaxpoll-vote-permission' ) . "\").css(\"display\",\"block\");'><input disabled='disabled' type='radio' id='ajaxpoll-post-answer-" . $xid . "' name='ajaxpoll-post-answer-" . $id . "' value='" . $answer . "'/>" . strip_tags( $lines[$i] ) . |
375 | 380 | "</label></div><div class='ajaxpoll-answer-vote" . ( $our ? ' ajaxpoll-our-vote' : '' ) ."'><span title='" . wfMsg( 'ajaxpoll-percent-votes', sprintf( $percent ) ) . "'>" . ( ( isset( $poll_result ) && !empty( $poll_result[$i + 1] ) ) ? $poll_result[$i + 1] : 0 ) . "</span><div style='width: " . $percent . "%;" . ( $percent == 0 ? ' border:0;' : '' ) . "'></div></div> |
376 | 381 | </div> |
377 | 382 | "; |
Index: trunk/extensions/AJAXPoll/AJAXPoll.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | * @author Jack Phoenix <jack@countervandalism.net> |
21 | 21 | * @author Thomas Gries |
22 | 22 | * @maintainer Thomas Gries |
23 | | - * @version 1.741 |
| 23 | + * @version 1.75 |
24 | 24 | * @link http://www.mediawiki.org/wiki/Extension:AJAX_Poll Documentation |
25 | 25 | */ |
26 | 26 | |
— | — | @@ -31,7 +31,7 @@ |
32 | 32 | $wgExtensionCredits['parserhook'][] = array( |
33 | 33 | 'path' => __FILE__, |
34 | 34 | 'name' => 'AJAX Poll', |
35 | | - 'version' => '1.741 20120317', |
| 35 | + 'version' => '1.75 20120317', |
36 | 36 | 'author' => array( 'Dariusz Siedlecki', 'Jack Phoenix', 'Thomas Gries' ), |
37 | 37 | 'descriptionmsg' => 'ajaxpoll-desc', |
38 | 38 | 'url' => 'https://www.mediawiki.org/wiki/Extension:AJAX_Poll', |