@@ -2039,8 +2039,59 @@ function RemoteFunctions(config = {}) {
20392039 color: #ff6b6b !important;
20402040 font-size: 14px !important;
20412041 }
2042+
2043+ .phoenix-ribbon-header {
2044+ position: absolute !important;
2045+ top: -20px !important;
2046+ left: 0 !important;
2047+ right: 0 !important;
2048+ display: flex !important;
2049+ justify-content: space-between !important;
2050+ align-items: center !important;
2051+ padding: 0 20px !important;
2052+ }
2053+
2054+ .phoenix-ribbon-search {
2055+ display: flex !important;
2056+ align-items: center !important;
2057+ gap: 8px !important;
2058+ background: rgba(0,0,0,0.5) !important;
2059+ padding: 5px 10px !important;
2060+ border-radius: 5px !important;
2061+ }
2062+
2063+ .phoenix-ribbon-search input {
2064+ background: transparent !important;
2065+ border: none !important;
2066+ outline: none !important;
2067+ color: white !important;
2068+ width: 200px !important;
2069+ }
2070+
2071+ .phoenix-ribbon-search-btn {
2072+ background: none !important;
2073+ border: none !important;
2074+ color: #6aa9ff !important;
2075+ cursor: pointer !important;
2076+ }
2077+
2078+ .phoenix-ribbon-close {
2079+ background: rgba(0,0,0,0.5) !important;
2080+ border: none !important;
2081+ color: white !important;
2082+ cursor: pointer !important;
2083+ padding: 5px 8px !important;
2084+ border-radius: 3px !important;
2085+ }
20422086 </style>
20432087 <div class="phoenix-image-ribbon">
2088+ <div class="phoenix-ribbon-header">
2089+ <div class="phoenix-ribbon-search">
2090+ <input type="text" placeholder="Search images..." />
2091+ <button class="phoenix-ribbon-search-btn">Search</button>
2092+ </div>
2093+ <button class="phoenix-ribbon-close">✕</button>
2094+ </div>
20442095 <div class="phoenix-ribbon-nav left">‹</div>
20452096 <div class="phoenix-ribbon-container">
20462097 <div class="phoenix-ribbon-strip">
@@ -2054,8 +2105,9 @@ function RemoteFunctions(config = {}) {
20542105 ` ;
20552106 } ,
20562107
2057- _fetchImages : function ( ) {
2058- const apiUrl = 'https://images.phcode.dev/api/images/search?q=sunshine&per_page=10' ;
2108+ _fetchImages : function ( searchQuery = 'sunshine' ) {
2109+ const apiUrl = `https://images.phcode.dev/api/images/search?q=${ encodeURIComponent ( searchQuery ) } &per_page=10` ;
2110+ this . _showLoading ( ) ;
20592111
20602112 fetch ( apiUrl )
20612113 . then ( response => {
@@ -2077,6 +2129,56 @@ function RemoteFunctions(config = {}) {
20772129 } ) ;
20782130 } ,
20792131
2132+ _showLoading : function ( ) {
2133+ const rowElement = this . _shadow . querySelector ( '.phoenix-ribbon-row' ) ;
2134+ if ( ! rowElement ) { return ; }
2135+
2136+ rowElement . innerHTML = 'Loading images...' ;
2137+ rowElement . className = 'phoenix-ribbon-row phoenix-ribbon-loading' ;
2138+ } ,
2139+
2140+ _attachEventHandlers : function ( ) {
2141+ const searchInput = this . _shadow . querySelector ( '.phoenix-ribbon-search input' ) ;
2142+ const searchButton = this . _shadow . querySelector ( '.phoenix-ribbon-search-btn' ) ;
2143+ const closeButton = this . _shadow . querySelector ( '.phoenix-ribbon-close' ) ;
2144+
2145+ if ( searchInput && searchButton ) {
2146+ const performSearch = ( e ) => {
2147+ e . stopPropagation ( ) ;
2148+ const query = searchInput . value . trim ( ) ;
2149+ if ( query ) {
2150+ this . _fetchImages ( query ) ;
2151+ }
2152+ } ;
2153+
2154+ searchButton . addEventListener ( 'click' , performSearch ) ;
2155+ searchInput . addEventListener ( 'keydown' , ( e ) => {
2156+ if ( e . key === 'Enter' ) {
2157+ performSearch ( e ) ;
2158+ }
2159+ } ) ;
2160+
2161+ searchInput . addEventListener ( 'click' , ( e ) => {
2162+ e . stopPropagation ( ) ;
2163+ } ) ;
2164+ }
2165+
2166+ if ( closeButton ) {
2167+ closeButton . addEventListener ( 'click' , ( e ) => {
2168+ e . stopPropagation ( ) ;
2169+ this . remove ( ) ;
2170+ } ) ;
2171+ }
2172+
2173+ // Prevent clicks anywhere inside the ribbon from bubbling up
2174+ const ribbonContainer = this . _shadow . querySelector ( '.phoenix-image-ribbon' ) ;
2175+ if ( ribbonContainer ) {
2176+ ribbonContainer . addEventListener ( 'click' , ( e ) => {
2177+ e . stopPropagation ( ) ;
2178+ } ) ;
2179+ }
2180+ } ,
2181+
20802182 _renderImages : function ( images ) {
20812183 const rowElement = this . _shadow . querySelector ( '.phoenix-ribbon-row' ) ;
20822184 if ( ! rowElement ) { return ; }
@@ -2113,7 +2215,7 @@ function RemoteFunctions(config = {}) {
21132215
21142216 this . _style ( ) ;
21152217 window . document . body . appendChild ( this . body ) ;
2116-
2218+ this . _attachEventHandlers ( ) ;
21172219 this . _fetchImages ( ) ;
21182220 } ,
21192221
@@ -2589,9 +2691,12 @@ function RemoteFunctions(config = {}) {
25892691
25902692 // if the image is an element we show the image ribbon gallery
25912693 if ( element && element . tagName . toLowerCase ( ) === 'img' ) {
2694+ event . preventDefault ( ) ;
2695+ event . stopPropagation ( ) ;
2696+ event . stopImmediatePropagation ( ) ;
2697+
25922698 _imageRibbonGallery = new ImageRibbonGallery ( element ) ;
2593- } else { // when any other element is clicked we close the ribbon
2594- dismissImageRibbonGallery ( ) ;
2699+ return ;
25952700 }
25962701 }
25972702
0 commit comments