|
1 | 1 | ;(function ($) { |
2 | 2 | 'use strict'; |
3 | 3 |
|
| 4 | + function cbxpetition_isEmptyOrUndefined(val) { |
| 5 | + return val === undefined || val === null || val === ''; |
| 6 | + }//end method cbxpetition_isEmptyOrUndefined |
| 7 | + |
4 | 8 | $(document).ready(function () { |
5 | 9 | //Initiate Color Picker |
6 | 10 | //$('.wp-color-picker-field').wpColorPicker(); |
|
20 | 24 | }; |
21 | 25 |
|
22 | 26 | $('.setting-color-picker-wrapper').each(function (index, element) { |
23 | | - //console.log(element); |
24 | | - |
25 | 27 | var $color_field_wrap = $(element); |
26 | 28 | //console.log($color_field); |
27 | 29 | var $color_field = $color_field_wrap.find('.setting-color-picker'); |
|
119 | 121 | //select2 |
120 | 122 | $('.selecttwo-select-wrapper').each(function (index, element) { |
121 | 123 | var $element = $(element); |
122 | | - var $allow_clear = parseInt($element.data('allow-clear', 0)); |
123 | 124 |
|
124 | | - $element.find('.selecttwo-select').select2({ |
125 | | - placeholder: cbxpetition_setting_js_var.placeholder.select, |
126 | | - allowClear : $allow_clear ? true : false, |
127 | | - theme : 'default select2-container--cbx' |
128 | | - //dropdownParent: $(element) |
129 | | - }); |
| 125 | + var $placeholder = $element.data('placeholder'); |
| 126 | + var $allow_clear = $element.data('allow-clear'); |
| 127 | + |
| 128 | + if(cbxpetition_isEmptyOrUndefined($placeholder)) $placeholder = cbxpetition_setting_js_var.please_select; |
| 129 | + |
| 130 | + $element |
| 131 | + .find('.selecttwo-select') |
| 132 | + .select2({ |
| 133 | + placeholder: $placeholder, |
| 134 | + allowClear: $allow_clear ? true : false, |
| 135 | + theme: 'default', |
| 136 | + dropdownParent: $element |
| 137 | + }) |
| 138 | + .on('select2:open', function () { |
| 139 | + $('.select2-search__field').attr( |
| 140 | + 'placeholder', |
| 141 | + cbxpetition_setting_js_var.placeholder.search |
| 142 | + ); |
| 143 | + }) |
| 144 | + .on('select2:close', function () { |
| 145 | + $('.select2-search__field').attr('placeholder', $placeholder); |
| 146 | + }); |
| 147 | + |
| 148 | + $element |
| 149 | + .find('.select2-selection__rendered') |
| 150 | + .find('.select2-search--inline .select2-search__field') |
| 151 | + .attr('placeholder', $placeholder); |
130 | 152 | }); |
131 | 153 |
|
132 | | - |
133 | | - |
134 | | - |
135 | | - |
136 | 154 | var $setting_page = $('#cbxpetition-setting'); |
137 | 155 | var $setting_nav = $setting_page.find('.setting-tabs-nav'); |
138 | 156 | var activetab = ''; |
|
160 | 178 | $setting_nav.find('a').removeClass('active'); |
161 | 179 | $('#' + $tab_id + '-tab').addClass('active'); |
162 | 180 |
|
163 | | - |
164 | 181 | var clicked_group = '#' + $tab_id; |
165 | 182 |
|
166 | | - |
167 | 183 | $('.global_setting_group').hide(); |
168 | 184 | $(clicked_group).fadeIn(); |
169 | 185 |
|
|
196 | 212 | var $this = $(this); |
197 | 213 | var $tab_id = $this.data('tabid'); |
198 | 214 |
|
199 | | - |
200 | 215 | $('.setting-select-nav').val($tab_id); |
201 | 216 | $('.setting-select-nav').trigger('change'); |
202 | | - |
203 | | - |
204 | 217 | }); |
205 | 218 |
|
206 | 219 | $('.setting-select-nav').on('change', function (e) { |
|
217 | 230 | $('.setting-select-nav').trigger('change'); |
218 | 231 | } |
219 | 232 |
|
220 | | - $("#setting_resetinfo").on( |
221 | | - 'click', |
222 | | - ".cbxpetition_setting_options_check_action_call", |
| 233 | + $("#setting_resetinfo").on('click', ".cbxpetition_setting_options_check_action_call", |
223 | 234 | function (e) { |
224 | 235 | e.preventDefault(); |
225 | 236 |
|
|
239 | 250 | } |
240 | 251 | ); |
241 | 252 |
|
242 | | - /*if (activetab !== '' && $(activetab).length && $(activetab).hasClass('global_setting_group')) { |
243 | | - $('.global_setting_group').hide(); |
244 | | - $(activetab).fadeIn(); |
245 | | - } |
246 | | -
|
247 | | -
|
248 | | -
|
249 | | - if (activetab !== '' && $(activetab + '-tab').length) { |
250 | | - $setting_nav.find('a').removeClass('active'); |
251 | | - $(activetab + '-tab').addClass('active'); |
252 | | - } |
253 | | -
|
254 | | - $setting_nav.on('click', 'a',function(e) { |
255 | | - e.preventDefault(); |
256 | | -
|
257 | | - var $this = $(this); |
258 | | -
|
259 | | - $setting_nav.find('a').removeClass('active'); |
260 | | - $this.addClass('active'); |
261 | | -
|
262 | | -
|
263 | | -
|
264 | | - var clicked_group = $(this).attr('href'); |
265 | | -
|
266 | | - if (typeof(localStorage) !== 'undefined') { |
267 | | - localStorage.setItem('cbxpetitionactivetab', $(this).attr('href')); |
268 | | - } |
269 | | - $('.global_setting_group').hide(); |
270 | | - $(clicked_group).fadeIn(); |
271 | | - });*/ |
272 | | - |
273 | 253 |
|
274 | 254 | $('.wpsa-browse').on('click', function (event) { |
275 | 255 | event.preventDefault(); |
|
288 | 268 | file_frame.on('select', function () { |
289 | 269 | var attachment = file_frame.state().get('selection').first().toJSON(); |
290 | 270 |
|
291 | | - self.prev('.wpsa-url').val(attachment.url); |
| 271 | + var picker_wrapper = self.closest('.cbxchota-setting_input_file_wrap'); |
| 272 | + |
| 273 | + picker_wrapper.find('.wpsa-url').val(attachment.url); |
| 274 | + picker_wrapper.find('.cbxchota-setting_marker_preview').css({ |
| 275 | + 'background-image': 'url("' + attachment.url + '")' |
| 276 | + }).removeClass('cbxchota-setting_marker_hide'); |
| 277 | + picker_wrapper.find('.cbxchota-setting_trash').removeClass('cbxchota-setting_trash_hide'); |
| 278 | + picker_wrapper.find('.cbxchota-setting_filepicker_btn').addClass('cbxchota-setting_filepicked').removeClass('cbxchota-setting_left_space'); |
292 | 279 | }); |
293 | 280 |
|
294 | 281 | // Finally, open the modal |
295 | 282 | file_frame.open(); |
296 | 283 | }); |
297 | 284 |
|
| 285 | + // for icon delete functionality |
| 286 | + $(document).on('click', '.cbxchota-setting_input_file_wrap .dashicons', function () { |
| 287 | + var picker_wrapper = $(this).closest('.cbxchota-setting_input_file_wrap'); |
| 288 | + picker_wrapper.find('.wpsa-url').val(''); |
| 289 | + picker_wrapper.find('.cbxchota-setting_marker_preview').addClass('cbxchota-setting_marker_hide'); |
| 290 | + picker_wrapper.find('.cbxchota-setting_filepicker_btn').removeClass('cbxchota-setting_filepicked').addClass('cbxchota-setting_left_space'); |
| 291 | + $(this).addClass('cbxchota-setting_trash_hide'); |
| 292 | + }); |
| 293 | + |
298 | 294 |
|
299 | 295 | //make the subheading single row |
300 | 296 | $('.setting_heading').each(function (index, element) { |
|
0 commit comments