-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d30ded5
commit 05b3376
Showing
3 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
(function($){ | ||
|
||
acf.add_action('ready', function( $el ){ | ||
if(acf.field_group) | ||
var acf_settings_tn = acf.field_group.field_object.extend({ | ||
type: 'tn', | ||
actions: { | ||
'render_settings': 'render', | ||
}, | ||
render: function () { | ||
var $choices = $('.acf-field-object-tab') | ||
var $input = this.setting('origin_tn_select').find('select') | ||
|
||
$input.off('select2:open') | ||
$input.on('select2:open', this.render.bind(this)) | ||
|
||
$.each($choices, function(k, c) { | ||
var data = acf.get_data($(c)) | ||
var name = $('#acf_fields-' + data.id +'-label').val() | ||
var text = name + ' (' + data.type + ')' | ||
|
||
if($input.find("option[value='" + data.key + "']").length) | ||
return | ||
|
||
var newOption = new Option(text, data.key, false, false) | ||
$input.append(newOption).trigger('change') | ||
}) | ||
} | ||
}) | ||
}) | ||
|
||
acf.add_action('prepare', function( $el ){ | ||
acf.fields.tn = acf.field.extend({ | ||
type: 'tn', | ||
$input: null, | ||
ref: null, | ||
actions: { | ||
'ready': 'render', | ||
'append': 'render', | ||
}, | ||
focus: function() { | ||
this.$input = this.$field.find('input') | ||
this.ref = this.$input.data('ref') | ||
this.$ref = $('a[data-key="' + this.ref + '"]') | ||
}, | ||
render: function () { | ||
var $ref = this.$ref | ||
|
||
var onType = function() { | ||
$ref.html(this.value) | ||
} | ||
|
||
if(this.$input.val() != ''){ | ||
$ref.html(this.$input.val()) | ||
} | ||
|
||
this.$input.off('input', onType) | ||
this.$input.on('input', onType) | ||
} | ||
}) | ||
}) | ||
|
||
})(jQuery); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
if( ! defined( 'ABSPATH' ) ) exit; | ||
|
||
if( !class_exists('origin_acf_field_tn') ) : | ||
|
||
class origin_acf_field_tn extends acf_field { | ||
|
||
function __construct( $settings ) { | ||
$this->name = 'tn'; | ||
$this->label = 'Origin/Tab Name'; | ||
$this->category = 'basic'; | ||
$this->settings = $settings; | ||
parent::__construct(); | ||
} | ||
|
||
function render_field( $field ) { | ||
?> | ||
<input | ||
type="text" | ||
data-ref="<?php echo esc_attr($field['origin_tn_select']) ?>" | ||
name="<?php echo esc_attr($field['name']) ?>" | ||
value="<?php echo esc_attr($field['value']) ?>" /> | ||
<?php | ||
} | ||
|
||
function render_field_settings( $field ) { | ||
acf_render_field_setting($field, [ | ||
'label' => 'Fields', | ||
'instructions' => 'Select a tab', | ||
'type' => 'select', | ||
'name' => 'origin_tn_select', | ||
'multiple' => 0, | ||
'allow_null' => 0, | ||
'required' => 1, | ||
'choices' => $this->get_tn_setting_choices( $field['origin_tn_select'] ), | ||
'ui' => 1, | ||
'placeholder' => '', | ||
]); | ||
} | ||
|
||
function get_tn_setting_choices( $value ) { | ||
$field = acf_get_field($value); | ||
return [$value => $field['label'] . ' (' . $field['type'] . ')']; | ||
} | ||
|
||
function input_admin_enqueue_scripts() { | ||
wp_register_script('acf-origin-tn', "{$this->settings['url']}assets/js/origin-acf-field-tab-name.js", array( 'acf-input'), $this->settings['version']); | ||
wp_enqueue_script('acf-origin-tn'); | ||
} | ||
} | ||
|
||
new origin_acf_field_tn( $this->settings ); | ||
|
||
endif; |