Переписать код jQuery на чистый JavaScript
255 UAHПереписать код jQuery на чистый JavaScript
Код:
(function($) { $(':not(.logo) img').filter(function() { return this.src.match - Pastebin.com
(function($) {
$(':not(.logo) img').filter(function() { return this.src.match(/.*\.svg$/); }).each(function(){
var imgSVG = $(this);
var imgURL = $(this).attr('src');
var imgAlt = $(this).attr('alt');
var imgTitle = $(this).attr('title');
var imgClass = $(this).attr('class');
$.get(imgURL, function(data) {
var svg = $(data).find('svg');
// Remove invalid XML tags - mostly that is usefull to preserve so it is commented out here
// svg = svg.removeAttr('xmlns xmlns:xlink');
// add replaced image's alt tag to the inline SVG
typeof imgAlt === 'undefined' || imgAlt === '' ? (svg = svg.attr('alt', 'Replaced Image')) : (svg = svg.attr('alt', imgAlt)) ;
// add replaced image's Title tag to the inline SVG
typeof imgTitle === 'undefined' || imgTitle === '' ? (svg = svg.attr('title', 'A SVG Image replaced by its inline code')) : (svg = svg.attr('title', imgTitle));
// Add replaced image's classes to the new SVG and add replaced-svg as new class
typeof imgClass === 'undefined' || imgClass === '' ? (svg = svg.attr('class', 'replaced-svg')) : (svg = svg.attr('class', imgClass+' replaced-svg'));
// Replace image with inline SVG Code
imgSVG.replaceWith(svg);
}, 'xml');
});
})(jQuery);
-
39 1 0 Сделаю без праблем и задержак.
Вот фрагмент кода:
let notLogoImg = document.querySelectorAll(':not(.logo) img').filter((v) => {
return this.src.match(/.*\.svg$/);
});
for (let svg of notLogoImg) {
if (!svg.hasOwnProperty('src')) {
throw new Error("Cant find url");
… }
const url = svg.getAttribute('src');
fetch(url).then(response => {
if (isJsonString(response)) {
response = response.json();
}
-
3759 111 3 5 Здравствуйте, Руслан
Готов переписать jquery код на чистый js.
C уважением, Юрий