function renderTweets(obj){
var checkTweets = setInterval(function(){
if( $(obj).find('iframe[id*="twitter-widget"]').contents().find('.timeline-TweetList-tweet').length > 0 ){
clearInterval(checkTweets);
var twt = $(obj).find('iframe[id*="twitter-widget"]').contents();
var tweets = twt.find('.timeline-TweetList-tweet');
var show = 1;
$(obj).find('.fsElementContent').append('<ul class="tweets">');
tweets.each(function(i){
if(i<show+1){
$(this).appendTo($(obj).find('.tweets'));
var $el = $(obj).find(".tweets > li:last-child")
var html = $el.html();
var regex = /class="(.*?)"/g;
html = html.replace(regex, function(className) {
return className.replace(/-/g, '-');
});
$el.html(html);
}
});
$(obj).find('iframe[id*="twitter-widget"]').hide();
}
},100);
}
It was mentioned by @fretburner that this part is inefficient
var $el = $(obj).find(".tweets > li:last-child")
var html = $el.html();
var regex = /class="(.*?)"/g;
html = html.replace(regex, function(className) {
return className.replace(/-/g, '-');
});
$el.html(html);
Is therea way to do this where I don’t take the newly-appended code, pull it back out, do the regex, and put it back in (and all within a loop)?
Ideally just run this once over the entire DOM set? I tried modifying var twt but I think .contents() isn’t the same as .html() so it’s erroring out there.
I don’t need the code here, but just where I should do it? Thanks.