This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
npm run eslint # lint src/*.js
npm test # run tests with coverage (mocha + c8)
npm run build # production build (minified JS + CSS + license banner)
npm run prebuild # dev build (unminified JS + CSS)
npm start # dev build + watch mode + local server at :8080Run a single test file:
npx mocha test/spec/smartbanner_spec.jsThe library reads configuration from <meta name="smartbanner:*"> tags in the page and renders a dismissible banner for iOS/Android users.
Source modules (src/):
index.js— entry point; instantiatesSmartBanneronwindow.load. Ifsmartbanner:apimeta is set totrue/yes, exposes the instance atwindow.smartbannerfor manual control; otherwise auto-callspublish().smartbanner.js— main class.publish()renders the banner HTML and callssetContentPosition()to push page content down.exit()removes the banner, restores position, and bakes the close cookie. Emits DOM events:smartbanner.init,smartbanner.view,smartbanner.exit,smartbanner.clickout.optionparser.js— reads all<meta>tags, filters those withname="smartbanner:*", and returns options as camelCase keys (e.g.button-url-apple→buttonUrlApple).detector.js— UA-based platform detection (android/ios). iOS 13+ iPad detection usesmaxTouchPointsbecause the UA reports as desktop Safari. Also detects jQuery Mobile pages and selects the appropriate wrapper element (.ui-pagevshtml) for content positioning.bakery.js— manages thesmartbanner_exited=1cookie.bake(hideTtl, hidePath)sets it;bakedgetter checks it. WhenhideTtlis falsy the cookie has no expiry (session-only).
Build pipeline: esbuild bundles src/index.js → dist/smartbanner[.min].js targeting ES2015; Sass compiles src/smartbanner.scss → dist/smartbanner[.min].css. add-banner prepends the license header from banner.tmpl after minification.
Tests: Mocha + Chai running in Node.js with JSDOM to simulate a browser environment. Tests set up a DOM string (including relevant meta tags and UA overrides) and import source modules directly as ESM.
ESLint enforces: 2-space indent, single quotes, semicolons, strict equality (===), max 1 consecutive blank line.