accurator/commit

Moved and improved code for link domains, resolves #262

authorChris Dijkshoorn
Tue Apr 19 14:14:18 2016 +0200
committerChris Dijkshoorn
Tue Apr 19 14:14:18 2016 +0200
commit13f4ed69c776eab36a5cd3459dda5c41f80c4c24
tree5902f871bd924bb2026a5d8dc6771fb25e6c9ed1
parent1f9fabe3f5611b0eaf5c93a96d41e6f2d24820e8
Diff style: patch stat
diff --git a/web/js/components/domain.js b/web/js/components/domain.js
index f021525..7a15aca 100644
--- a/web/js/components/domain.js
+++ b/web/js/components/domain.js
@@ -3,12 +3,12 @@ Domain
 
 Code for representing domains
 *******************************************************************************/
-function Domain(id, title, image, imageBrightness, subDomains, topics) {
+function Domain(id, title, link, image, imageBrightness, subDomains, topics) {
 	this.id = id; // id of domain
 	this.title = title; // title of domain
+	this.link = link; // URL of location where someone can show expertise of domain
 	this.image = image; // image illustrating domain
 	this.imageBrightness = imageBrightness; // is the descriptive image dark or light
-	this.link = null; // URL of location where someone can show expertise of domain
 	this.subDomains = subDomains;
 	this.expertiseTopics = topics;
 	this.node = null;  // html of thumbnail
@@ -26,21 +26,10 @@ Domain.prototype.init = function() {
 				  'src':this.image})
 	);
 
-	this.setLink();
 	this.setTitleColor();
 	this.setClickEvent();
 }
 
-Domain.prototype.setLink = function() {
-	if (this.subDomains.length > 0) {
-		this.link = "domain.html?domain=" + this.id;
-	} else if (this.expertiseTopics != null) {
-		this.link = "expertise.html";
-	} else {
-		this.link = "results.html";
-	}
-}
-
 Domain.prototype.setTitleColor = function() {
 	if(this.imageBrightness === "dark")
 		$(this.node).find("#domainTxt" + this.id).css('color', '#fff');
diff --git a/web/js/domain.js b/web/js/domain.js
index b6d0ad6..a0eed60 100644
--- a/web/js/domain.js
+++ b/web/js/domain.js
@@ -105,13 +105,7 @@ function addDomain(row, locale, pageLabels, rootDomain) {
 		.then(function(domainLabel) {
 			var topics = null;
 			var subDomains, domainLabel;
-
-			// set domain label for root domain if matched
-			if (rootDomain === domainData.domain) {
-				domainLabel = pageLabels.domainTxtAllObjects + domainLabel.textLabel;
-			} else {
-				domainLabel = domainLabel.textLabel;
-			}
+			var link = "results.html"; // go to results page by default
 
 			// see if there are subdomains
 			domainData.subDomains ?
@@ -128,10 +122,25 @@ function addDomain(row, locale, pageLabels, rootDomain) {
 				);
 			}
 
-			// domainData
+			if (rootDomain === domainData.domain) {
+				// set domain label for root domain if matched
+				domainLabel = pageLabels.domainTxtAllObjects + domainLabel.textLabel;
+			} else {
+				// set domain label and link for subdomain
+				domainLabel = domainLabel.textLabel;
+
+				if (subDomains.length > 0) {
+					link = "domain.html?domain=" + domainData.domain;
+				} else if (topics != null) {
+					link = "expertise.html";
+				}
+			}
+
+			// create domain object
 			var domain = new Domain (
 				domainData.domain,
 				domainLabel,
+				link,
 				domainData.image,
 				domainData.imageBrightness,
 				subDomains,