EBernhardson has uploaded a new change for review.

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

Change subject: Clean up a variety of jshint errors
......................................................................

Clean up a variety of jshint errors

Just a general style cleanup to begin passing a linting process.

Change-Id: I750513feb24050322c789633c32f61449e3ff3bb
---
M gui/gui.js
1 file changed, 122 insertions(+), 118 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikidata/query/rdf 
refs/changes/78/212478/1

diff --git a/gui/gui.js b/gui/gui.js
index 8d06bbe..ec81ebb 100644
--- a/gui/gui.js
+++ b/gui/gui.js
@@ -1,80 +1,75 @@
-var jQuery = $;
-var mediaWiki = {};
+window.mediaWiki = window.mediaWiki || {};
 
-$(function() {
-       var SERVICE = '/bigdata/namespace/wdq/sparql';
-
-       var SHORTURL = 'http://tinyurl.com/create.php?url=';
-
-       var NAMESPACE_SHORTCUTS = {
-               'Wikidata' : {
-                       'wikibase' : 'http://wikiba.se/ontology#',
-                       'wdata' : 
'http://wikidata.org/wiki/Special:EntityData/',
-                       'wd' : 'http://wikidata.org/entity/',
-                       'wdt' : 'http://wikidata.org/prop/direct/',
-                       'wds' : 'http://wikidata.org/entity/statement/',
-                       'p' : 'http://wikidata.org/prop/',
-                       'wdref' : 'http://wikidata.org/reference/',
-                       'wdv' : 'http://wikidata.org/value/',
-                       'ps' : 'http://wikidata.org/prop/statement/',
-                       'psv' : 'http://wikidata.org/prop/statement/value/',
-                       'pq' : 'http://wikidata.org/prop/qualifier/',
-                       'pqv' : 'http://wikidata.org/prop/qualifier/value/',
-                       'pr' : 'http://wikidata.org/prop/reference/',
-                       'prv' : 'http://wikidata.org/prop/reference/value/',
-                       'wdno' : 'http://wikidata.org/prop/novalue/'
+(function($, mw) {
+       var SERVICE = '/bigdata/namespace/wdq/sparql',
+               SHORTURL = 'http://tinyurl.com/create.php?url=',
+               NAMESPACE_SHORTCUTS = {
+                       'Wikidata' : {
+                               'wikibase' : 'http://wikiba.se/ontology#',
+                               'wdata' : 
'http://wikidata.org/wiki/Special:EntityData/',
+                               'wd' : 'http://wikidata.org/entity/',
+                               'wdt' : 'http://wikidata.org/prop/direct/',
+                               'wds' : 'http://wikidata.org/entity/statement/',
+                               'p' : 'http://wikidata.org/prop/',
+                               'wdref' : 'http://wikidata.org/reference/',
+                               'wdv' : 'http://wikidata.org/value/',
+                               'ps' : 'http://wikidata.org/prop/statement/',
+                               'psv' : 
'http://wikidata.org/prop/statement/value/',
+                               'pq' : 'http://wikidata.org/prop/qualifier/',
+                               'pqv' : 
'http://wikidata.org/prop/qualifier/value/',
+                               'pr' : 'http://wikidata.org/prop/reference/',
+                               'prv' : 
'http://wikidata.org/prop/reference/value/',
+                               'wdno' : 'http://wikidata.org/prop/novalue/'
+                       },
+                       'W3C' : {
+                               'rdf' : 
'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
+                               'rdfs' : 
'http://www.w3.org/2000/01/rdf-schema#',
+                               'owl' : 'http://www.w3.org/2002/07/owl#',
+                               'skos' : 'http://www.w3.org/2004/02/skos/core#',
+                               'xsd' : 'http://www.w3.org/2001/XMLSchema#'
+                       },
+                       'Social/Other' : {
+                               'schema' : 'http://schema.org/',
+                       },
+                       'Blazegraph' : {
+                               'bd' : 'http://www.bigdata.com/rdf#',
+                               'bds' : 'http://www.bigdata.com/rdf/search#',
+                               'gas' : 'http://www.bigdata.com/rdf/gas#',
+                               'hint' : 'http://www.bigdata.com/queryHints#'
+                       }
                },
-               'W3C' : {
-                       'rdf' : 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
-                       'rdfs' : 'http://www.w3.org/2000/01/rdf-schema#',
-                       'owl' : 'http://www.w3.org/2002/07/owl#',
-                       'skos' : 'http://www.w3.org/2004/02/skos/core#',
-                       'xsd' : 'http://www.w3.org/2001/XMLSchema#'
+               STANDARD_PREFIXES = [
+                               'PREFIX wd: <http://www.wikidata.org/entity/>',
+                               'PREFIX wdt: 
<http://www.wikidata.org/prop/direct/>',
+                               'PREFIX wikibase: <http://wikiba.se/ontology#>',
+                               'PREFIX p: <http://www.wikidata.org/prop/>',
+                               'PREFIX v: 
<http://www.wikidata.org/prop/statement/>',
+                               'PREFIX q: 
<http://www.wikidata.org/prop/qualifier/>',
+                               'PREFIX rdfs: 
<http://www.w3.org/2000/01/rdf-schema#>',
+               ].join( "\n" ),
+               QUERY_START = 0,
+               CODEMIRROR_DEFAULTS = {
+                               lineNumbers : true,
+                               matchBrackets : true,
+                               mode : "sparql",
                },
-               'Social/Other' : {
-                       'schema' : 'http://schema.org/',
-               },
-               'Blazegraph' : {
-                       'bd' : 'http://www.bigdata.com/rdf#',
-                       'bds' : 'http://www.bigdata.com/rdf/search#',
-                       'gas' : 'http://www.bigdata.com/rdf/gas#',
-                       'hint' : 'http://www.bigdata.com/queryHints#'
-               }
-       };
-
-       var STANDARD_PREFIXES = 'PREFIX wd: <http://www.wikidata.org/entity/>\n\
-PREFIX wdt: <http://www.wikidata.org/prop/direct/>\n\
-PREFIX wikibase: <http://wikiba.se/ontology#>\n\
-PREFIX p: <http://www.wikidata.org/prop/>\n\
-PREFIX v: <http://www.wikidata.org/prop/statement/>\n\
-PREFIX q: <http://www.wikidata.org/prop/qualifier/>\n\
-PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n\
-';
-
-       var QUERY_START = 0;
-
-       var CODEMIRROR_DEFAULTS = {
-               lineNumbers : true,
-               matchBrackets : true,
-               mode : "sparql",
-       };
-
-       var EDITOR = {};
-       var ERROR_LINE_MARKER = null;
-       var ERROR_CHARACTER_MARKER = null;
+               EDITOR = {},
+               ERROR_LINE_MARKER = null,
+               ERROR_CHARACTER_MARKER = null;
 
        function submitQuery(e) {
                e.preventDefault();
                EDITOR.save();
-               var query = $('#query-form').serialize();
-               var url = SERVICE + "?" + query;
-               var settings = {
-                       headers : {
-                               'Accept' : 'application/sparql-results+json'
-                       },
-                       success : showQueryResults,
-                       error : queryResultsError
-               };
+
+               var query = $('#query-form').serialize(),
+                       url = SERVICE + "?" + query,
+                       settings = {
+                               headers : {
+                                       'Accept' : 
'application/sparql-results+json'
+                               },
+                               success : showQueryResults,
+                               error : queryResultsError
+                       };
                $('#query-result').empty('');
                $('#query-result').hide();
                $('#total').hide();
@@ -86,37 +81,39 @@
        }
 
        function queryResultsError(jqXHR, textStatus, errorThrown) {
-               $('#query-error').show();
-               var message = 'ERROR: ';
+               var response,
+                       message = 'ERROR: ';
+
                if (jqXHR.status === 0) {
                        message += 'Could not contact server';
                } else {
-                       var response = $('<div>').append(jqXHR.responseText);
+                       response = $('<div>').append(jqXHR.responseText);
                        message += response.text();
                        highlightError(jqXHR.responseText);
                }
-               $('#query-error').text(message);
+               $('#query-error').text(message).show();
        }
 
        function showQueryResults(data) {
+               var results, thead, i, tr, j, binding, title,
+                       table = $('<table>').appendTo($('#query-result'));
                $('#query-error').hide();
                $('#query-result').show();
 
-               var table = $('<table>').appendTo($('#query-result'));
 
                if(typeof data.boolean != 'undefined') {
                        // ASK query
-               table.append('<tr><td>' + data.boolean + 
'</td></tr>').addClass('boolean');
-               return;
+                       table.append('<tr><td>' + data.boolean + 
'</td></tr>').addClass('boolean');
+                       return;
                }
 
-               var results = data.results.bindings.length;
+               results = data.results.bindings.length;
                $('#total-results').html(results);
                $('#query-time').html(Date.now() - QUERY_START);
                $('#total').show();
                $('#shorturl').attr("href", 
SHORTURL+encodeURIComponent(window.location));
 
-           var thead = $('<thead>').appendTo(table);
+               thead = $('<thead>').appendTo(table);
                tr = $('<tr>');
                for (i = 0; i < data.head.vars.length; i++) {
                        tr.append('<th>' + data.head.vars[i] + '</th>');
@@ -124,32 +121,32 @@
                thead.append(tr);
                table.append(thead);
 
-               for (var i = 0; i < results; i++) {
-                       var tr = $('<tr>');
-                       for (var j = 0; j < data.head.vars.length; j++) {
+               for (i = 0; i < results; i++) {
+                       tr = $('<tr>');
+                       for (j = 0; j < data.head.vars.length; j++) {
                                if (data.head.vars[j] in 
data.results.bindings[i]) {
-                                       var binding = 
data.results.bindings[i][data.head.vars[j]];
+                                       binding = 
data.results.bindings[i][data.head.vars[j]];
                                        text = binding.value;
                                        if (binding.type == 'uri') {
                                                text = abbreviate(text);
                                        }
                                        linkText = 
escapeHTML(text).replace(/\n/g, '<br>');
                                        if (binding.type == 'typed-literal') {
-                                               tdData = ' class="literal" 
data-datatype="'
-                                                               + 
binding.datatype + '"';
+                                               tdData = ' class="literal" 
data-datatype="' +
+                                                               
binding.datatype + '"';
                                        } else {
                                                if (binding.type == 'uri') {
-                                                       text = '<a href="' + 
binding.value + '">'
-                                                                       + 
linkText + '</a>';
+                                                       text = '<a href="' + 
binding.value + '">' +
+                                                                       
linkText + '</a>';
                                                        
if(binding.value.match(/http:\/\/www.wikidata.org\/entity\//)) {
                                                                text += '<a 
href="javascript:exploreURL(\'' + binding.value + '\')">*</a>';
                                                        }
                                                }
                                                tdData = ' class="' + 
binding.type + '"';
                                                if (binding['xml:lang']) {
-                                                       var title = text + "@" 
+ binding['xml:lang'];
-                                                       tdData += ' 
data-lang="' + binding['xml:lang']
-                                                                       + '" 
title="' + title + '"';
+                                                       title = text + "@" + 
binding['xml:lang'];
+                                                       tdData += ' 
data-lang="' + binding['xml:lang'] +
+                                                                       '" 
title="' + title + '"';
                                                }
                                        }
                                        tr.append('<td' + tdData + '>' + text + 
'</td>');
@@ -167,11 +164,12 @@
        }
 
        function abbreviate(uri) {
-               for ( var nsGroup in NAMESPACE_SHORTCUTS) {
-                       for ( var ns in NAMESPACE_SHORTCUTS[nsGroup]) {
+               var nsGroup, ns;
+
+               for ( nsGroup in NAMESPACE_SHORTCUTS) {
+                       for ( ns in NAMESPACE_SHORTCUTS[nsGroup]) {
                                if 
(uri.indexOf(NAMESPACE_SHORTCUTS[nsGroup][ns]) === 0) {
-                                       return 
uri.replace(NAMESPACE_SHORTCUTS[nsGroup][ns], ns
-                                                       + ':');
+                                       return 
uri.replace(NAMESPACE_SHORTCUTS[nsGroup][ns], ns + ':');
                                }
                        }
                }
@@ -184,25 +182,27 @@
        }
 
        function populateNamespaceShortcuts() {
+               var category, select, ns;
                // add namespaces to dropdowns
                $('.namespace-shortcuts').html('Namespace prefixes: ');
-               for ( var category in NAMESPACE_SHORTCUTS) {
-                       var select = $('<select><option>' + category + 
'</option></select>')
+               for ( category in NAMESPACE_SHORTCUTS) {
+                       select = $('<select><option>' + category + 
'</option></select>')
                                        .appendTo($('.namespace-shortcuts'));
-                       for ( var ns in NAMESPACE_SHORTCUTS[category]) {
-                               select.append('<option value="'
-                                               + 
NAMESPACE_SHORTCUTS[category][ns] + '">' + ns
-                                               + '</option>');
+                       for ( ns in NAMESPACE_SHORTCUTS[category]) {
+                               select.append('<option value="' +
+                                               
NAMESPACE_SHORTCUTS[category][ns] + '">' + ns +
+                                                '</option>');
                        }
                }
        }
 
        function selectNamespace() {
-               var uri = this.value;
-               var current = EDITOR.getValue();
+               var ns,
+                       uri = this.value,
+                       current = EDITOR.getValue();
 
                if (current.indexOf(uri) == -1) {
-                       var ns = $(this).find(':selected').text();
+                       ns = $(this).find(':selected').text();
                        EDITOR.setValue('prefix ' + ns + ': <' + uri + '>\n' + 
current);
                }
 
@@ -222,7 +222,7 @@
 
 
        function initQuery() {
-               if(window.location.hash != "") {
+               if(window.location.hash !== "") {
                        
EDITOR.setValue(decodeURIComponent(window.location.hash.substr(1)));
                        EDITOR.refresh();
                }
@@ -231,40 +231,42 @@
        function setupEditor() {
                EDITOR = CodeMirror.fromTextArea($('#query')[0], 
CODEMIRROR_DEFAULTS);
                EDITOR.on('change', function() {
-                     if(ERROR_LINE_MARKER) {
-                        ERROR_LINE_MARKER.clear();
-                        ERROR_CHARACTER_MARKER.clear();
-                     }
+                               if(ERROR_LINE_MARKER) {
+                                               ERROR_LINE_MARKER.clear();
+                                               ERROR_CHARACTER_MARKER.clear();
+                               }
                });
                EDITOR.addKeyMap({'Ctrl-Enter': submitQuery});
                EDITOR.focus();
        }
 
        function highlightError(description) {
-               var match = description.match(/line (\d+), column (\d+)/);
+               var line, character,
+                   match = description.match(/line (\d+), column (\d+)/);
                if(match) {
                        // highlight character at error position
-                       var line = match[1] - 1;
-                       var character = match[2] - 1;
+                       line = match[1] - 1;
+                       character = match[2] - 1;
                        ERROR_LINE_MARKER = EDITOR.doc.markText({line: line, 
ch: 0}, {line: line}, {className: 'error-line'});
                        ERROR_CHARACTER_MARKER = EDITOR.doc.markText({line: 
line, ch: character}, {line: line, ch: character + 1}, {className: 
'error-character'});
                }
        }
 
        window.exploreURL = function(url) {
-               var match = url.match(/http:\/\/www.wikidata.org\/entity\/(.+)/)
+               var id,
+                       match = 
url.match(/http:\/\/www.wikidata.org\/entity\/(.+)/);
                if(!match) {
                        return;
                }
                $('#hide-explorer').show();
                $('#show-explorer').hide();
-               var id = match[1];
-               mediaWiki.config = { get: function() {
+               id = match[1];
+               mw.config = { get: function() {
                        return id;
                }};
                $('html, body').animate({ scrollTop: $("#explore").offset().top 
}, 500);
-               EXPLORER($, mediaWiki, $("#explore"));
-       }
+               EXPLORER($, mw, $("#explore"));
+       };
 
        function hideExlorer(e) {
                e.preventDefault();
@@ -290,6 +292,8 @@
        }
 
 
-       startGUI();
-});
+       $(document).ready(function() {
+               startGUI();
+       });
+})(jQuery, mediaWiki);
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I750513feb24050322c789633c32f61449e3ff3bb
Gerrit-PatchSet: 1
Gerrit-Project: wikidata/query/rdf
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to