183 lines
7 KiB
XML
183 lines
7 KiB
XML
<?xml version="1.0"?>
|
|
<!--
|
|
***** BEGIN LICENSE BLOCK *****
|
|
|
|
Copyright (c) 2006 Center for History and New Media
|
|
George Mason University, Fairfax, Virginia, USA
|
|
http://chnm.gmu.edu
|
|
|
|
Licensed under the Educational Community License, Version 1.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.opensource.org/licenses/ecl1.php
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
|
|
***** END LICENSE BLOCK *****
|
|
-->
|
|
<?xml-stylesheet href="chrome://global/skin/global.css"?>
|
|
<?xml-stylesheet href="chrome://zotero/skin/zotero.css" type="text/css"?>
|
|
|
|
<window
|
|
id="csl-edit"
|
|
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
|
onload="Zotero_CSL_Editor.init();"
|
|
title="Zotero Reference Test pane">
|
|
|
|
<script src="chrome://zotero/content/include.js"/>
|
|
|
|
<script>
|
|
<![CDATA[
|
|
var Zotero_CSL_Editor = new function() {
|
|
var mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
|
.getInterface(Components.interfaces.nsIWebNavigation)
|
|
.QueryInterface(Components.interfaces.nsIDocShellTreeItem)
|
|
.rootTreeItem
|
|
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
|
.getInterface(Components.interfaces.nsIDOMWindow);
|
|
|
|
this.init = init;
|
|
this.handleKeyPress = handleKeyPress;
|
|
this.loadCSL = loadCSL;
|
|
this.generateBibliography = generateBibliography;
|
|
this.refresh = refresh;
|
|
|
|
function init() {
|
|
var cslList = document.getElementById('zotero-csl-list');
|
|
if (cslList.getAttribute('initialized') == 'true') {
|
|
return;
|
|
}
|
|
|
|
var csls = Zotero.DB.query("SELECT title, cslID FROM csl ORDER BY title");
|
|
for (var i=0; i<csls.length; i++) {
|
|
cslList.appendItem(csls[i].title, csls[i].cslID);
|
|
}
|
|
var pageList = document.getElementById('zotero-csl-page-type');
|
|
var locators = Zotero.CSL.Global.getLocatorStrings();
|
|
for each(var type in locators) {
|
|
var locator = type;
|
|
locator = locator[0].toUpperCase()+locator.substr(1);
|
|
pageList.appendItem(locator, type);
|
|
}
|
|
|
|
pageList.selectedIndex = 0;
|
|
cslList.setAttribute('initialized', true)
|
|
}
|
|
function refresh() {
|
|
var editor = document.getElementById('zotero-csl-editor')
|
|
generateBibliography(editor.value)
|
|
|
|
}
|
|
|
|
function handleKeyPress(event) {
|
|
if (event.keyCode == 9 &&
|
|
(!event.shiftKey && !event.metaKey && !event.altKey && !event.ctrlKey)) {
|
|
_insertText("\t");
|
|
event.preventDefault();
|
|
}
|
|
}
|
|
|
|
|
|
function loadCSL(cslID) {
|
|
var editor = document.getElementById('zotero-csl-editor')
|
|
editor.value = Zotero.DB.valueQuery("SELECT csl FROM csl WHERE cslID=?", cslID);
|
|
editor.doCommand();
|
|
document.getElementById('zotero-csl-list').value = cslID;
|
|
}
|
|
|
|
|
|
function generateBibliography(str) {
|
|
var iframe = document.getElementById('zotero-csl-preview-box');
|
|
|
|
var items = mainWindow.ZoteroPane.getSelectedItems();
|
|
if (items.length == 0) {
|
|
iframe.contentDocument.documentElement.innerHTML = '<html><head><title></title></head><body><p style="color: red">No references selected in Zotero.</p></body></html>';
|
|
return;
|
|
}
|
|
|
|
if (str.indexOf("<defaults") != -1) {
|
|
csl = new Zotero.CSL.Compat(str);
|
|
}
|
|
else {
|
|
csl = new Zotero.CSL(str);
|
|
}
|
|
|
|
var itemSet = csl.createItemSet(items);
|
|
|
|
// Generate multiple citations
|
|
var citation = csl.createCitation(itemSet.items);
|
|
// Generate single citations
|
|
var author = document.getElementById("preview-suppress-author").checked;
|
|
var search = document.getElementById('preview-pages');
|
|
var loc = document.getElementById('zotero-csl-page-type');
|
|
var pos = document.getElementById('zotero-ref-position').selectedItem.value;
|
|
var citations = '<h1>Single Citations</h1>';
|
|
for (var i=0; i<citation.citationItems.length; i++) {
|
|
citation.citationItems[i].suppressAuthor = author;
|
|
if (search.value != '') {
|
|
citation.citationItems[i].locator = search.value;
|
|
citation.citationItems[i].locatorType = loc.selectedItem.value;
|
|
}
|
|
citation.citationItems[i].position = pos;
|
|
citations += csl.formatCitation(csl.createCitation([citation.citationItems[i]]), "HTML") + '<br />';
|
|
}
|
|
var multCitations = '<hr><h1>Multi Citations</h1>' +
|
|
csl.formatCitation(citation, "HTML");
|
|
|
|
// Generate bibliography
|
|
var bibliography = '<hr/><h1>Bibliography</h1>' +
|
|
csl.formatBibliography(itemSet, "HTML");
|
|
iframe.contentDocument.documentElement.innerHTML =
|
|
citations +
|
|
multCitations + bibliography;
|
|
}
|
|
|
|
|
|
// From http://kb.mozillazine.org/Inserting_text_at_cursor
|
|
function _insertText(text) {
|
|
var command = "cmd_insertText";
|
|
var controller = document.commandDispatcher.getControllerForCommand(command);
|
|
if (controller && controller.isCommandEnabled(command)) {
|
|
controller = controller.QueryInterface(Components.interfaces.nsICommandController);
|
|
var params = Components.classes["@mozilla.org/embedcomp/command-params;1"];
|
|
params = params.createInstance(Components.interfaces.nsICommandParams);
|
|
params.setStringValue("state_data", "\t");
|
|
controller.doCommandWithParams(command, params);
|
|
}
|
|
}
|
|
}
|
|
]]>
|
|
</script>
|
|
|
|
<vbox flex="1">
|
|
<hbox align="center">
|
|
<button id="preview-refresh-button" label="Refresh" oncommand="Zotero_CSL_Editor.refresh()"/>
|
|
<menulist id="zotero-csl-page-type" style="min-height: 1.6em; min-width: 50px" oncommand="Zotero_CSL_Editor.refresh()" />
|
|
<label value=":" />
|
|
<textbox size="5" id="preview-pages" type="timed" timeout="250" oncommand="Zotero_CSL_Editor.refresh()"/>
|
|
<checkbox oncommand="Zotero_CSL_Editor.refresh()" id="preview-suppress-author" label="Suppress author" />
|
|
<label value="Citation is:" />
|
|
<menulist id="zotero-ref-position" oncommand="Zotero_CSL_Editor.refresh()">
|
|
<menupopup>
|
|
<menuitem label="First" value="0"/>
|
|
<menuitem label="Subsequent" value="1"/>
|
|
<menuitem label="Ibid" value="2"/>
|
|
<menuitem label="Ibid+Locator" value="3"/>
|
|
</menupopup>
|
|
</menulist>
|
|
<menulist id="zotero-csl-list" style="min-height: 1.6em; min-width: 100px" initialized="false" flex="1" oncommand="Zotero_CSL_Editor.loadCSL(this.selectedItem.value)"/>
|
|
</hbox>
|
|
<textbox id="zotero-csl-editor" type="timed" timeout="250" multiline="true"
|
|
flex="1"
|
|
onkeypress="Zotero_CSL_Editor.handleKeyPress(event)"
|
|
oncommand="document.getElementById('zotero-csl-list').selectedIndex = -1; Zotero_CSL_Editor.generateBibliography(this.value)"/>
|
|
<splitter/>
|
|
<iframe id="zotero-csl-preview-box" flex="1" style="padding: 0 1em;background:white" overflow="auto"/>
|
|
</vbox>
|
|
|
|
</window>
|