Skip to content

Commit

Permalink
extract js code from 404_doi.html
Browse files Browse the repository at this point in the history
the js code is now implemented as a macro
  • Loading branch information
curibe committed Jul 22, 2021
1 parent a663191 commit e9fb46f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
24 changes: 24 additions & 0 deletions scholia/app/static/scholia.js
Original file line number Diff line number Diff line change
Expand Up @@ -672,4 +672,28 @@ function searchTerm(placeholder) {
});


}

function quickStatement404DOI(doi, element) {
const c = require('citation-js')

try {
let example = new c.Cite([doi])
let output = example.format('quickstatements')
$( element ).append( output );
output = encodeURI(
output.replaceAll('\t', '|')
.replaceAll('\n', '||'))
.replaceAll('/','%2F')
htmlOutput = "<a href=\"https://quickstatements.toolforge.org/#/v1=" + output + "\">\n" +
" <button class=\"btn btn-primary\">Submit to Quickstatements ↗</button>\n" +
"</a>\n"
$( element ).after( htmlOutput );
} catch (error) {
if (error.message.includes("status code 404")) {
$( element ).append( "DOI does not exist" )
} else {
console.log(error)
}
}
}
29 changes: 3 additions & 26 deletions scholia/app/templates/404_doi.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,8 @@
{% extends "base.html" %}

{% block scripts %}
{{super()}}

<script src="{{ url_for('static', filename='js/citation.js') }}"></script>
<script>
const c = require('citation-js')
try {
let example = new c.Cite([ '{{ doi }}' ])
let output = example.format('quickstatements')
$( '#qs' ).append( output );
output = encodeURI(
output.replaceAll('\t', '|')
.replaceAll('\n', '||'))
.replaceAll('/','%2F')
htmlOutput = "<a href=\"https://quickstatements.toolforge.org/#/v1=" + output + "\">\n" +
" <button class=\"btn btn-primary\">Submit to Quickstatements ↗</button>\n" +
"</a>\n"
$( '#qs' ).after( htmlOutput );
} catch (error) {
if (error.message.includes("status code 404")) {
$( '#qs' ).append( "DOI does not exist" )
} else {
console.log(error)
}
}
</script>
{% block in_ready %}

{{ quick_statement( doi ,'qs') }}

{% endblock %}

Expand Down
7 changes: 6 additions & 1 deletion scholia/app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
"#{{ panel }}-iframe", "{{ aspect }}_{{ panel }}.sparql");
{%- endmacro %}

{% macro quick_statement(doi, element) -%}
quickStatement404DOI( "{{ doi }}" ,"#{{ element }}")
{%- endmacro %}



{% block head %}
{{super()}}
Expand All @@ -49,7 +54,7 @@
<script type="text/javascript" src="{{ url_for('static', filename='scholia.js') }}"></script>
<link href="{{ url_for('static', filename='widgets/select2/css/select2.min.css') }}" rel="stylesheet" />
<script type="text/javascript" src="{{ url_for('static', filename='widgets/select2/js/select2.min.js')}}"></script>

<script src="{{ url_for('static', filename='js/citation.js') }}"></script>
<script type="text/javascript">

{% if q %}
Expand Down

0 comments on commit e9fb46f

Please sign in to comment.