Use namespace object instead of global variables for javascript resources
[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,19 +9,24 @@
  * @subpackage Javascript
  */
 
-define(["jquery", "ext/jquery.qtip.min"],
-	function($) {
+define(["jquery", 'modules/snapshotformats'],
+	function($, formats) {
 		
 		function buildTipContent(href) {
 			var content = '<div>' + GitPHP.Resources.Snapshot + ': ';
 			var first = true;
-			var formats = GitPHP.Snapshot.Formats
+			var cleanurl = href.indexOf('/snapshot') != -1;
 			for (var type in formats) {
 				if (formats.hasOwnProperty(type)) {
 					if (!first) {
 						content += ' | ';
 					}
-					content += '<a href="' + href + '&fmt=' + type + '">' + formats[type] + '</a>';
+					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;
 				}
 			}
@@ -42,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