Skip to content

Commit b6cc1aa

Browse files
committed
Scroll the pin icon with note content
1 parent 1d597bd commit b6cc1aa

File tree

7 files changed

+134
-107
lines changed

7 files changed

+134
-107
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
All notable changes to the Pixel Banner plugin will be documented in this file.
44

5+
## [2.5.6] - 2024-10-27
6+
- Scroll the pin icon with note content
7+
58
## [2.5.5] - 2024-10-27
69

710
### Added

UPDATE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## 🎉 What's New
22

3-
### v2.5.5 - v2.5.1
3+
### v2.5.6 - v2.5.1
44
#### Added
55
- Note frontmatter now updated to allow for keywords separated by commas when using API (allowing for more random variety per note)
66
- `Folder Images` keywords input now supports multiple keywords separated by commas (allowing for more random variety per folder)
@@ -10,6 +10,7 @@
1010
- "Pinnings" now correctly updates note frontmatter to use local image when saving if the note didn't already have a banner field
1111
- Fix issue where a defined "Folder Images" path of root `/` was not being respected
1212
- Description messages in settings page is now rendering properly acoss all tabs
13+
- Scroll the pin icon with note content
1314

1415
---
1516

example-vault.zip

90 Bytes
Binary file not shown.

example-vault/pixel-banner-example/.obsidian/plugins/pexels-banner/main.js

Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ var ReleaseNotesModal = class extends import_obsidian2.Modal {
913913
};
914914

915915
// virtual-module:virtual:release-notes
916-
var releaseNotes = "<h2>\u{1F389} What&#39;s New</h2>\n<h3>v2.5.5 - v2.5.1</h3>\n<h4>Added</h4>\n<ul>\n<li>Note frontmatter now updated to allow for keywords separated by commas when using API (allowing for more random variety per note)</li>\n<li><code>Folder Images</code> keywords input now supports multiple keywords separated by commas (allowing for more random variety per folder)</li>\n<li>When &quot;Pinning&quot; an image, the plugin now waits for potential a rename/move of the file to the local vault before updating the note frontmatter</li>\n</ul>\n<h4>Fixed</h4>\n<ul>\n<li>&quot;Pinnings&quot; now correctly updates note frontmatter to use local image when saving if the note didn&#39;t already have a banner field</li>\n<li>Fix issue where a defined &quot;Folder Images&quot; path of root <code>/</code> was not being respected</li>\n<li>Description messages in settings page is now rendering properly acoss all tabs</li>\n</ul>\n<hr>\n<h3>v2.5.0</h3>\n<h4>Added</h4>\n<ul>\n<li>Pin Icon Feature: Save API images to your vault<ul>\n<li>Click the pin icon (\u{1F4CC}) to save random banner images locally</li>\n<li>Choose custom filenames when saving</li>\n<li>Automatically updates note frontmatter to use local image</li>\n<li>Configure save location in settings</li>\n</ul>\n</li>\n<li>Orphaned Pins Cleanup: Utility to remove unused pinned images<ul>\n<li>Clean up button in settings</li>\n<li>Safely moves unused images to trash</li>\n<li>Checks all custom banner field names</li>\n</ul>\n</li>\n</ul>\n";
916+
var releaseNotes = "<h2>\u{1F389} What&#39;s New</h2>\n<h3>v2.5.6 - v2.5.1</h3>\n<h4>Added</h4>\n<ul>\n<li>Note frontmatter now updated to allow for keywords separated by commas when using API (allowing for more random variety per note)</li>\n<li><code>Folder Images</code> keywords input now supports multiple keywords separated by commas (allowing for more random variety per folder)</li>\n<li>When &quot;Pinning&quot; an image, the plugin now waits for potential a rename/move of the file to the local vault before updating the note frontmatter</li>\n</ul>\n<h4>Fixed</h4>\n<ul>\n<li>&quot;Pinnings&quot; now correctly updates note frontmatter to use local image when saving if the note didn&#39;t already have a banner field</li>\n<li>Fix issue where a defined &quot;Folder Images&quot; path of root <code>/</code> was not being respected</li>\n<li>Description messages in settings page is now rendering properly acoss all tabs</li>\n<li>Scroll the pin icon with note content</li>\n</ul>\n<hr>\n<h3>v2.5.0</h3>\n<h4>Added</h4>\n<ul>\n<li>Pin Icon Feature: Save API images to your vault<ul>\n<li>Click the pin icon (\u{1F4CC}) to save random banner images locally</li>\n<li>Choose custom filenames when saving</li>\n<li>Automatically updates note frontmatter to use local image</li>\n<li>Configure save location in settings</li>\n</ul>\n</li>\n<li>Orphaned Pins Cleanup: Utility to remove unused pinned images<ul>\n<li>Clean up button in settings</li>\n<li>Safely moves unused images to trash</li>\n<li>Checks all custom banner field names</li>\n</ul>\n</li>\n</ul>\n";
917917

918918
// src/main.js
919919
module.exports = class PixelBannerPlugin extends import_obsidian3.Plugin {
@@ -1123,16 +1123,33 @@ module.exports = class PixelBannerPlugin extends import_obsidian3.Plugin {
11231123
return;
11241124
}
11251125
let bannerDiv = container.querySelector(":scope > .pixel-banner-image");
1126+
let pinIcon = container.querySelector(":scope > .pin-icon");
11261127
if (!bannerDiv) {
11271128
bannerDiv = createDiv({ cls: "pixel-banner-image" });
11281129
container.insertBefore(bannerDiv, container.firstChild);
11291130
bannerDiv._isPersistentBanner = true;
1131+
if (this.settings.showPinIcon) {
1132+
pinIcon = createDiv({ cls: "pin-icon" });
1133+
pinIcon.style.position = "absolute";
1134+
pinIcon.style.top = "10px";
1135+
pinIcon.style.left = "5px";
1136+
pinIcon.style.fontSize = "1.5em";
1137+
pinIcon.style.cursor = "pointer";
1138+
pinIcon.innerHTML = "\u{1F4CC}";
1139+
pinIcon._isPersistentPin = true;
1140+
container.insertBefore(pinIcon, bannerDiv.nextSibling);
1141+
}
11301142
if (!container._hasOverriddenSetChildrenInPlace) {
11311143
const originalSetChildrenInPlace = container.setChildrenInPlace;
11321144
container.setChildrenInPlace = function(children) {
11331145
const bannerElement = this.querySelector(":scope > .pixel-banner-image");
1146+
const pinElement = this.querySelector(":scope > .pin-icon");
1147+
children = Array.from(children);
11341148
if (bannerElement == null ? void 0 : bannerElement._isPersistentBanner) {
1135-
children = [bannerElement, ...Array.from(children)];
1149+
children = [bannerElement, ...children];
1150+
}
1151+
if (pinElement == null ? void 0 : pinElement._isPersistentPin) {
1152+
children.splice(1, 0, pinElement);
11361153
}
11371154
originalSetChildrenInPlace.call(this, children);
11381155
};
@@ -1168,15 +1185,25 @@ module.exports = class PixelBannerPlugin extends import_obsidian3.Plugin {
11681185
const borderRadius = (_f = (_e = (_d = getFrontmatterValue(frontmatter, this.settings.customBorderRadiusField)) != null ? _d : this.getFolderSpecificSetting(file.path, "borderRadius")) != null ? _e : this.settings.borderRadius) != null ? _f : 17;
11691186
bannerDiv.style.setProperty("--pixel-banner-radius", `${borderRadius}px`);
11701187
bannerDiv.style.display = "block";
1171-
if (inputType === "keyword" && this.settings.showPinIcon) {
1172-
addPinIcon(viewContent, imageUrl, this);
1173-
} else {
1174-
const existingPins = viewContent.querySelectorAll(".pin-icon");
1175-
existingPins.forEach((pin) => pin.remove());
1188+
if (inputType === "keyword" && this.settings.showPinIcon && pinIcon) {
1189+
pinIcon.style.display = "block";
1190+
pinIcon.onclick = async () => {
1191+
try {
1192+
await handlePinIconClick(imageUrl, this);
1193+
} catch (error) {
1194+
console.error("Error pinning image:", error);
1195+
new import_obsidian3.Notice("\u{1F62D} Failed to pin the image.");
1196+
}
1197+
};
1198+
} else if (pinIcon) {
1199+
pinIcon.style.display = "none";
11761200
}
11771201
}
11781202
} else {
11791203
bannerDiv.style.display = "none";
1204+
if (pinIcon) {
1205+
pinIcon.style.display = "none";
1206+
}
11801207
this.loadedImages.delete(file.path);
11811208
this.lastKeywords.delete(file.path);
11821209
this.applyContentStartPosition(viewContent, 0);
@@ -1576,43 +1603,16 @@ function getFrontmatterValue(frontmatter, fieldNames) {
15761603
}
15771604
return void 0;
15781605
}
1579-
function addPinIcon(noteElement, imageUrl, plugin) {
1580-
const existingPins = noteElement.querySelectorAll(".pin-icon");
1581-
existingPins.forEach((pin) => pin.remove());
1582-
const pinIcon = document.createElement("div");
1583-
pinIcon.className = "pin-icon";
1584-
pinIcon.style.position = "absolute";
1585-
pinIcon.style.top = "40px";
1586-
pinIcon.style.left = "5px";
1587-
pinIcon.style.fontSize = "1.5em";
1588-
pinIcon.style.cursor = "pointer";
1589-
pinIcon.innerHTML = "\u{1F4CC}";
1590-
pinIcon.addEventListener("click", async () => {
1591-
try {
1592-
await handlePinIconClick(imageUrl, plugin);
1593-
} catch (error) {
1594-
console.error("Error pinning image:", error);
1595-
new import_obsidian3.Notice("\u{1F62D} Failed to pin the image.");
1596-
}
1597-
});
1598-
noteElement.appendChild(pinIcon);
1599-
}
16001606
async function handlePinIconClick(imageUrl, plugin) {
1601-
console.log("\u{1F3AF} Starting pin process...");
16021607
const imageBlob = await fetchImage(imageUrl);
1603-
console.log("\u{1F4E5} Image fetched successfully");
16041608
const { initialPath, file } = await saveImageLocally(imageBlob, plugin);
1605-
console.log("\u{1F4BE} Initial save complete:", { initialPath, file });
1606-
console.log("\u{1F440} Waiting for potential file rename...");
16071609
const finalPath = await waitForFileRename(file, plugin);
16081610
if (!finalPath) {
16091611
console.error("\u274C Failed to resolve valid file path");
16101612
new import_obsidian3.Notice("Failed to save image - file not found");
16111613
return;
16121614
}
1613-
console.log("\u2705 File path resolved:", finalPath);
16141615
await updateNoteFrontmatter(finalPath, plugin);
1615-
console.log("\u{1F4DD} Frontmatter updated");
16161616
hidePinIcon();
16171617
}
16181618
async function fetchImage(url) {
@@ -1738,18 +1738,13 @@ var SaveImageModal = class extends import_obsidian3.Modal {
17381738
async function waitForFileRename(file, plugin) {
17391739
return new Promise((resolve) => {
17401740
const initialPath = file.path;
1741-
const initialFolder = plugin.settings.pinnedImageFolder;
1742-
console.log("\u{1F50D} Starting file watch for:", initialPath);
17431741
let timeoutId;
17441742
let renamedPath = null;
17451743
const validatePath = async (path) => {
17461744
if (!path) return false;
17471745
return await plugin.app.vault.adapter.exists(path);
17481746
};
17491747
const handleRename = async (theFile) => {
1750-
console.log("\u{1F4C2} Rename detected:", {
1751-
theFile: theFile == null ? void 0 : theFile.path
1752-
});
17531748
if (theFile == null ? void 0 : theFile.path) {
17541749
renamedPath = theFile == null ? void 0 : theFile.path;
17551750
}
@@ -1759,27 +1754,17 @@ async function waitForFileRename(file, plugin) {
17591754
};
17601755
plugin.app.vault.on("rename", handleRename);
17611756
timeoutId = setTimeout(async () => {
1762-
console.log("\u23F0 Timeout reached, checking paths in order...");
17631757
cleanup();
1764-
console.log("Checking paths:", {
1765-
renamedPath,
1766-
initialPath
1767-
});
17681758
if (renamedPath) {
17691759
const exists = await validatePath(renamedPath);
1770-
console.log("renamedPath exists:", exists);
17711760
if (exists) {
1772-
console.log("\u2705 Using renamedPath:", renamedPath);
17731761
return resolve(renamedPath);
17741762
}
17751763
}
17761764
const initialExists = await validatePath(initialPath);
1777-
console.log("initialPath exists:", initialExists);
17781765
if (initialExists) {
1779-
console.log("\u2705 Using initialPath:", initialPath);
17801766
return resolve(initialPath);
17811767
}
1782-
console.log("\u274C No valid path found");
17831768
resolve(null);
17841769
}, 1500);
17851770
});

example-vault/pixel-banner-example/.obsidian/plugins/pexels-banner/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "pexels-banner",
33
"name": "Pixel Banner",
4-
"version": "2.5.5",
4+
"version": "2.5.6",
55
"minAppVersion": "1.6.0",
66
"description": "Apply an image from various sources as a banner to your notes.",
77
"author": "Justin Parker",

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "pexels-banner",
33
"name": "Pixel Banner",
4-
"version": "2.5.5",
4+
"version": "2.5.6",
55
"minAppVersion": "1.6.0",
66
"description": "Apply an image from various sources as a banner to your notes.",
77
"author": "Justin Parker",

0 commit comments

Comments
 (0)