Sophivorus has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/361694 )

Change subject: Add button for running the Citoid script
......................................................................

Add button for running the Citoid script

Also various CSS changes

Change-Id: Ia76f29a79fb83c633eac9aa37d7fe03935d1dca0
---
M i18n/en.json
M i18n/es.json
M i18n/qqq.json
M proveit.css
M proveit.js
5 files changed, 66 insertions(+), 61 deletions(-)


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

diff --git a/i18n/en.json b/i18n/en.json
index 85804a7..8e06286 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -21,9 +21,10 @@
        "proveit-filter-references": "Filter references",
        "proveit-show-all-button": "Show all fields",
        "proveit-today-button": "Today",
-       "proveit-citoid-label": "Reference identifier",
+       "proveit-citoid-label": "Automatic reference",
        "proveit-citoid-tooltip": "Enter a URL, DOI, ISBN or PMC/PMID to try to 
extract the details automatically through the Citoid service",
        "proveit-citoid-placeholder": "URL, DOI, ISBN or PMC/PMID",
+       "proveit-citoid-load": "Load",
        "proveit-citoid-loading": "Loading...",
        "proveit-citoid-error": "Error"
 }
\ No newline at end of file
diff --git a/i18n/es.json b/i18n/es.json
index 132b2e2..7606ebb 100644
--- a/i18n/es.json
+++ b/i18n/es.json
@@ -23,9 +23,10 @@
        "proveit-filter-references": "Filtrar referencias",
        "proveit-show-all-button": "Mostrar todos los campos",
        "proveit-today-button": "Hoy",
-       "proveit-citoid-label": "Identificador de la referencia",
+       "proveit-citoid-label": "Referencia automática",
        "proveit-citoid-tooltip": "Ingresa una URL, DOI, ISBN or PMC/PMID para 
intentar extraer los detalles automáticamente a través del servicio Citoid",
        "proveit-citoid-placeholder": "URL, DOI, ISBN o PMC/PMID",
+       "proveit-citoid-load": "Cargar",
        "proveit-citoid-loading": "Cargando…",
        "proveit-citoid-error": "Error"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 54def56..cd37a24 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -24,9 +24,10 @@
        "proveit-filter-references": "Placeholder for the input field to filter 
references",
        "proveit-show-all-button": "Text for the button that shows all 
parameter fields",
        "proveit-today-button": "Text for the button that inserts the current 
date\n{{Identical|Today}}",
-       "proveit-citoid-label": "Reference identifier",
+       "proveit-citoid-label": "Label for the Citoid field",
        "proveit-citoid-tooltip": "Tooltip for the field that when filled with 
a reference identifier, triggers the Citoid service to automatically fill in 
the reference details",
        "proveit-citoid-placeholder": "Placeholder for the field that triggers 
the Citoid service",
+       "proveit-citoid-load": "Default text for the button that loads a 
reference out of a URI through the Citoid service",
        "proveit-citoid-loading": "Status text while Citoid service is loading 
the reference details",
        "proveit-citoid-error": "Generic error message when something went 
wrong with the Citoid service\n{{Identical|Error}}"
 }
diff --git a/proveit.css b/proveit.css
index acf6e5a..d68e7b2 100755
--- a/proveit.css
+++ b/proveit.css
@@ -31,22 +31,21 @@
 
 #proveit-list-tab,
 #proveit-add-tab {
-       color: black;
        cursor: pointer;
        display: inline-block;
-       outline: none;
-       padding: 15px;
+       border: 1px solid #ddd;
+       padding: 12px 30px;
+       margin-left: 5px;
+       position: relative;
+       top: 5px;
+       border-top-left-radius: 10px;
+       border-top-right-radius: 10px;
 }
 
 #proveit-list-tab.active,
 #proveit-add-tab.active {
-       background: #ccc;
-}
-
-#proveit-list-tab:not(.active):hover,
-#proveit-add-tab:not(.active):hover {
-       display: inline-block;
-       background: #eee;
+       background: #f4f4f4;
+       border-bottom-color: #f4f4f4;
 }
 
 #proveit-content {
@@ -146,24 +145,12 @@
        resize: vertical;
 }
 
-#proveit-reference-form .today-button {
-       background: none;
-       border: none;
+#proveit-reference-table button {
        cursor: pointer;
        font: inherit;
-       padding: .4em;
        position: absolute;
-       right: 0;
-}
-
-#proveit-reference-form .today-button:hover {
-       text-decoration: underline;
-}
-
-#proveit-reference-form .citoid-message {
-       padding: .4em;
-       position: absolute;
-       right: 0;
+       top: 4px;
+       right: 4px;
 }
 
 #proveit-footer {
@@ -222,12 +209,12 @@
  * http://www.webdesignerdepot.com/2012/11/how-to-create-a-simple-css3-tooltip/
  */
 
-label[data-tooltip] {
+#proveit [data-tooltip] {
     display: inline;
     position: relative;
 }
 
-label[data-tooltip]:hover:after {
+#proveit [data-tooltip]:hover:after {
     background: #333;
     background: rgba( 0, 0, 0, .8 );
     border-radius: 5px;
@@ -242,7 +229,7 @@
     width: 220px;
 }
 
-label[data-tooltip]:hover:before {
+#proveit [data-tooltip]:hover:before {
     border: solid;
     border-color: #333 transparent;
     border-width: 6px 6px 0 6px;
diff --git a/proveit.js b/proveit.js
index 4140082..15bfd3e 100755
--- a/proveit.js
+++ b/proveit.js
@@ -16,10 +16,13 @@
 var proveit = {
 
        /**
-        * URLs of the ProveIt icons hosted at Commons
+        * URL of the ProveIt icon hosted at Commons
         */
        ICON: 
'//upload.wikimedia.org/wikipedia/commons/thumb/1/19/ProveIt_logo_for_user_boxes.svg/22px-ProveIt_logo_for_user_boxes.svg.png',
 
+       /**
+        * URL of the ProveIt icon when the WikiEditor is disabled
+        */
        OLDICON: 
'//upload.wikimedia.org/wikipedia/commons/d/df/ProveitOldIcon.png',
 
        /**
@@ -38,6 +41,7 @@
 
        /**
         * Convenience method to get a ProveIt option
+        * These options are set on a per-wiki level when initializing ProveIt
         *
         * @param {string} option key without the "proveit-" prefix
         * @return {string} option value
@@ -50,7 +54,7 @@
         * Convenience method to get a ProveIt message
         *
         * @param {string} message key without the "proveit-" prefix
-        * @param {int} number of references
+        * @param {string} parameter passed to the message
         * @return {string} message value
         */
        getMessage: function ( key, param ) {
@@ -58,7 +62,7 @@
        },
 
        /**
-        * Convenience method to get the edit textbox
+        * Convenience method to get the MediaWiki edit textbox
         *
         * @return {jQuery} edit textbox
         */
@@ -76,20 +80,21 @@
                // Set the content language
                proveit.contentLanguage = mw.config.get( 'wgContentLanguage' );
 
-               // Set the interface language by getting the messages from 
Commons
+               // Get the interface messages from Commons
+               // Also get the English messages as fallback
                var userLanguage = mw.config.get( 'wgUserLanguage' );
                $.get( '//commons.wikimedia.org/w/api.php', {
-                       'titles': 'MediaWiki:Gadget-ProveIt-' + userLanguage + 
'.json|MediaWiki:Gadget-ProveIt-en.json', // Get the English messages as 
fallback
+                       'titles': 'MediaWiki:Gadget-ProveIt-' + userLanguage + 
'.json|MediaWiki:Gadget-ProveIt-en.json',
                        'action': 'query',
                        'prop': 'revisions',
                        'rvprop': 'content',
                        'format': 'json',
                        'origin': '*' // Allow requests from any origin so that 
ProveIt can be used on localhost and non-Wikimedia sites
                }).done( function ( data ) {
-                       // The Commons page for English messages has the lowest 
page id so it will always be first in the loop
                        //console.log( data );
                        var messages = {},
                                content;
+                       // The Commons page for English messages has the lowest 
page id so it will always be first in the loop
                        for ( var page in data.query.pages ) {
                                if ( page > -1 ) {
                                        page = data.query.pages[ page ];
@@ -856,7 +861,9 @@
                this.parseTemplateString = function () {
                        // Remove the outer braces and split by pipe, knowing 
that we may match pipes inside links and subtemplates
                        var paramArray = this.templateString.substring( 2, 
this.templateString.length - 2 ).split( '|' );
-                       paramArray.shift(); // Get rid of the template name
+
+                       // Get rid of the template name
+                       paramArray.shift();
 
                        var paramString, linkLevel = 0, subtemplateLevel = 0, 
indexOfEqual, paramNumber = 0, paramName, paramValue;
                        for ( var i = 0; i < paramArray.length; i++ ) {
@@ -943,7 +950,7 @@
                };
 
                /**
-                * Convert this reference to a list item
+                * Convert this reference to a list item for the reference list
                 *
                 * @return {jQuery} list item
                 */
@@ -1061,43 +1068,51 @@
                                var citoidLabel = proveit.getMessage( 
'citoid-label' ),
                                        citoidTooltip = proveit.getMessage( 
'citoid-tooltip' ),
                                        citoidPlaceholder = proveit.getMessage( 
'citoid-placeholder' ),
-                                       citoidMessage = $( '<span>' ).addClass( 
'citoid-message' );
+                                       citoidButton = $( '<button>' ).text( 
proveit.getMessage( 'citoid-load' ) );
                                label = $( '<label>' ).text( citoidLabel 
).attr( 'data-tooltip', citoidTooltip );
                                input = $( '<input>' ).attr( 'placeholder', 
citoidPlaceholder );
                                labelColumn = $( '<td>' ).append( label );
-                               inputColumn = $( '<td>' ).append( 
citoidMessage, input );
+                               inputColumn = $( '<td>' ).append( citoidButton, 
input );
                                row = $( '<tr>' ).append( labelColumn, 
inputColumn );
                                table.append( row );
 
-                               // When the reference identifier changes, try 
to extract the reference data automatically via the Citoid service
-                               input.change( this, function ( event ) {
-                                       citoidMessage.text( proveit.getMessage( 
'citoid-loading' ) );
+                               // When the Citoid button is clicked, try to 
extract the reference data automatically via the Citoid service
+                               citoidButton.click( this, function ( event ) {
+                                       var URI = input.val();
+                                       if ( !URI ) {
+                                               return; // Do nothing
+                                       }
 
-                                       var URI = $( this ).val(),
-                                               encodedURI = 
encodeURIComponent( URI );
-                                       $.get( '//' + proveit.contentLanguage + 
'.wikipedia.org/api/rest_v1/data/citation/mediawiki/' + encodedURI ).done( 
function ( data ) {
-                                               if ( typeof data === 'array' || 
typeof data[0] === 'object' ) {
+                                       citoidButton.text( proveit.getMessage( 
'citoid-loading' ) );
+
+                                       $.get( '//' + proveit.contentLanguage + 
'.wikipedia.org/api/rest_v1/data/citation/mediawiki/' + encodeURIComponent( URI 
) ).done( function ( data ) {
+                                               if ( data instanceof Array || 
typeof data[0] === 'object' ) {
                                                        var citoidData = 
data[0],
                                                                reference = 
event.data;
+
+                                                       // Helper function
+                                                       function setParamPair( 
paramName, paramValue ) {
+                                                               if ( typeof 
paramName === 'string' && typeof paramValue === 'string' && paramName in 
templateData.params ) {
+                                                                       
reference.paramPairs[ paramName ] = paramValue;
+                                                               } else if ( 
paramName instanceof Array && paramValue instanceof Array ) {
+                                                                       for ( 
var i = 0; i < paramName.length; i++ ) {
+                                                                               
setParamPair( paramName[ i ], paramValue[ i ] );
+                                                                       }
+                                                               }
+                                                       }
                                                        for ( var citoidKey in 
citoidData ) {
                                                                paramName = 
citoidMap[ citoidKey ];
                                                                paramValue = 
citoidData[ citoidKey ];
-                                                               function 
setParamPair( paramName, paramValue ) {
-                                                                       if ( 
typeof paramName === 'string' && typeof paramValue === 'string' && paramName in 
templateData.params ) {
-                                                                               
reference.paramPairs[ paramName ] = paramValue;
-                                                                       } else 
if ( paramName instanceof Array && paramValue instanceof Array ) {
-                                                                               
for ( var i = 0; i < paramName.length; i++ ) {
-                                                                               
        setParamPair( paramName[ i ], paramValue[ i ] );
-                                                                               
}
-                                                                       }
-                                                               }
                                                                setParamPair( 
paramName, paramValue );
                                                        }
                                                        $( 
'#proveit-reference-table' ).replaceWith( reference.toTable() );
-                                                       citoidMessage.empty();
+                                                       citoidButton.text( 
proveit.getMessage( 'citoid-load' ) );
                                                }
                                        }).error( function () {
-                                               citoidMessage.text( 
proveit.getMessage( 'citoid-error' ) );
+                                               citoidButton.text( 
proveit.getMessage( 'citoid-error' ) );
+                                               setTimeout( function () {
+                                                       citoidButton.text( 
proveit.getMessage( 'citoid-load' ) );
+                                               }, 3000 );
                                        });
                                });
                        }
@@ -1152,7 +1167,7 @@
 
                                // If the parameter is a date, add the Today 
button
                                if ( paramData.type === 'date' ) {
-                                       todayButton = $( '<button>' ).addClass( 
'today-button' ).text( proveit.getMessage( 'today-button' ) ).click( 
paramValueInput, function ( event ) {
+                                       todayButton = $( '<button>' ).text( 
proveit.getMessage( 'today-button' ) ).click( paramValueInput, function ( event 
) {
                                                var paramValueInput = 
event.data,
                                                        date = new Date(),
                                                        yyyy = 
date.getFullYear(),
@@ -1184,7 +1199,7 @@
                        }
 
                        // Finally, add any unregistered parameters left in 
paramPairs
-                       for ( paramName in paramPairs ) {
+                       for ( var paramName in paramPairs ) {
                                paramValue = paramPairs[ paramName ];
                                paramNameInput = $( '<input>' ).addClass( 
'proveit-param-name' ).val( paramName );
                                paramValueInput = $( '<input>' ).addClass( 
'proveit-param-value' ).val( paramValue );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia76f29a79fb83c633eac9aa37d7fe03935d1dca0
Gerrit-PatchSet: 1
Gerrit-Project: wikipedia/gadgets/ProveIt
Gerrit-Branch: master
Gerrit-Owner: Sophivorus <scheno...@gmail.com>

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

Reply via email to