Pass snapshot formats as requirejs config rather than globally
Pass snapshot formats as requirejs config rather than globally

--- /dev/null
+++ b/js/modules/snapshotformats.js
@@ -1,1 +1,17 @@
+/*
+ * GitPHP snapshot formats
+ *
+ * Passes snapshot formats from config to other modules
+ * 
+ * @author Christopher Han <xiphux@gmail.com>
+ * @copyright Copyright (c) 2012 Christopher Han
+ * @package GitPHP
+ * @subpackage Javascript
+ */
 
+define(['module'],
+	function (module) {
+		return module.config().formats || null;
+	}
+);
+

--- a/js/modules/tooltip.snapshot.js
+++ b/js/modules/tooltip.snapshot.js
@@ -9,13 +9,12 @@
  * @subpackage Javascript
  */
 
-define(["jquery"],
-	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)) {

--- a/templates/jsconst.tpl
+++ b/templates/jsconst.tpl
@@ -19,10 +19,6 @@
 	NoMatchesFound: '{t escape=no}No matches found for "%1"{/t}'
 {rdelim};
 
-GitPHP.Snapshot = {ldelim}
-	Formats: {ldelim}{foreach from=$snapshotformats key=format item=extension name=formats}"{$format}": "{$extension}"{if !$smarty.foreach.formats.last},{/if}{/foreach}{rdelim}
-{rdelim}
-
 GitPHP.BaseUrl = '{$baseurl}/';
 {if $project}
 GitPHP.Project = '{$project->GetProject()}';

--- a/templates/main.tpl
+++ b/templates/main.tpl
@@ -48,6 +48,11 @@
 		],
 		d3: 'ext/d3.v2.min',
 		qtip: 'ext/jquery.qtip.min'
+	{rdelim},
+	config: {ldelim}
+		'modules/snapshotformats': {ldelim}
+			formats: {ldelim}{foreach from=$snapshotformats key=format item=extension name=formats}"{$format}": "{$extension}"{if !$smarty.foreach.formats.last},{/if}{/foreach}{rdelim}
+		{rdelim}
 	{rdelim}
     {rdelim};
     {block name=javascript}

comments