I would like to change variable var ajax_loader = jQuery('<img class="fl-spinner" width="16" heigth="16" src="' + fl_mc_settings.fl_spinner + '" />');
of externally added _.js, that I can't change, remove etc.
jQuery(document).ready(function() {
jQuery(document).on("click", ".fl_click_switcher a", fl_switch_currency_handler)
});
var fl_switch_currency_handler = function(event) {
event.preventDefault();
if (jQuery(this).is(":disabled") || jQuery(this).parent().hasClass("fl-cs-active-currency") || jQuery(this).hasClass("fl-cs-active-currency")) {
return false
} else {
jQuery(this).off(event)
}
fl_load_currency(jQuery(this).attr("rel"))
};
function fl_load_currency(currency, force_switch) {
var ajax_loader = jQuery('<img class="fl-spinner" width="16" heigth="16" src="' + fl_mc_settings.fl_spinner + '" />');
jQuery(".fl_click_switcher").append(ajax_loader);
if (typeof force_switch === "undefined")
force_switch = 0;
jQuery.ajax({.........
Thanks you
The simplest solution must be to add fl_mc_settings.fl_spinner = "new-image.jpg";
to your script (make sure it loads after the spinner js)
With it one simply override the image being used as the spinner
E.g.
<script src="path-to-spinner.js"></script>
<script>
fl_mc_settings.fl_spinner = "new-image.jpg";
</script>
Updated based on a comment
As the image source is injected into a HTML fragment, here is a trick using an img
's onload
event.
What it does is to also inject onload="wrap_img(this);"
into the img
markup, and when the image gets inserted, and the image been loaded, the event fires, and one can then, here done with jQuery's .wrap()
method, wrap the image in e.g. a div
.
var fl_spinner = 'http://placehold.it/200x100/" onload="wrap_img(this);"';
var ajax_loader = '<img class="fl-spinner" width="160" heigth="160" src="' + fl_spinner + '" />';
function wrap_img(img) {
$(img).wrap( "<div class='spinner_wrapper'></div>" );
}
document.body.innerHTML = ajax_loader;
.spinner_wrapper {
display: inline-block;
background: red;
padding: 20px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
And in your case it could look something like this
<script src="path-to-spinner.js"></script>
<script>
fl_mc_settings.fl_spinner = 'new-image.jpg" onload="wrap_img(this);"';
function wrap_img(img) {
jQuery(img).wrap( "<div class='spinner_wrapper'></div>" );
}
</script>
<style>
.spinner_wrapper {
display: inline-block;
background: red;
padding: 20px;
}
</style>