UNPKG

@instawork/design-system

Version:

The design system for Instawork's web apps

50 lines 1.69 kB
import * as $ from 'jquery'; import { isJQueryComponentPlugin } from './custom-component-types'; function doInitComponents($root) { if ($.fn.iwNestedInput) { $root.iwNestedInput(); } if ($.fn.iwOtherField) { $root.iwOtherField(); } if ($.fn.iwSelectAll) { $root.iwSelectAll(); } // IMPORTANT: iwTimeInput and iwTimeSelector must be initialized before iwTimeRange, otherwise iwTimeRange will break // since it will be looking for component instances that won't exist yet if ($.fn.iwTimeInput) { $root.iwTimeInput(); } if ($.fn.iwTimeSelector) { $root.iwTimeSelector(); } // IMPORTANT: iwTimeRange must be initialized before iwTimeRangeDisplay, otherwise iwTimeRangeDisplay will break // since it will be looking for component instances that won't exist yet if ($.fn.iwTimeRange) { $root.iwTimeRange(); } if ($.fn.iwTimeRangeDisplay) { $root.iwTimeRangeDisplay(); } } function getOverloadArgs($rootOrComponent, components) { if (isJQueryComponentPlugin($rootOrComponent)) { components.unshift($rootOrComponent); return [undefined, components]; } return [$rootOrComponent, components]; } export function initComponents($rootOrComponent, ...components) { // handle function overloads const [$root, allComponents] = getOverloadArgs($rootOrComponent, components); for (const component of allComponents) { component.loadPlugin(); } if ($root) { doInitComponents($root); } else { $(() => doInitComponents($('body'))); } } //# sourceMappingURL=init-components.js.map