Archived
1
0

try fixing drag to move for reply box

This commit is contained in:
Jeff Becker 2016-04-30 14:44:06 -04:00
parent 61e390daf0
commit ecb223ebc4
No known key found for this signature in database
GPG Key ID: AB950234D6EA286B
3 changed files with 30 additions and 15 deletions

View File

@ -123,6 +123,11 @@ function DynReply(existingElem) {
this.prefix = null; this.prefix = null;
} }
DynReply.prototype.moveTo = function(x,y) {
this.elem.style.top = y + "px";
this.elem.style.left = x + "px";
}
DynReply.prototype.update = function() { DynReply.prototype.update = function() {
if (this.prefix) { if (this.prefix) {
// update captcha // update captcha
@ -171,15 +176,14 @@ DynReply.prototype.setRoot = function(roothash) {
} }
// reply box function // reply box function
function nntpchan_reply(prefix, parent, shorthash) { function nntpchan_reply(parent, shorthash) {
if (prefix && parent) { if (parent) {
var boardname = parent.getAttribute("boardname"); var boardname = parent.getAttribute("boardname");
var roothash = parent.getAttribute("root"); var roothash = parent.getAttribute("root");
var replyto = getReplyTo(); var replyto = getReplyTo();
// set target // set target
replyto.setBoard(boardname); replyto.setBoard(boardname);
replyto.setRoot(roothash); replyto.setRoot(roothash);
replyto.setPrefix(prefix);
// show it // show it
replyto.show(); replyto.show();
} }
@ -261,14 +265,22 @@ function init(prefix) {
var rpl = getReplyTo(); var rpl = getReplyTo();
rpl.setPrefix(prefix); rpl.setPrefix(prefix);
var e = rpl.elem; var e = rpl.elem;
e.setAttribute("draggable", "true");
e.ondragend = function(ev) { var mouseDownX, mouseDownY;
ev.preventDefault();
var x = 0; var originalX = window.width - 300;
var y = 0; var originalY = 10;
console.log(ev); rpl.moveTo(originalX, originalY);
var el = document.getElementById("postform_container");
el.setAttribute("style", "top: "+y+"px; left: "+x+ "px; position: fixed; "); e.addEventListener("mousedown", function(ev) {
} mouseDownX = ev.clientX;
mouseDownY = ev.clientY;
});
e.addEventListener("mouseup", function(ev) {
var x = originalX + ev.clientX - mouseDownX
var y = originalY + ev.clientY - mouseDownY
rpl.moveTo(x, y);
});
} }

View File

@ -19,6 +19,7 @@ function DynReply(existingElem){if(existingElem){this.elem=existingElem;this.for
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]) 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]) 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);document.body.appendChild(this.elem);this.board=null;this.roothash=null;this.prefix=null;} table.appendChild(tbody);this.form.appendChild(table);this.elem.appendChild(this.form);document.body.appendChild(this.elem);this.board=null;this.roothash=null;this.prefix=null;}
DynReply.prototype.moveTo=function(x,y){this.elem.style.top=y+"px";this.elem.style.left=x+"px";}
DynReply.prototype.update=function(){if(this.prefix){this.updateCaptcha();if(this.board&&this.roothash){var ref=document.getElementById("postform_reference");ref.setAttribute("value",this.roothash);this.form.action=this.prefix+"post/"+this.board;}}} DynReply.prototype.update=function(){if(this.prefix){this.updateCaptcha();if(this.board&&this.roothash){var ref=document.getElementById("postform_reference");ref.setAttribute("value",this.roothash);this.form.action=this.prefix+"post/"+this.board;}}}
DynReply.prototype.show=function(){console.log("show dynreply");this.update();this.elem.style.display='inline';} DynReply.prototype.show=function(){console.log("show dynreply");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.updateCaptcha=function(){if(this.prefix){var captcha_img=document.getElementById("captcha_img");captcha_img.src=this.prefix+"captcha/img";}}
@ -26,7 +27,7 @@ DynReply.prototype.setPrefix=function(prefix){this.prefix=prefix;}
DynReply.prototype.hide=function(){this.elem.style.display='none';} DynReply.prototype.hide=function(){this.elem.style.display='none';}
DynReply.prototype.setBoard=function(boardname){if(boardname){this.board=boardname;}} DynReply.prototype.setBoard=function(boardname){if(boardname){this.board=boardname;}}
DynReply.prototype.setRoot=function(roothash){if(roothash){this.roothash=roothash;}} DynReply.prototype.setRoot=function(roothash){if(roothash){this.roothash=roothash;}}
function nntpchan_reply(prefix,parent,shorthash){if(prefix&&parent){var boardname=parent.getAttribute("boardname");var roothash=parent.getAttribute("root");var replyto=getReplyTo();replyto.setBoard(boardname);replyto.setRoot(roothash);replyto.setPrefix(prefix);replyto.show();} function nntpchan_reply(parent,shorthash){if(parent){var boardname=parent.getAttribute("boardname");var roothash=parent.getAttribute("root");var replyto=getReplyTo();replyto.setBoard(boardname);replyto.setRoot(roothash);replyto.show();}
var elem=document.getElementById("postform_message");if(elem) var elem=document.getElementById("postform_message");if(elem)
{elem.value+=">>"+shorthash.substr(0,10)+"\n";}} {elem.value+=">>"+shorthash.substr(0,10)+"\n";}}
function inject_hover(prefix,el,parent){if(!prefix){throw"prefix is not defined";} function inject_hover(prefix,el,parent){if(!prefix){throw"prefix is not defined";}
@ -37,7 +38,9 @@ parent.appendChild(wrapper);parent.backlink=false;},function(msg){var wrapper=do
parent.backlink=true;}};parent.backlink=true;} parent.backlink=true;}};parent.backlink=true;}
function inject_hover_for_element(elem){var elems=elem.getElementsByClassName("backlink");var ls=[];var l=elems.length;for(var idx=0;idx<l;idx++){var e=elems[idx];ls.push(e);} function inject_hover_for_element(elem){var elems=elem.getElementsByClassName("backlink");var ls=[];var l=elems.length;for(var idx=0;idx<l;idx++){var e=elems[idx];ls.push(e);}
for(var elem in ls){inject_hover(prefix,ls[elem]);}} for(var elem in ls){inject_hover(prefix,ls[elem]);}}
function init(prefix){inject_hover_for_element(document);var rpl=getReplyTo();rpl.setPrefix(prefix);var e=rpl.elem;e.setAttribute("draggable","true");e.ondragend=function(ev){ev.preventDefault();var x=0;var y=0;console.log(ev);var el=document.getElementById("postform_container");el.setAttribute("style","top: "+y+"px; left: "+x+"px; position: fixed; ");}} function init(prefix){inject_hover_for_element(document);var rpl=getReplyTo();rpl.setPrefix(prefix);var e=rpl.elem;var mouseDownX,mouseDownY;var originalX=window.width-300;var originalY=10;rpl.moveTo(originalX,originalY);e.addEventListener("mousedown",function(ev){mouseDownX=ev.clientX;mouseDownY=ev.clientY;});e.addEventListener("mouseup",function(ev){var x=originalX+ev.clientX-mouseDownX
var y=originalY+ev.clientY-mouseDownY
rpl.moveTo(x,y);});}
/* ./contrib/js/banner.js */ /* ./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);} 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/expand-image.js */ /* ./contrib/js/expand-image.js */

View File

@ -14,7 +14,7 @@
<span class="subject">{{post.Subject}}</span> <span class="subject">{{post.Subject}}</span>
<span class="name">{{post.Name}}</span> <span class="name">{{post.Name}}</span>
<time datetime="{{post.DateRFC}}">{{post.Date}}</time> <time datetime="{{post.DateRFC}}">{{post.Date}}</time>
<a href="#" class="postnol">No.</a><a class="postno" onclick="nntpchan_reply('{{post.Prefix}}', this, '{{post.ShortHash}}');" title="{{post.MessageID}}" root="{{post.Reference}}" boardname="{{post.Board}}">{{post.ShortHash}}</a> <a href="#" class="postnol">No.</a><a class="postno" onclick="nntpchan_reply(this, '{{post.ShortHash}}');" title="{{post.MessageID}}" root="{{post.Reference}}" boardname="{{post.Board}}">{{post.ShortHash}}</a>
<a href="{{post.PostURL}}">[{{#i18n.Translations}}{{reply_label}}{{/i18n.Translations}}]</a> <a href="{{post.PostURL}}">[{{#i18n.Translations}}{{reply_label}}{{/i18n.Translations}}]</a>
<span class="tripcode">{{{post.Pubkey}}}</span> <span class="tripcode">{{{post.Pubkey}}}</span>
</legend> </legend>