From 10da1dee8348160094b241fcc3f60584559971d6 Mon Sep 17 00:00:00 2001 From: saithis Date: Tue, 12 Feb 2013 19:34:16 +0100 Subject: [PATCH 1/3] Added jQuery UI tooltips --- code/boot.js | 56 +++++++++++++++++++++++++++-- code/chat.js | 6 ++-- code/debugging.js | 2 +- code/portal_detail_display.js | 4 +-- code/portal_detail_display_tools.js | 16 ++++----- code/request_handling.js | 2 +- main.js | 3 +- 7 files changed, 71 insertions(+), 18 deletions(-) diff --git a/code/boot.js b/code/boot.js index 3f90fb63..2e91471d 100644 --- a/code/boot.js +++ b/code/boot.js @@ -161,7 +161,7 @@ window.setupPlayerStat = function() { + '\n\nNote: your player stats can only be updated by a full reload (F5)'; $('#playerstat').html('' - + '

'+level+' ' + + '

'+level+' ' + ''+PLAYER.nickname+'' + '
' + 'XM: '+xmRatio+'%' @@ -189,6 +189,56 @@ window.setupSidebarToggle = function() { }); } +window.setupTooltips = function() { + $(document).tooltip({ + // enable mouse tracking + track: true, + // disable show/hide animation + show: false, + hide: false, + items: "[data-tooltip]", + content: function(){ + var type = $(this).attr('data-tooltip'); + if(type == 'title'){ + return $(this).attr('title'); + } + else if(type == 'title_render'){ + var title = $(this).attr('title'); + var data = []; + var max_columns = 0; + + // parse data + var rows = title.split('\n'); + $.each(rows, function(i, row){ + data[i] = row.replace(/\t+/g, '\t').split('\t'); + if(data[i].length > max_columns) max_columns = data[i].length; + }); + + // build table + if(max_columns > 1) { + var tooltip = ''; + $.each(data, function(i, row){ + tooltip += ''; + $.each(data[i], function(k, cell){ + var attributes = ''; + if(k == 0 && data[i].length < max_columns){ + attributes = ' colspan="'+(max_columns - data[i].length + 1)+'"'; + } + tooltip += ''+cell+''; + }); + tooltip += ''; + }); + tooltip += '
'; + return tooltip; + } + else { + return title.replace(/\n/g, '
'); + } + } + } + }); +} + // BOOTING /////////////////////////////////////////////////////////// @@ -204,6 +254,7 @@ function boot() { window.setupSidebarToggle(); window.updateGameScore(); window.setupPlayerStat(); + window.setupTooltips(); window.chat.setup(); // read here ONCE, so the URL is only evaluated one time after the // necessary data has been loaded. @@ -232,10 +283,11 @@ function asyncLoadScript(a){return function(b,c){var d=document.createElement("s // contains the default Ingress map style. var LLGMAPS = 'http://breunigs.github.com/ingress-intel-total-conversion/dist/leaflet_google.js'; var JQUERY = 'https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js'; +var JQUERYUI = 'http://code.jquery.com/ui/1.10.0/jquery-ui.js'; var LEAFLET = 'http://cdn.leafletjs.com/leaflet-0.5/leaflet.js'; var AUTOLINK = 'http://breunigs.github.com/ingress-intel-total-conversion/dist/autolink.js'; // after all scripts have loaded, boot the actual app -load(JQUERY, LEAFLET, AUTOLINK).then(LLGMAPS).onError(function (err) { +load(JQUERY, LEAFLET, AUTOLINK).then(LLGMAPS, JQUERYUI).onError(function (err) { alert('Could not all resources, the script likely won’t work.\n\nIf this happend the first time for you, it’s probably a temporary issue. Just wait a bit and try again.\n\nIf you installed the script for the first time and this happens:\n– try disabling NoScript if you have it installed\n– press CTRL+SHIFT+K in Firefox or CTRL+SHIFT+I in Chrome/Opera and reload the page. Additional info may be available in the console.\n– Open an issue at https://github.com/breunigs/ingress-intel-total-conversion/issues'); }).thenRun(boot); diff --git a/code/chat.js b/code/chat.js index 7b091552..61bd1ffd 100644 --- a/code/chat.js +++ b/code/chat.js @@ -336,7 +336,7 @@ window.chat.handlePublicAutomated = function(data) { case 'PORTAL': var latlng = [part[1].latE6/1E6, part[1].lngE6/1E6]; var js = 'window.zoomToAndShowPortal(\''+part[1].guid+'\', ['+latlng[0]+', '+latlng[1]+'])'; - tmpmsg += ''+part[1].name+''; + tmpmsg += ''+part[1].name+''; break; } }); @@ -453,9 +453,9 @@ window.chat.renderMsg = function(msg, nick, time, team) { var ta = unixTimeToHHmm(time); var tb = unixTimeToString(time, true); // help cursor via “#chat time” - var t = ''; + var t = ''; var s = 'style="color:'+COLORS[team]+'"'; - var title = nick.length >= 8 ? 'title="'+nick+'" class="help"' : ''; + var title = nick.length >= 8 ? 'title="'+nick+'" class="help" data-tooltip="title"' : ''; return '

'+t+' <'+nick+'> '+msg+'

'; } diff --git a/code/debugging.js b/code/debugging.js index b3f12ecc..7156ddda 100644 --- a/code/debugging.js +++ b/code/debugging.js @@ -72,7 +72,7 @@ window.debug.console.renderLine = function(text, errorType) { var d = new Date(); var ta = d.toLocaleTimeString(); // print line instead maybe? var tb = d.toLocaleString(); - var t = ''; + var t = ''; var s = 'style="color:'+color+'"'; var l = '

'+t+''+errorType+''+text+'

'; $('#debugconsole').prepend(l); diff --git a/code/portal_detail_display.js b/code/portal_detail_display.js index 98b33592..cec6b052 100644 --- a/code/portal_detail_display.js +++ b/code/portal_detail_display.js @@ -18,7 +18,7 @@ window.renderPortalDetails = function(guid) { if(d.portalV2.linkedEdges) $.each(d.portalV2.linkedEdges, function(ind, link) { links[link.isOrigin ? 'outgoing' : 'incoming']++; }); - function linkExpl(t) { return ''+t+''; } + function linkExpl(t) { return ''+t+''; } var linksText = [linkExpl('links'), linkExpl(' ↳ ' + links.incoming+'  •  '+links.outgoing+' ↴')]; var player = d.captured && d.captured.capturingPlayerId @@ -62,7 +62,7 @@ window.renderPortalDetails = function(guid) { .html('' + '

'+d.portalV2.descriptiveText.TITLE+'

' // help cursor via “.imgpreview img” - + '
' + + '
' + ''+Math.floor(getPortalLevel(d))+'' + '
'+getModDetails(d)+'
' + '
'+randDetails+'
' diff --git a/code/portal_detail_display_tools.js b/code/portal_detail_display_tools.js index 6bcbe96e..71d7c333 100644 --- a/code/portal_detail_display_tools.js +++ b/code/portal_detail_display_tools.js @@ -56,10 +56,10 @@ window.getModDetails = function(d) { } }); - var t = ''+mods[0]+'' - + ''+mods[1]+'' - + ''+mods[2]+'' - + ''+mods[3]+'' + var t = ''+mods[0]+'' + + ''+mods[1]+'' + + ''+mods[2]+'' + + ''+mods[3]+'' return t; } @@ -69,7 +69,7 @@ window.getEnergyText = function(d) { var totalNrg = getTotalPortalEnergy(d); var inf = currentNrg + ' / ' + totalNrg; var fill = prettyEnergy(currentNrg) + ' / ' + prettyEnergy(totalNrg) - return ['energy', '' + fill + '']; + return ['energy', '' + fill + '']; } window.getAvgResoDistText = function(d) { @@ -112,7 +112,7 @@ window.getResonatorDetails = function(d) { // rotates clockwise. So, last one is 7 (southeast). window.renderResonatorDetails = function(slot, level, nrg, dist, nick, isLeft) { if(level === 0) { - var meter = ''; + var meter = ''; } else { var max = RESO_NRG[level]; var fillGrade = nrg/max*100; @@ -131,7 +131,7 @@ window.renderResonatorDetails = function(slot, level, nrg, dist, nick, isLeft) { var fill = ''; - var meter = '' + fill + lbar + ''; + var meter = '' + fill + lbar + ''; } var cls = isLeft ? 'left' : 'right'; var text = ''+(nick||'')+''; @@ -162,7 +162,7 @@ window.getDestroyAP = function(d) { t += linkCount + '×\tLinks\t\t= ' + digits(linkAp) + '\n'; t += fieldCount + '×\tFields\t\t= ' + digits(fieldAp) + '\n'; t += 'Sum: ' + digits(sum) + ' AP'; - return '' + digits(text) + ''; + return '' + digits(text) + ''; } return [tt('AP Gain'), tt(sum)]; diff --git a/code/request_handling.js b/code/request_handling.js index 042fc397..e28f4c7e 100644 --- a/code/request_handling.js +++ b/code/request_handling.js @@ -47,7 +47,7 @@ window.renderUpdateStatus = function() { t += 'Up to date.'; if(renderLimitReached()) - t += ' RENDER LIMIT ' + t += ' RENDER LIMIT ' if(window.failedRequestCount > 0) t += ' ' + window.failedRequestCount + ' failed.' diff --git a/main.js b/main.js index 64a0967d..2d63987d 100644 --- a/main.js +++ b/main.js @@ -57,7 +57,8 @@ document.getElementsByTagName('head')[0].innerHTML = '' + 'Ingress Intel Map' + '' + '' - + ''; + + '' + + ''; document.getElementsByTagName('body')[0].innerHTML = '' + '
Loading, please wait
' From e0bb10f9897c60c4afab089abb2d8262b2c3288f Mon Sep 17 00:00:00 2001 From: saithis Date: Tue, 12 Feb 2013 19:46:04 +0100 Subject: [PATCH 2/3] Added missing space between 'span' and 'title' --- code/portal_detail_display_tools.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/portal_detail_display_tools.js b/code/portal_detail_display_tools.js index 71d7c333..96b92094 100644 --- a/code/portal_detail_display_tools.js +++ b/code/portal_detail_display_tools.js @@ -56,10 +56,10 @@ window.getModDetails = function(d) { } }); - var t = ''+mods[0]+'' - + ''+mods[1]+'' - + ''+mods[2]+'' - + ''+mods[3]+'' + var t = ''+mods[0]+'' + + ''+mods[1]+'' + + ''+mods[2]+'' + + ''+mods[3]+'' return t; } From 039f9c14b5fdc2d3ac8007b91be752afc94264e0 Mon Sep 17 00:00:00 2001 From: saithis Date: Tue, 12 Feb 2013 23:16:12 +0100 Subject: [PATCH 3/3] * The jQuery UI js/css file is now taken from ajax.googleapis.com instead of code.jquery.com * Table or not is now autodetected, removed data-tooltip attributes * Empty table cells are now possible * Removed duplicated \t's on some titles * Some tooltip code cleanup --- code/boot.js | 80 +++++++++++++---------------- code/chat.js | 6 +-- code/debugging.js | 2 +- code/game_status.js | 2 +- code/portal_detail_display.js | 4 +- code/portal_detail_display_tools.js | 26 +++++----- code/request_handling.js | 2 +- main.js | 2 +- 8 files changed, 59 insertions(+), 65 deletions(-) diff --git a/code/boot.js b/code/boot.js index 2e91471d..a0c7a591 100644 --- a/code/boot.js +++ b/code/boot.js @@ -153,15 +153,15 @@ window.setupPlayerStat = function() { var cls = PLAYER.team === 'ALIENS' ? 'enl' : 'res'; - var t = 'Level:\t\t' + level + '\n' - + 'XM:\t\t\t' + PLAYER.energy + ' / ' + xmMax + '\n' - + 'AP:\t\t\t' + digits(ap) + '\n' + var t = 'Level:\t' + level + '\n' + + 'XM:\t' + PLAYER.energy + ' / ' + xmMax + '\n' + + 'AP:\t' + digits(ap) + '\n' + (level < 8 ? 'level up in:\t' + lvlUpAp + ' AP' : 'Congrats! (neeeeerd)') - + '\n\Invites:\t\t'+PLAYER.available_invites; + + '\n\Invites:\t'+PLAYER.available_invites; + '\n\nNote: your player stats can only be updated by a full reload (F5)'; $('#playerstat').html('' - + '

'+level+' ' + + '

'+level+' ' + ''+PLAYER.nickname+'' + '
' + 'XM: '+xmRatio+'%' @@ -196,45 +196,39 @@ window.setupTooltips = function() { // disable show/hide animation show: false, hide: false, - items: "[data-tooltip]", - content: function(){ - var type = $(this).attr('data-tooltip'); - if(type == 'title'){ - return $(this).attr('title'); - } - else if(type == 'title_render'){ - var title = $(this).attr('title'); - var data = []; - var max_columns = 0; + content: function() { + var title = $(this).attr('title'); - // parse data - var rows = title.split('\n'); - $.each(rows, function(i, row){ - data[i] = row.replace(/\t+/g, '\t').split('\t'); - if(data[i].length > max_columns) max_columns = data[i].length; + // check if it should be converted to a table + if(!title.match(/\t/)) { + return title.replace(/\n/g, '
'); + } + + var data = []; + var columnCount = 0; + + // parse data + var rows = title.split('\n'); + $.each(rows, function(i, row) { + data[i] = row.split('\t'); + if(data[i].length > columnCount) columnCount = data[i].length; + }); + + // build the table + var tooltip = ''; + $.each(data, function(i, row) { + tooltip += ''; + $.each(data[i], function(k, cell) { + var attributes = ''; + if(k === 0 && data[i].length < columnCount) { + attributes = ' colspan="'+(columnCount - data[i].length + 1)+'"'; + } + tooltip += ''+cell+''; }); - - // build table - if(max_columns > 1) { - var tooltip = '
'; - $.each(data, function(i, row){ - tooltip += ''; - $.each(data[i], function(k, cell){ - var attributes = ''; - if(k == 0 && data[i].length < max_columns){ - attributes = ' colspan="'+(max_columns - data[i].length + 1)+'"'; - } - tooltip += ''+cell+''; - }); - tooltip += ''; - }); - tooltip += '
'; - return tooltip; - } - else { - return title.replace(/\n/g, '
'); - } - } + tooltip += ''; + }); + tooltip += ''; + return tooltip; } }); } @@ -283,7 +277,7 @@ function asyncLoadScript(a){return function(b,c){var d=document.createElement("s // contains the default Ingress map style. var LLGMAPS = 'http://breunigs.github.com/ingress-intel-total-conversion/dist/leaflet_google.js'; var JQUERY = 'https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js'; -var JQUERYUI = 'http://code.jquery.com/ui/1.10.0/jquery-ui.js'; +var JQUERYUI = 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js'; var LEAFLET = 'http://cdn.leafletjs.com/leaflet-0.5/leaflet.js'; var AUTOLINK = 'http://breunigs.github.com/ingress-intel-total-conversion/dist/autolink.js'; diff --git a/code/chat.js b/code/chat.js index 61bd1ffd..7b091552 100644 --- a/code/chat.js +++ b/code/chat.js @@ -336,7 +336,7 @@ window.chat.handlePublicAutomated = function(data) { case 'PORTAL': var latlng = [part[1].latE6/1E6, part[1].lngE6/1E6]; var js = 'window.zoomToAndShowPortal(\''+part[1].guid+'\', ['+latlng[0]+', '+latlng[1]+'])'; - tmpmsg += ''+part[1].name+''; + tmpmsg += ''+part[1].name+''; break; } }); @@ -453,9 +453,9 @@ window.chat.renderMsg = function(msg, nick, time, team) { var ta = unixTimeToHHmm(time); var tb = unixTimeToString(time, true); // help cursor via “#chat time” - var t = ''; + var t = ''; var s = 'style="color:'+COLORS[team]+'"'; - var title = nick.length >= 8 ? 'title="'+nick+'" class="help" data-tooltip="title"' : ''; + var title = nick.length >= 8 ? 'title="'+nick+'" class="help"' : ''; return '

'+t+' <'+nick+'> '+msg+'

'; } diff --git a/code/debugging.js b/code/debugging.js index 7156ddda..b3f12ecc 100644 --- a/code/debugging.js +++ b/code/debugging.js @@ -72,7 +72,7 @@ window.debug.console.renderLine = function(text, errorType) { var d = new Date(); var ta = d.toLocaleTimeString(); // print line instead maybe? var tb = d.toLocaleString(); - var t = ''; + var t = ''; var s = 'style="color:'+color+'"'; var l = '

'+t+''+errorType+''+text+'

'; $('#debugconsole').prepend(l); diff --git a/code/game_status.js b/code/game_status.js index 6027bfe3..fe29b868 100644 --- a/code/game_status.js +++ b/code/game_status.js @@ -15,7 +15,7 @@ window.updateGameScore = function(data) { var es = ' '+Math.round(ep)+'%'; $('#gamestat').html(rs+es).one('click', function() { window.updateGameScore() }); // help cursor via “#gamestat span” - $('#gamestat').attr('title', 'Resistance:\t\t'+r+' MindUnits\nEnlightenment:\t'+e+' MindUnits'); + $('#gamestat').attr('title', 'Resistance:\t'+r+' MindUnits\nEnlightenment:\t'+e+' MindUnits'); window.setTimeout('window.updateGameScore', REFRESH_GAME_SCORE*1000); } diff --git a/code/portal_detail_display.js b/code/portal_detail_display.js index cec6b052..98b33592 100644 --- a/code/portal_detail_display.js +++ b/code/portal_detail_display.js @@ -18,7 +18,7 @@ window.renderPortalDetails = function(guid) { if(d.portalV2.linkedEdges) $.each(d.portalV2.linkedEdges, function(ind, link) { links[link.isOrigin ? 'outgoing' : 'incoming']++; }); - function linkExpl(t) { return ''+t+''; } + function linkExpl(t) { return ''+t+''; } var linksText = [linkExpl('links'), linkExpl(' ↳ ' + links.incoming+'  •  '+links.outgoing+' ↴')]; var player = d.captured && d.captured.capturingPlayerId @@ -62,7 +62,7 @@ window.renderPortalDetails = function(guid) { .html('' + '

'+d.portalV2.descriptiveText.TITLE+'

' // help cursor via “.imgpreview img” - + '
' + + '
' + ''+Math.floor(getPortalLevel(d))+'' + '
'+getModDetails(d)+'
' + '
'+randDetails+'
' diff --git a/code/portal_detail_display_tools.js b/code/portal_detail_display_tools.js index 96b92094..33571d6c 100644 --- a/code/portal_detail_display_tools.js +++ b/code/portal_detail_display_tools.js @@ -56,10 +56,10 @@ window.getModDetails = function(d) { } }); - var t = ''+mods[0]+'' - + ''+mods[1]+'' - + ''+mods[2]+'' - + ''+mods[3]+'' + var t = ''+mods[0]+'' + + ''+mods[1]+'' + + ''+mods[2]+'' + + ''+mods[3]+'' return t; } @@ -69,7 +69,7 @@ window.getEnergyText = function(d) { var totalNrg = getTotalPortalEnergy(d); var inf = currentNrg + ' / ' + totalNrg; var fill = prettyEnergy(currentNrg) + ' / ' + prettyEnergy(totalNrg) - return ['energy', '' + fill + '']; + return ['energy', '' + fill + '']; } window.getAvgResoDistText = function(d) { @@ -112,15 +112,15 @@ window.getResonatorDetails = function(d) { // rotates clockwise. So, last one is 7 (southeast). window.renderResonatorDetails = function(slot, level, nrg, dist, nick, isLeft) { if(level === 0) { - var meter = ''; + var meter = ''; } else { var max = RESO_NRG[level]; var fillGrade = nrg/max*100; - var inf = 'energy:\t\t' + nrg + ' / ' + max + ' (' + Math.round(fillGrade) + '%)\n' - + 'level:\t\t' + level + '\n' + var inf = 'energy:\t' + nrg + ' / ' + max + ' (' + Math.round(fillGrade) + '%)\n' + + 'level:\t' + level + '\n' + 'distance:\t' + dist + 'm\n' - + 'owner:\t\t' + nick + '\n' + + 'owner:\t' + nick + '\n' + 'octant:\t' + OCTANTS[slot]; var style = 'width:'+fillGrade+'%; background:'+COLORS_LVL[level]+';'; @@ -131,7 +131,7 @@ window.renderResonatorDetails = function(slot, level, nrg, dist, nick, isLeft) { var fill = ''; - var meter = '' + fill + lbar + ''; + var meter = '' + fill + lbar + ''; } var cls = isLeft ? 'left' : 'right'; var text = ''+(nick||'')+''; @@ -159,10 +159,10 @@ window.getDestroyAP = function(d) { function tt(text) { var t = 'Destroy:\n'; t += resoCount + '×\tResonators\t= ' + digits(resoAp) + '\n'; - t += linkCount + '×\tLinks\t\t= ' + digits(linkAp) + '\n'; - t += fieldCount + '×\tFields\t\t= ' + digits(fieldAp) + '\n'; + t += linkCount + '×\tLinks\t= ' + digits(linkAp) + '\n'; + t += fieldCount + '×\tFields\t= ' + digits(fieldAp) + '\n'; t += 'Sum: ' + digits(sum) + ' AP'; - return '' + digits(text) + ''; + return '' + digits(text) + ''; } return [tt('AP Gain'), tt(sum)]; diff --git a/code/request_handling.js b/code/request_handling.js index e28f4c7e..042fc397 100644 --- a/code/request_handling.js +++ b/code/request_handling.js @@ -47,7 +47,7 @@ window.renderUpdateStatus = function() { t += 'Up to date.'; if(renderLimitReached()) - t += ' RENDER LIMIT ' + t += ' RENDER LIMIT ' if(window.failedRequestCount > 0) t += ' ' + window.failedRequestCount + ' failed.' diff --git a/main.js b/main.js index 2d63987d..9d1ea3b1 100644 --- a/main.js +++ b/main.js @@ -58,7 +58,7 @@ document.getElementsByTagName('head')[0].innerHTML = '' + '' + '' + '' - + ''; + + ''; document.getElementsByTagName('body')[0].innerHTML = '' + '
Loading, please wait
'