| 1 |
const WSRInputs = window.WSRInputs || ( |
| 2 |
function ( document, window, $ ) { |
| 3 |
const app = { |
| 4 |
init() { |
| 5 |
$( app.ready ); |
| 6 |
}, |
| 7 |
ready() { |
| 8 |
app.initFileUploads(); |
| 9 |
app.initCheckboxMultiselectColumns(); |
| 10 |
}, |
| 11 |
initFileUploads() { |
| 12 |
$( '.wsrw-file-upload' ).each( |
| 13 |
function () { |
| 14 |
const $input = $( this ).find( 'input[type=file]' ), |
| 15 |
$label = $( this ).find( 'label' ), |
| 16 |
labelVal = $label.html(); |
| 17 |
$input.on( |
| 18 |
'change', |
| 19 |
function ( event ) { |
| 20 |
let fileName = ''; |
| 21 |
if ( this.files && this.files.length > 1 ) { |
| 22 |
fileName = ( |
| 23 |
this.getAttribute( 'data-multiple-caption' ) || '' |
| 24 |
).replace( '{count}', this.files.length ); |
| 25 |
} else if ( event.target.value ) { |
| 26 |
fileName = event.target.value.split( '\\' ).pop(); |
| 27 |
} |
| 28 |
if ( fileName ) { |
| 29 |
$label.find( '.wsrw-file-field' ).html( fileName ); |
| 30 |
} else { |
| 31 |
$label.html( labelVal ); |
| 32 |
} |
| 33 |
} |
| 34 |
); |
| 35 |
// Firefox bug fix. |
| 36 |
$input.on( |
| 37 |
'focus', |
| 38 |
function () { |
| 39 |
$input.addClass( 'has-focus' ); |
| 40 |
} |
| 41 |
).on( |
| 42 |
'blur', |
| 43 |
function () { |
| 44 |
$input.removeClass( 'has-focus' ); |
| 45 |
} |
| 46 |
); |
| 47 |
} |
| 48 |
); |
| 49 |
}, |
| 50 |
initCheckboxMultiselectColumns() { |
| 51 |
|
| 52 |
let checked = false; |
| 53 |
|
| 54 |
$( document ).on( |
| 55 |
'change', |
| 56 |
'.wsrw-checkbox-multiselect-columns input', |
| 57 |
function () { |
| 58 |
|
| 59 |
var $this = $( this ), |
| 60 |
$parent = $this.parent(), |
| 61 |
$container = $this.closest( '.wsrw-checkbox-multiselect-columns' ), |
| 62 |
label = $parent.text(), |
| 63 |
itemID = 'check-item-' + $this.val(), |
| 64 |
$item = $container.find( '#' + itemID ); |
| 65 |
|
| 66 |
if ( $this.prop( 'checked' ) ) { |
| 67 |
$this.parent().addClass( 'checked' ); |
| 68 |
if ( !$item.length ) { |
| 69 |
$container.find( '.second-column ul' ).append( '<li id="' + itemID + '">' + label + '</li>' ); |
| 70 |
} |
| 71 |
} else { |
| 72 |
$this.parent().removeClass( 'checked' ); |
| 73 |
$container.find( '#' + itemID ).remove(); |
| 74 |
} |
| 75 |
} |
| 76 |
); |
| 77 |
|
| 78 |
$( document ).on( |
| 79 |
'click', |
| 80 |
'.wsrw-checkbox-multiselect-columns .all', |
| 81 |
function ( event ) { |
| 82 |
|
| 83 |
event.preventDefault(); |
| 84 |
|
| 85 |
checked = !checked; |
| 86 |
|
| 87 |
$( this ).closest( '.wsrw-checkbox-multiselect-columns' ).find( 'input[type=checkbox]' ).prop( 'checked', checked ).trigger( 'change' ); |
| 88 |
} |
| 89 |
); |
| 90 |
|
| 91 |
$( document ).on( |
| 92 |
'input', |
| 93 |
'.wsrw-multiselect-search input', |
| 94 |
function ( event ) { |
| 95 |
// Let's hide the li elements in the .next() ul that don't match the search term. |
| 96 |
const $this = $( this ), |
| 97 |
$container = $this.parent(), |
| 98 |
$ul = $container.next( 'ul' ), |
| 99 |
search = $this.val().toLowerCase(); |
| 100 |
|
| 101 |
$ul.find( 'li' ).each( function () { |
| 102 |
const $li = $( this ), |
| 103 |
text = $li.text().toLowerCase(); |
| 104 |
|
| 105 |
if ( text.indexOf( search ) === - 1 ) { |
| 106 |
$li.hide(); |
| 107 |
} else { |
| 108 |
$li.show(); |
| 109 |
} |
| 110 |
|
| 111 |
} ); |
| 112 |
|
| 113 |
} |
| 114 |
); |
| 115 |
}, |
| 116 |
|
| 117 |
}; |
| 118 |
return app; |
| 119 |
}( document, window, jQuery ) |
| 120 |
); |
| 121 |
|
| 122 |
WSRInputs.init(); |
| 123 |
|