inherit
153968
0
Nov 19, 2012 15:03:05 GMT -8
Thesealion
New Phone Who Dis?
4,124
April 2010
joemaggio
|
Post by Thesealion on Nov 19, 2012 19:20:00 GMT -8
This code is supposed to remove the "edited by" line in posts when the user who last edited was staff. I thought I could figure out how to do it.....4 hours later I realize I am in way over my head Basically, I can get it to check if the user is on the list, but then I can't get it to only hide the "edited by" in those posts and not in the others. I am also having trouble because when it checks the "edited by" class it only looks at the first one on the page and I need it to check them all. I am sure this is just a simple loop that i need to add...but i haven't gotten that far yet I have a few versions that sorta work so bear with me: This one, I know that the style.display thing doesn't work now...i was just messing with things $(document).ready(function() { if($("div").hasClass("edited_by")) { var mod = $(".edited_by") var stod = $(mod).html() alert(stod); if(stod.match("user_1")) { $(mod).hide(); } } }); I think this one is closest to what I want...but like I said I am not the best coder and am relearning a lot of this so I need someone better to glance it over. $(document).ready(function() { if($("div").hasClass("edited_by")) { var mod = $(".edited_by").html().match("user_1"); if(mod.match("user_1")) { $(mod).hide } } }); Lastly: $(document).ready(function() { if($("div").hasClass("edited_by")) { var mod = $(".edited_by") var stod = $(mod).html() alert(stod); if(stod.match("user_1")) { $(mod).hide(); } } });
|
|
inherit
153968
0
Nov 19, 2012 15:03:05 GMT -8
Thesealion
New Phone Who Dis?
4,124
April 2010
joemaggio
|
Post by Thesealion on Nov 20, 2012 13:35:39 GMT -8
Here is the original code I was trying to copy... <script type="text/javascript"> <!-- /* remove last edit */ var font=document.getElementsByTagName("font"); if(location.href.match(/on=(displ|search2|(user)?rece)/)){ for(i=0;i<font.length;i++){ if(font.innerHTML.match(/Last\sEdit:/i) && font.parentNode.align=="left" && font.innerHTML.match(/user=admin/i)){ font.style.display="none"; } } } // --> </script> I did another try at it but firebug is giving me the error "Uncaught TypeError: Cannot call method 'match' of undefined" Don't really understand it and it's sorta driving me crazy $(document).ready(function() { if($("div").hasClass("edited_by")) { var mod = $(".edited_by") for(i=0;i<mod.length;i++){ if(mod.innerHTML.match(/1/)) { $(mod).hide(); } } } });
|
|
inherit
153968
0
Nov 19, 2012 15:03:05 GMT -8
Thesealion
New Phone Who Dis?
4,124
April 2010
joemaggio
|
Post by Thesealion on Nov 23, 2012 6:56:26 GMT -8
little bump...
Anyone have any helpful words?
|
|
inherit
118095
0
Feb 25, 2021 0:36:17 GMT -8
Rosefriend
Friendship is the Finest Rose in the Garden of Life
1,855
January 2008
rosefriend
|
Post by Rosefriend on Nov 23, 2012 7:00:54 GMT -8
|
|
inherit
153968
0
Nov 19, 2012 15:03:05 GMT -8
Thesealion
New Phone Who Dis?
4,124
April 2010
joemaggio
|
Post by Thesealion on Nov 23, 2012 7:05:09 GMT -8
Yea, I was trying to take a code like that and make it only hide if a staff member is the one who edited...
|
|
#00AF33
14306
0
1
Sept 8, 2023 8:54:17 GMT -8
Jordan
What is truth?
11,838
October 2003
jab2
|
Post by Jordan on Nov 23, 2012 14:20:18 GMT -8
You need to use the JQuery each() method. api.jquery.com/jQuery.each/Feel free to look at all my plugins as they are editable so you can easily see the code. One thing you need to realize is that the JQuery object contains an array of objects. So, $('div') would match all the divs on the page and retain an array of references to all of them. If you wanted to set all their background's to red, you'd do: $('div').each(function() { $(this).css('background-color','red'); // $(this) refers to the current <div> } When you call .hasClass('edited_by'), you are simply looking through that array of divs for the ones that have that class, but there could still be more than 1 in there.
|
|
inherit
153968
0
Nov 19, 2012 15:03:05 GMT -8
Thesealion
New Phone Who Dis?
4,124
April 2010
joemaggio
|
Post by Thesealion on Nov 23, 2012 19:38:39 GMT -8
Ok thanks Jordan. That makes a lot of sense. I just need to get some sleep and then come back tomorrow and knock this out... I think i might understand it better then....if not hopefully you can help me straiten it out a bit. This is actually the first time i have written in jQueary and it's been forever since i even used JS so i am still relearning/learning a lot
|
|
#00AF33
14306
0
1
Sept 8, 2023 8:54:17 GMT -8
Jordan
What is truth?
11,838
October 2003
jab2
|
Post by Jordan on Nov 23, 2012 19:41:18 GMT -8
Sounds good. I am planning on making a video for the plugin system as well as for JQuery. I'm just thinking about covering the basics and showing people how to get started with v5 because once you know how things work it's very easy.
|
|
inherit
153968
0
Nov 19, 2012 15:03:05 GMT -8
Thesealion
New Phone Who Dis?
4,124
April 2010
joemaggio
|
Post by Thesealion on Nov 23, 2012 19:43:53 GMT -8
I do have a question about your last comment. When you say .hasClass('edited_by') it is looking through the array for the div with that class right? You're saying it does not get rid of the ones that don't have that class? Or it does? Sorry....i should sleep
|
|
#00AF33
14306
0
1
Sept 8, 2023 8:54:17 GMT -8
Jordan
What is truth?
11,838
October 2003
jab2
|
Post by Jordan on Nov 23, 2012 19:55:57 GMT -8
Yes, but it is looking through all the divs so it could return more than one div. If all of the divs had that class it would return all of them. It will get rid of the divs that do not have that class in the fact that it is returning yet another JQuery object with only the divs with the class 'edited_by'. The $('div') still contains all the divs, but when you call .hasClass('edited_by'), you are getting another JQuery object with only the divs with 'edited_by'. Someone ( Peter) correct me if JQuery is doing things differently internally. It doesn't really matter how it is being done, just know that it is happening.
|
|
inherit
153968
0
Nov 19, 2012 15:03:05 GMT -8
Thesealion
New Phone Who Dis?
4,124
April 2010
joemaggio
|
Post by Thesealion on Nov 23, 2012 20:06:53 GMT -8
Ok so when i say: if($("div").hasClass("edited_by")) { I should only wind up with the edited by divs right? Which is what i want...then i just have to rule out the ones that don't have the ID's of the staff in them right? BTW: Think i sorta understand the each() thing....that's gonna make things much easier
|
|
#00AF33
14306
0
1
Sept 8, 2023 8:54:17 GMT -8
Jordan
What is truth?
11,838
October 2003
jab2
|
Post by Jordan on Nov 23, 2012 20:13:30 GMT -8
Yeah, it'll be something like...
var staff_ids = /^id1|id2$/i; $('div').hasClass('edited_by').each(function() { var staff_id = $(this).find('a').hasClass('user-link').attr('title').replace(/@/i,''); if(staff_ids.test(staff_id)) { // Do your stuff } });
I prefer this syntax, though.
var staff_ids = /^id1|id2$/i; $('div.edited_by').each(function() { var staff_id = $(this).find('a.user-link').attr('title').replace(/@/i,''); if(staff_ids.test(staff_id)) { // Do your stuff } });
Just think of each() as your good old for loop from the v4 days of Proboards.
|
|
inherit
153968
0
Nov 19, 2012 15:03:05 GMT -8
Thesealion
New Phone Who Dis?
4,124
April 2010
joemaggio
|
Post by Thesealion on Nov 23, 2012 20:24:17 GMT -8
Ok....I will finish this tomorrow...Thanks a million dude
|
|
#00AF33
14306
0
1
Sept 8, 2023 8:54:17 GMT -8
Jordan
What is truth?
11,838
October 2003
jab2
|
Post by Jordan on Nov 23, 2012 20:26:01 GMT -8
No problem, let me know if you have anymore questions.
|
|
inherit
153968
0
Nov 19, 2012 15:03:05 GMT -8
Thesealion
New Phone Who Dis?
4,124
April 2010
joemaggio
|
Post by Thesealion on Nov 24, 2012 7:31:55 GMT -8
Well it's looking like I don't totally understand this yet I am pretty sure the one line i added isn't right, but i can't even test it cause I am not getting past the function line... Here's what I got: (I am getting the firebug error Uncaught TypeError: Object true has no method 'each') $(document).ready(function() { var staff_ids = /^test$/i; $('div').hasClass('edited_by').each(function() { var staff_id = $(this).find('a').hasClass('user-link').attr('title').replace(/@/i,''); if(staff_ids.test(staff_id)) { $(this).hide(); } }); }); EDIT:Ok so I think i got something...i changed that line to $('.edited_by').each(function() { and it works...so can we only have one .action after the class thing? Cause now it is caught on the staff_id line... $(document).ready(function() { var staff_ids = /^test$/i; $('.edited_by').each(function() { alert('test'); var staff_id = $(this).find('a').hasClass('user-link').attr('title').replace(/@/i,''); if(staff_ids.test(staff_id)) { $(this).hide(); } }); });
|
|