Reorganize and improve locale drop-down code
This commit is contained in:
parent
06e6168cb4
commit
6ac0403049
|
@ -34,8 +34,7 @@
|
|||
|
||||
var Zotero_File_Interface_Bibliography = new function() {
|
||||
var _io, _saveStyle;
|
||||
var selectedLocale = "";
|
||||
var defaultStyleLocale = "";
|
||||
var lastSelectedLocale; // Only changes when explicitly selected
|
||||
|
||||
/*
|
||||
* Initialize some variables and prepare event listeners for when chrome is done
|
||||
|
@ -57,18 +56,18 @@ var Zotero_File_Interface_Bibliography = new function() {
|
|||
}
|
||||
|
||||
var listbox = document.getElementById("style-listbox");
|
||||
var styles = Zotero.Styles.getVisible();
|
||||
|
||||
// if no style is set, get the last style used
|
||||
// if no style is requested, get the last style used
|
||||
if(!_io.style) {
|
||||
_io.style = Zotero.Prefs.get("export.lastStyle");
|
||||
_saveStyle = true;
|
||||
}
|
||||
|
||||
// add styles to list
|
||||
var styles = Zotero.Styles.getVisible();
|
||||
var index = 0;
|
||||
var nStyles = styles.length;
|
||||
var selectIndex = -1;
|
||||
var selectIndex = null;
|
||||
for(var i=0; i<nStyles; i++) {
|
||||
var itemNode = document.createElement("listitem");
|
||||
itemNode.setAttribute("value", styles[i].styleID);
|
||||
|
@ -81,16 +80,23 @@ var Zotero_File_Interface_Bibliography = new function() {
|
|||
index++;
|
||||
}
|
||||
|
||||
if (selectIndex < 1) {
|
||||
let requestedLocale;
|
||||
if (selectIndex === null) {
|
||||
// Requested style not found in list, pre-select first style
|
||||
selectIndex = 0;
|
||||
} else {
|
||||
requestedLocale = _io.locale;
|
||||
}
|
||||
|
||||
let style = styles[selectIndex];
|
||||
lastSelectedLocale = Zotero.Prefs.get("export.lastLocale");
|
||||
if (requestedLocale && style && !style.locale) {
|
||||
// pre-select supplied locale
|
||||
lastSelectedLocale = requestedLocale;
|
||||
}
|
||||
|
||||
// add locales to list
|
||||
if(!_io.locale) {
|
||||
_io.locale = Zotero.Prefs.get("export.lastLocale");
|
||||
}
|
||||
var menulist = document.getElementById("locale-menu");
|
||||
selectedLocale = Zotero.Styles.populateLocaleList(menulist, _io.locale);
|
||||
Zotero.Styles.populateLocaleList(document.getElementById("locale-menu"));
|
||||
|
||||
// Has to be async to work properly
|
||||
window.setTimeout(function () {
|
||||
|
@ -161,7 +167,7 @@ var Zotero_File_Interface_Bibliography = new function() {
|
|||
* Called when locale is changed
|
||||
*/
|
||||
this.localeChanged = function (selectedValue) {
|
||||
selectedLocale = selectedValue;
|
||||
lastSelectedLocale = selectedValue;
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -219,39 +225,17 @@ var Zotero_File_Interface_Bibliography = new function() {
|
|||
* Update locale menulist when style is changed
|
||||
*/
|
||||
function updateLocaleMenu(selectedStyle) {
|
||||
// For styles with a default-locale, disable locale menulist and show locale
|
||||
var menulist = document.getElementById("locale-menu");
|
||||
|
||||
// If not null, then menulist is extended with the default-locale value
|
||||
// of the previously selected style
|
||||
if (defaultStyleLocale) {
|
||||
// Reset menulist
|
||||
menulist.removeItemAt(0);
|
||||
defaultStyleLocale = "";
|
||||
}
|
||||
|
||||
if (selectedStyle.locale) {
|
||||
defaultStyleLocale = selectedStyle.locale;
|
||||
|
||||
//add default-locale to menulist
|
||||
let localeLabel = defaultStyleLocale;
|
||||
if (Zotero.Styles.locales[defaultStyleLocale] !== undefined) {
|
||||
localeLabel = Zotero.Styles.locales[defaultStyleLocale];
|
||||
}
|
||||
|
||||
menulist.insertItemAt(0, localeLabel, defaultStyleLocale);
|
||||
menulist.selectedIndex = 0;
|
||||
menulist.disabled = true;
|
||||
} else {
|
||||
menulist.value = selectedLocale;
|
||||
menulist.disabled = false;
|
||||
}
|
||||
Zotero.Styles.updateLocaleList(
|
||||
document.getElementById("locale-menu"),
|
||||
selectedStyle,
|
||||
lastSelectedLocale
|
||||
);
|
||||
}
|
||||
|
||||
this.acceptSelection = function () {
|
||||
// collect code
|
||||
_io.style = document.getElementById("style-listbox").selectedItem.value;
|
||||
_io.locale = document.getElementById("locale-menu").selectedItem.value;
|
||||
_io.style = document.getElementById("style-listbox").value;
|
||||
_io.locale = document.getElementById("locale-menu").value;
|
||||
if(document.getElementById("output-method-radio")) {
|
||||
// collect settings
|
||||
_io.mode = document.getElementById("output-mode-radio").selectedItem.id;
|
||||
|
@ -280,6 +264,6 @@ var Zotero_File_Interface_Bibliography = new function() {
|
|||
}
|
||||
|
||||
// save locale
|
||||
Zotero.Prefs.set("export.lastLocale", selectedLocale);
|
||||
Zotero.Prefs.set("export.lastLocale", lastSelectedLocale);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -39,4 +39,4 @@
|
|||
</radiogroup>
|
||||
</groupbox>
|
||||
</vbox>
|
||||
</dialog>
|
||||
</dialog>
|
|
@ -428,7 +428,7 @@ var Zotero_File_Interface = new function() {
|
|||
getService(Components.interfaces.nsIClipboard);
|
||||
var style = Zotero.Styles.get(style);
|
||||
var cslEngine = style.getCiteProc(locale);
|
||||
|
||||
|
||||
// add HTML
|
||||
var bibliography = Zotero.Cite.makeFormattedBibliographyOrCitationList(cslEngine, items, "html", asCitations);
|
||||
var str = Components.classes["@mozilla.org/supports-string;1"].
|
||||
|
@ -524,7 +524,7 @@ var Zotero_File_Interface = new function() {
|
|||
// generate bibliography
|
||||
try {
|
||||
if(io.method == 'copy-to-clipboard') {
|
||||
copyItemsToClipboard(items, io.style, locale, false, io.mode === "citations");
|
||||
Zotero_File_Interface.copyItemsToClipboard(items, io.style, locale, false, io.mode === "citations");
|
||||
}
|
||||
else {
|
||||
var style = Zotero.Styles.get(io.style);
|
||||
|
|
|
@ -84,4 +84,4 @@
|
|||
<checkbox id="storeReferences" label="&zotero.integration.prefs.storeReferences.label;"/>
|
||||
<description class="radioDescription">&zotero.integration.prefs.storeReferences.caption;</description>
|
||||
</vbox>
|
||||
</dialog>
|
||||
</dialog>
|
|
@ -51,9 +51,10 @@ Zotero_Preferences.Export = {
|
|||
|
||||
// Initialize locale drop-down
|
||||
var localeMenulist = document.getElementById("zotero-quickCopy-locale-menu");
|
||||
this.populateQuickCopyLocaleList(localeMenulist);
|
||||
Zotero.Styles.populateLocaleList(localeMenulist);
|
||||
localeMenulist.setAttribute('preference', "pref-quickCopy-locale");
|
||||
|
||||
this._lastSelectedLocale = Zotero.Prefs.get("export.quickCopy.locale");
|
||||
this.updateQuickCopyUI();
|
||||
|
||||
if (!Zotero.isStandalone) {
|
||||
|
@ -151,37 +152,11 @@ Zotero_Preferences.Export = {
|
|||
checkbox.checked = contentType == 'html';
|
||||
checkbox.disabled = mode != 'bibliography';
|
||||
|
||||
var menulist = document.getElementById('zotero-quickCopy-locale-menu');
|
||||
var menulistLabel = document.getElementById('zotero-quickCopy-locale-menu-label');
|
||||
|
||||
var lastSelectedLocale = menulist.value;
|
||||
var localeLabel = "";
|
||||
if (menulist.disabled === true) {
|
||||
menulist.removeItemAt(0);
|
||||
}
|
||||
|
||||
if (mode == 'bibliography') {
|
||||
var defaultStyleLocale = Zotero.Styles.get(format).locale;
|
||||
if (defaultStyleLocale) {
|
||||
if (Zotero.Styles.locales[defaultStyleLocale] !== undefined) {
|
||||
localeLabel = Zotero.Styles.locales[defaultStyleLocale];
|
||||
} else {
|
||||
localeLabel = defaultStyleLocale;
|
||||
}
|
||||
}
|
||||
menulistLabel.disabled = false;
|
||||
} else {
|
||||
menulistLabel.disabled = true;
|
||||
}
|
||||
|
||||
if (mode == 'bibliography' && !defaultStyleLocale) {
|
||||
menulist.value = lastSelectedLocale;
|
||||
menulist.disabled = false;
|
||||
} else {
|
||||
menulist.insertItemAt(0, localeLabel, lastSelectedLocale);
|
||||
menulist.selectedIndex = 0;
|
||||
menulist.disabled = true;
|
||||
}
|
||||
Zotero.Styles.updateLocaleList(
|
||||
document.getElementById('zotero-quickCopy-locale-menu'),
|
||||
mode == 'bibliography' ? Zotero.Styles.get(format) : null,
|
||||
this._lastSelectedLocale
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -204,7 +179,7 @@ Zotero_Preferences.Export = {
|
|||
var treechildren = document.getElementById('quickCopy-siteSettings-rows');
|
||||
|
||||
var formattedName = document.getElementById('zotero-quickCopy-menu').label;
|
||||
var locale = document.getElementById('zotero-quickCopy-locale-menu').value;
|
||||
var locale = this._lastSelectedLocale;
|
||||
var asHTML = document.getElementById('zotero-quickCopy-copyAsHTML').checked;
|
||||
|
||||
if (index !== undefined && index > -1 && index < treechildren.childNodes.length) {
|
||||
|
@ -261,7 +236,7 @@ Zotero_Preferences.Export = {
|
|||
var domainCell = document.createElement('treecell');
|
||||
var formatCell = document.createElement('treecell');
|
||||
var localeCell = document.createElement('treecell');
|
||||
var HTMLCell = document.createElement('treecell');
|
||||
var htmlCell = document.createElement('treecell');
|
||||
|
||||
domainCell.setAttribute('label', siteData[i].domainPath);
|
||||
|
||||
|
@ -270,12 +245,12 @@ Zotero_Preferences.Export = {
|
|||
|
||||
var format = Zotero.QuickCopy.unserializeSetting(siteData[i].format);
|
||||
localeCell.setAttribute('label', format.locale);
|
||||
HTMLCell.setAttribute('label', format.contentType == 'html' ? ' ✓ ' : '');
|
||||
htmlCell.setAttribute('label', format.contentType == 'html' ? ' ✓ ' : '');
|
||||
|
||||
treerow.appendChild(domainCell);
|
||||
treerow.appendChild(formatCell);
|
||||
treerow.appendChild(localeCell);
|
||||
treerow.appendChild(HTMLCell);
|
||||
treerow.appendChild(htmlCell);
|
||||
treeitem.appendChild(treerow);
|
||||
treechildren.appendChild(treeitem);
|
||||
}
|
||||
|
@ -292,16 +267,6 @@ Zotero_Preferences.Export = {
|
|||
this.refreshQuickCopySiteList();
|
||||
},
|
||||
|
||||
/*
|
||||
* Builds the Quick Copy locale drop-down
|
||||
*/
|
||||
populateQuickCopyLocaleList: function (menulist, quickCopyLocale) {
|
||||
if (!quickCopyLocale) {
|
||||
quickCopyLocale = Zotero.Prefs.get("export.quickCopy.locale");
|
||||
}
|
||||
|
||||
Zotero.Styles.populateLocaleList(menulist, quickCopyLocale);
|
||||
},
|
||||
|
||||
updateQuickCopyInstructions: function () {
|
||||
var prefix = Zotero.isMac ? Zotero.getString('general.keys.cmdShift') : Zotero.getString('general.keys.ctrlShift');
|
||||
|
|
|
@ -23,7 +23,12 @@
|
|||
|
||||
***** END LICENSE BLOCK *****
|
||||
-->
|
||||
<!DOCTYPE prefwindow SYSTEM "chrome://zotero/locale/preferences.dtd">
|
||||
<!DOCTYPE window [
|
||||
<!ENTITY % prefWindow SYSTEM "chrome://zotero/locale/preferences.dtd">
|
||||
%prefWindow;
|
||||
<!ENTITY % common SYSTEM "chrome://zotero/locale/zotero.dtd">
|
||||
%common;
|
||||
]>
|
||||
|
||||
<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
<prefpane id="zotero-prefpane-export"
|
||||
|
@ -51,8 +56,8 @@
|
|||
<menulist id="zotero-quickCopy-menu"/>
|
||||
|
||||
<hbox align="center">
|
||||
<label id="zotero-quickCopy-locale-menu-label" value="&zotero.preferences.quickCopy.locale;" control="zotero-quickCopy-locale-menu"/>
|
||||
<menulist id="zotero-quickCopy-locale-menu"/>
|
||||
<label id="zotero-quickCopy-locale-menu-label" value="&zotero.bibliography.locale.label;" control="zotero-quickCopy-locale-menu"/>
|
||||
<menulist id="zotero-quickCopy-locale-menu" oncommand="Zotero_Preferences.Export._lastSelectedLocale = this.value"/>
|
||||
|
||||
<separator orient="vertical" width="15px"/>
|
||||
|
||||
|
|
|
@ -27,11 +27,18 @@
|
|||
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
|
||||
<?xml-stylesheet href="chrome://zotero/skin/preferences.css"?>
|
||||
|
||||
<!DOCTYPE window SYSTEM "chrome://zotero/locale/preferences.dtd">
|
||||
|
||||
<!DOCTYPE window [
|
||||
<!ENTITY % prefWindow SYSTEM "chrome://zotero/locale/preferences.dtd">
|
||||
%prefWindow;
|
||||
<!ENTITY % common SYSTEM "chrome://zotero/locale/zotero.dtd">
|
||||
%common;
|
||||
]>
|
||||
|
||||
<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
title="" buttons="cancel,accept"
|
||||
id="zotero-quickCopySiteEditor"
|
||||
onload="sizeToContent();"
|
||||
onload="Zotero_Preferences.Export.updateQuickCopyUI(); sizeToContent()"
|
||||
ondialogaccept="Zotero_QuickCopySiteEditor.onAccept();">
|
||||
|
||||
<script src="chrome://zotero/content/include.js"/>
|
||||
|
@ -48,11 +55,9 @@
|
|||
io.domain = document.getElementById('zotero-quickCopy-domain').value;
|
||||
io.format = document.getElementById('zotero-quickCopy-menu').value;
|
||||
|
||||
var menulist = document.getElementById('zotero-quickCopy-locale-menu');
|
||||
if (menulist.disabled === false) {
|
||||
io.locale = menulist.value;
|
||||
} else {
|
||||
io.locale = "";
|
||||
io.locale = '';
|
||||
if (!document.getElementById('zotero-quickCopy-locale-menu').disabled) {
|
||||
io.locale = document.getElementById('zotero-quickCopy-locale-menu').value;
|
||||
}
|
||||
|
||||
io.ok = true;
|
||||
|
@ -72,9 +77,9 @@
|
|||
|
||||
<separator class="thin"/>
|
||||
|
||||
<label id="zotero-quickCopy-locale-menu-label" value="&zotero.preferences.quickCopy.locale;" control="zotero-quickCopy-locale-menu"/>
|
||||
<label id="zotero-quickCopy-locale-menu-label" value="&zotero.preferences.quickCopy.siteEditor.locale;" control="zotero-quickCopy-locale-menu"/>
|
||||
<hbox align="center">
|
||||
<menulist id="zotero-quickCopy-locale-menu"/>
|
||||
<menulist id="zotero-quickCopy-locale-menu" oncommand="Zotero_Preferences.Export._lastSelectedLocale = this.value"/>
|
||||
</hbox>
|
||||
|
||||
<separator class="thin"/>
|
||||
|
@ -90,17 +95,16 @@
|
|||
var io = window.arguments[0];
|
||||
var contentType = io.asHTML ? 'html' : '';
|
||||
document.getElementById('zotero-quickCopy-domain').value = io.domain ? io.domain : '';
|
||||
window.opener.Zotero_Preferences.Export.buildQuickCopyFormatDropDown(
|
||||
Zotero_Preferences.Export.buildQuickCopyFormatDropDown(
|
||||
document.getElementById('zotero-quickCopy-menu'),
|
||||
contentType,
|
||||
io.format
|
||||
);
|
||||
window.opener.Zotero_Preferences.Export.populateQuickCopyLocaleList(
|
||||
document.getElementById('zotero-quickCopy-locale-menu'),
|
||||
io.locale
|
||||
Zotero.Styles.populateLocaleList(
|
||||
document.getElementById('zotero-quickCopy-locale-menu')
|
||||
);
|
||||
document.getElementById('zotero-quickCopy-copyAsHTML').checked = io.asHTML;
|
||||
Zotero_Preferences.Export.updateQuickCopyUI();
|
||||
Zotero_Preferences.Export._lastSelectedLocale = io.locale;
|
||||
]]>
|
||||
</script>
|
||||
</dialog>
|
||||
|
|
|
@ -495,8 +495,8 @@ var Zotero_RTFScan = new function() {
|
|||
|
||||
function _formatRTF() {
|
||||
// load style and create ItemSet with all items
|
||||
var zStyle = Zotero.Styles.get(document.getElementById("style-listbox").selectedItem.value)
|
||||
var locale = document.getElementById("locale-menu").selectedItem.value;
|
||||
var zStyle = Zotero.Styles.get(document.getElementById("style-listbox").value)
|
||||
var locale = document.getElementById("locale-menu").value;
|
||||
var style = zStyle.getCiteProc(locale);
|
||||
style.setOutputFormat("rtf");
|
||||
var isNote = style.class == "note";
|
||||
|
@ -599,7 +599,9 @@ var Zotero_RTFScan = new function() {
|
|||
Zotero.File.putContents(outputFile, contents);
|
||||
|
||||
// save locale
|
||||
Zotero.Prefs.set("export.lastLocale", locale);
|
||||
if (!document.getElementById("locale-menu").disabled) {
|
||||
Zotero.Prefs.set("export.lastLocale", locale);
|
||||
}
|
||||
|
||||
document.documentElement.canAdvance = true;
|
||||
document.documentElement.advance();
|
||||
|
|
|
@ -92,7 +92,7 @@
|
|||
<groupbox>
|
||||
<hbox align="center">
|
||||
<caption label="&zotero.bibliography.locale.label;"/>
|
||||
<menulist id="locale-menu" oncommand="Zotero_File_Interface_Bibliography.localeChanged(this.selectedItem.value)"/>
|
||||
<menulist id="locale-menu" oncommand="Zotero_File_Interface_Bibliography.localeChanged(this.value)"/>
|
||||
</hbox>
|
||||
</groupbox>
|
||||
<groupbox>
|
||||
|
|
|
@ -27,44 +27,32 @@ var Zotero_CSL_Editor = new function() {
|
|||
this.init = init;
|
||||
this.handleKeyPress = handleKeyPress;
|
||||
this.loadCSL = loadCSL;
|
||||
this.generateBibliography = generateBibliography;
|
||||
this.refresh = refresh;
|
||||
function init() {
|
||||
var quickCopyLocale = Zotero.Prefs.get("export.quickCopy.locale");
|
||||
var menulist = document.getElementById("locale-menu");
|
||||
|
||||
Zotero.Styles.populateLocaleList(menulist, quickCopyLocale);
|
||||
Zotero.Styles.populateLocaleList(document.getElementById("locale-menu"));
|
||||
|
||||
var cslList = document.getElementById('zotero-csl-list');
|
||||
if (cslList.getAttribute('initialized') == 'true') {
|
||||
if (currentStyle) {
|
||||
loadCSL(currentStyle);
|
||||
refresh();
|
||||
}
|
||||
return;
|
||||
}
|
||||
cslList.removeAllItems();
|
||||
|
||||
var quickCopyFormat = Zotero.Prefs.get('export.quickCopy.setting');
|
||||
quickCopyFormat = Zotero.QuickCopy.unserializeSetting(quickCopyFormat);
|
||||
var lastStyle = Zotero.Prefs.get('export.lastStyle');
|
||||
|
||||
var styles = Zotero.Styles.getAll();
|
||||
var currentStyle = null;
|
||||
var listPos = 0;
|
||||
for each(var style in styles) {
|
||||
if (style.source) {
|
||||
continue;
|
||||
}
|
||||
var item = cslList.appendItem(style.title, style.styleID);
|
||||
if (!currentStyle || (quickCopyFormat.mode == 'bibliography' && quickCopyFormat.id == style.styleID)) {
|
||||
currentStyle = style.styleID;
|
||||
cslList.selectedIndex = listPos;
|
||||
if (!currentStyle && lastStyle == style.styleID) {
|
||||
currentStyle = style;
|
||||
cslList.selectedItem = item;
|
||||
}
|
||||
listPos += 1;
|
||||
}
|
||||
|
||||
if (currentStyle) {
|
||||
loadCSL(currentStyle);
|
||||
refresh();
|
||||
// Call asynchronously, see note in Zotero.Styles
|
||||
window.setTimeout(this.onStyleSelected.bind(this, currentStyle.styleID), 1);
|
||||
}
|
||||
|
||||
var pageList = document.getElementById('zotero-csl-page-type');
|
||||
var locators = Zotero.Cite.labels;
|
||||
for each(var type in locators) {
|
||||
|
@ -74,13 +62,25 @@ var Zotero_CSL_Editor = new function() {
|
|||
}
|
||||
|
||||
pageList.selectedIndex = 0;
|
||||
cslList.setAttribute('initialized', true);
|
||||
}
|
||||
function refresh() {
|
||||
var editor = document.getElementById('zotero-csl-editor');
|
||||
generateBibliography(editor.value);
|
||||
|
||||
|
||||
this.onStyleSelected = function(styleID) {
|
||||
Zotero.Prefs.set('export.lastStyle', styleID);
|
||||
let style = Zotero.Styles.get(styleID);
|
||||
Zotero.Styles.updateLocaleList(
|
||||
document.getElementById("locale-menu"),
|
||||
style,
|
||||
Zotero.Prefs.get('export.lastLocale')
|
||||
);
|
||||
|
||||
loadCSL(style.styleID);
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
this.refresh = function() {
|
||||
this.generateBibliography(this.loadStyleFromEditor());
|
||||
}
|
||||
|
||||
this.save = function() {
|
||||
var editor = document.getElementById('zotero-csl-editor');
|
||||
var style = editor.value;
|
||||
|
@ -125,22 +125,52 @@ var Zotero_CSL_Editor = new function() {
|
|||
document.getElementById('zotero-csl-list').value = cslID;
|
||||
}
|
||||
|
||||
this.loadStyleFromEditor = function() {
|
||||
var styleObject;
|
||||
try {
|
||||
styleObject = new Zotero.Style(
|
||||
document.getElementById('zotero-csl-editor').value
|
||||
);
|
||||
} catch(e) {
|
||||
document.getElementById('zotero-csl-preview-box')
|
||||
.contentDocument.documentElement.innerHTML = '<div>'
|
||||
+ Zotero.getString('styles.editor.warning.parseError')
|
||||
+ '</div><div>' + e + '</div>';
|
||||
throw e;
|
||||
}
|
||||
|
||||
return styleObject;
|
||||
}
|
||||
|
||||
function generateBibliography(str) {
|
||||
var editor = document.getElementById('zotero-csl-editor')
|
||||
this.onStyleModified = function(str) {
|
||||
document.getElementById('zotero-csl-list').selectedIndex = -1;
|
||||
|
||||
let styleObject = this.loadStyleFromEditor();
|
||||
|
||||
Zotero.Styles.updateLocaleList(
|
||||
document.getElementById("locale-menu"),
|
||||
styleObject,
|
||||
Zotero.Prefs.get('export.lastLocale')
|
||||
);
|
||||
Zotero_CSL_Editor.generateBibliography(styleObject);
|
||||
}
|
||||
|
||||
this.generateBibliography = function(style) {
|
||||
var iframe = document.getElementById('zotero-csl-preview-box');
|
||||
|
||||
var items = Zotero.getActiveZoteroPane().getSelectedItems();
|
||||
if (items.length == 0) {
|
||||
iframe.contentDocument.documentElement.innerHTML = '<html><head><title></title></head><body><p style="color: red">' + Zotero.getString('styles.editor.warning.noItems') + '</p></body></html>';
|
||||
iframe.contentDocument.documentElement.innerHTML =
|
||||
'<html><head><title></title></head><body><p style="color: red">'
|
||||
+ Zotero.getString('styles.editor.warning.noItems')
|
||||
+ '</p></body></html>';
|
||||
return;
|
||||
}
|
||||
|
||||
var locale = document.getElementById("locale-menu").selectedItem.value;
|
||||
var styleObject, styleEngine;
|
||||
var selectedLocale = document.getElementById("locale-menu").value;
|
||||
var styleEngine;
|
||||
try {
|
||||
styleObject = new Zotero.Style(str);
|
||||
styleEngine = styleObject.getCiteProc(locale);
|
||||
styleEngine = style.getCiteProc(style.locale || selectedLocale);
|
||||
} catch(e) {
|
||||
iframe.contentDocument.documentElement.innerHTML = '<div>' + Zotero.getString('styles.editor.warning.parseError') + '</div><div>'+e+'</div>';
|
||||
throw e;
|
||||
|
|
|
@ -58,13 +58,13 @@
|
|||
<menuitem label="near-note" value="4"/>
|
||||
</menupopup>
|
||||
</menulist>
|
||||
<menulist id="locale-menu" oncommand="Zotero_CSL_Editor.refresh()"/>
|
||||
<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)"/>
|
||||
<menulist id="locale-menu" oncommand="Zotero.Prefs.set('export.lastLocale', this.value); Zotero_CSL_Editor.refresh()"/>
|
||||
<menulist id="zotero-csl-list" style="min-height: 1.6em; min-width: 100px" flex="1" oncommand="Zotero_CSL_Editor.onStyleSelected(this.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)"/>
|
||||
oncommand="Zotero_CSL_Editor.onStyleModified()"/>
|
||||
<splitter id="csledit-splitter" collapse="before" persist="state">
|
||||
<grippy/>
|
||||
</splitter>
|
||||
|
|
|
@ -30,11 +30,10 @@ var Zotero_CSL_Preview = new function() {
|
|||
this.generateBibliography = generateBibliography;
|
||||
|
||||
function init() {
|
||||
//refresh();
|
||||
var quickCopyLocale = Zotero.Prefs.get("export.quickCopy.locale");
|
||||
var menulist = document.getElementById("locale-menu");
|
||||
|
||||
Zotero.Styles.populateLocaleList(menulist, quickCopyLocale);
|
||||
Zotero.Styles.populateLocaleList(menulist);
|
||||
menulist.value = Zotero.Prefs.get('export.lastLocale');;
|
||||
|
||||
var iframe = document.getElementById('zotero-csl-preview-box');
|
||||
iframe.contentDocument.documentElement.innerHTML = '<html><head><title></title></head><body><p>' + Zotero.getString('styles.preview.instructions') + '</p></body></html>';
|
||||
|
@ -91,8 +90,7 @@ var Zotero_CSL_Preview = new function() {
|
|||
return '';
|
||||
}
|
||||
|
||||
var locale = document.getElementById("locale-menu").selectedItem.value;
|
||||
|
||||
var locale = document.getElementById("locale-menu").value;
|
||||
var styleEngine = style.getCiteProc(locale);
|
||||
|
||||
// Generate multiple citations
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
</menupopup>
|
||||
</menulist>
|
||||
|
||||
<menulist id="locale-menu" oncommand="Zotero_CSL_Preview.refresh()"/>
|
||||
<menulist id="locale-menu" oncommand="Zotero.Prefs.set('export.lastLocale', this.value); Zotero_CSL_Preview.refresh()"/>
|
||||
</hbox>
|
||||
<iframe id="zotero-csl-preview-box" flex="1" style="padding: 0 1em; background:white;" overflow="auto" type="content"/>
|
||||
</vbox>
|
||||
|
|
|
@ -44,7 +44,7 @@ Zotero.QuickCopy = new function() {
|
|||
this.unserializeSetting = function (setting) {
|
||||
var settingObject = {};
|
||||
|
||||
if (typeof setting === 'string' || setting instanceof String) {
|
||||
if (typeof setting === 'string') {
|
||||
try {
|
||||
// First test if string input is a stringified object
|
||||
settingObject = JSON.parse(setting);
|
||||
|
@ -104,9 +104,10 @@ Zotero.QuickCopy = new function() {
|
|||
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
var nsIURI = ioService.newURI(url, null, null);
|
||||
|
||||
try {
|
||||
var nsIURI = ioService.newURI(url, null, null);
|
||||
// Accessing some properties may throw for URIs that do not support those
|
||||
// parts. E.g. hostPort throws NS_ERROR_FAILURE for about:blank
|
||||
var urlHostPort = nsIURI.hostPort;
|
||||
var urlPath = nsIURI.path;
|
||||
}
|
||||
|
@ -114,18 +115,19 @@ Zotero.QuickCopy = new function() {
|
|||
return quickCopyPref;
|
||||
}
|
||||
|
||||
|
||||
var matches = [];
|
||||
|
||||
var sql = "SELECT key AS domainPath, value AS format FROM settings "
|
||||
+ "WHERE setting='quickCopySite' AND (key LIKE ? OR key LIKE ?)";
|
||||
var urlDomain = urlHostPort.match(/[^\.]+\.[^\.]+$/);
|
||||
var rows = Zotero.DB.query(sql, ['%' + urlDomain + '%', '/%']);
|
||||
var rows = Zotero.DB.query(sql, ['%' + urlDomain[0] + '%', '/%']);
|
||||
for (let i = 0; i < rows.length; i++) {
|
||||
let row = rows[i];
|
||||
let [domain, path] = row.domainPath.split(/\//);
|
||||
path = '/' + (path ? path : '');
|
||||
let re = new RegExp(domain + '$');
|
||||
if (urlHostPort.match(re) && urlPath.indexOf(path) === 0) {
|
||||
let domain = row.domainPath.split('/',1)[0];
|
||||
let path = row.domainPath.substr(domain.length) || '/';
|
||||
let re = new RegExp('(^|[./])' + Zotero.Utilities.quotemeta(domain) + '$', 'i');
|
||||
if (re.test(urlHostPort) && urlPath.indexOf(path) === 0) {
|
||||
matches.push({
|
||||
format: JSON.stringify(this.unserializeSetting(row.format)),
|
||||
domainLength: domain.length,
|
||||
|
|
|
@ -44,11 +44,19 @@ Zotero.Styles = new function() {
|
|||
this.ns = {
|
||||
"csl":"http://purl.org/net/xbiblio/csl"
|
||||
};
|
||||
|
||||
// TEMP
|
||||
// Until we get asynchronous style loading, load renamed styles at startup, since the
|
||||
// synchronous call we were using breaks the first drag of the session (on OS X, at least)
|
||||
|
||||
this.preinit = function () {
|
||||
// Upgrade style locale prefs for 4.0.27
|
||||
var bibliographyLocale = Zotero.Prefs.get("export.bibliographyLocale");
|
||||
if (bibliographyLocale) {
|
||||
Zotero.Prefs.set("export.lastLocale", bibliographyLocale);
|
||||
Zotero.Prefs.set("export.quickCopy.locale", bibliographyLocale);
|
||||
Zotero.Prefs.clear("export.bibliographyLocale");
|
||||
}
|
||||
|
||||
// TEMP
|
||||
// Until we get asynchronous style loading, load renamed styles at startup, since the
|
||||
// synchronous call we were using breaks the first drag of the session (on OS X, at least)
|
||||
_renamedStyles = {};
|
||||
Zotero.HTTP.promise(
|
||||
"GET", "resource://zotero/schema/renamed-styles.json", { responseType: 'json' }
|
||||
|
@ -83,16 +91,14 @@ Zotero.Styles = new function() {
|
|||
dir.append("hidden");
|
||||
if (dir.exists()) i += _readStylesFromDirectory(dir, true);
|
||||
|
||||
Zotero.debug("Cached "+i+" styles in "+((new Date()).getTime() - start)+" ms");
|
||||
// Sort visible styles by title
|
||||
_visibleStyles.sort(function(a, b) {
|
||||
return a.title.localeCompare(b.title);
|
||||
})
|
||||
// .. and freeze, so they can be returned directly
|
||||
_visibleStyles = Object.freeze(_visibleStyles);
|
||||
|
||||
// transfer and reset "export.bibliographyLocale" pref value
|
||||
var bibliographyLocale = '';
|
||||
bibliographyLocale = Zotero.Prefs.get("export.bibliographyLocale");
|
||||
if (bibliographyLocale) {
|
||||
Zotero.Prefs.set("export.lastLocale", bibliographyLocale);
|
||||
Zotero.Prefs.set("export.quickCopy.locale", bibliographyLocale);
|
||||
Zotero.Prefs.clear("export.bibliographyLocale");
|
||||
}
|
||||
Zotero.debug("Cached "+i+" styles in "+((new Date()).getTime() - start)+" ms");
|
||||
|
||||
// load available CSL locales
|
||||
var localeFile = {};
|
||||
|
@ -154,6 +160,7 @@ Zotero.Styles = new function() {
|
|||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
@ -182,11 +189,11 @@ Zotero.Styles = new function() {
|
|||
|
||||
/**
|
||||
* Gets all visible styles
|
||||
* @return {Zotero.Style[]} An array of Zotero.Style objects
|
||||
* @return {Zotero.Style[]} An immutable array of Zotero.Style objects
|
||||
*/
|
||||
this.getVisible = function() {
|
||||
if(!_initialized || !_cacheTranslatorData) this.init();
|
||||
return _visibleStyles.slice(0);
|
||||
return _visibleStyles; // Immutable
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -428,71 +435,94 @@ Zotero.Styles = new function() {
|
|||
|
||||
/**
|
||||
* Populate menulist with locales
|
||||
*
|
||||
* @param {xul:menulist} menulist
|
||||
*/
|
||||
this.populateLocaleList = function(menulist, prefLocale) {
|
||||
this.populateLocaleList = function(menulist) {
|
||||
if(!_initialized) this.init();
|
||||
|
||||
// Reset menulist
|
||||
menulist.selectedItem = null;
|
||||
menulist.removeAllItems();
|
||||
|
||||
var doc = menulist.ownerDocument;
|
||||
var popup = doc.createElement('menupopup');
|
||||
menulist.appendChild(popup);
|
||||
let fallbackLocale = Zotero.Styles.primaryDialects[Zotero.locale]
|
||||
|| Zotero.locale;
|
||||
|
||||
var desiredLocale = "";
|
||||
var fallbackLocale = Zotero.locale;
|
||||
let menuLocales = Zotero.Utilities.deepCopy(Zotero.Styles.locales);
|
||||
let menuLocalesKeys = Object.keys(menuLocales).sort();
|
||||
|
||||
// Primary dialect conversion (e.g. "en" to "en-US")
|
||||
if (Zotero.Styles.primaryDialects[prefLocale] !== undefined) {
|
||||
prefLocale = Zotero.Styles.primaryDialects[prefLocale];
|
||||
}
|
||||
if (Zotero.Styles.primaryDialects[fallbackLocale] !== undefined) {
|
||||
fallbackLocale = Zotero.Styles.primaryDialects[fallbackLocale];
|
||||
}
|
||||
|
||||
if (prefLocale) {
|
||||
desiredLocale = prefLocale;
|
||||
} else {
|
||||
desiredLocale = fallbackLocale;
|
||||
}
|
||||
|
||||
var menuLocales = {};
|
||||
var menuLocalesKeys = [];
|
||||
var styleLocales = Zotero.Styles.locales;
|
||||
|
||||
for (let locale in styleLocales) {
|
||||
menuLocales[locale] = styleLocales[locale];
|
||||
}
|
||||
|
||||
menuLocalesKeys = Object.keys(menuLocales);
|
||||
menuLocalesKeys.sort();
|
||||
|
||||
if (fallbackLocale && menuLocales[fallbackLocale] === undefined) {
|
||||
// Make sure that client locale is always available as a choice
|
||||
if (fallbackLocale && !(fallbackLocale in menuLocales)) {
|
||||
menuLocales[fallbackLocale] = fallbackLocale;
|
||||
menuLocalesKeys.unshift(fallbackLocale);
|
||||
}
|
||||
if (prefLocale && menuLocales[prefLocale] === undefined) {
|
||||
menuLocales[prefLocale] = prefLocale;
|
||||
menuLocalesKeys.unshift(prefLocale);
|
||||
}
|
||||
|
||||
var itemNode;
|
||||
for (let i=0; i<menuLocalesKeys.length; i++) {
|
||||
var menuValue = menuLocalesKeys[i];
|
||||
var menuLabel = menuLocales[menuLocalesKeys[i]];
|
||||
itemNode = doc.createElement("menuitem");
|
||||
itemNode.setAttribute("value", menuValue);
|
||||
itemNode.setAttribute("label", menuLabel);
|
||||
popup.appendChild(itemNode);
|
||||
|
||||
if (menuValue == desiredLocale) {
|
||||
menulist.selectedItem = itemNode;
|
||||
menulist.appendItem(menuLocales[menuLocalesKeys[i]], menuLocalesKeys[i]);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Update locale list state based on style selection.
|
||||
* For styles that do not define a locale, enable the list and select a
|
||||
* preferred locale.
|
||||
* For styles that define a locale, disable the list and select the
|
||||
* specified locale. If the locale does not exist, it is added to the list.
|
||||
* If null is passed instead of style, the list and its label are disabled,
|
||||
* and set to blank value.
|
||||
*
|
||||
* Note: Do not call this function synchronously immediately after
|
||||
* populateLocaleList. The menulist items are added, but the values are not
|
||||
* yet set.
|
||||
*
|
||||
* @param {xul:menulist} menulist Menulist object that will be manipulated
|
||||
* @param {Zotero.Style} style Currently selected style
|
||||
* @param {String} prefLocale Preferred locale if not overridden by the style
|
||||
*
|
||||
* @return {String} The locale that was selected
|
||||
*/
|
||||
this.updateLocaleList = function(menulist, style, prefLocale) {
|
||||
// Remove any nodes that were manually added to menulist
|
||||
let availableLocales = [];
|
||||
for (let i=0; i<menulist.itemCount; i++) {
|
||||
let item = menulist.getItemAtIndex(i);
|
||||
if (item.getAttributeNS('zotero:', 'customLocale')) {
|
||||
menulist.removeItemAt(i);
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
|
||||
availableLocales.push(item.value);
|
||||
}
|
||||
|
||||
return desiredLocale;
|
||||
};
|
||||
if (!style) {
|
||||
// disable menulist and label
|
||||
menulist.disabled = true;
|
||||
if (menulist.labelElement) menulist.labelElement.disabled = true;
|
||||
|
||||
// set node to blank node
|
||||
// If we just set value to "", the internal label is collapsed and the dropdown list becomes shorter
|
||||
let blankListNode = menulist.appendItem('', '');
|
||||
blankListNode.setAttributeNS('zotero:', 'customLocale', true);
|
||||
|
||||
menulist.selectedItem = blankListNode;
|
||||
return menulist.value;
|
||||
}
|
||||
|
||||
menulist.disabled = !!style.locale;
|
||||
if (menulist.labelElement) menulist.labelElement.disabled = false;
|
||||
|
||||
let selectLocale = style.locale || prefLocale || Zotero.locale;
|
||||
selectLocale = Zotero.Styles.primaryDialects[selectLocale] || selectLocale;
|
||||
|
||||
// Make sure the locale we want to select is in the menulist
|
||||
if (availableLocales.indexOf(selectLocale) == -1) {
|
||||
let customLocale = menulist.insertItemAt(0, selectLocale, selectLocale);
|
||||
customLocale.setAttributeNS('zotero:', 'customLocale', true);
|
||||
}
|
||||
|
||||
return menulist.value = selectLocale;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -410,20 +410,21 @@ Zotero.Utilities = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Encode special XML/HTML characters<br/>
|
||||
* <br/>
|
||||
* Certain entities can be inserted manually:<br/>
|
||||
* <pre> <ZOTEROBREAK/> => <br/>
|
||||
* <ZOTEROHELLIP/> => &#8230;</pre>
|
||||
* @type String
|
||||
* Encode special XML/HTML characters
|
||||
* Certain entities can be inserted manually:
|
||||
* <ZOTEROBREAK/> => <br/>
|
||||
* <ZOTEROHELLIP/> => …
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {String}
|
||||
*/
|
||||
"htmlSpecialChars":function(/**String*/ str) {
|
||||
if (typeof str != 'string') str = str.toString();
|
||||
|
||||
if (!str) {
|
||||
return '';
|
||||
"htmlSpecialChars":function(str) {
|
||||
if (str && typeof str != 'string') {
|
||||
str = str.toString();
|
||||
}
|
||||
|
||||
if (!str) return '';
|
||||
|
||||
return str
|
||||
.replace(/&/g, '&')
|
||||
.replace(/"/g, '"')
|
||||
|
|
|
@ -101,14 +101,13 @@
|
|||
|
||||
<!ENTITY zotero.preferences.quickCopy.caption "Quick Copy">
|
||||
<!ENTITY zotero.preferences.quickCopy.defaultOutputFormat "Default Output Format:">
|
||||
<!ENTITY zotero.preferences.quickCopy.locale "Bibliography Locale:">
|
||||
<!ENTITY zotero.preferences.quickCopy.copyAsHTML "Copy as HTML">
|
||||
<!ENTITY zotero.preferences.quickCopy.macWarning "Note: Rich-text formatting will be lost on Mac OS X.">
|
||||
<!ENTITY zotero.preferences.quickCopy.siteEditor.setings "Site-Specific Settings:">
|
||||
<!ENTITY zotero.preferences.quickCopy.siteEditor.domainPath "Domain/Path">
|
||||
<!ENTITY zotero.preferences.quickCopy.siteEditor.domainPath.example "(e.g. wikipedia.org)">
|
||||
<!ENTITY zotero.preferences.quickCopy.siteEditor.outputFormat "Output Format">
|
||||
<!ENTITY zotero.preferences.quickCopy.siteEditor.locale "Locale">
|
||||
<!ENTITY zotero.preferences.quickCopy.siteEditor.locale "Language">
|
||||
<!ENTITY zotero.preferences.quickCopy.dragLimit "Disable Quick Copy when dragging more than">
|
||||
|
||||
<!ENTITY zotero.preferences.prefpane.cite "Cite">
|
||||
|
|
|
@ -165,7 +165,7 @@
|
|||
|
||||
<!ENTITY zotero.bibliography.title "Create Citation/Bibliography">
|
||||
<!ENTITY zotero.bibliography.style.label "Citation Style:">
|
||||
<!ENTITY zotero.bibliography.locale.label "Locale:">
|
||||
<!ENTITY zotero.bibliography.locale.label "Language:">
|
||||
<!ENTITY zotero.bibliography.outputMode "Output Mode:">
|
||||
<!ENTITY zotero.bibliography.bibliography "Bibliography">
|
||||
<!ENTITY zotero.bibliography.outputMethod "Output Method:">
|
||||
|
|
Loading…
Reference in New Issue
Block a user