Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor({
el = null, value, maxItems = 10, itemTemplate = ITEM_TEMPLATE,
geoLocate = true, apiRoot = 'https://api.teleport.org/api', apiVersion = 1,
embeds = 'city:country,city:admin1_division,city:timezone/tz:offsets-now,city:urban_area',
} = {}) {
events(this);
const elem = (typeof el === 'string') ? document.querySelector(el) : el;
this.setupInput(elem);
assign(this, {
maxItems, geoLocate, apiRoot, apiVersion, itemTemplate, embeds, results: [],
_activeIndex: 0, _cache: {}, _query: this.el.value, value,
});
// Prefetch results
if (this.value && this.value.title) {
this.query = this.value.title;
} else if (this.query) {
this.fetchResults(() => {
this.value = this.getResultByTitle(this.query);
this.emit('change', this.value);
});
}
this.getCities = debounce(this.getCities, 200);
return this;
refreshEvents: ['resize', 'karl:element#header:classToggled'],
dropdownListClassName: 'k-PlatformSwitch k-PlatformSwitch--withoutBorderTop',
dropdownContent: ,
onToggle: function() {
// Example event to trigger
const event = document.createEvent('Event')
event.initEvent('karl:platformSwitch:toggle', true, true)
window.dispatchEvent(event)
}
}
// Unlogged header dropdown
const unloggedPlatformSwitchProps = objectAssign(
{ positionedWith: () => document.getElementById('header') },
platformSwitchProps
)
const KarlUnloggedHeaderPlatformSwitch = defaultProps(
Dropdown,
unloggedPlatformSwitchProps
)
// Logged header dropdowns
const loggedPlatformSwitchProps = objectAssign(
{ positionedWith: () => document.getElementById('header-logged') },
platformSwitchProps
)
const KarlLoggedHeaderPlatformSwitch = defaultProps(
Dropdown,
loggedPlatformSwitchProps
import browserSync from 'browser-sync';
const bs = browserSync.create();
const gp = gulpLoadPlugins();
import pkg from './package.json';
const BANNER = `/*! ${pkg.name} - v${pkg.version} | ${pkg.homepage} | ${pkg.license} */
`;
// ----------------------------- BROWSERIFY ------------------------------------
// Browserify params
const browserifyArgs = assign({}, watchify.args, {
standalone: 'TeleportAutocomplete',
transform: [
"babelify",
["ractivate", { "extensions": [".rac"] }]
],
debug: true,
});
// Browserify bundle command
const rebundle = (bundler, entry) => {
return bundler.bundle()
.on('error', gp.util.log)
.pipe(source(entry))
.pipe(gp.derequire())
.pipe(buffer())
.pipe(gp.rename({
window.dispatchEvent(event)
}
}
// Unlogged header dropdown
const unloggedPlatformSwitchProps = objectAssign(
{ positionedWith: () => document.getElementById('header') },
platformSwitchProps
)
const KarlUnloggedHeaderPlatformSwitch = defaultProps(
Dropdown,
unloggedPlatformSwitchProps
)
// Logged header dropdowns
const loggedPlatformSwitchProps = objectAssign(
{ positionedWith: () => document.getElementById('header-logged') },
platformSwitchProps
)
const KarlLoggedHeaderPlatformSwitch = defaultProps(
Dropdown,
loggedPlatformSwitchProps
)
const userMenuDropdownList = [
<a href="#">Mon profil</a>,
<a href="#">Mes projets</a>,
<a href="#">Mes contributions</a>,
<a href="#">Mes messages</a>,
static init(el, options = {}) {
const opt = (typeof el === 'string' || el instanceof HTMLInputElement) ? assign(options, { el }) : el;
return new TeleportAutocomplete(opt);
}
onrender() {
const { maxItems, apiRoot, geoLocate, itemTemplate, embeds, value } = this.get();
this.ac = new Autocomplete(assign({ el: this.find('input') }, {
maxItems, apiRoot, geoLocate, itemTemplate, embeds, value,
}));
this.ac.on('change', val => this.set('value', val));
this.ac.on('querychange', query => this.set('query', query));
},
parseCity(res) {
const city = res.embedded('location:nearest-city') || res.embedded('city:item');
city.country = city.embedded('city:country');
city.admin1_division = city.embedded('city:admin1_division');
city.timezone = city.embedded('city:timezone');
city.urban_area = city.embedded('city:urban_area');
const { full_name: fullName, name, geoname_id: geonameId, population,
location: { latlon: { latitude, longitude } } } = city;
const { matching_full_name: title = fullName } = res;
const result = { title, name, geonameId, latitude, longitude, population };
if (city.country) assign(result, { country: city.country.name });
if (city.admin1_division) {
const { name: admin1Division, geonames_admin1_code: admin1DivisionCode } = city.admin1_division;
assign(result, { admin1Division, admin1DivisionCode });
}
if (city.timezone) {
const tzNow = city.timezone.embedded('tz:offsets-now');
assign(result, { tzOffsetMinutes: tzNow.total_offset_min });
}
if (city.urban_area) {
const { slug: uaSlug, name: uaName, ua_id: uaId, teleport_city_url: uaCityUrl } = city.urban_area;
assign(result, { uaName, uaId, uaCityUrl, uaSlug });
}
return result;
city.country = city.embedded('city:country');
city.admin1_division = city.embedded('city:admin1_division');
city.timezone = city.embedded('city:timezone');
city.urban_area = city.embedded('city:urban_area');
const { full_name: fullName, name, geoname_id: geonameId, population,
location: { latlon: { latitude, longitude } } } = city;
const { matching_full_name: title = fullName } = res;
const result = { title, name, geonameId, latitude, longitude, population };
if (city.country) assign(result, { country: city.country.name });
if (city.admin1_division) {
const { name: admin1Division, geonames_admin1_code: admin1DivisionCode } = city.admin1_division;
assign(result, { admin1Division, admin1DivisionCode });
}
if (city.timezone) {
const tzNow = city.timezone.embedded('tz:offsets-now');
assign(result, { tzOffsetMinutes: tzNow.total_offset_min });
}
if (city.urban_area) {
const { slug: uaSlug, name: uaName, ua_id: uaId, teleport_city_url: uaCityUrl } = city.urban_area;
assign(result, { uaName, uaId, uaCityUrl, uaSlug });
}
return result;
}
}
const tasks = ['js/autocomplete.js', 'js/autocomplete-ractive.js'].map(entry => {
const bundler = watchify(browserify(assign(browserifyArgs, { entries: [entry] })));
bundler.on('update', rebundle.bind(this, bundler, entry));
bundler.on('log', gp.util.log);
return rebundle(bundler, entry);
});