1(function($){ 2 3 function update_preview( value, parent ) { 4 var class_prefix = ( ACFFA.major_version >= 5 ) ? '' : 'fa '; 5 $( '.acf-field-setting-fa_live_preview .acf-input', parent ).html( acf.escHtml('<i class="' + class_prefix + value + '" aria-hidden="true"></i>') ); 6 $( '.icon_preview', parent ).html( acf.escHtml('<i class="' + class_prefix + value + '" aria-hidden="true"></i>') ); 7 } 8 9 function select2_init_args( element, parent ) { 10 return { 11 key : $( parent ).data('key'), 12 allowNull : $( element ).data('allow_null'), 13 ajax : 1, 14 ajaxAction : 'acf/fields/font-awesome/query' 15 } 16 } 17 18 function select2_init( fa_field ) { 19 var $select = $( fa_field ); 20 var parent = $( $select ).closest('.acf-field-font-awesome'); 21 22 update_preview( $select.val(), parent ); 23 24 acf.select2.init( $select, select2_init_args( fa_field, parent ), parent ); 25 } 26 27 acf.add_action( 'select2_init', function( $input, args, settings, $field ) { 28 if ( $field instanceof jQuery && $field.hasClass('fontawesome-edit') ) { 29 $field.addClass('select2_initalized'); 30 } 31 }); 32 33 // Adjust FontAwesome select2 field settings 34 acf.add_filter( 'select2_args', function( args, $select, settings, $field ) { 35 if ( $select.hasClass('select2-fontawesome') ) { 36 if ( 4 == ACFFA.major_version ) { 37 args.dropdownCssClass = 'fa-select2-drop fa4'; 38 args.containerCssClass = 'fa-select2 fa4' 39 } 40 args.escapeMarkup = function( markup ) { 41 if (typeof markup !== 'string') { 42 return markup; 43 } 44 return acf.escHtml( markup ); 45 } 46 } 47 48 return args; 49 }); 50 51 // Update FontAwesome field previews in field create area 52 acf.add_action( 'open_field/type=font-awesome', function( $el ) { 53 var $field_objects = $('.acf-field-object[data-type="font-awesome"]'); 54 55 $field_objects.each( function( index, field_object ) { 56 update_preview( $( 'select.fontawesome-create', field_object ).val(), field_object ); 57 58 if ( $( '.acf-field[data-name="icon_sets"] input[type="checkbox"][value="custom"]:checked', field_object ).length ) { 59 $( '.acf-field-setting-custom_icon_set', field_object ).show(); 60 } else { 61 $( '.acf-field-setting-custom_icon_set', field_object ).hide(); 62 } 63 64 }); 65 }); 66 67 // Uncheck standard icon set choices if 'custom icon set' is checked, and show the custom icon set select box 68 $( document ).on( 'change', '.acf-field[data-name="icon_sets"] input[type="checkbox"]', function() { 69 var parent = $( this ).closest('.acf-field-object-font-awesome'); 70 if ( $( this ).is('[value="custom"]') && $( this ).is(':checked') ) { 71 $( 'input[type="checkbox"]:not([value="custom"])', parent ).prop('checked', false); 72 $( '.acf-field-setting-custom_icon_set', parent ).show(); 73 } else { 74 $( 'input[type="checkbox"][value="custom"]', parent ).prop('checked', false); 75 $( '.acf-field-setting-custom_icon_set', parent ).hide(); 76 } 77 }); 78 79 // Handle new menu items with FontAwesome fields assigned to them 80 $( document ).on( 'menu-item-added', function( event, $menuMarkup ) { 81 var $fa_fields = $( 'select.fontawesome-edit:not(.select2_initalized)', $menuMarkup ); 82 83 if ( $fa_fields.length ) { 84 $fa_fields.each( function( index, fa_field ) { 85 select2_init( fa_field ); 86 }); 87 } 88 }); 89 90 // Update FontAwesome field previews and init select2 in field edit area 91 acf.add_action( 'ready_field/type=font-awesome append_field/type=font-awesome show_field/type=font-awesome', function( $el ) { 92 var $fa_fields = $( 'select.fontawesome-edit:not(.select2_initalized)', $el ); 93 94 if ( $fa_fields.length ) { 95 $fa_fields.each( function( index, fa_field ) { 96 select2_init( fa_field ); 97 }); 98 } 99 }); 100 101 // Update FontAwesome field previews when value changes 102 $( document ).on( 'select2:select', 'select.select2-fontawesome', function() { 103 var $input = $( this ); 104 105 if ( $input.hasClass('fontawesome-create') ) { 106 update_preview( $input.val(), $input.closest('.acf-field-object') ); 107 $('.acf-field-setting-default_label input').val( $( 'option:selected', $input ).html() ); 108 } 109 110 if ( $input.hasClass('fontawesome-edit') ) { 111 update_preview( $input.val(), $input.closest('.acf-field-font-awesome') ); 112 } 113 }); 114 115})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.