PageSourceSearch

https://puckettmachinery.com/wp-content/themes/puckettmachinery/as…/js/components/FxChoices.js?ver=1680468604

js puckettmachinery.com collected 2026-10-09 01:27:41 UTC 2,308 bytes, 108 lines download raw bytes

1( () => {
2    document.addEventListener( 'DOMContentLoaded', () => {
3        if( 'function' !== typeof Choices ) {
4            console.warn( 'ChoicesJS not loaded' )
5        } else {
6            document.querySelectorAll('select').forEach( el => {
7
8                // allow selects to have custom setup
9                if( el.classList.contains( 'js-ignore-choices-auto' ) ) {
10                    return
11                }                
12                
13                const config = {}
14    
15                // add config conditions here
16                config.shouldSort = false
17    
18                new FxChoice( el, config )
19            })
20        }
21    })
22}) ()
23
24
25
26
27class FxChoice {
28
29    constructor( el, config = {} ) {
30        this.el 		= el
31		this.config 	= this.parseConfig( config )
32        
33		this.choices 	= null
34
35		this.setUpChoices()
36        this.formResetFix()
37    }
38
39
40	// slight adjustment to config to support initialization
41	parseConfig( config ) {
42		const self = this
43
44		let origInitCallback
45
46		if( 'function' === typeof config.callbackOnInit ) {
47			origInitCallback = config.callbackOnInit
48		}
49
50		config.callbackOnInit = () => {
51			if( undefined !== origInitCallback ) {
52				origInitCallback()
53			}
54
55			self.setInitStatus( true )
56		}
57
58		return config
59	}
60
61
62    setUpChoices() {
63		const self = this
64
65		// prevents duplicate initialization
66		if( true === self.el.fxChoicesIsInitialized ) {
67			return
68		}
69
70		self.choices = new Choices( self.el, self.config )
71
72		// auto-submit category dropdowns on select
73        if( 'cat' === self.el.id ) {
74            self.el.onchange = null
75
76            self.choices.passedElement.element.addEventListener( 'change', e => {
77				const form = e.target.form
78
79                if( form ) {
80                    form.submit()
81                }
82            })
83        }
84    }
85
86
87    formResetFix() {
88        const self  = this,
89            form    = self.el.form
90
91        if( null !== form && null !== self.choices ) {
92            form.addEventListener( 'reset', () => {
93                self.choices.destroy()
94				self.el.fxChoicesIsInitialized = false
95
96                self.setUpChoices()
97            }, {
98                once: true
99            })
100        }
101    }
102
103
104    setInitStatus( status = false ) {
105        this.el.fxChoicesIsInitialized = status
106    }
107
108}

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.