author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:40:08 +0200 | |
changeset 21 | 48c4eec2b7e6 |
parent 19 | 3d72ae0968f4 |
permissions | -rwxr-xr-x |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
function bws_show_settings_notice() { |
19 | 2 |
"use strict"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
(function($) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
$( '.updated.fade:not(.bws_visible), .error:not(.bws_visible)' ).css( 'display', 'none' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
$( '#bws_save_settings_notice' ).css( 'display', 'block' ); |
19 | 6 |
})( jQuery ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
7 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
8 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
9 |
(function($) { |
19 | 10 |
"use strict"; |
11 |
$( document ).ready( |
|
12 |
function() { |
|
13 |
/** |
|
14 |
* add notice about changing on the settings page |
|
15 |
*/ |
|
16 |
$( '.bws_form input, .bws_form textarea, .bws_form select' ).on( |
|
17 |
"change paste select", |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
18 |
function( e ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
19 |
if ( $( this ).attr( 'type' ) != 'submit' && ! $( this ).hasClass( 'bws_no_bind_notice' ) && typeof ( e.originalEvent ) != 'undefined' ) { |
19 | 20 |
bws_show_settings_notice(); |
21 |
}; |
|
22 |
} |
|
23 |
); |
|
24 |
$( '.bws_save_anchor' ).on( |
|
25 |
"click", |
|
26 |
function( event ) { |
|
27 |
event.preventDefault(); |
|
28 |
$( '.bws_form #bws-submit-button' ).click(); |
|
29 |
} |
|
30 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
31 |
|
19 | 32 |
/* custom code */ |
16 | 33 |
|
19 | 34 |
if ( 'function' == typeof wp.CodeMirror || 'function' == typeof CodeMirror ) { |
35 |
var CodeMirrorFunc = ( typeof wp.CodeMirror != 'undefined' ) ? wp.CodeMirror : CodeMirror; |
|
36 |
if ( $( '#bws_newcontent_css' ).length > 0 ) { |
|
37 |
var editor = CodeMirrorFunc.fromTextArea( |
|
38 |
document.getElementById( 'bws_newcontent_css' ), |
|
39 |
{ |
|
40 |
mode: "css", |
|
41 |
theme: "default", |
|
42 |
styleActiveLine: true, |
|
43 |
matchBrackets: true, |
|
44 |
lineNumbers: true, |
|
45 |
addModeClass: 'bws_newcontent_css', |
|
46 |
readOnly: 'nocursor' |
|
47 |
} |
|
48 |
); |
|
49 |
} |
|
50 |
||
51 |
if ( $( '#bws_newcontent_php' ).length > 0 ) { |
|
52 |
var editor = CodeMirrorFunc.fromTextArea( |
|
53 |
document.getElementById( "bws_newcontent_php" ), |
|
54 |
{ |
|
55 |
mode: 'text/x-php', |
|
56 |
styleActiveLine: true, |
|
57 |
matchBrackets: true, |
|
58 |
lineNumbers: true, |
|
59 |
readOnly: 'nocursor' |
|
60 |
} |
|
61 |
); |
|
62 |
/* disable lines */ |
|
63 |
editor.markText( {ch:0,line:0}, {ch:0,line:5}, { readOnly: true, className: 'bws-readonly' } ); |
|
64 |
} |
|
65 |
||
66 |
if ( $( '#bws_newcontent_js' ).length > 0 ) { |
|
67 |
var editor = CodeMirrorFunc.fromTextArea( |
|
68 |
document.getElementById( "bws_newcontent_js" ), |
|
69 |
{ |
|
70 |
mode: 'javascript', |
|
71 |
styleActiveLine: true, |
|
72 |
matchBrackets: true, |
|
73 |
lineNumbers: true, |
|
74 |
readOnly: 'nocursor' |
|
75 |
} |
|
76 |
); |
|
77 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
78 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
79 |
|
19 | 80 |
/* banner to settings */ |
81 |
$( '.bws_banner_to_settings_joint .bws-details' ).addClass( 'hidden' ).removeClass( 'hide-if-js' ); |
|
82 |
$( '.bws_banner_to_settings_joint .bws-more-links' ).on( |
|
83 |
"click", |
|
84 |
function( event ) { |
|
85 |
event.preventDefault(); |
|
86 |
if ( $( '.bws_banner_to_settings_joint .bws-less' ).hasClass( 'hidden' ) ) { |
|
87 |
$( '.bws_banner_to_settings_joint .bws-less, .bws_banner_to_settings_joint .bws-details' ).removeClass( 'hidden' ); |
|
88 |
$( '.bws_banner_to_settings_joint .bws-more' ).addClass( 'hidden' ); |
|
89 |
} else { |
|
90 |
$( '.bws_banner_to_settings_joint .bws-less, .bws_banner_to_settings_joint .bws-details' ).addClass( 'hidden' ); |
|
91 |
$( '.bws_banner_to_settings_joint .bws-more' ).removeClass( 'hidden' ); |
|
92 |
} |
|
93 |
} |
|
94 |
); |
|
95 |
||
96 |
/* help tooltips */ |
|
97 |
if ( $( '.bws_help_box' ).length > 0 ) { |
|
98 |
if ( $( 'body' ).hasClass( 'rtl' ) ) { |
|
99 |
var current_position = { my: "right top+15", at: "right bottom" }; |
|
100 |
} else { |
|
101 |
var current_position = { my: "left top+15", at: "left bottom" }; |
|
102 |
} |
|
103 |
$( document ).tooltip( |
|
104 |
{ |
|
105 |
items: $( '.bws_help_box' ), |
|
106 |
content: function() { |
|
107 |
return $( this ).find( '.bws_hidden_help_text' ).html() |
|
108 |
}, |
|
109 |
show: null, /* show immediately */ |
|
110 |
tooltipClass: "bws-tooltip-content", |
|
111 |
position: current_position, |
|
112 |
open: function( event, ui ) { |
|
113 |
if ( typeof( event.originalEvent ) === 'undefined' ) { |
|
114 |
return false; |
|
115 |
} |
|
116 |
if ( $( event.originalEvent.target ).hasClass( 'bws-auto-width' ) ) { |
|
117 |
ui.tooltip.css( "max-width", "inherit" ); |
|
118 |
} |
|
119 |
var $id = $( ui.tooltip ).attr( 'id' ); |
|
120 |
/* close any lingering tooltips */ |
|
121 |
$( 'div.ui-tooltip' ).not( '#' + $id ).remove(); |
|
122 |
}, |
|
123 |
close: function( event, ui ) { |
|
124 |
ui.tooltip.hover( |
|
125 |
function() { |
|
126 |
$( this ).stop( true ).fadeTo( 200, 1 ); |
|
127 |
}, |
|
128 |
function() { |
|
129 |
$( this ).fadeOut( |
|
130 |
'200', |
|
131 |
function() { |
|
132 |
$( this ).remove(); |
|
133 |
} |
|
134 |
); |
|
135 |
} |
|
136 |
); |
|
137 |
} |
|
138 |
} |
|
139 |
); |
|
140 |
} |
|
141 |
||
142 |
/** |
|
143 |
* Handle the styling of the "Settings" tab on the plugin settings page |
|
144 |
*/ |
|
145 |
var tabs = $( '#bws_settings_tabs_wrapper' ); |
|
146 |
if ( tabs.length ) { |
|
147 |
var current_tab_field = $( 'input[name="bws_active_tab"]' ), |
|
148 |
prevent_tabs_change = false, |
|
149 |
active_tab = current_tab_field.val(); |
|
150 |
if ( '' == active_tab ) { |
|
151 |
var active_tab_index = 0; |
|
152 |
} else { |
|
153 |
var active_tab_index = $( '#bws_settings_tabs li[data-slug=' + active_tab + ']' ).index(); |
|
154 |
} |
|
155 |
||
156 |
$( '.bws_tab' ).css( 'min-height', $( '#bws_settings_tabs' ).css( 'height' ) ); |
|
157 |
||
158 |
/* jQuery tabs initialization */ |
|
159 |
tabs.tabs( |
|
160 |
{ |
|
161 |
active: active_tab_index |
|
162 |
} |
|
163 |
).on( |
|
164 |
"tabsactivate", |
|
165 |
function( event, ui ) { |
|
166 |
if ( ! prevent_tabs_change ) { |
|
167 |
active_tab = ui.newTab.data( 'slug' ); |
|
168 |
current_tab_field.val( active_tab ); |
|
169 |
} |
|
170 |
prevent_tabs_change = false; |
|
171 |
} |
|
172 |
); |
|
173 |
$( '.bws_trigger_tab_click' ).on( |
|
174 |
'click', |
|
175 |
function () { |
|
176 |
$( '#bws_settings_tabs a[href="' + $( this ).attr( 'href' ) + '"]' ).click(); |
|
177 |
} |
|
178 |
); |
|
179 |
} |
|
180 |
/** |
|
181 |
* Hide content for options on the plugin settings page |
|
182 |
*/ |
|
183 |
var options = $( '.bws_option_affect' ); |
|
184 |
if ( options.length ) { |
|
185 |
options.each( |
|
186 |
function() { |
|
187 |
var element = $( this ); |
|
188 |
if ( element.is( ':selected' ) || element.is( ':checked' ) ) { |
|
189 |
$( element.data( 'affect-show' ) ).show(); |
|
190 |
$( element.data( 'affect-hide' ) ).hide(); |
|
191 |
} else { |
|
192 |
$( element.data( 'affect-show' ) ).hide(); |
|
193 |
$( element.data( 'affect-hide' ) ).show(); |
|
194 |
} |
|
195 |
if ( element.is( 'option' ) ) { |
|
196 |
element.parent().on( |
|
197 |
'change', |
|
198 |
function() { |
|
199 |
var affect_hide = element.data( 'affect-hide' ), |
|
200 |
affect_show = element.data( 'affect-show' ); |
|
201 |
if ( element.is( ':selected' ) ) { |
|
202 |
$( affect_show ).show(); |
|
203 |
$( affect_hide ).hide(); |
|
204 |
} else { |
|
205 |
$( affect_show ).hide(); |
|
206 |
$( affect_hide ).show(); |
|
207 |
} |
|
208 |
} |
|
209 |
); |
|
210 |
} else { |
|
211 |
element.on( |
|
212 |
'change', |
|
213 |
function() { |
|
214 |
var affect_hide = element.data( 'affect-hide' ), |
|
215 |
affect_show = element.data( 'affect-show' ); |
|
216 |
if ( element.is( ':selected' ) || element.is( ':checked' ) ) { |
|
217 |
$( affect_show ).show(); |
|
218 |
$( affect_hide ).hide(); |
|
219 |
} else { |
|
220 |
$( affect_show ).hide(); |
|
221 |
$( affect_hide ).show(); |
|
222 |
} |
|
223 |
} |
|
224 |
); |
|
225 |
} |
|
226 |
} |
|
227 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
228 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
229 |
} |
19 | 230 |
); |
231 |
})( jQuery ); |