Version 2.3.6
This commit is contained in:
1 parent
a3bb603c96
commit
19b38c7c74
764 files changed
+143731
-118164
No files matched your search
@@ -0,0 +1,440 @@
|
||||
//------------------------------------------
|
||||
// Invision Power Board v2.1
|
||||
// POLL JS File
|
||||
// (c) 2005 Invision Power Services, Inc.
|
||||
//
|
||||
// http://www.invisionboard.com
|
||||
// ASSUMES 'ipb_global.php' as been loaded
|
||||
//------------------------------------------
|
||||
|
||||
/*--------------------------------------------*/
|
||||
// INIT
|
||||
/*--------------------------------------------*/
|
||||
|
||||
//-------------------------------
|
||||
// DIV & FORM id names
|
||||
//-------------------------------
|
||||
|
||||
var open_div = 'poll-box-open';
|
||||
var closed_div = 'poll-box-closed';
|
||||
var stat_div = 'poll-box-stat';
|
||||
var main_div = 'poll-box-main';
|
||||
var form_id = 'postingform';
|
||||
|
||||
//-------------------------------
|
||||
// DIV AND FORM objects
|
||||
//-------------------------------
|
||||
|
||||
var openobj;
|
||||
var closedobj;
|
||||
var formobj;
|
||||
var statobj;
|
||||
var mainobj;
|
||||
|
||||
//-------------------------------
|
||||
// Counters
|
||||
//-------------------------------
|
||||
|
||||
var used_questions = 0;
|
||||
|
||||
/*--------------------------------------------*/
|
||||
// INIT STATE
|
||||
/*--------------------------------------------*/
|
||||
|
||||
function poll_init_state()
|
||||
{
|
||||
//-------------------------------
|
||||
// Get objects
|
||||
//-------------------------------
|
||||
|
||||
openobj = document.getElementById( open_div );
|
||||
closedobj = document.getElementById( closed_div );
|
||||
formobj = document.getElementById( form_id );
|
||||
statobj = document.getElementById( stat_div );
|
||||
mainobj = document.getElementById( main_div );
|
||||
|
||||
//-------------------------------
|
||||
// Open and close divs
|
||||
//-------------------------------
|
||||
|
||||
if ( showfullonload )
|
||||
{
|
||||
my_show_div( openobj );
|
||||
my_hide_div( closedobj );
|
||||
}
|
||||
else
|
||||
{
|
||||
my_show_div( closedobj );
|
||||
my_hide_div( openobj );
|
||||
}
|
||||
|
||||
poll_draw_main_box();
|
||||
}
|
||||
|
||||
/*--------------------------------------------*/
|
||||
// DRAW MAIN BOX
|
||||
/*--------------------------------------------*/
|
||||
|
||||
function poll_draw_main_box()
|
||||
{
|
||||
var html = '';
|
||||
used_questions = 0;
|
||||
|
||||
//-------------------------------
|
||||
// Draw all current questions
|
||||
//-------------------------------
|
||||
|
||||
for( var i in poll_questions )
|
||||
{
|
||||
var qhtml = '';
|
||||
used_questions++;
|
||||
|
||||
//-------------------------------
|
||||
// Show question box
|
||||
//-------------------------------
|
||||
|
||||
var question = poll_questions[i];
|
||||
|
||||
var this_poll_multi = '';
|
||||
|
||||
for ( var x in poll_multi )
|
||||
{
|
||||
if( x == i )
|
||||
{
|
||||
if( poll_multi[x] == 1 )
|
||||
{
|
||||
this_poll_multi = "checked='checked'";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var inputhtml = lang_build_string( html_question_box, i, _poll_make_form_safe( question ), this_poll_multi );
|
||||
|
||||
qhtml += "\n" + inputhtml + "\n";
|
||||
|
||||
//-------------------------------
|
||||
// Now, to add the poll choices..
|
||||
//-------------------------------
|
||||
|
||||
var choices = '';
|
||||
var choices_count = 0;
|
||||
|
||||
for ( var c in poll_choices )
|
||||
{
|
||||
var votes_box;
|
||||
|
||||
//-------------------------------
|
||||
// Is this a choice for this q?
|
||||
//-------------------------------
|
||||
|
||||
var id = c.replace( new RegExp( "^" + i + "_(\\d+)$" ), "$1" );
|
||||
|
||||
if ( ! isNaN( id ) )
|
||||
{
|
||||
if ( is_mod )
|
||||
{
|
||||
votes_box = lang_build_string( html_votes_box, i, id, poll_votes[c]);
|
||||
}
|
||||
else
|
||||
{
|
||||
votes_box = '';
|
||||
}
|
||||
|
||||
choices_count++;
|
||||
|
||||
choices += "\n" + lang_build_string( html_choice_box, i, id, _poll_make_form_safe( poll_choices[c] ), votes_box );
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------
|
||||
// Not used max questions?
|
||||
//-------------------------------
|
||||
|
||||
if ( choices_count < max_poll_choices )
|
||||
{
|
||||
choices += lang_build_string( html_add_choice, i );
|
||||
}
|
||||
|
||||
if ( choices != '' )
|
||||
{
|
||||
qhtml += "\n" + lang_build_string( html_choice_wrap, choices ) + "\n";
|
||||
}
|
||||
|
||||
//-------------------------------
|
||||
// Add wrapped question w/choice
|
||||
//-------------------------------
|
||||
|
||||
html += lang_build_string(html_question_wrap, qhtml );
|
||||
}
|
||||
|
||||
//-------------------------------
|
||||
// Add a question link?
|
||||
//-------------------------------
|
||||
|
||||
if ( used_questions < max_poll_questions )
|
||||
{
|
||||
html += lang_build_string( html_question_wrap, html_add_question );
|
||||
}
|
||||
|
||||
mainobj.innerHTML = html;
|
||||
|
||||
poll_update_state();
|
||||
}
|
||||
|
||||
/*--------------------------------------------*/
|
||||
// WRITE FORM TO ARRAY
|
||||
/*--------------------------------------------*/
|
||||
|
||||
function poll_write_form_to_array()
|
||||
{
|
||||
//-------------------------------
|
||||
// Update question array with form
|
||||
//-------------------------------
|
||||
|
||||
var tmp_poll_questions = {};
|
||||
var tmp_poll_choices = {};
|
||||
var tmp_poll_multi = {};
|
||||
|
||||
for ( var i in poll_questions )
|
||||
{
|
||||
//-------------------------------
|
||||
// Get form value...
|
||||
//-------------------------------
|
||||
|
||||
try
|
||||
{
|
||||
tmp_poll_questions[ i ] = document.getElementById( 'question_' + i ).value;
|
||||
}
|
||||
catch(e) { }
|
||||
}
|
||||
|
||||
for ( var x in poll_multi )
|
||||
{
|
||||
//-------------------------------
|
||||
// Get form value...
|
||||
//-------------------------------
|
||||
|
||||
try
|
||||
{
|
||||
tmp_poll_multi[ x ] = document.getElementById( 'multi_' + x ).checked ? 1 : 0;
|
||||
}
|
||||
catch(e) { }
|
||||
}
|
||||
|
||||
for ( var c in poll_choices )
|
||||
{
|
||||
//-------------------------------
|
||||
// Get form value...
|
||||
//-------------------------------
|
||||
|
||||
try
|
||||
{
|
||||
tmp_poll_choices[ c ] = document.getElementById( 'choice_' + c ).value;
|
||||
}
|
||||
catch(e) { }
|
||||
}
|
||||
|
||||
//-------------------------------
|
||||
// Update
|
||||
//-------------------------------
|
||||
|
||||
poll_questions = tmp_poll_questions;
|
||||
poll_choices = tmp_poll_choices;
|
||||
poll_multi = tmp_poll_multi;
|
||||
}
|
||||
|
||||
/*--------------------------------------------*/
|
||||
// ADD POLL QUESTION
|
||||
/*--------------------------------------------*/
|
||||
|
||||
function poll_add_question()
|
||||
{
|
||||
var maxid = 0;
|
||||
|
||||
//-------------------------------
|
||||
// Get max choice ID
|
||||
//-------------------------------
|
||||
|
||||
for ( var i in poll_questions )
|
||||
{
|
||||
if ( i > maxid )
|
||||
{
|
||||
maxid = parseInt(i);
|
||||
}
|
||||
}
|
||||
|
||||
maxid = maxid + 1;
|
||||
|
||||
poll_write_form_to_array();
|
||||
|
||||
poll_questions[ maxid ] = '';
|
||||
poll_multi[ maxid ] = '';
|
||||
|
||||
poll_draw_main_box();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------------------------*/
|
||||
// ADD POLL CHOICE
|
||||
/*--------------------------------------------*/
|
||||
|
||||
function poll_add_choice( qid )
|
||||
{
|
||||
var maxid = 0;
|
||||
|
||||
//-------------------------------
|
||||
// Get max choice ID
|
||||
//-------------------------------
|
||||
|
||||
for ( var c in poll_choices )
|
||||
{
|
||||
//-------------------------------
|
||||
// Is this a choice for this q?
|
||||
//-------------------------------
|
||||
|
||||
var id = c.replace( new RegExp( "^" + qid + "_(\\d+)$" ), "$1" );
|
||||
|
||||
if ( ! isNaN( id ) )
|
||||
{
|
||||
if ( id > maxid )
|
||||
{
|
||||
maxid = parseInt(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
maxid = maxid + 1;
|
||||
|
||||
poll_write_form_to_array();
|
||||
|
||||
poll_choices[ qid +'_'+maxid ] = '';
|
||||
|
||||
if ( is_mod )
|
||||
{
|
||||
poll_votes[ qid +'_'+maxid ] = 0;
|
||||
}
|
||||
|
||||
poll_draw_main_box();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------------------------*/
|
||||
// REMOVE POLL CHOICE
|
||||
/*--------------------------------------------*/
|
||||
|
||||
function poll_remove_choice( mainid )
|
||||
{
|
||||
if ( confirm( js_lang_confirm ) )
|
||||
{
|
||||
delete( poll_choices[ mainid ] );
|
||||
|
||||
if ( is_mod )
|
||||
{
|
||||
delete( poll_votes[ mainid ] );
|
||||
}
|
||||
|
||||
poll_write_form_to_array();
|
||||
poll_draw_main_box();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*--------------------------------------------*/
|
||||
// REMOVE POLL QUESTION
|
||||
/*--------------------------------------------*/
|
||||
|
||||
function poll_remove_question( mainid )
|
||||
{
|
||||
if ( confirm( js_lang_confirm ) )
|
||||
{
|
||||
//-------------------------------
|
||||
// Delete question
|
||||
//-------------------------------
|
||||
|
||||
delete( poll_questions[ mainid ] );
|
||||
|
||||
//-------------------------------
|
||||
// Delete choices
|
||||
//-------------------------------
|
||||
|
||||
for ( var c in poll_choices )
|
||||
{
|
||||
//-------------------------------
|
||||
// Is this a choice for this q?
|
||||
//-------------------------------
|
||||
|
||||
var id = c.replace( new RegExp( "^" + mainid + "_(\\d+)$" ), "$1" );
|
||||
|
||||
if ( ! isNaN( id ) )
|
||||
{
|
||||
delete( poll_choices[ c ] );
|
||||
|
||||
if ( is_mod )
|
||||
{
|
||||
delete( poll_votes[ c ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
poll_write_form_to_array();
|
||||
poll_draw_main_box();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*--------------------------------------------*/
|
||||
// UPDATE POLL STATE
|
||||
/*--------------------------------------------*/
|
||||
|
||||
function poll_update_state()
|
||||
{
|
||||
used = max_poll_questions - used_questions;
|
||||
|
||||
var tmp_lang = lang_build_string( poll_stat_lang, used, max_poll_choices );
|
||||
statobj.innerHTML = lang_build_string( html_stat_wrap, tmp_lang );
|
||||
}
|
||||
|
||||
/*--------------------------------------------*/
|
||||
// SHOW POLL FORM
|
||||
/*--------------------------------------------*/
|
||||
|
||||
function show_poll_form()
|
||||
{
|
||||
my_show_div( openobj );
|
||||
my_hide_div( closedobj );
|
||||
}
|
||||
|
||||
/*--------------------------------------------*/
|
||||
// CLOSE POLL FORM
|
||||
/*--------------------------------------------*/
|
||||
|
||||
function close_poll_form()
|
||||
{
|
||||
my_show_div( closedobj );
|
||||
my_hide_div( openobj );
|
||||
}
|
||||
|
||||
/*--------------------------------------------*/
|
||||
// FORM MAKE SAFE
|
||||
/*--------------------------------------------*/
|
||||
|
||||
function _poll_make_form_safe( t )
|
||||
{
|
||||
t = t.replace( /'/g, ''' );
|
||||
t = t.replace( /"/g, '"' );
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user