initial dynamic reply code
This commit is contained in:
parent
982cbf2eb1
commit
1b7526ff2f
18
build-js.sh
18
build-js.sh
@ -14,6 +14,16 @@ if [ ! -f $GOPATH/bin/minify ]; then
|
||||
fi
|
||||
outfile=$(readlink -e ./contrib/static/nntpchan.js)
|
||||
|
||||
lint() {
|
||||
if [ "x$(which jslint)" == "x" ] ; then
|
||||
# no jslint
|
||||
true
|
||||
else
|
||||
echo "jslint: $1"
|
||||
jslint --browser $1
|
||||
fi
|
||||
}
|
||||
|
||||
mini() {
|
||||
echo "minify $1"
|
||||
echo "" >> $2
|
||||
@ -21,6 +31,14 @@ mini() {
|
||||
$GOPATH/bin/minify --mime=text/javascript >> $2 < $1
|
||||
}
|
||||
|
||||
# do linting too
|
||||
if [ "x$1" == "xlint" ] ; then
|
||||
echo "linting..."
|
||||
for f in ./contrib/js/*.js ; do
|
||||
lint $f
|
||||
done
|
||||
fi
|
||||
|
||||
echo -e "//For source code and license information please check https://github.com/majestrate/nntpchan \n" > $outfile
|
||||
|
||||
mini ./contrib/js/main.js_ $outfile
|
||||
|
@ -1,5 +1,189 @@
|
||||
// insert a backlink for a post given its short hash
|
||||
function nntpchan_backlink(shorthash) {
|
||||
|
||||
var dynreply;
|
||||
|
||||
function getReplyTo() {
|
||||
if(!dynreply) {
|
||||
var e = document.getElementById("postform-container");
|
||||
if (e) {
|
||||
// use existing postform
|
||||
dynreply = new DynReply(e);
|
||||
} else {
|
||||
// build a new postform
|
||||
dynreply = new DynReply();
|
||||
}
|
||||
}
|
||||
return dynreply;
|
||||
}
|
||||
|
||||
function table_insert_row(table, header, items) {
|
||||
var tr = document.createElement("tr");
|
||||
// insert header element
|
||||
var th = document.createElement("th");
|
||||
th.appendChild(header);
|
||||
tr.appendChild(th);
|
||||
// insert the rest of the elements
|
||||
for (var idx = 0; idx < items.length; idx ++ ) {
|
||||
var elem = document.createElement("td");
|
||||
elem.appendChild(items[idx]);
|
||||
tr.appendChild(elem);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
build dynamic reply box
|
||||
*/
|
||||
function DynReply(existingElem) {
|
||||
if (existingElem) {
|
||||
// wrap existing post form
|
||||
this.elem = existingElem;
|
||||
this.form = this.elem.querySelector("form");
|
||||
return;
|
||||
}
|
||||
|
||||
// build new post form
|
||||
|
||||
var elem = document.createElement("div");
|
||||
elem.setAttribute("id", "postform-container");
|
||||
|
||||
this.elem = elem;
|
||||
// build post form
|
||||
this.form = document.createElement("form");
|
||||
this.form.enctype = "multipart/form-data";
|
||||
this.form.name = "post";
|
||||
this.form.method = "post";
|
||||
// reference
|
||||
elem = document.createElement("input");
|
||||
elem.setAttribute("id", "postform_reference");
|
||||
elem.name = "reference";
|
||||
elem.type = "hidden";
|
||||
this.form.appendChild(elem);
|
||||
|
||||
var table = document.createElement("table");
|
||||
table.setAttribute("class", "postform");
|
||||
var tbody = document.createElement("tbody");
|
||||
|
||||
// name
|
||||
elem = document.createElement("input");
|
||||
elem.setAttribute("name", "name");
|
||||
elem.setAttribute("value", "Anonymous");
|
||||
table_insert_row(tbody, document.createTextNode("Name"), [elem])
|
||||
|
||||
// subject
|
||||
elem = document.createElement("input");
|
||||
elem.setAttribute("name", "subject");
|
||||
elem.setAttribute("value", "");
|
||||
// submit
|
||||
var submit = document.createElement("input");
|
||||
submit.setAttribute("type", "submit");
|
||||
submit.setAttribute("value", "reply");
|
||||
submit.setAttribute("class", "button");
|
||||
table_insert_row(tbody, document.createTextNode("Subject"), [elem, submit]);
|
||||
|
||||
// Comment
|
||||
elem = document.createElement("textarea");
|
||||
elem.setAttribute("id", "postform_message");
|
||||
elem.setAttribute("name", "message");
|
||||
elem.setAttribute("cols", "40");
|
||||
elem.setAttribute("rows", "5");
|
||||
table_insert_row(tbody, document.createTextNode("Comment"), [elem]);
|
||||
|
||||
// file
|
||||
elem = document.createElement("input");
|
||||
elem.setAttribute("class", "postform_attachment");
|
||||
elem.setAttribute("id", "postform_attachments");
|
||||
elem.setAttribute("type", "file");
|
||||
elem.setAttribute("name", "attachment_uploaded");
|
||||
elem.setAttribute("multiple", "multiple");
|
||||
table_insert_row(tbody, document.createTextNode("Files"), [elem]);
|
||||
|
||||
// dubs
|
||||
elem = document.createElement("input");
|
||||
elem.setAttribute("type", "checkbox");
|
||||
elem.setAttribute("name", "dubs");
|
||||
table_insert_row(tbody, document.createTextNode("Get Dubs"), [elem]);
|
||||
|
||||
// captcha
|
||||
elem = document.createElement("img");
|
||||
elem.setAttribute("id", "captcha_img");
|
||||
elem.alt = "captcha";
|
||||
table_insert_row(tbody, document.createTextNode("Captcha"), [elem]);
|
||||
|
||||
// captcha solution
|
||||
elem = document.createElement("input");
|
||||
elem.name = "captcha";
|
||||
elem.autocomplete = "off";
|
||||
table_insert_row(tbody, document.createTextNode("Name"), [elem])
|
||||
|
||||
table.appendChild(tbody);
|
||||
this.form.appendChild(table);
|
||||
this.elem.appendChild(this.form);
|
||||
|
||||
parent.appendChild(this.elem);
|
||||
|
||||
this.board = null;
|
||||
this.roothash = null;
|
||||
this.prefix = null;
|
||||
}
|
||||
|
||||
DynReply.prototype.update = function() {
|
||||
if (this.prefix) {
|
||||
// update captcha
|
||||
this.updateCaptcha();
|
||||
if (this.board && this.roothash) {
|
||||
// update post form
|
||||
var ref = document.getElementById("postform_reference");
|
||||
ref.value = this.roothash;
|
||||
this.form.action = this.prefix + "post/" + this.board;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DynReply.prototype.show = function() {
|
||||
this.update();
|
||||
this.elem.style.display = 'inline';
|
||||
}
|
||||
|
||||
DynReply.prototype.updateCaptcha = function() {
|
||||
if (this.prefix) {
|
||||
var captcha_img = document.getElementById("captcha_img");
|
||||
captcha_img.src = this.prefix + "captcha/img";
|
||||
}
|
||||
}
|
||||
|
||||
DynReply.prototype.setPrefix = function(prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
DynReply.prototype.hide = function() {
|
||||
this.elem.style.display = 'none';
|
||||
}
|
||||
|
||||
|
||||
DynReply.prototype.setBoard = function(boardname) {
|
||||
if (boardname) {
|
||||
this.board = boardname;
|
||||
}
|
||||
}
|
||||
|
||||
DynReply.prototype.setRoot = function(roothash) {
|
||||
if (roothash) {
|
||||
this.roothash = roothash;
|
||||
}
|
||||
}
|
||||
|
||||
// reply box function
|
||||
function nntpchan_reply(prefix, parent, shorthash) {
|
||||
if (prefix && parent && parent.roothash && parent.boardname) {
|
||||
var boardname = parent.boardname;
|
||||
var roothash = parent.roothash;
|
||||
var replyto = getReplyTo();
|
||||
// set target
|
||||
replyto.setBoard(boardname);
|
||||
replyto.setRoot(roothash);
|
||||
replyto.setPrefix(prefix);
|
||||
// show it
|
||||
replyto.show();
|
||||
}
|
||||
var elem = document.getElementById("postform_message");
|
||||
if ( elem )
|
||||
{
|
||||
|
@ -11,7 +11,22 @@ handler(j);}};ajax.open("GET",url);ajax.send();}
|
||||
function nntpchan_buildpost(parent,j){var post=document.createElement("div");if(j){post.innerHTML=j.PostMarkup;inject_hover_for_element(post);}else{post.setAttribute("class","notfound post");post.appendChild(document.createTextNode("post not found"));}
|
||||
parent.appendChild(post);}
|
||||
/* ./contrib/js/backlink.js */
|
||||
function nntpchan_backlink(shorthash){var elem=document.getElementById("postform_message");if(elem)
|
||||
var dynreply;function getReplyTo(){if(!dynreply){var e=document.getElementById("postform-container");if(e){dynreply=new DynReply(e);}else{dynreply=new DynReply();}}
|
||||
return dynreply;}
|
||||
function table_insert_row(table,header,items){var tr=document.createElement("tr");var th=document.createElement("th");th.appendChild(header);tr.appendChild(th);for(var idx=0;idx<items.length;idx++){var elem=document.createElement("td");elem.appendChild(items[idx]);tr.appendChild(elem);}}
|
||||
function DynReply(existingElem){if(existingElem){this.elem=existingElem;this.form=this.elem.querySelector("form");return;}
|
||||
var elem=document.createElement("div");elem.setAttribute("id","postform-container");this.elem=elem;this.form=document.createElement("form");this.form.enctype="multipart/form-data";this.form.name="post";this.form.method="post";elem=document.createElement("input");elem.setAttribute("id","postform_reference");elem.name="reference";elem.type="hidden";this.form.appendChild(elem);var table=document.createElement("table");table.setAttribute("class","postform");var tbody=document.createElement("tbody");elem=document.createElement("input");elem.setAttribute("name","name");elem.setAttribute("value","Anonymous");table_insert_row(tbody,document.createTextNode("Name"),[elem])
|
||||
elem=document.createElement("input");elem.setAttribute("name","subject");elem.setAttribute("value","");var submit=document.createElement("input");submit.setAttribute("type","submit");submit.setAttribute("value","reply");submit.setAttribute("class","button");table_insert_row(tbody,document.createTextNode("Subject"),[elem,submit]);elem=document.createElement("textarea");elem.setAttribute("id","postform_message");elem.setAttribute("name","message");elem.setAttribute("cols","40");elem.setAttribute("rows","5");table_insert_row(tbody,document.createTextNode("Comment"),[elem]);elem=document.createElement("input");elem.setAttribute("class","postform_attachment");elem.setAttribute("id","postform_attachments");elem.setAttribute("type","file");elem.setAttribute("name","attachment_uploaded");elem.setAttribute("multiple","multiple");table_insert_row(tbody,document.createTextNode("Files"),[elem]);elem=document.createElement("input");elem.setAttribute("type","checkbox");elem.setAttribute("name","dubs");table_insert_row(tbody,document.createTextNode("Get Dubs"),[elem]);elem=document.createElement("img");elem.setAttribute("id","captcha_img");elem.alt="captcha";table_insert_row(tbody,document.createTextNode("Captcha"),[elem]);elem=document.createElement("input");elem.name="captcha";elem.autocomplete="off";table_insert_row(tbody,document.createTextNode("Name"),[elem])
|
||||
table.appendChild(tbody);this.form.appendChild(table);this.elem.appendChild(this.form);parent.appendChild(this.elem);this.board=null;this.roothash=null;this.prefix=null;}
|
||||
DynReply.prototype.update=function(){if(this.prefix){this.updateCaptcha();if(this.board&&this.roothash){var ref=document.getElementById("postform_reference");ref.value=this.roothash;this.form.action=this.prefix+"post/"+this.board;}}}
|
||||
DynReply.prototype.show=function(){this.update();this.elem.style.display='inline';}
|
||||
DynReply.prototype.updateCaptcha=function(){if(this.prefix){var captcha_img=document.getElementById("captcha_img");captcha_img.src=this.prefix+"captcha/img";}}
|
||||
DynReply.prototype.setPrefix=function(prefix){this.prefix=prefix;}
|
||||
DynReply.prototype.hide=function(){this.elem.style.display='none';}
|
||||
DynReply.prototype.setBoard=function(boardname){if(boardname){this.board=boardname;}}
|
||||
DynReply.prototype.setRoot=function(roothash){if(roothash){this.roothash=roothash;}}
|
||||
function nntpchan_reply(prefix,parent,shorthash){if(prefix&&parent&&parent.roothash&&parent.boardname){var boardname=parent.boardname;var roothash=parent.roothash;var replyto=getReplyTo();replyto.setBoard(boardname);replyto.setRoot(roothash);replyto.setPrefix(prefix);replyto.show();}
|
||||
var elem=document.getElementById("postform_message");if(elem)
|
||||
{elem.value+=">>"+shorthash.substr(0,10)+"\n";}}
|
||||
function inject_hover(prefix,el,parent){if(!prefix){throw"prefix is not defined";}
|
||||
var linkhash=el.getAttribute("backlinkhash");if(!linkhash){throw"linkhash undefined";}
|
||||
@ -24,6 +39,8 @@ for(var elem in ls){inject_hover(prefix,ls[elem]);}}
|
||||
function init(prefix){inject_hover_for_element(document);}
|
||||
/* ./contrib/js/banner.js */
|
||||
var banner_count=3;function nntpchan_inject_banners(elem,prefix){var n=Math.floor(Math.random()*banner_count);var banner=prefix+"static/banner_"+n+".jpg";var e=document.createElement("img");e.src=banner;e.id="nntpchan_banner";elem.appendChild(e);}
|
||||
/* ./contrib/js/dynamic-reply.js */
|
||||
|
||||
/* ./contrib/js/expand-image.js */
|
||||
function filenameIsImage(fname){return/\.(gif|jpeg|jpg|png|webp)/.test(fname);}
|
||||
function setupInlineImage(thumb,url){if(thumb.inlineIsSetUp)return;thumb.inlineIsSetUp=true;var img=thumb.querySelector("img.thumbnail");var expanded=false;var oldurl=img.src;thumb.onclick=function(){if(expanded){img.setAttribute("class","thumbnail");img.src=oldurl;expanded=false;}else{img.setAttribute("class","expanded-thumbnail");img.src=url;expanded=true;}
|
||||
|
@ -14,7 +14,7 @@
|
||||
<span class="subject">{{post.Subject}}</span>
|
||||
<span class="name">{{post.Name}}</span>
|
||||
<time datetime="{{post.DateRFC}}">{{post.Date}}</time>
|
||||
<a href="#" class="postnol">No.</a><a class="postno" onclick="nntpchan_backlink('{{post.ShortHash}}');" title="{{post.MessageID}}">{{post.ShortHash}}</a>
|
||||
<a href="#" class="postnol">No.</a><a class="postno" onclick="nntpchan_reply('{{post.Prefix}}', this, '{{post.ShortHash}}');" title="{{post.MessageID}}" roothash="{{post.ReferenceHash}}" boardname="{{post.Board}}">{{post.ShortHash}}</a>
|
||||
<a href="{{post.PostURL}}">[{{#i18n.Translations}}{{reply_label}}{{/i18n.Translations}}]</a>
|
||||
<span class="tripcode">{{{post.Pubkey}}}</span>
|
||||
</legend>
|
||||
|
@ -10,7 +10,7 @@
|
||||
}}
|
||||
<form action="{{post_url}}" enctype="multipart/form-data" name="post" method="post">
|
||||
{{{csrf}}}
|
||||
<input type="hidden" name="reference" value="{{reference}}" />
|
||||
<input type="hidden" name="reference" value="{{reference}}" id="postform_reference"/>
|
||||
<div id="postform-outer">
|
||||
<div id="postform-inner">
|
||||
<table class="postform">
|
||||
|
Reference in New Issue
Block a user