Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?
You are not logged in.
If you highlight anything on the page and quick quote somebody, it says they wrote that... Why is it not just for what that person wrote?
thanks zoey aaaaaaaaaaaand thanks latif for the avatar
Offline
Because that's how the mod works and I don't know enough javascript to change that if it's even easily possible.
"Sometimes failing a leap of faith is better than inching forward"
- ShinsukeIto
Offline
This is what handles the quick quote with highlight(embedded directly inside html)
function get_quote_text()
{
//IE
if (document.selection && document.selection.createRange())
quote_text = document.selection.createRange().text;
//NS,FF,SM
if (document.getSelection)
quote_text = document.getSelection();
}
This is already on the forums, but it doesn't do any check.
Thanks to StackOverflow, I found this function:
function getSelectionParentElement() {
var parentEl = null, sel;
if (window.getSelection) {
sel = window.getSelection();
if (sel.rangeCount) {
parentEl = sel.getRangeAt(0).commonAncestorContainer;
if (parentEl.nodeType != 1) {
parentEl = parentEl.parentNode;
}
}
} else if ( (sel = document.selection) && sel.type != "Control") {
parentEl = sel.createRange().parentElement();
}
return parentEl;
}
By using this piece of code I just wrote:
$(".postquickquote").mousedown(function(){
posttag = $(this).parents(".blockpost")[0];
highlighttag = $(getSelectionParentElement());
issig = highlighttag.parents(".postmsg").hasClass("postsignature");
//console.log(posttag);
//console.log($(getSelectionParentElement()));
if (!issig && posttag == $(getSelectionParentElement()).parents(".postmsg").parents(".blockpost")[0]){
//console.log("OK");
get_quote_text();
} else {
//console.log("ERROR");
quote_text = '';
}
});
.blockpost contains the whole user+post info
The highlight thing should behave as expected (paste the 2 functions into a javascript console to test)
Maybe the code will be integrated into the site, who knows
If not, there are ways to auto-execute the piece of code on the forums using an addon, but I don't have much information about that, so you'll have to search.
EDIT: uncomment the console.log to see how it works
EDIT 2: apparently it still allows highlighting of the signature and user info next to the post, I'll fix this later. [I'm busy now]
Offline
Offline
UPDATE: I got all the boxes other than the post out, including the signature (I had to do some special checking on this one). The only thing I can't really take out is the "Last edited" thing, but I guess it's not really an issue compared to what it was without it.
Offline
Thanks, Jonathan. Will add.
EDIT: Added, I think.
"Sometimes failing a leap of faith is better than inching forward"
- ShinsukeIto
Offline
This doesn't work properly for me. I'm trying to quick quote parts of the above post. If I just quick quote the first line, it works. However, if I try to quick quote the first line plus part of the second line, it will just quote the whole thing.
EDIT: It seems I can only quick quote a highlighted area which contains no new line spaces (idk what these are called).
thx for sig bobithan
Offline
Not working for me, either, it seems... I'm not sure how it even worked in the first place -- document.getSelection() gives me the start element and end element. Tostring works tho...
Come to think of it, did we want to keep formatting? That'll be an entirely different can of worms. We'd have to use the string in the onclick event and somehow see what was hovered.
Edit: Ah, I see what's going on. Reasonably so, the function is calling the parent because you're dealing between two siblings... so to get the whole story, they just give the parent
I'd think nextUntil would work, but elements could possibly be from different parents...
Offline
Nubs I need browser versions and OS.
Not working for me, either, it seems... I'm not sure how it even worked in the first place -- document.getSelection() gives me the start element and end element. Tostring works tho...
Come to think of it, did we want to keep formatting? That'll be an entirely different can of worms. We'd have to use the string in the onclick event and somehow see what was hovered.
Alternatively, we could not do that, and avoid tearing our hair out in frustration.
Anyway, until I get this figured out better I've removed the highlighting mod.
"Sometimes failing a leap of faith is better than inching forward"
- ShinsukeIto
Offline
You didn't remove it? I can still highlight+quickquote. Lying is bad!
thanks zoey aaaaaaaaaaaand thanks latif for the avatar
Offline
I guess it's more complicated than expected, so unless someone else finds the fixes I think it'll stay this way. I've tried more things and yep, newlines don't work(maybe related to going through multiple <p> ?) [Win7, Firefox 40.0.3]
Offline
Well, probably a revert, frog.
@Jonathan -- I figured it out to a point. I took the parent element and the two anchor/focus nodes. I got the children from the parent and looped to get all (any level) children between the two... to get the text inside regardless of html stack. PROBLEM: I have no idea how to compare a node to an element. The NodeValue is null, so...
Thoughts?
Offline
I figured it out to a point. I took the parent element and the two anchor/focus nodes. I got the children from the parent and looped to get all (any level) children between the two... to get the text inside regardless of html stack. PROBLEM: I have no idea how to compare a node to an element. The NodeValue is null, so...
I don't really get it, but I'm sure it will become clear if you post here or on pastebin (or anywhere) the bits of code you've managed to produce so far
Offline
Well, shoot. I was plugging it all into the console.
imported that getSelectionParentElement
then...
get_quote_text()
var _qt = quote_text; // for fun... I just found out it doesn't actually make the copy, it's just a reference. :\
var oar = getSelectionParentElement();
var chiles = $(oar).find("*");
for(var i = 0; i < chiles.length; i++){ if (chiles[i] == _qt.anchorNode){ console.log("hiya"); } else if (chiles[i] == _qt.focusNode){ console.log("eh"); } }'
good luck
Offline
Offline
He's saying that you can highlight ANYTHING on the page and quick quote someone. Normally, you're supposed to only be able to highlight the user's post and then quick quote it.
Offline
anch159 wrote:He's saying that you can highlight ANYTHING on the page and quick quote someone. Normally, you're supposed to only be able to highlight the user's post and then quick quote it.
Oh. Oops. Well that doesn't work for me anyway.
Offline
MLGNinja wrote:anch159 wrote:He's saying that you can highlight ANYTHING on the page and quick quote someone. Normally, you're supposed to only be able to highlight the user's post and then quick quote it.
Oh. Oops. Well that doesn't work for me anyway.
It works for me just fine. I don't know why you can't do it.
Offline
Well, shoot. I was plugging it all into the console.
imported that getSelectionParentElement
then...get_quote_text() var _qt = quote_text; // for fun... I just found out it doesn't actually make the copy, it's just a reference. :\ var oar = getSelectionParentElement(); var chiles = $(oar).find("*"); for(var i = 0; i < chiles.length; i++){ if (chiles[i] == _qt.anchorNode){ console.log("hiya"); } else if (chiles[i] == _qt.focusNode){ console.log("eh"); } }'
good luck
So I've tried different things with it, and I couldn't make use of the _qt thing , so I've tried something else using your .find("*") idea (which seems to work now on my browser ).
Here is the updated code below.
function getSelectionParentElement() {
var parentEl = null, sel;
if (window.getSelection) {
sel = window.getSelection();
if (sel.rangeCount) {
parentEl = sel.getRangeAt(0).commonAncestorContainer;
if (parentEl.nodeType != 1) {
parentEl = parentEl.parentNode;
}
}
} else if ( (sel = document.selection) && sel.type != "Control") {
parentEl = sel.createRange().parentElement();
}
return parentEl;
}
$(".postquickquote").mousedown(function(){
posttag = $(this).parents(".blockpost")[0];
highlighttag = $(getSelectionParentElement());
globalselecttag = $(highlighttag).find("*").parents(".postmsg");
issig = globalselecttag.hasClass("postsignature") || highlighttag.parents(".postmsg").hasClass("postsignature");
//console.log(posttag);
//console.log(issig);
//console.log(globalselecttag);
//console.log($(getSelectionParentElement()));
if(!issig && (posttag == globalselecttag.parents(".blockpost")[0]
|| posttag == $(getSelectionParentElement()).parents(".postmsg").parents(".blockpost")[0])){
//console.log("OK");
get_quote_text();
} else {
//console.log("ERROR");
quote_text = '';
}
});
I prefer putting it in a new post, in case something goes wrong with it and I have to go back to the older one, but It seems to work well now.
For some explanation:
$(highlighttag).find("*").parents(".postmsg") selects the common parent of the tags (which determines if all the tags are part of the post)
find("*") works only if the selection spans through multiple tags, so I left the old condition which works for single tags
EDIT: The only thing missing now are the BBCode tags, but these were already stripped out without my code when using highlighting+quickquote
EDIT 2: if something goes wrong with it, try uncommenting the console.log() and check the results
EDIT 3: added function from above post, now you can just get the contents of the <code>
Offline
Hi, it's been 4 days but I haven't got any feedback about the piece a code which is supposed to fix the problem (maybe because I posted just before the forums crash). So unless the fix is no longer wanted, I think it is worth a try
@mods: I know I'm double posting, but if I just edited the last post it would be unnoticed and the topic would sink to the bottom
Offline
I'm curious, too, to see if this worked out
Because I found this source code which apparently shuffles up through the stack to verify that the selected text is a signature, while still retaining the selected text between child elements.
function getSelectedText()
{
var result = "no"
if (document.selection) //IE & Opera
{
selNode = document.selection.createRange().parentElement();
var testNode = selNode;
var flag = 1;
while(flag == 1)
{
if ((testNode.parentNode.nodeName == 'BLOCKQUOTE'))
testNode = testNode.parentNode.parentNode;
else if ((testNode.parentNode.nodeName == 'LI'))
testNode = testNode.parentNode;
else if ((testNode.parentNode.nodeName == 'UL'))
testNode = testNode.parentNode;
else if ((testNode.nodeName == 'CODE'))
testNode = testNode.parentNode.parentNode;
else if ((testNode.nodeName == 'CITE'))
testNode = testNode.parentNode;
else if ((testNode.nodeName == 'EM'))
testNode = testNode.parentNode;
else if ((testNode.nodeName == 'STRONG'))
testNode = testNode.parentNode;
else if ((testNode.nodeName == 'SPAN'))
testNode = testNode.parentNode;
else
flag = 0;
}
if ((testNode.parentNode.className == 'entry-content') && (testNode.className != 'sig-content'))
result = document.selection.createRange().text;
}
else if (document.getSelection) //FF
{
selNode = window.getSelection().anchorNode.parentNode;
var testNode = selNode;
var flag = 1;
while(flag == 1)
{
if ((testNode.parentNode.nodeName == 'BLOCKQUOTE'))
testNode = testNode.parentNode.parentNode;
else if ((testNode.parentNode.nodeName == 'LI'))
testNode = testNode.parentNode;
else if ((testNode.parentNode.nodeName == 'UL'))
testNode = testNode.parentNode;
else if ((testNode.nodeName == 'CODE'))
testNode = testNode.parentNode.parentNode;
else if ((testNode.nodeName == 'CITE'))
testNode = testNode.parentNode;
else if ((testNode.nodeName == 'EM'))
testNode = testNode.parentNode;
else if ((testNode.nodeName == 'STRONG'))
testNode = testNode.parentNode;
else if ((testNode.nodeName == 'SPAN'))
testNode = testNode.parentNode;
else
flag = 0;
}
if ((testNode.parentNode.className == 'postmsg') && (testNode.className != 'sig-content'))
{ result = document.getSelection();
console.log(document.getSelection());
}
}
else if (window.getSelection) //Google Chrome & Safari
{
selNode = window.getSelection().anchorNode.parentNode;
var testNode = selNode;
var flag = 1;
while(flag == 1)
{
if ((testNode.parentNode.nodeName == 'BLOCKQUOTE'))
testNode = testNode.parentNode.parentNode;
else if ((testNode.parentNode.nodeName == 'LI'))
testNode = testNode.parentNode;
else if ((testNode.parentNode.nodeName == 'UL'))
testNode = testNode.parentNode;
else if ((testNode.nodeName == 'CODE'))
testNode = testNode.parentNode.parentNode;
else if ((testNode.nodeName == 'CITE'))
testNode = testNode.parentNode;
else if ((testNode.nodeName == 'EM'))
testNode = testNode.parentNode;
else if ((testNode.nodeName == 'STRONG'))
testNode = testNode.parentNode;
else if ((testNode.nodeName == 'SPAN'))
testNode = testNode.parentNode;
else
flag = 0;
}
if ((testNode.parentNode.className == 'entry-content') && (testNode.className != 'sig-content'))
result = window.getSelection();
}
else
return result;
}
But I don't remember what our problem was to begin with. Consider this a halfhearted bump then?
Offline
How are you guys testing these? When I tested the first version before uploading it worked fine but I think I'm doing something wrong/different this time.
"Sometimes failing a leap of faith is better than inching forward"
- ShinsukeIto
Offline
I'm guessing Jonathan's latest update requires some functions above what he just posted
Mine does as well. Actually, it requires quite a bit of rewriting, not just alternative functions. Probably should check into Jonathan's first.
We're pasting into either the javascript scratchpad or the browser console itself
Regarding jonathan's code, it requires getselectionparentelement (I think)
I believe it works. Am checking what actually happens w/o code to double check
final? edit: yep, his code works. KEeps me from quoting the wrong post... or the entire page...
Now we just need the bbcode .any thoughts?
Offline
I'm guessing Jonathan's latest update requires some functions above what he just posted
Mine does as well. Actually, it requires quite a bit of rewriting, not just alternative functions. Probably should check into Jonathan's first.We're pasting into either the javascript scratchpad or the browser console itself
Regarding jonathan's code, it requires getselectionparentelement (I think)
I believe it works. Am checking what actually happens w/o code to double checkfinal? edit: yep, his code works. KEeps me from quoting the wrong post... or the entire page...
Now we just need the bbcode .any thoughts?
You're right, maybe I should have mentioned it still requires the function getSelectionParentElement from the first post.
EDIT: I included it in the post
And about the BBcode, it's not gettable with highlight, because all the BBcode is converted into tags. Not highlighting gets the BBcode only because the post content with the BBcode is included in a function parameter. An example below, with Diff55's post above which contains BBcode:
<a href="post.php?tid=30553&qid=542221" onclick="Quote('Different55',
'Nubs I need browser versions and OS.\n\n[quote=hummerz5]Not working for me, either, it seems... I\'m not sure how it even worked in the first place -- document.getSelection() gives me the start element and end element. Tostring works tho...\n\nCome to think of it, did we want to keep formatting? That\'ll be an entirely different can of worms. We\'d have to use the string in the onclick event and somehow see what was hovered.[/quote]\nAlternatively, we could not do that, and avoid tearing our hair out in frustration.\n\nAnyway, until I get this figured out better I\'ve removed the highlighting mod.'
); return false;" onmousedown="get_quote_text();">Quick quote</a>
Added some newlines around block for clarity
Offline
I'm aware of this
But surely the bbcode is simply a few string replace lines, right?
Like replace [quote=hummerz5] with
<div style='quote'>
<cite>Written by: Hummerz5</cite>
<blockquote> my quoted info </blockquote>
</div>
If the html is generated by replacing the code, we should be able to go the other direction to convert the html back to bbcode
And we have the original markup for verfication
Offline
[ Started around 1738471244.2958 - Generated in 0.127 seconds, 12 queries executed - Memory usage: 1.72 MiB (Peak: 1.98 MiB) ]