f7e9fc8174460bbec56aa71db7233129b4ce904f tdreszer Wed May 14 11:39:22 2014 -0700 Polished for jshint. diff --git src/hg/js/alleles.js src/hg/js/alleles.js index 355e786..2a81e7c 100644 --- src/hg/js/alleles.js +++ src/hg/js/alleles.js @@ -1,19 +1,19 @@ // JavaScript Especially for the Gene Haplotype Alleles section of hgGene CGI -// Tell jslint and browser to use strict mode for this file: -"use strict"; +// Don't complain about line break before '||' etc: +/* jshint -W014 */ // Alleles supports gene haplotype alleles section var alleles = (function() { var sectionName = "haplotypes"; // This define is used throughout var seqCharsPerPos = 1; // These globals should only need to be calculated once var seqPxPerPos = 7; var ajaxUpdates = 0; // persistence between ajax calls var persistRareHapsShown = false; var persistScoresShown = false; var persistSortReverse = false; var persistSortColId = ''; @@ -73,342 +73,347 @@ dataType: "html", trueSuccess: update, success: catchErrorOrDispatch, error: errorHandler, //async: false, //cmd: cmd, loadingId: showLoadingImage(sectionName), cache: false }); } function afterSort(obj) { // The sort table is controlled by utls.js, but this is some allele specific stuff var thisId = $(obj).attr('id'); - if (persistSortColId != thisId) + if (persistSortColId !== thisId) persistSortColId = thisId; else persistSortReverse = ( !persistSortReverse ); // Sorted variant is hilited special if ($(obj).hasClass('var')) { hiliteId = thisId; hiliteSpecial( hiliteId ); } } function persistThroughUpdates() { // When an ajax update occurs, restore the non-ajax settings state // See if table was sorted previously - if (persistSortColId != '') { + if (persistSortColId !== '') { var col = $('table#alleles').find('TH#' + persistSortColId); - if (col != undefined && col.length != 0) { + if (col && col.length !== 0) { var colIx = Number( $(col).attr('cellIndex') ); $(col).click(); if (persistSortReverse) {// click twice if reverse order! persistSortReverse = false; // Needed so that it is set again setTimeout("$('table#alleles').find('TH#" + persistSortColId + "').click();", 50); } } } // Make sure that sort command saves the coumn for persistence $('table#alleles').find('TH').click(function (e) { afterSort(this); }); // Persist on lighlite as red - if (hiliteId != '') + if (hiliteId !== '') hiliteSpecial( hiliteId ); } function propgateTitle(obj) { // Adds this objects title to all other objs with the same class // Relies upon a span and fixed width text // Find pointer position within text // Is there a title? var theTitle = obj.title; - if (theTitle == undefined || theTitle.length === 0) + if (!theTitle || theTitle.length === 0) return; var varId = $( obj ).attr('id'); $('table#alleles').find('TD.' + varId).not("[title]").attr('title', theTitle); } var hilites = []; // Hold on to all the hilite ids that are currently displayed var hiliteId = ''; function hiliteTag(xPx, widthPx) { // returns an id based upon dimensions return "hilite" + xPx.toFixed(0) + "-" + widthPx.toFixed(0); } function hiliteAdd(xPx, widthPx, yPx, heightPx) { // Adds a hilite div with the specific dimensions. // Returns the div for further customization if (xPx === 0) return; // make sure it doesn't already exist! var hId = hiliteTag(xPx,widthPx); - if (hilites.indexOf(hId) != -1) + if (hilites.indexOf(hId) !== -1) return hId; var tbl = $('table#alleles'); var tripleView = ($(tbl).find('TD.dnaToo').length > 0); - if (yPx == undefined) { + if (yPx === undefined || yPx === null) { // number could be 0 so be explicit if (tripleView) yPx = $(tbl).position().top + 2; // span whole height of table else yPx = $(tbl).find('TH#seq').position().top; // skip first row of header } - if (heightPx == undefined || heightPx === 0) { + if (!heightPx || heightPx === 0) { if (tripleView) heightPx = $(tbl).height() - 8; // span whole height of table else heightPx = $(tbl).height() - (2 * $(tbl).find('TH#seq').height()) + 4; } var div = $("