PageSourceSearch

https://swio.lu/themes/custom/losch_theme/assets/js/select.js?v=1

js swio.lu collected 2026-10-01 14:14:41 UTC 4,829 bytes, 153 lines download raw bytes

1function customSelect()
2{
3    var x, i, j, l, ll, selElmnt, a, b, c;
4    /* Look for any elements with the class "custom-select": */
5    x = document.getElementsByClassName( "custom-select" );
6    l = x.length;
7
8    for ( i = 0; i < l; i++ )
9    {
10        // Chech if x contains '.select-selected' and '.select-items' then skip
11
12        if ( x[ i ].querySelector( '.select-selected' ) && x[ i ].querySelector( '.select-items' ) )
13        {
14            continue;
15        }
16
17        selElmnt = x[ i ].getElementsByTagName( "select" )[ 0 ];
18        ll = selElmnt.length;
19        /* For each element, create a new DIV that will act as the selected item: */
20        a = document.createElement( "DIV" );
21        a.setAttribute( "class", "select-selected" );
22        a.innerHTML = selElmnt.options[ selElmnt.selectedIndex ].innerHTML;
23        x[ i ].appendChild( a );
24        /* For each element, create a new DIV that will contain the option list: */
25        b = document.createElement( "DIV" );
26        b.setAttribute( "class", "select-items select-hide" );
27        cat = selElmnt.getAttribute( "id" );
28        b.setAttribute( "id", cat+"-select" );
29
30        for ( j = 1; j < ll; j++ )
31        {
32            /* For each option in the original select element,
33            create a new DIV that will act as an option item: */
34            c = document.createElement( "DIV" );
35            c.innerHTML = selElmnt.options[ j ].innerHTML;
36            val = selElmnt.options[ j ].getAttribute( "value" );
37            c.setAttribute( 'data-value', val )
38
39            //console.log('item', selElmnt.options[j].getAttribute("value"));
40
41            c.addEventListener( "click", function ( e )
42            {
43                /* When an item is clicked, update the original select box,
44                and the selected item: */
45                var y, i, k, s, h, sl, yl;
46                s = this.parentNode.parentNode.getElementsByTagName( "select" )[ 0 ];
47                sl = s.length;
48                h = this.parentNode.previousSibling;
49
50                for ( i = 0; i < sl; i++ )
51                {
52                    if ( s.options[ i ].innerHTML == this.innerHTML )
53                    {
54                        s.selectedIndex = i;
55                        h.innerHTML = this.innerHTML;
56
57                        //console.log('item', h.innerHTML);
58
59                        y = this.parentNode.getElementsByClassName( "same-as-selected" );
60                        yl = y.length;
61
62                        for ( k = 0; k < yl; k++ )
63                        {
64                            y[ k ].removeAttribute( "class" );
65                        }
66
67                        this.setAttribute( "class", "same-as-selected" );
68
69                        break;
70                    }
71                }
72
73                h.click();
74            }
75            );
76        b.appendChild( c );
77    }
78
79    x[ i ].appendChild( b );
80    a.addEventListener( "click", function ( e )
81    {
82        /* When the select box is clicked, close any other select boxes,
83        and open/close the current select box: */
84        e.stopPropagation();
85        closeAllSelect( this );
86        this.nextSibling.classList.toggle( "select-hide" );
87        this.classList.toggle( "select-arrow-active" );
88    }
89    );
90}
91}
92
93function closeAllSelect( elmnt )
94{
95    /* A function that will close all select boxes in the document,
96    except the current select box: */
97    var x, y, i, xl, yl, arrNo = [];
98    x = document.getElementsByClassName( "select-items" );
99    y = document.getElementsByClassName( "select-selected" );
100    xl = x.length;
101    yl = y.length;
102
103    for ( i = 0; i < yl; i++ )
104    {
105        if ( elmnt == y[ i ] )
106        {
107            arrNo.push( i )
108        }
109        else
110        {
111            y[ i ].classList.remove( "select-arrow-active" );
112        }
113    }
114
115    for ( i = 0; i < xl; i++ )
116    {
117        if ( arrNo.indexOf( i ) )
118        {
119            x[ i ].classList.add( "select-hide" );
120        }
121    }
122}
123
124/* If the user clicks anywhere outside the select box,
125then close all select boxes: */
126document.addEventListener( "click", closeAllSelect );
127
128document.addEventListener( 'DOMContentLoaded', function ()
129{
130    // When using the Page builder reinitiate the custom select
131    if ( document.querySelector( '.user-logged-in' ) )
132    {
133        var open = XMLHttpRequest.prototype.open;
134        XMLHttpRequest.prototype.open = function ()
135        {
136            var self = this;
137
138            this.addEventListener( 'load', function ()
139            {
140                if ( self.responseText.includes( 'LayoutParagraphsEventCommand' ) )
141                {
142                    setTimeout( function ()
143                    {
144                    }, 1000 );
145                }
146            }
147            );
148
149            open.apply( this, arguments );
150        };
151    }
152}
153);

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.