From: Simon Brandhof Date: Mon, 15 Jul 2013 12:06:47 +0000 (+0200) Subject: Fix some JS quality flaws X-Git-Tag: 3.7~123 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=148e6b13dfb213a6083b5413b8a59675c10e1db8;p=sonarqube.git Fix some JS quality flaws --- diff --git a/sonar-server/src/main/webapp/javascripts/dashboard.js b/sonar-server/src/main/webapp/javascripts/dashboard.js index 9f14490c8b9..9aa52e28cd0 100644 --- a/sonar-server/src/main/webapp/javascripts/dashboard.js +++ b/sonar-server/src/main/webapp/javascripts/dashboard.js @@ -1,23 +1,25 @@ var Portal = Class.create(); Portal.prototype = { initialize: function (options) { - this.setOptions(options); - if (!this.options.editorEnabled) return; + this.setOptions(options); + if (!this.options.editorEnabled) { + return; + } - Droppables.add(this.options.blocklist, { - containment : $A($$("."+this.options.column)), - hoverclass : this.options.hoverclass, - overlap : 'horizontal', - onDrop: function(dragged, dropped) { - $(dragged).remove(); - } - }); + Droppables.add(this.options.blocklist, { + containment: $A($$("." + this.options.column)), + hoverclass: this.options.hoverclass, + overlap: 'horizontal', + onDrop: function (dragged, dropped) { + $(dragged).remove(); + } + }); - this.createAllSortables(); + this.createAllSortables(); - this.lastSaveString = ""; + this.lastSaveString = ""; - this.saveDashboardsState(); + this.saveDashboardsState(); }, /****************************************************/ @@ -56,12 +58,14 @@ Portal.prototype = { var result = ""; var index = 1; $$("."+this.options.column).each(function (sortable) { - if ($(sortable).select("."+this.options.block).length == 0) { + if ($(sortable).select("."+this.options.block).length === 0) { $(sortable).select("."+this.options.columnhandle)[0].show(); } else { $(sortable).select("."+this.options.columnhandle)[0].hide(); } - if (index > 1) result += ";"; + if (index > 1) { + result += ";"; + } result += Sortable.sequence($(sortable).identify()); index++; }); @@ -71,7 +75,9 @@ Portal.prototype = { var firstTime=this.lastSaveString==""; this.lastSaveString=result; - if (firstTime) return; + if (firstTime) { + return; + } try { if ($(this.options.dashboardstate)) { diff --git a/sonar-server/src/main/webapp/javascripts/issue.js b/sonar-server/src/main/webapp/javascripts/issue.js index 2beda2b9d7b..8ae078bdcda 100644 --- a/sonar-server/src/main/webapp/javascripts/issue.js +++ b/sonar-server/src/main/webapp/javascripts/issue.js @@ -52,7 +52,7 @@ function submitIssueForm(elt) { var issueKey = issueElt.attr('data-issue-key'); var replaced = $j(htmlResponse); issueElt.replaceWith(replaced); - notifyIssueChange(issueKey) + notifyIssueChange(issueKey); } ).fail(function (jqXHR, textStatus) { closeIssueForm(elt); @@ -87,17 +87,17 @@ function doIssueAction(elt, action, parameters) { // Used for actions defined by plugins function doPluginIssueAction(elt, action) { var parameters = {}; - return doIssueAction(elt, action, parameters) + return doIssueAction(elt, action, parameters); } function assignIssueToMe(elt) { var parameters = {'me': true}; - return doIssueAction(elt, 'assign', parameters) + return doIssueAction(elt, 'assign', parameters); } function doIssueTransition(elt, transition) { var parameters = {'transition': transition}; - return doIssueAction(elt, 'transition', parameters) + return doIssueAction(elt, 'transition', parameters); } function formDeleteIssueComment(elt) { diff --git a/sonar-server/src/main/webapp/javascripts/recent-history.js b/sonar-server/src/main/webapp/javascripts/recent-history.js index 08fd5b23e74..e0845428029 100644 --- a/sonar-server/src/main/webapp/javascripts/recent-history.js +++ b/sonar-server/src/main/webapp/javascripts/recent-history.js @@ -3,38 +3,38 @@ window.Sonar = {}; Sonar.RecentHistory = function () { }; -Sonar.RecentHistory.prototype.getRecentHistory = function() { +Sonar.RecentHistory.prototype.getRecentHistory = function () { var sonarHistory = localStorage.getItem("sonar_recent_history"); if (sonarHistory == null) { - sonarHistory = new Array(); + sonarHistory = []; } else { sonarHistory = JSON.parse(sonarHistory); } return sonarHistory; }; - + Sonar.RecentHistory.prototype.clear = function () { localStorage.clear(); }; - + Sonar.RecentHistory.prototype.add = function (resourceKey, resourceName, iconPath) { var sonarHistory = this.getRecentHistory(); - - if (resourceKey != '') { + + if (resourceKey !== '') { var newEntry = {'key': resourceKey, 'name': resourceName, 'iconPath': iconPath}; // removes the element of the array if it exists - for (i = 0; i < sonarHistory.length; i++) { + for (var i = 0; i < sonarHistory.length; i++) { var item = sonarHistory[i]; - if (item['key'] == resourceKey) { + if (item['key'] === resourceKey) { sonarHistory.splice(i, 1); break; } - } + } // then add it to the beginning of the array sonarHistory.unshift(newEntry); // and finally slice the array to keep only 10 elements - sonarHistory = sonarHistory.slice(0,10); - + sonarHistory = sonarHistory.slice(0, 10); + localStorage.setItem("sonar_recent_history", JSON.stringify(sonarHistory)); } }; @@ -42,22 +42,22 @@ Sonar.RecentHistory.prototype.add = function (resourceKey, resourceName, iconPat Sonar.RecentHistory.prototype.populateRecentHistoryPanel = function () { var historyLinksList = $j('#recent-history-list'); historyLinksList.empty(); - - var recentHistory = this.getRecentHistory(); - if (recentHistory.length == 0) { + + var recentHistory = this.getRecentHistory(); + if (recentHistory.length === 0) { $j("#recent-history").hide(); - } else { + } else { recentHistory.forEach(function (resource) { historyLinksList.append('
  • ' - + resource['name'] - + '
  • '); + + baseUrl + + resource['iconPath'] + + '"> ' + + resource['name'] + + ''); }); $j("#recent-history").show(); } diff --git a/sonar-server/src/main/webapp/javascripts/resource.js b/sonar-server/src/main/webapp/javascripts/resource.js index 07ef48116a6..45efcf8a270 100644 --- a/sonar-server/src/main/webapp/javascripts/resource.js +++ b/sonar-server/src/main/webapp/javascripts/resource.js @@ -45,7 +45,7 @@ function collapseTests(index, elt){ function highlight_usages(event){ var isAlreadyHighlighted = false; var selectedElementClasses = $j(this).attr("class").split(" "); - if(selectedElementClasses.indexOf("highlighted") != -1) { + if(selectedElementClasses.indexOf("highlighted") !== -1) { isAlreadyHighlighted = true; } $j("#" + event.data.id + " span.highlighted").removeClass("highlighted");