-
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.
#6 : try to work load the icon for custom image in BO
- Loading branch information
1 parent
2362cf4
commit 180daba
Showing
2 changed files
with
90 additions
and
5 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 +1,72 @@ | ||
!function(a){function n(n){function t(n){return n.id?a('<span class="acf_svg__span"><svg class="acf_svg__icon icon '+n.id+'" aria-hidden="true" role="img"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#'+n.id+'"></use></svg>'+n.text+"</span>"):n.text}function i(n){return n.id?a('<span class="acf_svg__span"><svg class="acf_svg__icon small icon '+n.id+'" aria-hidden="true" role="img"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#'+n.id+'"></use></svg>'+n.text+"</span>"):n.text}var s=n.find(".acf-input input"),e=a(s).attr("data-allow-clear")||0,l={dropdownCssClass:"bigdrop widefat",dropdownAutoWidth:!0,templateResult:t,templateSelection:i,data:svg_icon_format_data,allowClear:1==e};s.select2(l)}acf.add_action("ready append",function(t){acf.get_fields({type:"svg_icon"},t).each(function(){n(a(this))})})}(jQuery); | ||
(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) { | ||
console.log(css); | ||
if (!css.id) { | ||
return css.text; | ||
} | ||
if (css.url) { | ||
return $('<span class="acf_svg__span" data-id="' + css.id + '">' + css.text + '</span>'); | ||
} else { | ||
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) { | ||
console.log(css); | ||
if (!css.id) { | ||
return css.text; | ||
} | ||
if (css.url) { | ||
return $('<span class="acf_svg__span" data-id="' + css.id + '">' + css.text + '</span>'); | ||
} else { | ||
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); |