Skip to content

Commit

Permalink
#6 : try to work load the icon for custom image in BO
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximeCulea committed Oct 31, 2018
1 parent 2362cf4 commit 180daba
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 5 deletions.
22 changes: 18 additions & 4 deletions assets/js/input-56.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@
* @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>');
console.log(css);
if (!css.id) {
return css.text;
}
if (css.url) {
return $('<span class="acf_svg__span">' + $.load(css.url) + '</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>');
}
};

/**
Expand All @@ -31,8 +38,15 @@
* @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>');
console.log(css);
if (!css.id) {
return css.text;
}
if (css.url) {
return $('<span class="acf_svg__span">' + $.load(css.url) + '</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>');
}
};
}

Expand Down
73 changes: 72 additions & 1 deletion assets/js/input-56.min.js
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);

0 comments on commit 180daba

Please sign in to comment.