Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <script defer src="https://app.glean.com/embedded-search-latest.min.js"></script>

<div class="header">Sidebar search</div>
<input id="sidebar-search-box" placeholder="search" type="text" />

<div class="header">Full search experience</div>
<div class="row">
  <input id="search-box" placeholder="search" type="text" />
  &nbsp;&nbsp;<button id="prepopulate">Prepopulate query</button>
  &nbsp;&nbsp;Latest search: <div id="latest-search"></div>
</div>

<div class="header">Autocomplete only</div>
<div id="autocomplete-container"></div>
<div id="autocomplete-output"></div> 
<br />
<button id="autocomplete-focus-button">Click me to focus on autocomplete</button>

<div class="header">Search results only</div>
<div class="row">
  <input id="native-search-box" placeholder="search" type="text" />
  Current datasource:&nbsp;<span id="datasource-label">All</span>
</div>
<div id="search-results" />
              
            
!

CSS

              
                #autocomplete-container {
  display: block;
  position: relative;
  height: 60px;
  width: 500px;
}

#native-search-box {
  margin-right: 10px;
}

#search-results {
  width: 100%;
  height: 400px;
}

.header {
  font-size: 20px;
  margin: 30px 0 10px;
}

.row {
  display: flex;
}

#chat-container {
  height: 800px;
  width: 750px;
  max-width: 100%;
  margin-bottom: 48px;
}
              
            
!

JS

              
                addEventListener("DOMContentLoaded", () => {

  // Modal based full search experience
  const attach = (query = undefined) => {
    EmbeddedSearch.attach(document.getElementById("search-box"), {
      domainsToOpenInCurrentTab: ['github.com'],
      onSearch: (query) => {
        document.getElementById("latest-search").innerText = query
      },
      query
    });
  }
  
  // Attach modal search to the search input box
  attach()
  
  // Example | Open NSR with a query pre-filled
  document.getElementById("prepopulate").addEventListener('click', (e) => attach("test query"))

  // Autocomplete only
  const autocomplete = EmbeddedSearch.renderSearchBox(document.getElementById("autocomplete-container"), {
    onSearch: (query) => {
      document.getElementById("autocomplete-output").innerText = `Searched for ${query}`
    },
    searchBoxCustomizations: {
      border: '2px solid red',
      borderRadius: 5,
      boxShadow: '0px 0px 10px rgba(0, 255, 0, 0.5)',
      height: 40,
      horizontalMargin: 10,
      verticalMargin: 10
    }
  });
  
  // Example | Externally focus on autocomplete when clicked
  document.getElementById('autocomplete-focus-button').addEventListener('click', () => autocomplete.focus())
  
  // Search results only
  const sb = document.getElementById("native-search-box")
  sb.addEventListener('keydown', (e) => {
    if (e.key === 'Enter') {
      EmbeddedSearch.renderSearchResults( 
        document.getElementById("search-results"),
        {
          query: sb.value,
          onSearch: (query) => {
            console.log('ON SEARCH', query)
            document.getElementById("native-search-box").value = query
          },
          onDatasourceChange: (datasource) => {
            document.getElementById("datasource-label")
              .innerText = datasource || "All"
          }
        }
      )
    }
  })
  
  // Sidebar search
  const ssb = document.getElementById("sidebar-search-box")
  ssb.addEventListener('keydown', (e) => {
    if (e.key === 'Enter') {
      const query = ssb.value
      EmbeddedSearch.openSidebar({
        query,
        recommendationsUrl: query.startsWith('http') ? query : undefined
      })
    }
  })
});
              
            
!
999px

Console