diff options
author | emkael <emkael@tlen.pl> | 2017-12-13 23:35:03 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2017-12-13 23:37:35 +0100 |
commit | 5fafec026532c9b00675f62658e08314e2096967 (patch) | |
tree | aac99e4ad998d8c27542b466c6525b667bf0252b /res | |
parent | 1bda1e000faf1e10cf0cb2860b8d07a1edd88c0b (diff) |
Compressing bidding data files into JSON files
Fixes #3
Diffstat (limited to 'res')
-rw-r--r-- | res/javas/bidding.js | 71 |
1 files changed, 40 insertions, 31 deletions
diff --git a/res/javas/bidding.js b/res/javas/bidding.js index 72a4ec4..bacbeca 100644 --- a/res/javas/bidding.js +++ b/res/javas/bidding.js @@ -1,39 +1,48 @@ -var display_bidding = function(element, bidding) { - var popup = $('<tr class="bidding_popup"><td class="n"> </td><td class="bidding_cell noc" colspan="1000"></td></tr>'); - popup.find('.bidding_cell').html(bidding); - element.closest('tr').after(popup); - element.data('bidding-row', popup); -} +var BIDDING_DATA = { + toggle_bidding: function() { + var element = $(this); + if (element.data('bidding-row')) { + element.data('bidding-row').remove(); + element.removeData('bidding-row'); + } else { + var popup = $('<tr class="bidding_popup"><td class="n"> </td><td class="bidding_cell noc" colspan="1000"></td></tr>'); + var bidding = BIDDING_DATA.data[element.attr('data-bidding-link')] || BIDDING_DATA.errorString; + popup.find('.bidding_cell').html(bidding); + element.closest('tr').after(popup); + element.data('bidding-row', popup); + } + return false; + }, -var load_bidding = function() { - var elem = $(this); - if (elem.data('bidding-row')) { - elem.data('bidding-row').remove(); - elem.removeData('bidding-row'); - } else { - $.ajax( - { - url: elem.attr('data-bidding-link'), - complete: function(xhr, status) { - if (status == 'success') { - display_bidding(elem, xhr.responseText); - } - else { - display_bidding(elem, 'Brak danych'); + load_bidding: function() { + $('a.biddingLink').hide(); + var dataLink = $('link[rel="bidding-file"]'); + if (dataLink.size() > 0) { + $.ajax( + { + url: dataLink.eq(0).attr('src'), + complete: function(xhr, status) { + if (status == 'success') { + BIDDING_DATA.data = JSON.parse(xhr.responseText); + } + $('a.biddingLink').show(); } } - } - ); - } - return false; -}; + ); + } + }, + + bind_bidding_links: function() { + $('a.biddingLink').each(function() { + $(this).unbind('click').attr('title', 'Pokaż/ukryj licytację').click(BIDDING_DATA.toggle_bidding); + }); + }, -var bind_bidding_links = function() { - $('a.biddingLink').each(function() { - $(this).unbind('click').attr('title', 'Pokaż/ukryj licytację').click(load_bidding); - }); + data: {}, + errorString: 'Brak danych' }; $(document).ready(function() { - setInterval(bind_bidding_links, 1000); + BIDDING_DATA.load_bidding(); + setInterval(BIDDING_DATA.bind_bidding_links, 1000); }); |