| 1 |
/* |
| 2 |
* Nozzle R Package - JavaScript Library |
| 3 |
* |
| 4 |
* Copyright 2011-2012, Harvard Medical School / Broad Institute |
| 5 |
* Authored and maintained by Nils Gehlenborg ([email protected]) |
| 6 |
*/ |
| 7 |
|
| 8 |
$(window).load(function() { $("#mask").fadeOut() }); |
| 9 |
|
| 10 |
function initNozzle( reportId, jquery ) { |
| 11 |
|
| 12 |
var $ = jquery; |
| 13 |
|
| 14 |
var menuHeight = 25; |
| 15 |
var minHorizontalBorder = 30; |
| 16 |
var maxWidth = 1000; |
| 17 |
var autoWidth = false; |
| 18 |
|
| 19 |
var defaultMainToNoteRatio = 0.5; |
| 20 |
var currentMainToNoteRatio = 0.50; |
| 21 |
var mainToNoteDistance = 20; |
| 22 |
|
| 23 |
var isNoteVisible = false; |
| 24 |
var visibleNoteId = null; |
| 25 |
|
| 26 |
var getVerticalMargins = function( element ) { |
| 27 |
return ( parseInt( element.css( "margin-top" ) ) + parseInt( element.css( "margin-bottom" ) ) ); |
| 28 |
}; |
| 29 |
|
| 30 |
var getVerticalPadding = function( element ) { |
| 31 |
return ( parseInt( element.css( "padding-top" ) ) + parseInt( element.css( "padding-bottom" ) ) ); |
| 32 |
}; |
| 33 |
|
| 34 |
var getHorizontalMargins = function( element ) { |
| 35 |
return ( parseInt( element.css( "margin-left" ) ) + parseInt( element.css( "margin-right" ) ) ); |
| 36 |
}; |
| 37 |
|
| 38 |
var getHorizontalPadding = function( element ) { |
| 39 |
return ( parseInt( element.css( "padding-left" ) ) + parseInt( element.css( "padding-right" ) ) ); |
| 40 |
}; |
| 41 |
|
| 42 |
|
| 43 |
var getFrame = function() { |
| 44 |
return $( "#" + reportId + " .frame" ); |
| 45 |
} |
| 46 |
|
| 47 |
var getMain = function() { |
| 48 |
return $( "#" + reportId + " .main" ); |
| 49 |
} |
| 50 |
|
| 51 |
var getReport = function() { |
| 52 |
return $( "#" + reportId ); |
| 53 |
} |
| 54 |
|
| 55 |
var getMenu = function() { |
| 56 |
return $( "#" + reportId + " .menu" ); |
| 57 |
} |
| 58 |
|
| 59 |
var getVisibleNote = function() { |
| 60 |
return $( visibleNoteId ); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
var getCurrentFrameWidth = function() { |
| 65 |
if ( !autoWidth ) { |
| 66 |
return ( Math.min( $(window).width() - 2*minHorizontalBorder, maxWidth ) ); |
| 67 |
} |
| 68 |
else { |
| 69 |
return ( $(window).width() - 2*minHorizontalBorder ); |
| 70 |
} |
| 71 |
}; |
| 72 |
|
| 73 |
var getCurrentFrameLeftBorder = function() { |
| 74 |
if ( !autoWidth ) { |
| 75 |
return ( ($(window).width() - getCurrentFrameWidth() )/2 ); |
| 76 |
} |
| 77 |
else { |
| 78 |
return ( minHorizontalBorder ); |
| 79 |
} |
| 80 |
}; |
| 81 |
|
| 82 |
$(document).ready( function() { |
| 83 |
// prefix and postfix to be applied to all relative URLs |
| 84 |
var args = getUrlVars( true ); |
| 85 |
applyFilePrefixPostfix( args["prefix"], args["postfix"] ); |
| 86 |
|
| 87 |
getFrame().css( 'height', $(window).height() + "px" ); |
| 88 |
getFrame().css( 'width', getCurrentFrameWidth() + "px" ); |
| 89 |
getFrame().css( 'left', getCurrentFrameLeftBorder() + "px" ); |
| 90 |
|
| 91 |
getMenu().css( "height", menuHeight ); |
| 92 |
getMain().css( "top", getMenu().outerHeight( true ) ); |
| 93 |
|
| 94 |
if ( visibleNoteId != null ) |
| 95 |
{ |
| 96 |
getMain().css( "bottom", computeMainBottom() ); |
| 97 |
getVisibleNote().css( "top", computeNoteTop() ); |
| 98 |
evidenceToggleButton.css( 'top', computeNoteTop() + "px" ); |
| 99 |
} |
| 100 |
}); |
| 101 |
|
| 102 |
$(window).resize( function() { |
| 103 |
getFrame().css( 'height', $(window).height() + "px" ); |
| 104 |
getFrame().css( 'width', getCurrentFrameWidth() + "px" ); |
| 105 |
getFrame().css( 'left', getCurrentFrameLeftBorder() + "px" ); |
| 106 |
|
| 107 |
getMenu().css( "height", menuHeight ); |
| 108 |
getMain().css( "top", getMenu().outerHeight( true ) ); |
| 109 |
|
| 110 |
if ( visibleNoteId != null ) |
| 111 |
{ |
| 112 |
getMain().css( "bottom", computeMainBottom() ); |
| 113 |
getVisibleNote().css( "top", computeNoteTop() ); |
| 114 |
evidenceToggleButton.css( 'top', computeNoteTop() + "px" ); |
| 115 |
} |
| 116 |
}); |
| 117 |
|
| 118 |
|
| 119 |
$( "#" + reportId + " .main" ).scroll( function() { |
| 120 |
//console.log( $( "#" + reportId + " .main" ).scrollTop() ); |
| 121 |
}); |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
// Read a page's GET URL variables and return them as an associative array. |
| 126 |
function getUrlVars( decode ) |
| 127 |
{ |
| 128 |
var vars = [], hash; |
| 129 |
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); |
| 130 |
|
| 131 |
for(var i = 0; i < hashes.length; i++) |
| 132 |
{ |
| 133 |
hash = hashes[i].split('='); |
| 134 |
vars.push(hash[0]); |
| 135 |
|
| 136 |
if ( decode == true ) { |
| 137 |
vars[hash[0]] = decodeURIComponent( hash[1] ); |
| 138 |
} |
| 139 |
else { |
| 140 |
vars[hash[0]] = hash[1]; |
| 141 |
} |
| 142 |
|
| 143 |
} |
| 144 |
|
| 145 |
return vars; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
// add a prefix and postfix to each img src and href anchor tag that contain a relative path/url |
| 150 |
function applyFilePrefixPostfix( prefix, postfix ) |
| 151 |
{ |
| 152 |
// check if both prefix and postfix are not undefined |
| 153 |
if ( prefix == undefined && postfix == undefined ) { |
| 154 |
return 1; |
| 155 |
} |
| 156 |
|
| 157 |
// find all img tags |
| 158 |
var imageTags = $( "img" ); |
| 159 |
var anchorTags = $( "a" ); |
| 160 |
|
| 161 |
var counter = 0; |
| 162 |
|
| 163 |
imageTags.each( function() { |
| 164 |
// check if this is a relative URL |
| 165 |
if ( $(this).attr( "src" ) === undefined ) { |
| 166 |
return; |
| 167 |
} |
| 168 |
|
| 169 |
if ( $(this).attr( "src" ).indexOf( "://" ) === -1 ) { |
| 170 |
$(this).attr( "src", prefix + $(this).attr( "src" ) + postfix ); |
| 171 |
|
| 172 |
console.log( $(this).attr( "src" ) ); |
| 173 |
|
| 174 |
counter++; |
| 175 |
} |
| 176 |
|
| 177 |
console.log( $(this).attr( "src" ) ); |
| 178 |
}); |
| 179 |
|
| 180 |
anchorTags.each( function() { |
| 181 |
// check if this is a relative URL |
| 182 |
if ( $(this).attr( "href" ) === undefined ) { |
| 183 |
return; |
| 184 |
} |
| 185 |
|
| 186 |
if ( $(this).attr( "href" ).indexOf( "://" ) === -1 && |
| 187 |
$(this).attr( "href" ).indexOf( "mailto:" ) === -1 && |
| 188 |
$(this).attr( "href" ) !== "#" ) { |
| 189 |
$(this).attr( "href", prefix + $(this).attr( "href" ) + postfix ); |
| 190 |
|
| 191 |
console.log( $(this).attr( "src" ) ); |
| 192 |
|
| 193 |
counter++; |
| 194 |
} |
| 195 |
}); |
| 196 |
|
| 197 |
return 0; |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
ToggleMode = { |
| 202 |
TOGGLE: 0, |
| 203 |
SHOW: 1, |
| 204 |
HIDE: 2 |
| 205 |
}; |
| 206 |
|
| 207 |
var toggleContents = function( section, animation, mode, target ) |
| 208 |
{ |
| 209 |
target = target || ".sectionbody"; |
| 210 |
|
| 211 |
section.each( function() { |
| 212 |
|
| 213 |
var section = $(this); |
| 214 |
mode = mode || ToggleMode.TOGGLE; |
| 215 |
|
| 216 |
var button = section.find( ".button.contenttoggle" ).first(); |
| 217 |
var body = section.find( target ).first(); |
| 218 |
var summarySignificant = section.find( ".summary.significant" ).first(); |
| 219 |
|
| 220 |
if ( body.length == 0 ) |
| 221 |
{ |
| 222 |
body = section; |
| 223 |
} |
| 224 |
|
| 225 |
// get all subsections in this section - if there is only one it will be expanded along with the section |
| 226 |
var subSections = section.find( ".subsection" ).not( ".meta, #" + reportId + " .evidence .section, #" + reportId + " .evidence .subsection, #" + reportId + " subsubsection .sectionheader" ); |
| 227 |
|
| 228 |
switch ( mode ) |
| 229 |
{ |
| 230 |
case ToggleMode.TOGGLE: |
| 231 |
if ( subSections.length == 1 ) |
| 232 |
{ |
| 233 |
if ( !section.hasClass( "visible" ) ) |
| 234 |
{ |
| 235 |
toggleContents( subSections, false, ToggleMode.SHOW ); |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
section.toggleClass( "visible" ); |
| 240 |
animation ? body.slideToggle( "fast" ) : body.toggle(); |
| 241 |
if ( summarySignificant !== undefined ) |
| 242 |
{ |
| 243 |
summarySignificant.toggleClass( "deactivated" ); |
| 244 |
} |
| 245 |
break; |
| 246 |
case ToggleMode.SHOW: |
| 247 |
if ( subSections.length == 1 ) |
| 248 |
{ |
| 249 |
toggleContents( subSections, false, ToggleMode.SHOW ); |
| 250 |
} |
| 251 |
|
| 252 |
section.addClass( "visible" ); |
| 253 |
animation ? body.slideDown( "fast" ) : body.show(); |
| 254 |
if ( summarySignificant !== undefined ) |
| 255 |
{ |
| 256 |
summarySignificant.addClass( "deactivated" ); |
| 257 |
} |
| 258 |
break; |
| 259 |
case ToggleMode.HIDE: |
| 260 |
section.removeClass( "visible" ); |
| 261 |
animation ? body.slideUp( "fast" ) : body.hide(); |
| 262 |
if ( summarySignificant !== undefined ) |
| 263 |
{ |
| 264 |
summarySignificant.removeClass( "deactivated" ); |
| 265 |
} |
| 266 |
break; |
| 267 |
|
| 268 |
} |
| 269 |
|
| 270 |
button.text( section.hasClass( "visible" ) ? "-" : "+" ); |
| 271 |
button.attr( "title", section.hasClass( "visible" ) ? "Click to collapse" : "Click to expand" ); |
| 272 |
} ); |
| 273 |
|
| 274 |
}; |
| 275 |
|
| 276 |
// create button to open/close sections/subsections |
| 277 |
var createContentsToggleButtons = function() { |
| 278 |
|
| 279 |
var sectionheaders = $( "#" + reportId + " .sectionheader" ).not( ".evidence .sectionheader, .subsubsection .sectionheader" ); |
| 280 |
|
| 281 |
sectionheaders.prepend( "<span class=\"button contenttoggle\"><a>" + "-" + "</a></span>" ); |
| 282 |
sectionheaders.parent().addClass( "visible" ); |
| 283 |
|
| 284 |
var buttons = $( "#" + reportId + " .button.contenttoggle" ); |
| 285 |
|
| 286 |
buttons.click( function() { |
| 287 |
toggleContents( $(this).parent().parent(), true, ToggleMode.TOGGLE ); |
| 288 |
}); |
| 289 |
}; |
| 290 |
|
| 291 |
|
| 292 |
// remove buttons to open/close sections/subsections (for printing) |
| 293 |
var removeContentsToggleButtons = function() { |
| 294 |
|
| 295 |
$( ".button.contenttoggle" ).remove(); |
| 296 |
}; |
| 297 |
|
| 298 |
|
| 299 |
var toggleAllContents = function( animation, mode ) { |
| 300 |
|
| 301 |
var sections = $( "#" + reportId + " .section, #" + reportId + " .subsection" ).not( "#" + reportId + " .evidence .section, #" + reportId + " .evidence .subsection, #" + reportId + " subsubsection .sectionheader" ); |
| 302 |
|
| 303 |
toggleContents( sections, animation, mode ); |
| 304 |
} |
| 305 |
|
| 306 |
var createContentsSummaryBar = function() { |
| 307 |
|
| 308 |
// contents summary bar (will contain indicator for significant results if any) |
| 309 |
var sectionheaders = $( ".results .sectionheader" ).not( "#" + reportId + " .evidence .sectionheader, #" + reportId + " .meta .sectionheader, #" + reportId + " .subsubsection .sectionheader" ); |
| 310 |
sectionheaders.append( "<span class=\"bar contentssummary\"></span>" ); |
| 311 |
}; |
| 312 |
|
| 313 |
|
| 314 |
var toggleWidthStateButton = function() { |
| 315 |
if ( autoWidth ) { |
| 316 |
$( "#menu_width_state" ).text( "Fixed" ); |
| 317 |
} |
| 318 |
else { |
| 319 |
$( "#menu_width_state" ).text( "Auto" ); |
| 320 |
} |
| 321 |
}; |
| 322 |
|
| 323 |
var createNozzleMenu = function() { |
| 324 |
|
| 325 |
var menu = "<div id=\"nozzlemenu\" class=\"menu\"><div class=\"menubar\">"; |
| 326 |
|
| 327 |
if ( nozzleNavigation.parentUrl != null ) { |
| 328 |
menu += "<a href=\"" + nozzleNavigation.parentUrl + "\"><div class=\"menuitem\" id=\"menu_go_parent\" title=\"" + nozzleNavigation.parentName + "\">Up</div></a>"; |
| 329 |
} |
| 330 |
else { |
| 331 |
menu += "<div class=\"menuitem deactivated\">Up</div>"; |
| 332 |
} |
| 333 |
|
| 334 |
if ( nozzleNavigation.previousUrl != null ) { |
| 335 |
menu += "<a href=\"" + nozzleNavigation.previousUrl + "\"><div class=\"menuitem\" id=\"menu_go_previous\" title=\"" + nozzleNavigation.previousName + "\"><</div></a>"; |
| 336 |
} |
| 337 |
else { |
| 338 |
menu += "<div class=\"menuitem deactivated\"><</div>"; |
| 339 |
} |
| 340 |
|
| 341 |
if ( nozzleNavigation.nextUrl != null ) { |
| 342 |
menu += "<a href=\"" + nozzleNavigation.nextUrl + "\"><div class=\"menuitem\" id=\"menu_go_next\" title=\"" + nozzleNavigation.nextName + "\">></div></a>"; |
| 343 |
} |
| 344 |
else { |
| 345 |
menu += "<div class=\"menuitem deactivated\">></div>"; |
| 346 |
} |
| 347 |
|
| 348 |
menu += "<div class=\"menuitem separator\"></div>"; |
| 349 |
|
| 350 |
menu += "<div class=\"menuitem\" id=\"menu_expand_all\">Expand All</div>\ |
| 351 |
<div class=\"menuitem\" id=\"menu_collapse_all\">Collapse All</div>\ |
| 352 |
<div class=\"menuitem\" id=\"menu_width\">Set <span id=\"menu_width_state\">Auto</span> Width</div>\ |
| 353 |
<div class=\"menuitem\" id=\"menu_print_view\">Print</div>"; |
| 354 |
|
| 355 |
if ( nozzleMeta.contact != null ) |
| 356 |
{ |
| 357 |
menu += "<div class=\"menuitem separator\"></div>"; |
| 358 |
|
| 359 |
var label = nozzleMeta.contact.label; |
| 360 |
|
| 361 |
if ( label == null ) |
| 362 |
{ |
| 363 |
label = "Contact"; |
| 364 |
} |
| 365 |
|
| 366 |
menu += "<div class=\"menuitem highlighted\" id=\"menu_report_problem\" title=\"Send an email.\">" + label + "</div>"; |
| 367 |
} |
| 368 |
|
| 369 |
menu += "</div></div>"; |
| 370 |
|
| 371 |
getFrame().prepend( menu ); |
| 372 |
|
| 373 |
$( "#menu_expand_all" ).click( function() { |
| 374 |
toggleAllContents( true, ToggleMode.SHOW ); |
| 375 |
}); |
| 376 |
|
| 377 |
$( "#menu_collapse_all" ).click( function() { |
| 378 |
toggleAllContents( true, ToggleMode.HIDE ); |
| 379 |
reduceAllFigures(); |
| 380 |
}); |
| 381 |
|
| 382 |
$( "#menu_width" ).click( function() { |
| 383 |
autoWidth = !autoWidth; |
| 384 |
toggleWidthStateButton(); |
| 385 |
getFrame().animate( { "width": getCurrentFrameWidth() + "px", "left": getCurrentFrameLeftBorder() + "px" }, "slow" ); |
| 386 |
}); |
| 387 |
|
| 388 |
$( "#menu_print_view" ).click( function() { |
| 389 |
|
| 390 |
// cover the report with an opaque mask |
| 391 |
$( "#mask" ).fadeIn(); |
| 392 |
document.getElementById("mask").style.display = "block"; |
| 393 |
|
| 394 |
// remove buttons, menus, and other stuff not required in the printed version |
| 395 |
removeContentsToggleButtons(); |
| 396 |
removeEvidenceToggleButtons(); |
| 397 |
$( "#nozzlemenu" ).remove(); |
| 398 |
$( "a.download" ).remove(); |
| 399 |
|
| 400 |
enlargeAllFigures(); |
| 401 |
|
| 402 |
toggleAllContents( false, ToggleMode.SHOW ); |
| 403 |
|
| 404 |
// add "end note" style numbers next to each supplementary result in the text and |
| 405 |
// move the supplementary result information to the end of the document and make |
| 406 |
// it visible |
| 407 |
addResultNumbers(); |
| 408 |
|
| 409 |
// open the print dialog (the media=print stylesheet will be applied) |
| 410 |
window.print(); |
| 411 |
|
| 412 |
// reload the file (restores report) |
| 413 |
window.location.reload(false); |
| 414 |
}); |
| 415 |
|
| 416 |
if ( nozzleMeta.contact != null ) |
| 417 |
{ |
| 418 |
$( "#menu_report_problem" ).click( function() { |
| 419 |
var subject = nozzleMeta.contact.subject; // "Problem Report for \"" + nozzleMeta.reportTitle + "\" (" + nozzleMeta.reportId + ")"; |
| 420 |
var message = nozzleMeta.contact.message; |
| 421 |
var email = nozzleMeta.contact.email; |
| 422 |
|
| 423 |
var browserDetails = navigator.userAgent; |
| 424 |
var locationDetails = window.location.href; |
| 425 |
var displayDetails = "Not detected." |
| 426 |
|
| 427 |
if (window.screen) { |
| 428 |
displayDetails = 'Current Dimensions: ' + $(window).width() + " x " + $(window).height() + "%0A"; |
| 429 |
displayDetails += 'Maximum Dimensions: ' + screen.availWidth + " x " + screen.availHeight + "%0A"; |
| 430 |
displayDetails += 'Color Depth: ' + screen.colorDepth; |
| 431 |
} |
| 432 |
|
| 433 |
var softwareName = "NA"; |
| 434 |
var softwareVersion = "NA"; |
| 435 |
|
| 436 |
if ( nozzleMeta.software != undefined ) |
| 437 |
{ |
| 438 |
softwareName = nozzleMeta.software.name; |
| 439 |
softwareVersion = nozzleMeta.software.version; |
| 440 |
} |
| 441 |
|
| 442 |
var body = |
| 443 |
message + "%0A" + |
| 444 |
"%0A" + |
| 445 |
"%0A" + |
| 446 |
"%0A" + |
| 447 |
"== REPORT ======================" + "%0A" + |
| 448 |
"%0A" + |
| 449 |
"URL: " + locationDetails + "%0A" + |
| 450 |
"Title: " + nozzleMeta.reportTitle + "%0A" + |
| 451 |
"Id: " + nozzleMeta.reportId + "%0A" + |
| 452 |
"Creator: " + nozzleMeta.creator.name + "%0A" + |
| 453 |
"Creation Date: " + nozzleMeta.creator.date + "%0A" + |
| 454 |
"Renderer: " + nozzleMeta.renderer.name + "%0A" + |
| 455 |
"Render Date: " + nozzleMeta.renderer.date + "%0A" + |
| 456 |
"Google Analytics: " + nozzleMeta.googleAnalyticsId + "%0A" + |
| 457 |
"%0A" + |
| 458 |
"%0A" + |
| 459 |
"== SOFTWARE ====================" + "%0A" + |
| 460 |
"%0A" + |
| 461 |
"Name: " + softwareName + "%0A" + |
| 462 |
"Version: " + softwareVersion + "%0A" + |
| 463 |
"%0A" + |
| 464 |
"%0A" + |
| 465 |
"== MAINTAINER ==================" + "%0A" + |
| 466 |
"%0A" + |
| 467 |
"Name: " + nozzleMeta.maintainer.name + "%0A" + |
| 468 |
"Affiliation: " + nozzleMeta.maintainer.affiliation + "%0A" + |
| 469 |
"Email: " + nozzleMeta.maintainer.email + "%0A" + |
| 470 |
"%0A" + |
| 471 |
"%0A" + |
| 472 |
"== SYSTEM ======================" + "%0A" + |
| 473 |
"%0A" + |
| 474 |
"System Time: " + (new Date()) + "%0A" + |
| 475 |
"User Agent: " + browserDetails + "%0A" + |
| 476 |
displayDetails + "%0A" + |
| 477 |
"%0A"; |
| 478 |
|
| 479 |
window.location = "mailto:" + email + "?subject=" + subject + "&body=" + body; |
| 480 |
}); |
| 481 |
} |
| 482 |
|
| 483 |
toggleWidthStateButton(); |
| 484 |
}; |
| 485 |
|
| 486 |
|
| 487 |
var addResultNumbers = function() { |
| 488 |
|
| 489 |
var nextResultNumber = 1; |
| 490 |
|
| 491 |
$( ".evidence" ).each( function( index ) { |
| 492 |
var resultId = $(this).attr( "id" ).split( '_' )[1]; |
| 493 |
|
| 494 |
$( "#resultid_" + resultId + "_" + reportId ).after( " <span class=\"resultnumbersup\">" + nextResultNumber + "</span>" ); |
| 495 |
|
| 496 |
$(this).prepend( "<span class=\"resultnumber\">" + nextResultNumber + " - Supplementary Result</span>" ); |
| 497 |
$(this).insertBefore( ".copyright" ); |
| 498 |
$(this).show(); |
| 499 |
|
| 500 |
nextResultNumber++; |
| 501 |
} ); |
| 502 |
} |
| 503 |
|
| 504 |
/** |
| 505 |
* Forces a reload of all stylesheets by appending a unique query string |
| 506 |
* to each stylesheet URL. |
| 507 |
*/ |
| 508 |
function reloadStylesheets() { |
| 509 |
var queryString = '?reload=' + new Date().getTime(); |
| 510 |
$('link[rel="stylesheet"]').each(function () { |
| 511 |
this.href = this.href.replace(/\?.*|$/, queryString); |
| 512 |
}); |
| 513 |
} |
| 514 |
|
| 515 |
|
| 516 |
/** These buttons are used to close the supplementary results. |
| 517 |
*/ |
| 518 |
var createEvidenceToggleButtons = function() { |
| 519 |
|
| 520 |
// create button |
| 521 |
var sectionheaders = $( "#" + reportId + " .evidence" ); |
| 522 |
|
| 523 |
sectionheaders.prepend( "<span class=\"button evidencetoggle\"><a title=\"Click to hide details\">" + "×" + "</a></span>" ); |
| 524 |
sectionheaders.addClass( "visible" ); |
| 525 |
|
| 526 |
var buttons = $( "#" + reportId + " .evidence .button.evidencetoggle" ); |
| 527 |
|
| 528 |
buttons.click( function() { |
| 529 |
toggleContents( getVisibleNote(), false, ToggleMode.HIDE, ".evidence" ); |
| 530 |
evidenceToggleButton.appendTo( $( visibleNoteId ) ); |
| 531 |
|
| 532 |
var resultId = getVisibleNote().attr( 'id' ).split( '_' )[1]; |
| 533 |
$( "#resultid_" + resultId + "_" + reportId ).removeClass( "active" ); |
| 534 |
|
| 535 |
var oldScrollTop = $( "#" + reportId + " .main" ).scrollTop(); |
| 536 |
|
| 537 |
//console.log( "before: " + $( "#" + reportId + " .main" ).scrollTop() ); |
| 538 |
|
| 539 |
|
| 540 |
getMain().animate( |
| 541 |
{ |
| 542 |
'bottom': "0px" |
| 543 |
}, |
| 544 |
"slow", |
| 545 |
function() { |
| 546 |
isNoteVisible = false; |
| 547 |
visibleNoteId = null; |
| 548 |
}); |
| 549 |
}); |
| 550 |
}; |
| 551 |
|
| 552 |
// remove evidence toggle buttons |
| 553 |
var removeEvidenceToggleButtons = function() { |
| 554 |
$( ".button.evidencetoggle" ).remove(); |
| 555 |
}; |
| 556 |
|
| 557 |
|
| 558 |
createContentsToggleButtons(); |
| 559 |
createContentsSummaryBar(); |
| 560 |
createEvidenceToggleButtons(); |
| 561 |
createNozzleMenu(); |
| 562 |
|
| 563 |
$( ".evidence" ).hide(); |
| 564 |
|
| 565 |
|
| 566 |
var resultLocationRatio = 0.5; |
| 567 |
|
| 568 |
var computeMainBottom = function() { |
| 569 |
return ( getFrame().height() * (1 - currentMainToNoteRatio ) ); |
| 570 |
}; |
| 571 |
|
| 572 |
var computeNoteTop = function() { |
| 573 |
return ( getFrame().height() * currentMainToNoteRatio + mainToNoteDistance ); |
| 574 |
}; |
| 575 |
|
| 576 |
var evidenceToggleButton; |
| 577 |
|
| 578 |
var toggleEvidence = function() { |
| 579 |
var resultId = $(this).attr( 'id' ).split( '_' )[1]; |
| 580 |
var evidence = $('#evidenceid_' + resultId + "_" + reportId ); |
| 581 |
|
| 582 |
// move the evidence out of the main document and embedded directly in frame |
| 583 |
evidence.appendTo( getFrame() ); |
| 584 |
|
| 585 |
if ( evidence.length != 0 ) |
| 586 |
{ |
| 587 |
if ( visibleNoteId != null && visibleNoteId != '#evidenceid_' + resultId + "_" + reportId ) { |
| 588 |
//toggleContents( $( visibleNoteId ), false, ToggleMode.HIDE, ".evidence" ); |
| 589 |
} |
| 590 |
|
| 591 |
//$( "#results_" + reportId + " .result" ).not( $(this) ).removeClass( "active" ); |
| 592 |
$( ".result" ).not( $(this) ).removeClass( "active" ); |
| 593 |
$(this).toggleClass( 'active' ); |
| 594 |
$(this).attr( "title", $(this).hasClass( "active" ) ? "Click to hide details" : "Click to show details" ); |
| 595 |
|
| 596 |
evidence.css( 'top', computeNoteTop() + "px" ); |
| 597 |
evidence.css( 'bottom', "0px" ); |
| 598 |
|
| 599 |
var offset = $(this).offset().top; |
| 600 |
var scrollTop = $( "#" + reportId + " .main" ).scrollTop(); |
| 601 |
var height = $( "#" + reportId + " .main" ).height(); |
| 602 |
|
| 603 |
resultLocationRatio = offset/height; |
| 604 |
scrollTarget = scrollTop + (($(window).height()/2) * (resultLocationRatio)); |
| 605 |
|
| 606 |
// working, but loss of focus area |
| 607 |
if ( !isNoteVisible ) { |
| 608 |
getMain().animate({ |
| 609 |
"bottom": computeMainBottom() + "px", |
| 610 |
}, |
| 611 |
"slow", |
| 612 |
function() { |
| 613 |
// move the evidence toggle button out of the main document and embedded directly in frame |
| 614 |
evidenceToggleButton = $( '#evidenceid_' + resultId + "_" + reportId + " .button.evidencetoggle" ); |
| 615 |
evidenceToggleButton.css( 'top', computeNoteTop() + "px" ); |
| 616 |
evidenceToggleButton.css( 'left', "-23px" ); |
| 617 |
|
| 618 |
evidence.fadeToggle( 'slow', function() { evidenceToggleButton.appendTo( getFrame() ); } ); |
| 619 |
$(this).animate( { scrollTop: scrollTarget }, "slow" ); |
| 620 |
|
| 621 |
isNoteVisible = true; |
| 622 |
visibleNoteId = "#evidenceid_" + resultId + "_" + reportId; |
| 623 |
}); |
| 624 |
} |
| 625 |
else |
| 626 |
{ |
| 627 |
toggleContents( getVisibleNote(), false, ToggleMode.HIDE, ".evidence" ); |
| 628 |
evidenceToggleButton.appendTo( $( visibleNoteId ) ); |
| 629 |
|
| 630 |
if ( visibleNoteId != '#evidenceid_' + resultId + "_" + reportId ) { |
| 631 |
evidence.fadeToggle( 'slow', function() { evidenceToggleButton.appendTo( getFrame() ); } ); |
| 632 |
visibleNoteId = "#evidenceid_" + resultId + "_" + reportId; |
| 633 |
|
| 634 |
evidenceToggleButton = $( '#evidenceid_' + resultId + "_" + reportId + " .button.evidencetoggle" ); |
| 635 |
evidenceToggleButton.css( 'top', computeNoteTop() + "px" ); |
| 636 |
evidenceToggleButton.css( 'left', "-23px" ); |
| 637 |
} |
| 638 |
else |
| 639 |
{ |
| 640 |
|
| 641 |
getMain().animate( |
| 642 |
{ |
| 643 |
'bottom': 0 + "px" |
| 644 |
}, |
| 645 |
"slow", |
| 646 |
function() { |
| 647 |
isNoteVisible = false; |
| 648 |
visibleNoteId = null; |
| 649 |
}); |
| 650 |
} |
| 651 |
} |
| 652 |
} |
| 653 |
else |
| 654 |
{ |
| 655 |
alert( "No evidence found for result \"" + resultId + "\"." ); |
| 656 |
} |
| 657 |
|
| 658 |
return false; |
| 659 |
} |
| 660 |
|
| 661 |
|
| 662 |
$( ".result" ).not( ".noevidence" ).click( toggleEvidence ); |
| 663 |
|
| 664 |
var overallSignificantResults = 0; |
| 665 |
|
| 666 |
// find subsections in declared "results" sections that have significant results |
| 667 |
$( ".results .subsection" ).not( ".evidence" ).each( function( index ) { |
| 668 |
var significantResults = 0; |
| 669 |
|
| 670 |
$(this).find( '.result.significant' ).each( function( index ) { |
| 671 |
++significantResults; |
| 672 |
}); |
| 673 |
|
| 674 |
if ( significantResults > 0 ) |
| 675 |
{ |
| 676 |
$(this).addClass( "significant" ); |
| 677 |
$(this).find( ".contentssummary" ).first().append( "<span class=\"summary significant\" title=\"Section contains findings that crossed a statistical threshold.\"></span>" ); |
| 678 |
} |
| 679 |
|
| 680 |
overallSignificantResults += significantResults; |
| 681 |
} ); |
| 682 |
|
| 683 |
if ( overallSignificantResults > 0 ) |
| 684 |
{ |
| 685 |
$( ".results .sectionheader .contentssummary" ).not( ".subsection .sectionheader .contentssummary" ).html( "<span class=\"summary significant\" title=\"Section contains findings that crossed a statistical threshold.\"></span>" ); |
| 686 |
} |
| 687 |
|
| 688 |
var scaleImage = function() { |
| 689 |
var width = $(this).css( 'width' ); |
| 690 |
|
| 691 |
if ( width === "200px" ) |
| 692 |
{ |
| 693 |
$(this).animate( { 'width': "800px" }, "fast" ); |
| 694 |
$(this).attr( "title", "Click to reduce" ); |
| 695 |
} |
| 696 |
else |
| 697 |
{ |
| 698 |
$(this).animate( { 'width': "200px" }, "fast" ); |
| 699 |
$(this).attr( "title", "Click to enlarge" ); |
| 700 |
} |
| 701 |
|
| 702 |
return false; |
| 703 |
} |
| 704 |
|
| 705 |
var enlargeAllFigures = function() { |
| 706 |
$( '.figure .image').each( function() { |
| 707 |
$(this).find( "img" ).css( "width", "800px" ); |
| 708 |
}); |
| 709 |
} |
| 710 |
|
| 711 |
var reduceAllFigures = function() { |
| 712 |
$( '.figure .image').each( function() { |
| 713 |
$(this).find( "img" ).css( "width", "200px" ); |
| 714 |
}); |
| 715 |
} |
| 716 |
|
| 717 |
// make figures "scalable" |
| 718 |
$( '.figure .image').each( function() { |
| 719 |
$(this).find( "img" ).css( "width", "200px" ); |
| 720 |
$(this).find( "img" ).click( scaleImage ); |
| 721 |
$(this).find( "img" ).attr( "title", "Click to enlarge" ); |
| 722 |
}); |
| 723 |
|
| 724 |
// add parser through the tablesorter addParser method |
| 725 |
// from: http://stackoverflow.com/questions/4126206/javascript-parsefloat-1-23e-7-gives-1-23e-7-when-need-0-000000123 |
| 726 |
// see also here: http://tablesorter.com/docs/example-parsers.html |
| 727 |
$.tablesorter.addParser({ |
| 728 |
// set a unique id |
| 729 |
id: 'scientificNotation', |
| 730 |
is: function(s) { |
| 731 |
return /[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?/.test(s); |
| 732 |
}, |
| 733 |
format: function(s) { |
| 734 |
return $.tablesorter.formatFloat(s); |
| 735 |
}, |
| 736 |
type: 'numeric' |
| 737 |
}); |
| 738 |
|
| 739 |
$.tablesorter.addParser({ |
| 740 |
// set a unique id |
| 741 |
id: 'bigMark', |
| 742 |
is: function(s) { |
| 743 |
return /^[0-9]?[0-9]?[0-9](,[0-9][0-9][0-9])*$/.test(s); |
| 744 |
}, |
| 745 |
format: function(s) { |
| 746 |
return s.replace( /,/gi, "" ); |
| 747 |
}, |
| 748 |
type: 'numeric' |
| 749 |
}); |
| 750 |
|
| 751 |
// make tables sortable |
| 752 |
$( '.resulttable.tablesorter.sortabletable').each( function() { |
| 753 |
$( this ).tablesorter(); // debug with: $( this ).tablesorter( { debug: true }); |
| 754 |
} ); |
| 755 |
|
| 756 |
var toggleDefaultState = function( animate ) { |
| 757 |
toggleAllContents( animate, ToggleMode.HIDE ); |
| 758 |
toggleContents( $( "#overview_" + reportId + ", #summary_" + reportId ), animate ); |
| 759 |
toggleContents( $( "#results_" + reportId ), animate ); |
| 760 |
}; |
| 761 |
|
| 762 |
toggleDefaultState( false ); |
| 763 |
} |