Can someone help me to make this work with ajax pager in drupal 6? It’s a script that turns links to a picture into embedded pics on forum, when u go to another page it doesn’t work anymore have to refresh page.
<script>
$('a[href$=".png"], a[href$=".jpg"], a[href$=".gif"], a[href$=".tiff"], a[href$=".webp"]').each(function(){
$(this).html('<img src="' + $(this).attr('href') + '" />');
});
</script>
This code works it turns youtube links into embeds, how to change it into image links into <img tags?
$(document).ready(function(){
var ytRegExpUrl = /^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)((?!\bchannel\b)[\w\-]+)([\S]+)?$/;
var ytFrame = '<iframe width="100%" height="315" src="https://www.youtube.com/embed/{youtubeVideoId}" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'
function replaceUrlToPlayer() {
$("#content-content a").each(function() {
var toText = $(this).attr('href');
var match = ytRegExpUrl.exec(toText);
if (match !== null) {
var textToReplace = match[5];
if(typeof(match[6]) != "undefined"){
if(match[6].toLowerCase().includes("t=")){
textToReplace += match[6];
}
}
var replacement = ytFrame.replace('{youtubeVideoId}', textToReplace);
$(this).replaceWith(replacement);
}
});
};
Drupal.behaviors.YtUrlToPlayerBehaviour = function(context, settings) {
$(document).ajaxComplete(function(event, xhr, settings) {
replaceUrlToPlayer();
});
}
});
system
Closed
July 18, 2021, 6:18am
3
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.