Skip to content

Commit

Permalink
0.7.5 fixed bug when changing the location of the preview element
Browse files Browse the repository at this point in the history
  • Loading branch information
dcartertod committed Feb 28, 2024
1 parent 3848c69 commit 156950c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
Binary file modified ZoteroPreview7.xpi
Binary file not shown.
2 changes: 1 addition & 1 deletion ZoteroPreview7/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "ZoteroPreview",
"version": "0.7.4",
"version": "0.7.5",
"description": "Citation preview pane for Zotero.",
"homepage_url": "https://github.com/dcartertod/zotero-plugins",
"applications": {
Expand Down
30 changes: 23 additions & 7 deletions ZoteroPreview7/zoteropreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,33 +47,43 @@ Zotero.zoteropreview = {
positionpref = Zotero.Prefs.get('extensions.zoteropreview.position', true);
}

this.log(positionpref);

var mainDocument = Zotero.getActiveZoteroPane().document;

var target = mainDocument.getElementById(positionpref);
this.log(target);

var zpdiv = mainDocument.getElementById('zotero-preview-container');
this.log(zpdiv);
var zpdivContainer = mainDocument.getElementById('zotero-preview-container');
Zotero.debug('zpdivContainer done');

// it appears that if we move a collapsible element, it loses it's contents
this.log('zpdiv');
var zpdiv = mainDocument.getElementById('zotero-preview');
if (zpdiv == null){
this.log('adding div')
// Add the div, and put it into a collapsible container
this.log('adding zpdiv');
zpdiv = mainDocument.createElement('div');
zpdiv.id = 'zotero-preview';
this.storeAddedElement(zpdiv);
}
Zotero.debug('zpdiv done');

if (zpdivContainer == null){
this.log('adding zpdivContainer')

zpdivContainer = mainDocument.createXULElement("collapsible-section");
zpdivContainer.id='zotero-preview-container';
zpdivContainer.style='--open-height: auto;';
zpdivContainer.open="";
zpdivContainer.label='Preview';
zpdivContainer.dataset.pane="preview";
zpdivContainer.appendChild(zpdiv);

this.log('adding span');
this.log('storing elements');

// Add a stylesheet to the main Zotero pane - based on make-it-red
// see _collapsibleSection.scss
// this is how the icons are done
let link1 = mainDocument.createElement('link');
this.log('link1');
link1.id = 'zotero-preview-stylesheet';
Expand All @@ -85,9 +95,14 @@ Zotero.zoteropreview = {
this.storeAddedElement(link1);

this.storeAddedElement(zpdivContainer);
this.storeAddedElement(zpdiv);
}

this.log('appending container to target')
target.after(zpdivContainer);

// basic order of operations thing here. add the div after adding the container to the main document
this.log('appending zpdiv to zpdivContainer');
zpdivContainer.appendChild(zpdiv);
// this.addIcon();
this.log('store')

Expand Down Expand Up @@ -121,7 +136,7 @@ Zotero.zoteropreview = {
doc.getElementById(id)?.remove();
}
try {
doc.querySelector('#zotero-preview')?.remove();
doc.querySelector('#zotero-preview-container')?.remove();
}
catch(err){
this.log(err);
Expand Down Expand Up @@ -153,6 +168,7 @@ Zotero.zoteropreview = {
}
},

// the way this works is that you register with the Zotero Notifier, which then calls the "notify" function
notify(event, _type, ids, extraData) {
Zotero.debug('not sure if there is an event for selecting an item in the main pane');
this.log(event);
Expand Down
2 changes: 1 addition & 1 deletion ZoteroPreview7/zoteropreview7-updates.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"[email protected]": {
"updates": [
{
"version": "0.7.4",
"version": "0.7.5",
"update_link": "https://raw.githubusercontent.com/dcartertod/zotero-plugins/main/ZoteroPreview7.xpi",
"applications": {
"zotero": {
Expand Down

0 comments on commit 156950c

Please sign in to comment.