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