Skip to content

Instantly share code, notes, and snippets.

@aeakett
Created March 15, 2010 14:26
Show Gist options
  • Save aeakett/332874 to your computer and use it in GitHub Desktop.
Save aeakett/332874 to your computer and use it in GitHub Desktop.
<!--
* Complex Citation Generator
* Lives at: http://brighsworkshop.tumblr.com/post/399209671/complex-citation-template-generator
* Code revisions at: http://gist.github.com/332874
-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button#addRow").click(function(event){
$(".row:last").after("<div class='row'><input type='text' size='30' /><input type='text' size='30' /><input type='text' size='1' /><input type='text' size='1' /></div>");
});
$("button#generate").click(function(event){
var citation="<includeonly>{{Cite article\n| author = ";
$("div.row").each(function(){
if ($(this).children().first().val()!=$("div.row").last().children().first().val()) {
citation=citation+"{{#ifexpr: {{{1}}}<";
citation=citation+parseInt(parseInt($(this).children().first().next().next().next().val())+1);
citation=citation+" | ";
citation=citation+$(this).children().first().next().val();
citation=citation+" |\n";
}
else {
citation=citation+$(this).children().first().next().val();
}
});
$("div.row").each(function(){
if ($(this).children().first().val()!=$("div.row").last().children().first().val()) {
citation=citation+"}}";
}
});
citation=citation+"\n";
citation=citation+"| year = ";
citation=citation+$("#year").val();
citation=citation+"\n| article = ";
$("div.row").each(function(){
if ($(this).children().first().val()!=$("div.row").last().children().first().val()) {
citation=citation+"{{#ifexpr: {{{1}}}<";
citation=citation+parseInt(parseInt($(this).children().first().next().next().next().val())+1);
citation=citation+" | ";
citation=citation+$(this).children().first().val();
citation=citation+" |\n";
}
else {
citation=citation+$(this).children().first().val();
}
});
$("div.row").each(function(){
if ($(this).children().first().val()!=$("div.row").last().children().first().val()) {
citation=citation+"}}";
}
});
citation=citation+"\n";
citation=citation+"| title = [[";
citation=citation+$("#publicationTitle").val();
citation=citation+"]]\n";
citation=citation+"| publisher = [[";
citation=citation+$("#publisher").val();
citation=citation+"]]\n";
citation=citation+"| ISBN = ";
citation=citation+$("#isbn").val();
citation=citation+"\n";
citation=citation+"| pages = {{{1}}}\n";
citation=citation+"| display = {{#if: {{{2|}}} | {{{2}}} | }}\n";
citation=citation+"}}< /includeonly><noinclude>{{Esoteric}}\n\n";
$("div.row").each(function(){
citation=citation+"{{Cite book/";
citation=citation+$("#publicationTitle").val();
citation=citation+"|";
citation=citation+$(this).children().first().next().next().val();
citation=citation+"|";
citation=citation+$(this).children().first().next().next().val();
citation=citation+"-";
citation=citation+$(this).children().first().next().next().next().val();
citation=citation+"}}\n\n";
});
citation=citation+"[[Category:Citation templates|";
citation=citation+$("#publicationTitle").val();
citation=citation+"]]</noinclude>";
$("#stuffgoeshere").val(citation).toggle();
});
});
</script>
<label for="publicationTitle">Title</label><br /><input type="text" id="publicationTitle" size="50" /><br /><br />
<label>Articles</label><br />
<table border="1">
<tr>
<td width="290" align="left" valign="bottom">Title</td>
<td width="250" align="left" valign="bottom">Author(s)</td>
<td align="center">Start<br />Page</td>
<td align="center">End<br />Page</td>
</tr>
</table>
<div class="row"><input type="text" size="30" /><input type="text" size="30" /><input type="text" size="1" /><input type="text" size="1" /></div>
<button id="addRow">Add an article</button><br />
<label for="publisher">Publisher</label><br /><input type="text" id="publisher" size="50" value="Paizo Publishing, LLC" /><br />
<label for="year">Year</label><br /><input type="text" id="year" size="50" /><br />
<label for="isbn">ISBN</label><br /><input type="text" id="isbn" size="50" /><br />
<button id="generate">Generate Template</button><br>
<textarea id="stuffgoeshere" cols="100" rows="30" style="display:none;"></textarea>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment