115 lines
3.7 KiB
JavaScript
115 lines
3.7 KiB
JavaScript
|
/*! DSFR v1.11.2 | SPDX-License-Identifier: MIT | License-Filename: LICENSE.md | restricted use (see terms and conditions) */
|
||
|
|
||
|
(function () {
|
||
|
'use strict';
|
||
|
|
||
|
var config = {
|
||
|
prefix: 'fr',
|
||
|
namespace: 'dsfr',
|
||
|
organisation: '@gouvfr',
|
||
|
version: '1.11.2'
|
||
|
};
|
||
|
|
||
|
var api = window[config.namespace];
|
||
|
|
||
|
var ToggleInput = /*@__PURE__*/(function (superclass) {
|
||
|
function ToggleInput () {
|
||
|
superclass.apply(this, arguments);
|
||
|
}
|
||
|
|
||
|
if ( superclass ) ToggleInput.__proto__ = superclass;
|
||
|
ToggleInput.prototype = Object.create( superclass && superclass.prototype );
|
||
|
ToggleInput.prototype.constructor = ToggleInput;
|
||
|
|
||
|
var prototypeAccessors = { isChecked: { configurable: true } };
|
||
|
var staticAccessors = { instanceClassName: { configurable: true } };
|
||
|
|
||
|
staticAccessors.instanceClassName.get = function () {
|
||
|
return 'ToggleInput';
|
||
|
};
|
||
|
|
||
|
prototypeAccessors.isChecked.get = function () {
|
||
|
return this.node.checked;
|
||
|
};
|
||
|
|
||
|
Object.defineProperties( ToggleInput.prototype, prototypeAccessors );
|
||
|
Object.defineProperties( ToggleInput, staticAccessors );
|
||
|
|
||
|
return ToggleInput;
|
||
|
}(api.core.Instance));
|
||
|
|
||
|
var ToggleStatusLabel = /*@__PURE__*/(function (superclass) {
|
||
|
function ToggleStatusLabel () {
|
||
|
superclass.apply(this, arguments);
|
||
|
}
|
||
|
|
||
|
if ( superclass ) ToggleStatusLabel.__proto__ = superclass;
|
||
|
ToggleStatusLabel.prototype = Object.create( superclass && superclass.prototype );
|
||
|
ToggleStatusLabel.prototype.constructor = ToggleStatusLabel;
|
||
|
|
||
|
var prototypeAccessors = { proxy: { configurable: true },input: { configurable: true } };
|
||
|
var staticAccessors = { instanceClassName: { configurable: true } };
|
||
|
|
||
|
staticAccessors.instanceClassName.get = function () {
|
||
|
return 'ToggleStatusLabel';
|
||
|
};
|
||
|
|
||
|
ToggleStatusLabel.prototype.init = function init () {
|
||
|
this.register(("input[id=\"" + (this.getAttribute('for')) + "\"]"), ToggleInput);
|
||
|
this.update();
|
||
|
this.isSwappingFont = true;
|
||
|
};
|
||
|
|
||
|
prototypeAccessors.proxy.get = function () {
|
||
|
var scope = this;
|
||
|
return Object.assign.call(this, superclass.prototype.proxy, {
|
||
|
update: scope.update.bind(scope)
|
||
|
});
|
||
|
};
|
||
|
|
||
|
prototypeAccessors.input.get = function () {
|
||
|
return this.getRegisteredInstances('ToggleInput')[0];
|
||
|
};
|
||
|
|
||
|
ToggleStatusLabel.prototype.update = function update () {
|
||
|
this.node.style.removeProperty('--toggle-status-width');
|
||
|
var checked = this.input.isChecked;
|
||
|
|
||
|
var style = getComputedStyle(this.node, ':before');
|
||
|
var maxWidth = parseFloat(style.width);
|
||
|
this.input.node.checked = !checked;
|
||
|
|
||
|
var style2 = getComputedStyle(this.node, ':before');
|
||
|
var width = parseFloat(style2.width);
|
||
|
if (width > maxWidth) { maxWidth = width; }
|
||
|
this.input.node.checked = checked;
|
||
|
|
||
|
this.node.style.setProperty('--toggle-status-width', (maxWidth / 16) + 'rem');
|
||
|
};
|
||
|
|
||
|
ToggleStatusLabel.prototype.swapFont = function swapFont (families) {
|
||
|
this.update();
|
||
|
};
|
||
|
|
||
|
Object.defineProperties( ToggleStatusLabel.prototype, prototypeAccessors );
|
||
|
Object.defineProperties( ToggleStatusLabel, staticAccessors );
|
||
|
|
||
|
return ToggleStatusLabel;
|
||
|
}(api.core.Instance));
|
||
|
|
||
|
var ToggleSelector = {
|
||
|
STATUS_LABEL: ("" + (api.internals.ns.selector('toggle__label')) + (api.internals.ns.attr.selector('checked-label')) + (api.internals.ns.attr.selector('unchecked-label')))
|
||
|
};
|
||
|
|
||
|
// import { ToggleInput } from './script/toggle/toggle-input.js';
|
||
|
|
||
|
api.toggle = {
|
||
|
ToggleStatusLabel: ToggleStatusLabel,
|
||
|
ToggleSelector: ToggleSelector
|
||
|
};
|
||
|
|
||
|
api.internals.register(api.toggle.ToggleSelector.STATUS_LABEL, api.toggle.ToggleStatusLabel);
|
||
|
|
||
|
})();
|
||
|
//# sourceMappingURL=toggle.nomodule.js.map
|