1/** 2 * UpSolution Element: List Order 3 */ 4! function( $, _undefined ) { 5 "use strict"; 6 7 const DELETE_FILTER = null; 8 const urlManager = $ush.urlManager(); 9 10 /** 11 * @param {Node} container. 12 */ 13 function usListOrder( container ) { 14 const self = this; 15 16 // Bindable events 17 self._events = { 18 selectChanged: self._selectChanged.bind( self ), 19 }; 20 21 // Elements 22 self.$container = $( container ); 23 self.$pageContent = $( 'main#page-content' ); 24 25 // Sets value from URL 26 if ( self.changeURLParams() ) { 27 var urlValue = urlManager.get( '_orderby' ); 28 if ( ! $ush.isUndefined( urlValue ) ) { 29 $( 'select', container ).val( urlValue ); 30 } 31 } 32 33 // Events 34 self.$container.on( 'change', 'select', self._events.selectChanged ); 35 } 36 37 // List Order API 38 $.extend( usListOrder.prototype, { 39 40 /** 41 * Determines if enabled URL. 42 * 43 * @return {Boolean} True if enabled url, False otherwise. 44 */ 45 changeURLParams: function() { 46 return this.$container.hasClass( 'change_url_params' ); 47 }, 48 49 /** 50 * @event handler 51 * @param {Event} e The Event interface represents an event which takes place in the DOM. 52 */ 53 _selectChanged: function( e ) { 54 const self = this; 55 56 const $firstList = $( ` 57 .w-grid.us_post_list:visible, 58 .w-grid.us_product_list:visible, 59 .w-grid-none:visible 60 `, self.$pageContent ).first(); 61 62 if ( $firstList.hasClass( 'w-grid' ) ) { 63 $firstList.addClass( 'used_by_list_order' ); 64 } 65 66 var value = e.target.value; 67 if ( value === '' ) { 68 value = DELETE_FILTER; 69 } 70 if ( value === self.lastValue ) { 71 return; 72 } 73 self.lastValue = value; 74 75 if ( self.changeURLParams() ) { 76 urlManager.set( '_orderby', value ).push(); 77 } 78 79 $firstList.trigger( 'usListOrder', [ 80 { 81 'scroll_to_list': self.$container.hasClass( 'scroll_to_list' ), 82 '_orderby': value, 83 } 84 ] ); 85 } 86 } ); 87 88 $.fn.usListOrder = function() { 89 return this.each( function() { 90 $( this ).data( 'usListOrder', new usListOrder( this ) ); 91 } ); 92 }; 93 94 $( () => $( '.w-order.for_list' ).usListOrder() ); 95 96}( jQuery );
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.