PluginProbe
Search & Replace Everything by WPCode – Find and Replace Media, Text, Links, and More / 1.0.6
Search & Replace Everything by WPCode – Find and Replace Media, Text, Links, and More v1.0.6
trunk 1.0.0 1.0.1 1.0.10 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
search-replace-wpcode / src / admin / inputs.js

inputs.js in Search & Replace Everything by WPCode – Find and Replace Media, Text, Links, and More 1.0.6, at src/admin/inputs.js

123 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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