zotero/chrome/content/zotero/bibliography.js

168 lines
5.8 KiB
JavaScript
Raw Normal View History

/*
***** BEGIN LICENSE BLOCK *****
2009-12-28 09:47:49 +00:00
Copyright © 2009 Center for History and New Media
George Mason University, Fairfax, Virginia, USA
http://zotero.org
2009-12-28 09:47:49 +00:00
This file is part of Zotero.
2009-12-28 09:47:49 +00:00
Zotero is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
2009-12-28 09:47:49 +00:00
Zotero is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
***** END LICENSE BLOCK *****
*/
//////////////////////////////////////////////////////////////////////////////
//
// Zotero_File_Interface_Bibliography
//
//////////////////////////////////////////////////////////////////////////////
// Class to provide options for bibliography
var Zotero_File_Interface_Bibliography = new function() {
2007-10-23 07:11:59 +00:00
var _io, _saveStyle;
this.init = init;
2007-10-23 07:11:59 +00:00
this.styleChanged = styleChanged;
this.acceptSelection = acceptSelection;
/*
* Initialize some variables and prepare event listeners for when chrome is done
* loading
*/
function init() {
2007-10-23 07:11:59 +00:00
// Set font size from pref
// Affects bibliography.xul and integrationDocPrefs.xul
Zotero.setFontSize(document.documentElement);
2007-10-23 07:11:59 +00:00
if(window.arguments && window.arguments.length) {
_io = window.arguments[0];
if(_io.wrappedJSObject) _io = _io.wrappedJSObject;
} else {
_io = {};
2007-10-23 07:11:59 +00:00
}
2007-10-23 07:11:59 +00:00
var listbox = document.getElementById("style-listbox");
var styles = Zotero.Styles.getVisible();
2007-10-23 07:11:59 +00:00
// if no style is set, get the last style used
if(!_io.style) {
_io.style = Zotero.Prefs.get("export.lastStyle");
_saveStyle = true;
}
// add styles to list
var index = 0;
var nStyles = styles.length;
var selectIndex = -1;
for(var i=0; i<nStyles; i++) {
2007-10-23 07:11:59 +00:00
var itemNode = document.createElement("listitem");
itemNode.setAttribute("value", styles[i].styleID);
itemNode.setAttribute("label", styles[i].title);
listbox.appendChild(itemNode);
if(styles[i].styleID == _io.style) {
selectIndex = index;
}
index++;
}
if (selectIndex < 1) {
selectIndex = 0;
}
// Has to be async to work properly
setTimeout(function () {
listbox.ensureIndexIsVisible(selectIndex);
listbox.selectedIndex = selectIndex;
});
2007-10-23 07:11:59 +00:00
// ONLY FOR bibliography.xul: export options
if(document.getElementById("save-as-rtf")) {
// restore saved bibliographic settings
document.getElementById('output-radio').selectedItem =
document.getElementById(Zotero.Prefs.get("export.bibliographySettings"));
}
2007-10-23 07:11:59 +00:00
// ONLY FOR integrationDocPrefs.xul: update status of displayAs, set
// bookmarks text
if(document.getElementById("displayAs")) {
if(_io.useEndnotes && _io.useEndnotes == 1) document.getElementById("displayAs").selectedIndex = 1;
styleChanged(selectIndex);
}
if(document.getElementById("formatUsing")) {
if(_io.fieldType == "Bookmark") document.getElementById("formatUsing").selectedIndex = 1;
var formatOption = (_io.primaryFieldType == "ReferenceMark" ? "referenceMarks" : "fields");
2007-10-23 07:11:59 +00:00
document.getElementById("fields").label = Zotero.getString("integration."+formatOption+".label");
document.getElementById("fields-caption").textContent = Zotero.getString("integration."+formatOption+".caption");
document.getElementById("fields-file-format-notice").textContent = Zotero.getString("integration."+formatOption+".fileFormatNotice");
document.getElementById("bookmarks-file-format-notice").textContent = Zotero.getString("integration.fields.fileFormatNotice");
2007-10-23 07:11:59 +00:00
}
2009-08-25 07:02:24 +00:00
// set style to false, in case this is cancelled
_io.style = false;
2007-10-23 07:11:59 +00:00
}
/*
* ONLY FOR integrationDocPrefs.xul: called when style is changed
*/
function styleChanged(index) {
// When called from init(), selectedItem isn't yet set
if (index != undefined) {
var selectedItem = document.getElementById("style-listbox").getItemAtIndex(index);
}
else {
var selectedItem = document.getElementById("style-listbox").selectedItem;
}
var selectedStyle = selectedItem.getAttribute('value');
// update status of displayAs box based on style class
if(document.getElementById("displayAs")) {
var isNote = Zotero.Styles.get(selectedStyle).class == "note";
document.getElementById("displayAs").disabled = !isNote;
}
// update status of formatUsing box based on style class
if(document.getElementById("formatUsing")) {
if(isNote) document.getElementById("formatUsing").selectedIndex = 0;
document.getElementById("bookmarks").disabled = isNote;
document.getElementById("bookmarks-caption").disabled = isNote;
}
}
function acceptSelection() {
// collect code
2007-10-23 07:11:59 +00:00
_io.style = document.getElementById("style-listbox").selectedItem.value;
if(document.getElementById("output-radio")) {
2007-10-23 07:11:59 +00:00
// collect settings
_io.output = document.getElementById("output-radio").selectedItem.id;
2007-10-23 07:11:59 +00:00
// save settings
Zotero.Prefs.set("export.bibliographySettings", _io.output);
}
// ONLY FOR integrationDocPrefs.xul: collect displayAs
if(document.getElementById("displayAs")) {
_io.useEndnotes = document.getElementById("displayAs").selectedIndex;
_io.fieldType = (document.getElementById("formatUsing").selectedIndex == 0 ? _io.primaryFieldType : _io.secondaryFieldType);
2007-10-23 07:11:59 +00:00
}
// save style (this happens only for "Export Bibliography," or Word
// integration when no bibliography style was previously selected)
if(_saveStyle) {
Zotero.Prefs.set("export.lastStyle", _io.style);
}
}
}