Skip to content

Commit

Permalink
Merge branch '4.0'
Browse files Browse the repository at this point in the history
Since modal windows (e.g., the Create Bib window and the Quick Copy site
editor window) can't use yield, style retrieval
(Zotero.Styles.getVisible()/getAll()) is now synchronous, depending on a
previous async Zotero.Styles.init(). The translator list is generated in
the prefs window and passed into the Quick Copy site editor, but it's
possible the translators API should be changed to make getTranslators()
synchronous with a prior init() as well.
  • Loading branch information
dstillman committed Jun 27, 2015
2 parents 0d1d4ee + 3a5854f commit 99dd1c0
Show file tree
Hide file tree
Showing 187 changed files with 1,227 additions and 443 deletions.
84 changes: 57 additions & 27 deletions chrome/content/zotero/bibliography.js
Expand Up @@ -34,16 +34,13 @@

var Zotero_File_Interface_Bibliography = new function() {
var _io, _saveStyle;

this.init = init;
this.styleChanged = styleChanged;
this.acceptSelection = acceptSelection;
var lastSelectedLocale; // Only changes when explicitly selected

/*
* Initialize some variables and prepare event listeners for when chrome is done
* loading
*/
function init() {
this.init = function () {
// Set font size from pref
// Affects bibliography.xul and integrationDocPrefs.xul
var bibContainer = document.getElementById("zotero-bibliography-container");
Expand All @@ -59,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);
Expand All @@ -83,14 +80,29 @@ 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
Zotero.Styles.populateLocaleList(document.getElementById("locale-menu"));

// Has to be async to work properly
window.setTimeout(function () {
listbox.ensureIndexIsVisible(selectIndex);
listbox.selectedIndex = selectIndex;
Zotero_File_Interface_Bibliography.styleChanged();
}, 0);

// ONLY FOR bibliography.xul: export options
Expand Down Expand Up @@ -149,22 +161,24 @@ var Zotero_File_Interface_Bibliography = new function() {

// set style to false, in case this is cancelled
_io.style = false;
}

};

/*
* Called when locale is changed
*/
this.localeChanged = function (selectedValue) {
lastSelectedLocale = selectedValue;
};

/*
* 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;
}
this.styleChanged = function () {
var selectedItem = document.getElementById("style-listbox").selectedItem;
var selectedStyle = selectedItem.getAttribute('value');
var selectedStyleObj = Zotero.Styles.get(selectedStyle);

var selectedStyle = selectedItem.getAttribute('value'),
selectedStyleObj = Zotero.Styles.get(selectedStyle);
updateLocaleMenu(selectedStyleObj);

//
// For integrationDocPrefs.xul
Expand Down Expand Up @@ -195,20 +209,33 @@ var Zotero_File_Interface_Bibliography = new function() {

// Change label to "Citation" or "Note" depending on style class
if(document.getElementById("citations")) {
let label = "";
if(Zotero.Styles.get(selectedStyle).class == "note") {
var label = Zotero.getString('citation.notes');
label = Zotero.getString('citation.notes');
} else {
var label = Zotero.getString('citation.citations');
label = Zotero.getString('citation.citations');
}
document.getElementById("citations").label = label;
}

window.sizeToContent();
};

/*
* Update locale menulist when style is changed
*/
function updateLocaleMenu(selectedStyle) {
Zotero.Styles.updateLocaleList(
document.getElementById("locale-menu"),
selectedStyle,
lastSelectedLocale
);
}

function acceptSelection() {
this.acceptSelection = function () {
// collect code
_io.style = document.getElementById("style-listbox").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;
Expand All @@ -235,5 +262,8 @@ var Zotero_File_Interface_Bibliography = new function() {
if(_saveStyle) {
Zotero.Prefs.set("export.lastStyle", _io.style);
}
}
}

// save locale
Zotero.Prefs.set("export.lastLocale", lastSelectedLocale);
};
}
6 changes: 6 additions & 0 deletions chrome/content/zotero/bibliography.xul
Expand Up @@ -16,6 +16,12 @@
<caption label="&zotero.bibliography.style.label;"/>
<listbox id="style-listbox" onselect="Zotero_File_Interface_Bibliography.styleChanged()"/>
</groupbox>
<groupbox>
<hbox align="center">
<caption label="&zotero.bibliography.locale.label;"/>
<menulist id="locale-menu" oncommand="Zotero_File_Interface_Bibliography.localeChanged(this.selectedItem.value)"/>
</hbox>
</groupbox>
<groupbox>
<caption label="&zotero.bibliography.outputMode;"/>
<radiogroup id="output-mode-radio">
Expand Down

0 comments on commit 99dd1c0

Please sign in to comment.