Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made citations easier to copy #37

Merged
merged 2 commits into from
Mar 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ctn_waterloo/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,12 @@ h6 {
padding: 10px;
}

/* Citation modal popup stuff */

.tab-content > .tab-pane {
cursor: pointer;
}

/* make list.js pagination like bootstrap pagination */

.pagination ul>li:first-child>.page>a, .pagination ul>li:first-child>.page>span {
Expand Down
52 changes: 52 additions & 0 deletions ctn_waterloo/static/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Miscellaneous JavaScript used on multiple pages

/**
* Selects the text in a div so the user can easily copy it to the clipboard.
* @param {Object} div
*/
function selectdiv(div) {
var doc = document;
var text = doc.getElementById(div)
var range;

if (doc.body.createTextRange) {
range = doc.body.createTextRange();
range.moveToElementText(text);
range.select();
} else if (window.getSelection) {
var selection = window.getSelection();
range = doc.createRange();
range.selectNodeContents(text);
selection.removeAllRanges();
selection.addRange(range);
}
}

/**
* Shows the modal with the given citekey, and switches to the given tab.
* @param {string} citekey
* @param {string} tab
*/
function showmodaltab(citekey, tab) {
var m = $("#" + citekey + "cite");
var t = m.find('a[href="#' + citekey + tab + '"]');
m.modal('show');
t.tab('show');
}

// Don't reload the page when clicking on an anchor link
(function($) {
$('a[href="#"]').click(function(e) {
e.preventDefault();
});
})(jQuery);

// Hook up all the tooltips
(function($) {
$('[data-tooltip]').tooltip();
})(jQuery);

// Use $ for inline math
MathJax.Hub.Config({
"tex2jax": { inlineMath: [ [ '$', '$' ] ] }
});
55 changes: 36 additions & 19 deletions ctn_waterloo/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,31 @@
</a>
</span>
{%- endmacro -%}
{% macro citation_box(pub, class="modal hide fade") -%}
<div id="{{ pub.citekey }}cite" class="{{ class }}" tabindex="-1" role="dialog" aria-labelledby="Cite this paper" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h3 id="title">Cite "{{ pub.title }}"</h3>
</div>
<div class="modal-body">
<ul class="nav nav-tabs" id="cite">
<li class="active"><a href="#{{ pub.citekey }}pt" data-toggle="tab">Plain text</a></li>
<li><a href="#{{ pub.citekey }}bt" data-toggle="tab">BibTeX</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="{{ pub.citekey }}pt" onclick="selectdiv('{{ pub.citekey }}pt')">
<p>{{ pub.cite_plain }}</p>
</div>
<div class="tab-pane" id="{{ pub.citekey }}bt" onclick="selectdiv('{{ pub.citekey }}bt')">
<p><pre>{{ pub.cite_bibtex }}</pre></p>
</div>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>
</div>
{%- endmacro -%}
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
Expand All @@ -21,11 +46,16 @@

<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
<link type="text/plain" rel="author" href="/humans.txt">

<!-- CSS -->
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.no-icons.min.css" rel="stylesheet">
<link href="http://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic" rel="stylesheet" type="text/css">
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">

<!-- Fonts -->
<link href="//fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic" rel="stylesheet" type="text/css">

<!-- Load modernizr here (other JavaScript at the bottom of the page -->
<script src="//cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
</head>
<body{% block bodytags %}{% endblock bodytags %}>
Expand Down Expand Up @@ -101,26 +131,13 @@
</div>
</footer>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
<script type="text/javascript">
(function($) {
$('a[href="#"]').click(function(e) {
e.preventDefault();
});
})(jQuery);
(function($) {
$('[data-tooltip]').tooltip();
})(jQuery);
</script>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript">
MathJax.Hub.Config({
"tex2jax": { inlineMath: [ [ '$', '$' ] ] }
});
</script>
<!-- JavaScript -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
<script type="text/javascript" src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script src="{{ url_for('static', filename='js/list.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/list.paging.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/main.js') }}"></script>
{% block extrajs %}{% endblock extrajs %}
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
Expand Down
24 changes: 1 addition & 23 deletions ctn_waterloo/templates/publications_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,7 @@ <h1>Publications</h1>
</div>
{% endif -%}
</div>
<div id="{{ pub.citekey }}cite" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="Cite this paper" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h3>Cite {{ pub.title }}</h3>
</div>
<div class="modal-body">
<ul class="nav nav-tabs" id="cite">
<li class="active"><a href="#{{ pub.citekey }}pt" data-toggle="tab">Plain text</a></li>
<li><a href="#{{ pub.citekey }}bt" data-toggle="tab">BibTeX</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="{{ pub.citekey }}pt">
<p>{{ pub.cite_plain }}</p>
</div>
<div class="tab-pane" id="{{ pub.citekey }}bt">
<p><pre>{{ pub.cite_bibtex }}</pre></p>
</div>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>
</div>
{{ citation_box(pub) }}
</li>{% endfor %}
</ul>
</div>
Expand Down
39 changes: 11 additions & 28 deletions ctn_waterloo/templates/publications_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h3>Supplementary information</h3>
{{ publication }}
{% endif -%}
</div>
<div class="span4">
<div class="span3">
<h4>{{ publication.type }}</h4>
<dl>
{% for key, val in publication.cite_info.iteritems() %}
Expand All @@ -51,33 +51,16 @@ <h4>{{ publication.type }}</h4>
{% endfor %}
</dl>
<h4>Cite</h4>
<div class="accordion" id="citation">
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#citation" href="#plaintext">
Plain text
</a>
</div>
<div id="plaintext" class="accordion-body collapse">
<div class="accordion-inner">
<p>{{ publication.cite_plain }}</p>
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#citation" href="#bibtex">
BibTeX
</a>
</div>
<div id="bibtex" class="accordion-body collapse">
<div class="accordion-inner">
<p><pre>{{ publication.cite_bibtex }}</pre></p>
</div>
</div>
</div>
</div>
{{ github(publication, extension="bib", spanclass="rightcol-link") }}
<p>
<a href="#{{ publication.citekey }}cite" onclick="showmodaltab('{{ publication.citekey }}', 'pt');">Plain text</a>
</p>
<p>
<a href="#{{ publication.citekey }}cite" onclick="showmodaltab('{{ publication.citekey }}', 'bt');">BibTeX</a>
</p>
<p>
{{ github(publication, extension="bib", spanclass="rightcol-link") }}
</p>
</div>
</div>
{{ citation_box(publication) }}
{% endblock main %}