diff options
author | splitt3r <splitt3r@users.noreply.github.com> | 2017-11-10 01:08:00 +0300 |
---|---|---|
committer | splitt3r <splitt3r@users.noreply.github.com> | 2017-11-10 01:08:00 +0300 |
commit | 2ad929a8e7f889d627b43c6045af96759d1f612c (patch) | |
tree | 5fdfaefb9b10b5cbd92f1637b4f0ad413d6259b2 /js | |
parent | e2c664a8c61b4c9f878466829b0184e6b7b1fe26 (diff) |
Restored missing files
Diffstat (limited to 'js')
-rw-r--r-- | js/app.js | 12 | ||||
-rw-r--r-- | js/create_edit.js | 149 | ||||
-rwxr-xr-x | js/start.js | 39 | ||||
-rw-r--r-- | js/vote.js | 205 |
4 files changed, 213 insertions, 192 deletions
diff --git a/js/app.js b/js/app.js new file mode 100644 index 00000000..ebb294da --- /dev/null +++ b/js/app.js @@ -0,0 +1,12 @@ +function deletePoll($pollEl) { + var str = t('polls', 'Do you really want to delete that poll (new)?') + '\n\n' + $($pollEl).attr('data-value'); + if (confirm(str)) { + var form = document.form_delete_poll; + var hiddenId = document.createElement("input"); + hiddenId.setAttribute("name", "pollId"); + hiddenId.setAttribute("type", "hidden"); + form.appendChild(hiddenId); + form.elements.pollId.value = $pollEl.id.split('_')[2]; + form.submit(); + } +} diff --git a/js/create_edit.js b/js/create_edit.js index 82459e98..ab1ffd2f 100644 --- a/js/create_edit.js +++ b/js/create_edit.js @@ -48,7 +48,7 @@ function deselectItem(cell) { } function insertText(text, set) { - if (typeof set === 'undefined') { + if (typeof set == 'undefined') { set = false; } var table = document.getElementById('selected-texts-table'); @@ -66,7 +66,7 @@ function insertText(text, set) { } function addRowToList(ts, text, timeTs) { - if (typeof timeTs === 'undefined') { + if (typeof timeTs == 'undefined') { timeTs = -1; } var table = document.getElementById('selected-dates-table'); @@ -74,7 +74,7 @@ function addRowToList(ts, text, timeTs) { var td, tr, tdId; var i, j; var curr; - if (rows.length === 0) { + if (rows.length == 0) { tr = table.insertRow(-1); //start new header tr.insertCell(-1); tr = table.insertRow(-1); //append new row @@ -87,11 +87,11 @@ function addRowToList(ts, text, timeTs) { } for ( i=1; i<rows.length; i++) { curr = rows[i]; - if (curr.id === ts) { + if (curr.id == ts) { for (j=1; j<curr.cells.length; j++) { td = curr.cells[j]; - tdId = curr.cells[j].id; - if ( timeTs === tdId) { + tdId = curr.cells[j].id; + if ( timeTs == tdId) { td.className = 'icon-checkmark date-text-selected'; } } @@ -106,9 +106,9 @@ function addRowToList(ts, text, timeTs) { for (j=1; j<rows[0].cells.length; j++) { tdId = rows[0].cells[j].id; td = tr.insertCell(-1); - if (timeTs === tdId) { + if (timeTs == tdId) { td.className = 'icon-checkmark date-text-selected'; - } else { + } else { td.className = 'icon-close date-text-not-selected'; } td.id = tdId; @@ -126,7 +126,7 @@ function addRowToList(ts, text, timeTs) { for (j=1; j<rows[0].cells.length; j++) { tdId = rows[0].cells[j].id; td = tr.insertCell(-1); - if (timeTs === tdId) { + if (timeTs == tdId) { td.className = 'icon-checkmark date-text-selected'; } else { td.className = 'icon-close date-text-not-selected'; @@ -137,7 +137,7 @@ function addRowToList(ts, text, timeTs) { } function addColToList(ts, text, dateTs) { - if (typeof dateTs === 'undefined') { + if (typeof dateTs == 'undefined') { dateTs = -1; } var table = document.getElementById('selected-dates-table'); @@ -145,7 +145,7 @@ function addColToList(ts, text, dateTs) { var tr, row, td, cells, tmpRow; var i, curr; var index = -1; - if (rows.length === 0) { + if (rows.length == 0) { tr = table.insertRow(-1); tr.insertCell(-1); } @@ -153,7 +153,7 @@ function addColToList(ts, text, dateTs) { tmpRow = rows[0]; for (i=0; i<tmpRow.cells.length; i++) { curr = tmpRow.cells[i]; - if (curr.id === ts) { + if (curr.id == ts) { return; //already in table, cancel } else if (curr.id > ts) { index = i; @@ -166,14 +166,14 @@ function addColToList(ts, text, dateTs) { cells = row.cells; td = row.insertCell(index); //only display time in header row - if (i===0) { + if (i==0) { td.innerHTML = text; td.className = 'date-col'; } else { td.innerHTML = ''; - if (row.id === dateTs) { + if (row.id == dateTs) { td.className = 'icon-checkmark date-text-selected'; - } else { + } else { td.className = 'icon-close date-text-not-selected'; } } @@ -183,10 +183,10 @@ function addColToList(ts, text, dateTs) { function debounce(f, wait, immediate) { var timeout; - return function() { + return function () { var context = this; var args = arguments; - var later = function() { + var later = function () { timeout = null; if (!immediate) { f.apply(context, args); @@ -204,19 +204,19 @@ function debounce(f, wait, immediate) { $(document).ready(function () { // enable / disable date picker var i; - $('#id_expire_set').click(function(){ + $('#id_expire_set').click(function (){ $('#id_expire_date').prop("disabled", !this.checked); if (this.checked) { - $("#id_expire_date").focus(); + $("#id_expire_date").focus(); } }); var anonOptions = document.getElementById('anonOptions'); - $('#hideNames').click(function() { + $('#hideNames').click(function () { hideNames = this.checked; }); - $('#isAnonymous').click(function() { + $('#isAnonymous').click(function () { isAnonymous = this.checked; if (isAnonymous) { anonOptions.style.display = 'inline'; @@ -248,25 +248,25 @@ $(document).ready(function () { var accessValueArr = accessValues.value.split(';'); for (i=0; i<accessValueArr.length; i++) { var val = accessValueArr[i]; - if (val === '') { + if (val == '') { continue; } var li = document.createElement('li'); li.id = val; li.className = 'cl_item cl_access_item selected'; var index = val.indexOf('group_'); - if (index === 0) { + if (index == 0) { g_chosen_groups.push(val); li.className += ' is-group'; li.appendChild(document.createTextNode(val.substring(6) + " (group)")); list.appendChild(li); } else { index = val.indexOf('user_'); - if (index === 0) { + if (index == 0) { g_chosen_users.push(val); li.className = 'cl_item cl_access_item selected'; var username = val.substring(5); - $.post(OC.generateUrl('/apps/polls/get/displayname'), {username: username}, function(data) { + $.post(OC.generateUrl('/apps/polls/get/displayname'), {username: username}, function (data) { li.appendChild(document.createTextNode(username + " (" + data + ")")); list.appendChild(li); }); @@ -317,7 +317,7 @@ $(document).ready(function () { var expirepicker = jQuery('#id_expire_date').datetimepicker({ inline: false, - onSelectDate: function(date) { + onSelectDate: function (date) { var year = date.getFullYear(); var month = date.getMonth(); var day = date.getDate(); @@ -332,7 +332,7 @@ $(document).ready(function () { inline:true, step: 15, todayButton: true, - onSelectDate: function(date) { + onSelectDate: function (date) { var year = date.getFullYear(); var month = date.getMonth(); var day = date.getDate(); @@ -342,7 +342,7 @@ $(document).ready(function () { var dateStr = day.substr(-2) + '.' + month.substr(-2) + '.' + year; addRowToList(newDate/1000, dateStr); }, - onSelectTime: function(date) { + onSelectTime: function (date) { var hours = date.getHours(); var minutes = date.getMinutes(); var ms = (hours * 60 * 60 * 1000) + (minutes * 60 * 1000); //time of day in milliseconds @@ -353,7 +353,7 @@ $(document).ready(function () { } }); - $(document).on('click', '.date-row', function() { + $(document).on('click', '.date-row', function () { var tr = $(this).parent(); var dateId = parseInt(tr.attr('id')); var index = tr.index(); @@ -369,7 +369,7 @@ $(document).ready(function () { table.deleteRow(index); }); - $(document).on('click', '.date-col', function() { + $(document).on('click', '.date-col', function () { var cellIndex = $(this).index(); var timeId = parseInt($(this).attr('id')); var table = document.getElementById('selected-dates-table'); @@ -385,7 +385,7 @@ $(document).ready(function () { } }); - $(document).on('click', '.text-row', function() { + $(document).on('click', '.text-row', function () { var tr = $(this).parent(); var rowIndex = tr.index(); var name = $(this).html(); @@ -397,17 +397,17 @@ $(document).ready(function () { table.deleteRow(rowIndex); }); - $(document).on('click', '.icon-close', function() { + $(document).on('click', '.icon-close', function () { selectItem($(this)); }); - $(document).on('click', '.icon-checkmark', function() { + $(document).on('click', '.icon-checkmark', function () { deselectItem($(this)); }); - $(document).on('click', '#text-submit', function() { + $(document).on('click', '#text-submit', function () { var text = document.getElementById('text-title'); - if (text.value.length === 0) { + if (text.value.length == 0) { alert('Please enter a text!'); return false; } @@ -415,7 +415,7 @@ $(document).ready(function () { text.value = ''; }); - $(document).on('click', '.cl_item', function() { + $(document).on('click', '.cl_item', function () { var index; var list = document.getElementById('selected-search-list-id'); var isGroup = $(this).hasClass('is-group'); @@ -423,7 +423,7 @@ $(document).ready(function () { if (isGroup) { index = g_chosen_groups.indexOf(this.id); } - else { + else { index = g_chosen_users.indexOf(this.id); } if (index > -1) { @@ -447,7 +447,7 @@ $(document).ready(function () { li.id = this.id; li.className = 'cl_item cl_access_item selected' + (isGroup ? ' is-group' : ''); if (!isGroup) { - $.post(OC.generateUrl('/apps/polls/get/displayname'), {username: text}, function(data) { + $.post(OC.generateUrl('/apps/polls/get/displayname'), {username: text}, function (data) { li.appendChild(document.createTextNode(text + " (" + data + ")")); list.appendChild(li); }); @@ -460,15 +460,15 @@ $(document).ready(function () { }); $('.toggleable-row').hover( - function() { + function () { var td = this.insertCell(-1); td.className = 'toggle-all selected-all'; - }, function() { + }, function () { $(this).find('td:last-child').remove(); } ); - $(document).on('click', '.toggle-all', function() { + $(document).on('click', '.toggle-all', function () { var children; var i; if ($(this).attr('class').indexOf('selected-all') > -1) { @@ -488,8 +488,8 @@ $(document).ready(function () { } }); - $('input[type=radio][name=pollType]').change(function() { - if (this.value === 'event') { + $('input[type=radio][name=pollType]').change(function () { + if (this.value == 'event') { chosen_type = 'event'; document.getElementById('text-select-container').style.display = 'none'; document.getElementById('date-select-container').style.display = 'inline'; @@ -500,9 +500,9 @@ $(document).ready(function () { } }); - $('input[type=radio][name=accessType]').click(function() { + $('input[type=radio][name=accessType]').click(function () { access_type = this.value; - if (access_type === 'select') { + if (access_type == 'select') { $("#access_rights").show(); $("#selected_access").show(); } else { @@ -511,13 +511,13 @@ $(document).ready(function () { } }); - $('input[type=checkbox][name=check_expire]').change(function() { + $('input[type=checkbox][name=check_expire]').change(function () { if (!$(this).is(':checked')) { document.getElementById('expireTs').value = ''; } }); - $('#user-group-search-box').on('input', debounce(function() { + $('#user-group-search-box').on('input', debounce(function () { var ul = document.getElementById('live-search-list-id'); while(ul.firstChild) { ul.removeChild(ul.firstChild); @@ -531,7 +531,7 @@ $(document).ready(function () { groups: JSON.stringify(g_chosen_groups), users: JSON.stringify(g_chosen_users) }; - $.post(OC.generateUrl('/apps/polls/search'), formData, function(data) { + $.post(OC.generateUrl('/apps/polls/search'), formData, function (data) { for (var i=0; i<data.length; i++) { var ug = data[i]; var li = document.createElement('li'); @@ -554,15 +554,15 @@ $(document).ready(function () { }); }, 250)); - $('.live-search-list-user li').each(function(){ - $(this).attr('data-search-term', $(this).text().toLowerCase()); + $('.live-search-list-user li').each(function (){ + $(this).attr('data-search-term', $(this).text().toLowerCase()); }); - $('.live-search-box-user').on('keyup', function(){ - var searchTerm = $(this).val().toLowerCase(); - $('.live-search-list-user li').each(function(){ - if ( $(this).filter('[data-search-term *= ' + searchTerm + ']').length > 0 - || searchTerm.length < 1 + $('.live-search-box-user').on('keyup', function (){ + var searchTerm = $(this).val().toLowerCase(); + $('.live-search-list-user li').each(function (){ + if ( $(this).filter('[data-search-term *= ' + searchTerm + ']').length > 0 + || searchTerm.length < 1 ) { $(this).show(); } else { @@ -571,50 +571,54 @@ $(document).ready(function () { }); }); - $('.live-search-list-group li').each(function(){ + $('.live-search-list-group li').each(function (){ $(this).attr('data-search-term', $(this).text().toLowerCase()); }); - - $('.live-search-box-group').on('keyup', function(){ - var searchTerm = $(this).val().toLowerCase(); - $('.live-search-list-group li').each(function(){ - if ( $(this).filter('[data-search-term *= ' + searchTerm + ']').length > 0 - || searchTerm.length < 1 + + $('.live-search-box-group').on('keyup', function (){ + var searchTerm = $(this).val().toLowerCase(); + $('.live-search-list-group li').each(function (){ + if ( + $(this).filter('[data-search-term *= ' + searchTerm + ']').length > 0 || + searchTerm.length < 1 ) { $(this).show(); } else { $(this).hide(); } }); - }); + }); var form = document.finish_poll; var submit_finish_poll = document.getElementById('submit_finish_poll'); if (submit_finish_poll !== null) { - submit_finish_poll.onclick = function() { - if ( g_chosen_datetimes.length === 0 - && g_chosen_texts.length === 0 + submit_finish_poll.onclick = function () { + if ( + g_chosen_datetimes.length == 0 && + g_chosen_texts.length == 0 ) { alert(t('polls', 'Nothing selected!\nClick on cells to turn them green.')); return false; } - if (chosen_type === 'event') { + if (chosen_type == 'event') { form.elements.chosenDates.value = JSON.stringify(g_chosen_datetimes); } else { form.elements.chosenDates.value = JSON.stringify(g_chosen_texts); } var title = document.getElementById('pollTitle'); - if ( title === null - || title.value.length === 0 + if ( + title == null || + title.value.length == 0 ) { alert(t('polls', 'You must enter at least a title for the new poll.')); return false; } - if (access_type === 'select') { - if ( g_chosen_groups.length === 0 - && g_chosen_users === 0 + if (access_type == 'select') { + if ( + g_chosen_groups.length == 0 && + g_chosen_users == 0 ) { alert(t('polls', 'Please select at least one user or group!')); return false; @@ -630,4 +634,3 @@ $(document).ready(function () { }; } }); - diff --git a/js/start.js b/js/start.js index 556d4e55..bc5010d9 100755 --- a/js/start.js +++ b/js/start.js @@ -1,29 +1,26 @@ -function deletePoll() { - var str = t('polls', 'Do you really want to delete that poll?') + '\n\n' + $(this).attr('data-value'); - if (confirm(str)) { - var form = document.form_delete_poll; - var hiddenId = document.createElement("input"); - hiddenId.setAttribute("name", "pollId"); - hiddenId.setAttribute("type", "hidden"); - form.appendChild(hiddenId); - form.elements.pollId.value = this.id.split('_')[2]; - form.submit(); - } -} - $(document).ready(function () { - $('.table-body .avatardiv').each(function(i, obj) { + new Clipboard('.copy-link'); + $('.alt-tooltip').tooltip(); + + $('.delete-poll').click(function () { + deletePoll(this); + }); + + /* + $('.copy-link').click(function () { + copyToClipboard(this); + }); + */ + + $('.table-body .avatardiv').each(function (i, obj) { $(obj).avatar(obj.title, 32); }); - - $('.popupmenu').each(function() { - OC.registerMenu($('#expand_' + $(this).attr('value')), $('#expanddiv_' + $(this).attr('value')) ); + + $('.popupmenu').each(function () { + OC.registerMenu($('#expand_' + $(this).attr('value')), $('#expanddiv_' + $(this).attr('value')) ); }); - - $('.delete_poll').click(deletePoll); - $('.copy_link').click(function() { + $('.copy_link').click(function () { window.prompt(t('polls','Copy to clipboard: Ctrl+C, Enter'), $(this).data('url')); }); }); - @@ -1,68 +1,91 @@ var newUserDates = []; var newUserTypes = []; -var max_votes = 0; -var values_changed = false; +var maxVotes = 0; +var valuesChanged = false; var tzOffset = new Date().getTimezoneOffset(); -$.fn.switchClass = function(a, b) { +$.fn.switchClass = function (a, b) { this.removeClass(a); this.addClass(b); return this; }; +function updateCommentsCount() { + // TODO: Update the Badgecounter + $('#comment-counter').removeClass('no-comments'); + $('#comment-counter').text(parseInt($('#comment-counter').text()) +1); + +} + +function updateBest() { + maxVotes = 0; + $('.counter').each(function () { + var yes = parseInt($(this).find('.yes').text()); + var no = parseInt($(this).find('.no').text()); + if(yes - no > maxVotes) { + maxVotes = yes - no; + } + }); + var i = 0; + $('.vote').each(function () { + var yes = parseInt($(this).find('.yes').text()); + var no = parseInt($(this).find('.no').text()); + $(this).toggleClass('winner', yes - no === maxVotes); + }); +} + +function updateCounters() { + $('.result-cell.yes').each(function () { + $(this).text($('#voteid_'+ $(this).attr('data-voteId') + '.poll-cell.yes').length); + }); + $('.result-cell.no').each(function () { + $(this).text($('#voteid_'+ $(this).attr('data-voteId') + '.poll-cell.no').length); + }); + updateBest(); +} + +function switchSidebar() { + if ($('#app-content').hasClass('with-app-sidebar')) { + OC.Apps.hideAppSidebar(); + } else { + OC.Apps.showAppSidebar(); + } +} + + $(document).ready(function () { // count how many times in each date - var arr_dates = []; // will be like: [21.02] => 3 - var arr_years = []; // [1992] => 6 - var dateStr = ''; - var k; + new Clipboard('.copy-link'); + updateBest(); + $('.delete-poll').click(function () { + deletePoll(this); + }); - $('.poll.avatardiv').each(function(i, obj) { - $(obj).avatar(obj.title, 32); + $('#switchDetails').click(function () { + switchSidebar(); }); - $('.hidden-dates').each(function(i, obj) { - var exDt = new Date(obj.value.replace(/ /g,"T")+"Z"); //Fix display in Safari and IE, still NaN on Firefox on iPad - var day = ('0' + exDt.getDate()).substr(-2); - var month = ('0' + (exDt.getMonth()+1)).substr(-2); - var day_month = day + '.' + month; - var year = exDt.getFullYear(); - - if(typeof arr_dates[day_month] !== 'undefined') { - arr_dates[day_month] += 1; - } else { - arr_dates[day_month] = 1; - } - if(typeof arr_years[year] !== 'undefined') { - arr_years[year] += 1; - } else { - arr_years[year] = 1; - } - dateStr += '<th class="time-slot" value="' + obj.value + '">' + - '<div class="month">' + exDt.toLocaleString(window.navigator.language, {month: 'short'}) + - // ' \'' + exDt.toLocaleString(window.navigator.language, {year: '2-digit'}) + - '</div>' + - '<div class="day">' + exDt.toLocaleString(window.navigator.language, {day: 'numeric'}) + '</div>' + - '<div class="dayow">' + exDt.toLocaleString(window.navigator.language, {weekday: 'short'}) + '</div>' + - '<div class="time">' + ('0' + (exDt.getHours())).substr(-2) + ':' + ('0' + exDt.getMinutes()).substr(-2) + '</div>' + - '</th>'; + $('#closeDetails').click(function () { + OC.Apps.hideAppSidebar(); }); - var for_string_dates = ''; - for(k in arr_dates) { - for_string_dates += '<th colspan="' + arr_dates[k] + '" class="bordered">' + k + '</th>'; - } + $('.poll.avatardiv').each(function (i, obj) { + $(obj).avatar(obj.title, 32); + }); - var for_string_years = ''; - for(k in arr_years) { - for_string_years += '<th colspan="' + arr_years[k] + '" class="bordered">' + k + '</th>'; - } + $('.vote.time').each(function () { + var extendedDate = new Date($(this).attr("data-value-utc").replace(/ /g,"T")+"Z"); //Fix display in Safari and IE + + $(this).find('.month').text(extendedDate.toLocaleString(window.navigator.language, {month: 'short'})); + $(this).find('.day').text(extendedDate.toLocaleString(window.navigator.language, {day: 'numeric'})); + $(this).find('.dayow').text(extendedDate.toLocaleString(window.navigator.language, {weekday: 'short'})); + $(this).find('.time').text(extendedDate.toLocaleTimeString(window.navigator.language, {hour: 'numeric', minute:'2-digit', timeZoneName:'short'})); - $('#time-slots-header').append(dateStr); + }); - $('#submit_finish_vote').click(function() { + $('#submit_finish_vote').click(function () { var form = document.finish_vote; var ac = document.getElementById('user_name'); if (ac !== null) { @@ -75,12 +98,12 @@ $(document).ready(function () { } var check_notif = document.getElementById('check_notif'); var newUserDates = [], newUserTypes = []; - $(".cl_click").each(function() { + $(".poll-cell.active").each(function () { if($(this).hasClass('no')) { newUserTypes.push(0); - } else if ($(this).hasClass('yes')){ + } else if ($(this).hasClass('yes')) { newUserTypes.push(1); - } else if($(this).hasClass('maybe')){ + } else if($(this).hasClass('maybe')) { newUserTypes.push(2); } else { newUserTypes.push(-1); @@ -94,94 +117,80 @@ $(document).ready(function () { form.elements.dates.value = JSON.stringify(newUserDates); form.elements.types.value = JSON.stringify(newUserTypes); form.elements.receiveNotifications.value = (check_notif && check_notif.checked) ? 'true' : 'false'; - form.elements.changed.value = values_changed ? 'true' : 'false'; + form.elements.changed.value = valuesChanged ? 'true' : 'false'; form.submit(); }); - $('#submit_send_comment').click(function(e) { + $('#submit_send_comment').click(function (e) { e.preventDefault(); var form = document.send_comment; var ac = document.getElementById('user_name_comm'); if (ac !== null) { - if(ac.value.length >= 3){ + if(ac.value.length >= 3) { form.elements.userId.value = ac.value; } else { alert(t('polls', 'You are not registered.\nPlease enter your name to vote\n(at least 3 characters).')); return; } } - var comm = document.getElementById('commentBox'); - if(comm.value.trim().length <= 0) { + var comment = document.getElementById('commentBox'); + if(comment.value.trim().length <= 0) { alert(t('polls', 'Please add some text to your comment before submitting it.')); return; } var data = { pollId: form.elements.pollId.value, userId: form.elements.userId.value, - commentBox: comm.value.trim() + commentBox: comment.value.trim() }; $('.new-comment .icon-loading-small').show(); - $.post(form.action, data, function(data) { + $.post(form.action, data, function (data) { $('.comments .comment:first').after('<div class="comment"><div class="comment-header"><span class="comment-date">' + data.date + '</span>' + data.userName + '</div><div class="wordwrap comment-content">' + data.comment + '</div></div>'); $('.new-comment textarea').val('').focus(); $('.new-comment .icon-loading-small').hide(); - }).error(function() { - alert(t('polls', 'An error occurred, your comment was not posted…')); + updateCommentsCount(); + }).error(function () { + alert(t('polls', 'An error occurred, your comment was not posted.')); $('.new-comment .icon-loading-small').hide(); }); }); - $(".share input").click(function() { + $(".share input").click(function () { $(this).select(); }); + + $('.toggle-cell').tooltip(); + $('.time-slot').tooltip(); + $('.avatardiv').tooltip(); + updateCounters(); + }); -function updateCounts(){ - max_votes = 0; - $('td.total').each(function() { - var yes = parseInt($(this).find('.yes').text()); - var no = parseInt($(this).find('.no').text()); - if(yes - no > max_votes) { - max_votes = yes - no; - } - }); - var i = 0; - $('td.total').each(function() { - var yes = parseInt($(this).find('.yes').text()); - var no = parseInt($(this).find('.no').text()); - $('#id_total_' + i++).toggleClass('icon-checkmark', yes - no === max_votes); - }); -} +$(document).on('click', '.toggle-cell, .poll-cell.active', function () { + valuesChanged = true; + var $nextClass = ""; + var $toggleAllClasses = ""; -$(document).on('click', '.toggle-all, .cl_click', function() { - values_changed = true; - var $cl = ""; - var $toggle = ""; if($(this).hasClass('yes')) { - $cl = "no"; - $toggle= "yes"; + $nextClass = "no"; + $toggleAllClasses= "yes"; } else if($(this).hasClass('no')) { - $cl = "maybe"; - $toggle= "no"; + $nextClass = "maybe"; + $toggleAllClasses= "no"; } else if($(this).hasClass('maybe')) { - $cl = "yes"; - $toggle= "maybe"; + $nextClass = "yes"; + $toggleAllClasses= "maybe"; } else { - $cl = "yes"; - $toggle= "maybe"; + $nextClass = "yes"; + $toggleAllClasses= "maybe"; } - if($(this).hasClass('toggle-all')) { - $(".cl_click").attr('class', 'cl_click poll-cell active ' + $toggle); - $(this).attr('class', 'toggle-all toggle ' + $cl); - } else { - $(this).attr('class', 'cl_click poll-cell active ' + $cl); + + $(this).removeClass('yes no maybe unvoted'); + $(this).addClass($nextClass); + + if($(this).hasClass('toggle-cell')) { + $(".poll-cell.active").removeClass('yes no maybe unvoted'); + $(".poll-cell.active").addClass($toggleAllClasses); } - $('.cl_click').each(function() { - var yes_c = $('#id_y_' + $(this).attr('id')); - var no_c = $('#id_n_' + $(this).attr('id')); - $(yes_c).text(parseInt($(yes_c).attr('data-value')) + ($(this).hasClass('yes') ? 1 : 0)); - $(no_c).text(parseInt($(no_c).attr('data-value')) + ($(this).hasClass('no') ? 1 : 0)); - }); - updateCounts(); + updateCounters(); }); - |