inherit
173855
0
Apr 23, 2024 9:59:44 GMT -8
Texas
I check in every once in a while...
869
November 2011
petermaggio
|
Post by Texas on Jun 3, 2013 6:51:03 GMT -8
Okay, so I created a plugin that will change @(displayname) (minus the parentheses of course) to @(username). The way the plugin works is it caches all the displaynames with there corresponding username. I was having problems with special characters so I made the code replace any characters that didn't match the RegExp /[^a-zA-Z0-9\s-_~* ]/g Which seems to solve the problem. However, I would like a little more experienced developer then I to look it over for any obvious problems before I submit it to the ProBoards library. Dowload
|
|
inherit
The Dream Crusher (Ret.)
164921
0
Apr 1, 2014 11:00:25 GMT -8
Tim Camara
Teach a man to fish, etc., etc.
1,721
March 2011
tcamara
|
Post by Tim Camara on Jun 3, 2013 14:27:36 GMT -8
Link's busted.
|
|
inherit
173855
0
Apr 23, 2024 9:59:44 GMT -8
Texas
I check in every once in a while...
869
November 2011
petermaggio
|
Post by Texas on Jun 4, 2013 4:44:29 GMT -8
Fixed, why can't links just read you mind and go to wherever you want them too.
|
|
inherit
173855
0
Apr 23, 2024 9:59:44 GMT -8
Texas
I check in every once in a while...
869
November 2011
petermaggio
|
Post by Texas on Jun 5, 2013 7:24:34 GMT -8
bump
|
|
inherit
The Dream Crusher (Ret.)
164921
0
Apr 1, 2014 11:00:25 GMT -8
Tim Camara
Teach a man to fish, etc., etc.
1,721
March 2011
tcamara
|
Post by Tim Camara on Jun 5, 2013 8:33:41 GMT -8
Looks fine. The only thing I would suggest is seeing if you can find a way to use the user's group color. I'm not all that familiar with using localstorage, what are the chances that a large thread with a bunch of tags will slow down the page?
|
|
inherit
173855
0
Apr 23, 2024 9:59:44 GMT -8
Texas
I check in every once in a while...
869
November 2011
petermaggio
|
Post by Texas on Jun 5, 2013 8:43:34 GMT -8
Maybe slightly. But I looked into that and I don't think it should. I had the smangii test it on his board for me and it didn't seem to affect anything. What I worried about when I first made the code was whether it would be able to loop through all the cached usernames and displaynames on every keystroke. So I did a little research and found enough information to satisfy me that it shouldn't be a problem.
And I'm not to sure what you mean by using the groups color. What would I be using it for?
|
|
inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on Jun 6, 2013 2:41:42 GMT -8
Not sure I get why you are using localStorage. Unless you plan on doing something later with it, then I wouldn't bother trying to cache them. I would look more into improving the performance of your script.
Why do you need to remove special characters? Just safely inject it back in to the link as a text node.
Your plugin loops over all links on a page, and on every page. I would do a location check (proboards.data("route").name) to limit it to threads, private messages, recent posts etc etc.
<a title="@admin" itemprop="url" class="user-link user-1 group-1" href="/user/1"><span itemprop="name">Peter</span></a>
Target these links specifically. You are using jQuery, I would recommend reading up on selectors if you aren't familiar with them, as then you will only be grapping a handful of links, though make sure the context is the "message" if your intention is not to change the link in the mini profile.
|
|
inherit
173855
0
Apr 23, 2024 9:59:44 GMT -8
Texas
I check in every once in a while...
869
November 2011
petermaggio
|
Post by Texas on Jun 6, 2013 5:10:55 GMT -8
I don't think I explained how this works properly. The code goes through and caches everyone's username and displayname. That way, while your typing, on every keystroke it goes through the localStorage and checks the text you are typing to see if any of the text matches @(someonesdisplayname) (plus a space). If it does, it will replace that text with the @(username) that goes with the displayname. So that's why I'm using localStorage to cache everything. (I didn't want to use a key but it would be trivial to add that if it's a better option.)
I tried just getting the text $('item').text() and then pushing that into the localStorage. But for some reason the special characters were messing with something so that if you typed at all. Then it would write hundreds of @(someone's username) in the quick reply and overload your browser. I tried encoding the displayname with encodeURIcompontent() before I added it to the cache, and then decoding it to check if it matched the textarea. But that didn't seem to work at all. The first couple ones cached would work fine. But after that, the first couple would still work, but the twentieth or so and after wouldn't.
I started out using the '.user-link' selector but then entirely rewrote the code. I guess I just forgot to use it again. But there's definitely no reason to be looping through all the links. I'll change that.
I also thought I only had it running on the main page and posting page but I guess that was something I forgot to add on the rewrite also.
|
|