1jQuery(document).ready(function($) { 2 initHuePollVote(); 3}); 4 5function initHuePollVote() { 6 $(document).on('click', '.poll-vote .user-vote', function(e) { 7 e.preventDefault(); 8 var nonce = $(this).attr("data-nonce"); 9 var value = $(this).attr("data-value"); 10 11 $.ajax({ 12 type : "post", 13 dataType : "json", 14 url : hueVars.ajaxUrl, 15 data : { 16 action: "hue_poll_vote", 17 nonce: nonce, 18 value : value 19 }, 20 success: function(response) { 21 if(response.type == "success") { 22 console.log("Vote ok for "+value); 23 advancePollPage(); 24 updatePollResults(value); 25 } else { 26 console.log("Vote not ok for "+value); 27 $('.poll-vote-page').removeClass('active'); 28 $('.poll-vote-page[data-page="0"]').addClass('active'); 29 } 30 }, 31 error: function(response) { 32 console.log("Vote not ok for "+value); 33 $('.poll-vote-page').removeClass('active'); 34 $('.poll-vote-page[data-page="0"]').addClass('active'); 35 $('body').addClass('poll-white-bg'); 36 } 37 }); 38 }); 39 $(document).on('click', '.poll-vote .more-button', function(e) { // info 40 if ( !$(this).parents('.poll-option').hasClass('view') ) { 41 $('.poll-vote .poll-option').removeClass('view'); 42 } 43 $(this).parents('.poll-option').toggleClass('view'); 44 //$(this).parents('.poll-options').removeClass('accept'); 45 }); 46 $(document).on('click', '.poll-vote .button.vote', function(e) { // select 47 $('.poll-vote .poll-option').removeClass('active').removeClass('view'); 48 $(this).parents('.poll-option').addClass('active'); 49 $(this).parents('.poll-options').addClass('accept'); 50 }); 51 $(document).on('click', '.poll-vote .previous-option-button', function(e) { 52 $(this).parents('.poll-option').removeClass('view').removeClass('active'); 53 $(this).parents('.poll-options').removeClass('accept'); 54 }); 55 $(document).on('click', '.poll-vote .next-poll-vote-page, .poll-vote .next-page-button', function(e) { 56 advancePollPage(); 57 }); 58 refreshPollResults(); 59} 60 61function updatePollResults(value) { 62 var totalCount = parseInt($('.poll-results').attr('data-total-count'))+1; 63 $('.poll-results').attr('data-total-count', totalCount); 64 $('.poll-result[data-index="'+value+'"]').attr('data-count', parseInt($('.poll-result[data-index="'+value+'"]').attr('data-count'))+1); 65 $('.poll-result').each(function() { 66 var percentage = parseInt($(this).attr('data-count'))/totalCount*100; 67 $('.percentage', this).html(Math.round(percentage)+"%"); 68 $(this).css('height', percentage+"%"); 69 }); 70 displayPollResultDisplay(); 71} 72 73function refreshPollResults() { // XXX 74 var totalCount = parseInt($('.poll-results').attr('data-total-count')); 75 $('.poll-result').each(function() { 76 var percentage = parseInt($(this).attr('data-count'))/totalCount*100; 77 $('.percentage', this).html(Math.round(percentage)+"%"); 78 $(this).css('height', percentage+"%"); 79 }); 80 $('.poll-result').removeClass('small').removeClass('toosmall'); 81 displayPollResultDisplay(); 82} 83 84function advancePollPage() { 85 var $container = $('.poll-vote .poll-vote-content'); 86 var currentPage = parseInt($container.attr('data-current-page')); 87 $('.poll-vote-page').removeClass('active'); 88 $('.poll-vote-page[data-page="'+(currentPage+1)+'"]').addClass('active'); 89 $container.attr('data-current-page', (currentPage+1)); 90 if ( (currentPage+1) == 4 ) { 91 $('body').addClass('poll-white-bg'); 92 } else { 93 $('body').removeClass('poll-white-bg'); 94 } 95} 96 97function displayPollResultDisplay() { 98 if ( $('.poll-results').length == 0 ) return; 99 100 // check if everything fits 101 var missingHeight = 0; 102 $('.poll-results .poll-result').each(function(i) { 103 if ( $('.prcontent', this).outerHeight() > $(this).outerHeight() ) { 104 $(this).addClass('small'); 105 } 106 if ( $('.prcontent', this).outerHeight() > $(this).outerHeight() ) { 107 $(this).addClass('toosmall'); 108 missingHeight += $('.prcontent', this).outerHeight() - $(this).outerHeight(); 109 $(this).css('height', $('.prcontent', this).outerHeight()+'px'); 110 } 111 }); 112 //console.log("missingHeight "+missingHeight); 113 114 // find smallest and substract as much as possible 115 var x = 0; 116 while ( missingHeight > 0 ) { 117 var smallesHeight = 999999; 118 var freeElementCount = 0; 119 $('.poll-results .poll-result').each(function(i) { 120 if ( $(this).outerHeight() > $('.prcontent', this).outerHeight() ) { 121 var leftSpace = $(this).outerHeight() - $('.prcontent', this).outerHeight(); 122 //console.log("leftSpace "+leftSpace); 123 if ( leftSpace < smallesHeight ) { 124 smallesHeight = leftSpace; 125 freeElementCount++; 126 } 127 } 128 }); 129 //console.log("smallesHeight "+smallesHeight); 130 //console.log("freeElementCount "+freeElementCount); 131 if ( smallesHeight*freeElementCount > missingHeight ) { 132 // fin 133 $('.poll-results .poll-result').each(function(i) { 134 if ( $(this).outerHeight() > $('.prcontent', this).outerHeight() ) { 135 var substract = missingHeight/freeElementCount; 136 $(this).css('height', ($(this).outerHeight()-substract)+'px'); 137 missingHeight -= substract; 138 } 139 }); 140 } else { 141 // substract and repeat 142 //console.log("repeat"); 143 $('.poll-results .poll-result').each(function(i) { 144 if ( $(this).outerHeight() > $('.prcontent', this).outerHeight() ) { 145 var leftSpace = $(this).outerHeight() - $('.prcontent', this).outerHeight(); 146 if ( leftSpace >= smallesHeight ) { 147 $(this).css('height', ($(this).outerHeight()-smallesHeight)+'px'); 148 missingHeight -= smallesHeight; 149 } 150 } 151 }); 152 } 153 //console.log("new missingHeight "+missingHeight); 154 if ( missingHeight <= 1 ) { 155 //console.log("break"); 156 break; 157 } 158 if ( x > 10 ) { 159 break; 160 } 161 x++; 162 } 163 164}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.