Skip to content

Instantly share code, notes, and snippets.

@alexeightsix
Created March 6, 2013 20:05
Show Gist options
  • Save alexeightsix/5102581 to your computer and use it in GitHub Desktop.
Save alexeightsix/5102581 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
function generateFaceValues() {
var gameLevel = '{{ product.metafields.level.GameLevel }}';
switch (gameLevel) {
case 'Bronze':
var key = 0;
break;
case 'Silver':
var key = 1;
break;
case 'Gold':
var key = 2;
break;
}
var rows = $('.ticketDetail-table li');
$.each(rows, function (index, value) {
var row = new Object();
row.status = $(this).data('status');
row.row = $(this).data('row');
row.section = $(this).data('section');
switch (row.section) {
case 101:
if (row.row == 'P' || row.row == 'M' || row.row == 'O' || row.row == 'J') {
row.faceValue = ["$100.00", "$110", "$175"];
}
break;
case 102:
if (row.row == 'M') {
row.faceValue = ["$100.00", "$110.00", "$175.00"];
}
break;
case 103:
if (row.row == 'O') {
row.faceValue = ["$100.00", "$110.00", "$175.00"];
}
break;
case 109:
if (row.row == 'K' || row.row == 'J' || row.row == 'O' || row.row == 'B') {
row.faceValue = ["$100.00", "$110.00", "$200.00"];
}
break;
case 110:
if (row.row == 'L' || row.row == 'K') {
row.faceValue = ["$100.00", "$110.00", "$200.00"];
}
break;
case 111:
if (row.row == 'R' || row.row == 'N' || row.row == 'P') {
row.faceValue = ["$100.00", "$110.00", "$200.00"];
}
break;
case 112:
if (row.row == 'N' || row.row == 'M') {
row.faceValue = ["$100.00", "$110.00", "$200.00"];
}
break;
case 113:
if (row.row == "B" || row.row == 'N' || row.row == 'K') {
row.faceValue = ["$100.00", "$110.00", "$200.00"];
}
if (row.row == 'A') {
row.faceValue = ["$155.00", "$225.00", "$300.00"];
}
break;
case 115:
if (row.row == 'C') {
row.faceValue = ["$135.00", "$174.00", "$250.00"];
}
break;
case 120:
if (row.row == "L" || row.row == 'M' || row.row == 'O' || row.row == 'N') {
row.faceValue = ["$100.00", "$110.00", "$175.00"];
}
break;
case 201:
if (row.row == 'B') {
row.faceValue = ["$75.00", "$95.00", "$150.00"];
}
case 204:
if (row.row == 'B') {
row.faceValue = ["$75.00", "$95.00", "$150.00"];
}
break;
case 205:
if (row.row == 'F') {
row.faceValue = ["$75.00", "$95.00", "$150.00"];
}
break;
case 224:
if (row.row == 'E') {
row.faceValue = ["$75.00", "$95.00", "$150.00"];
}
break;
case 225:
if (row.row == 'F') {
row.faceValue = ["$75.00", "$95.00", "$150.00"];
}
break;
case 226:
if (row.row == 'C') {
row.faceValue = ["$75.00", "$95.00", "$150.00"];
}
break;
case 312:
if (row.row == 'B') {
row.faceValue = ["$40.00", "$50.00", "$85.00"];
}
break;
case 301:
if (row.row == 'K') {
row.faceValue = ["$32.00", "$42.00", "$75.00"];
}
case 308:
if (row.row == 'J') {
row.faceValue = ["$40.00", "$50.00", "$85.00"];
}
}
if (Object.prototype.toString.call(row.faceValue) === '[object Array]') {
if ($(this).find('span.col-1').text().trim() != 'N/A') {
$(this).find('span.facevalue').text(row.faceValue[key]);
}
}
});
}
function removeDuplicates() {
var seen = {};
$('option').each(function () {
var txt = $(this).text();
if (seen[txt]) $(this).remove();
else seen[txt] = true;
});
}
function sortSelect() {
var my_options = $("#section-filter option");
my_options.sort(function (a, b) {
if (a.text > b.text) return 1;
else if (a.text < b.text) return -1;
else return 0
})
$('#section-filter').empty().append(my_options);
var priceFilter = $("#filtering-price option");
priceFilter.sort(function (a, b) {
if (a.text < b.text) return 1;
else if (a.text > b.text) return -1;
else return 0
})
$("#filtering-price").empty().append(priceFilter);
}
function generateSectionDropdown(tickets, select) {
$.each(tickets, function () {
var ticketRow = $(this).attr('data-row');
var ticketSection = $(this).attr('data-section')
if (ticketSection) {
select.append('<option value="' + ticketSection + '">' + ticketSection + '</option>')
}
})
}
function generatePriceDropdown(tickets) {
$.each(tickets, function () {
var thisPrice = $(this).attr('data-ppt');
var thisPriceFormatted = $(this).attr('data-pptm');
var isVisable = $(this).css('display');
var isAvailable = $(this).attr('data-status');
if (isAvailable == 'available') {
$('#filtering-price').append('<option value="' + thisPrice + '">' + thisPriceFormatted + '</option>');
}
})
}
$(document).ready(function () {
var tickets = $(".ticketDetail-table ul li:not(:first)");
var select = $('.filtering select');
generateSectionDropdown(tickets, select);
generatePriceDropdown(tickets);
removeDuplicates();
generateFaceValues()
$('#section-filter').on('change', function () {
var selectedSection = $(this).attr('value');
$('#filtering-price option:nth-child(1)').attr('selected', '');
if (selectedSection == 'All Sections') {
tickets.show();
}
else {
tickets.hide();
$('[data-section="' + selectedSection + '"]').show();
}
})
$('#hide-sold').mousedown(function () {
if (!$(this).is(':checked')) {
$('[data-status="sold"]').hide();
}
else {
$('[data-status="sold"]').show();
}
});
$('#filtering-price').on('change', function () {
//$('#section-filter option:nth-child(1)')
$('option[value="All Sections"]').attr('selected', '');
var thisPrice = $(this).attr('value');
if (thisPrice == 'All Prices') {
tickets.show();
}
else {
tickets.hide();
$('[data-ppt="' + thisPrice + '"]').show();
}
})
sortSelect();
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment