Skip to content

Commit

Permalink
Add wysiwyg to admin citations
Browse files Browse the repository at this point in the history
  • Loading branch information
dshorthouse committed Dec 20, 2016
1 parent d9631fb commit f24732b
Show file tree
Hide file tree
Showing 10 changed files with 2,229 additions and 19 deletions.
51 changes: 40 additions & 11 deletions public/javascript/simplemappr.admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var SimpleMapprAdmin = (function($, window, sm) {
api_list: $('#admin-api-list'),

init: function() {
this.loadWYSIWYG();
this.loadUserList();
this.bindTools();
this.loadCitationList();
Expand All @@ -59,6 +60,16 @@ var SimpleMapprAdmin = (function($, window, sm) {
return decodeURIComponent(results[1].replace(/\+/g, " "));
},

loadWYSIWYG: function() {
$.trumbowyg.svgPath = '/public/stylesheets/raw/icons.svg';
$('#citation-reference').trumbowyg({
removeformatPasted: true,
btns: [['bold', 'italic']],
autogrow: true,
semantic: false
});
},

loadUserList: function(object) {
var self = this,
obj = object || {},
Expand Down Expand Up @@ -122,19 +133,36 @@ var SimpleMapprAdmin = (function($, window, sm) {
});

$('#citation-doi').on('blur', function() {
var val = $(this).val();
var val = $(this).val(), citation = "", matches;
if(val.length > 0 && $('#citation-reference').val().length === 0) {
sm.showSpinner();
$.getJSON("http://search.crossref.org/dois?q=" + encodeURIComponent(val), function(data) {
if (data && data.length > 0) {
$.each(data[0], function(key, value) {
if(key === "fullCitation") {
$('#citation-reference').val(value);
}
if(key === "year") {
$('#citation-year').val(value);
}
});
$.ajax({
type: 'POST',
url: "https://doi.org/" + encodeURIComponent(val),
dataType: 'json',
beforeSend: function(xhr) {
xhr.setRequestHeader('Accept', 'application/vnd.citationstyles.csl+json;q=1.0');
},
success: function(data) {
$('#citation-surname').val(data.author[0].family);
$('#citation-year').val(data.issued["date-parts"][0][0]);
},
error: function() {
}
});
$.ajax({
type: 'POST',
url: "https://doi.org/" + encodeURIComponent(val),
dataType: 'text',
beforeSend: function(xhr) {
xhr.setRequestHeader('Accept', 'text/x-bibliography; style=american-journal-of-botany');
},
success: function(data) {
matches = data.match(/^(.*)(?:available at:)/i);
$("#citation-reference").val(matches[1].trim());
$(".trumbowyg-editor").text(matches[1].trim());
},
error: function() {
}
});
sm.hideSpinner();
Expand Down Expand Up @@ -233,6 +261,7 @@ var SimpleMapprAdmin = (function($, window, sm) {
success : function(data) {
if(data.status === "ok") {
$('#map-admin').find(".citation").val("");
$('#citation-reference').trumbowyg('empty');
$.each(["reference", "surname", "year"], function() {
$('#citation-'+this).removeClass('ui-state-error');
});
Expand Down
2 changes: 1 addition & 1 deletion public/javascript/simplemappr.js
Original file line number Diff line number Diff line change
Expand Up @@ -2603,7 +2603,7 @@ var SimpleMappr = (function($, window, document) {
},

bindTextAreaResizers: function() {
$.each([this.vars.fieldSetsPoints, this.vars.fieldSetsRegions, this.vars.fieldSetsWKT, '#map-admin'], function() {
$.each([this.vars.fieldSetsPoints, this.vars.fieldSetsRegions, this.vars.fieldSetsWKT], function() {
$(this).find('textarea.resizable:not(.textarea-processed)').TextAreaResizer();
});
},
Expand Down
Loading

0 comments on commit f24732b

Please sign in to comment.