MediaWiki:Common.js/shops.js

$(function{ $('.shoptable th b').click(function { if ($(this).parents('.shoptable').is('.collapsed')) { $(this).parents('.shoptable').removeClass('collapsed'); $(this).html('Close window') } else { $(this).parents('.shoptable').addClass('collapsed'); $(this).html('Open shop') } })

$('.money').attr('contenteditable','true') $('.info td+td+td').click(function {$('.money').focus;}).attr('title','click to change the amount of money you have.'); })

$(function{ $('td[colspan="2"][title]').click(function { $('.select').removeClass('select'); $(this).addClass('select'); var item = $(this).children('img').attr('alt').replace(/\.\w{2,4}$/,''); var price = $(this).attr('title').replace('gp',''); var amount = parseInt($(this).children('.stock').html); if (amount > 0) { var amounts = '1'+(amount>=5?'5':)+(amount>=10?'10':)+(amount>=50?'50':''); $('.buy').html(''+item+': buy for '+price+'gp each Buy:'+amounts+'X  '); $('.sell').html(' You do not have any of this item to sell ') } else { amount = Math.abs(amount); var amounts = '1'+(amount>=5?'5':)+(amount>=10?'10</b>':)+(amount>=50?'50</b>':''); $('.sell').html('<td colspan="12" style="text-align:left;">'+item+': sell for '+price+'gp each Sell:'+amounts+'X</b>  '); $('.buy').html(' This item is currently not available to buy '); }

//$('.buy b, .sell b').click(submitOffer); }) })

function submitOffer { var thistd = $(this).parents('td[colspan][title]'); var amount = parseInt($(this).attr('data-amount')); amount = amount?amount:parseInt(prompt('Type the number of items to buy and press enter')); if (!amount) { alert('The amount you entered is not a number.'); return false; } var stock = Math.abs(parseInt(thistd.children('.stock').html)); var type = $(this).is('.buy b')?'buy':'sell'; if (amount > stock) { alert('The amount you entered is bigger than the '+(type=='buy'?'buy offer':'shop stocks')+'. Please enter an amount smaller than '+stock+'.'); return false;} var item = thistd.children('.img').attr('alt').replace(/\.\w{2,4}$/,''); if (!confirm('Are you sure you want to place an offer to '+type+' '+amount+' '+item+'s?')) {return false;} //Code for submitting the offer here }