Sophivorus has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/317741

Change subject: General debugging
......................................................................

General debugging

Also some code pretification.

Change-Id: I886588d935cedaa82ed605cbd98d3685f3bbcf16
---
M proveit.js
1 file changed, 22 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikipedia/gadgets/ProveIt 
refs/changes/41/317741/1

diff --git a/proveit.js b/proveit.js
index 7042f01..85f83ab 100755
--- a/proveit.js
+++ b/proveit.js
@@ -681,11 +681,14 @@
                 *
                 * @return {string} full template name
                 */
-               this.getTemplateName = function () {
-                       var formattedNamespaces = mw.config.get( 
'wgFormattedNamespaces' ),
-                               templateNamespace = formattedNamespaces[10];
-                               templateName = templateNamespace + ':' + 
this.template;
-                       return templateName;
+               this.getTemplateTitle = function () {
+                       var templateTitle = '';
+                       if ( this.template ) {
+                               var formattedNamespaces = mw.config.get( 
'wgFormattedNamespaces' ),
+                                       templateNamespace = 
formattedNamespaces[10];
+                               templateTitle = templateNamespace + ':' + 
this.template;
+                       }
+                       return templateTitle;
                };
 
                /**
@@ -694,8 +697,11 @@
                 * @return {object}
                 */
                this.getTemplateData = function () {
-                       var templateName = this.getTemplateName();
-                               templateData = proveit.templateData[ 
templateName ]
+                       var templateData = {},
+                               templateTitle = this.getTemplateTitle();
+                       if ( templateTitle in proveit.templateData ) {
+                               templateData = proveit.templateData[ 
templateTitle ];
+                       }
                        return templateData;
                };
 
@@ -705,9 +711,12 @@
                 * @return {object} TemplateData of the registered parameters
                 */
                this.getRegisteredParams = function () {
-                       var templateData = this.getTemplateData(),
-                               paramsData = templateData.params;
-                       return paramsData;
+                       var registeredParams = {},
+                               templateData = this.getTemplateData();
+                       if ( 'params' in templateData ) {
+                               registeredParams = templateData.params;
+                       }
+                       return registeredParams;
                };
 
                /**
@@ -802,7 +811,7 @@
                this.getTemplateMap = function () {
                        var templateMap = {},
                                templateData = this.getTemplateData();
-                       if ( 'maps' in templateData && 'proveit' in 
templateData.maps ) {
+                       if ( templateData && 'maps' in templateData && 
'proveit' in templateData.maps ) {
                                templateMap = templateData.maps.proveit;
                        }
                        return templateMap;
@@ -921,8 +930,8 @@
                                templateOption = $( '<option>' ).text( 
templateName ).val( '' );
                        templateSelect.append( templateOption );
                        templateRow.append( templateLabel, templateSelect );
-                       for ( templateName in proveit.templateData ) {
-                               templateName = templateName.substr( 
templateName.indexOf( ':' ) + 1 ); // Remove the namespace
+                       for ( var templateTitle in proveit.templateData ) {
+                               templateName = templateTitle.substr( 
templateTitle.indexOf( ':' ) + 1 ); // Remove the namespace
                                templateOption = $( '<option>' ).text( 
templateName ).val( templateName );
                                if ( this.template === templateName ) {
                                        templateOption.attr( 'selected', 
'selected' );

-- 
To view, visit https://gerrit.wikimedia.org/r/317741
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I886588d935cedaa82ed605cbd98d3685f3bbcf16
Gerrit-PatchSet: 1
Gerrit-Project: wikipedia/gadgets/ProveIt
Gerrit-Branch: master
Gerrit-Owner: Sophivorus <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to