View unanswered posts | View active topics It is currently 18 Jul 2019 20:51

Forum rules


- Use common sense and be respectful towards each other at all times, even when disagreeing.
- Do not reveal sensitive game information. Guild secrets, player seconds are examples of things not allowed.



Reply to topic  [ 24 posts ]  Go to page Previous  1, 2, 3  Next
Text Coloring 
Author Message
Adventurer

Joined: 04 Mar 2010 08:07
Posts: 93
For your trigger check the regular expression box, and put in (peculiar|exotic|unusual) in the box (that triggers on peculiar OR exotic OR unusual)

Code:
var src_str=$("#mudoutput .line").last().html();
var pattern = new RegExp("(peculiar|unusual|exotic)", "i");
src_str = src_str.replace(pattern, "<mark>$1</mark>");
$("#mudoutput .line").last().html(src_str);


There's a simpler version. The other had a lot additional checks that I don't think will be needed.

Basically all those funny symbols are regular expressions, often referred to as "regex". Regex is super handy and great to use, but it has a little bit of a learning curve. You can try some of it out here http://regexone.com/


22 Aug 2013 00:32
Profile
Adventurer

Joined: 04 Mar 2010 08:07
Posts: 93
Code:
var src_str=$("#mudoutput .line").last().html();
var pattern = new RegExp("(peculiar|unusual|exotic)", "i");
src_str = src_str.replace(pattern, "<span style=\"color:green\">$1</span>");
$("#mudoutput .line").last().html(src_str);


This gives you a little more control over the color. Note in this code the color is green, but could be changed to anything.


22 Aug 2013 00:55
Profile
Now ya talkin'!
I'm with Rincon on this one.


22 Aug 2013 02:32
Wizard
User avatar

Joined: 03 Mar 2010 21:55
Posts: 106
Location: Middle Earth
Nice one Gub. I am just thinking, we could send the last line (as jquery object) as one of the variables available within the trigger (like the args var that contains the original matching regexp), and then your trigger would not be using any internal API's at all.

_________________
Caretaker of Arda


22 Aug 2013 08:08
Profile
Adventurer

Joined: 04 Mar 2010 08:07
Posts: 93
I'm not picturing it. What would it look like?

In my ideal world I would be making calls such as:
Code:
var pattern = new RegExp("(peculiar|unusual|exotic)", "i");
gwc.output.replace(pattern, "<span style=\"color:green\">$1</span>");


I think any wrapper around the jquery calls I made would be good.


22 Aug 2013 08:36
Profile
Wizard
User avatar

Joined: 03 Mar 2010 21:55
Posts: 106
Location: Middle Earth
Gub wrote:
I'm not picturing it. What would it look like?

In my ideal world I would be making calls such as:
Code:
var pattern = new RegExp("(peculiar|unusual|exotic)", "i");
gwc.output.replace(pattern, "<span style=\"color:green\">$1</span>");


I think any wrapper around the jquery calls I made would be good.


You abstracted the calls even more then I had initially thought, but this sounds good .. Only question would be, would it be safe to do the replace on a .html() of the last line, if another trigger added different HTML before, it could mess things up, perhaps use .text() instead? Or would this be a 'user error' kind of thing?

_________________
Caretaker of Arda


22 Aug 2013 11:41
Profile
Adventurer

Joined: 04 Mar 2010 08:07
Posts: 93
I think you may be right, it is too abstracted. Maybe something closer to this?

Code:
var src_str = gwc.output.getLine();
var pattern = new RegExp("(peculiar|unusual|exotic)", "i");
src_str = src_str.replace(pattern, "<span style=\"color:green\">$1</span>");
gwc.output.replaceLine(src_str);


I could go either way on that argument. Maybe I want two triggers to alter the line twice? I think if I changed the html once, I would have to expect it to be changed moving forward and base my subsequent calls on my initial change, but thats just my stream of though. I think the argument for either case is strong. I don't know if I'd use text there, I think it'd escape the html and I wouldn't be able to use span or any html to change the line?


22 Aug 2013 22:42
Profile
Wizard
User avatar

Joined: 03 Mar 2010 21:55
Posts: 106
Location: Middle Earth
Gub wrote:
I think you may be right, it is too abstracted. Maybe something closer to this?

Code:
var src_str = gwc.output.getLine();
var pattern = new RegExp("(peculiar|unusual|exotic)", "i");
src_str = src_str.replace(pattern, "<span style=\"color:green\">$1</span>");
gwc.output.replaceLine(src_str);


I could go either way on that argument. Maybe I want two triggers to alter the line twice? I think if I changed the html once, I would have to expect it to be changed moving forward and base my subsequent calls on my initial change, but thats just my stream of though. I think the argument for either case is strong. I don't know if I'd use text there, I think it'd escape the html and I wouldn't be able to use span or any html to change the line?


I think text() removes the html tags,not escape then. Then, if we put the result back into the html() function, you should be able to use spans and such ... I suppose we could add it as an optional 3rd argument.

_________________
Caretaker of Arda


23 Aug 2013 07:37
Profile
Wizard
User avatar

Joined: 03 Mar 2010 21:55
Posts: 106
Location: Middle Earth
eowul wrote:
I think text() removes the html tags,not escape then. Then, if we put the result back into the html() function, you should be able to use spans and such ... I suppose we could add it as an optional 3rd argument.


Added gwc.output.replace with searchValue, newValue and an optional [use html] argument. The last argument determines if text() or htm() is used as the input value. Output is always added using html()

_________________
Caretaker of Arda


25 Aug 2013 12:54
Profile
Adventurer

Joined: 08 Mar 2010 15:58
Posts: 95
.


Last edited by Yanus on 30 May 2014 22:44, edited 1 time in total.



19 Oct 2013 14:46
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 24 posts ]  Go to page Previous  1, 2, 3  Next

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.