jQuery(document).ready(vote_init); // // preload images here jQuery(window).bind('load', function() { var preload = new Array(); jQuery(".vote_option_button_up").each(function() { s0 = jQuery(this).attr("src").replace(/\.(.+)$/i, "_hover.$1"); preload.push(s0) s1 = jQuery(this).attr("src").replace(/\.(.+)$/i, "_disabled.$1"); preload.push(s1) }); jQuery(".vote_option_button_down").each(function() { s0 = jQuery(this).attr("src").replace(/\.(.+)$/i, "_hover.$1"); preload.push(s0) s1 = jQuery(this).attr("src").replace(/\.(.+)$/i, "_disabled.$1"); preload.push(s1) }); var img = document.createElement('img'); jQuery(img).bind('load', function() { if(preload[0]) { this.src = preload.shift(); } }).trigger('load'); }); function vote_init() { /* // works :) // jQuery().ajaxStart( function() { jQuery("#vote_option_value_up-1").ajaxStart( function() { jQuery("#vote_option_value_up-1").text("Loading ..."); }); */ jQuery("img.vote_option_button_up") .filter(function (index) { // return index == 1 || $(this).attr("id") == "fourth"; return jQuery(this).attr("src").indexOf("_disabled.") == -1; }) .mouseover(function($){ jQuery(this).attr("src", "http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_up_hover.png"); }) .mouseout(function($){ jQuery(this).attr("src", "http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_up.png"); }) .bind("click", {element: jQuery(this)}, accept_vote_click); jQuery("img.vote_option_button_up") .filter(function (index) { return jQuery(this).attr("src").indexOf("_disabled.") != -1; }) // .bind("click", ignore_vote_click); .bind("click", {element: jQuery(this)}, ignore_vote_click); // ================================================= jQuery("img.vote_option_button_down") .filter(function (index) { return jQuery(this).attr("src").indexOf("_disabled.") == -1; }) .mouseover(function($){ jQuery(this).attr("src", "http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_down_hover.png"); }) .mouseout(function($){ jQuery(this).attr("src", "http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_down.png"); }) // .bind("click", accept_vote_click); .bind("click", {element: jQuery(this)}, accept_vote_click); jQuery("img.vote_option_button_down") .filter(function (index) { return jQuery(this).attr("src").indexOf("_disabled.") != -1; }) // .bind("click", ignore_vote_click); .bind("click", {element: jQuery(this)}, ignore_vote_click); } function do_nothing(evt) {} function ignore_vote_click(evt) {} function accept_vote_click(evt) { // alert('accept'); // var element_id = evt.data.element.id; var element_id = evt.target.id; var pos_start = element_id.indexOf('-'); var vote_option_id = element_id.substr(pos_start + 1); var value = 0; if (element_id.indexOf("vote_option_button_up") != -1) { value = 1; } if (element_id.indexOf("vote_option_button_down") != -1) { value = -1; } // // the next one was used previously when we expect response from the // // server before updating the vote up/down values. Now we just update // // it offline and silently sent the vote value in the background. // var successFunction = function(response){vote_click_complete(response, vote_option_id, value);} // // update buttons without waiting for server response vote_click_offline(vote_option_id, value); // // tell the ajax functionality which sends the vote online to do nothing after it completes var successFunction = function(response){do_nothing_after_vote(response);} jQuery.ajax({ type: "POST", url: "http://www.collectiblescornertv.com/wp-content/plugins/vote/php/vote_post_debug.php", data: "vote_option_id=" + vote_option_id + "&value=" + value + "&user_id=0", success: successFunction }); } function vote_click_complete(t, vote_option_id, vote_value) { // alert(t.responseText); // alert(t.responseXML); // alert(t); var up_button_id = "#vote_option_button_up-" + vote_option_id; var up_value_id = "#vote_option_value_up-" + vote_option_id; var down_button_id = "#vote_option_button_down-" + vote_option_id; var down_value_id = "#vote_option_value_down-" + vote_option_id; var up_button = jQuery(up_button_id); var up_value = jQuery(up_value_id); var down_button = jQuery(down_button_id); var down_value = jQuery(down_value_id); var up = 0; var down = 0; // var xml = t.responseXML; var xml = t; try { up = xml.getElementsByTagName("up")[0].textContent; down = xml.getElementsByTagName("down")[0].textContent; } catch (ex) { up = xml.getElementsByTagName("up")[0].text down = xml.getElementsByTagName("down")[0].text } // IE fix if (up == undefined) { up = xml.getElementsByTagName("up")[0].firstChild.text; down = xml.getElementsByTagName("down")[0].firstChild.text; } // alert(up + '|' + down); // // user voted up if (vote_value == 1) { // // disable the vote up button var src = up_button.attr("src"); if (src.indexOf("_disabled.") == -1) { up_button.attr("src", "http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_up_disabled.png"); up_button.unbind("click"); up_button.unbind("mouseover"); up_button.unbind("mouseout"); up_button.bind("click", ignore_vote_click); // up_button.bind('mouseover', do_nothing); // up_button.bind('mouseout', do_nothing); } // // is there a decrease in the voted down value ? if yes, enable it if (down == -1) { down_button.attr("src", "http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_down.png"); down_button.unbind("click"); down_button.unbind("mouseover"); down_button.unbind("mouseout"); down_button.bind("click", accept_vote_click); down_button.bind('mouseover', function(){jQuery(this).attr('src', 'http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_down_hover.png')}); down_button.bind('mouseout', function(){jQuery(this).attr('src', 'http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_down.png')}); } } // // end : if (vote_value == 1) // // user voted down if (vote_value == -1) { // // disable the vote down button var src = down_button.attr("src"); if (src.indexOf("_disabled.") == -1) { down_button.attr("src", "http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_down_disabled.png"); down_button.unbind("click"); down_button.unbind("mouseover"); down_button.unbind("mouseout"); down_button.bind("click", ignore_vote_click); // down_button.bind('mouseover', do_nothing); // down_button.bind('mouseout', do_nothing); } // // is there a decrease in the voted up value ? if yes, enable it if (up == -1) { up_button.attr("src", "http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_up.png"); up_button.unbind("click"); up_button.unbind("mouseover"); up_button.unbind("mouseout"); up_button.bind("click", accept_vote_click); up_button.bind('mouseover', function(){jQuery(this).attr('src', 'http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_up_hover.png')}); up_button.bind('mouseout', function(){jQuery(this).attr('src', 'http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_up.png')}); } } // // end : if (vote_value == -1) // update up value if (up != 0) { var raw_value = up_value.text(); var vote_value = parseInt(raw_value, 10) + parseInt(up, 10); up_value.html(vote_value); } if (down != 0) { var raw_value = down_value.text(); var vote_value = parseInt(raw_value, 10) + parseInt(down, 10); down_value.html(vote_value); } } function do_nothing_after_vote(t) { } function vote_click_offline(vote_option_id, vote_value) { // alert(t.responseText); // alert(t.responseXML); // alert(t); var up_button_id = "#vote_option_button_up-" + vote_option_id; var up_value_id = "#vote_option_value_up-" + vote_option_id; var down_button_id = "#vote_option_button_down-" + vote_option_id; var down_value_id = "#vote_option_value_down-" + vote_option_id; // // remember, down_button and down_value elements may be absent from a vote var up_button = jQuery(up_button_id); var up_value = jQuery(up_value_id); var down_button = jQuery(down_button_id); var down_value = jQuery(down_value_id); var up = 0; var down = 0; if (vote_value > 0) { // // user voted up up = 1; // // enable down button, if any. this will be done later actually if (down_button.length > 0) { if (down_button.attr("src").indexOf("_disabled.") != -1) { down = -1; } } } else { // // user voted down down = 1; // // enable up button. this will be done later actually if (up_button.attr("src").indexOf("_disabled.") != -1) { up = -1; } } // // user voted up if (vote_value == 1) { // // disable the vote up button var src = up_button.attr("src"); if (src.indexOf("_disabled.") == -1) { up_button.attr("src", "http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_up_disabled.png"); up_button.unbind("click"); up_button.unbind("mouseover"); up_button.unbind("mouseout"); up_button.bind("click", ignore_vote_click); // up_button.bind('mouseover', do_nothing); // up_button.bind('mouseout', do_nothing); } // // is there a decrease in the voted down value ? if yes, enable it if (down == -1) { if (down_button.length > 0) { down_button.attr("src", "http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_down.png"); down_button.unbind("click"); down_button.unbind("mouseover"); down_button.unbind("mouseout"); down_button.bind("click", accept_vote_click); down_button.bind('mouseover', function(){jQuery(this).attr('src', 'http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_down_hover.png')}); down_button.bind('mouseout', function(){jQuery(this).attr('src', 'http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_down.png')}); } } } // // end : if (vote_value == 1) // // user voted down if (vote_value == -1) { // // disable the vote down button, if any if (down_button.length > 0) { var src = down_button.attr("src"); if (src.indexOf("_disabled.") == -1) { down_button.attr("src", "http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_down_disabled.png"); down_button.unbind("click"); down_button.unbind("mouseover"); down_button.unbind("mouseout"); down_button.bind("click", ignore_vote_click); // down_button.bind('mouseover', do_nothing); // down_button.bind('mouseout', do_nothing); } } // // is there a decrease in the voted up value ? if yes, enable it if (up == -1) { up_button.attr("src", "http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_up.png"); up_button.unbind("click"); up_button.unbind("mouseover"); up_button.unbind("mouseout"); up_button.bind("click", accept_vote_click); up_button.bind('mouseover', function(){jQuery(this).attr('src', 'http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_up_hover.png')}); up_button.bind('mouseout', function(){jQuery(this).attr('src', 'http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_up.png')}); } } // // end : if (vote_value == -1) // update up value if (up != 0) { var raw_value = up_value.text(); var vote_value = parseInt(raw_value, 10) + parseInt(up, 10); // // the '' below ensures that 0 will be properly written by jQuery up_value.html(vote_value + ''); } if (down != 0) { if (down_value.length > 0) { var raw_value = down_value.text(); var vote_value = parseInt(raw_value, 10) + parseInt(down, 10); // // the '' below ensures that 0 will be properly written by jQuery down_value.html(vote_value + ''); } } } /* // // the remarked code below is the Prototype version. Obsolete and broken. Kept for reference. // Event.observe(window, 'load', vote_init, false); // Event.observe(window, 'load', vote_init); Event.observe(document, 'dom:loaded', vote_init); function vote_init() { // // $$ is also used by jQuery :( // var f = $$('img.vote_option_button_up'); var f = Element.select(document, 'img[class="vote_option_button_up"]'); alert(f.length); for (var i=0; i < f.length; i++) { var src = f[i].readAttribute("src"); if (src.indexOf("_disabled.") == -1) { // f[i].onclick = accept_vote_click; f[i].observe('click', accept_vote_click); f[i].observe('mouseover', function(){this.writeAttribute('src', 'http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_up_hover.png')}); f[i].observe('mouseout', function(){this.writeAttribute('src', 'http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_up.png')}); } else { // f[i].onclick = ignore_vote_click; f[i].observe('click', ignore_vote_click); } } // var f = $$('img.vote_option_button_down'); var f = Element.select(document, 'img[class="vote_option_button_down"]'); // alert(f.length); for (var i=0; i < f.length; i++) { var src = f[i].readAttribute("src"); if (src.indexOf("_disabled.") == -1) { // f[i].onclick = accept_vote_click; f[i].observe('click', accept_vote_click); f[i].observe('mouseover',function(){this.writeAttribute('src', 'http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_down_hover.png')}); f[i].observe('mouseout',function(){this.writeAttribute('src', 'http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_down.png')}); } else { // f[i].onclick = ignore_vote_click; f[i].observe('click', ignore_vote_click); } } } function do_nothing(evt) {} function ignore_vote_click(evt) {} function accept_vote_click(evt) { var element = Event.element(evt); var element_id = element.id; var pos_start = element_id.indexOf('-'); var vote_option_id = element_id.substr(pos_start + 1); // alert(vote_option_id); var value = 0; if (element_id.indexOf("vote_option_button_up") != -1) { value = 1; } if (element_id.indexOf("vote_option_button_down") != -1) { value = -1; } var url = "http://www.collectiblescornertv.com/wp-content/plugins/vote/php/vote_post_debug.php"; var success = function(t){vote_click_complete(t, vote_option_id);} var pars = "vote_option_id=" + vote_option_id + "&value=" + value + "&user_id=0"; // alert(url + '\n' + pars); var myAjax = new Ajax.Request(url, {method:'post', parameters: pars, onSuccess:success}); return false; } function vote_click_complete(t, vote_option_id) { // alert(t.responseText); var up_button_id = "vote_option_button_up-" + vote_option_id; var up_value_id = "vote_option_value_up-" + vote_option_id; var down_button_id = "vote_option_button_down-" + vote_option_id; var down_value_id = "vote_option_value_down-" + vote_option_id; var up_button = $(up_button_id); var up_value = $(up_value_id); var down_button = $(down_button_id); var down_value = $(down_value_id); var up = 0; var down = 0; var xml = t.responseXML; try { up = xml.getElementsByTagName("up")[0].textContent; down = xml.getElementsByTagName("down")[0].textContent; } catch (ex) { up = xml.getElementsByTagName("up")[0].text down = xml.getElementsByTagName("down")[0].text } // IE fix if (up == undefined) { up = xml.getElementsByTagName("up")[0].firstChild.text; down = xml.getElementsByTagName("down")[0].firstChild.text; } // alert(up + '|' + down); if (up == 1) { var src = up_button.readAttribute("src"); if (src.indexOf("_disabled.") == -1) { up_button.stopObserving(); up_button.writeAttribute("src", "http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_up_disabled.png"); // up_button.onclick = ignore_vote_click; up_button.observe('click', ignore_vote_click); up_button.observe('mouseover', do_nothing); up_button.observe('mouseout', do_nothing); } up_value.cleanWhitespace(); var raw_value = up_value.innerHTML; var vote_value = parseInt(raw_value, 10) + 1; Element.update(up_value, vote_value); } if (down == 1) { var src = down_button.readAttribute("src"); if (src.indexOf("_disabled.") == -1) { down_button.stopObserving(); down_button.writeAttribute("src", "http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_down_disabled.png"); // down_button.onclick = ignore_vote_click; down_button.observe('click', ignore_vote_click); down_button.observe('mouseover', do_nothing); down_button.observe('mouseout', do_nothing); } down_value.cleanWhitespace(); var raw_value = down_value.innerHTML; var vote_value = parseInt(raw_value, 10) + 1; Element.update(down_value, vote_value); } if (up == -1) { var src = up_button.readAttribute("src"); if (src.indexOf("_disabled.") != -1) { up_button.stopObserving(); up_button.writeAttribute("src", "http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_up.png"); // up_button.onclick = accept_vote_click; up_button.observe('click', accept_vote_click); up_button.observe('mouseover', function(){this.writeAttribute('src', 'http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_up_hover.png')}); up_button.observe('mouseout', function(){this.writeAttribute('src', 'http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_up.png')}); } up_value.cleanWhitespace(); var raw_value = up_value.innerHTML; var vote_value = parseInt(raw_value, 10) - 1; Element.update(up_value, vote_value); } if (down == -1) { var src = down_button.readAttribute("src"); if (src.indexOf("_disabled.") != -1) { down_button.stopObserving(); down_button.writeAttribute("src", "http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_down.png"); // down_button.onclick = accept_vote_click; down_button.observe('click', accept_vote_click); down_button.observe('mouseover', function(){this.writeAttribute('src', 'http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_down_hover.png')}); down_button.observe('mouseout', function(){this.writeAttribute('src', 'http://www.collectiblescornertv.com/wp-content/plugins/vote/icons/vote_down.png')}); } down_value.cleanWhitespace(); var raw_value = down_value.innerHTML; var vote_value = parseInt(raw_value, 10) - 1; Element.update(down_value, vote_value); } } */