Changeset 949

Show
Ignore:
Timestamp:
03/14/08 21:42:52 (9 months ago)
Author:
_ck_
Message:

0.5.4 javascript payload is now kept as small as possible,
also more "ajax-like" actions for new/edit polls,
CSS will be need to be reset in admin panel because of xhtml changes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • bbpress-polls/trunk/bb-polls.php

    r948 r949  
    66Author: _ck_ 
    77Author URI: http://bbShowcase.org 
    8 Version: 0.5.2 
     8Version: 0.5.4 
    99 
    1010License: CC-GNU-GPL http://creativecommons.org/licenses/GPL/2.0/ 
     
    5858 
    5959        $bb_polls['style']= 
    60         "#bb_polls {list-style: none; width:350px; line-height:120%; margin:5px 0; padding:5px; border:1px solid #ADADAD;  font-size:85%; color:#000; background:#eee; } 
     60        "#bb_polls {list-style: none; width:400px; line-height:120%; margin:5px 0; padding:5px; border:1px solid #ADADAD;  font-size:90%; color:#000; background:#eee; } 
    6161        #bb_polls .submit {cursor: pointer; cursor: hand; text-align:center; padding:2px 5px;} 
    6262        #bb_polls .nowrap {white-space:nowrap;} 
    6363        #bb_polls p {margin:15px 0;padding:0;} 
    6464        #bb_polls .poll_question, #bb_polls .poll_footer {font-weight:bold; text-align:center; color:#2E6E15;} 
    65         #bb_polls .poll_label {font-weight:bold;}                                                              
    66         #bb_polls .poll_option {margin:-12px 0 -5px 0; text-align:center;font-weight:bold; font-size:9px; line-height:5px; padding:2px 1px;  border:1px solid #303030; color:#fff; } 
     65        #bb_polls .poll_label {font-weight:bold; margin:1em 0 1em 1em;}                                                                
     66        #bb_polls .poll_option {margin:2px 0 -2px 0; text-align:center;font-weight:bold; font-size:9px; line-height:5px; padding:2px 1px;  border:1px solid #303030; color:#fff; } 
    6767        #bb_polls .poll_option1 {background:red;} 
    6868        #bb_polls .poll_option2 {background:green;} 
     
    7777                                         
    7878        $bb_polls['poll_question']=__("Would you like to add a poll to this topic for members to vote on?"); 
    79         $bb_polls['poll_instructions']=__("You may submit a poll question with several options for other members to vote from."); 
     79        $bb_polls['poll_instructions']=__("You may add a poll question with options for members to vote from."); 
    8080        $bb_polls['label_single']=__("you can vote on <u>ONE</u> choice"); 
    8181        $bb_polls['label_multiple']=__("you can vote on <u>MULTIPLE</u> choices"); 
     
    297297if ($bb_polls['minimum_view_level']=="read" || bb_current_user_can($bb_polls['minimum_view_level']) ) { 
    298298$topic_id=bb_polls_check_cache($topic_id); 
    299 $output='<p class="poll_question">'.$bb_polls['label_poll_text'].': '.$poll_options['poll_question'].'</p>'; 
     299$output='<div class="poll_question">'.$bb_polls['label_poll_text'].': '.$poll_options['poll_question'].'</div>'; 
    300300 
    301301if (!$poll_options['poll_multiple_choice'] && isset($poll_options['poll_count_0'])) {$real_vote_count=intval($poll_options['poll_count_0']);} 
     
    304304for ($i=1; $i<=$bb_polls['max_options']; $i++) { 
    305305        if (isset($poll_options[$i])) {                  
    306                 $output.= '<p class="poll_label">'.$poll_options[$i].' : ';    
     306                $output.= '<div class="poll_label">'.$poll_options[$i].' : ';  
    307307                $test=(isset($poll_options['poll_count_'.$i]) ? intval($poll_options['poll_count_'.$i]) : 0); 
    308                 $output.= ' ('.$test.' '.$bb_polls['label_votes_text'].')'; 
     308                $output.= ' ('.$test.' '.$bb_polls['label_votes_text'].') <br />'; 
    309309                if ($test) { 
    310310                        $vote_percent=(round($test/$real_vote_count,2)*100); 
     
    312312                        $output.= ' <div style="width:'.$vote_width.'%" class="poll_option poll_option'.$i.'"> '.$vote_percent.' % </div> '; 
    313313                } 
    314                 $output.= ' </p>'; 
     314                $output.= ' </div>'; 
    315315        } 
    316316} 
     
    318318$output.= '<p class="poll_footer">'.intval($test).' '.$bb_polls['label_votes_text'].'</p>'; 
    319319if (isset($_GET['show_poll_results']) || (bb_get_current_user_info( 'id' ) && !bb_polls_has_voted(bb_get_current_user_info( 'id' ),$topic_id) )) { 
    320 $output.= '<p class="poll_footer">( <a onClick="if (window.bb_polls_insert_ajax) {bb_polls_show_poll_vote_form_ajax();return false;}" href="'.remove_query_arg( 'show_poll_results').'">'.$bb_polls['label_now_text'].'</a> )</p>'; 
     320$output.= '<p class="poll_footer">( <a onClick="if (window.bb_polls_insert_ajax) {bb_polls_show_poll_vote_form_ajax();return false;}" href="'.remove_query_arg(array('start_new_poll','edit_poll','delete_poll','show_poll_vote_form_ajax','show_poll_setup_form_ajax','bb_polls_cache')).'">'.$bb_polls['label_now_text'].'</a> )</p>'; 
    321321} 
    322322$output.=bb_polls_edit_link(); 
     
    331331$topic_id=bb_polls_check_cache($topic_id); 
    332332if ($poll_options['poll_multiple_choice']==1) {$poll_type="checkbox";} else {$poll_type="radio";} 
    333 $output='<form action="'.remove_query_arg( 'show_poll_results').'" method="post" name="bb_polls" onSubmit="if (window.bb_polls_insert_ajax) {bb_polls_add_vote_ajax();return false;}"> 
    334          <p class="poll_question">'.$bb_polls['label_poll_text'].': '.$poll_options['poll_question'].'</p>'; 
     333$output='<form action="'.remove_query_arg(array('start_new_poll','edit_poll','delete_poll','show_poll_vote_form_ajax','show_poll_setup_form_ajax','bb_polls_cache')).'" method="post" name="bb_polls" onSubmit="if (window.bb_polls_insert_ajax) {bb_polls_add_vote_ajax();return false;}"> 
     334         <div class="poll_question">'.$bb_polls['label_poll_text'].': '.$poll_options['poll_question'].'</div>'; 
    335335for ($i=1; $i<=$bb_polls['max_options']; $i++) { 
    336336        if (isset($poll_options[$i])) { 
     
    389389$topic_id=bb_polls_check_cache($topic_id); 
    390390 
    391 $output='<form action="'.remove_query_arg(array('start_new_poll','edit_poll')).'" method="post"><p>'.$bb_polls['poll_instructions'].'</p>'; 
     391$output='<form action="'.remove_query_arg(array('start_new_poll','edit_poll','delete_poll','show_poll_vote_form_ajax','show_poll_setup_form_ajax','bb_polls_cache')).'" method="post"><p>'.$bb_polls['poll_instructions'].'</p>'; 
    392392                         
    393 $output.='<p class="poll_label">'.$bb_polls['label_question_text'].' : <input name="poll_question" type="text" style="width:98%" maxlength="'.$bb_polls['max_length'].'" value="'.$poll_options['poll_question'].'" /></p>'; 
     393$output.='<div class="poll_label">'.$bb_polls['label_question_text'].' : <br /><input name="poll_question" type="text" style="width:98%" maxlength="'.$bb_polls['max_length'].'" value="'.$poll_options['poll_question'].'" /></div>'; 
    394394                         
    395 $output.='<p class="poll_label"><span class="nowrap"><input name="poll_multiple_choice" type="radio" value="0" '; 
     395$output.='<div class="poll_label"><span class="nowrap"><input name="poll_multiple_choice" type="radio" value="0" '; 
    396396$output.=($poll_options['poll_multiple_choice']) ? ' ' : ' checked="checked" '; 
    397397$output.=' />'.$bb_polls['label_single'].'</span> <span class="nowrap"><input name="poll_multiple_choice" type="radio" value="1" '; 
    398398$output.=($poll_options['poll_multiple_choice']) ? ' checked="checked" ' : ' '; 
    399 $output.=' /> '.$bb_polls['label_multiple'].'</span></p>'; 
     399$output.=' /> '.$bb_polls['label_multiple'].'</span></div>'; 
    400400                         
    401401for ($i=1; $i<=$bb_polls['max_options']; $i++) {                         
     
    403403                $output.='<a href="javascript:void(0)" onClick="this.style.display='."'none'".'; document.getElementById('."'poll_more_options'".').style.display='."'block'".'">[+] '.$bb_polls['label_option_text'].'</a><div id="poll_more_options" style="display:none;">'; 
    404404        } 
    405         $output.='<p class="poll_label">'.$bb_polls['label_option_text'].' #'.$i.' : <input name="poll_option_'.$i.'" type="text" style="width:98%" maxlength="'.$bb_polls['max_length'].'" value="'.$poll_options[$i].'" /></p>'; 
     405        $output.='<div class="poll_label">'.$bb_polls['label_option_text'].' #'.$i.' : <br /><input name="poll_option_'.$i.'" type="text" style="width:98%" maxlength="'.$bb_polls['max_length'].'" value="'.$poll_options[$i].'" /></div>'; 
    406406} // loop  
    407407if ($bb_polls['max_options']>4 && !$poll_options[5]) {$output.='</div>';} 
    408408                 
    409409$output.='<p class="poll_footer"> 
    410 <input class="submit" type="button"  value="'.$bb_polls['label_cancel_text'].'" onClick="document.location='."'".remove_query_arg( 'start_new_poll')."'".'" />  
     410<input class="submit" type="button"  value="'.$bb_polls['label_cancel_text'].'" onClick="document.location='."'".remove_query_arg(array('start_new_poll','edit_poll','delete_poll','show_poll_vote_form_ajax','show_poll_setup_form_ajax','bb_polls_cache'))."'".'" />  
    411411<input class="submit" type="submit"  value="'.$bb_polls['label_save_text'].'" /></p></form>'; 
    412412$output=stripslashes($output);if ($display) {echo '<li id="bb_polls" class="extra-caps-row">'.$output.'</li>';} else {return $output;} 
     
    435435        if (isset($_GET['delete_poll']) && intval($_GET['delete_poll'])) {       
    436436                bb_polls_delete_poll(); 
    437                 wp_redirect(remove_query_arg(array('start_new_poll','delete_poll'))); // I *really* don't like this technique but it's the only way to clear post data? 
     437                wp_redirect(remove_query_arg(array('start_new_poll','edit_poll','delete_poll','show_poll_vote_form_ajax','show_poll_setup_form_ajax','bb_polls_cache')));     // I *really* don't like this technique but it's the only way to clear post data? 
    438438        }                                
    439439        if (isset($_GET['show_poll_results_ajax'])) { 
     
    448448                echo 'bb_polls_insert_ajax("'.mysql_escape_string(bb_polls_show_poll_vote_form($topic_id,0)).'")'; 
    449449                exit(); 
     450        }        
     451        if (isset($_GET['show_poll_setup_form_ajax'])) { 
     452                $topic_id=intval($_GET['show_poll_setup_form_ajax']); 
     453                header("Content-Type: application/x-javascript"); 
     454                echo 'bb_polls_insert_ajax("'.mysql_escape_string(bb_polls_show_poll_setup_form($topic_id,0,1)).'")'; 
     455                exit(); 
    450456        } 
    451457        if (isset($_GET['add_vote_ajax'])) { 
     
    459465 
    460466function bb_polls_add_javascript($topic_id=0) { 
    461 global $bb_polls; 
    462 if ($bb_polls['use_ajax']) : 
     467global $bb_polls, $topic; 
     468if ($bb_polls['use_ajax'] && bb_current_user_can($bb_polls['minimum_vote_level']) ) : 
     469$topic_id=bb_polls_check_cache($topic_id); 
    463470echo '<scr'.'ipt type="text/javascript" defer="defer"> 
    464471<!-- 
     
    469476function append_dhead(bb_polls_src) { 
    470477if (bb_polls_script) {dhead.removeChild(bb_polls_script);} 
    471 d = new Date();  bb_polls_src=bb_polls_src+"&"+d.getTime(); 
     478d = new Date();  bb_polls_src=bb_polls_src+"&bb_polls_cache="+d.getTime(); 
    472479bb_polls_script = document.createElement("script"); 
    473480bb_polls_script.src = bb_polls_src; 
     
    483490} 
    484491function bb_polls_insert_ajax_delayed() {document.getElementById("bb_polls").innerHTML=bb_polls_htmldata;} 
    485  
     492'; 
     493 
     494// only add new poll support if they can add and there's no poll already  
     495if (bb_current_user_can($bb_polls['minimum_add_level']) && !isset($topic->poll_options)) {       
     496echo ' 
     497function bb_polls_start_new_poll_ajax() { 
     498append_dhead("'.add_query_arg( 'show_poll_setup_form_ajax', $topic_id).'"); 
     499
     500';} 
     501 
     502// only add edit support if they can edit and saved poll question with options    
     503if (bb_current_user_can($bb_polls['minimum_edit_level']) && isset($topic->poll_options)) {       
     504echo ' 
     505function bb_polls_edit_poll_ajax() { 
     506append_dhead("'.add_query_arg( 'show_poll_setup_form_ajax', $topic_id).'"); 
     507
     508';} 
     509 
     510// only add vote and view toggle support javascript if they have not yet voted 
     511if (!bb_polls_has_voted(bb_get_current_user_info( 'id' ),$topic_id) ) {  
     512echo ' 
    486513function bb_polls_show_poll_results_ajax() { 
    487 append_dhead("'.add_query_arg( 'show_poll_results_ajax', get_topic_id( $topic_id )).'"); 
    488 
    489  
     514append_dhead("'.add_query_arg( 'show_poll_results_ajax', $topic_id).'"); 
     515
    490516function bb_polls_show_poll_vote_form_ajax() { 
    491 var bb_polls_poll_vote_form = "'.mysql_escape_string(bb_polls_show_poll_vote_form(get_topic_id( $topic_id ),0)).'"; 
    492 if (bb_polls_poll_vote_form) {bb_polls_insert_ajax(bb_polls_poll_vote_form);} 
    493 else { 
    494 append_dhead("'.add_query_arg( 'show_poll_vote_form_ajax', get_topic_id( $topic_id )).'"); 
    495 
    496 
    497  
    498 function bb_polls_start_new_poll_ajax() { 
    499 var bb_polls_poll_setup_form = "'.mysql_escape_string(bb_polls_show_poll_setup_form(get_topic_id( $topic_id ),0,1)).'"; 
    500 if (bb_polls_poll_setup_form) {bb_polls_insert_ajax(bb_polls_poll_setup_form);} 
    501 
    502  
    503 function bb_polls_edit_poll_ajax() { 
    504 var bb_polls_poll_setup_form = "'.mysql_escape_string(bb_polls_show_poll_setup_form(get_topic_id( $topic_id ),0,1)).'"; 
    505 if (bb_polls_poll_setup_form) {bb_polls_insert_ajax(bb_polls_poll_setup_form);} 
    506 
    507  
     517append_dhead("'.add_query_arg( 'show_poll_vote_form_ajax', $topic_id).'"); 
     518
    508519function bb_polls_add_vote_ajax() { 
    509520vote=""; 
     
    516527        if (test && test.checked) {vote=vote+"&poll_vote_"+i+"="+i;} 
    517528} 
    518 if (vote.length) {append_dhead("'.add_query_arg( 'add_vote_ajax', get_topic_id( $topic_id )).'"+vote);} 
     529if (vote.length) {append_dhead("'.add_query_arg( 'add_vote_ajax', $topic_id).'"+vote);} 
    519530else {alert("'.$bb_polls['label_nocheck_text'].'"); return false;} 
    520531} 
     532';} 
     533 
     534echo ' 
    521535//--> 
    522536</scr'.'ipt>'; 
  • bbpress-polls/trunk/readme.txt

    r947 r949  
    5454* 0.50  2008-March-1 basic admin menu  added 
    5555* 0.5.2 2008-March-14 xhtml and non-ajax-edit bug fixes, props zmaroti 
     56* 0.5.3 2008-March-14 javascript payload is now kept as small as possible  
     57* 0.5.4 2008-March-14 new poll form (and edit form) remotely loaded when in "ajax" mode 
    5658         
    5759== To Do ==