@ideal-postcodes/postcode-lookup
Version:
UK Postcode Lookup plugin from Ideal Postcodes
45 lines (44 loc) • 1.31 kB
JavaScript
/**
* @module Setup
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.controllers = exports.setup = void 0;
const controller_1 = require("./controller");
/**
* Creates Postcode lookup field and button when called on <div>
*
* First argument `context` is a query selector string which designates where on the DOM the plugin will be instantiated
*
* Second argument `config` allows for advanced configuration of the plugin
*
* When invoked, an instance of the Postcode Lookup controller is stored in contollers
*
* Returns an instance of Postcode Lookup controller unless `checkKey: true`. If key checking is enabled, controller can be accessed by the `onLoaded` callback
*
* @example
*
*```javascript
* PostcodeLookup.setup({
* context: "#container",
* apiKey: "foo",
* output_fields: {
* line_1: "#address_line_1",
* line_2: "#address_line_2",
* line_3: "#address_line_3",
* post_town: "#post_town",
* postcode: "#postcode",
* }
* });
*```
*/
const setup = (config) => {
const controller = new controller_1.Controller(config);
exports.controllers.push(controller);
return controller;
};
exports.setup = setup;
/**
* Caches all instances of the plugin created via `setup`
*/
exports.controllers = [];
;