Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <style type="text/css">
- .author-line {margin: 3px 0;}
- .author-avatar {vertical-align:middle;}
- </style>
- <script type="text/javascript">
- //
- // Blog authors gadget, works like multi author profile gadget,
- // but with post counts and avatars, ordered most written first,
- // by MS-potilas 2013. See http://yabtb.blogspot.fi/2012/06/profile-gadget-with-avatars-and-post.html
- // Special version which allows overriding of author profile urls.
- //
- var auth_url = {};
- //
- // CONFIG:
- var maxUserNameLength = 42; // 0: don't cut, >4: cut usernames
- //
- var txtAuthorLine = '[image] [user] has written [count] [post]'; // can also use [#] (=position)
- //
- var sizeAvatar = 20;
- var cropAvatar = true;
- //
- var urlNoAvatar = "http://lh4.googleusercontent.com/-069mnq7DV_g/TvgRrBI_JaI/AAAAAAAAAic/Iot55vywnYw/s"+sizeAvatar+"/avatar_blue_m_96.png"; // http://www.blogger.com/img/avatar_blue_m_96.png resizeable
- // Override author links, in case they are missing from the feed:
- auth_url['Izmail'] = 'http://www.somelink.com/';
- auth_url['Macmohan'] = 'http://www.someotherlink.com/';
- // config end
- function replaceAuthorVars(text, item, position)
- {
- if(!item || !item.author) return text;
- var author = item.author;
- var authorUri = "";
- if(author.uri && author.uri.$t != "")
- authorUri = author.uri.$t;
- var avaimg = urlNoAvatar;
- if(author.gd$image && author.gd$image.src)
- avaimg = author.gd$image.src;
- if(avaimg == "http://img2.blogblog.com/img/b16-rounded.gif" && urlNoAvatar != "")
- avaimg = urlNoAvatar;
- var newsize="s"+sizeAvatar;
- avaimg = avaimg.replace(/\/s\d\d+-c\//, "/"+newsize+"-c/");
- if(cropAvatar) newsize+="-c";
- avaimg = avaimg.replace(/\/s\d\d+(-c){0,1}\//, "/"+newsize+"/");
- var authorName = author.name.$t;
- if(auth_url[authorName] && auth_url[authorName] != "")
- authorUri = auth_url[authorName];
- var imgcode = '<img class="author-avatar" height="'+sizeAvatar+'" width="'+sizeAvatar+'" title="'+authorName+'" src="'+avaimg+'" />';
- if(authorUri!="") imgcode = '<a href="'+authorUri+'">'+imgcode+'</a>';
- if(maxUserNameLength > 3 && authorName.length > maxUserNameLength)
- authorName = authorName.substr(0, maxUserNameLength-3) + "...";
- var authorcode = authorName;
- if(authorUri!="") authorcode = '<a class="profile-name-link" href="'+authorUri+'">'+authorcode+'</a>';
- text = text.replace('[user]', authorcode);
- text = text.replace('[image]', imgcode);
- text = text.replace('[#]', position);
- text = text.replace('[count]', item.count);
- if(item.count != 1)
- text = text.replace('[post]', "posts");
- else
- text = text.replace('[post]', "post");
- return text;
- }
- var blauthors = {};
- var blndxbase = 1;
- function showAuthors(json) {
- for(var i = 0 ; i < json.feed.entry.length ; i++ ) {
- var entry = json.feed.entry[i];
- var authorUri = "";
- if(entry.author[0].uri && entry.author[0].uri.$t != "")
- authorUri = entry.author[0].uri.$t;
- var authorName = entry.author[0].name.$t;
- if(blauthors[authorName])
- blauthors[authorName].count++;
- else {
- var aut = new Object();
- aut.author = entry.author[0];
- aut.count = 1;
- blauthors[authorName] = aut;
- }
- }
- if(json.feed.entry.length == 500) {
- blndxbase += 500;
- document.write('<script type="text/javascript" src="http://'+window.location.hostname+'/feeds/posts/default?redirect=false&max-results=500&start-index='+blndxbase+'&alt=json-in-script&callback=showAuthors"></'+'script>');
- return;
- }
- var tuplear = [];
- for(var key in blauthors) tuplear.push([key, blauthors[key]]);
- tuplear.sort(function(a, b) {
- if(b[1].count-a[1].count)
- return b[1].count-a[1].count;
- return (a[1].author.name.$t.toLowerCase() < b[1].author.name.$t.toLowerCase()) ? -1 : 1;
- });
- // output authors:
- document.write('<di'+'v class="blog-author">');
- for(var i = 0; i < tuplear.length ; i++) {
- var item = tuplear[i][1];
- document.write('<di'+'v class="author-line">');
- document.write(replaceAuthorVars(txtAuthorLine, item, i+1));
- document.write('</d'+'iv>');
- }
- document.write('</d'+'iv>');
- }
- document.write('<script type="text/javascript" src="http://'+window.location.hostname+'/feeds/posts/default?redirect=false&max-results=500&alt=json-in-script&callback=showAuthors"></'+'script>');
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement