|
| 1 | +# Project: OpenStack Search Bar Widget |
| 2 | + |
| 3 | +**Last Updated:** 2026-03-11 |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Embedded search bar widget for OpenStack sites. Provides search with autocomplete suggestions and paginated results via a popup overlay. Designed to be embedded on any page via a single `<div>` + script tag. |
| 8 | + |
| 9 | +## Technology Stack |
| 10 | + |
| 11 | +- **Language:** JavaScript (ES5, no transpilation) |
| 12 | +- **Module System:** RequireJS (AMD) with `almond` for production builds |
| 13 | +- **UI Framework:** Ractive.js 0.10.x (reactive templates with mustache syntax) |
| 14 | +- **DOM / AJAX:** jQuery 3.x (`$.noConflict()` mode — always use `$` from the AMD module, never global) |
| 15 | +- **Build Tool:** RequireJS Optimizer (`r.js`) via Makefile |
| 16 | +- **Icons:** Font Awesome 4.7 (loaded externally by the embedding page) |
| 17 | +- **Tests:** None configured |
| 18 | + |
| 19 | +## Directory Structure |
| 20 | + |
| 21 | +``` |
| 22 | +├── app/app.js # Main widget logic (search, suggestions, pagination) |
| 23 | +├── config.js # RequireJS path configuration |
| 24 | +├── embed.js # Entry point — loads jQuery + app, calls app.init() |
| 25 | +├── embed.build.js # r.js optimizer build config |
| 26 | +├── embed.min.js # Built/minified output (committed) |
| 27 | +├── css/widget-styles.css |
| 28 | +├── templates/template.html # Ractive template (mustache syntax) |
| 29 | +├── example/index.html # Test page for the widget |
| 30 | +└── Makefile |
| 31 | +``` |
| 32 | + |
| 33 | +## Key Files |
| 34 | + |
| 35 | +- **Entry Point:** `embed.js` → requires `app/app.js` → calls `app.init()` |
| 36 | +- **Build Config:** `embed.build.js` (r.js optimizer settings) |
| 37 | +- **RequireJS Paths:** `config.js` (maps module names to `node_modules/` paths) |
| 38 | +- **Output:** `embed.min.js` (self-contained bundle with almond loader) |
| 39 | + |
| 40 | +## Development Commands |
| 41 | + |
| 42 | +| Task | Command | |
| 43 | +|------|---------| |
| 44 | +| Install deps | `make init` (or `npm install`) | |
| 45 | +| Build CSS | `make css` | |
| 46 | +| Build JS | `make js` | |
| 47 | +| Build all | `make` | |
| 48 | +| Test locally | Open `example/index.html` in a browser after building | |
| 49 | + |
| 50 | +## Architecture |
| 51 | + |
| 52 | +### Embedding |
| 53 | + |
| 54 | +Host pages add a `<div class="openstack-search-bar">` with data attributes and load `embed.min.js`: |
| 55 | + |
| 56 | +```html |
| 57 | +<div class="openstack-search-bar" data-baseUrl="search.openstack.org" data-context="www-openstack"></div> |
| 58 | +``` |
| 59 | + |
| 60 | +- `data-baseUrl` — API host (default: `search.openstack.org`) |
| 61 | +- `data-context` — search context/scope (default: `www-openstack`) |
| 62 | + |
| 63 | +### API Endpoints |
| 64 | + |
| 65 | +All requests go to `https://{baseUrl}/api/public/v1/`: |
| 66 | + |
| 67 | +| Endpoint | Purpose | |
| 68 | +|----------|---------| |
| 69 | +| `search/{context}/{term}?page=N&page_size=N` | Full search with pagination | |
| 70 | +| `suggestions/{context}/{term}` | Autocomplete suggestions | |
| 71 | + |
| 72 | +### Widget Lifecycle |
| 73 | + |
| 74 | +1. `embed.min.js` loads → RequireJS resolves AMD modules |
| 75 | +2. `app.init()` finds all `.openstack-search-bar` elements |
| 76 | +3. Each element gets its own Ractive instance with search/suggestion/pagination state |
| 77 | +4. CSS is injected into `<head>` at runtime |
0 commit comments