Adjust dynamic requires to minify more code and lazy load qtip
Adjust dynamic requires to minify more code and lazy load qtip

--- a/js/commitdiff.js
+++ b/js/commitdiff.js
@@ -9,18 +9,12 @@
  * @subpackage Javascript
  */
 
-define(["jquery", "common"], function($) {
+define(["jquery", "modules/sidebysidecommitdiff", "common"], function($, sbsDiff) {
 	$(function(){
 		var toc = $('div.commitDiffSBS div.SBSTOC');
 		var content = $('div.SBSContent');
 		if ((toc.size() > 0) && (content.size() > 0)) {
-			require(["jquery", "modules/sidebysidecommitdiff"],
-				function($, sbsDiff) {
-					$(function() {
-						sbsDiff.init(toc, content);
-					});
-				}
-			);
+			sbsDiff.init(toc, content);
 		}
 	});
 });

--- a/js/common.js
+++ b/js/common.js
@@ -9,24 +9,16 @@
  * @subpackage Javascript
  */
 
-define(["jquery", "modules/getproject", "modules/lang", "modules/tooltip.snapshot"],
-	function($, getProject, lang, tooltipSnapshot) {
+define(["jquery", "modules/getproject", "modules/lang", "modules/tooltip.snapshot", "modules/tooltip.commit", "modules/tooltip.tag"],
+	function($, getProject, lang, tooltipSnapshot, tooltipCommit, tooltipTag) {
 		$(function() {
 			lang($('div.lang_select'));
 			tooltipSnapshot($('a.snapshotTip'));
 		});
 
 		if (getProject()) {
-
-			require(["jquery", "modules/tooltip.commit", "modules/tooltip.tag"],
-				function($, tooltipCommit, tooltipTag) {
-					$(function() {
-						tooltipCommit($('a.commitTip'));
-						tooltipTag($('a.tagTip'));
-					});
-				}
-			);
-
+			tooltipCommit($('a.commitTip'));
+			tooltipTag($('a.tagTip'));
 		}
 	}
 );

--- a/js/modules/tooltip.commit.js
+++ b/js/modules/tooltip.commit.js
@@ -9,7 +9,7 @@
  * @subpackage Javascript
  */
 
-define(["jquery", "modules/geturl", "modules/getproject", "qtip"],
+define(["jquery", "modules/geturl", "modules/getproject"],
 	function($, getUrl, getProject) {
 
 		var url = null;
@@ -48,17 +48,23 @@
 		}
 
 		return function(elements) {
-			url = getUrl();
-			project = getProject();
-			elements.each(function(){
-				var jThis = $(this);
-				var hash = getCommitHash(jThis);
-				if (!hash) {
-					return;
-				}
-				var config = buildTipConfig(hash);
-				jThis.qtip(config);
-			});
+			
+			if (elements && (elements.size() > 0)) {
+				url = getUrl();
+				project = getProject();
+
+				require(['qtip'], function() {
+					elements.each(function(){
+						var jThis = $(this);
+						var hash = getCommitHash(jThis);
+						if (!hash) {
+							return;
+						}
+						var config = buildTipConfig(hash);
+						jThis.qtip(config);
+					});
+				});
+			}
 		}
 	}
 );

--- a/js/modules/tooltip.snapshot.js
+++ b/js/modules/tooltip.snapshot.js
@@ -9,7 +9,7 @@
  * @subpackage Javascript
  */
 
-define(["jquery", "qtip"],
+define(["jquery"],
 	function($) {
 		
 		function buildTipContent(href) {
@@ -57,14 +57,18 @@
 		}
 
 		return function(elements) {
-			elements.each(function(){
-				var jThis = $(this);
-				var href = jThis.attr('href');
-				var content = buildTipContent(href);
-				var config = buildTipConfig(content);
-				jThis.qtip(config);
-				jThis.click(function() { return false; });
-			});
+			if (elements && (elements.size() > 0)) {
+				require(['qtip'], function() {
+					elements.each(function(){
+						var jThis = $(this);
+						var href = jThis.attr('href');
+						var content = buildTipContent(href);
+						var config = buildTipConfig(content);
+						jThis.qtip(config);
+						jThis.click(function() { return false; });
+					});
+				});
+			}
 		}
 	}
 );

--- a/js/modules/tooltip.tag.js
+++ b/js/modules/tooltip.tag.js
@@ -9,7 +9,7 @@
  * @subpackage Javascript
  */
 
-define(["jquery", "modules/geturl", "modules/getproject", "qtip"],
+define(["jquery", "modules/geturl", "modules/getproject"],
 	function($, getUrl, getProject) {
 
 		var url = null;
@@ -48,17 +48,24 @@
 		}
 
 		return function(elements) {
-			url = getUrl();
-			project = getProject();
-			elements.each(function(){
-				var jThis = $(this);
-				var tag = getTagName(jThis);
-				if (!tag) {
-					return;
-				}
-				var config = buildTipConfig(tag);
-				jThis.qtip(config);
-			});
+
+			if (elements && (elements.size() > 0)) {
+
+				url = getUrl();
+				project = getProject();
+
+				require(['qtip'], function() {
+					elements.each(function(){
+						var jThis = $(this);
+						var tag = getTagName(jThis);
+						if (!tag) {
+							return;
+						}
+						var config = buildTipConfig(tag);
+						jThis.qtip(config);
+					});
+				});
+			}
 		}
 	}
 );

comments