Skip to content

Commit

Permalink
Added et al. and and global settings for author column
Browse files Browse the repository at this point in the history
  • Loading branch information
frianasoa committed Jan 5, 2024
1 parent 168fb87 commit adff458
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 10 deletions.
6 changes: 6 additions & 0 deletions content/settings/note-style.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div xmlns="https://www.w3.org/1999/xhtml" id="group-note-style">
<table id="style">
<tr><td><label style="padding:0;margin:0;" for="zn-display-and">And</label></td><td colspan="2"><input onchange="Zotero_Preferences.ZeNotes.setpreference(event, 'display-and');" id="zn-display-and"/></td></tr>
<tr><td><label style="padding:0;margin:0;" for="zn-display-etal">Et al.</label></td><td colspan="2"><input onchange="Zotero_Preferences.ZeNotes.setpreference(event, 'display-etal');" id="zn-display-etal"/></td></tr>
</table>
</div>
6 changes: 6 additions & 0 deletions content/settings/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@ Zotero_Preferences.ZeNotes = {
case 'exclude-from-prompt':
this.promptdataselection();
return;
case 'note-style':
args = [
["display-and", "zn-display-and"],
["display-etal", "zn-display-etal"],
];
break;
}

for(arg of args)
Expand Down
4 changes: 4 additions & 0 deletions content/settings/preferences.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
<div class="zn-include" data-src="display.xhtml" onload="Zotero_Preferences.ZeNotes.initpanel('global')"> </div>
</fieldset>

<fieldset>
<legend class='zn-legend'>Note style</legend>
<div class="zn-include" data-src="note-style.xhtml" onload="Zotero_Preferences.ZeNotes.initpanel('note-style')"> </div>
</fieldset>

<fieldset>
<legend class='zn-legend'>Advanced</legend>
Expand Down
4 changes: 4 additions & 0 deletions content/settings/preferences6.xul
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
<caption label="Global display"/>
<box class="zn-include" src="display.xhtml" onload="Zotero_Preferences.ZeNotes.initpanel('global')"> </box>
</groupbox>
<groupbox>
<caption label="Note style"/>
<box class="zn-include" src="note-style.xhtml" onload="Zotero_Preferences.ZeNotes.initpanel('note-style')"> </box>
</groupbox>
</tabpanel>

<tabpanel orient="vertical" id="zn-advanced-panel">
Expand Down
53 changes: 51 additions & 2 deletions core/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ Format = {

var color = Zotero.ZeNotes.Utils.addopacity(note["annotationColor"], Zotero.ZeNotes.Prefs.get("bg-opacity"));

let note_ = "<div class='annotation-body'><div class='annotation-comment'>"+comment+"</div><hr style='width: 25%;'/><div id='annotation-"+note["parentItem"].key+"-"+note["key"]+"' class='annotation' data-attachmentkey='"+note["parentItem"].key+"' data-tag='"+tag+"' data-attachmentid='"+note["parentItem"].id+"' data-pagelabel='"+note["annotationPageLabel"]+"' data-annotationpage='"+annotationpage+"' data-annotationid='"+note.id+"' data-annotationkey='"+note["key"]+"' style='background-color:"+color+";' data-author='"+Format.creatorshort(item)+"' data-date='"+Format.year(item)+"'>"+contents+"</div></div><hr/>";
let note_ = "<div class='annotation-body'><div class='annotation-comment'>"+comment+"</div><hr style='width: 25%;'/><div id='annotation-"+note["parentItem"].key+"-"+note["key"]+"' class='annotation' data-attachmentkey='"+note["parentItem"].key+"' data-tag='"+tag+"' data-attachmentid='"+note["parentItem"].id+"' data-pagelabel='"+note["annotationPageLabel"]+"' data-annotationpage='"+annotationpage+"' data-annotationid='"+note.id+"' data-annotationkey='"+note["key"]+"' style='background-color:"+color+";' data-source='"+Format.creatorshortlocale(item)+"' data-author='"+Format.creatorshort(item)+"' data-date='"+Format.year(item)+"'>"+contents+"</div></div><hr/>";
notetext+=note_;
}
else
Expand All @@ -260,7 +260,7 @@ Format = {
date: Format.year(item),
journal: this.xmlescape(item.getField("publicationTitle")),
author: Format.creatorshort(item)+" ("+Format.year(item)+")",
source: Format.creatorshort(item)+" ("+Format.year(item)+")",
source: Format.creatorshortlocale(item)+" ("+Format.year(item)+")",
creators: Format.creators(item),
filenames: filenames,
filekey: Format.filekey(item),
Expand Down Expand Up @@ -308,9 +308,58 @@ Format = {
},

creatorshort(item) {
let _and = Zotero.ZeNotes.Prefs.get("display-and", " and ");
let _etal = Zotero.ZeNotes.Prefs.get("display-etal", " et al.");
return this.getFirstCreatorFromData(item.itemTypeID, item.getCreators(), _and, _etal);
},

creatorshortlocale(item) {
return Zotero.Items.getFirstCreatorFromData(item.itemTypeID, item.getCreators());
},

getFirstCreatorFromData(itemTypeID, creatorsData, _and, _etal, options) {
//From Zotero
if (!options) {
options = {
omitBidiIsolates: false
};
}

if (creatorsData.length === 0) {
return "";
}

var validCreatorTypes = [
Zotero.CreatorTypes.getPrimaryIDForType(itemTypeID),
Zotero.CreatorTypes.getID('editor'),
Zotero.CreatorTypes.getID('contributor')
];

for (let creatorTypeID of validCreatorTypes) {
let matches = creatorsData.filter(data => data.creatorTypeID == creatorTypeID)
if (!matches.length) {
continue;
}
if (matches.length === 1) {
return matches[0].lastName;
}
if (matches.length === 2) {
let a = matches[0];
let b = matches[1];
let args = options.omitBidiIsolates
? [a.lastName, b.lastName]
// \u2068 FIRST STRONG ISOLATE: Isolates the directionality of characters that follow
// \u2069 POP DIRECTIONAL ISOLATE: Pops the above isolation
: [`\u2068${a.lastName}\u2069`, `\u2068${b.lastName}\u2069`];
return args.join(_and);
}
if (matches.length >= 3) {
return matches[0].lastName + " " + _etal;
}
}
return "";
},

creators(item) {
var variable = item.getCreatorsJSON();
var creators = [];
Expand Down
2 changes: 1 addition & 1 deletion install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Description about="urn:mozilla:install-manifest">
<em:id>[email protected]</em:id>
<em:name>ZeNotes</em:name>
<em:version>0.7.6</em:version>
<em:version>0.7.7</em:version>
<em:multiprocessCompatible>true</em:multiprocessCompatible>
<em:updateURL>https://raw.githubusercontent.com/frianasoa/zenotes/main/zenote-update.json</em:updateURL>
<em:homepageURL>https://github.com/frianasoa/zenotes</em:homepageURL>
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Ze Notes",
"version": "0.7.6",
"version": "0.7.7",
"description": "Advanced notes manager",
"homepage_url": "https://github.com/frianasoa/zenotes",
"author": "Fanantenana Rianasoa Andriariniaina",
Expand Down
6 changes: 3 additions & 3 deletions zenote-update.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"[email protected]": {
"updates": [
{
"version": "0.7.6",
"update_link": "https://github.com/frianasoa/Ze-Notes/releases/download/v0.7.6/zenotes-v0.7.6.xpi",
"update_hash": "sha256:ef93bfe98a558526fdfeec367276eb8590070a95ab309606531a7a0694501ce7",
"version": "0.7.7",
"update_link": "https://github.com/frianasoa/Ze-Notes/releases/download/v0.7.7/zenotes-v0.7.7.xpi",
"update_hash": "sha256:5c7573098676a08d4b1839548caa33fb33aadcc910ef50ae82ef6ecc9d2b256d",
"applications": {
"gecko": {
"strict_min_version": "60.0"
Expand Down
6 changes: 3 additions & 3 deletions zenote-update.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<rdf:Seq>
<rdf:li>
<rdf:Description>
<ns1:version>0.7.6</ns1:version>
<ns1:version>0.7.7</ns1:version>
<ns1:targetApplication>
<rdf:Description>
<ns1:id>[email protected]</ns1:id>
<ns1:minVersion>5.0.0</ns1:minVersion>
<ns1:maxVersion>6.*</ns1:maxVersion>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.7.6/zenotes-v0.7.6.xpi</ns1:updateLink>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.7.7/zenotes-v0.7.7.xpi</ns1:updateLink>
</rdf:Description>
</ns1:targetApplication>

Expand All @@ -20,7 +20,7 @@
<ns1:id>[email protected]</ns1:id>
<ns1:minVersion>4.999</ns1:minVersion>
<ns1:maxVersion>6.*</ns1:maxVersion>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.7.6/zenotes-v0.7.6.xpi</ns1:updateLink>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.7.7/zenotes-v0.7.7.xpi</ns1:updateLink>
</rdf:Description>
</ns1:targetApplication>

Expand Down

0 comments on commit adff458

Please sign in to comment.