javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -
i run blogger blog , use follow code javascript code (requires no jquery) show related post labels/categories of post.
<script type='text/javascript'> var defaultnoimage="http://1.bp.blogspot.com/-m72rpguntq0/vuokijudn_i/aaaaaaaaboi/lq18sceunsg/w72/favicon-tik.png"; var maxresults=16; var splittercolor="#d4eaf2"; var relatedpoststitle="related posts"; </script> <script type='text/javascript'>//<![cdata[ var relatedtitles = new array(); var relatedtitlesnum = 0; var relatedurls = new array(); var thumburl = new array(); function related_results_labels_thumbs(json) { (var = 0; < json.feed.entry.length; i++) { var entry = json.feed.entry[i]; relatedtitles[relatedtitlesnum] = entry.title.$t; try { thumburl[relatedtitlesnum] = entry.media$thumbnail.url } catch (error) { s = entry.content.$t; = s.indexof("<img"); b = s.indexof("src=\"", a); c = s.indexof("\"", b + 5); d = s.substr(b + 5, c - b - 5); if ((a != -1) && (b != -1) && (c != -1) && (d != "")) { thumburl[relatedtitlesnum] = d } else { if (typeof(defaultnoimage) !== 'undefined') { thumburl[relatedtitlesnum] = defaultnoimage } else { thumburl[relatedtitlesnum] = "http://1.bp.blogspot.com/_u4gysn2zgqe/sosvnavwq0i/aaaaaaaaark/yl95wlytqr0/s400/noimage.png" } } } if (relatedtitles[relatedtitlesnum].length > 80) { relatedtitles[relatedtitlesnum] = relatedtitles[relatedtitlesnum].substring(0, 80) + "..." } (var k = 0; k < entry.link.length; k++) { if (entry.link[k].rel == 'alternate') { relatedurls[relatedtitlesnum] = entry.link[k].href; relatedtitlesnum++ } } } } function removerelatedduplicates_thumbs() { var tmp = new array(0); var tmp2 = new array(0); var tmp3 = new array(0); (var = 0; < relatedurls.length; i++) { if (!contains_thumbs(tmp, relatedurls[i])) { tmp.length += 1; tmp[tmp.length - 1] = relatedurls[i]; tmp2.length += 1; tmp3.length += 1; tmp2[tmp2.length - 1] = relatedtitles[i]; tmp3[tmp3.length - 1] = thumburl[i] } } relatedtitles = tmp2; relatedurls = tmp; thumburl = tmp3 } function contains_thumbs(a, e) { (var j = 0; j < a.length; j++) { if (a[j] == e) { return true } } return false } function printrelatedlabels_thumbs(current) { var splitbarcolor; if (typeof(splittercolor) !== 'undefined') { splitbarcolor = splittercolor } else { splitbarcolor = "#d4eaf2" } (var = 0; < relatedurls.length; i++) { if ((relatedurls[i] == current) || (!relatedtitles[i])) { relatedurls.splice(i, 1); relatedtitles.splice(i, 1); thumburl.splice(i, 1); i-- } } var r = math.floor((relatedtitles.length - 1) * math.random()); var = 0; if (relatedtitles.length > 0) { document.write('<div class="title">' + relatedpoststitle + '</div>') } document.write('<div style="clear: both;"/>'); while (i < relatedtitles.length && < 20 && < maxresults) { document.write(' <a href="' + relatedurls[r] + '"><img src="' + thumburl[r] + '"/><br/><div class="relatedpostitle" >' + relatedtitles[r] + '</div></a>'); i++; if (r < relatedtitles.length - 1) { r++ } else { r = 0 } } document.write('</div>'); relatedurls.splice(0, relatedurls.length); thumburl.splice(0, thumburl.length); relatedtitles.splice(0, relatedtitles.length) } //]]></script> <div id='related-posts'> <b:loop values='data:post.labels' var='label'> <b:if cond='data:label.islast != "true"'/> <script expr:src='"/feeds/posts/summary/-/" + data:label.name + "?alt=json-in-script&callback=related_results_labels_thumbs&max-results=6"' type='text/javascript'/> </b:loop> <script defer='defer' type='text/javascript'>removerelatedduplicates_thumbs();printrelatedlabels_thumbs("<data:post.url/>");</script> </div> <div style='clear:both'/>
this code works fine except 1 problem. code generates small images ( in default blogger thumbnail size s72-c) , there no way customize size (to change s72-c s200/s200-c/w200).
i have found image re-sizing solution script blogger not helping. here it
function resizethumb(size) { var popularpost = document.getelementbyid('popularposts1'); var image = popularpost.getelementsbytagname('img'); (var = 0; < image.length; i++) { image[i].src = image[i].src.replace(/\/s72\-c/g, "\/s" + size + "-c") } } resizethumb(200);
this popular post widget. , know if change id in first line replace image. not solution cover up. , means 2 images loaded on s72-c , replaced one.
i want integrate (something this) in first related post script. have tried hard very little knowledge of javascript have fail. signed stackoverflow , question post.
thank in advance trying me.
function code image size s200-c
function resizethumb(size) { var popularpost = document.getelementbyid('popularposts1'); var image = popularpost.getelementsbytagname('img'); (var = 0; < image.length; i++) { image[i].src = image[i].src.replace(/\/s200\-c/g, "\/s" + size + "-c") } } resizethumb(200);
function code image size s200
function resizethumb(size) { var popularpost = document.getelementbyid('popularposts1'); var image = popularpost.getelementsbytagname('img'); (var = 0; < image.length; i++) { image[i].src = image[i].src.replace(/\/s200\/g, "\/s" + size + "") } } resizethumb(200);
Comments
Post a Comment