// tarragon2.assanka.com Inferno = { reqid: 1, requests:[], host:'http://inferno.t.ft.com', replyto:null, reporting:null, config:{}, user: null, linksByRef:{}, linksByURI:{}, comments:{}, domReady: false, JSON: {}, hooks:{ preDOMChange:function(content, contid, itemid, mode, sortindex){}, postDOMChange:function(content, contid, itemid, mode, sortindex){}, load:function(){} }, init:function() { // Backwards compatibility if (typeof infernositeid != 'undefined') InfernoConfig.site = infernositeid; // Quit if siteid has not yet been specified - init can be called again by user code once config is done if (typeof InfernoConfig == 'undefined' || typeof InfernoConfig.site == 'undefined') return false; // Backwards compatibility if (typeof InfernoConfig == 'undefined') InfernoConfig = {}; if (typeof infernothiscontent != 'undefined') InfernoConfig.thiscontent=infernothiscontent; if (typeof InfernoConfig.ops == 'undefined') InfernoConfig.ops = []; if (typeof infernocontent != 'undefined') InfernoConfig.ops[InfernoConfig.ops.length] = {method:'editcontent', args: Inferno.JSON.parse(infernocontent)}; if (typeof infernouser != 'undefined') InfernoConfig.user = Inferno.JSON.parse(infernouser); // Defaults if (typeof InfernoConfig.commentcontainer == 'undefined') InfernoConfig.commentcontainer = 'inferno-comments'; if (typeof InfernoConfig.inputuicontainer == 'undefined') InfernoConfig.inputuicontainer = 'inferno-input'; if (typeof InfernoConfig.commentlinktext == 'undefined') InfernoConfig.commentlinktext = 'comment'; if (typeof InfernoConfig.thiscontent == 'undefined') InfernoConfig.thiscontent = location.pathname; // Set document.domain to highest level var d = document.domain.split('.'); document.domain = d[d.length-2]+'.'+d[d.length-1]; // Use custom host if specified if (typeof InfernoConfig.host != 'undefined') Inferno.host = InfernoConfig.host; // Set up custom event hooks if ('hooks' in InfernoConfig) { for (h in InfernoConfig.hooks) Inferno.addFunctionHook(InfernoConfig.hooks[h], h); } // Compile initial API request for (var i=0, s=InfernoConfig.ops.length; i=0; --i) { if (links[i].innerHTML.toLowerCase() == InfernoConfig.commentlinktext) { if (s = links[i].getAttribute('infernoref')) { if (typeof Inferno.linksByRef[s] == 'undefined') { refs[refs.length] = s; Inferno.linksByRef[s] = []; } Inferno.linksByRef[s][Inferno.linksByRef[s].length] = links[i]; } else { s = links[i].href.replace(/\/?#.*$/, "").replace(/^https?:\/\/[^\/]+/, ""); if (typeof Inferno.linksByURI[s] == 'undefined') { uris[uris.length] = s; Inferno.linksByURI[s] = []; } Inferno.linksByURI[s][Inferno.linksByURI[s].length] = links[i]; } } } if (refs.length) Inferno.queueOperation("getMultiCounts", {'refs':refs}); if (uris.length) Inferno.queueOperation("getMultiCounts", {'uris':uris}); if (Inferno.el(InfernoConfig.commentcontainer) || Inferno.el(InfernoConfig.inputuicontainer)) { Inferno.queueOperation('getCSS', {ref:InfernoConfig.thiscontent}); } if (Inferno.el(InfernoConfig.commentcontainer)) { Inferno.queueOperation('getListWrapperUI', {ref:InfernoConfig.thiscontent}); listcomopts = {ref:InfernoConfig.thiscontent}; if (typeof InfernoConfig.overrides != 'undefined' && typeof InfernoConfig.overrides.sort != 'undefined') { listcomopts.sort = InfernoConfig.overrides.sort; } Inferno.queueOperation('listComments', listcomopts); } if (Inferno.el(InfernoConfig.inputuicontainer)) { Inferno.queueOperation('getInputUI', {ref:InfernoConfig.thiscontent}); } // Send API request if (Inferno.requests[Inferno.reqid]) Inferno.sendRequest(); }, queueOperation: function(method, args) { if (!args) args = {}; if (typeof Inferno.requests[Inferno.reqid] == 'undefined') Inferno.requests[Inferno.reqid] = []; Inferno.requests[Inferno.reqid][Inferno.requests[Inferno.reqid].length] = {method:method,args:args}; }, sendRequest: function() { if (!InfernoConfig.site) throw("Site ID not specified"); var req = {site: InfernoConfig.site, output:{format:'iframe', jsonp:'parent.Inferno.receiveResponse', themed:1,data:1}, operations:[]}; if (Inferno.user && typeof Inferno.user.id != 'undefined') req.user = Inferno.user.token; else if (typeof InfernoConfig.user != 'undefined') req.user = InfernoConfig.user; Inferno.queueOperation('echo', {key:'reqid', val:Inferno.reqid}); req.operations = Inferno.requests[Inferno.reqid]; var reqdata = Inferno.JSON.stringify(req, function(key, value) { if (typeof this[key] == 'object' && Object.prototype.toString.apply(this[key]) === '[object Array]') { return this[key]; } else { return value; } }); var html = "
"; var enc = encodeURIComponent(reqdata).replace(/\n/g,"%0A").replace(/&/g, "%26").replace(/'/g, "%27"); html += ""; html += "
"; var reqdiv = document.createElement("DIV"); reqdiv.id = "infernoreq"+Inferno.reqid; reqdiv.innerHTML = html; document.body.appendChild(reqdiv); try { reqdiv.firstChild.submit(); } catch(e) {}; Inferno.reqid++; }, receiveResponse: function(data) { if (typeof data.status != 'undefined' && data.status=='error'){ if (data.code == 0) alert(data.message); //console.log("API ERROR", data.code, data.message); return false; } if (typeof data.length == 'undefined' || !data.length || typeof data[data.length-1].reqid == 'undefined') throw "Unable to parse API response"; var thisreq = data[data.length-1].reqid; for (var i in data) { var req = Inferno.requests[thisreq][i], resp = data[i]; //console.log(req.method, resp); if (typeof resp.status != 'undefined' && resp.status=='error') { if (resp.code==0) { alert(resp.message); Inferno.enabletextarea(); } else { //console.log("API ERROR", resp.code, resp.message); } if (req.method=='reportAbuse') Inferno.cancelAbuseReport(); } else if (req.method=='getMultiCounts') { if (req.args.uris) { var links = Inferno.linksByURI; var reqrefs = req.args.uris; } else { var links = Inferno.linksByRef; var reqrefs = req.args.refs; } for (r in resp) { if (typeof resp[r].rendered != 'undefined') { if (typeof links[reqrefs[r]] != 'undefined') { for (l in links[reqrefs[r]]) links[reqrefs[r]][l].innerHTML = resp[r].rendered; } } } } else if (req.method=='getListWrapperUI') { Inferno.dom(resp.rendered, InfernoConfig.commentcontainer, false, 'add'); Inferno.prepUI(); } else if (req.method=='listComments') { Inferno.dom('', 'inferno-commentlist'); for (r in resp) { Inferno.dom(resp[r].rendered, 'inferno-commentlist', 'inferno-item'+resp[r].id, 'add', resp[r].sortindex); Inferno.comments[resp[r].id] = resp[r]; } Inferno.renumberComments(); Inferno.showHideModOpts(); // Scroll to anchor comment, if specified on query string var loc = String(document.location); var idx = loc.indexOf('#comment-'); if (idx>0) { var cmtid = loc.substring(idx+9); var cmtobj = Inferno.el("inferno-item"+cmtid); if (cmtobj) window.scrollTo(0, cmtobj.offsetTop); } } else if (req.method=='newComment') { Inferno.dom(resp.rendered, 'inferno-commentlist', 'infernocomment'+resp.id, 'add', resp.sortindex); Inferno.comments[resp.id] = resp; Inferno.renumberComments(); Inferno.showHideModOpts(); Inferno.enabletextarea(); Inferno.el('inferno-postform-txtcommment').value = Inferno.config.deftext } else if (req.method=='getConfig') { Inferno.config = resp; if (typeof InfernoConfig.overrides != 'undefined' && typeof InfernoConfig.overrides.sort != 'undefined') { Inferno.config.sort = InfernoConfig.overrides.sort; } Inferno.prepUI(); } else if (req.method=='getUserDetail') { Inferno.user = resp; Inferno.showHideModOpts(); } else if (req.method=='getInputUI') { Inferno.dom(resp.rendered, InfernoConfig.inputuicontainer, false, 'add'); Inferno.enabletextarea(); } else if (req.method=='getCSS') { var styleElement = document.createElement("style"); styleElement.type = "text/css"; styleElement.id = "inferno-css"; if (styleElement.styleSheet) { styleElement.styleSheet.cssText = resp.rendered; } else { styleElement.appendChild(document.createTextNode(resp.rendered)); } document.getElementsByTagName("head")[0].appendChild(styleElement); } else if (req.method=='getModOpts') { Inferno.el('inferno-optmenu').innerHTML = resp.rendered; } else if (req.method=='openCommenting' || req.method=='closeCommenting') { // No action } else if (req.method=='rejectComment' || req.method=='queueForModeration') { Inferno.hideCommentOpts(); Inferno.dom(null, 'inferno-item'+req.args.id, null, 'remove'); } else if (req.method=='reportAbuse') { if (Inferno.reporting) { alert("Thank you for your abuse report. The comment has been queued to be examined by a member of our moderation team"); Inferno.cancelAbuseReport(); Inferno.reporting = null; } } else if (req.method=='editComment') { Inferno.dom(resp.rendered, 'inferno-commentlist', 'inferno-item'+resp.id, 'add', resp.sortindex); Inferno.comments[resp.id] = resp; Inferno.renumberComments(); Inferno.showHideModOpts(); } else if (req.method=='vote') { //TODO } } if (thisreq==1) Inferno.hooks.load(); }, prepUI: function() { if (Inferno.el('inferno-sortopts')) { Inferno.hide(Inferno.el('inferno-sortopts').childNodes); Inferno.show('inferno-sort-'+Inferno.config.sort); } if (Inferno.el('inferno-contentopts')) { Inferno.hide(Inferno.el('inferno-contentopts').childNodes); if (Inferno.user && Inferno.user.canmoderate) { if ((!Inferno.config.expdate || Inferno.config.expdate > Inferno.time()) && (!Inferno.config.embdate || Inferno.config.embdate < Inferno.time())) { Inferno.show('inferno-contentopts-open'); Inferno.el('inferno-contentopts-open').getElementsByTagName('a')[0].onclick = function() { Inferno.queueOperation('closeCommenting', {ref:Inferno.config.ref}); Inferno.queueOperation('getConfig', {ref:Inferno.config.ref}); Inferno.sendRequest(); }; } else { Inferno.show('inferno-contentopts-closed'); Inferno.el('inferno-contentopts-closed').getElementsByTagName('a')[0].onclick = function() { Inferno.queueOperation('openCommenting', {ref:Inferno.config.ref}); Inferno.queueOperation('getConfig', {ref:Inferno.config.ref}); Inferno.sendRequest(); }; } } } if (typeof Inferno.config.reportabuse != "undefined" && Inferno.config.reportabuse && !Inferno.el('inferno-recaptchalib')) { var scripttag = document.createElement("SCRIPT"); scripttag.id = "inferno-recaptchalib"; scripttag.type = "text/javascript"; scripttag.src = "http://api.recaptcha.net/js/recaptcha_ajax.js"; document.getElementsByTagName("HEAD")[0].appendChild(scripttag); } if (typeof Inferno.config.sort != "undefined") Inferno.show('inferno-sort-'+Inferno.config.sort); Inferno.hide('inferno-reportform'); Inferno.hide('inferno-editcommentform'); Inferno.hide('inferno-optmenu'); }, clearReq: function(ifr) { var div = ifr.frameElement.parentNode; if (div.tagName!='DIV') return; div.parentNode.removeChild(div); }, showHideModOpts: function() { var els = Inferno.digForClass(Inferno.el(InfernoConfig.commentcontainer), 'inferno-optslink'); for (var i = 0, s=els.length; i sortindex && isascending) || (items[i].getAttribute('sortindex') < sortindex && !isascending))) { insert(Inferno.el(contid), content, items[i]); inserted = true; break; } } if (!inserted) insert(Inferno.el(contid), content); } else { Inferno.el(contid).innerHTML = content; } } else if (mode=="remove") { remove(Inferno.el(contid)); } else { Inferno.el(contid).innerHTML = content; } Inferno.hooks.postDOMChange(content, contid, dedupid, mode, sortindex); return true; function insert(parent, html, insertposition) { var fr = document.createDocumentFragment(); var ol = document.createElement('OL'); ol.innerHTML = html; var els = ol.childNodes; for (var i=0, s=els.length; i 10000) { alert('Your comment is too long. Please keep your remarks under 10,000 characters in length'); return false; } ta.value = ta.value.replace(/^[\s-\.\,\:\;\_\`]+/, '').replace(/[\s-\,\:\;\_\`]+$/, ''); if (ta.value == Inferno.config.deftext || !ta.value.length) { alert('Please type a comment first.'); ta.focus(); return false; } ta.blur(); ta.disabled=true; Inferno.el("inferno-postform-btnsubmit").disabled = true; var params = {ref:Inferno.config.ref, mask:chkmask, name:name, comment:ta.value}; if (Inferno.replyto) { params.replyto = Inferno.replyto; Inferno.replyto = null; Inferno.el(InfernoConfig.inputuicontainer).appendChild(Inferno.el('inferno-postform')); } Inferno.queueOperation('newComment', params); Inferno.sendRequest(); return false; }, showReply:function(el) { var id = Inferno.getID(el); if (Inferno.replyto != id) { Inferno.replyto = id; Inferno.el('inferno-item'+id).appendChild(Inferno.el('inferno-postform')); } Inferno.enabletextarea(); }, enabletextarea: function() { if (Inferno.el("inferno-postform-txtcommment")) { var tb = Inferno.el("inferno-postform-txtcommment"); tb.onclick = function() { if (this.value==Inferno.config.deftext) this.value = ''; } tb.onblur = function() { if (this.value=='') this.value = Inferno.config.deftext; } tb.disabled = false; if (tb.className=='growable' && window.XMLHttpRequest) { var frm = Inferno.el('inferno-postform-form'); tb.style.overflow = 'hidden'; tb.rows = 5; tb.onkeyup = function() { var tb = Inferno.el('inferno-postform-txtcommment'); var lh = tb.clientHeight / tb.rows; while (tb.scrollHeight > tb.clientHeight && !window.opera && tb.rows < 30) { tb.style.overflow = 'hidden'; tb.rows += 1; } if (tb.scrollHeight > tb.clientHeight) tb.style.overflow = 'auto'; } tb.onkeyup(); } } if (Inferno.el("inferno-postform-btnsubmit")) { Inferno.el("inferno-postform-btnsubmit").disabled = false; } }, vote:function(el, dir) { var id = Inferno.getID(el); Inferno.queueOperation("vote", {dir:dir, id:id}); Inferno.sendRequest(); }, showCommentOpts: function(comment) { comment.blur(); while (comment = comment.parentNode) if (comment.id.indexOf('inferno-item') == 0) break; var cid = comment.id.substr(12); Inferno.show('inferno-optmenu'); Inferno.el('inferno-optmenu').innerHTML = "..."; comment.appendChild(Inferno.el('inferno-optmenu')); Inferno.queueOperation('getModOpts', {id:cid}); Inferno.sendRequest(); }, hideCommentOpts: function() { Inferno.el(InfernoConfig.commentcontainer).appendChild(Inferno.el('inferno-optmenu')); Inferno.hide('inferno-optmenu'); }, ban:function(user, level, el) { var id = Inferno.getID(el); Inferno.queueOperation("banUser", {id:user, level:level}); Inferno.queueOperation("getModOpts", {id:id}); Inferno.sendRequest(); }, ratelimit:function(user, el) { var id = Inferno.getID(el); var limit = prompt("Enter a rate limit in comments per hour", ""); if (!limit) pph = 0; Inferno.queueOperation("rateLimitUser", {id:user, pph:limit}); Inferno.queueOperation("getModOpts", {id:id}); Inferno.sendRequest(); }, rejectcomment:function(el) { var id = Inferno.getID(el); if (!confirm("Reject this comment: are you sure?")) return false; Inferno.queueOperation("rejectComment", {id:id}); Inferno.sendRequest(); }, queuecomment:function(el) { var id = Inferno.getID(el); if (!confirm("Queue this comment for moderation: are you sure? This will hide the comment.")) return false; Inferno.queueOperation("queueForModeration", {id:id}); Inferno.sendRequest(); }, showAbuseReport: function(el) { var id = Inferno.getID(el); if (Inferno.reporting) { Inferno.show("inferno-comtext"+Inferno.reporting); } var cmt = Inferno.el("inferno-comtext"+id); var rpt = Inferno.el("inferno-reportform"); Inferno.hide(cmt); Inferno.show(rpt); cmt.parentNode.insertBefore(rpt, cmt.nextSibling); Inferno.hide('inferno-reportform-inprog'); Inferno.show('inferno-reportform-buttons'); Inferno.reporting = id; Inferno.hideCommentOpts(); setTimeout(function() { Recaptcha.create(Inferno.config.recaptchapublic, "inferno-reportform-recaptcha", {theme: "clean", callback: Recaptcha.focus_response_field}); }, 50); }, cancelAbuseReport: function(id) { if (Inferno.reporting) { Inferno.show("inferno-comtext"+Inferno.reporting); Inferno.hide("inferno-reportform"); Inferno.reporting = null; } }, sendAbuseReport: function() { if (Inferno.reporting) { Inferno.queueOperation('reportAbuse', {id:Inferno.reporting,rc:Recaptcha.get_challenge(),rr:Recaptcha.get_response()}); Inferno.sendRequest(); Inferno.hide("inferno-reportform-buttons"); Inferno.show("inferno-reportform-inprog"); } return false; }, showEditComment:function(el) { var id = Inferno.getID(el); var cmt = Inferno.el("inferno-comtext"+id); var frm = Inferno.el("inferno-editcommentform"); Inferno.hide(cmt); Inferno.show(frm); cmt.parentNode.insertBefore(frm, cmt.nextSibling); Inferno.el("inferno-editcommentform-txtcomment").value = Inferno.comments[id].comment; Inferno.el("inferno-editcommentform-txtcomment").focus(); Inferno.hideCommentOpts(); }, cancelEditComment:function(el) { var id = Inferno.getID(el); Inferno.hide("inferno-editcommentform"); Inferno.show("inferno-comtext"+id); Inferno.el(InfernoConfig.commentcontainer).appendChild(Inferno.el('inferno-editcommentform')); }, saveEditComment:function(el) { var id = Inferno.getID(el); Inferno.queueOperation("editComment", {id:id, comment:Inferno.el("inferno-editcommentform-txtcomment").value}); Inferno.sendRequest(); }, getID: function(el) { el.blur(); while (el = el.parentNode) if (el.id.indexOf('inferno-item') == 0) break; return el.id.substr(12); }, el: function(id) { return document.getElementById(id); }, hide: function(id) { if (Inferno.isNL(id)) for (var i=0, s=id.length; i