Pass resource strings as requirejs config rather than globally
Pass resource strings as requirejs config rather than globally

--- a/js/modules/blameasync.js
+++ b/js/modules/blameasync.js
@@ -9,8 +9,8 @@
  * @subpackage Javascript
  */
 
-define(["jquery", "modules/geturl", "modules/tooltip.commit"],
-	function($, getUrl, tooltipCommit) {
+define(["jquery", "modules/geturl", "modules/tooltip.commit", 'modules/resources'],
+	function($, getUrl, tooltipCommit, resources) {
 
 		var blobTable = null;
 		var blameLink = null;
@@ -22,7 +22,7 @@
 			col.css('display', 'none');
 
 			var p = $(document.createElement('p'));
-			p.text(GitPHP.Resources.LoadingBlameData);
+			p.text(resources.LoadingBlameData);
 			p.appendTo(col);
 
 			var div = $(document.createElement('div'));
@@ -30,7 +30,7 @@
 
 			var img = $(document.createElement('img'));
 			img.attr('src', getUrl() + 'images/blame-loader.gif');
-			img.attr('alt', GitPHP.Resources.Loading);
+			img.attr('alt', resources.Loading);
 			img.appendTo(div);
 
 			div.appendTo(col);

--- a/js/modules/projectsearch.js
+++ b/js/modules/projectsearch.js
@@ -9,8 +9,8 @@
  * @subpackage Javascript
  */
 
-define(["jquery"],
-	function($) {
+define(["jquery", 'modules/resources'],
+	function($, resources) {
 
 		var table = null;
 		var searchPanel = null;
@@ -84,7 +84,7 @@
 					msgContainer.appendTo(table);
 				}
 
-				var msg = GitPHP.Resources.NoMatchesFound.replace(new RegExp('%1'), searchString);
+				var msg = resources.NoMatchesFound.replace(new RegExp('%1'), searchString);
 				msgContainer.text(msg);
 
 				msgContainer.show();

--- /dev/null
+++ b/js/modules/resources.js
@@ -1,1 +1,17 @@
+/*
+ * GitPHP resources
+ *
+ * Passes resource strings 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().resources;
+	}
+);
+

--- a/js/modules/tooltip.commit.js
+++ b/js/modules/tooltip.commit.js
@@ -9,8 +9,8 @@
  * @subpackage Javascript
  */
 
-define(["jquery", "modules/geturl", "modules/getproject"],
-	function($, getUrl, getProject) {
+define(["jquery", "modules/geturl", "modules/getproject", 'modules/resources'],
+	function($, getUrl, getProject, resources) {
 
 		var url = null;
 		var project = null;
@@ -26,7 +26,7 @@
 		function buildTipConfig(hash) {
 			return {
 				content: {
-					text: '<img src="' + url + 'images/tooltip-loader.gif" alt="' + GitPHP.Resources.Loading + '" />',
+					text: '<img src="' + url + 'images/tooltip-loader.gif" alt="' + resources.Loading + '" />',
 					ajax: {
 						url: url,
 						data: {

--- a/js/modules/tooltip.snapshot.js
+++ b/js/modules/tooltip.snapshot.js
@@ -9,11 +9,11 @@
  * @subpackage Javascript
  */
 
-define(["jquery", 'modules/snapshotformats'],
-	function($, formats) {
+define(["jquery", 'modules/snapshotformats', 'modules/resources'],
+	function($, formats, resources) {
 		
 		function buildTipContent(href) {
-			var content = '<div>' + GitPHP.Resources.Snapshot + ': ';
+			var content = '<div>' + resources.Snapshot + ': ';
 			var first = true;
 			var cleanurl = href.indexOf('/snapshot') != -1;
 			for (var type in formats) {

--- a/js/modules/tooltip.tag.js
+++ b/js/modules/tooltip.tag.js
@@ -9,8 +9,8 @@
  * @subpackage Javascript
  */
 
-define(["jquery", "modules/geturl", "modules/getproject"],
-	function($, getUrl, getProject) {
+define(["jquery", "modules/geturl", "modules/getproject", 'modules/resources'],
+	function($, getUrl, getProject, resources) {
 
 		var url = null;
 		var project = null;
@@ -26,7 +26,7 @@
 		function buildTipConfig(tag) {
 			return {
 				content: {
-					text: '<img src="' + url + 'images/tooltip-loader.gif" alt="' + GitPHP.Resources.Loading + '" />',
+					text: '<img src="' + url + 'images/tooltip-loader.gif" alt="' + resources.Loading + '" />',
 					ajax: {
 						url: url,
 						data: {

--- a/js/modules/treedrilldown.js
+++ b/js/modules/treedrilldown.js
@@ -9,8 +9,8 @@
  * @subpackage Javascript
  */
 
-define(["jquery", "modules/geturl"],
-	function($, getUrl) {
+define(["jquery", "modules/geturl", 'modules/resources'],
+	function($, getUrl, resources) {
 
 		var collapsed = '[+]';
 		var expanded = '[–]';
@@ -65,7 +65,7 @@
 
 			var img = $(document.createElement('img'));
 			img.attr('src', url + "images/tree-loader.gif");
-			img.attr('alt', GitPHP.Resources.Loading);
+			img.attr('alt', resources.Loading);
 			img.addClass('treeSpinner');
 			parentRow.find('a.treeLink').after(img);
 

file:a/templates/jsconst.tpl (deleted)
--- a/templates/jsconst.tpl
+++ /dev/null
@@ -1,23 +1,1 @@
-{*
- * JSConst
- *
- * Javascript constants template
- *
- * @author Christopher Han <xiphux@gmail.com>
- * @copyright Copyright (c) 2011 Christopher Han
- * @package GitPHP
- * @subpackage Template
- *}
-<script type="text/javascript">
 
-var GitPHP = GitPHP || {ldelim}{rdelim};
-
-GitPHP.Resources = {ldelim}
-	Loading: "{t escape='js'}Loading…{/t}",
-	LoadingBlameData: "{t escape='js'}Loading blame data…{/t}",
-	Snapshot: "{t escape='js'}snapshot{/t}",
-	NoMatchesFound: '{t escape=no}No matches found for "%1"{/t}'
-{rdelim};
-
-</script>
-

--- a/templates/main.tpl
+++ b/templates/main.tpl
@@ -35,7 +35,6 @@
     {block name=css}
     {/block}
     {if $javascript}
-    {include file='jsconst.tpl'}
     <script type="text/javascript">
     var require = {ldelim}
     	baseUrl: '{$baseurl}/js',
@@ -60,6 +59,14 @@
 		{/if}
 		'modules/geturl': {ldelim}
 			baseurl: '{$baseurl}/'
+		{rdelim},
+		'modules/resources': {ldelim}
+			resources: {ldelim}
+				Loading: "{t escape='js'}Loading…{/t}",
+				LoadingBlameData: "{t escape='js'}Loading blame data…{/t}",
+				Snapshot: "{t escape='js'}snapshot{/t}",
+				NoMatchesFound: '{t escape=no}No matches found for "%1"{/t}'
+			{rdelim}
 		{rdelim}
 	{rdelim}
     {rdelim};

comments