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 Aug 4, 2021
1 parent 357baee commit 1a1ed42
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
24 changes: 24 additions & 0 deletions scholia/app/static/scholia.js
Original file line number Diff line number Diff line change
Expand Up @@ -931,3 +931,27 @@ 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)
}
}
}
28 changes: 3 additions & 25 deletions scholia/app/templates/404_doi.html
Original file line number Diff line number Diff line change
@@ -1,30 +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 = encodeURIComponent(
output.replaceAll('\t', '|')
.replaceAll('\n', '||'))
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
8 changes: 7 additions & 1 deletion scholia/app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
"#{{ panel }}-table", "{{ aspect }}_{{ panel }}.sparql" );
{%- endmacro %}

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




{% block metas %}
<meta charset="UTF-8">
Expand Down Expand Up @@ -84,7 +90,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 1a1ed42

Please sign in to comment.