@@ -146,26 +146,34 @@ window.createPopup = async function() {
146
146
top : '20px' ,
147
147
right : '20px' ,
148
148
zIndex : '2147483647' ,
149
- width : '550px' ,
150
149
background : 'transparent' ,
151
150
borderRadius : '21px' ,
152
151
border : '0px' ,
153
152
margin : '0px' ,
154
153
padding : '0px' ,
155
154
transform : 'translateY(0px)' ,
156
155
boxSizing : 'border-box' ,
156
+ width : '550px' , // Initial width
157
+ height : '200px' , // Initial height
158
+ transition : 'height 0.2s ease-out' // Smooth height transitions
157
159
} ) ;
158
160
159
161
document . body . appendChild ( iframe ) ;
160
162
163
+ // Function to resize iframe based on content
164
+ function resizeIframe ( ) {
165
+ const doc = iframe . contentDocument || iframe . contentWindow . document ;
166
+ const content = doc . querySelector ( '.archive-box-popup' ) ;
167
+ if ( content ) {
168
+ const height = content . offsetHeight ;
169
+ const dropdown = doc . querySelector ( '.ARCHIVEBOX__autocomplete-dropdown' ) ;
170
+ const dropdownHeight = dropdown && dropdown . style . display !== 'none' ? dropdown . offsetHeight : 0 ;
171
+ iframe . style . height = ( height + dropdownHeight + 20 ) + 'px' ; // Add padding
172
+ }
173
+ }
174
+
161
175
// Create popup content inside iframe
162
176
const doc = iframe . contentDocument || iframe . contentWindow . document ;
163
-
164
- // iframe.addEventListener('load', () => {
165
- // // resize iframe to fit content
166
- // iframe.style.width = doc.body.scrollWidth + 'px';
167
- // iframe.style.height = doc.body.scrollHeight + 'px';
168
- // });
169
177
170
178
// Add styles to iframe
171
179
const style = doc . createElement ( 'style' ) ;
@@ -176,20 +184,21 @@ window.createPopup = async function() {
176
184
font-family: system-ui, -apple-system, sans-serif;
177
185
font-size: 14px;
178
186
width: 100%;
187
+ height: auto;
188
+ overflow: visible;
179
189
}
180
190
181
191
.archive-box-popup {
182
- height: 65px ;
183
- background: linear-gradient(45deg, #bf7070, rgb(200 50 50)) ;
192
+ min- height: 90px ;
193
+ background: #bf7070;
184
194
margin: 0px;
185
- padding: 0px ;
195
+ padding: 6px ;
186
196
color: white;
187
- padding: 26px 13px 10px;
188
197
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
189
198
font-family: system-ui, -apple-system, sans-serif;
190
- transition: display 0.3s ease-in-out;
191
- animation: slideDown 0.3s ease-in-out forwards;
199
+ transition: all 0.2s ease-out;
192
200
}
201
+
193
202
.archive-box-popup:hover {
194
203
animation: slideDown -0.3s ease-in-out forwards;
195
204
opacity: 1;
@@ -350,11 +359,11 @@ window.createPopup = async function() {
350
359
.ARCHIVEBOX__autocomplete-dropdown {
351
360
background: white;
352
361
border: 1px solid #ddd;
353
- border-radius: 0 0 4px 4px ;
362
+ border-radius: 0 0 14px 14px ;
354
363
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
355
364
max-height: 200px;
356
365
overflow-y: auto;
357
- z-index: 2147483647 ;
366
+ transition: all 0.2s ease-out ;
358
367
}
359
368
360
369
.ARCHIVEBOX__autocomplete-item {
@@ -376,8 +385,8 @@ window.createPopup = async function() {
376
385
popup . innerHTML = `
377
386
<a href="#" class="options-link" title="Open in ArchiveBox">🏛️</a> <input type="search" placeholder="Add tags + press ⏎ | ⎋ to close">
378
387
<br/>
379
- <div class="ARCHIVEBOX__current-tags"></div>
380
388
<div class="ARCHIVEBOX__tag-suggestions"></div><br/>
389
+ <div class="ARCHIVEBOX__current-tags"></div>
381
390
<small>
382
391
<span class="status-indicator"></span>
383
392
Saved
@@ -452,20 +461,21 @@ window.createPopup = async function() {
452
461
if ( filteredTags . length === 0 ) {
453
462
dropdownContainer . style . display = 'none' ;
454
463
selectedIndex = - 1 ;
455
- return ;
464
+ } else {
465
+ dropdownContainer . innerHTML = filteredTags
466
+ . map ( ( tag , index ) => `
467
+ <div class="ARCHIVEBOX__autocomplete-item ${ index === selectedIndex ? 'selected' : '' } "
468
+ data-tag="${ tag } ">
469
+ ${ tag }
470
+ </div>
471
+ ` )
472
+ . join ( '' ) ;
473
+
474
+ dropdownContainer . style . display = 'block' ;
456
475
}
457
476
458
- // Update dropdown content
459
- dropdownContainer . innerHTML = filteredTags
460
- . map ( ( tag , index ) => `
461
- <div class="ARCHIVEBOX__autocomplete-item ${ index === selectedIndex ? 'selected' : '' } "
462
- data-tag="${ tag } ">
463
- ${ tag }
464
- </div>
465
- ` )
466
- . join ( '' ) ;
467
-
468
- dropdownContainer . style . display = 'block' ;
477
+ // Trigger resize after dropdown visibility changes
478
+ setTimeout ( resizeIframe , 0 ) ;
469
479
}
470
480
471
481
// Handle input changes
@@ -565,6 +575,87 @@ window.createPopup = async function() {
565
575
566
576
input . focus ( ) ;
567
577
console . log ( '+ Showed ArchiveBox popup in iframe' ) ;
578
+
579
+ // Add resize triggers
580
+ const resizeObserver = new ResizeObserver ( ( ) => {
581
+ resizeIframe ( ) ;
582
+ } ) ;
583
+
584
+ // Observe the popup content for size changes
585
+ resizeObserver . observe ( popup ) ;
586
+
587
+ // Additional resize triggers for dynamic content
588
+ async function updateCurrentTags ( ) {
589
+ if ( ! popup_element ) return ;
590
+ const current_tags_div = popup_element . querySelector ( '.ARCHIVEBOX__current-tags' ) ;
591
+ const status_div = popup_element . querySelector ( 'small' ) ;
592
+ const { current_entry } = await getCurrentEntry ( ) ;
593
+
594
+ current_tags_div . innerHTML = current_entry . tags . length
595
+ ? `${ current_entry . tags
596
+ . map ( tag => `<span class="ARCHIVEBOX__tag-badge current" data-tag="${ tag } ">${ tag } </span>` )
597
+ . join ( ' ' ) } `
598
+ : '' ;
599
+
600
+ const result = await sendToArchiveBox ( current_entry . url , current_entry . tags ) ;
601
+ status_div . innerHTML = `
602
+ <span class="status-indicator ${ result . ok ? 'success' : 'error' } "></span>
603
+ ${ result . status }
604
+ ` ;
605
+
606
+ // Add click handlers for removing tags
607
+ current_tags_div . querySelectorAll ( '.tag-badge.current' ) . forEach ( badge => {
608
+ badge . addEventListener ( 'click' , async ( e ) => {
609
+ if ( e . target . classList . contains ( 'current' ) ) {
610
+ const { current_entry, entries } = await getCurrentEntry ( ) ;
611
+ const tag_to_remove = e . target . dataset . tag ;
612
+ current_entry . tags = current_entry . tags . filter ( tag => tag !== tag_to_remove ) ;
613
+ await chrome . storage . local . set ( { entries } ) ;
614
+ await updateCurrentTags ( ) ;
615
+ await updateSuggestions ( ) ;
616
+ }
617
+ } ) ;
618
+ } ) ;
619
+
620
+ resizeIframe ( ) ;
621
+ }
622
+
623
+ async function updateDropdown ( ) {
624
+ const inputValue = input . value . toLowerCase ( ) ;
625
+ const allTags = await getAllTags ( ) ;
626
+
627
+ // Filter tags that match input and aren't already used
628
+ const { current_entry } = await getCurrentEntry ( ) ;
629
+ filteredTags = allTags
630
+ . filter ( tag =>
631
+ tag . toLowerCase ( ) . includes ( inputValue ) &&
632
+ ! current_entry . tags . includes ( tag ) &&
633
+ inputValue
634
+ )
635
+ . slice ( 0 , 5 ) ; // Limit to 5 suggestions
636
+
637
+ if ( filteredTags . length === 0 ) {
638
+ dropdownContainer . style . display = 'none' ;
639
+ selectedIndex = - 1 ;
640
+ } else {
641
+ dropdownContainer . innerHTML = filteredTags
642
+ . map ( ( tag , index ) => `
643
+ <div class="ARCHIVEBOX__autocomplete-item ${ index === selectedIndex ? 'selected' : '' } "
644
+ data-tag="${ tag } ">
645
+ ${ tag }
646
+ </div>
647
+ ` )
648
+ . join ( '' ) ;
649
+
650
+ dropdownContainer . style . display = 'block' ;
651
+ }
652
+
653
+ // Trigger resize after dropdown visibility changes
654
+ setTimeout ( resizeIframe , 0 ) ;
655
+ }
656
+
657
+ // Initial resize
658
+ setTimeout ( resizeIframe , 0 ) ;
568
659
}
569
660
570
661
window . createPopup ( ) ;
0 commit comments