$(document).ready(function () { var suitImage = ['spades', 'hearts', 'diamonds', 'clubs']; //alert('page loaded'); console.log('page loaded'); $('span.biddingSequence').each(function() { var EVEN_SEP = ' – '; var ODD_SEP = ', '; var result = ' '; var bids = $(this).text().split(' '); //console.log(bids); for(var index = 0; index < bids.length; index++ ) { if(isOdd(index)) result += EVEN_SEP; result += formatOneBid(bids[index].trim()); if(isOdd(index) && index < bids.length -1 ) result += ODD_SEP; } result += '\n'; //$(this).removeClass('biddingSequence'); $(this).html(result); }); function isOdd(number) { return (number % 2) == 1; } function formatOneBid(str) { //console.log('formatOneBid: str = >>>' + str + '<<<'); //console.log(str[0] + ' ' + str[1]); var result = ''; //console.log(cnvtSuitImage(str[1])); if(2 == str.length) { result = str[0] + cnvtSuitImage(str[1].toLowerCase()); } else result = str; //console.log(result); return result; } function cnvtSuitImage(char) { //console.log('cnvtSuitImage: char = >>>' + char + '<<<'); if(char == 's') return suitImage[0]; if(char == 'h') return suitImage[1]; if(char == 'd') return suitImage[2]; if(char == 'c') return suitImage[3]; if(char == 'n') return 'N'; } $('span.bridgeHand').each(function() { var SUIT_SPACING = '\u2002'; console.log($(this).text()); var suits = $(this).text().split('#'); console.log(suits); $(this).text(''); for(var index = 0; index < 4; index++ ) { //console.log('suits[' + index +'] = ' + suits[index]); $(this).append(suitImage[index]) .append(' ') .append(letterSpaceText(suits[index])) .append(SUIT_SPACING); } }); function letterSpaceText(str) { console.log('letterSpaceText: str = ' + str); var INSERTION = '\u2009'; if( 0 == str.length) return; var result = str[0].toUpperCase() + INSERTION; if( 1 == str.length) return result; var index; for(index = 1; index < str.length-1; index++) { var character = str[index].toUpperCase(); console.log('letterSpaceText: character = ' + character); result += character + INSERTION ; if(index == 3 && index < str.length-1) result += INSERTION; } result += str.charAt(str.length-1).toUpperCase(); if(index >= 4) result += INSERTION; console.log('letterSpaceText: result = ' + result); return result; } var citationImage = "information"; $('.citation').each( function () { var spacing = "  "; var citationContent = $(this).text(); console.log('citation found: content = ' + citationContent); var parent = $(this).parent(); $(this).remove(); parent.append(spacing + citationImage) .find('.citationImage') .attr('title',citationContent) ; }); var noteImage = "note"; $('.note').each( function () { var spacing = "  "; var noteContent = $(this).text(); console.log('note found: content = ' + noteContent); var parent = $(this).parent(); $(this).remove(); parent.append(spacing + noteImage) .find('.noteImage') .attr('title',noteContent) ; }); });