1/** 2 * PrimeFaces Extensions LightSwitch Widget. 3 * 4 * @author Jasper de Vries <[email protected]> 5 * @since 10.0 6 */ 7PrimeFaces.widget.ExtLightSwitch = class extends PrimeFaces.widget.BaseWidget { 8 9 /** 10 * Initializes the widget. 11 * 12 * @param {object} 13 * cfg The widget configuration. 14 */ 15 init(cfg) { 16 super.init(cfg); 17 this.id = cfg.id; 18 this.cfg = cfg; 19 this.formId = $(PrimeFaces.escapeClientId(this.cfg.parent)).closest('form').attr('id'); 20 this.selected = cfg.selected; 21 if (cfg.automatic) { 22 this.automatic(); 23 } 24 } 25 26 /** 27 * Automatically set the theme based on the OS setting. 28 */ 29 automatic() { 30 this.changeTheme(PrimeFaces.env.preferredColorSchemeDark ? this.cfg.dark : this.cfg.light); 31 } 32 33 /** 34 * Change to the light theme. 35 */ 36 light() { 37 this.changeTheme(this.cfg.light); 38 } 39 40 /** 41 * Change to the dark theme. 42 */ 43 dark() { 44 this.changeTheme(this.cfg.dark); 45 } 46 47 /** 48 * Toggle between the light and dark theme. 49 */ 50 toggle() { 51 this.changeTheme(this.selected === this.cfg.dark ? this.cfg.light : this.cfg.dark); 52 } 53 54 /** 55 * Change the theme to the one provided, if it is not the selected theme, and sends the theme to the server side. 56 * @param {string} theme to change to. 57 */ 58 changeTheme(theme) { 59 var $this = this; 60 if (theme !== this.selected) { 61 this.selected = theme; 62 var options = {params: [{name: this.id + '_theme', value: theme}]}; 63 if (this.hasBehavior('switch')) { 64 this.callBehavior('switch', options); 65 PrimeFacesExt.changeTheme(theme); 66 } else { 67 options.source = this.id; 68 options.process = this.id; 69 options.update = this.id; 70 options.formId = this.formId; 71 options.oncomplete = function () { 72 PrimeFacesExt.changeTheme(theme); 73 } 74 PrimeFaces.ajax.Request.handle(options); 75 } 76 } 77 } 78 79};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.