diff --git a/acf.php b/acf.php index fcd99ea..2b988af 100644 --- a/acf.php +++ b/acf.php @@ -3,7 +3,7 @@ Plugin Name: Advanced Custom Fields PRO Plugin URI: https://www.advancedcustomfields.com/ Description: Customise WordPress with powerful, professional and intuitive fields -Version: 5.5.3 +Version: 5.5.10 Author: Elliot Condon Author URI: http://www.elliotcondon.com/ Copyright: Elliot Condon @@ -58,7 +58,7 @@ class acf { // basic 'name' => __('Advanced Custom Fields', 'acf'), - 'version' => '5.5.3', + 'version' => '5.5.10', // urls 'basename' => plugin_basename( __FILE__ ), @@ -86,7 +86,8 @@ class acf { 'enqueue_select2' => true, 'enqueue_datepicker' => true, 'enqueue_datetimepicker' => true, - 'select2_version' => 3 + 'select2_version' => 3, + 'row_index_offset' => 1 ); @@ -104,8 +105,11 @@ class acf { // core acf_include('core/ajax.php'); acf_include('core/cache.php'); - acf_include('core/fields.php'); + acf_include('core/compatibility.php'); + acf_include('core/deprecated.php'); acf_include('core/field.php'); + acf_include('core/fields.php'); + acf_include('core/form.php'); acf_include('core/input.php'); acf_include('core/validation.php'); acf_include('core/json.php'); @@ -114,7 +118,6 @@ class acf { acf_include('core/loop.php'); acf_include('core/media.php'); acf_include('core/revisions.php'); - acf_include('core/compatibility.php'); acf_include('core/third_party.php'); acf_include('core/updates.php'); diff --git a/admin/field-group.php b/admin/field-group.php index 7bfe15c..9389e9e 100644 --- a/admin/field-group.php +++ b/admin/field-group.php @@ -697,8 +697,9 @@ class acf_admin_field_group { case "post_type" : // get post types + // - removed show_ui to allow 3rd party code to register a post type using a custom admin edit page $post_types = acf_get_post_types(array( - 'show_ui' => 1, + //'show_ui' => 1, 'exclude' => array('attachment') )); diff --git a/admin/field-groups.php b/admin/field-groups.php index 26574fd..f9fe0ec 100644 --- a/admin/field-groups.php +++ b/admin/field-groups.php @@ -768,6 +768,11 @@ class acf_admin_field_groups { + diff --git a/admin/install-updates.php b/admin/install-updates.php index a5a78b8..876fc2b 100644 --- a/admin/install-updates.php +++ b/admin/install-updates.php @@ -347,16 +347,6 @@ function acf_update_550() { //acf_log('acf_update_550'); do_action('acf/update_550'); - // bail early if no table - if( !acf_isset_termmeta() ) { - - update_option('acf_update_550_termmeta', 1); - echo __('Term meta upgrade not possible (termmeta table does not exist)', 'acf'); - return; - - } - - // termmeta acf_update_550_termmeta(); @@ -383,6 +373,16 @@ function acf_update_550() { //acf_log('acf_update_550'); function acf_update_550_termmeta() { //acf_log('acf_update_550_termmeta'); + // bail early if no table + if( !acf_isset_termmeta() ) { + + update_option('acf_update_550_termmeta', 1); // no longer used + //echo __('Term meta upgrade not possible (termmeta table does not exist)', 'acf'); + return; + + } + + // vars $taxonomies = get_taxonomies(false, 'objects'); diff --git a/admin/install.php b/admin/install.php index ab09a4b..1ddc0be 100644 --- a/admin/install.php +++ b/admin/install.php @@ -288,8 +288,13 @@ class acf_admin_install { function wp_upgrade( $wp_db_version, $wp_current_db_version ) { - // termmeta was added in 34370 - if( $wp_db_version >= 34370 && $wp_current_db_version < 34370 && get_option('acf_update_550_termmeta') ) { + // vars + $acf_db_version = acf_get_db_version(); + + + // termmeta was added in WP 4.4 (34370) + // if website has already updated to ACF 5.5.0, termmeta will not have yet been migrated + if( $wp_db_version >= 34370 && $wp_current_db_version < 34370 && acf_version_compare($acf_db_version, '>=', '5.5.0') ) { $this->run_update('acf_update_550_termmeta'); diff --git a/admin/views/field-group-locations.php b/admin/views/field-group-locations.php index 4131d1e..c556332 100644 --- a/admin/views/field-group-locations.php +++ b/admin/views/field-group-locations.php @@ -48,7 +48,7 @@ $rule_operators = apply_filters( 'acf/location/rule_operators', array(
-

+

diff --git a/admin/views/settings-tools-export.php b/admin/views/settings-tools-export.php index 3da5216..af69a7f 100644 --- a/admin/views/settings-tools-export.php +++ b/admin/views/settings-tools-export.php @@ -6,10 +6,10 @@ $field_groups = acf_extract_var( $args, 'field_groups'); // replace $str_replace = array( - " " => "\t", - "!!\'" => "'", - "'!!" => "", - "!!'" => "" + " " => "\t", + "'!!__(!!\'" => "__('", + "!!\', !!\'" => "', '", + "!!\')!!'" => "')" ); $preg_replace = array( diff --git a/api/api-field-group.php b/api/api-field-group.php index aa95e5a..af39f06 100644 --- a/api/api-field-group.php +++ b/api/api-field-group.php @@ -71,7 +71,7 @@ function acf_get_valid_field_group( $field_group = false ) { // filter - $field_group = apply_filters('acf/get_valid_field_group', $field_group); + $field_group = apply_filters('acf/validate_field_group', $field_group); // translate @@ -335,6 +335,10 @@ function acf_get_field_group( $selector = null ) { if( !$field_group ) return false; + // validate + $field_group = acf_get_valid_field_group( $field_group ); + + // filter for 3rd party customization $field_group = apply_filters('acf/get_field_group', $field_group); @@ -375,11 +379,7 @@ function _acf_get_field_group_by_id( $post_id = 0 ) { // bail early if no post, or is not a field group - if( empty($post) || $post->post_type != 'acf-field-group' ) { - - return false; - - } + if( empty($post) || $post->post_type != 'acf-field-group' ) return false; // modify post_status (new field-group starts as auto-draft) @@ -406,22 +406,22 @@ function _acf_get_field_group_by_id( $post_id = 0 ) { $field_group['active'] = ($post->post_status === 'publish') ? 1 : 0; - // is JSON + // override with JSON if( acf_is_local_field_group( $field_group['key'] ) ) { - // override - $field_group = acf_get_local_field_group( $field_group['key'] ); + // load JSON field + $local = acf_get_local_field_group( $field_group['key'] ); // restore ID - $field_group['ID'] = $post->ID; + $local['ID'] = $post->ID; + + + // return + return $local; } - - // validate - $field_group = acf_get_valid_field_group( $field_group ); - // return return $field_group; @@ -444,23 +444,43 @@ function _acf_get_field_group_by_id( $post_id = 0 ) { function _acf_get_field_group_by_key( $key = '' ) { - // vars - $field_group = false; - - // try JSON before DB to save query time if( acf_is_local_field_group( $key ) ) { - $field_group = acf_get_local_field_group( $key ); - - // validate - $field_group = acf_get_valid_field_group( $field_group ); - - // return - return $field_group; + return acf_get_local_field_group( $key ); } + + + // vars + $post_id = acf_get_field_group_id( $key ); + + + // bail early if no post_id + if( !$post_id ) return false; + + + // return + return _acf_get_field_group_by_id( $post_id ); + +} + +/* +* acf_get_field_group_id +* +* This function will lookup a field group's ID from the DB +* Useful for local fields to find DB sibling +* +* @type function +* @date 25/06/2015 +* @since 5.5.8 +* +* @param $key (string) +* @return $post_id (int) +*/ + +function acf_get_field_group_id( $key = '' ) { // vars $args = array( @@ -479,19 +499,11 @@ function _acf_get_field_group_by_key( $key = '' ) { // validate - if( empty($posts[0]) ) { - - return $field_group; - - } - - - // load from ID - $field_group = _acf_get_field_group_by_id( $posts[0]->ID ); + if( empty($posts) ) return 0; // return - return $field_group; + return $posts[0]->ID; } @@ -1153,8 +1165,11 @@ function acf_import_field_group( $field_group ) { function acf_prepare_field_group_for_export( $field_group ) { - // extract field group ID - $id = acf_extract_var( $field_group, 'ID' ); + // extract some args + $extract = acf_extract_vars($field_group, array( + 'ID', + 'local' // local may have added 'php' or 'json' + )); // prepare fields diff --git a/api/api-field.php b/api/api-field.php index 462bbc9..8eb9031 100644 --- a/api/api-field.php +++ b/api/api-field.php @@ -28,7 +28,7 @@ function acf_is_field_key( $key = '' ) { // special - allow local field key to be any string - if( acf_is_local_field($key) ) return true; + if( acf_is_local_field_key($key) ) return true; // return @@ -76,16 +76,18 @@ function acf_get_valid_field( $field = false ) { 'class' => '', 'conditional_logic' => 0, 'parent' => 0, - 'wrapper' => array( - 'width' => '', - 'class' => '', - 'id' => '' - ), + 'wrapper' => array(), '_name' => '', '_prepare' => 0, '_valid' => 0, )); + $field['wrapper'] = wp_parse_args($field['wrapper'], array( + 'width' => '', + 'class' => '', + 'id' => '' + )); + // _name $field['_name'] = $field['name']; @@ -96,8 +98,8 @@ function acf_get_valid_field( $field = false ) { // field specific defaults - $field = apply_filters( "acf/get_valid_field", $field ); - $field = apply_filters( "acf/get_valid_field/type={$field['type']}", $field ); + $field = apply_filters( "acf/validate_field", $field ); + $field = apply_filters( "acf/validate_field/type={$field['type']}", $field ); // translate @@ -973,6 +975,14 @@ function _acf_get_field_by_key( $key = '', $db_only = false ) { function _acf_get_field_by_name( $name = '', $db_only = false ) { + // try JSON before DB to save query time + if( !$db_only && acf_is_local_field( $name ) ) { + + return acf_get_local_field( $name ); + + } + + // vars $args = array( 'posts_per_page' => 1, @@ -1657,6 +1667,7 @@ function acf_prepare_field_for_export( $field ) { // filter for 3rd party customization $field = apply_filters( "acf/prepare_field_for_export", $field ); + $field = apply_filters( "acf/prepare_field_for_export/type={$field['type']}", $field ); // return @@ -1755,6 +1766,7 @@ function acf_prepare_field_for_import( $field ) { // filter for 3rd party customization $field = apply_filters( "acf/prepare_field_for_import", $field ); + $field = apply_filters( "acf/prepare_field_for_import/type={$field['type']}", $field ); // return @@ -1847,6 +1859,7 @@ function acf_maybe_get_sub_field( $selectors, $post_id = false, $strict = true ) // vars + $offset = acf_get_setting('row_index_offset'); $selector = acf_extract_var( $selectors, 0 ); $selectors = array_values( $selectors ); // reset keys @@ -1866,7 +1879,7 @@ function acf_maybe_get_sub_field( $selectors, $post_id = false, $strict = true ) $sub_i = $selectors[ $j ]; $sub_s = $selectors[ $j+1 ]; $field_name = $field['name']; - + // find sub field $field = acf_get_sub_field( $sub_s, $field ); @@ -1877,7 +1890,7 @@ function acf_maybe_get_sub_field( $selectors, $post_id = false, $strict = true ) // add to name - $field['name'] = $field_name . '_' . ($sub_i-1) . '_' . $field['name']; + $field['name'] = $field_name . '_' . ($sub_i-$offset) . '_' . $field['name']; } diff --git a/api/api-helpers.php b/api/api-helpers.php index b4b4eeb..d2c5bfc 100644 --- a/api/api-helpers.php +++ b/api/api-helpers.php @@ -238,6 +238,73 @@ function acf_include( $file ) { } +/* +* acf_get_external_path +* +* This function will return the path to a file within an external folder +* +* @type function +* @date 22/2/17 +* @since 5.5.8 +* +* @param $file (string) +* @param $path (string) +* @return (string) +*/ + +function acf_get_external_path( $file, $path = '' ) { + + return trailingslashit( dirname( $file ) ) . $path; + +} + + +/* +* acf_get_external_dir +* +* This function will return the url to a file within an external folder +* +* @type function +* @date 22/2/17 +* @since 5.5.8 +* +* @param $file (string) +* @param $path (string) +* @return (string) +*/ + +function acf_get_external_dir( $file, $path = '' ) { + + // vars + $external_url = ''; + $external_path = acf_get_external_path( $file, $path ); + $wp_plugin_path = wp_normalize_path(WP_PLUGIN_DIR); + $wp_content_path = wp_normalize_path(WP_CONTENT_DIR); + $wp_path = wp_normalize_path(ABSPATH); + + + // wp-content/plugins + if( strpos($external_path, $wp_plugin_path) === 0 ) { + + return str_replace($wp_plugin_path, plugins_url(), $external_path); + + } + + + // wp-content + if( strpos($external_path, $wp_content_path) === 0 ) { + + return str_replace($wp_content_path, content_url(), $external_path); + + } + + + // return + return str_replace($wp_path, home_url(), $external_path); + +} + + /* * acf_parse_args * @@ -626,7 +693,7 @@ function acf_get_post_types( $args = array() ) { $exclude[] = 'acf-field'; $exclude[] = 'acf-field-group'; - + // loop foreach( $post_types as $i => $post_type ) { @@ -1339,7 +1406,7 @@ function acf_decode_taxonomy_terms( $strings = false ) { /* * acf_decode_taxonomy_term * -* This function will convert a term string into an array of term data +* This function will return the taxonomy and term slug for a given value * * @type function * @date 31/03/2014 @@ -1349,34 +1416,71 @@ function acf_decode_taxonomy_terms( $strings = false ) { * @return (array) */ -function acf_decode_taxonomy_term( $string ) { +function acf_decode_taxonomy_term( $value ) { // vars - $r = array(); + $data = array( + 'taxonomy' => '', + 'term' => '' + ); - // vars - $data = explode(':', $string); - $taxonomy = 'category'; - $term = ''; - - - // check data - if( isset($data[1]) ) { + // int + if( is_numeric($value) ) { - $taxonomy = $data[0]; - $term = $data[1]; + $data['term'] = $value; + + // string + } elseif( is_string($value) ) { + + $value = explode(':', $value); + $data['taxonomy'] = isset($value[0]) ? $value[0] : ''; + $data['term'] = isset($value[1]) ? $value[1] : ''; + + // error + } else { + + return false; } - // add data to $r - $r['taxonomy'] = $taxonomy; - $r['term'] = $term; + // allow for term_id (Used by ACF v4) + if( is_numeric($data['term']) ) { + + // global + global $wpdb; + + + // find taxonomy + if( !$data['taxonomy'] ) { + + $data['taxonomy'] = $wpdb->get_var( $wpdb->prepare("SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d LIMIT 1", $data['term']) ); + + } + + + // find term (may have numeric slug '123') + $term = get_term_by( 'slug', $data['term'], $data['taxonomy'] ); + + + // attempt get term via ID (ACF4 uses ID) + if( !$term ) $term = get_term( $data['term'], $data['taxonomy'] ); + + + // bail early if no term + if( !$term ) return false; + + + // update + $data['taxonomy'] = $term->taxonomy; + $data['term'] = $term->slug; + + } // return - return $r; + return $data; } @@ -1490,9 +1594,11 @@ function acf_get_posts( $args = array() ) { // defaults // leave suppress_filters as true becuase we don't want any plugins to modify the query as we know exactly what $args = wp_parse_args( $args, array( - 'posts_per_page' => -1, - 'post_type' => '', - 'post_status' => 'any' + 'posts_per_page' => -1, + 'post_type' => '', + 'post_status' => 'any', + 'update_post_meta_cache' => false, + 'update_post_term_cache' => false )); @@ -2145,7 +2251,7 @@ function acf_json_encode( $json ) { // PHP at least 5.4 if( version_compare(PHP_VERSION, '5.4.0', '>=') ) { - return json_encode($json, JSON_PRETTY_PRINT); + return json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); } @@ -2837,6 +2943,10 @@ function acf_in_array( $value = '', $array = false ) { function acf_get_valid_post_id( $post_id = 0 ) { + // vars + $_post_id = $post_id; + + // if not $post_id, load queried object if( !$post_id ) { @@ -2869,8 +2979,8 @@ function acf_get_valid_post_id( $post_id = 0 ) { // term } elseif( isset($post_id->taxonomy, $post_id->term_id) ) { - - $post_id = 'term_' . $post_id->term_id; + + $post_id = acf_get_term_post_id( $post_id->taxonomy, $post_id->term_id ); // comment } elseif( isset($post_id->comment_ID) ) { @@ -2910,43 +3020,9 @@ function acf_get_valid_post_id( $post_id = 0 ) { } - /* - * Override for preview - * - * If the $_GET['preview_id'] is set, then the user wants to see the preview data. - * There is also the case of previewing a page with post_id = 1, but using get_field - * to load data from another post_id. - * In this case, we need to make sure that the autosave revision is actually related - * to the $post_id variable. If they match, then the autosave data will be used, otherwise, - * the user wants to load data from a completely different post_id - */ - - if( isset($_GET['preview_id']) ) { - - $autosave = wp_get_post_autosave( $_GET['preview_id'] ); - - if( $autosave && $autosave->post_parent == $post_id ) { - - $post_id = (int) $autosave->ID; - - } - - } elseif( isset($_GET['p']) && isset($_GET['preview']) ) { - - $revision = acf_get_post_latest_revision( $_GET['p'] ); - - // save - if( $revision && $revision->post_parent == $post_id) { - - $post_id = (int) $revision->ID; - - } - - } - // filter for 3rd party - $post_id = apply_filters('acf/get_valid_post_id', $post_id); + $post_id = apply_filters('acf/validate_post_id', $post_id, $_post_id); // return @@ -3001,7 +3077,7 @@ function acf_get_post_id_info( $post_id = 0 ) { $type = explode($glue, $post_id); $id = array_pop($type); $type = implode($glue, $type); - $meta = array('post', 'user', 'comment', 'term'); // add in 'term' + $meta = array('post', 'user', 'comment', 'term'); // check if is taxonomy (ACF < 5.5) @@ -3035,6 +3111,7 @@ function acf_get_post_id_info( $post_id = 0 ) { } + /* acf_log( acf_get_post_id_info(4) ); @@ -3088,6 +3165,36 @@ function acf_isset_termmeta( $taxonomy = '' ) { } +/* +* acf_get_term_post_id +* +* This function will return a valid post_id string for a given term and taxonomy +* +* @type function +* @date 6/2/17 +* @since 5.5.6 +* +* @param $taxonomy (string) +* @param $term_id (int) +* @return (string) +*/ + +function acf_get_term_post_id( $taxonomy, $term_id ) { + + // WP < 4.4 + if( !acf_isset_termmeta() ) { + + return $taxonomy . '_' . $term_id; + + } + + + // return + return 'term_' . $term_id; + +} + + /* * acf_upload_files * @@ -3845,7 +3952,8 @@ function acf_validate_attachment( $attachment, $field, $context = 'prepare' ) { // custom } else { - $file = wp_parse_args($file, $attachment); + $file = array_merge($file, $attachment); + $file['type'] = pathinfo($attachment['url'], PATHINFO_EXTENSION); } @@ -4105,7 +4213,8 @@ function acf_translate( $string ) { function acf_maybe_add_action( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) { // if action has already run, execute it - if( did_action($tag) ) { + // - if currently doing action, allow $tag to be added as per usual to allow $priority ordering needed for 3rd party asset compatibility + if( did_action($tag) && !doing_action($tag) ) { call_user_func( $function_to_add ); @@ -4913,4 +5022,151 @@ function _acf_settings_slug( $v ) { return $slug; } + + + +/* +* acf_strip_protocol +* +* This function will remove the proticol from a url +* Used to allow licences to remain active if a site is switched to https +* +* @type function +* @date 10/01/2017 +* @since 5.5.4 +* @author Aaron +* +* @param $url (string) +* @return (string) +*/ + +function acf_strip_protocol( $url ) { + + // strip the protical + return str_replace(array('http://','https://'), '', $url); + +} + + +/* +* acf_connect_attachment_to_post +* +* This function will connect an attacment (image etc) to the post +* Used to connect attachements uploaded directly to media that have not been attaced to a post +* +* @type function +* @date 11/01/2017 +* @since 5.5.4 +* +* @param $attachment_id (int) +* @param $post_id (int) +* @return (boolean) +*/ + +function acf_connect_attachment_to_post( $attachment_id = 0, $post_id = 0 ) { + + // bail ealry if $attachment_id is not valid + if( !$attachment_id || !is_numeric($attachment_id) ) return false; + + + // bail ealry if $post_id is not valid + if( !$post_id || !is_numeric($post_id) ) return false; + + + // vars + $post = get_post( $attachment_id ); + + + // check if valid post + if( $post && $post->post_type == 'attachment' && $post->post_parent == 0 ) { + + // update + wp_update_post( array('ID' => $post->ID, 'post_parent' => $post_id) ); + + + // return + return true; + + } + + + // return + return true; + +} + + +/* +* acf_encrypt +* +* This function will encrypt a string using PHP +* https://bhoover.com/using-php-openssl_encrypt-openssl_decrypt-encrypt-decrypt-data/ +* +* @type function +* @date 27/2/17 +* @since 5.5.8 +* +* @param $data (string) +* @return (string) +*/ + + +function acf_encrypt( $data = '' ) { + + // bail ealry if no encrypt function + if( !function_exists('openssl_encrypt') ) return base64_encode($data); + + + // generate a key + $key = wp_hash('acf_encrypt'); + + + // Generate an initialization vector + $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc')); + + + // Encrypt the data using AES 256 encryption in CBC mode using our encryption key and initialization vector. + $encrypted_data = openssl_encrypt($data, 'aes-256-cbc', $key, 0, $iv); + + + // The $iv is just as important as the key for decrypting, so save it with our encrypted data using a unique separator (::) + return base64_encode($encrypted_data . '::' . $iv); + +} + + +/* +* acf_decrypt +* +* This function will decrypt an encrypted string using PHP +* https://bhoover.com/using-php-openssl_encrypt-openssl_decrypt-encrypt-decrypt-data/ +* +* @type function +* @date 27/2/17 +* @since 5.5.8 +* +* @param $data (string) +* @return (string) +*/ + +function acf_decrypt( $data = '' ) { + + // bail ealry if no decrypt function + if( !function_exists('openssl_decrypt') ) return base64_decode($data); + + + // generate a key + $key = wp_hash('acf_encrypt'); + + + // To decrypt, split the encrypted data from our IV - our unique separator used was "::" + list($encrypted_data, $iv) = explode('::', base64_decode($data), 2); + + + // decrypt + return openssl_decrypt($encrypted_data, 'aes-256-cbc', $key, 0, $iv); + +} + + ?> diff --git a/api/api-template.php b/api/api-template.php index ad970cc..5e8c520 100644 --- a/api/api-template.php +++ b/api/api-template.php @@ -627,10 +627,11 @@ function get_row_index() { // vars $i = acf_get_loop('active', 'i'); + $offset = acf_get_setting('row_index_offset'); // return - return $i + 1; + return $offset + $i; } @@ -946,8 +947,8 @@ function get_row_layout() { * @return (string) */ -function acf_shortcode( $atts ) -{ +function acf_shortcode( $atts ) { + // extract attributs extract( shortcode_atts( array( 'field' => '', @@ -960,594 +961,20 @@ function acf_shortcode( $atts ) $value = get_field( $field, $post_id, $format_value ); - if( is_array($value) ) - { + // array + if( is_array($value) ) { + $value = @implode( ', ', $value ); + } + // return return $value; -} -add_shortcode( 'acf', 'acf_shortcode' ); - - - -/* -* acf_template_form -* -* This class contains funcitonality for a template form to work -* -* @type function -* @date 7/09/2016 -* @since 5.4.0 -* -* @param $post_id (int) -* @return $post_id (int) -*/ - -if( ! class_exists('acf_template_form') ) : - -class acf_template_form { - - // vars - var $fields; - - - /* - * __construct - * - * This function will setup the class functionality - * - * @type function - * @date 5/03/2014 - * @since 5.0.0 - * - * @param n/a - * @return n/a - */ - - function __construct() { - - // vars - $this->fields = array( - - '_post_title' => array( - 'prefix' => 'acf', - 'name' => '_post_title', - 'key' => '_post_title', - 'label' => __('Title', 'acf'), - 'type' => 'text', - 'required' => true, - ), - - '_post_content' => array( - 'prefix' => 'acf', - 'name' => '_post_content', - 'key' => '_post_content', - 'label' => __('Content', 'acf'), - 'type' => 'wysiwyg', - ), - - '_validate_email' => array( - 'prefix' => 'acf', - 'name' => '_validate_email', - 'key' => '_validate_email', - 'label' => __('Validate Email', 'acf'), - 'type' => 'text', - 'value' => '', - 'wrapper' => array('style' => 'display:none !important;') - ) - - ); - - - // actions - add_action('acf/validate_save_post', array($this, 'validate_save_post'), 1); - - - // filters - add_filter('acf/pre_save_post', array($this, 'pre_save_post'), 5, 2); - - } - - - /* - * validate_save_post - * - * This function will validate fields from the above array - * - * @type function - * @date 7/09/2016 - * @since 5.4.0 - * - * @param $post_id (int) - * @return $post_id (int) - */ - - function validate_save_post() { - - // register field if isset in $_POST - foreach( $this->fields as $k => $field ) { - - // bail early if no in $_POST - if( !isset($_POST['acf'][ $k ]) ) continue; - - - // register - acf_add_local_field($field); - - } - - - // honeypot - if( !empty($_POST['acf']['_validate_email']) ) { - - acf_add_validation_error( '', __('Spam Detected', 'acf') ); - - } - - } - - - /* - * pre_save_post - * - * description - * - * @type function - * @date 7/09/2016 - * @since 5.4.0 - * - * @param $post_id (int) - * @return $post_id (int) - */ - - function pre_save_post( $post_id, $form ) { - - // vars - $save = array( - 'ID' => 0 - ); - - - // determine save data - if( is_numeric($post_id) ) { - - // update post - $save['ID'] = $post_id; - - } elseif( $post_id == 'new_post' ) { - - // new post - $form['new_post'] = wp_parse_args( $form['new_post'], array( - 'post_type' => 'post', - 'post_status' => 'draft', - )); - - - // merge in new post data - $save = array_merge($save, $form['new_post']); - - } else { - - // not post - return $post_id; - - } - - - // save post_title - if( isset($_POST['acf']['_post_title']) ) { - - $save['post_title'] = acf_extract_var($_POST['acf'], '_post_title'); - - } - - - // save post_content - if( isset($_POST['acf']['_post_content']) ) { - - $save['post_content'] = acf_extract_var($_POST['acf'], '_post_content'); - - } - - - // honeypot - if( !empty($_POST['acf']['_validate_email']) ) return; - - - // validate - if( count($save) == 1 ) { - - return $post_id; - - } - - - if( $save['ID'] ) { - - wp_update_post( $save ); - - } else { - - $post_id = wp_insert_post( $save ); - - } - - - // return - return $post_id; - - } - - - /* - * enqueue - * - * This function will enqueue a form - * - * @type function - * @date 7/09/2016 - * @since 5.4.0 - * - * @param $post_id (int) - * @return $post_id (int) - */ - - function enqueue_form() { - - // verify nonce - if( acf_verify_nonce('acf_form') ) { - - // validate data - if( acf_validate_save_post(true) ) { - - // form - $GLOBALS['acf_form'] = acf_extract_var($_POST, '_acf_form'); - $GLOBALS['acf_form'] = @json_decode(base64_decode($GLOBALS['acf_form']), true); - - - // validate - if( empty($GLOBALS['acf_form']) ) return; - - - // vars - $post_id = acf_maybe_get( $GLOBALS['acf_form'], 'post_id', 0 ); - - - // allow for custom save - $post_id = apply_filters('acf/pre_save_post', $post_id, $GLOBALS['acf_form']); - - - // save - acf_save_post( $post_id ); - - - // vars - $return = acf_maybe_get( $GLOBALS['acf_form'], 'return', '' ); - - - // redirect - if( $return ) { - - // update %placeholders% - $return = str_replace('%post_url%', get_permalink($post_id), $return); - - - // redirect - wp_redirect( $return ); - exit; - } - - } - // if - - } - // if - - - // load acf scripts - acf_enqueue_scripts(); - - } - - - /* - * render - * - * description - * - * @type function - * @date 7/09/2016 - * @since 5.4.0 - * - * @param $post_id (int) - * @return $post_id (int) - */ - - function render_form( $args = array() ) { - - // vars - $url = acf_get_current_url(); - - - // defaults - $args = wp_parse_args( $args, array( - 'id' => 'acf-form', - 'post_id' => false, - 'new_post' => false, - 'field_groups' => false, - 'fields' => false, - 'post_title' => false, - 'post_content' => false, - 'form' => true, - 'form_attributes' => array(), - 'return' => add_query_arg( 'updated', 'true', $url ), - 'html_before_fields' => '', - 'html_after_fields' => '', - 'submit_value' => __("Update", 'acf'), - 'updated_message' => __("Post updated", 'acf'), - 'label_placement' => 'top', - 'instruction_placement' => 'label', - 'field_el' => 'div', - 'uploader' => 'wp', - 'honeypot' => true - )); - - $args['form_attributes'] = wp_parse_args( $args['form_attributes'], array( - 'id' => $args['id'], - 'class' => 'acf-form', - 'action' => '', - 'method' => 'post', - )); - - - // filter post_id - $args['post_id'] = acf_get_valid_post_id( $args['post_id'] ); - - - // load values from this post - $post_id = $args['post_id']; - - - // new post? - if( $post_id == 'new_post' ) { - - // dont load values - $post_id = false; - - - // new post defaults - $args['new_post'] = wp_parse_args( $args['new_post'], array( - 'post_type' => 'post', - 'post_status' => 'draft', - )); - - } - - - // register local fields - foreach( $this->fields as $k => $field ) { - - acf_add_local_field($field); - - } - - - // vars - $field_groups = array(); - $fields = array(); - - - // post_title - if( $args['post_title'] ) { - - // load local field - $_post_title = acf_get_field('_post_title'); - $_post_title['value'] = $post_id ? get_post_field('post_title', $post_id) : ''; - - - // append - $fields[] = $_post_title; - - } - - - // post_content - if( $args['post_content'] ) { - - // load local field - $_post_content = acf_get_field('_post_content'); - $_post_content['value'] = $post_id ? get_post_field('post_content', $post_id) : ''; - - - // append - $fields[] = $_post_content; - - } - - - // specific fields - if( $args['fields'] ) { - - foreach( $args['fields'] as $selector ) { - - // append field ($strict = false to allow for better compatibility with field names) - $fields[] = acf_maybe_get_field( $selector, $post_id, false ); - - } - - } elseif( $args['field_groups'] ) { - - foreach( $args['field_groups'] as $selector ) { - - $field_groups[] = acf_get_field_group( $selector ); - - } - - } elseif( $args['post_id'] == 'new_post' ) { - - $field_groups = acf_get_field_groups( $args['new_post'] ); - - } else { - - $field_groups = acf_get_field_groups(array( - 'post_id' => $args['post_id'] - )); - - } - - - //load fields based on field groups - if( !empty($field_groups) ) { - - foreach( $field_groups as $field_group ) { - - $field_group_fields = acf_get_fields( $field_group ); - - if( !empty($field_group_fields) ) { - - foreach( array_keys($field_group_fields) as $i ) { - - $fields[] = acf_extract_var($field_group_fields, $i); - } - - } - - } - - } - - - // honeypot - if( $args['honeypot'] ) { - - $fields[] = acf_get_field('_validate_email'); - - } - - - // updated message - if( !empty($_GET['updated']) && $args['updated_message'] ) { - - echo '

' . $args['updated_message'] . '

'; - - } - - - // uploader (always set incase of multiple forms on the page) - acf_update_setting('uploader', $args['uploader']); - - - // display form - if( $args['form'] ): ?> - -
> - - $args['post_id'], - 'nonce' => 'acf_form' - )); - - ?> - -
- '_acf_form', 'value' => base64_encode(json_encode($args)) )); ?> -
- -
- -
- - - -
- - - - -
- -
- template_form = new acf_template_form(); - -endif; // class_exists check - - -/* -* acf_form_head() -* -* This function is placed at the very top of a template (before any HTML is rendered) and saves the $_POST data sent by acf_form. -* -* @type function -* @since 1.1.4 -* @date 29/01/13 -* -* @param n/a -* @return n/a -*/ - -function acf_form_head() { - - acf()->template_form->enqueue_form(); - -} - - -/* -* acf_form() -* -* This function is used to create an ACF form. -* -* @type function -* @since 1.1.4 -* @date 29/01/13 -* -* @param array $options: an array containing many options to customize the form -* string + post_id: post id to get field groups from and save data to. Default is false -* array + field_groups: an array containing field group ID's. If this option is set, -* the post_id will not be used to dynamically find the field groups -* boolean + form: display the form tag or not. Defaults to true -* array + form_attributes: an array containg attributes which will be added into the form tag -* string + return: the return URL -* string + html_before_fields: html inside form before fields -* string + html_after_fields: html inside form after fields -* string + submit_value: value of submit button -* string + updated_message: default updated message. Can be false -* -* @return N/A -*/ - -function acf_form( $args = array() ) { - - acf()->template_form->render_form($args); - -} +add_shortcode('acf', 'acf_shortcode'); /* @@ -1576,13 +1003,14 @@ function update_field( $selector, $value, $post_id = false ) { // create dummy field - if( !$field ) - { + if( !$field ) { + $field = acf_get_valid_field(array( 'name' => $selector, 'key' => '', 'type' => '', )); + } @@ -1613,17 +1041,15 @@ function update_sub_field( $selector, $value, $post_id = false ) { $sub_field = false; - // filter post_id - $post_id = acf_get_valid_post_id( $post_id ); - - // get sub field if( is_array($selector) ) { + $post_id = acf_get_valid_post_id( $post_id ); $sub_field = acf_maybe_get_sub_field( $selector, $post_id, false ); - + } else { + $post_id = acf_get_loop('active', 'post_id'); $sub_field = get_row_sub_field( $selector ); } @@ -1713,7 +1139,7 @@ function add_row( $selector, $row = false, $post_id = false ) { // get field - $field = acf_maybe_get_field( $selector, $post_id ); + $field = acf_maybe_get_field( $selector, $post_id, false ); // bail early if no field @@ -1733,7 +1159,11 @@ function add_row( $selector, $row = false, $post_id = false ) { // update value - return acf_update_value( $value, $post_id, $field ); + acf_update_value( $value, $post_id, $field ); + + + // return + return count($value); } @@ -1759,17 +1189,15 @@ function add_sub_row( $selector, $row = false, $post_id = false ) { $sub_field = false; - // filter post_id - $post_id = acf_get_valid_post_id( $post_id ); - - // get sub field if( is_array($selector) ) { + $post_id = acf_get_valid_post_id( $post_id ); $sub_field = acf_maybe_get_sub_field( $selector, $post_id, false ); } else { + $post_id = acf_get_loop('active', 'post_id'); $sub_field = get_row_sub_field( $selector ); } @@ -1792,7 +1220,11 @@ function add_sub_row( $selector, $row = false, $post_id = false ) { // update - return acf_update_value( $value, $post_id, $sub_field ); + acf_update_value( $value, $post_id, $sub_field ); + + + // return + return count($value); } @@ -1816,7 +1248,8 @@ function add_sub_row( $selector, $row = false, $post_id = false ) { function update_row( $selector, $i = 1, $row = false, $post_id = false ) { // vars - $i--; + $offset = acf_get_setting('row_index_offset'); + $i = $i - $offset; // filter post_id @@ -1824,7 +1257,7 @@ function update_row( $selector, $i = 1, $row = false, $post_id = false ) { // get field - $field = acf_maybe_get_field( $selector, $post_id ); + $field = acf_maybe_get_field( $selector, $post_id, false ); // bail early if no field @@ -1872,20 +1305,19 @@ function update_sub_row( $selector, $i = 1, $row = false, $post_id = false ) { // vars $sub_field = false; - $i--; - - - // filter post_id - $post_id = acf_get_valid_post_id( $post_id ); + $offset = acf_get_setting('row_index_offset'); + $i = $i - $offset; // get sub field if( is_array($selector) ) { + $post_id = acf_get_valid_post_id( $post_id ); $sub_field = acf_maybe_get_sub_field( $selector, $post_id, false ); } else { + $post_id = acf_get_loop('active', 'post_id'); $sub_field = get_row_sub_field( $selector ); } @@ -1935,7 +1367,8 @@ function update_sub_row( $selector, $i = 1, $row = false, $post_id = false ) { function delete_row( $selector, $i = 1, $post_id = false ) { // vars - $i--; + $offset = acf_get_setting('row_index_offset'); + $i = $i - $offset; // filter post_id @@ -1957,13 +1390,21 @@ function delete_row( $selector, $i = 1, $post_id = false ) { // ensure array $value = acf_get_array($value); + + // bail early if index doesn't exist + if( !isset($value[ $i ]) ) return false; + // unset unset( $value[ $i ] ); // update - return acf_update_value( $value, $post_id, $field ); + acf_update_value( $value, $post_id, $field ); + + + // return + return true; } @@ -1987,20 +1428,19 @@ function delete_sub_row( $selector, $i = 1, $post_id = false ) { // vars $sub_field = false; - $i--; - - - // filter post_id - $post_id = acf_get_valid_post_id( $post_id ); + $offset = acf_get_setting('row_index_offset'); + $i = $i - $offset; // get sub field if( is_array($selector) ) { + $post_id = acf_get_valid_post_id( $post_id ); $sub_field = acf_maybe_get_sub_field( $selector, $post_id, false ); } else { + $post_id = acf_get_loop('active', 'post_id'); $sub_field = get_row_sub_field( $selector ); } @@ -2018,12 +1458,20 @@ function delete_sub_row( $selector, $i = 1, $post_id = false ) { $value = acf_get_array( $value ); + // bail early if index doesn't exist + if( !isset($value[ $i ]) ) return false; + + // append unset( $value[ $i ] ); // update - return acf_update_value( $value, $post_id, $sub_field ); + acf_update_value( $value, $post_id, $sub_field ); + + + // return + return true; } @@ -2041,12 +1489,6 @@ function delete_sub_row( $selector, $i = 1, $post_id = false ) { * @return n/a */ -function register_field_group( $field_group ) { - - acf_add_local_field_group( $field_group ); - -} - function create_field( $field ) { acf_render_field( $field ); diff --git a/api/api-value.php b/api/api-value.php index 82378ed..9ba6239 100644 --- a/api/api-value.php +++ b/api/api-value.php @@ -351,7 +351,15 @@ function acf_update_value( $value = null, $post_id = 0, $field ) { $value = apply_filters( "acf/update_value/name={$field['name']}", $value, $post_id, $field ); $value = apply_filters( "acf/update_value/key={$field['key']}", $value, $post_id, $field ); - + + // allow null to delete + if( $value === null ) { + + return acf_delete_value( $post_id, $field ); + + } + + // update value $return = acf_update_metadata( $post_id, $field['name'], $value ); diff --git a/assets/css/acf-field-group.css b/assets/css/acf-field-group.css index be17e24..8072912 100644 --- a/assets/css/acf-field-group.css +++ b/assets/css/acf-field-group.css @@ -37,6 +37,15 @@ * Postbox: Fields * *---------------------------------------------------------------------------------------------*/ +.acf-field p.description { + margin: 0; + padding: 0; + font-style: normal; + font-size: 12px; + line-height: 1.4em; + color: #777777; + display: block; +} #acf-field-group-fields > .inside, #acf-field-group-locations > .inside, #acf-field-group-options > .inside { diff --git a/assets/css/acf-global.css b/assets/css/acf-global.css index 324d193..eb42c78 100644 --- a/assets/css/acf-global.css +++ b/assets/css/acf-global.css @@ -636,48 +636,53 @@ a.acf-icon.-cancel.grey:hover { margin: 0; width: 100%; clear: both; + /* defaults */ + /* thead */ + /* tbody */ + /* -clear */ } -.acf-table > tbody > tr { - z-index: 1; -} +.acf-table > tbody > tr > th, .acf-table > thead > tr > th, -.acf-table > tbody > tr > td { +.acf-table > tbody > tr > td, +.acf-table > thead > tr > td { padding: 8px; vertical-align: top; background: #fff; text-align: left; - font-size: 14px; - line-height: 1.4em; border-style: solid; - border-color: #EDEDED; - border-width: 1px 0 0 1px; + font-weight: normal; } -/* th */ +.acf-table > tbody > tr > th, .acf-table > thead > tr > th { position: relative; color: #333333; - font-weight: normal; +} +.acf-table > thead > tr > th { border-color: #E1E1E1; border-width: 0 0 1px 1px; } .acf-table > thead > tr > th:first-child { border-left-width: 0; } -/* td */ -.acf-table > tbody > tr > td { - font-size: 13px; +.acf-table > tbody > tr { + z-index: 1; } -.acf-table > tbody > tr:first-child > td { - border-top-width: 0; +.acf-table > tbody > tr > td { + border-color: #EDEDED; + border-width: 1px 0 0 1px; } .acf-table > tbody > tr > td:first-child { border-left-width: 0; } -/* clear table */ +.acf-table > tbody > tr:first-child > td { + border-top-width: 0; +} .acf-table.-clear { border: 0 none; } .acf-table.-clear > tbody > tr > td, +.acf-table.-clear > thead > tr > td, +.acf-table.-clear > tbody > tr > th, .acf-table.-clear > thead > tr > th { border: 0 none; padding: 4px; diff --git a/assets/css/acf-input.css b/assets/css/acf-input.css index ff7eefd..4966a66 100644 --- a/assets/css/acf-input.css +++ b/assets/css/acf-input.css @@ -24,6 +24,11 @@ /* input */ /* error */ } +.acf-field p.description { + display: block; + margin: 0; + padding: 0; +} .acf-field .acf-label { vertical-align: top; margin: 0 0 10px; @@ -31,22 +36,15 @@ .acf-field .acf-label label { display: block; font-weight: bold; - font-size: 13px; - line-height: 1.4em; margin: 0 0 3px; -} -.acf-field .acf-label p { - color: #777777; - display: block; - font-size: 12px; - line-height: 1.4em; - font-style: normal; - margin: 3px 0 0 !important; - padding: 0 !important; + padding: 0; } .acf-field .acf-input { vertical-align: top; } +.acf-field .acf-input > p.description { + margin-top: 5px; +} .acf-field .acf-error-message { background: #F55E4F; color: #fff; @@ -497,9 +495,6 @@ html[dir="rtl"] input.acf-is-prepended.acf-is-appended { margin: 0; padding: 5px 5px 5px 7px; } -.select2-container.-acf .select2-search-choice-close { - margin-top: -1px; -} .select2-container.-acf .select2-choice { border-color: #BBBBBB; } @@ -520,6 +515,17 @@ html[dir="rtl"] input.acf-is-prepended.acf-is-appended { background: #fff; border-color: #5B9DD9; } +/* rtl */ +html[dir="rtl"] .select2-container.-acf .select2-search-choice-close { + left: 24px; +} +html[dir="rtl"] .select2-container.-acf .select2-choice > .select2-chosen { + margin-left: 42px; +} +html[dir="rtl"] .select2-container.-acf .select2-choice .select2-arrow { + padding-left: 0; + padding-right: 1px; +} /* description */ .select2-drop { /* search*/ @@ -637,6 +643,7 @@ html[dir="rtl"] ul.acf-checkbox-list input[type="radio"] { transition: background 0.25s ease; /* hover */ /* active */ + /* focus */ /* message */ } .acf-switch span { @@ -681,9 +688,23 @@ html[dir="rtl"] ul.acf-checkbox-list input[type="radio"] { right: 3px; border-color: #1f7db1; } +.acf-switch.-focus .acf-switch-slider { + border-color: #5b9dd9; + box-shadow: 0 0 2px rgba(30, 140, 190, 0.5); +} +.acf-switch.-focus.-on .acf-switch-slider { + border-color: #185e85; + box-shadow: 0 0 2px #1f7db1; +} .acf-switch + span { margin-left: 6px; } +/* checkbox */ +.acf-switch-input { + opacity: 0; + position: absolute; + margin: 0; +} /* .acf-field[data-name="alt"] .acf-switch { background: #fff; @@ -1021,6 +1042,10 @@ html[dir="rtl"] .acf-relationship .selection .values .acf-icon { .acf-editor-wrap.tmce-active .wp-editor-area { color: #333 !important; } +/* fix z-index behind media modal */ +div.mce-toolbar-grp.mce-inline-toolbar-grp { + z-index: 170000; +} /*--------------------------------------------------------------------------------------------- * * Tab @@ -1667,19 +1692,22 @@ html[dir="rtl"] .acf-taxonomy-field[data-type="select"] .acf-icon { float: left; } .media-modal .compat-attachment-fields > tbody > .acf-field > .acf-label > label { - padding-top: 7px; - margin: 5px 0 0; + padding-top: 6px; + margin: 0; color: #666666; font-weight: 400; line-height: 16px; } .media-modal .compat-attachment-fields > tbody > .acf-field > .acf-input { width: 65%; - margin: 5px 0 0; + margin: 0; padding: 0; float: right; display: block; } +.media-modal .compat-attachment-fields > tbody > .acf-field p.description { + margin: 0; +} /* restricted selection (copy of WP .upload-errors)*/ .acf-selection-error { background: #ffebe8; @@ -1718,8 +1746,7 @@ html[dir="rtl"] .acf-taxonomy-field[data-type="select"] .acf-icon { /* fix % margin which causes .acf-uploadedTo to drop down below select */ /* allow line breaks in upload error */ /* fix required span */ - /* Sidebar: Collapse */ - /* Create gallery fix */ + /* sidebar */ /* mobile md */ } .media-modal .compat-field-acf-form-data, @@ -1747,28 +1774,8 @@ html[dir="rtl"] .acf-taxonomy-field[data-type="select"] .acf-icon { float: none !important; color: #f00 !important; } -.media-modal .compat-item .label { - margin: 0; -} -.media-modal .media-sidebar .setting span, -.media-modal .compat-item label span, -.media-modal .media-sidebar .setting input, -.media-modal .media-sidebar .setting textarea, -.media-modal .compat-item .field { - min-height: 0; - margin: 5px 0 0; -} -.media-modal .media-sidebar .setting span, -.media-modal .compat-item label span { - padding-top: 7px; -} -.media-modal .attachment-display-settings .setting span { - margin-top: 0; - margin-right: 3%; -} -.media-modal .media-modal .media-sidebar .collection-settings .setting span { - padding-top: 8px; - margin: 0 10px 0 0; +.media-modal .media-sidebar .compat-item { + padding-bottom: 20px; } @media (max-width: 900px) { .media-modal { @@ -1844,14 +1851,12 @@ html[dir="rtl"] .acf-taxonomy-field[data-type="select"] .acf-icon { .media-modal.acf-expanded .acf-expand-details .is-closed { display: none; } -.media-modal.acf-expanded .attachments-browser .media-toolbar { - right: 700px; -} +.media-modal.acf-expanded .media-toolbar, .media-modal.acf-expanded .attachments { - right: 700px; + right: 740px; } .media-modal.acf-expanded .media-sidebar { - width: 667px; + width: 708px; } .media-modal.acf-expanded .media-sidebar { /* label */ @@ -1869,6 +1874,9 @@ html[dir="rtl"] .acf-taxonomy-field[data-type="select"] .acf-icon { .media-modal.acf-expanded .media-sidebar .compat-attachment-fields > tbody > .acf-field > .acf-input { min-width: 77%; } +.media-modal.acf-expanded .media-sidebar .setting span { + margin-right: 2%; +} .media-modal.acf-expanded .media-sidebar .attachment-info .thumbnail { max-height: none; } @@ -1964,8 +1972,8 @@ body.major-4 .acf-media-modal.-edit .media-frame-content { } .acf-media-modal.-edit .media-sidebar { padding: 0 16px; - /* reposition thumbnail */ - /* add missing padding below fields */ + /* WP details */ + /* ACF fields */ } .acf-media-modal.-edit .media-sidebar .attachment-details { overflow: visible; @@ -1986,14 +1994,21 @@ body.major-4 .acf-media-modal.-edit .media-frame-content { .acf-media-modal.-edit .media-sidebar .attachment-details .thumbnail { margin: 0 16px 0 0; } -.acf-media-modal.-edit .media-sidebar .attachment-details label { +.acf-media-modal.-edit .media-sidebar .attachment-details .setting { display: block; overflow: hidden; float: none; width: auto; + margin: 0 0 5px; } -.acf-media-modal.-edit .media-sidebar .compat-item { - padding-bottom: 16px; +.acf-media-modal.-edit .media-sidebar .attachment-details .setting span { + margin: 0; +} +.acf-media-modal.-edit .media-sidebar .compat-attachment-fields > tbody > .acf-field { + margin: 0 0 5px; +} +.acf-media-modal.-edit .media-sidebar .compat-attachment-fields > tbody > .acf-field p.description { + margin-top: 3px; } @media (max-width: 900px) { .acf-media-modal.-edit { @@ -2092,11 +2107,19 @@ p.submit .acf-spinner { * Widget * *--------------------------------------------------------------------------------------------*/ +#widgets-right .widget .acf-field .description { + padding-left: 0; + padding-right: 0; +} +.widget .acf-field { + margin: 1em 0; +} .widget .acf-field .acf-label { - margin: 0; + margin-bottom: 5px; } .widget .acf-field .acf-label label { font-weight: normal; + margin: 0; } .widget .widget-inside > form > .acf-error-message { margin-top: 15px; diff --git a/assets/js/acf-field-group.js b/assets/js/acf-field-group.js index d124c10..02daf76 100644 --- a/assets/js/acf-field-group.js +++ b/assets/js/acf-field-group.js @@ -1308,7 +1308,7 @@ parent : acf.o.post_id, field_group : acf.o.post_id, prefix : $select.attr('name').replace('[type]', ''), - type : new_type, + type : new_type }; @@ -2315,7 +2315,7 @@ 'change_field_type' : '_change_field_type', 'change_field_label' : '_change_field_label', 'change_field_name' : '_change_field_name', - 'render_field_settings' : '_render_field_settings', + 'render_field_settings' : '_render_field_settings' }, _save_field: function( $el ){ @@ -2405,7 +2405,7 @@ acf.field_group.append = acf.model.extend({ actions: { - 'render_field_settings' : '_render_field_settings', + 'render_field_settings' : '_render_field_settings' }, render: function( $el ){ @@ -2491,7 +2491,7 @@ type: 'select', actions: { - 'render_settings': 'render', + 'render_settings': 'render' }, events: { @@ -2536,7 +2536,7 @@ type: 'radio', actions: { - 'render_settings': 'render', + 'render_settings': 'render' }, events: { @@ -2581,7 +2581,7 @@ type: 'true_false', actions: { - 'render_settings': 'render', + 'render_settings': 'render' }, events: { @@ -2627,7 +2627,7 @@ type: 'date_picker', actions: { - 'render_settings': 'render', + 'render_settings': 'render' }, events: { @@ -2720,7 +2720,7 @@ type: 'tab', actions: { - 'render_settings': 'render', + 'render_settings': 'render' }, render: function( $el ){ @@ -2844,8 +2844,244 @@ } + } + + }); + + + /* + * sub fields + * + * description + * + * @type function + * @date 31/1/17 + * @since 5.5.6 + * + * @param $post_id (int) + * @return $post_id (int) + */ + + acf.field_group.sub_fields = acf.model.extend({ + + actions: { + 'open_field': 'update_field_parent', + 'sortstop': 'update_field_parent', + 'duplicate_field': 'duplicate_field', + 'delete_field': 'delete_field', + 'change_field_type': 'change_field_type' }, + + /* + * fix_conditional_logic + * + * This function will update sub field conditional logic rules after duplication + * + * @type function + * @date 10/06/2014 + * @since 5.0.0 + * + * @param $fields (jquery selection) + * @return n/a + */ + + fix_conditional_logic : function( $fields ){ + + // build refernce + var ref = {}; + + $fields.each(function(){ + + ref[ $(this).attr('data-orig') ] = $(this).attr('data-key'); + + }); + + + $fields.find('.conditional-rule-param').each(function(){ + + // vars + var key = $(this).val(); + + + // bail early if val is not a ref key + if( !(key in ref) ) { + + return; + + } + + + // add option if doesn't yet exist + if( ! $(this).find('option[value="' + ref[key] + '"]').exists() ) { + + $(this).append(''); + + } + + + // set new val + $(this).val( ref[key] ); + + }); + + }, + + + /* + * update_field_parent + * + * This function will update field meta such as parent + * + * @type function + * @date 8/04/2014 + * @since 5.0.0 + * + * @param $el + * @return n/a + */ + + update_field_parent: function( $el ){ + + // bail early if not div.field (flexible content tr) + if( !$el.hasClass('acf-field-object') ) return; + + + // vars + var $parent = $el.parent().closest('.acf-field-object'), + val = acf.get('post_id'); + + + // find parent + if( $parent.exists() ) { + + // set as parent ID + val = acf.field_group.get_field_meta( $parent, 'ID' ); + + + // if parent is new, no ID exists + if( !val ) { + + val = acf.field_group.get_field_meta( $parent, 'key' ); + + } + + } + + + // update parent + acf.field_group.update_field_meta( $el, 'parent', val ); + + + // action for 3rd party customization + acf.do_action('update_field_parent', $el, $parent); + + }, + + + /* + * duplicate_field + * + * This function is triggered when duplicating a field + * + * @type function + * @date 8/04/2014 + * @since 5.0.0 + * + * @param $el + * @return n/a + */ + + duplicate_field: function( $el ) { + + // vars + var $fields = $el.find('.acf-field-object'); + + + // bail early if $fields are empty + if( !$fields.exists() ) { + + return; + + } + + + // loop over sub fields + $fields.each(function(){ + + // vars + var $parent = $(this).parent().closest('.acf-field-object'), + key = acf.field_group.get_field_meta( $parent, 'key'); + + + // wipe field + acf.field_group.wipe_field( $(this) ); + + + // update parent + acf.field_group.update_field_meta( $(this), 'parent', key ); + + + // save field + acf.field_group.save_field( $(this) ); + + + }); + + + // fix conditional logic rules + this.fix_conditional_logic( $fields ); + + }, + + + /* + * delete_field + * + * This function is triggered when deleting a field + * + * @type function + * @date 8/04/2014 + * @since 5.0.0 + * + * @param $el + * @return n/a + */ + + delete_field : function( $el ){ + + $el.find('.acf-field-object').each(function(){ + + acf.field_group.delete_field( $(this), false ); + + }); + + }, + + + /* + * change_field_type + * + * This function is triggered when changing a field type + * + * @type function + * @date 7/06/2014 + * @since 5.0.0 + * + * @param $post_id (int) + * @return $post_id (int) + */ + + change_field_type : function( $el ) { + + $el.find('.acf-field-object').each(function(){ + + acf.field_group.delete_field( $(this), false ); + + }); + + } + }); })(jQuery); diff --git a/assets/js/acf-field-group.min.js b/assets/js/acf-field-group.min.js index 0a97bdb..63fccfb 100644 --- a/assets/js/acf-field-group.min.js +++ b/assets/js/acf-field-group.min.js @@ -1 +1 @@ -!function($){acf.field_group=acf.model.extend({$fields:null,$locations:null,$options:null,actions:{ready:"init"},events:{"submit #post":"submit",'click a[href="#"]':"preventDefault","click .submitdelete":"trash","mouseenter .acf-field-list":"sortable"},init:function(){this.$fields=$("#acf-field-group-fields"),this.$locations=$("#acf-field-group-locations"),this.$options=$("#acf-field-group-options"),acf.validation.active=0},sortable:function(e){if(!e.$el.hasClass("ui-sortable")){var t=this;e.$el.sortable({handle:".acf-sortable-handle",connectWith:".acf-field-list",update:function(e,i){var a=i.item;t.render_fields(),acf.do_action("sortstop",a)}})}},preventDefault:function(e){e.preventDefault()},get_selector:function(e){e=e||"";var t=".acf-field-object";return e&&(t+="-"+e,t=t.split("_").join("-")),t},render_fields:function(){var e=this;$(".acf-field-list").each(function(){var t=$(this).children(".acf-field-object");t.each(function(t){e.update_field_meta($(this),"menu_order",t),$(this).children(".handle").find(".acf-icon").html(t+1)}),t.exists()?$(this).children(".no-fields-message").hide():$(this).children(".no-fields-message").show()})},get_field_meta:function(e,t){var i=e.find("> .meta > .input-"+t);return!!i.exists()&&i.val()},update_field_meta:function(e,t,i){var a=e.find("> .meta > .input-"+t);if(!a.exists()){var n=e.find("> .meta > .input-ID").outerHTML();n=acf.str_replace("ID",t,n),a=$(n),a.val(i),e.children(".meta").append(a)}a.val()!=i&&(a.val(i),"save"!=t&&this.save_field(e,"meta"))},delete_field_meta:function(e,t){var i=e.find("> .meta > .input-"+t);i.exists()&&(i.remove(),this.save_field(e,"meta"))},save_field:function(e,t){t=t||"settings";var i=this.get_field_meta(e,"save");"settings"!=i&&i!=t&&(this.update_field_meta(e,"save",t),acf.do_action("save_field",e,t))},submit:function(e){var t=this,i=$("#titlewrap #title");i.val()||(e.preventDefault(),acf.validation.toggle(e.$el,"unlock"),alert(acf._e("title_is_required")),i.focus()),$(".acf-field-object").each(function(){var e=t.get_field_meta($(this),"save"),i=t.get_field_meta($(this),"ID"),a=$(this).hasClass("open");a&&t.close_field($(this)),"settings"==e||("meta"==e?$(this).children(".settings").find('[name^="acf_fields['+i+']"]').remove():$(this).find('[name^="acf_fields['+i+']"]').remove())})},trash:function(e){var t=confirm(acf._e("move_to_trash"));t||e.preventDefault()},render_field:function(e){var t=e.find(".field-label:first").val(),i=e.find(".field-name:first").val(),a=e.find(".field-type:first option:selected").text(),n=e.find(".field-required:first").prop("checked"),d=e.children(".handle");d.find(".li-field-label strong a").text(t),d.find(".li-field-label .acf-required").remove(),n&&d.find(".li-field-label strong").append('*'),d.find(".li-field-name").text(i),d.find(".li-field-type").text(a),acf.do_action("render_field_handle",e,d)},edit_field:function(e){e.hasClass("open")?this.close_field(e):this.open_field(e)},open_field:function(e){return!e.hasClass("open")&&(e.addClass("open"),acf.do_action("open_field",e),void e.children(".settings").animate({height:"toggle"},250))},close_field:function(e){return!!e.hasClass("open")&&(e.removeClass("open"),acf.do_action("close_field",e),void e.children(".settings").animate({height:"toggle"},250))},wipe_field:function(e){var t=e.attr("data-id"),i=e.attr("data-key"),a=acf.get_uniqid(),n="field_"+a;e.attr("data-id",a),e.attr("data-key",n),e.attr("data-orig",i),this.update_field_meta(e,"ID",""),this.update_field_meta(e,"key",n),e.find('[id*="'+t+'"]').each(function(){$(this).attr("id",$(this).attr("id").replace(t,a))}),e.find('[name*="'+t+'"]').each(function(){$(this).attr("name",$(this).attr("name").replace(t,a))}),e.find("> .handle .pre-field-key").text(n),e.find(".ui-sortable").removeClass("ui-sortable"),acf.do_action("wipe_field",e)},add_field:function(e){var t=$($("#tmpl-acf-field").html()),i=t.find(".field-label:first"),a=t.find(".field-name:first");this.wipe_field(t),e.append(t),i.val(""),a.val(""),setTimeout(function(){i.focus()},251),this.render_fields(),acf.do_action("append",t),this.edit_field(t),acf.do_action("add_field",t)},duplicate_field:function(e){acf.do_action("before_duplicate",e);var t=e.clone(),i=t.find(".field-label:first"),a=t.find(".field-name:first");acf.do_action("remove",t),this.wipe_field(t),acf.do_action("after_duplicate",e,t),e.after(t),acf.do_action("append",t),setTimeout(function(){i.focus()},251),this.render_fields(),e.hasClass("open")?this.close_field(e):this.open_field(t);var n=i.val(),d=a.val(),l=d.split("_").pop(),f=acf._e("copy");if(0===l.indexOf(f)){var c=1*l.replace(f,"");c=c?c+1:2,n=n.replace(l,f+c),d=d.replace(l,f+c)}else n+=" ("+f+")",d+="_"+f;return i.val(n),a.val(d),this.save_field(t),this.render_field(t),acf.do_action("duplicate_field",t),t},move_field:function(e){var t=this,i=acf.prepare_for_ajax({action:"acf/field_group/move_field",field_id:this.get_field_meta(e,"ID")}),a=!1;return i.field_id?"settings"==this.get_field_meta(e,"save")?a=!0:e.find(".acf-field-object").each(function(){return t.get_field_meta($(this),"ID")?void("settings"==t.get_field_meta($(this),"save")&&(a=!0)):(a=!0,!1)}):a=!0,a?void alert(acf._e("move_field_warning")):(acf.open_popup({title:acf._e("move_field"),loading:!0,height:145}),void $.ajax({url:acf.get("ajaxurl"),data:i,type:"post",dataType:"html",success:function(i){t.move_field_confirm(e,i)}}))},move_field_confirm:function(e,t){var i=this;acf.update_popup({content:t});var a=acf.prepare_for_ajax({action:"acf/field_group/move_field",field_id:this.get_field_meta(e,"ID"),field_group_id:0});$("#acf-move-field-form").on("submit",function(){return a.field_group_id=$(this).find("select").val(),$.ajax({url:acf.get("ajaxurl"),data:a,type:"post",dataType:"html",success:function(t){acf.update_popup({content:t}),i.remove_field(e)}}),!1})},delete_field:function(e,t){t=t||!0;var i=this.get_field_meta(e,"ID");i&&$("#input-delete-fields").val($("#input-delete-fields").val()+"|"+i),acf.do_action("delete_field",e),t&&this.remove_field(e)},remove_field:function(e){var t=this,i=e.closest(".acf-field-list");e.css({height:e.height(),width:e.width(),position:"absolute"}),e.wrap('
'),e.animate({opacity:0},250);var a=0,n=!1;i.children(".acf-field-object").length||(n=i.children(".no-fields-message"),a=n.outerHeight()),e.parent(".temp-field-wrap").animate({height:a},250,function(){n&&n.show(),acf.do_action("remove",$(this)),$(this).remove(),t.render_fields()})},change_field_type:function(e){var t=e.closest("tbody"),i=t.closest(".acf-field-object"),a=i.parent().closest(".acf-field-object"),n=i.attr("data-key"),d=i.attr("data-type"),l=e.val();i.removeClass("acf-field-object-"+acf.str_replace("_","-",d)),i.addClass("acf-field-object-"+acf.str_replace("_","-",l)),i.attr("data-type",l),i.data("type",l),i.data("xhr")&&i.data("xhr").abort();var f=t.children('.acf-field[data-setting="'+d+'"]'),c="";if(f.each(function(){c+=$(this).outerHTML()}),f.remove(),acf.update(n+"_settings_"+d,c),this.render_field(i),c=acf.get(n+"_settings_"+l))return t.children('.acf-field[data-name="conditional_logic"]').before(c),acf.update(n+"_settings_"+l,""),void acf.do_action("change_field_type",i);var r=$('
');t.children('.acf-field[data-name="conditional_logic"]').before(r);var o={action:"acf/field_group/render_field_settings",nonce:acf.o.nonce,parent:acf.o.post_id,field_group:acf.o.post_id,prefix:e.attr("name").replace("[type]",""),type:l};a.exists()&&(o.parent=this.get_field_meta(a,"ID"));var s=$.ajax({url:acf.o.ajaxurl,data:o,type:"post",dataType:"html",success:function(e){if(e){var t=$(e);r.after(t),acf.do_action("append",t),acf.do_action("change_field_type",i)}},complete:function(){r.remove()}});i.data("xhr",s)},change_field_label:function(e){var t=e.find(".field-label:first"),i=e.find(".field-name:first"),a=e.attr("data-type");if(""==i.val()){var n=t.val();n=acf.str_sanitize(n),i.val(n).trigger("change")}this.render_field(e),acf.do_action("change_field_label",e)},change_field_name:function(e){var t=e.find(".field-name:first");"field_"===t.val().substr(0,6)&&(alert(acf._e("field_name_start")),setTimeout(function(){t.focus()},1)),acf.do_action("change_field_name",e)}}),acf.field_group.field=acf.model.extend({events:{"click .edit-field":"edit","click .duplicate-field":"duplicate","click .move-field":"move","click .delete-field":"delete","click .add-field":"add","change .field-type":"change_type","blur .field-label":"change_label","blur .field-name":"change_name","keyup .field-label":"render","keyup .field-name":"render","change .field-required":"render","change .acf-field-object input":"save","change .acf-field-object textarea":"save","change .acf-field-object select":"save"},event:function(e){return e.$field=e.$el.closest(".acf-field-object"),e},edit:function(e){acf.field_group.edit_field(e.$field)},duplicate:function(e){acf.field_group.duplicate_field(e.$field)},move:function(e){acf.field_group.move_field(e.$field)},delete:function(e){acf.field_group.delete_field(e.$field)},add:function(e){var t=e.$el.closest(".acf-field-list-wrap").children(".acf-field-list");acf.field_group.add_field(t)},change_type:function(e){acf.field_group.change_field_type(e.$el)},change_label:function(e){acf.field_group.change_field_label(e.$field)},change_name:function(e){acf.field_group.change_field_name(e.$field)},render:function(e){acf.field_group.render_field(e.$field)},save:function(e){acf.field_group.save_field(e.$field)}}),acf.field_group.conditional_logic=acf.model.extend({actions:{open_field:"render_field",change_field_label:"render_fields",change_field_type:"render_fields"},events:{"click .add-conditional-rule":"add_rule","click .add-conditional-group":"add_group","click .remove-conditional-rule":"remove_rule","change .conditional-toggle":"change_toggle","change .conditional-rule-param":"change_param"},render_fields:function(){var e=this;$(".acf-field-object.open").each(function(){e.render_field($(this))})},render_field:function(e){var t=this,i=e.attr("data-key"),a=e.parents(".acf-field-list"),n=e.find('.acf-field[data-name="conditional_logic"]:last'),d=[];$.each(a,function(e){var t=0==e?acf._e("sibling_fields"):acf._e("parent_fields");$(this).children(".acf-field-object").each(function(){var e=$(this),a=e.attr("data-key"),n=e.attr("data-type"),l=e.find(".field-label:first").val();$.inArray(n,["select","checkbox","true_false","radio"])!==-1&&a!=i&&d.push({value:a,label:l,group:t})})}),d.length||d.push({value:"",label:acf._e("no_fields")}),n.find(".rule").each(function(){t.render_rule($(this),d)})},render_rule:function(e,t){var i=e.find(".conditional-rule-param"),a=e.find(".conditional-rule-value");t&&acf.render_select(i,t);var n=$('.acf-field-object[data-key="'+i.val()+'"]'),d=n.attr("data-type"),l=[];if("true_false"==d)l.push({value:1,label:acf._e("checked")});else if("select"==d||"checkbox"==d||"radio"==d){var f=n.find('.acf-field[data-name="choices"] textarea').val().split("\n");$.each(f,function(e,t){t=t.split(":"),t[1]=t[1]||t[0],l.push({value:$.trim(t[0]),label:$.trim(t[1])})});var c=n.find('.acf-field[data-name="allow_null"]');c.exists()&&"1"==c.find("input:checked").val()&&l.unshift({value:"",label:acf._e("null")})}acf.render_select(a,l)},change_toggle:function(e){var t=e.$el,i=e.$el.prop("checked"),a=t.closest(".acf-input");i?(a.find(".rule-groups").show(),a.find(".rule-groups").find("[name]").prop("disabled",!1)):(a.find(".rule-groups").hide(),a.find(".rule-groups").find("[name]").prop("disabled",!0))},change_param:function(e){var t=e.$el.closest(".rule");this.render_rule(t)},add_rule:function(e){var t=e.$el.closest("tr");$tr2=acf.duplicate(t),$tr2.find("select:first").trigger("change")},remove_rule:function(e){var t=e.$el.closest("tr");t.find("select:first").trigger("change"),0==t.siblings("tr").length&&t.closest(".rule-group").remove(),t.remove()},add_group:function(e){var t=e.$el.closest(".rule-groups"),i=t.find(".rule-group:last");$group2=acf.duplicate(i),$group2.find("h4").text(acf._e("or")),$group2.find("tr:not(:first)").remove(),$group2.find("select:first").trigger("change")}}),acf.field_group.locations=acf.model.extend({events:{"click .add-location-rule":"add_rule","click .add-location-group":"add_group","click .remove-location-rule":"remove_rule","change .location-rule-param":"change_rule"},add_rule:function(e){var t=e.$el.closest("tr");$tr2=acf.duplicate(t)},remove_rule:function(e){var t=e.$el.closest("tr");t.find("select:first").trigger("change"),0==t.siblings("tr").length&&t.closest(".rule-group").remove(),t.remove()},add_group:function(e){var t=e.$el.closest(".rule-groups"),i=t.find(".rule-group:last");$group2=acf.duplicate(i),$group2.find("h4").text(acf._e("or")),$group2.find("tr:not(:first)").remove()},change_rule:function(e){var t=e.$el,i=t.closest("tr"),a=i.attr("data-id"),n=i.closest(".rule-group"),d=n.attr("data-id"),l=$('
');i.find("td.value").html(l),$.ajax({url:acf.get("ajaxurl"),data:acf.prepare_for_ajax({action:"acf/field_group/render_location_value",rule_id:a,group_id:d,param:t.val(),value:""}),type:"post",dataType:"html",success:function(e){l.replaceWith(e)}})}}),acf.field_group.field_object=acf.model.extend({type:"",o:{},$field:null,$settings:null,_add_action:function(e,t){var i=this,a=e.split("_");a.splice(1,0,"field"),e=a.join("_")+"/type="+i.type,acf.add_action(e,function(e){i.set("$field",e),i[t].apply(i,arguments)})},_add_filter:function(e,t){var i=this,a=e.split("_");a.splice(1,0,"field"),e=a.join("_")+"/type="+i.type,acf.add_filter(e,function(e){i.set("$field",e),i[t].apply(i,arguments)})},_add_event:function(e,t){var i=this,a=e.substr(0,e.indexOf(" ")),n=e.substr(e.indexOf(" ")+1),d=acf.field_group.get_selector(i.type);$(document).on(a,d+" "+n,function(e){e.$el=$(this),e.$field=e.$el.closest(".acf-field-object"),i.set("$field",e.$field),i[t].apply(i,[e])})},_set_$field:function(){this.o=this.$field.data(),this.$settings=this.$field.find("> .settings > table > tbody"),this.focus()},focus:function(){},setting:function(e){return this.$settings.find("> .acf-field-setting-"+e)}}),acf.field_group.field_objects=acf.model.extend({actions:{save_field:"_save_field",open_field:"_open_field",close_field:"_close_field",wipe_field:"_wipe_field",add_field:"_add_field",duplicate_field:"_duplicate_field",delete_field:"_delete_field",change_field_type:"_change_field_type",change_field_label:"_change_field_label",change_field_name:"_change_field_name",render_field_settings:"_render_field_settings"},_save_field:function(e){acf.do_action("save_field/type="+e.data("type"),e)},_open_field:function(e){acf.do_action("open_field/type="+e.data("type"),e),acf.do_action("render_field_settings",e)},_close_field:function(e){acf.do_action("close_field/type="+e.data("type"),e)},_wipe_field:function(e){acf.do_action("wipe_field/type="+e.data("type"),e)},_add_field:function(e){acf.do_action("add_field/type="+e.data("type"),e)},_duplicate_field:function(e){acf.do_action("duplicate_field/type="+e.data("type"),e)},_delete_field:function(e){acf.do_action("delete_field/type="+e.data("type"),e)},_change_field_type:function(e){acf.do_action("change_field_type/type="+e.data("type"),e),acf.do_action("render_field_settings",e)},_change_field_label:function(e){acf.do_action("change_field_label/type="+e.data("type"),e)},_change_field_name:function(e){acf.do_action("change_field_name/type="+e.data("type"),e)},_render_field_settings:function(e){acf.do_action("render_field_settings/type="+e.data("type"),e)}}),acf.field_group.append=acf.model.extend({actions:{render_field_settings:"_render_field_settings"},render:function(e){var t=e.data("append");if($sibling=e.siblings('[data-name="'+t+'"]'),$sibling.exists()){var i=$sibling.children(".acf-input"),a=i.children(".acf-hl");a.exists()||(i.wrapInner('
'),a=i.children(".acf-hl"));var n=$("
  • ").append(e.children(".acf-input").children());a.append(n),a.attr("data-cols",a.children().length),e.remove()}},_render_field_settings:function(e){var t=this;e.find(".acf-field[data-append]").each(function(){t.render($(this))})}});var e=acf.field_group.field_object.extend({type:"select",actions:{render_settings:"render"},events:{"change .acf-field-setting-ui input":"render"},render:function(e){this.setting('ui input[type="checkbox"]').prop("checked")?this.setting("ajax").show():(this.setting("ajax").hide(),this.setting('ajax input[type="checkbox"]').prop("checked",!1).trigger("change"))}}),t=acf.field_group.field_object.extend({type:"radio",actions:{render_settings:"render"},events:{"change .acf-field-setting-other_choice input":"render"},render:function(e){this.setting('other_choice input[type="checkbox"]').prop("checked")?this.setting("save_other_choice").show():(this.setting("save_other_choice").hide(),this.setting('save_other_choice input[type="checkbox"]').prop("checked",!1).trigger("change"))}}),i=acf.field_group.field_object.extend({type:"true_false",actions:{render_settings:"render"},events:{"change .acf-field-setting-ui input":"render"},render:function(e){this.setting('ui input[type="checkbox"]').prop("checked")?(this.setting("ui_on_text").show(),this.setting("ui_off_text").show()):(this.setting("ui_on_text").hide(),this.setting("ui_off_text").hide())}}),a=acf.field_group.field_object.extend({type:"date_picker",actions:{render_settings:"render"},events:{"change .acf-field-setting-display_format input":"render","change .acf-field-setting-return_format input":"render"},render:function(e){this.render_list(this.setting("display_format")),this.render_list(this.setting("return_format"))},render_list:function(e){var t=e.find("ul"),i=t.find('input[type="radio"]:checked'),a=t.find('input[type="text"]');"other"!=i.val()&&a.val(i.val())}}),n=a.extend({type:"date_time_picker"}),n=a.extend({type:"time_picker"}),d=acf.field_group.field_object.extend({type:"tab",actions:{render_settings:"render"},render:function(e){this.setting("name input").val("").trigger("change"),this.setting('required input[type="checkbox"]').prop("checked",!1).trigger("change")}}),l=d.extend({type:"message"});acf.field_group.screen=acf.model.extend({actions:{ready:"ready"},events:{"click #acf-field-key-hide":"toggle"},ready:function(){var e=$("#adv-settings"),t=e.find("#acf-append-show-on-screen");e.find(".metabox-prefs").append(t.html()),e.find(".metabox-prefs br").remove(),t.remove(),this.render()},toggle:function(e){var t=e.$el.prop("checked")?1:0;acf.update_user_setting("show_field_keys",t),this.render()},render:function(){var e=acf.serialize_form($("#adv-settings"));e.show_field_keys=parseInt(e.show_field_keys);var t=acf.field_group.$fields;e.show_field_keys?t.addClass("show-field-keys"):t.removeClass("show-field-keys")}})}(jQuery); +!function($){acf.field_group=acf.model.extend({$fields:null,$locations:null,$options:null,actions:{ready:"init"},events:{"submit #post":"submit",'click a[href="#"]':"preventDefault","click .submitdelete":"trash","mouseenter .acf-field-list":"sortable"},init:function(){this.$fields=$("#acf-field-group-fields"),this.$locations=$("#acf-field-group-locations"),this.$options=$("#acf-field-group-options"),acf.validation.active=0},sortable:function(e){if(!e.$el.hasClass("ui-sortable")){var i=this;e.$el.sortable({handle:".acf-sortable-handle",connectWith:".acf-field-list",update:function(e,t){var a=t.item;i.render_fields(),acf.do_action("sortstop",a)}})}},preventDefault:function(e){e.preventDefault()},get_selector:function(e){e=e||"";var i=".acf-field-object";return e&&(i+="-"+e,i=i.split("_").join("-")),i},render_fields:function(){var e=this;$(".acf-field-list").each(function(){var i=$(this).children(".acf-field-object");i.each(function(i){e.update_field_meta($(this),"menu_order",i),$(this).children(".handle").find(".acf-icon").html(i+1)}),i.exists()?$(this).children(".no-fields-message").hide():$(this).children(".no-fields-message").show()})},get_field_meta:function(e,i){var t=e.find("> .meta > .input-"+i);return!!t.exists()&&t.val()},update_field_meta:function(e,i,t){var a=e.find("> .meta > .input-"+i);if(!a.exists()){var d=e.find("> .meta > .input-ID").outerHTML();d=acf.str_replace("ID",i,d),a=$(d),a.val(t),e.children(".meta").append(a)}a.val()!=t&&(a.val(t),"save"!=i&&this.save_field(e,"meta"))},delete_field_meta:function(e,i){var t=e.find("> .meta > .input-"+i);t.exists()&&(t.remove(),this.save_field(e,"meta"))},save_field:function(e,i){i=i||"settings";var t=this.get_field_meta(e,"save");"settings"!=t&&t!=i&&(this.update_field_meta(e,"save",i),acf.do_action("save_field",e,i))},submit:function(e){var i=this,t=$("#titlewrap #title");t.val()||(e.preventDefault(),acf.validation.toggle(e.$el,"unlock"),alert(acf._e("title_is_required")),t.focus()),$(".acf-field-object").each(function(){var e=i.get_field_meta($(this),"save"),t=i.get_field_meta($(this),"ID"),a=$(this).hasClass("open");a&&i.close_field($(this)),"settings"==e||("meta"==e?$(this).children(".settings").find('[name^="acf_fields['+t+']"]').remove():$(this).find('[name^="acf_fields['+t+']"]').remove())})},trash:function(e){var i=confirm(acf._e("move_to_trash"));i||e.preventDefault()},render_field:function(e){var i=e.find(".field-label:first").val(),t=e.find(".field-name:first").val(),a=e.find(".field-type:first option:selected").text(),d=e.find(".field-required:first").prop("checked"),n=e.children(".handle");n.find(".li-field-label strong a").text(i),n.find(".li-field-label .acf-required").remove(),d&&n.find(".li-field-label strong").append('*'),n.find(".li-field-name").text(t),n.find(".li-field-type").text(a),acf.do_action("render_field_handle",e,n)},edit_field:function(e){e.hasClass("open")?this.close_field(e):this.open_field(e)},open_field:function(e){return!e.hasClass("open")&&(e.addClass("open"),acf.do_action("open_field",e),void e.children(".settings").animate({height:"toggle"},250))},close_field:function(e){return!!e.hasClass("open")&&(e.removeClass("open"),acf.do_action("close_field",e),void e.children(".settings").animate({height:"toggle"},250))},wipe_field:function(e){var i=e.attr("data-id"),t=e.attr("data-key"),a=acf.get_uniqid(),d="field_"+a;e.attr("data-id",a),e.attr("data-key",d),e.attr("data-orig",t),this.update_field_meta(e,"ID",""),this.update_field_meta(e,"key",d),e.find('[id*="'+i+'"]').each(function(){$(this).attr("id",$(this).attr("id").replace(i,a))}),e.find('[name*="'+i+'"]').each(function(){$(this).attr("name",$(this).attr("name").replace(i,a))}),e.find("> .handle .pre-field-key").text(d),e.find(".ui-sortable").removeClass("ui-sortable"),acf.do_action("wipe_field",e)},add_field:function(e){var i=$($("#tmpl-acf-field").html()),t=i.find(".field-label:first"),a=i.find(".field-name:first");this.wipe_field(i),e.append(i),t.val(""),a.val(""),setTimeout(function(){t.focus()},251),this.render_fields(),acf.do_action("append",i),this.edit_field(i),acf.do_action("add_field",i)},duplicate_field:function(e){acf.do_action("before_duplicate",e);var i=e.clone(),t=i.find(".field-label:first"),a=i.find(".field-name:first");acf.do_action("remove",i),this.wipe_field(i),acf.do_action("after_duplicate",e,i),e.after(i),acf.do_action("append",i),setTimeout(function(){t.focus()},251),this.render_fields(),e.hasClass("open")?this.close_field(e):this.open_field(i);var d=t.val(),n=a.val(),l=n.split("_").pop(),f=acf._e("copy");if(0===l.indexOf(f)){var c=1*l.replace(f,"");c=c?c+1:2,d=d.replace(l,f+c),n=n.replace(l,f+c)}else d+=" ("+f+")",n+="_"+f;return t.val(d),a.val(n),this.save_field(i),this.render_field(i),acf.do_action("duplicate_field",i),i},move_field:function(e){var i=this,t=acf.prepare_for_ajax({action:"acf/field_group/move_field",field_id:this.get_field_meta(e,"ID")}),a=!1;return t.field_id?"settings"==this.get_field_meta(e,"save")?a=!0:e.find(".acf-field-object").each(function(){return i.get_field_meta($(this),"ID")?void("settings"==i.get_field_meta($(this),"save")&&(a=!0)):(a=!0,!1)}):a=!0,a?void alert(acf._e("move_field_warning")):(acf.open_popup({title:acf._e("move_field"),loading:!0,height:145}),void $.ajax({url:acf.get("ajaxurl"),data:t,type:"post",dataType:"html",success:function(t){i.move_field_confirm(e,t)}}))},move_field_confirm:function(e,i){var t=this;acf.update_popup({content:i});var a=acf.prepare_for_ajax({action:"acf/field_group/move_field",field_id:this.get_field_meta(e,"ID"),field_group_id:0});$("#acf-move-field-form").on("submit",function(){return a.field_group_id=$(this).find("select").val(),$.ajax({url:acf.get("ajaxurl"),data:a,type:"post",dataType:"html",success:function(i){acf.update_popup({content:i}),t.remove_field(e)}}),!1})},delete_field:function(e,i){i=i||!0;var t=this.get_field_meta(e,"ID");t&&$("#input-delete-fields").val($("#input-delete-fields").val()+"|"+t),acf.do_action("delete_field",e),i&&this.remove_field(e)},remove_field:function(e){var i=this,t=e.closest(".acf-field-list");e.css({height:e.height(),width:e.width(),position:"absolute"}),e.wrap('
    '),e.animate({opacity:0},250);var a=0,d=!1;t.children(".acf-field-object").length||(d=t.children(".no-fields-message"),a=d.outerHeight()),e.parent(".temp-field-wrap").animate({height:a},250,function(){d&&d.show(),acf.do_action("remove",$(this)),$(this).remove(),i.render_fields()})},change_field_type:function(e){var i=e.closest("tbody"),t=i.closest(".acf-field-object"),a=t.parent().closest(".acf-field-object"),d=t.attr("data-key"),n=t.attr("data-type"),l=e.val();t.removeClass("acf-field-object-"+acf.str_replace("_","-",n)),t.addClass("acf-field-object-"+acf.str_replace("_","-",l)),t.attr("data-type",l),t.data("type",l),t.data("xhr")&&t.data("xhr").abort();var f=i.children('.acf-field[data-setting="'+n+'"]'),c="";if(f.each(function(){c+=$(this).outerHTML()}),f.remove(),acf.update(d+"_settings_"+n,c),this.render_field(t),c=acf.get(d+"_settings_"+l))return i.children('.acf-field[data-name="conditional_logic"]').before(c),acf.update(d+"_settings_"+l,""),void acf.do_action("change_field_type",t);var o=$('
    ');i.children('.acf-field[data-name="conditional_logic"]').before(o);var r={action:"acf/field_group/render_field_settings",nonce:acf.o.nonce,parent:acf.o.post_id,field_group:acf.o.post_id,prefix:e.attr("name").replace("[type]",""),type:l};a.exists()&&(r.parent=this.get_field_meta(a,"ID"));var s=$.ajax({url:acf.o.ajaxurl,data:r,type:"post",dataType:"html",success:function(e){if(e){var i=$(e);o.after(i),acf.do_action("append",i),acf.do_action("change_field_type",t)}},complete:function(){o.remove()}});t.data("xhr",s)},change_field_label:function(e){var i=e.find(".field-label:first"),t=e.find(".field-name:first"),a=e.attr("data-type");if(""==t.val()){var d=i.val();d=acf.str_sanitize(d),t.val(d).trigger("change")}this.render_field(e),acf.do_action("change_field_label",e)},change_field_name:function(e){var i=e.find(".field-name:first");"field_"===i.val().substr(0,6)&&(alert(acf._e("field_name_start")),setTimeout(function(){i.focus()},1)),acf.do_action("change_field_name",e)}}),acf.field_group.field=acf.model.extend({events:{"click .edit-field":"edit","click .duplicate-field":"duplicate","click .move-field":"move","click .delete-field":"delete","click .add-field":"add","change .field-type":"change_type","blur .field-label":"change_label","blur .field-name":"change_name","keyup .field-label":"render","keyup .field-name":"render","change .field-required":"render","change .acf-field-object input":"save","change .acf-field-object textarea":"save","change .acf-field-object select":"save"},event:function(e){return e.$field=e.$el.closest(".acf-field-object"),e},edit:function(e){acf.field_group.edit_field(e.$field)},duplicate:function(e){acf.field_group.duplicate_field(e.$field)},move:function(e){acf.field_group.move_field(e.$field)},delete:function(e){acf.field_group.delete_field(e.$field)},add:function(e){var i=e.$el.closest(".acf-field-list-wrap").children(".acf-field-list");acf.field_group.add_field(i)},change_type:function(e){acf.field_group.change_field_type(e.$el)},change_label:function(e){acf.field_group.change_field_label(e.$field)},change_name:function(e){acf.field_group.change_field_name(e.$field)},render:function(e){acf.field_group.render_field(e.$field)},save:function(e){acf.field_group.save_field(e.$field)}}),acf.field_group.conditional_logic=acf.model.extend({actions:{open_field:"render_field",change_field_label:"render_fields",change_field_type:"render_fields"},events:{"click .add-conditional-rule":"add_rule","click .add-conditional-group":"add_group","click .remove-conditional-rule":"remove_rule","change .conditional-toggle":"change_toggle","change .conditional-rule-param":"change_param"},render_fields:function(){var e=this;$(".acf-field-object.open").each(function(){e.render_field($(this))})},render_field:function(e){var i=this,t=e.attr("data-key"),a=e.parents(".acf-field-list"),d=e.find('.acf-field[data-name="conditional_logic"]:last'),n=[];$.each(a,function(e){var i=0==e?acf._e("sibling_fields"):acf._e("parent_fields");$(this).children(".acf-field-object").each(function(){var e=$(this),a=e.attr("data-key"),d=e.attr("data-type"),l=e.find(".field-label:first").val();$.inArray(d,["select","checkbox","true_false","radio"])!==-1&&a!=t&&n.push({value:a,label:l,group:i})})}),n.length||n.push({value:"",label:acf._e("no_fields")}),d.find(".rule").each(function(){i.render_rule($(this),n)})},render_rule:function(e,i){var t=e.find(".conditional-rule-param"),a=e.find(".conditional-rule-value");i&&acf.render_select(t,i);var d=$('.acf-field-object[data-key="'+t.val()+'"]'),n=d.attr("data-type"),l=[];if("true_false"==n)l.push({value:1,label:acf._e("checked")});else if("select"==n||"checkbox"==n||"radio"==n){var f=d.find('.acf-field[data-name="choices"] textarea').val().split("\n");$.each(f,function(e,i){i=i.split(":"),i[1]=i[1]||i[0],l.push({value:$.trim(i[0]),label:$.trim(i[1])})});var c=d.find('.acf-field[data-name="allow_null"]');c.exists()&&"1"==c.find("input:checked").val()&&l.unshift({value:"",label:acf._e("null")})}acf.render_select(a,l)},change_toggle:function(e){var i=e.$el,t=e.$el.prop("checked"),a=i.closest(".acf-input");t?(a.find(".rule-groups").show(),a.find(".rule-groups").find("[name]").prop("disabled",!1)):(a.find(".rule-groups").hide(),a.find(".rule-groups").find("[name]").prop("disabled",!0))},change_param:function(e){var i=e.$el.closest(".rule");this.render_rule(i)},add_rule:function(e){var i=e.$el.closest("tr");$tr2=acf.duplicate(i),$tr2.find("select:first").trigger("change")},remove_rule:function(e){var i=e.$el.closest("tr");i.find("select:first").trigger("change"),0==i.siblings("tr").length&&i.closest(".rule-group").remove(),i.remove()},add_group:function(e){var i=e.$el.closest(".rule-groups"),t=i.find(".rule-group:last");$group2=acf.duplicate(t),$group2.find("h4").text(acf._e("or")),$group2.find("tr:not(:first)").remove(),$group2.find("select:first").trigger("change")}}),acf.field_group.locations=acf.model.extend({events:{"click .add-location-rule":"add_rule","click .add-location-group":"add_group","click .remove-location-rule":"remove_rule","change .location-rule-param":"change_rule"},add_rule:function(e){var i=e.$el.closest("tr");$tr2=acf.duplicate(i)},remove_rule:function(e){var i=e.$el.closest("tr");i.find("select:first").trigger("change"),0==i.siblings("tr").length&&i.closest(".rule-group").remove(),i.remove()},add_group:function(e){var i=e.$el.closest(".rule-groups"),t=i.find(".rule-group:last");$group2=acf.duplicate(t),$group2.find("h4").text(acf._e("or")),$group2.find("tr:not(:first)").remove()},change_rule:function(e){var i=e.$el,t=i.closest("tr"),a=t.attr("data-id"),d=t.closest(".rule-group"),n=d.attr("data-id"),l=$('
    ');t.find("td.value").html(l),$.ajax({url:acf.get("ajaxurl"),data:acf.prepare_for_ajax({action:"acf/field_group/render_location_value",rule_id:a,group_id:n,param:i.val(),value:""}),type:"post",dataType:"html",success:function(e){l.replaceWith(e)}})}}),acf.field_group.field_object=acf.model.extend({type:"",o:{},$field:null,$settings:null,_add_action:function(e,i){var t=this,a=e.split("_");a.splice(1,0,"field"),e=a.join("_")+"/type="+t.type,acf.add_action(e,function(e){t.set("$field",e),t[i].apply(t,arguments)})},_add_filter:function(e,i){var t=this,a=e.split("_");a.splice(1,0,"field"),e=a.join("_")+"/type="+t.type,acf.add_filter(e,function(e){t.set("$field",e),t[i].apply(t,arguments)})},_add_event:function(e,i){var t=this,a=e.substr(0,e.indexOf(" ")),d=e.substr(e.indexOf(" ")+1),n=acf.field_group.get_selector(t.type);$(document).on(a,n+" "+d,function(e){e.$el=$(this),e.$field=e.$el.closest(".acf-field-object"),t.set("$field",e.$field),t[i].apply(t,[e])})},_set_$field:function(){this.o=this.$field.data(),this.$settings=this.$field.find("> .settings > table > tbody"),this.focus()},focus:function(){},setting:function(e){return this.$settings.find("> .acf-field-setting-"+e)}}),acf.field_group.field_objects=acf.model.extend({actions:{save_field:"_save_field",open_field:"_open_field",close_field:"_close_field",wipe_field:"_wipe_field",add_field:"_add_field",duplicate_field:"_duplicate_field",delete_field:"_delete_field",change_field_type:"_change_field_type",change_field_label:"_change_field_label",change_field_name:"_change_field_name",render_field_settings:"_render_field_settings"},_save_field:function(e){acf.do_action("save_field/type="+e.data("type"),e)},_open_field:function(e){acf.do_action("open_field/type="+e.data("type"),e),acf.do_action("render_field_settings",e)},_close_field:function(e){acf.do_action("close_field/type="+e.data("type"),e)},_wipe_field:function(e){acf.do_action("wipe_field/type="+e.data("type"),e)},_add_field:function(e){acf.do_action("add_field/type="+e.data("type"),e)},_duplicate_field:function(e){acf.do_action("duplicate_field/type="+e.data("type"),e)},_delete_field:function(e){acf.do_action("delete_field/type="+e.data("type"),e)},_change_field_type:function(e){acf.do_action("change_field_type/type="+e.data("type"),e),acf.do_action("render_field_settings",e)},_change_field_label:function(e){acf.do_action("change_field_label/type="+e.data("type"),e)},_change_field_name:function(e){acf.do_action("change_field_name/type="+e.data("type"),e)},_render_field_settings:function(e){acf.do_action("render_field_settings/type="+e.data("type"),e)}}),acf.field_group.append=acf.model.extend({actions:{render_field_settings:"_render_field_settings"},render:function(e){var i=e.data("append");if($sibling=e.siblings('[data-name="'+i+'"]'),$sibling.exists()){var t=$sibling.children(".acf-input"),a=t.children(".acf-hl");a.exists()||(t.wrapInner('
    '),a=t.children(".acf-hl"));var d=$("
  • ").append(e.children(".acf-input").children());a.append(d),a.attr("data-cols",a.children().length),e.remove()}},_render_field_settings:function(e){var i=this;e.find(".acf-field[data-append]").each(function(){i.render($(this))})}});var e=acf.field_group.field_object.extend({type:"select",actions:{render_settings:"render"},events:{"change .acf-field-setting-ui input":"render"},render:function(e){this.setting('ui input[type="checkbox"]').prop("checked")?this.setting("ajax").show():(this.setting("ajax").hide(),this.setting('ajax input[type="checkbox"]').prop("checked",!1).trigger("change"))}}),i=acf.field_group.field_object.extend({type:"radio",actions:{render_settings:"render"},events:{"change .acf-field-setting-other_choice input":"render"},render:function(e){this.setting('other_choice input[type="checkbox"]').prop("checked")?this.setting("save_other_choice").show():(this.setting("save_other_choice").hide(),this.setting('save_other_choice input[type="checkbox"]').prop("checked",!1).trigger("change"))}}),t=acf.field_group.field_object.extend({type:"true_false",actions:{render_settings:"render"},events:{"change .acf-field-setting-ui input":"render"},render:function(e){this.setting('ui input[type="checkbox"]').prop("checked")?(this.setting("ui_on_text").show(),this.setting("ui_off_text").show()):(this.setting("ui_on_text").hide(),this.setting("ui_off_text").hide())}}),a=acf.field_group.field_object.extend({type:"date_picker",actions:{render_settings:"render"},events:{"change .acf-field-setting-display_format input":"render","change .acf-field-setting-return_format input":"render"},render:function(e){this.render_list(this.setting("display_format")),this.render_list(this.setting("return_format"))},render_list:function(e){var i=e.find("ul"),t=i.find('input[type="radio"]:checked'),a=i.find('input[type="text"]');"other"!=t.val()&&a.val(t.val())}}),d=a.extend({type:"date_time_picker"}),d=a.extend({type:"time_picker"}),n=acf.field_group.field_object.extend({type:"tab",actions:{render_settings:"render"},render:function(e){this.setting("name input").val("").trigger("change"),this.setting('required input[type="checkbox"]').prop("checked",!1).trigger("change")}}),l=n.extend({type:"message"});acf.field_group.screen=acf.model.extend({actions:{ready:"ready"},events:{"click #acf-field-key-hide":"toggle"},ready:function(){var e=$("#adv-settings"),i=e.find("#acf-append-show-on-screen");e.find(".metabox-prefs").append(i.html()),e.find(".metabox-prefs br").remove(),i.remove(),this.render()},toggle:function(e){var i=e.$el.prop("checked")?1:0;acf.update_user_setting("show_field_keys",i),this.render()},render:function(){var e=acf.serialize_form($("#adv-settings"));e.show_field_keys=parseInt(e.show_field_keys);var i=acf.field_group.$fields;e.show_field_keys?i.addClass("show-field-keys"):i.removeClass("show-field-keys")}}),acf.field_group.sub_fields=acf.model.extend({actions:{open_field:"update_field_parent",sortstop:"update_field_parent",duplicate_field:"duplicate_field",delete_field:"delete_field",change_field_type:"change_field_type"},fix_conditional_logic:function(e){var i={};e.each(function(){i[$(this).attr("data-orig")]=$(this).attr("data-key")}),e.find(".conditional-rule-param").each(function(){var e=$(this).val();e in i&&($(this).find('option[value="'+i[e]+'"]').exists()||$(this).append('"),$(this).val(i[e]))})},update_field_parent:function(e){if(e.hasClass("acf-field-object")){var i=e.parent().closest(".acf-field-object"),t=acf.get("post_id");i.exists()&&(t=acf.field_group.get_field_meta(i,"ID"),t||(t=acf.field_group.get_field_meta(i,"key"))),acf.field_group.update_field_meta(e,"parent",t),acf.do_action("update_field_parent",e,i)}},duplicate_field:function(e){var i=e.find(".acf-field-object");i.exists()&&(i.each(function(){var e=$(this).parent().closest(".acf-field-object"),i=acf.field_group.get_field_meta(e,"key");acf.field_group.wipe_field($(this)),acf.field_group.update_field_meta($(this),"parent",i),acf.field_group.save_field($(this))}),this.fix_conditional_logic(i))},delete_field:function(e){e.find(".acf-field-object").each(function(){acf.field_group.delete_field($(this),!1)})},change_field_type:function(e){e.find(".acf-field-object").each(function(){acf.field_group.delete_field($(this),!1)})}})}(jQuery); diff --git a/assets/js/acf-input.js b/assets/js/acf-input.js index 16475dd..8adfcc9 100644 --- a/assets/js/acf-input.js +++ b/assets/js/acf-input.js @@ -682,6 +682,11 @@ var acf; // filter out fields if( !all ) { + // remove clone fields + $fields = $fields.not('.acf-clone .acf-field'); + + + // filter $fields = acf.apply_filters('get_fields', $fields); } @@ -1259,8 +1264,7 @@ var acf; $el.css({ height : $el.height(), width : $el.width(), - position : 'absolute', - //padding : 0 + position : 'absolute' }); @@ -1505,7 +1509,7 @@ var acf; $popup.find('.acf-popup-box').css({ 'width' : args.width, - 'margin-left' : 0 - (args.width / 2), + 'margin-left' : 0 - (args.width / 2) }); } @@ -1517,7 +1521,7 @@ var acf; $popup.find('.acf-popup-box').css({ 'height' : args.height, - 'margin-top' : 0 - (args.height / 2), + 'margin-top' : 0 - (args.height / 2) }); } @@ -1915,6 +1919,27 @@ var acf; }, + /* + * addslashes + * + * This function mimics the PHP addslashes function. + * Returns a string with backslashes before characters that need to be escaped. + * + * @type function + * @date 9/1/17 + * @since 5.5.0 + * + * @param text (string) + * @return (string) + */ + + addslashes: function(text){ + + return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); + + }, + + /* * render_select * @@ -2515,7 +2540,7 @@ var acf; 'show' : '_show', 'show_field' : '_show_field', 'hide' : '_hide', - 'hide_field' : '_hide_field', + 'hide_field' : '_hide_field' }, // prepare @@ -2735,116 +2760,286 @@ var acf; active: 0, actions: { - 'refresh': 'refresh', + 'prepare 99': 'prepare', + 'refresh': 'refresh' }, - refresh: function( $el ){ + prepare: function(){ + + // vars + this.active = 1; + + + // render + this.refresh(); + + }, + + refresh: function( $el ){ + + // bail early if not yet active + if( !this.active ) return; - //console.log('acf.layout.refresh', $el); // defaults - $el = $el || false; + $el = $el || $('body'); - // if is '.acf-fields' - if( $el && $el.is('.acf-fields') ) { + // reference + var self = this; + + + // render + this.render_tables( $el ); + this.render_groups( $el ); + + }, + + render_tables: function( $el ){ + + // reference + var self = this; + + + // vars + var $tables = $el.find('.acf-table:visible'); + + + // appent self if is tr + if( $el.is('tr') ) { - $el = $el.parent(); + $tables = $el.parent().parent(); } - // loop over visible fields - $('.acf-fields:visible', $el).each(function(){ - - // vars - var $els = $(), - top = 0, - height = 0, - cell = -1; - - - // get fields - var $fields = $(this).children('.acf-field[data-width]:visible'); - - - // bail early if no fields - if( !$fields.exists() ) { - - return; - - } - - - // reset fields - $fields.removeClass('acf-r0 acf-c0').css({'min-height': 0}); - - - $fields.each(function( i ){ - - // vars - var $el = $(this), - this_top = $el.position().top; - - - // set top - if( i == 0 ) { - - top = this_top; - - } - - - // detect new row - if( this_top != top ) { - - // set previous heights - $els.css({'min-height': (height+1)+'px'}); - - // reset - $els = $(); - top = $el.position().top; // don't use variable as this value may have changed due to min-height css - height = 0; - cell = -1; - - } - - - // increase - cell++; - - // set height - height = ($el.outerHeight() > height) ? $el.outerHeight() : height; - - // append - $els = $els.add( $el ); - - // add classes - if( this_top == 0 ) { - - $el.addClass('acf-r0'); - - } else if( cell == 0 ) { - - $el.addClass('acf-c0'); - - } - - }); - - - // clean up - if( $els.exists() ) { - - $els.css({'min-height': (height+1)+'px'}); - - } + // loop + $tables.each(function(){ + self.render_table( $(this) ); }); - //console.timeEnd('acf.width.render'); - + }, + + render_table: function( $table ){ + + // vars + var $ths = $table.find('> thead th.acf-th'), + colspan = 1, + available_width = 100; + + + // bail early if no $ths + if( !$ths.exists() ) return; + + + // vars + var $trs = $table.find('> tbody > tr'), + $tds = $trs.find('> td.acf-field'); + + + // remove clones if has visible rows + if( $trs.hasClass('acf-clone') && $trs.length > 1 ) { + + $tds = $trs.not('.acf-clone').find('> td.acf-field'); + + } + + + // render th/td visibility + $ths.each(function(){ + + // vars + var $th = $(this), + key = $th.attr('data-key'), + $td = $tds.filter('[data-key="'+key+'"]'); + + // clear class + $td.removeClass('appear-empty'); + $th.removeClass('hidden-by-conditional-logic'); + + + // no td + if( !$td.exists() ) { + + // do nothing + + // if all td are hidden + } else if( $td.not('.hidden-by-conditional-logic').length == 0 ) { + + $th.addClass('hidden-by-conditional-logic'); + + // if 1 or more td are visible + } else { + + $td.filter('.hidden-by-conditional-logic').addClass('appear-empty'); + + } + + }); + + + + // clear widths + $ths.css('width', 'auto'); + + + // update $ths + $ths = $ths.not('.hidden-by-conditional-logic'); + + + // set colspan + colspan = $ths.length; + + + // set custom widths first + $ths.filter('[data-width]').each(function(){ + + // vars + var width = parseInt( $(this).attr('data-width') ); + + + // remove from available + available_width -= width; + + + // set width + $(this).css('width', width + '%'); + + }); + + + // update $ths + $ths = $ths.not('[data-width]'); + + + // set custom widths first + $ths.each(function(){ + + // cal width + var width = available_width / $ths.length; + + + // set width + $(this).css('width', width + '%'); + + }); + + + // update colspan + $table.find('.acf-row .acf-field.-collapsed-target').removeAttr('colspan'); + $table.find('.acf-row.-collapsed .acf-field.-collapsed-target').attr('colspan', colspan); + + }, + + render_groups: function( $el ){ + + // reference + var self = this; + + + // vars + var $groups = $el.find('.acf-fields:visible'); + + + // appent self if is '.acf-fields' + if( $el && $el.is('.acf-fields') ) { + + $groups = $groups.add( $el ); + + } + + + // loop + $groups.each(function(){ + + self.render_group( $(this) ); + + }); + + }, + + render_group: function( $el ){ + + // vars + var $els = $(), + top = 0, + height = 0, + cell = -1; + + + // get fields + var $fields = $el.children('.acf-field[data-width]:visible'); + + + // bail early if no fields + if( !$fields.exists() ) return; + + + // reset fields + $fields.removeClass('acf-r0 acf-c0').css({'min-height': 0}); + + + // loop + $fields.each(function( i ){ + + // vars + var $el = $(this), + this_top = $el.position().top; + + + // set top + if( i == 0 ) top = this_top; + + + // detect new row + if( this_top != top ) { + + // set previous heights + $els.css({'min-height': (height+1)+'px'}); + + // reset + $els = $(); + top = $el.position().top; // don't use variable as this value may have changed due to min-height css + height = 0; + cell = -1; + + } + + + // increase + cell++; + + + // set height + height = ($el.outerHeight() > height) ? $el.outerHeight() : height; + + + // append + $els = $els.add( $el ); + + + // add classes + if( this_top == 0 ) { + + $el.addClass('acf-r0'); + + } else if( cell == 0 ) { + + $el.addClass('acf-c0'); + + } + + }); + + + // clean up + if( $els.exists() ) { + + $els.css({'min-height': (height+1)+'px'}); + + } } @@ -2928,7 +3123,7 @@ var acf; }, events: { - 'submit form': 'off', + 'submit form': 'off' }, validation_complete: function( json, $form ){ @@ -2990,7 +3185,7 @@ var acf; events: { 'mouseenter .acf-js-tooltip': 'on', - 'mouseleave .acf-js-tooltip': 'off', + 'mouseleave .acf-js-tooltip': 'off' }, on: function( e ){ @@ -3102,7 +3297,7 @@ var acf; events: { 'mouseenter .acf-postbox .handlediv': 'on', - 'mouseleave .acf-postbox .handlediv': 'off', + 'mouseleave .acf-postbox .handlediv': 'off' }, on: function( e ){ @@ -3304,6 +3499,28 @@ var acf; }, 999); */ + + + /* + * indexOf + * + * This function will provide compatibility for ie8 + * + * @type function + * @date 5/3/17 + * @since 5.5.10 + * + * @param n/a + * @return n/a + */ + + if( !Array.prototype.indexOf ) { + + Array.prototype.indexOf = function(val) { + return $.inArray(val, this); + }; + + } })(jQuery); @@ -3330,7 +3547,7 @@ var acf; //'page_parent': 0, //'page_type': 0, //'post_format': 0, - //'post_taxonomy': 0, + //'post_taxonomy': 0 }, xhr: null, @@ -4103,13 +4320,13 @@ var acf; // calculate visibility - for( var i in groups ) { + for( var i = 0; i < groups.length; i++ ) { // vars var group = groups[i], match_group = true; - for( var k in group ) { + for( var k = 0; k < group.length; k++ ) { // vars var rule = group[k]; @@ -4420,7 +4637,7 @@ var acf; acf.datepicker = acf.model.extend({ actions: { - 'ready 1': 'ready', + 'ready 1': 'ready' }, ready: function(){ @@ -4524,7 +4741,7 @@ var acf; }, events: { - 'blur input[type="text"]': 'blur', + 'blur input[type="text"]': 'blur' }, focus: function(){ @@ -4570,6 +4787,10 @@ var acf; // add date picker acf.datepicker.init( this.$input, args ); + + // action for 3rd party customization + acf.do_action('date_picker_init', this.$input, args, this.$field); + }, initialize2: function(){ @@ -4610,6 +4831,10 @@ var acf; // now change the format back to how it should be. this.$input.datepicker( 'option', 'dateFormat', dateFormat ); + + // action for 3rd party customization + acf.do_action('date_picker_init', this.$input, args, this.$field); + }, blur: function(){ @@ -4644,7 +4869,7 @@ var acf; acf.datetimepicker = acf.model.extend({ actions: { - 'ready 1': 'ready', + 'ready 1': 'ready' }, ready: function(){ @@ -4729,7 +4954,7 @@ var acf; // do nothing - }, + } }); @@ -4749,7 +4974,7 @@ var acf; }, events: { - 'blur input[type="text"]': 'blur', + 'blur input[type="text"]': 'blur' }, focus: function(){ @@ -4792,6 +5017,10 @@ var acf; // add date time picker acf.datetimepicker.init( this.$input, args ); + + // action for 3rd party customization + acf.do_action('date_time_picker_init', this.$input, args, this.$field); + }, blur: function(){ @@ -4911,7 +5140,7 @@ var acf; alt: '', title: '', filename: '', - filesize: '', + filesizeHumanReadable: '', icon: '/wp-includes/images/media/default.png' }; @@ -4921,7 +5150,7 @@ var acf; // update data data = attachment.attributes; - + } @@ -4962,7 +5191,7 @@ var acf; }); this.$el.find('[data-name="title"]').text( data.title ); this.$el.find('[data-name="filename"]').text( data.filename ).attr( 'href', data.url ); - this.$el.find('[data-name="filesize"]').text( data.filesize ); + this.$el.find('[data-name="filesize"]').text( data.filesizeHumanReadable ); // vars @@ -5171,10 +5400,83 @@ var acf; }, + /* + * get_file_info + * + * This function will find basic file info and store it in a hidden input + * + * @type function + * @date 18/1/17 + * @since 5.5.0 + * + * @param $file_input (jQuery) + * @param $hidden_input (jQuery) + * @return n/a + */ + + get_file_info: function( $file_input, $hidden_input ){ + + // vars + var attachment = {}; + + + // url + attachment.url = $file_input.val(); + + + // modern browsers + var files = $file_input[0].files; + + if( files ){ + + // vars + var file = files[0]; + + + // update + attachment.size = file.size; + attachment.type = file.type; + + + // image + if( file.type.indexOf('image') > -1 ) { + + // vars + var _url = window.URL || window.webkitURL; + + + // temp image + var img = new Image(); + + img.onload = function () { + + // update + attachment.width = this.width; + attachment.height = this.height; + + + // set hidden input value + $hidden_input.val( jQuery.param(attachment) ); + + }; + + img.src = _url.createObjectURL(file); + + } + + } + + + // set hidden input value + $hidden_input.val( jQuery.param(attachment) ); + + }, + + /* * change * - * This function will update the hidden input when selecting a basic file to clear validation errors + * This function will update the hidden input when selecting a basic file to add basic validation * * @type function * @date 12/04/2016 @@ -5186,7 +5488,7 @@ var acf; change: function( e ){ - this.$input.val( e.$el.val() ); + this.get_file_info( e.$el, this.$input ); } @@ -5212,6 +5514,7 @@ var acf; $pending: $(), actions: { + // have considered changing to 'load', however, could cause issues with devs expecting the API to exist earlier 'ready': 'initialize', 'append': 'initialize', 'show': 'show' @@ -5226,7 +5529,7 @@ var acf; 'focus .search': '_focus', 'blur .search': '_blur', //'paste .search': '_paste', - 'mousedown .acf-google-map': '_mousedown', + 'mousedown .acf-google-map': '_mousedown' }, focus: function(){ @@ -6324,7 +6627,7 @@ var acf; /* * change * - * This function will update the hidden input when selecting a basic file to clear validation errors + * This function will update the hidden input when selecting a basic file to add basic validation * * @type function * @date 12/04/2016 @@ -6336,7 +6639,7 @@ var acf; change: function( e ){ - this.$input.val( e.$el.val() ); + acf.fields.file.get_file_info( e.$el, this.$input ); } @@ -6904,7 +7207,7 @@ var acf; title: settings.title, multiple: settings.multiple, library: {}, - states: [], + states: [] }; @@ -6944,7 +7247,7 @@ var acf; // If the user isn't allowed to edit fields, // can they still edit it locally? - allowLocalEdits: true, + allowLocalEdits: true }) ]; @@ -7469,7 +7772,7 @@ var acf; 'click [data-name="value-title"]': '_edit', 'keypress [data-name="search-input"]': '_keypress', 'keyup [data-name="search-input"]': '_keyup', - 'blur [data-name="search-input"]': '_blur', + 'blur [data-name="search-input"]': '_blur' }, @@ -7525,7 +7828,7 @@ var acf; // bail early if no value if( !new_url ) { - this.clear( $el ); + this.clear(); return; } @@ -7577,8 +7880,7 @@ var acf; var ajax_data = acf.prepare_for_ajax({ 'action' : 'acf/fields/oembed/search', 's' : s, - 'width' : this.$el.data('width'), - 'height' : this.$el.data('height') + 'field_key' : this.$field.data('key') }); @@ -7591,7 +7893,7 @@ var acf; url: acf.get('ajaxurl'), data: ajax_data, type: 'post', - dataType: 'html', + dataType: 'json', context: this, success: this.search_success }); @@ -7602,7 +7904,7 @@ var acf; }, - search_success: function( html ){ + search_success: function( json ){ // vars var s = this.$search.val(); @@ -7613,7 +7915,7 @@ var acf; // error - if( !html ) { + if( !json || !json.html ) { this.$el.removeClass('has-value').addClass('has-error'); return; @@ -7628,7 +7930,7 @@ var acf; // update vars this.$input.val( s ); this.$title.html( s ); - this.$embed.html( html ); + this.$embed.html( json.html ); }, @@ -7696,7 +7998,7 @@ var acf; }, - _keyup: function( e ){ console.log('_keypress', e.which); + _keyup: function( e ){ //console.log('_keypress', e.which); // bail early if no value if( !this.$search.val() ) return; @@ -7711,7 +8013,7 @@ var acf; this.blur(); - }, + } }); @@ -7731,7 +8033,7 @@ var acf; }, events: { - 'click input[type="radio"]': 'click', + 'click input[type="radio"]': 'click' }, focus: function(){ @@ -8115,8 +8417,15 @@ var acf; // Looks like Select2 v4 has moved away from highlighting results, so perhaps we should too if( this.o.s ) { + // vars var s = this.o.s; + + // allow special characters to be used within regex + s = acf.addslashes(s); + + + // loop $new.find('.acf-rel-item').each(function(){ // vars @@ -8346,7 +8655,7 @@ var acf; // actions actions: { - 'ready 1': 'ready', + 'ready 1': 'ready' }, @@ -8482,31 +8791,36 @@ var acf; * @return (mixed) */ - init: function( $select, args ){ + init: function( $select, args, $field ){ // bail early if no version found if( !this.version ) return; // defaults + args = args || {}; + $field = $field || null; + + + // merge args = $.extend({ allow_null: false, placeholder: '', multiple: false, ajax: false, - ajax_action: '', + ajax_action: '' }, args); // v3 if( this.version == 3 ) { - return this.init_v3( $select, args ); + return this.init_v3( $select, args, $field ); // v4 } else if( this.version == 4 ) { - return this.init_v4( $select, args ); + return this.init_v4( $select, args, $field ); } @@ -8676,19 +8990,19 @@ var acf; * @return $post_id (int) */ - get_ajax_data: function( args, params ){ + get_ajax_data: function( args, params, $el, $field ){ // vars var data = acf.prepare_for_ajax({ action: args.ajax_action, field_key: args.key, - s: params.term, - paged: params.page + s: params.term || '', + paged: params.page || 1 }); // filter - data = acf.apply_filters( 'select2_ajax_data', data, args, params ); + data = acf.apply_filters( 'select2_ajax_data', data, args, $el, $field ); // return @@ -8817,7 +9131,7 @@ var acf; * @return args (object) */ - init_v3: function( $select, args ){ + init_v3: function( $select, args, $field ){ // vars var $input = $select.siblings('input'); @@ -8936,7 +9250,7 @@ var acf; // return - return acf.select2.get_ajax_data(args, params); + return acf.select2.get_ajax_data(args, params, $input, $field); }, results: function( data, page ){ @@ -8973,7 +9287,7 @@ var acf; // filter for 3rd party customization - select2_args = acf.apply_filters( 'select2_args', select2_args, $select, args ); + select2_args = acf.apply_filters( 'select2_args', select2_args, $select, args, $field ); // add select2 @@ -9031,6 +9345,10 @@ var acf; }); + + // action for 3rd party customization + acf.do_action('select2_init', $input, select2_args, args, $field); + }, @@ -9083,7 +9401,7 @@ var acf; }, - init_v4: function( $select, args ){ + init_v4: function( $select, args, $field ){ // vars var $input = $select.siblings('input'); @@ -9101,7 +9419,7 @@ var acf; multiple: args.multiple, separator: '||', data: [], - escapeMarkup: function( m ){ return m; }, + escapeMarkup: function( m ){ return m; } /* sorter: function (data) { console.log('sorter %o', data); return data; @@ -9177,7 +9495,7 @@ var acf; data: function( params ) { // return - return acf.select2.get_ajax_data(args, params); + return acf.select2.get_ajax_data(args, params, $select, $field); }, processResults: function( data, params ){ @@ -9245,17 +9563,24 @@ var acf; // filter for 3rd party customization - select2_args = acf.apply_filters( 'select2_args', select2_args, $select, args ); + select2_args = acf.apply_filters( 'select2_args', select2_args, $select, args, $field ); // add select2 - //console.log( '%o %o ', $select, select2_args ); var $container = $select.select2( select2_args ); + // clear value (allows null to be saved) + $input.val(''); + + // add class $container.addClass('-acf'); + + // action for 3rd party customization + acf.do_action('select2_init', $select, select2_args, args, $field); + }, @@ -9410,7 +9735,7 @@ var acf; } - acf.select2.init( this.$select, this.o ); + acf.select2.init( this.$select, this.o, this.$field ); }, @@ -9435,7 +9760,7 @@ var acf; // user acf.fields.user = acf.fields.select.extend({ - type: 'user', + type: 'user' }); @@ -9443,7 +9768,7 @@ var acf; // post_object acf.fields.post_object = acf.fields.select.extend({ - type: 'post_object', + type: 'post_object' }); @@ -9451,7 +9776,7 @@ var acf; // page_link acf.fields.page_link = acf.fields.select.extend({ - type: 'page_link', + type: 'page_link' }); @@ -9919,7 +10244,7 @@ var acf; }, events: { - 'blur input[type="text"]': 'blur', + 'blur input[type="text"]': 'blur' }, focus: function(){ @@ -9986,7 +10311,7 @@ var acf; // add date picker - this.$input.addClass('active').timepicker( args ); + this.$input.timepicker( args ); // wrap the datepicker (only if it hasn't already been wrapped) @@ -9996,6 +10321,10 @@ var acf; } + + // action for 3rd party customization + acf.do_action('time_picker_init', this.$input, args, this.$field); + }, blur: function(){ @@ -10027,7 +10356,10 @@ var acf; }, events: { - 'change .acf-switch-input': 'change' + 'change .acf-switch-input': '_change', + 'focus .acf-switch-input': '_focus', + 'blur .acf-switch-input': '_blur', + 'keypress .acf-switch-input': '_keypress' }, @@ -10089,6 +10421,48 @@ var acf; }, + /* + * on + * + * description + * + * @type function + * @date 10/1/17 + * @since 5.5.0 + * + * @param $post_id (int) + * @return $post_id (int) + */ + + on: function() { //console.log('on'); + + this.$input.prop('checked', true); + this.$switch.addClass('-on'); + + }, + + + /* + * off + * + * description + * + * @type function + * @date 10/1/17 + * @since 5.5.0 + * + * @param $post_id (int) + * @return $post_id (int) + */ + + off: function() { //console.log('off'); + + this.$input.prop('checked', false); + this.$switch.removeClass('-on'); + + }, + + /* * change * @@ -10102,7 +10476,7 @@ var acf; * @return $post_id (int) */ - change: function( e ){ + _change: function( e ){ // vars var checked = e.$el.prop('checked'); @@ -10111,15 +10485,88 @@ var acf; // enable if( checked ) { - this.$switch.addClass('-on'); + this.on(); // disable } else { - this.$switch.removeClass('-on'); + this.off(); } + }, + + + /* + * _focus + * + * description + * + * @type function + * @date 10/1/17 + * @since 5.5.0 + * + * @param $post_id (int) + * @return $post_id (int) + */ + + _focus: function( e ){ + + this.$switch.addClass('-focus'); + + }, + + + /* + * _blur + * + * description + * + * @type function + * @date 10/1/17 + * @since 5.5.0 + * + * @param $post_id (int) + * @return $post_id (int) + */ + + _blur: function( e ){ + + this.$switch.removeClass('-focus'); + + }, + + + /* + * _keypress + * + * description + * + * @type function + * @date 10/1/17 + * @since 5.5.0 + * + * @param $post_id (int) + * @return $post_id (int) + */ + + _keypress: function( e ){ + + // left + if( e.keyCode === 37 ) { + + return this.off(); + + } + + + // right + if( e.keyCode === 39 ) { + + return this.on(); + + } + } }); @@ -10140,7 +10587,7 @@ var acf; 'remove': 'remove' }, events: { - 'click a[data-name="add"]': 'add_term', + 'click a[data-name="add"]': 'add_term' }, focus: function(){ @@ -11627,8 +12074,17 @@ var acf; // initialize try { + // init tinymce.init( mceInit ); + + // vars + var ed = tinyMCE.get( mceInit.id ); + + + // action for 3rd party customization + acf.do_action('wysiwyg_tinymce_init', ed, ed.id, mceInit, this.$field); + } catch(e){} }, @@ -11649,11 +12105,18 @@ var acf; // initialize try { - + + // init var qtag = quicktags( qtInit ); + + // buttons this._buttonsInit( qtag ); + + // action for 3rd party customization + acf.do_action('wysiwyg_quicktags_init', qtag, qtag.id, qtInit, this.$field); + } catch(e){} }, @@ -11776,7 +12239,7 @@ ed.on('ResizeEditor', function(e) { // hook for 3rd party customization - mceInit = acf.apply_filters('wysiwyg_tinymce_settings', mceInit, mceInit.id); + mceInit = acf.apply_filters('wysiwyg_tinymce_settings', mceInit, mceInit.id, this.$field); // return @@ -11795,7 +12258,7 @@ ed.on('ResizeEditor', function(e) { // hook for 3rd party customization - qtInit = acf.apply_filters('wysiwyg_quicktags_settings', qtInit, qtInit.id); + qtInit = acf.apply_filters('wysiwyg_quicktags_settings', qtInit, qtInit.id, this.$field); // return @@ -11839,12 +12302,16 @@ ed.on('ResizeEditor', function(e) { enable: function(){ - // bail early if html mode - if( this.$el.hasClass('tmce-active') && acf.isset(window,'switchEditors') ) { + try { - switchEditors.go( this.o.id, 'tmce'); - - } + // bail early if html mode + if( this.$el.hasClass('tmce-active') ) { + + switchEditors.go( this.o.id, 'tmce'); + + } + + } catch(e) {} }, @@ -11926,7 +12393,7 @@ ed.on('ResizeEditor', function(e) { ed.toolbar.innerHTML = html; ed.theButtons = theButtons; - }, + } }); diff --git a/assets/js/acf-input.min.js b/assets/js/acf-input.min.js index d837f02..cd3c099 100644 --- a/assets/js/acf-input.min.js +++ b/assets/js/acf-input.min.js @@ -1,3 +1,3 @@ -!function(e,t){"use strict";var i=function(){function e(){return u}function t(e,t,i,a){return"string"==typeof e&&"function"==typeof t&&(i=parseInt(i||10,10),l("actions",e,t,i,a)),f}function i(){var e=Array.prototype.slice.call(arguments),t=e.shift();return"string"==typeof t&&d("actions",t,e),f}function a(e,t){return"string"==typeof e&&o("actions",e,t),f}function n(e,t,i,a){return"string"==typeof e&&"function"==typeof t&&(i=parseInt(i||10,10),l("filters",e,t,i,a)),f}function s(){var e=Array.prototype.slice.call(arguments),t=e.shift();return"string"==typeof t?d("filters",t,e):f}function r(e,t){return"string"==typeof e&&o("filters",e,t),f}function o(e,t,i,a){if(u[e][t])if(i){var n=u[e][t],s;if(a)for(s=n.length;s--;){var r=n[s];r.callback===i&&r.context===a&&n.splice(s,1)}else for(s=n.length;s--;)n[s].callback===i&&n.splice(s,1)}else u[e][t]=[]}function l(e,t,i,a,n){var s={callback:i,priority:a,context:n},r=u[e][t];r?(r.push(s),r=c(r)):r=[s],u[e][t]=r}function c(e){for(var t,i,a,n=1,s=e.length;nt.priority;)e[i]=e[i-1],--i;e[i]=t}return e}function d(e,t,i){var a=u[e][t];if(!a)return"filters"===e&&i[0];var n=0,s=a.length;if("filters"===e)for(;n0},$.fn.outerHTML=function(){return $(this).get(0).outerHTML},acf={l10n:{},o:{},update:function(e,t){this.o[e]=t},get:function(e){return"undefined"!=typeof this.o[e]?this.o[e]:null},_e:function(e,t){t=t||!1;var i=this.l10n[e]||"";return t&&(i=i[t]||""),i},add_action:function(){for(var e=arguments[0].split(" "),t=e.length,i=0;ie.length?Array(1+(t-e.length)).join("0")+e:e};return this.php_js||(this.php_js={}),this.php_js.uniqidSeed||(this.php_js.uniqidSeed=Math.floor(123456789*Math.random())),this.php_js.uniqidSeed++,i=e,i+=a(parseInt((new Date).getTime()/1e3,10),8),i+=a(this.php_js.uniqidSeed,5),t&&(i+=(10*Math.random()).toFixed(8).toString()),i},serialize_form:function(e){var t={},i={};return $selector=e.find("select, textarea, input"),$.each($selector.serializeArray(),function(e,a){"[]"===a.name.slice(-2)&&(a.name=a.name.replace("[]",""),"undefined"==typeof i[a.name]&&(i[a.name]=-1),i[a.name]++,a.name+="["+i[a.name]+"]"),t[a.name]=a.value}),t},serialize:function(e){return this.serialize_form(e)},disable:function(e,t){if(t=t||"",e.hasClass("acf-disabled"))return!1;if(e.prop("disabled",!0),t){var i=e.data("acf_disabled")||[],a=i.indexOf(t);a<0&&(i.push(t),e.data("acf_disabled",i))}return!0},enable:function(e,t){if(t=t||"",e.hasClass("acf-disabled"))return!1;var i=e.data("acf_disabled")||[];if(t){var a=i.indexOf(t);a>-1&&(i.splice(a,1),e.data("acf_disabled",i))}return!i.length&&(e.prop("disabled",!1),!0)},disable_el:function(e,t){t=t||"",e.find("select, textarea, input").each(function(){acf.disable($(this),t)})},disable_form:function(e,t){this.disable_el.apply(this,arguments)},enable_el:function(e,t){t=t||"",e.find("select, textarea, input").each(function(){acf.enable($(this),t)})},enable_form:function(e,t){this.enable_el.apply(this,arguments)},remove_tr:function(e,t){var i=e.height(),a=e.children().length;e.addClass("acf-remove-element"),setTimeout(function(){e.removeClass("acf-remove-element"),e.html(''),e.children("td").animate({height:0},250,function(){e.remove(),"function"==typeof t&&t()})},250)},remove_el:function(e,t,i){i=i||0,e.css({height:e.height(),width:e.width(),position:"absolute"}),e.wrap('
    '),e.animate({opacity:0},250),e.parent(".acf-temp-wrap").animate({height:i},250,function(){$(this).remove(),"function"==typeof t&&t()})},isset:function(){var e=arguments,t=e.length,a=null,n;if(0===t)throw new Error("Empty isset");for(a=e[0],i=1;i #acf-popup"),$popup.exists())return update_popup(e);var t=['
    ','
    ','

    ','
    ','
    ',"
    ",'
    ',"
    "].join("");return $("body").append(t),$("#acf-popup").on("click",".bg, .acf-close-popup",function(e){e.preventDefault(),acf.close_popup()}),this.update_popup(e)},update_popup:function(e){return $popup=$("#acf-popup"),!!$popup.exists()&&(e=$.extend({},{title:"",content:"",width:0,height:0,loading:!1},e),e.title&&$popup.find(".title h3").html(e.title),e.content&&($inner=$popup.find(".inner:first"),$inner.html(e.content),acf.do_action("append",$inner),$inner.attr("style","position: relative;"),e.height=$inner.outerHeight(),$inner.removeAttr("style")),e.width&&$popup.find(".acf-popup-box").css({width:e.width,"margin-left":0-e.width/2}),e.height&&(e.height+=44,$popup.find(".acf-popup-box").css({height:e.height,"margin-top":0-e.height/2})),e.loading?$popup.find(".loading").show():$popup.find(".loading").hide(),$popup)},close_popup:function(){$popup=$("#acf-popup"),$popup.exists()&&$popup.remove()},update_user_setting:function(e,t){$.ajax({url:acf.get("ajaxurl"),dataType:"html",type:"post",data:acf.prepare_for_ajax({action:"acf/update_user_setting",name:e,value:t})})},prepare_for_ajax:function(e){return e.nonce=acf.get("nonce"),e.post_id=acf.get("post_id"),e=acf.apply_filters("prepare_for_ajax",e)},is_ajax_success:function(e){return!(!e||!e.success)},get_ajax_message:function(e){var t={text:"",type:"error"};return e?(e.success&&(t.type="success"),e.data&&e.data.message&&(t.text=e.data.message),e.data&&e.data.error&&(t.text=e.data.error),t):t},is_in_view:function(e){var t=e.offset().top,i=t+e.height();if(t===i)return!1;var a=$(window).scrollTop(),n=a+$(window).height();return i<=n&&t>=a},val:function(e,t){var i=e.val();e.val(t),t!=i&&e.trigger("change")},str_replace:function(e,t,i){return i.split(e).join(t)},str_sanitize:function(e){var t="",a={"æ":"a","å":"a","á":"a","ä":"a","č":"c","ď":"d","è":"e","é":"e","ě":"e","ë":"e","í":"i","ĺ":"l","ľ":"l","ň":"n","ø":"o","ó":"o","ô":"o","ő":"o","ö":"o","ŕ":"r","š":"s","ť":"t","ú":"u","ů":"u","ű":"u","ü":"u","ý":"y","ř":"r","ž":"z"," ":"_","'":"","?":"","/":"","\\":"",".":"",",":"",">":"","<":"",'"':"","[":"","]":"","|":"","{":"","}":"","(":"",")":""};for(e=e.toLowerCase(),i=0;i'),e.append(n))),n.append('"),i==a.value&&e.prop("selectedIndex",t)})},duplicate:function(e){"undefined"!=typeof e.length&&(e={$el:e}),e=acf.parse_args(e,{$el:!1,search:"",replace:"",before:function(e){},after:function(e,t){},append:function(e,t){e.after(t)}});var t=e.$el,i;e.search||(e.search=t.attr("data-id")),e.replace||(e.replace=acf.get_uniqid()),e.before.apply(this,[t]),acf.do_action("before_duplicate",t);var i=t.clone();return i.removeClass("acf-clone"),acf.do_action("remove",i),e.search&&(i.attr("data-id",e.replace),i.find('[id*="'+e.search+'"]').each(function(){$(this).attr("id",$(this).attr("id").replace(e.search,e.replace))}),i.find('[name*="'+e.search+'"]').each(function(){$(this).attr("name",$(this).attr("name").replace(e.search,e.replace))}),i.find('label[for*="'+e.search+'"]').each(function(){$(this).attr("for",$(this).attr("for").replace(e.search,e.replace))})),i.find(".ui-sortable").removeClass("ui-sortable"),acf.do_action("after_duplicate",t,i),e.after.apply(this,[t,i]),e.append.apply(this,[t,i]),setTimeout(function(){acf.do_action("append",i)},1),i},decode:function(e){return $("