(function(d, t, e, m, undef){ var version = "1.1.0"; var author = "Vova Feldman"; window.RW_Async_Init = function() { RW.Blogger = function() { return { getPostID : function (post) { var id, meta = RW._getFirstByAttr('itemprop', 'postId', '', 'meta', post); if (null !== meta) return meta.getAttribute('content'); var a = RW._filterElements( RW._getByAttr('name', '', '', 'a', post), function(item){ return RW._isNumeric(item.getAttribute('name')); } ); if (RW._isNotEmptyArray(a)) return a[0].getAttribute('name'); return null; }, isSuffixID : function (s) { return (RW._isNotEmptyString(s) && /^(.)*\d{3,}$/.test(s)); }, getSuffixID : function (s) { var id = ''; for (var i = s.length - 1; i >= 0; i--) { if (isNaN(s[i])) break; else id = s[i] + id; } return id; }, getCommentIDFromInner : function (comment, innerClass) { if (!RW._Class.has(comment, innerClass)) { var innerItem = RW._getFirstByClassName(innerClass, '*', comment); if (null !== innerItem && this.isSuffixID(innerItem.id)) return this.getSuffixID(innerItem.id); } return null; }, getCommentID : function (comment) { if (this.isSuffixID(comment.id)) return this.getSuffixID(comment.id); var innerClasses = ['comment-body', 'comment-block', 'body', 'block'], commentID; for (var i = 0, len = innerClasses.length; i < len; i++) { commentID = this.getCommentIDFromInner(comment, innerClasses[i]); if (null !== commentID) return commentID; } return null; }, getPostTitle : function (post) { var titleNode = RW._getByClassName('post-title', '*', post); if (titleNode.length == 0) return null; var a = RW._getByTagName('a', titleNode[0]); return (a.length > 0) ? a[0].innerHTML : titleNode[0].innerHTML; }, getCommentTitle : function (comment) { var commentContentNode = RW._getFirstByTagName('p', comment); return (null !== commentContentNode) ? commentContentNode.innerHTML.trim() : null; }, getPostImg : function (post) { var imgNode = RW._getFirstByTagName('img', post); return (null !== imgNode) ? imgNode.src : ''; }, appendPostRating : function (post, rating) { var targetContainer = this.getPostTargetContainer(post); if (null == targetContainer) return; // Insert content just before target container. RW.insertBefore(this.createRating(rating, 'blog-post'), targetContainer); }, appendCommentRating : function (comment, rating) { var commentContentNode = RW._getFirstByTagName('p', comment); if (null == commentContentNode) return; // Insert content right after target container. RW.insertAfter(this.createRating(rating, 'comment'), commentContentNode); }, getPostTargetContainer : function (post) { var container = RW._getByClassName('rw-rating-container', '*', post); if (RW._isNotEmptyArray(container)) return container[0]; var share_buttons = RW._getByClassName('post-share-buttons', '*', post); if (RW._isNotEmptyArray(share_buttons)) return share_buttons[0]; return this.getFooter(post); }, getCommentTargetContainer : function (comment) { var container = RW._getByClassName('rw-rating-container', '*', post); return (container.length > 0) ? container[0] : this.getFooter(post); }, getFooter : function (post) { var footer = RW._getByClassName('post-footer', '*', post); if (footer.length > 0) return footer[0]; // Give another chance to find footer. footer = RW._getByClassName('post-footer-line', '*', post); if (0 === footer.length) return null; return footer[0].parentNode; }, createRating : function (rating, rclass) { var r = document.createElement('div'); rclass = rclass || 'blog-post'; RW._Class.set(r, 'rw-ui-blogger-container'); r.innerHTML = '
'; return r; }, containerHAlign : function (labelAlign) { switch (labelAlign) { case 'left': return 'right'; case 'center': return 'center'; default: return 'left'; } }, getCanonicalUrl : function () { // Extract image from og:image meta. var canonical = RW._getFirstByAttr('rel', 'canonical', '', 'link', document.head); return RW._is(canonical) ? canonical.getAttribute('href') : false; }, isPost : function (posts) { return (1 === posts.length); }, // // // if one post handle differently // // appendRatingsToPosts : function (posts) { var postsData = [], postData, canonical = RW.Blogger.isPost(posts) ? RW.Blogger.getCanonicalUrl() : false; RW._foreach(posts, function(post){ // Get post id. var postID = RW.Blogger.getPostID(post); if (null == postID) return; // Get post title. var postTitle = RW.Blogger.getPostTitle(post), postImg = RW.Blogger.getPostImg(post); postData = {urid: postID, title: postTitle, img: postImg}; if (false !== canonical) postData.url = canonical; // Append rating container. RW.Blogger.appendPostRating(post, postData); postsData.push(postData); }); return postsData; }, appendRatingsToComments : function (comments) { var commentsData = [], commentData; RW._foreach(comments, function(comment){ // Get comment id. var commentID = RW.Blogger.getCommentID(comment); if (null == commentID) return; // Get comment title. var commentTitle = RW.Blogger.getCommentTitle(comment); commentData = {urid: commentID, title: commentTitle}; // Append rating container. RW.Blogger.appendCommentRating(comment, commentData); commentsData.push(commentData); }); return commentsData; } }; }(); var post_classes = ['hentry', 'h-entry', 'entry', 'post'], postEntries; // Find post entries. for (var i = 0; i < post_classes.length; i++) { postEntries = RW._getByClassName(post_classes[i], '*', document.body); if (RW._isArray(postEntries) && 0 < postEntries.length) break; } var comment_classes = ['comment', 'comment-body', 'comment-block'], commentEntries; if (!(window._rwscHide || false)) { for (var i = 0; i < comment_classes.length; i++) { commentEntries = RW._getByClassName(comment_classes[i], '*', document.body); if (RW._isArray(commentEntries) && 0 < commentEntries.length) break; } } if ((!RW._isArray(postEntries) || 0 === postEntries.length) && (!RW._isArray(commentEntries) || 0 === commentEntries.length)) // No entries found. return; var // Append ratings containers and retrieve posts data. posts = RW.Blogger.appendRatingsToPosts(postEntries), // Append ratings containers and retrieve posts data. comments = RW.Blogger.appendRatingsToComments(commentEntries); if ((!RW._isArray(posts) || 0 === posts.length) && (!RW._isArray(comments) || 0 === comments.length)) // No valid entries - can't identify posts ids. return; // Init global settings. RW.init.apply(RW, _rws); for (var i = 0, len = posts.length; i < len; i++) RW.initRating(posts[i].urid, posts[i]); for (var i = 0, len = comments.length; i < len; i++) RW.initRating(comments[i].urid, comments[i]); if (RW._isArray(comments) && 0 < comments.length) { // Create default comments style. var _rwsc = _rwsc || { type: RW.TYPE.NERO, style: 'thumbs', lng: (RW._is(_rws) && RW._is(_rws[0].options) && RW._is(_rws[0].options.lng)) ? _rws[0].options.lng : 'en' }; RW.initClass('comment', _rwsc); } RW.render(function(ratings){ // Add alignment. for (var urid in ratings) { var elements = RW._getByClassName('rw-urid-' + urid, 'div'); RW._foreach(elements, function (e){ RW._Class.add(e.parentNode, 'rw-' + RW.Blogger.containerHAlign(ratings[urid].getInstances(0).options.advanced.layout.align.hor)); }); } }); }; // Append Rating-Widget JavaScript library. var rw, s = d.getElementsByTagName(e)[0], id = "rw-js", l = d.location, ck = "Y" + t.getFullYear() + "M" + t.getMonth() + "D" + t.getDate(), p = l.protocol, f = (-1 < l.search.indexOf("DBG=") ? "" : ".min"), a = ("https:" == p ? "secure." + m + "js/" : "js." + m); if (d.getElementById(id)) return; rw = d.createElement(e); rw.id = id; rw.async = true; rw.type = "text/javascript"; rw.src = p + "//" + a + "external" + f + ".js?ck=" + ck; s.parentNode.insertBefore(rw, s); }(document, new Date(), "script", "rating-widget.com/"));