website/themes/hugo-theme-wave/static/bower_components/talaria/dist/talaria.min.js

1 line
9.3 KiB
JavaScript
Raw Normal View History

2020-01-12 14:14:15 +01:00
var talaria=function(t){"use strict";function e(t){this.name="RateLimitedError",this.message=t||"Rate-Limit exceeded."}function a(t){this.name="NotFoundError",this.message=t||"Object not found."}function n(t){return 403===t.status}var r={},o={COMMENTABLE_CONTENT_PATH_PREFIX:"_posts/",CONTENT_SUFFIX:".md",CACHE_TIMEOUT:36e5,PAGINATION_SCHEME:/\/page\d+\//,LOCAL_STORAGE_SUPPORTED:!1,PERMALINK_IDENTIFIER:"a.permalink",PERMALINK_STYLE:/[\.\w\-_:\/]+\/(\d+)\/(\d+)\/(\d+)\/([\w\-\.]+)$/},i=function(){switch(r.PERMALINK_STYLE){case"pretty":return/[\.\w\-_:\/]+\/(\d+)\/(\d+)\/(\d+)\/([\w\-\.]+)\/$/;case"date":return/[\.\w\-_:\/]+\/(\d+)\/(\d+)\/(\d+)\/([\w\-\.]+)\.html$/;case"none":if(!r.USE_GISTS)throw new Error("When using commit-based comments, talaria requires the use of permalinks that include the date of the post");return/[\.\w\-_:\/]+\/([\w\-\.]+)\.html$/;default:return r.PERMALINK_STYLE}},c=function(t){return t.replace(r.PERMALINK_STYLE,r.COMMENTABLE_CONTENT_PATH_PREFIX+"$1-$2-$3-$4"+r.CONTENT_SUFFIX)},m=function(t){return t.substr(0,7)},s=function(){try{return sessionStorage.setItem("dummy","dummy"),sessionStorage.removeItem("dummy"),!0}catch(t){return!1}},u=function(t){return(new Date).getTime()-t.timestamp>r.CACHE_TIMEOUT},l=function(e){var a;return r.LOCAL_STORAGE_SUPPORTED&&(a=sessionStorage.getItem(e),a&&(a=JSON.parse(a),!u(a)))?t.resolve(a.commentData):t.reject("cache miss")},d=function(t,e){r.LOCAL_STORAGE_SUPPORTED&&sessionStorage.setItem(t,JSON.stringify({timestamp:(new Date).getTime(),commentData:e}))},h=function(t){return t.length>0?t.sort(function(t,e){return new Date(t.commit.committer.date)>new Date(e.commit.committer.date)})[0]:void 0},p=function(t,e){var a=function(t){return 1===t?"":"s"},n=6e4,r=60*n,o=24*r,i=30*o,c=365*o,m=15e3,s=t-e,u=0;return n>s?m>s?" just now":Math.round(s/1e3)+" seconds ago":r>s?(u=Math.round(s/n),u+" minute"+a(u)+" ago"):o>s?(u=Math.round(s/r),u+" hour"+a(u)+" ago"):i>s?(u=Math.round(s/o),u+" day"+a(u)+" ago"):c>s?(u=Math.round(s/i),"about "+u+" month"+a(u)+" ago"):(u=Math.round(s/c),"about "+u+" year"+a(u)+" ago")},f=function(t,e,a){document.getElementById("talaria-show-"+t).addEventListener("click",function(e){a&&(e.preventDefault(),document.querySelector("#talaria-wrap-"+t+" .talaria-comment-list-wrapper").classList.remove("hide"),this.classList.add("hide"))}),document.getElementById("talaria-add-"+t).addEventListener("click",function(){r.LOCAL_STORAGE_SUPPORTED&&sessionStorage.removeItem(e)})},E=function(t){t=t||{};for(var e=1;e<arguments.length;e++)if(arguments[e])for(var a in arguments[e])arguments[e].hasOwnProperty(a)&&(t[a]=arguments[e][a]);return t},v=function(t){return new Promise(function(e,a){var n=new XMLHttpRequest;n.open("GET",t,!0),n.setRequestHeader("Accept","application/vnd.github.v3.html+json"),n.onload=function(){n.status>=200&&n.status<400?e(JSON.parse(n.responseText)):a(n)},n.onerror=function(){a(n)},n.send()})},T=function(t){for(var e=t;null!==e.parentNode;){if("ARTICLE"===e.parentElement.tagName)return e.parentNode;e=e.parentNode}return e};e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,a.prototype=Object.create(Error.prototype),a.prototype.constructor=a;var _=function(t,e,a,n){var r=document.createElement("div");return n=0===a||n,r.innerHTML='<div id="talaria-wrap-'+t+'" class="talaria-wrapper"> <div class="talaria-load-error hide"> Unable to retrieve comments for this post. </div> <div class="talaria-comment-count'+(n?"":" hide")+'"> <a id="talaria-show-'+t+'" href="'+e+'">'+(0===a?"Be the first to comment":a+" comment"+(1===a?"":"s"))+'</a> </div> <div class="talaria-comment-list-wrapper'+(n?" hide":"")+'"> <div class="talaria-header"> <h3>Comments <small>via <a class="talaria-last-commit-href" href="'+e+'">github</a></small></h3> </div> <div class="talaria-comment-list" id="talaria-comment-list-'+t+'"> <!-- comments are dynamically added here --> </div> <div class="talaria-align-right"> <a id="talaria-add-'+t+'" class="talaria-add-comment-button" href="'+e+'"> <button type="submit">A