Skip to content

Commit

Permalink
Resolved merge conflicts; html positioning of the field should be cor…
Browse files Browse the repository at this point in the history
…rect
  • Loading branch information
CAYdenberg committed Jul 19, 2014
2 parents 60d6298 + 826d9f4 commit 30da3d8
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 87 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ORCID WordPress Plugin
=====

This is a WordPress plugin that displays ORCIDs in comments and posts.
This is a WordPress plugin that displays ORCIDs in comments and posts. The ORCID for post authors can be entered as a user option, and the ORCID for commentors is optionally entered in the Wordpress comments form.

TODO:

Expand Down
Binary file added assets/orcid-waiting.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion assets/orcid.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
padding-bottom: 5px;
}

#orcid-success, #orcid-failure {
.orcid-icon {
display: none;
}

#orcid-instructions {
font-style: italic;
font-size: 0.9em;
}

.form-table td:first-child {
text-align: right;
vertical-align: top;
Expand Down
48 changes: 43 additions & 5 deletions assets/orcid.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,68 @@
jQuery(document).ready(function() {
var orcid = Orcid();
//check ORCID number on form submission
jQuery('.comment-form').submit(orcid.validateForm);
//bind event handlers to the textbox itself
//should work for both comments form and User form in admin panel
jQuery('#orcid').blur(orcid.validateId);
})


function Orcid() {
var $ = jQuery;
var that = Object();

//validate form
that.validateForm = function(e) {
return that.validateId();
}

//validate the ORCID number entered by the user.
//First by the sturcture of the input and then by checking in with ORCID API
that.validateId = function(e) {
var inputString = $('#orcid').val();
var id = $('#orcid').val();
//this Regex could be improved to check whole string.
//Right now just checks for illegal characters
var orcidRegex = new RegExp("[^A-Za-z0-9\-\:\/\.]");
var illegalChar = orcidRegex.test(inputString);
if (!illegalChar) {
$('#orcid-failure').hide();
$('#orcid-success').show();
//valid so far. Now check with ORCID API
that.showIcon( $('#orcid-waiting') );
that.checkOrcidAPI(inputString);
return true;
} else {
$('#orcid-failure').show();
$('#orcid-success').hide();
//not a valid string. Show user the fail icon.
that.showIcon( $('#orcid-failure') );
$('#orcid-instructions').html('e.g. 0000-0002-7299-680X');
return false;
}
}

//method for contacting the ORCID API. On success, shows the success icon and
//gives the user their credit name (so they can confirm).
//On error (number is not valid or ORCID cannot be contacted) shows the fail icon.
that.checkOrcidAPI = function(number) {
$.ajax({
method: 'get',
url: 'http://pub.orcid.org/' + number,
dataType: 'xml',
success: function(response) {
that.showIcon( $('#orcid-success') );
//find users name from XML response
var name = $(response).find('credit-name')[0].innerHTML;
$('#orcid-instructions').html('You are: ' + name);
},
error: function() {
that.showIcon( $('#orcid-failure') );
$('#orcid-instructions').html('Your ORCID profile could not be found');
}
})
}

//Shows an icon (passed in as a jQuery object.) Hides all the other icons.
that.showIcon = function(icon) {
$('.orcid-icon').hide();
$(icon).show();
}
return that;
}
Loading

0 comments on commit 30da3d8

Please sign in to comment.