Move modules to their own directory
[gitphp.git] / js / modules / tooltip.snapshot.js
blob:a/js/modules/tooltip.snapshot.js -> blob:b/js/modules/tooltip.snapshot.js
--- a/js/modules/tooltip.snapshot.js
+++ b/js/modules/tooltip.snapshot.js
@@ -9,18 +9,26 @@
  * @subpackage Javascript
  */
 
-define(["jquery", "ext/jquery.qtip.min"],
-	function($) {
+define(["jquery", 'modules/snapshotformats'],
+	function($, formats) {
 		
 		function buildTipContent(href) {
-			var content = '<div>' + GITPHP_RES_SNAPSHOT + ': ';
+			var content = '<div>' + GitPHP.Resources.Snapshot + ': ';
 			var first = true;
-			for (var type in GITPHP_SNAPSHOT_FORMATS) {
-				if (!first) {
-					content += ' | ';
+			var cleanurl = href.indexOf('/snapshot') != -1;
+			for (var type in formats) {
+				if (formats.hasOwnProperty(type)) {
+					if (!first) {
+						content += ' | ';
+					}
+					if (cleanurl) {
+						var newhref = href.replace("/snapshot", "/" + type);
+						content += '<a href="' + newhref + '">' + formats[type] + '</a>';
+					} else {
+						content += '<a href="' + href + '&fmt=' + type + '">' + formats[type] + '</a>';
+					}
+					first = false;
 				}
-				content += '<a href="' + href + '&fmt=' + type + '">' + GITPHP_SNAPSHOT_FORMATS[type] + '</a>';
-				first = false;
 			}
 			content += '</div>';
 			return content;
@@ -39,25 +47,27 @@
 					delay: 150
 				},
 				style: {
-					classes: 'ui-tooltip-light ui-tooltip-shadow'
+					classes: 'ui-tooltip-gitphp ui-tooltip-light ui-tooltip-shadow'
 				},
 				position: {
-					adjust: {
-						screen: true
-					}
+					viewport: $(window)
 				}
 			}
 		}
 
 		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; });
+					});
+				});
+			}
 		}
 	}
 );

comments