-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
311 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,51 @@ | ||
# Advanced Custom Fields: SVG # | ||
|
||
## Description ## | ||
This enhance [Advanced Custom Field](https://www.advancedcustomfields.com/pro/) plugin by adding a custom field. | ||
|
||
This enhance ACF with a field icons. Add a field type selector to include your great font icon and returns class icon. | ||
One activated you'll be able to use a custom ACF field type which is an icon selector | ||
This ACF field is a select2 field in order to include your great fonts. It will allow you to select icons and then return the corresponding class icon. | ||
|
||
## Important to know ## | ||
## Compatibility | ||
|
||
In case you want to include this small plugin to your project running composer you can add this line to your composer.json : | ||
This ACF field type is compatible with: | ||
* ACF 5.0.0 and up, that means the pro version. | ||
* ACF 4 (not supported). | ||
|
||
```json | ||
"repositories": [ | ||
{ | ||
"type": "vcs", | ||
"url": "https://github.com/BeAPI/acf-svg-icon" | ||
} | ||
] | ||
``` | ||
## Installation | ||
|
||
then run the command : | ||
### via Composer | ||
|
||
```shell | ||
composer require bea/acf-svg-icon | ||
``` | ||
1. Add a line to your repositories array: `{ "type": "git", "url": "https://github.com/strickdj/acf-field-address" }` | ||
2. Add a line to your require block: `"strickdj/acf-address": "dev-master"` | ||
3. Run: `composer update | ||
|
||
### Manual | ||
|
||
1. Copy the plugin folder into your plugins folder. | ||
2. Activate the plugin via the plugins admin page. | ||
3. Create a new field via ACF and select the SVG Icon selector. | ||
|
||
## Tips ## | ||
## How to ## | ||
|
||
### Using this with your own svg file in your own theme ### | ||
|
||
```php | ||
add_filter( 'acf_svg_icon_filepath', 'bea_svg_icon_filepath' ); | ||
function bea_svg_icon_filepath( $filepath ) { | ||
if ( is_file( get_stylesheet_directory() . '/assets/icons/icons.svg' ) ) { | ||
$filepath = get_stylesheet_directory() . '/assets/icons/icons.svg'; | ||
|
||
} | ||
|
||
return $filepath; | ||
if ( is_file( get_stylesheet_directory() . '/assets/icons/icons.svg' ) ) { | ||
$filepath = get_stylesheet_directory() . '/assets/icons/icons.svg'; | ||
} | ||
return $filepath; | ||
} | ||
``` | ||
|
||
## Changelog ## | ||
|
||
### 1.0.1 | ||
* 11 May 2017 | ||
### 1.2.0 - 27 July 2017 | ||
* Add compatibility for ACF 5.6.0 and more versions | ||
* Still keep compatibility for ACF 5.6.0 and lower versions | ||
* Add some custom CSS for a more beautiful admin UI | ||
* Now displaying the icon name, not anymore like a slug | ||
* Improve readme | ||
|
||
### 1.0.1 - 11 May 2017 | ||
* Initial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
(function ($) { | ||
function initialize_field($field) { | ||
var input = $field.find('.acf-input input'); | ||
var allowClear = $(input).attr('data-allow-clear') || 0; | ||
var opts = { | ||
dropdownCssClass: "bigdrop widefat", | ||
dropdownAutoWidth: true, | ||
formatResult: svg_icon_format, | ||
formatSelection: svg_icon_format_small, | ||
data: {results: svg_icon_format_data}, | ||
allowClear: 1 == allowClear | ||
}; | ||
|
||
input.select2(opts); | ||
|
||
/** | ||
* Format the content in select 2 for the selected item | ||
* | ||
* @param css | ||
* @returns {string} | ||
*/ | ||
function svg_icon_format(css) { | ||
return '<svg class="acf_svg__icon icon ' + css.id + '" aria-hidden="true" role="img"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#' + css.id + '"></use> </svg>' + css.text; | ||
} | ||
|
||
/** | ||
* Format the content in select 2 for the dropdown list | ||
* | ||
* @param css | ||
* @returns {string} | ||
*/ | ||
function svg_icon_format_small(css) { | ||
return '<svg class="acf_svg__icon small icon ' + css.id + '" aria-hidden="true" role="img"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#' + css.id + '"></use> </svg>' + css.text; | ||
} | ||
|
||
} | ||
|
||
/* | ||
* ready append (ACF5) | ||
* | ||
* These are 2 events which are fired during the page load | ||
* ready = on page load similar to jQuery(document).ready() | ||
* append = on new DOM elements appended via repeater field | ||
* | ||
* @type event | ||
* @date 20/07/13 | ||
* | ||
* @param jQueryel (jQuery selection) the jQuery element which contains the ACF fields | ||
* @return n/a | ||
*/ | ||
acf.add_action('ready append', function (jQueryel) { | ||
// search jQueryel for fields of type 'FIELD_NAME' | ||
acf.get_fields({type: 'svg_icon'}, jQueryel).each(function () { | ||
initialize_field($(this)); | ||
}); | ||
}); | ||
})(jQuery); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
(function ($) { | ||
function initialize_field($field) { | ||
var input = $field.find('.acf-input input'); | ||
var allowClear = $(input).attr('data-allow-clear') || 0; | ||
var opts = { | ||
dropdownCssClass: "bigdrop widefat", | ||
dropdownAutoWidth: true, | ||
templateResult: bea_svg_format, | ||
templateSelection: bea_svg_format_small, | ||
data: svg_icon_format_data, | ||
allowClear: 1 == allowClear, | ||
}; | ||
|
||
input.select2(opts); | ||
|
||
/** | ||
* Format the content in select 2 for the selected item | ||
* | ||
* @param css | ||
* @returns {string} | ||
*/ | ||
function bea_svg_format(css) { | ||
if (!css.id) { return css.text; } | ||
return $('<span class="acf_svg__span"><svg class="acf_svg__icon icon ' + css.id + '" aria-hidden="true" role="img"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#' + css.id + '"></use></svg>' + css.text + '</span>'); | ||
}; | ||
|
||
/** | ||
* Format the content in select 2 for the dropdown list | ||
* | ||
* @param css | ||
* @returns {string} | ||
*/ | ||
function bea_svg_format_small(css) { | ||
if (!css.id) { return css.text; } | ||
return $('<span class="acf_svg__span"><svg class="acf_svg__icon small icon ' + css.id + '" aria-hidden="true" role="img"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#' + css.id + '"></use></svg>' + css.text + '</span>'); | ||
}; | ||
} | ||
|
||
/* | ||
* ready append (ACF5) | ||
* | ||
* These are 2 events which are fired during the page load | ||
* ready = on page load similar to jQuery(document).ready() | ||
* append = on new DOM elements appended via repeater field | ||
* | ||
* @type event | ||
* @date 20/07/13 | ||
* | ||
* @param jQueryel (jQuery selection) the jQuery element which contains the ACF fields | ||
* @return n/a | ||
*/ | ||
acf.add_action('ready append', function (jQueryel) { | ||
// search jQueryel for fields of type 'FIELD_NAME' | ||
acf.get_fields({type: 'svg_icon'}, jQueryel).each(function () { | ||
initialize_field($(this)); | ||
}); | ||
}); | ||
})(jQuery); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php class acf_field_svg_icon_5 extends acf_field_svg_icon { | ||
|
||
function __construct() { | ||
// do not delete! | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Enqueue assets for the SVG icon field in admin | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
function input_admin_enqueue_scripts() { | ||
// The suffix. | ||
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG === true ? '' : '.min'; | ||
|
||
// Scripts. | ||
wp_register_script( 'acf-input-svg-icon', ACF_SVG_ICON_URL . 'assets/js/input-5' . $suffix . '.js', array( | ||
'jquery', | ||
'select2', | ||
'acf-input' | ||
), ACF_SVG_ICON_VER ); | ||
|
||
// Enqueuing. | ||
wp_enqueue_script( 'acf-input-svg-icon' ); | ||
|
||
parent::input_admin_enqueue_scripts(); | ||
} | ||
} |
Oops, something went wrong.