mirror of
https://github.com/alberti42/obsidian-plugins-annotations.git
synced 2026-07-22 10:10:24 +00:00
Gray out placeholders
This commit is contained in:
parent
4d48790965
commit
044ade629c
2 changed files with 42 additions and 12 deletions
42
src/main.ts
42
src/main.ts
|
|
@ -96,12 +96,33 @@ export default class PluginComment extends Plugin {
|
|||
comment_container.appendChild(label);
|
||||
|
||||
const comment = document.createElement('div');
|
||||
comment.className = 'plugin-comment';
|
||||
comment.className = 'plugin-comment-annotation';
|
||||
comment.contentEditable = 'true';
|
||||
comment.innerText = this.annotations[pluginId] || `Add your personal comment about '${pluginName}' here...`;
|
||||
const placeholder = `Add your personal comment about '${pluginName}' here...`;
|
||||
let isPlaceholder = this.annotations[pluginId] ? false : true;
|
||||
const initialText = this.annotations[pluginId] || placeholder;
|
||||
|
||||
comment_container.addEventListener('click', (event) => {
|
||||
event.stopPropagation();
|
||||
if(isPlaceholder) {
|
||||
comment.addClass('plugin-comment-placeholder');
|
||||
}
|
||||
|
||||
comment.innerText = initialText;
|
||||
|
||||
// Remove placeholder class when user starts typing
|
||||
comment.addEventListener('focus', () => {
|
||||
if (isPlaceholder) {
|
||||
comment.innerText = '';
|
||||
comment.classList.remove('plugin-comment-placeholder');
|
||||
isPlaceholder = false;
|
||||
}
|
||||
});
|
||||
|
||||
comment.addEventListener('blur', () => {
|
||||
if (comment.innerText.trim() === '') {
|
||||
comment.innerText = placeholder;
|
||||
comment.classList.add('plugin-comment-placeholder');
|
||||
isPlaceholder = true;
|
||||
}
|
||||
});
|
||||
|
||||
// Prevent click event propagation to parent
|
||||
|
|
@ -111,8 +132,16 @@ export default class PluginComment extends Plugin {
|
|||
|
||||
// Save the comment on input change
|
||||
comment.addEventListener('input', () => {
|
||||
this.annotations[pluginId] = comment.innerText;
|
||||
saveAnnotations(this.app.vault, this.annotations);
|
||||
if (comment.innerText.trim() === '') {
|
||||
delete this.annotations[pluginId];
|
||||
comment.classList.add('plugin-comment-placeholder');
|
||||
isPlaceholder = true;
|
||||
} else {
|
||||
this.annotations[pluginId] = comment.innerText;
|
||||
comment.classList.remove('plugin-comment-placeholder');
|
||||
isPlaceholder = false;
|
||||
}
|
||||
saveAnnotations(this.app.vault, this.annotations);
|
||||
});
|
||||
|
||||
comment_container.appendChild(comment);
|
||||
|
|
@ -124,6 +153,7 @@ export default class PluginComment extends Plugin {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
onunload() {
|
||||
console.log('Unloading Plugin Comment');
|
||||
|
||||
|
|
|
|||
|
|
@ -11,18 +11,18 @@
|
|||
box-sizing: border-box; /* Ensure padding is included in the element's total width and height */
|
||||
}
|
||||
|
||||
.plugin-comment-annotation.plugin-comment-placeholder {
|
||||
color: #CCCCCC; /* Standard placeholder color */
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
/* Additional styles for consistency */
|
||||
.plugin-comment-label {
|
||||
padding-top: 5px;
|
||||
}
|
||||
|
||||
|
||||
.plugin-comment-annotation {
|
||||
padding-top: 5px;
|
||||
|
||||
font-style: italic;
|
||||
width: 100%;
|
||||
margin-top: 5px;
|
||||
border: 1px solid var(--background-modifier-border);
|
||||
padding: 5px;
|
||||
font-style: italic;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue