PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.9.9
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.9.9
4.0.3 4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 341 releases
profile-builder / assets / js / jquery-manage-fields-live-change.js

jquery-manage-fields-live-change.js in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 3.9.9, at assets/js/jquery-manage-fields-live-change.js

969 lines 41.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 var fields = {
2 'Default - Name (Heading)': { 'show_rows' : [
3 '.row-field-title',
4 '.row-description',
5 ],
6 'properties': {
7 'meta_name_value' : ''
8 }
9 },
10
11 'Default - Contact Info (Heading)': { 'show_rows' : [
12 '.row-field-title',
13 '.row-description',
14 ],
15 'properties': {
16 'meta_name_value' : ''
17 }
18 },
19
20 'Default - About Yourself (Heading)': { 'show_rows' : [
21 '.row-field-title',
22 '.row-description',
23 ],
24 'properties': {
25 'meta_name_value' : ''
26 }
27 },
28
29 'Default - Username': { 'show_rows' : [
30 '.row-field-title',
31 '.row-description',
32 '.row-default-value',
33 '.row-required'
34 ],
35 'properties': {
36 'meta_name_value' : ''
37 },
38 'required' : [
39 true
40 ]
41 },
42
43 'Default - First Name': { 'show_rows' : [
44 '.row-field-title',
45 '.row-meta-name',
46 '.row-description',
47 '.row-default-value',
48 '.row-required'
49 ],
50 'properties': {
51 'meta_name_value' : 'first_name'
52 }
53 },
54
55 'Default - Last Name': { 'show_rows' : [
56 '.row-field-title',
57 '.row-meta-name',
58 '.row-description',
59 '.row-default-value',
60 '.row-required'
61 ],
62 'properties': {
63 'meta_name_value' : 'last_name'
64 }
65 },
66
67 'Default - Nickname': { 'show_rows' : [
68 '.row-field-title',
69 '.row-meta-name',
70 '.row-description',
71 '.row-default-value',
72 '.row-required'
73 ],
74 'properties': {
75 'meta_name_value' : 'nickname'
76 },
77 'required' : [
78 true
79 ]
80 },
81
82 'Default - E-mail': { 'show_rows' : [
83 '.row-field-title',
84 '.row-description',
85 '.row-default-value',
86 '.row-required'
87 ],
88 'properties': {
89 'meta_name_value' : ''
90 },
91 'required' : [
92 true
93 ]
94 },
95
96 'Default - Website': { 'show_rows' : [
97 '.row-field-title',
98 '.row-description',
99 '.row-default-value',
100 '.row-required'
101 ],
102 'properties': {
103 'meta_name_value' : ''
104 }
105 },
106
107 'Default - AIM': { 'show_rows' : [
108 '.row-field-title',
109 '.row-meta-name',
110 '.row-description',
111 '.row-default-value',
112 '.row-required'
113 ],
114 'properties': {
115 'meta_name_value' : 'aim'
116 }
117 },
118
119 'Default - Yahoo IM': { 'show_rows' : [
120 '.row-field-title',
121 '.row-meta-name',
122 '.row-description',
123 '.row-default-value',
124 '.row-required'
125 ],
126 'properties': {
127 'meta_name_value' : 'yim'
128 }
129 },
130
131 'Default - Jabber / Google Talk': { 'show_rows' : [
132 '.row-field-title',
133 '.row-meta-name',
134 '.row-description',
135 '.row-default-value',
136 '.row-required'
137 ],
138 'properties': {
139 'meta_name_value' : 'jabber'
140 }
141 },
142
143 'Default - Password': { 'show_rows' : [
144 '.row-field-title',
145 '.row-description',
146 '.row-required'
147 ],
148 'properties': {
149 'meta_name_value' : ''
150 },
151 'required' : [
152 true
153 ]
154 },
155
156 'Default - Repeat Password': { 'show_rows' : [
157 '.row-field-title',
158 '.row-description',
159 '.row-required'
160 ],
161 'properties': {
162 'meta_name_value' : ''
163 },
164 'required' : [
165 true
166 ]
167 },
168
169 'Default - Biographical Info': { 'show_rows' : [
170 '.row-field-title',
171 '.row-meta-name',
172 '.row-description',
173 '.row-row-count',
174 '.row-default-content',
175 '.row-required'
176 ],
177 'properties': {
178 'meta_name_value' : 'description'
179 }
180 },
181
182 'Default - Display name publicly as': { 'show_rows' : [
183 '.row-field-title',
184 '.row-description',
185 '.row-default-value',
186 '.row-required'
187 ],
188 'properties': {
189 'meta_name_value' : ''
190 }
191 },
192
193 'Default - Blog Details': { 'show_rows' : [
194 '.row-field-title',
195 '.row-description'
196 ],
197 'properties': {
198 'meta_name_value' : ''
199 }
200 },
201
202 'GDPR Checkbox': { 'show_rows' : [
203 '.row-field-title',
204 '.row-meta-name',
205 '.row-description',
206 '.row-required',
207 '.row-overwrite-existing'
208 ],
209 'properties': {
210 'meta_name_value' : 'user_consent_gdpr',
211 'field_title' : wppb_fields_strings.gdpr_title,
212 'description' : wppb_fields_strings.gdpr_description
213 },
214 'required' : [
215 true
216 ]
217 },
218 'GDPR Delete Button': { 'show_rows' : [
219 '.row-field-title',
220 '.row-description',
221 ],
222 'properties': {
223 'meta_name_value' : ''
224 }
225 },
226
227 'Heading': { 'show_rows' : [
228 '.row-field-title',
229 '.row-description',
230 '.row-heading-tag'
231 ],
232 'properties': {
233 'meta_name_value' : ''
234 }
235 },
236
237 'Input': { 'show_rows' : [
238 '.row-field-title',
239 '.row-meta-name',
240 '.row-description',
241 '.row-default-value',
242 '.row-required',
243 '.row-overwrite-existing'
244 ]
245 },
246
247 'Email': { 'show_rows' : [
248 '.row-field-title',
249 '.row-meta-name',
250 '.row-description',
251 '.row-default-value',
252 '.row-required',
253 '.row-overwrite-existing'
254 ]
255 },
256 'Email Confirmation': { 'show_rows' : [
257 '.row-field-title',
258 '.row-field',
259 '.row-description',
260 '.row-required'
261 ],
262 'required' : [
263 true
264 ],
265 'properties': {
266 'meta_name_value' : ''
267 }
268 },
269 'URL': { 'show_rows' : [
270 '.row-field-title',
271 '.row-meta-name',
272 '.row-description',
273 '.row-default-value',
274 '.row-required',
275 '.row-overwrite-existing'
276 ]
277 },
278
279 'Number': { 'show_rows' : [
280 '.row-field-title',
281 '.row-meta-name',
282 '.row-description',
283 '.row-default-value',
284 '.row-min-number-value',
285 '.row-max-number-value',
286 '.row-number-step-value',
287 '.row-required',
288 '.row-overwrite-existing'
289 ]
290 },
291 'Input (Hidden)': { 'show_rows' : [
292 '.row-field-title',
293 '.row-meta-name',
294 '.row-description',
295 '.row-default-value',
296 '.row-overwrite-existing'
297 ]
298 },
299 'Language': { 'show_rows' : [
300 '.row-field-title',
301 '.row-meta-name',
302 '.row-description',
303 '.row-default-value',
304 '.row-overwrite-existing'
305 ]
306 },
307
308 'Textarea': { 'show_rows' : [
309 '.row-field-title',
310 '.row-meta-name',
311 '.row-description',
312 '.row-default-content',
313 '.row-required',
314 '.row-row-count',
315 '.row-overwrite-existing'
316 ]
317 },
318 'WYSIWYG': { 'show_rows' : [
319 '.row-field-title',
320 '.row-meta-name',
321 '.row-description',
322 '.row-default-content',
323 '.row-required',
324 '.row-overwrite-existing'
325 ]
326 },
327 'Phone': { 'show_rows' : [
328 '.row-field-title',
329 '.row-meta-name',
330 '.row-description',
331 '.row-phone-format',
332 '.row-required',
333 '.row-overwrite-existing'
334 ]
335 },
336 'Select': { 'show_rows' : [
337 '.row-field-title',
338 '.row-meta-name',
339 '.row-description',
340 '.row-default-option',
341 '.row-required',
342 '.row-overwrite-existing',
343 '.row-options',
344 '.row-labels'
345 ]
346 },
347 'Select (Multiple)': { 'show_rows' : [
348 '.row-field-title',
349 '.row-meta-name',
350 '.row-description',
351 '.row-default-options',
352 '.row-required',
353 '.row-overwrite-existing',
354 '.row-options',
355 '.row-labels'
356 ]
357 },
358
359 'Select (Country)': { 'show_rows' : [
360 '.row-field-title',
361 '.row-meta-name',
362 '.row-description',
363 '.row-default-option-country',
364 '.row-required',
365 '.row-overwrite-existing'
366 ]
367 },
368
369 'Select (Currency)': { 'show_rows' : [
370 '.row-field-title',
371 '.row-meta-name',
372 '.row-description',
373 '.row-show-currency-symbol',
374 '.row-default-option-currency',
375 '.row-required',
376 '.row-overwrite-existing'
377 ]
378 },
379
380 'Select (Timezone)': { 'show_rows' : [
381 '.row-field-title',
382 '.row-meta-name',
383 '.row-description',
384 '.row-default-option-timezone',
385 '.row-required',
386 '.row-overwrite-existing'
387 ]
388 },
389 'Select (CPT)': { 'show_rows' : [
390 '.row-field-title',
391 '.row-meta-name',
392 '.row-description',
393 '.row-default-option',
394 '.row-cpt',
395 '.row-required',
396 '.row-overwrite-existing'
397 ]
398 },
399 "Select2": { 'show_rows' : [
400 '.row-field-title',
401 '.row-meta-name',
402 '.row-description',
403 '.row-default-option',
404 '.row-required',
405 '.row-overwrite-existing',
406 '.row-options',
407 '.row-labels',
408 '.row-visibility',
409 '.row-user-role-visibility',
410 '.row-location-visibility'
411 ]
412 },
413 "Select2 (Multiple)": { 'show_rows' : [
414 '.row-field-title',
415 '.row-meta-name',
416 '.row-description',
417 '.row-default-options',
418 '.row-required',
419 '.row-overwrite-existing',
420 '.row-options',
421 '.row-labels',
422 '.row-select2-multiple-limit',
423 '.row-select2-multiple-tags',
424 '.row-visibility',
425 '.row-user-role-visibility',
426 '.row-location-visibility'
427 ]
428 },
429 'Honeypot': { 'show_rows' : [
430 '.row-field-title'
431 ],
432 'properties': {
433 'meta_name_value' : 'honeypot',
434 'field_title' : wppb_fields_strings.honeypot_title
435 }
436 },
437 'Checkbox': { 'show_rows' : [
438 '.row-field-title',
439 '.row-meta-name',
440 '.row-description',
441 '.row-default-options',
442 '.row-required',
443 '.row-overwrite-existing',
444 '.row-options',
445 '.row-labels'
446 ]
447 },
448
449 'Checkbox (Terms and Conditions)': { 'show_rows' : [
450 '.row-field-title',
451 '.row-meta-name',
452 '.row-description',
453 '.row-required',
454 '.row-overwrite-existing'
455 ],
456 'required' : [
457 true
458 ]
459 },
460
461 'Radio': { 'show_rows' : [
462 '.row-field-title',
463 '.row-meta-name',
464 '.row-description',
465 '.row-default-option',
466 '.row-required',
467 '.row-overwrite-existing',
468 '.row-options',
469 '.row-labels'
470 ]
471 },
472
473 'Upload': { 'show_rows' : [
474 '.row-field-title',
475 '.row-meta-name',
476 '.row-description',
477 '.row-simple-upload',
478 '.row-allowed-extensions',
479 '.row-required',
480 '.row-overwrite-existing',
481 '.row-allowed-upload-extensions'
482 ]
483 },
484
485 'Avatar': { 'show_rows' : [
486 '.row-field-title',
487 '.row-meta-name',
488 '.row-description',
489 '.row-simple-upload',
490 '.row-allowed-image-extensions',
491 '.row-avatar-size',
492 '.row-required',
493 '.row-overwrite-existing'
494 ]
495 },
496
497 'Datepicker': { 'show_rows' : [
498 '.row-field-title',
499 '.row-meta-name',
500 '.row-description',
501 '.row-default-value',
502 '.row-required',
503 '.row-date-format',
504 '.row-overwrite-existing'
505 ]
506 },
507
508
509 'Timepicker': { 'show_rows' : [
510 '.row-field-title',
511 '.row-meta-name',
512 '.row-description',
513 '.row-required',
514 '.row-time-format',
515 '.row-overwrite-existing'
516 ]
517 },
518
519 'Colorpicker': { 'show_rows' : [
520 '.row-field-title',
521 '.row-meta-name',
522 '.row-description',
523 '.row-required',
524 '.row-overwrite-existing'
525 ]
526 },
527
528
529 'Validation': { 'show_rows' : [
530 '.row-field-title',
531 '.row-meta-name',
532 '.row-description',
533 '.row-validation-possible-values',
534 '.row-custom-error-message',
535 '.row-required'
536 ],
537 'required' : [
538 true
539 ]
540 },
541
542 'reCAPTCHA': { 'show_rows' : [
543 '.row-field-title',
544 '.row-description',
545 '.row-recaptcha-type',
546 '.row-public-key',
547 '.row-private-key',
548 '.row-captcha-pb-forms',
549 '.row-captcha-wp-forms',
550 '.row-required'
551 ],
552 'required' : [
553 true
554 ],
555 'properties': {
556 'meta_name_value' : ''
557 }
558 },
559
560 'Select (User Role)': { 'show_rows' : [
561 '.row-field-title',
562 '.row-description',
563 '.row-user-roles',
564 '.row-user-roles-on-edit-profile',
565 '.row-required'
566 ],
567 'properties': {
568 'meta_name_value' : ''
569 }
570 },
571
572 'Map': { 'show_rows' : [
573 '.row-field-title',
574 '.row-meta-name',
575 '.row-description',
576 '.row-map-api-key',
577 '.row-map-default-lat',
578 '.row-map-default-lng',
579 '.row-map-default-zoom',
580 '.row-map-height',
581 '.row-map-pins-load-type',
582 '.row-map-pagination-number',
583 '.row-map-bubble-fields',
584 '.row-required',
585 '.row-overwrite-existing'
586 ],
587 'properties': {
588 'meta_name_value' : 'map'
589 }
590 },
591 'HTML': { 'show_rows' : [
592 '.row-field-title',
593 '.row-description',
594 '.row-html-content'
595 ],
596 'properties': {
597 'meta_name_value' : ''
598 }
599 }
600 }
601 var fields_to_show = [
602 '.row-field-title',
603 '.row-field',
604 '.row-meta-name',
605 '.row-required'
606 ]
607
608 function wppb_hide_properties_for_already_added_fields( container_name ){
609
610 jQuery( container_name + ' tr:not(.update_container_wppb_manage_fields)' ).each(function() {
611
612 field = jQuery('.row-field pre', this).text();
613
614 jQuery( 'li', this ).each(function() {
615 var class_name = '';
616
617 class_name = jQuery(this).attr('class');
618 jQuery(this).hide();
619
620 if ( ( field in fields ) ){
621 var to_show = fields[field]['show_rows'];
622 for (var key in to_show) {
623 if ('.'+class_name == fields_to_show[key]){
624 jQuery(this).show();
625 }
626 }
627 }
628
629 });
630 });
631
632 /* hide the delete button for username,password and email fields */
633 jQuery( container_name + ' ' + '.element_type_default-e-mail .mbdelete,' + ' ' + container_name + ' ' + '.element_type_default-password .mbdelete,' + ' ' + container_name + ' ' + '.element_type_default-username .mbdelete' ).hide(); // PB specific line
634 }
635
636
637
638 function wppb_hide_all ( container_name ){
639 jQuery( container_name + ' ' + '.mb-list-entry-fields > li' ).each(function() {
640 if ( !( ( jQuery(this).hasClass('row-field') ) || ( jQuery(this).children().hasClass('button-primary') ) ) || jQuery(this).hasClass('row-rpf-button') ){
641 jQuery(this).hide();
642 }
643 });
644
645 jQuery( container_name + ' ' + '.mb-list-entry-fields .button-primary' ).attr( 'disabled', true );
646
647 jQuery( container_name + ' ' + '.element_type_default-e-mail .mbdelete,' + ' ' + container_name + ' ' + '.element_type_default-password .mbdelete,' + ' ' + container_name + ' ' + '.element_type_default-username .mbdelete' ).hide(); // PB specific line
648 jQuery( container_name + ' ' + '.element_type_default-e-mail #field' + ', ' + container_name + ' ' + '.element_type_default-password #field' + ', ' + container_name + ' ' + '.element_type_default-username #field' + ', ' + container_name + ' ' + '.element_type_default-e-mail #required' + ', ' + container_name + ' ' + '.element_type_default-password #required,' + container_name + ' ' + '.element_type_default-username #required,' + container_name + ' ' + '.element_type_checkbox-terms-and-conditions #required,' + container_name + ' ' + '.element_type_recaptcha #required,' + container_name + ' ' + '.element_type_woocommerce-customer-billing-address #field, ' + container_name + ' ' + '.element_type_woocommerce-customer-shipping-address #field').attr( 'disabled', true ); // PB specific line
649
650 }
651
652
653 function wppb_disable_add_entry_button( container_name ){
654 jQuery( container_name + ' ' + '.mb-list-entry-fields .button-primary' ).each( function(){
655
656 //jQuery(this).data('myclick', this.onclick );
657 this.onclick = function(event) {
658 if ( jQuery(this).attr( 'disabled' ) ) {
659 return false;
660 }
661 /* changed this in version 2.5.0 because the commented line generated stack exceeded error when multiple fields were opened with edit */
662 if ( typeof( event.currentTarget ) == 'undefined' ){
663 // Repeater field triggered the click event of the "Add Field" / "Save changes" buttons, so the onclick attribute is in the target, not currentTarget
664 eval(event.target.getAttribute('onclick'));
665 }else {
666 // normal Manage Fields Add Field button press
667 eval(event.currentTarget.getAttribute('onclick'));
668 }
669
670 //jQuery(this).data('myclick').call(this, event || window.event);
671 };
672 });
673
674 }
675
676
677 function wppb_edit_form_properties( container_name, element_id ){
678 wppb_hide_all ( container_name );
679 wppb_disable_add_entry_button ( container_name );
680
681 field = jQuery( container_name + ' #' + element_id + ' ' + '#field' ).val();
682
683 if ( ( field in fields ) ){
684 var to_show = fields[ field.trim() ]['show_rows'];
685 for (var key in to_show)
686 jQuery( container_name + ' #' + element_id + ' ' + to_show[key] ).show();
687
688 var properties = fields[ field.trim() ]['properties'];
689 if( typeof properties !== 'undefined' && properties ) {
690 for( var key in properties ) {
691 if( typeof properties['meta_name_value'] !== 'undefined' ) {
692 jQuery( container_name + ' ' + '#meta-name').attr( 'readonly', true );
693 }
694 }
695 }
696
697 jQuery( container_name + ' ' + '.mb-list-entry-fields .button-primary' ).removeAttr( 'disabled' );
698
699 //Handle user role sorting
700 wppb_handle_user_role_field( container_name );
701 }
702 }
703
704
705 function wppb_display_needed_fields( index, container_name, current_field_select ){
706
707 var show_rows = fields[index.trim()]['show_rows'];
708 for (var key in show_rows) {
709 jQuery( show_rows[key], jQuery( current_field_select ).parents( '.mb-list-entry-fields' ) ).show();
710 }
711
712 var properties = fields[index.trim()]['properties'];
713 if ( ( ( typeof properties !== 'undefined' ) && ( properties ) ) ) { //the extra (second) condition is a particular case since only the username is defined in our global array that has no meta-name
714 for (var key in properties) {
715 if ( ( typeof properties['meta_name_value'] !== 'undefined' ) ){
716 jQuery( container_name + ' ' + '#meta-name' ).val( properties['meta_name_value'] );
717 jQuery( container_name + ' ' + '#meta-name' ).attr( 'readonly', true );
718 }
719 if ( ( typeof properties['field_title'] !== 'undefined' ) ){
720 jQuery( container_name + ' ' + '#field-title' ).val( properties['field_title'] );
721 }
722 if ( ( typeof properties['description'] !== 'undefined' ) ){
723 jQuery( container_name + ' ' + '#description' ).val( properties['description'] );
724 }
725 }
726
727 }else{
728 /* meta value when editing a field shouldn't change so we take it from the current entered value which is displayed above the edit form */
729 if( jQuery( current_field_select).parents('.update_container_wppb_manage_fields').length != 0 ){
730 meta_value = jQuery( '.row-meta-name pre', jQuery( current_field_select).parents( '.update_container_wppb_manage_fields' ).prev() ).text();
731 }
732 /* for the add form it should change */
733 else{
734
735 // Repeater fields have different meta name prefixes, stored in the GET parameter 'wppb_field_metaname_prefix'.
736 var get_parameter_prefix = wppb_get_parameter_by_name( 'wppb_field_metaname_prefix' );
737 var field_metaname_prefix = ( get_parameter_prefix == null ) ? 'custom_field' : get_parameter_prefix;
738
739 numbers = new Array();
740 jQuery( '#container_wppb_manage_fields .row-meta-name pre').each(function(){
741 meta_name = jQuery(this).text();
742 if( meta_name.indexOf( field_metaname_prefix ) !== -1 ){
743 var meta_name = meta_name.replace(field_metaname_prefix, '' );
744 /* we should have an underscore present in custom_field_# so remove it */
745 meta_name = meta_name.replace('_', '' );
746
747 if( isNaN( meta_name ) ){
748 meta_name = Math.floor((Math.random() * 200) + 100);
749 }
750 numbers.push( parseInt(meta_name) );
751 }
752
753 });
754 if( numbers.length > 0 ){
755 numbers.sort( function(a, b){return a-b} );
756 numbers.reverse();
757 meta_number = parseInt(numbers[0])+1;
758 }
759 else
760 meta_number = 1;
761
762 meta_value = field_metaname_prefix + '_' + meta_number;
763 }
764
765 jQuery( container_name + ' ' + '#meta-name' ).val( meta_value );
766 jQuery( container_name + ' ' + '#meta-name' ).attr( 'readonly', false );
767 }
768
769 //Handle user role sorting
770 wppb_handle_user_role_field( container_name );
771
772 var set_required = fields[index.trim()]['required'];
773 if ( ( typeof set_required !== 'undefined' ) && ( set_required ) ){
774 jQuery( container_name + ' ' + '#required' ).val( 'Yes' );
775 jQuery( container_name + ' ' + '#required' ).attr( 'disabled', true );
776
777 }else{
778 jQuery( container_name + ' ' + '#required' ).val( 'No' );
779 jQuery( container_name + ' ' + '#required' ).attr( 'disabled', false );
780 }
781
782 jQuery( container_name + ' ' + '.mb-list-entry-fields .button-primary' ).removeAttr( 'disabled' );
783 }
784
785
786 function wppb_get_parameter_by_name(name, url) {
787 if (!url) url = window.location.href;
788 name = name.replace(/[\[\]]/g, "\\$&");
789 var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
790 results = regex.exec(url);
791 if (!results) return null;
792 if (!results[2]) return null;
793 return decodeURIComponent(results[2].replace(/\+/g, " "));
794 }
795
796 /*
797 * Function that handles the sorting of the user roles from the Select (User Role)
798 * extra field
799 *
800 */
801 function wppb_handle_user_role_field( container_name ) {
802
803 jQuery( container_name + ' ' + '.row-user-roles .wck-checkboxes').sortable({
804
805 //Assign a custom handle for the drag and drop
806 handle: '.sortable-handle',
807
808 create: function( event, ui ) {
809
810 //Add the custom handle for drag and drop
811 jQuery(this).find('div').each( function() {
812 jQuery(this).prepend('<span class="sortable-handle"></span>');
813 });
814
815 $sortOrderInput = jQuery(this).parents('.row-user-roles').siblings('.row-user-roles-sort-order').find('input[type=text]');
816
817 if( $sortOrderInput.val() == '' ) {
818 jQuery(this).find('input[type=checkbox]').each( function() {
819 $sortOrderInput.val( $sortOrderInput.val() + ', ' + jQuery(this).val() );
820 });
821 } else {
822 sortOrderElements = $sortOrderInput.val().split(', ');
823 sortOrderElements.shift();
824
825 for( var i=0; i < sortOrderElements.length; i++ ) {
826 jQuery( container_name + ' ' + '.row-user-roles .wck-checkboxes').append( jQuery( container_name + ' ' + '.row-user-roles .wck-checkboxes input[value="' + sortOrderElements[i] + '"]').parent().parent().get(0) );
827 }
828 }
829 },
830
831 update: function( event, ui ) {
832 $sortOrderInput = ui.item.parents('.row-user-roles').siblings('.row-user-roles-sort-order').find('input[type=text]');
833 $sortOrderInput.val('');
834
835 ui.item.parent().find('input[type=checkbox]').each( function() {
836 $sortOrderInput.val( $sortOrderInput.val() + ', ' + jQuery(this).val() );
837 });
838 }
839 });
840 }
841
842 function wppb_initialize_live_select( container_name ){
843 wppb_hide_all( container_name );
844 jQuery(document).on( 'change', container_name + ' ' + '.mb-list-entry-fields #field', function () {
845 field = jQuery(this).val();
846
847 if ( field != ''){
848 wppb_hide_all( container_name );
849 wppb_display_needed_fields( field, container_name, this );
850 }else{
851 wppb_hide_all( container_name );
852 }
853 });
854 }
855
856
857 function wppb_enable_select2(container_name){
858 // Select2 initialization on manage fields.
859
860 wppbSelect2.call( jQuery( container_name + ' #field'), {
861 placeholder: 'Select an option',
862 allowClear: true
863 });
864
865 var $eventSelect = jQuery( container_name + ' #field');
866 $eventSelect.on("select2:open", function (e) {
867 jQuery('#wppb_select2_overlay').fadeIn('100')
868 });
869 $eventSelect.on("select2:close", function (e) {
870 jQuery('#wppb_select2_overlay').hide();
871 });
872 }
873
874
875 jQuery(function(){
876 wppb_initialize_live_select ( '#wppb_manage_fields' );
877 wppb_initialize_live_select ( '#container_wppb_manage_fields' );
878
879 wppb_hide_properties_for_already_added_fields( '#container_wppb_manage_fields' );
880 wppb_disable_add_entry_button ( '#wppb_manage_fields' );
881
882 var overlay = jQuery('<div id="wppb_select2_overlay"> </div>')
883 overlay.appendTo(document.body)
884
885 wppb_enable_select2('#wppb_manage_fields');
886
887 });
888
889 // Custom functionality for sorting options (see the Map POIs attributes).
890 (function ($) {
891 window.SortSelCheck = {
892 // Initiate the events and triggers.
893 init: function () {
894 SortSelCheck.assess();
895 SortSelCheck.listen();
896 },
897
898 // Listen for events.
899 listen: function () {
900 // Listen for the new element setup and trigger the expected custom event.
901 $('.wck-add-form').on('change', function() {
902 SortSelCheck.assess('wck-add-form');
903 });
904 },
905
906 // Assess the potential elements and configure these when possible.
907 assess: function (elem) {
908 var $elem = $('.wppb_sortable_checkboxes_wrap');
909 // console.log('assess triggerer ' + elem, $elem);
910 $elem.each(function() {
911 $rows = SortSelCheck.remake($(this));
912 SortSelCheck.attach($(this), $rows);
913 });
914 },
915
916 // Configure the elements that form the sortable checkboxes options.
917 remake: function ($field) {
918 var $rows = $field.children('.wck-checkboxes');
919 if (!$rows.length) {
920 $field.prepend('<div class="wck-checkboxes cozmoslabs-checkbox-list"> </div>');
921 var $rows = $field.children('.wck-checkboxes');
922 }
923 if ($rows.length) {
924 SortSelCheck.sortable($rows);
925 }
926 return $rows;
927 },
928
929 // Attach the custom dropdown options as sortable checkboxes options.
930 attach: function ($field, $rows) {
931 var $ddwn = $field.children('.wppb_selector_for_sortable_checkbox');
932 if ($ddwn.length) {
933 $ddwn.on('change', function() {
934 var val = $(this).val();
935 if ('' !== val) {
936 $rows.append('<div class="cozmoslabs-chckbox-container"><input type="checkbox" name="' + $(this).data('list') + '" id="' + $(this).data('list') + '_' + val + '" value="' + val + '" checked="checked" class="mb-checkbox mb-field"><label for="' + $(this).data('list') + '_' + val + '">' + $(this).children('option').filter(':selected').text() + '</label></div>');
937 $(this).children('option').filter(':selected').remove();
938 SortSelCheck.sortable($rows);
939 }
940 });
941 }
942 },
943
944 // Make sortable items from the list.
945 sortable: function ($list) {
946 var $items = $list.children('div');
947 $items.addClass('wppb_manage_fields_sortables');
948 $items.remove('em');
949 $items.prepend('<em class="dashicons dashicons-menu"></em> ');
950 $list.sortable({
951 items: '> div',
952 classes: {'ui-sortable': 'highlight'}
953 });
954 },
955
956 };
957
958 $(document).ready(function () {
959 // Initialize the custom functionality.
960 SortSelCheck.init('init');
961
962 // Bind the event to the custom functionality.
963 $('html').on('wpbFormMetaLoaded', function(e, elem) {
964 SortSelCheck.assess(elem);
965 });
966 });
967
968 })(jQuery);
969