Official Everybody Edits Forums

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.

#1 2015-09-16 02:42:42

Xfrogman43
Member
From: need to find a new home
Joined: 2015-02-15
Posts: 4,174

Highlighting + quickqoute

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?


zsbu6Xm.png thanks zoey aaaaaaaaaaaand thanks latif for the avatar

Offline

#2 2015-09-16 03:04:02

Different55
Forum Admin
Joined: 2015-02-07
Posts: 16,575

Re: Highlighting + quickqoute

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

Wooted by: (2)

#3 2015-09-16 13:05:28, last edited by AlphaJon (2015-09-16 14:54:05)

AlphaJon
Member
From: Who knows
Joined: 2015-07-21
Posts: 1,297

Re: Highlighting + quickqoute

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 //forums.everybodyedits.com/img/smilies/smile
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

Wooted by: (2)

#4 2015-09-16 13:24:43, last edited by hummerz5 (2015-09-16 13:31:32)

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,854

Re: Highlighting + quickqoute

edit: yep, jon has it figured out

ignore my ramble //forums.everybodyedits.com/img/smilies/big_smile

@jon: Yeah, you'll need to jump around a bit. Probably go up to ".blockquote" and then back down to ".postmsg" if you want the message itself.

Offline

#5 2015-09-16 14:56:39

AlphaJon
Member
From: Who knows
Joined: 2015-07-21
Posts: 1,297

Re: Highlighting + quickqoute

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

#6 2015-09-16 16:04:39, last edited by Different55 (2015-09-16 16:12:08)

Different55
Forum Admin
Joined: 2015-02-07
Posts: 16,575

Re: Highlighting + quickqoute

Thanks, Jonathan. Will add.

EDIT: Added, I think.


"Sometimes failing a leap of faith is better than inching forward"
- ShinsukeIto

Offline

#7 2015-09-16 16:55:03, last edited by skullz17 (2015-09-16 16:57:35)

skullz17
Member
Joined: 2015-02-15
Posts: 6,699

Re: Highlighting + quickqoute

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).


m3gPDRb.png

thx for sig bobithan

Offline

#8 2015-09-16 23:08:07, last edited by hummerz5 (2015-09-16 23:14:29)

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,854

Re: Highlighting + quickqoute

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

#9 2015-09-16 23:13:51, last edited by Different55 (2015-09-16 23:16:14)

Different55
Forum Admin
Joined: 2015-02-07
Posts: 16,575

Re: Highlighting + quickqoute

Nubs I need browser versions and OS.

hummerz5 wrote:

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

Wooted by:

#10 2015-09-17 03:32:20

Xfrogman43
Member
From: need to find a new home
Joined: 2015-02-15
Posts: 4,174

Re: Highlighting + quickqoute

You didn't remove it? I can still highlight+quickquote. Lying is bad!


zsbu6Xm.png thanks zoey aaaaaaaaaaaand thanks latif for the avatar

Offline

#11 2015-09-17 08:30:40

AlphaJon
Member
From: Who knows
Joined: 2015-07-21
Posts: 1,297

Re: Highlighting + quickqoute

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

#12 2015-09-17 13:35:57

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,854

Re: Highlighting + quickqoute

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

#13 2015-09-17 14:34:22

AlphaJon
Member
From: Who knows
Joined: 2015-07-21
Posts: 1,297

Re: Highlighting + quickqoute

hummerz5 wrote:

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 //forums.everybodyedits.com/img/smilies/smile

Offline

#14 2015-09-17 22:37:26

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,854

Re: Highlighting + quickqoute

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

Wooted by:

#15 2015-09-18 00:37:38

Anch
Member
Joined: 2015-02-16
Posts: 5,447

Re: Highlighting + quickqoute

Offline

#16 2015-09-18 01:05:48

Schlog
Banned
Joined: 2015-07-21
Posts: 1,960

Re: Highlighting + quickqoute

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

#17 2015-09-18 01:10:47

Anch
Member
Joined: 2015-02-16
Posts: 5,447

Re: Highlighting + quickqoute

MLGNinja 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

#18 2015-09-18 01:11:52

Schlog
Banned
Joined: 2015-07-21
Posts: 1,960

Re: Highlighting + quickqoute

anch159 wrote:
MLGNinja 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

#19 2015-09-18 08:57:53, last edited by AlphaJon (2015-09-25 11:33:19)

AlphaJon
Member
From: Who knows
Joined: 2015-07-21
Posts: 1,297

Re: Highlighting + quickqoute

hummerz5 wrote:

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 //forums.everybodyedits.com/img/smilies/neutral, so I've tried something else using your .find("*") idea (which seems to work now on my browser //forums.everybodyedits.com/img/smilies/smile ).
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

#20 2015-09-22 08:29:05

AlphaJon
Member
From: Who knows
Joined: 2015-07-21
Posts: 1,297

Re: Highlighting + quickqoute

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 //forums.everybodyedits.com/img/smilies/smile

@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

#21 2015-09-25 02:39:32

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,854

Re: Highlighting + quickqoute

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

#22 2015-09-25 03:35:42

Different55
Forum Admin
Joined: 2015-02-07
Posts: 16,575

Re: Highlighting + quickqoute

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

#23 2015-09-25 03:38:59, last edited by hummerz5 (2015-09-25 03:43:24)

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,854

Re: Highlighting + quickqoute

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

#24 2015-09-25 11:28:25, last edited by AlphaJon (2015-09-25 11:34:01)

AlphaJon
Member
From: Who knows
Joined: 2015-07-21
Posts: 1,297

Re: Highlighting + quickqoute

hummerz5 wrote:

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?

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&amp;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

#25 2015-09-25 13:46:47

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,854

Re: Highlighting + quickqoute

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

Wooted by:
hummerz51453597403577448

Board footer

Powered by FluxBB

[ Started around 1738461055.304 - Generated in 0.335 seconds, 11 queries executed - Memory usage: 1.71 MiB (Peak: 1.98 MiB) ]