inherit
169267
0
May 3, 2024 11:06:57 GMT -8
Mike
Praise God Almighty!
1,532
July 2011
riccetts
|
Post by Mike on Dec 23, 2017 6:15:50 GMT -8
I've created a plugin and for some reason it just shows up as undefined. Can someone help? My site
|
|
inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on Dec 23, 2017 7:19:52 GMT -8
First fix up the missing script tag on this code...
<script type="text/javascript">
$(document).ready(function() { $('#move-shoutbox').append($('div.shoutbox.container.full')); });
As for your undefined issue. It's because you are trying to run code when the board object doesn't exist.
pb.data('page').board.name
Either check the route then use the board object, or check that board exists before attempting to access any of its props.
|
|
inherit
169267
0
May 3, 2024 11:06:57 GMT -8
Mike
Praise God Almighty!
1,532
July 2011
riccetts
|
Post by Mike on Dec 23, 2017 8:24:37 GMT -8
PeterI'm not sure what you mean about the board object
|
|
inherit
169267
0
May 3, 2024 11:06:57 GMT -8
Mike
Praise God Almighty!
1,532
July 2011
riccetts
|
Post by Mike on Dec 24, 2017 13:15:26 GMT -8
Alright now I made some changes and still I'm getting Undefined Can anybody help? $(document).ready(function(){ var help=pb.plugin.get('closet').settings.settings; for(p=0;p<help.length;p++) { var board=help .board; if(board.length > 0){ for(r=0;r<board.length;r++){ if(pb.data('page').board.id==board[r]){ var text=.tex; var dot=.ad; var pict=.pic; } } } } var bod_man='<div id="shelf">'; bod_man+='<img src="'+pict+'"><a href="'+dot+'" style="font-size:17 px">'+text+'</a>'; bod_man+='</div>'; $('#shelf').html(bod_man); });
|
|
inherit
Official Code Helper
65613
0
1
Apr 15, 2024 17:01:41 GMT -8
Chris
"'Oops' is the sound we make when we improve"
8,870
December 2005
horace
|
Post by Chris on Dec 25, 2017 21:06:34 GMT -8
The error remains
There would be no " board" in pb.data('page') when you are on a page such as the homepage or a profile page, the " board" object is only populated with the characteristics of that board (name, id, etc.) when you are in an actual board otherwise the board object is undefined, this is critical! You have to grasp this concept in order to proceed! You cannot get the "id" from something that is undefined!
|
|
inherit
169267
0
May 3, 2024 11:06:57 GMT -8
Mike
Praise God Almighty!
1,532
July 2011
riccetts
|
Post by Mike on Dec 26, 2017 8:42:41 GMT -8
ChrisI don't understand I used pb.data('page').board.id in other plugin before and it worked.Can you further explain? I'm not grasping it.
|
|
inherit
Official Code Helper
65613
0
1
Apr 15, 2024 17:01:41 GMT -8
Chris
"'Oops' is the sound we make when we improve"
8,870
December 2005
horace
|
Post by Chris on Dec 26, 2017 9:17:42 GMT -8
You're kidding right?
|
|
inherit
169267
0
May 3, 2024 11:06:57 GMT -8
Mike
Praise God Almighty!
1,532
July 2011
riccetts
|
Post by Mike on Dec 26, 2017 9:30:06 GMT -8
ChrisNo man i'm serious How do you define the board?
|
|
#eb7100
33409
0
1
May 3, 2024 16:38:41 GMT -8
Brian
48,129
November 2004
smashmaster3
|
Post by Brian on Dec 26, 2017 9:43:02 GMT -8
You don't. There's no way to forcibly define it. You need to check whether or not it's defined before running any code that handles pb.data('page').board.id.
pb.data('page') always exists, but contains different things depending on the page that you're on. pb.data('page').board and everything within it only exists when you're inside a board.
You can type pb.data('page') in your browser's console to see what exists within the object on that particular page.
|
|
inherit
169267
0
May 3, 2024 11:06:57 GMT -8
Mike
Praise God Almighty!
1,532
July 2011
riccetts
|
Post by Mike on Jan 10, 2018 19:06:22 GMT -8
BrianSorry man for not replying.Thanks for your help
|
|
inherit
169267
0
May 3, 2024 11:06:57 GMT -8
Mike
Praise God Almighty!
1,532
July 2011
riccetts
|
Post by Mike on Feb 26, 2018 10:56:28 GMT -8
Hello, I got this plug-in working right for the most part, it shows up on the board I assign the message but the other board has undefined on it. anyway I can get rid of the undefined from that board?
|
|
#eb7100
33409
0
1
May 3, 2024 16:38:41 GMT -8
Brian
48,129
November 2004
smashmaster3
|
Post by Brian on Feb 26, 2018 13:03:09 GMT -8
mess is returning as undefined because your code only defines it if you're in a board that you've added a message to in the plugin settings. Use an if statement to check if mess exists before adding HTML to the element it's affecting.
While you're at it you should add an if statement around your entire code checking for the existence of pb.data('page').board before running any of your code. It's throwing a bunch of errors on the homepage because it's trying to handle pb.data('page').board.id when it doesn't exist. Realistically your plugin shouldn't error anywhere.
You can press F12 to open your browser's console and check for any Javascript errors thrown by your plugin.
|
|
inherit
169267
0
May 3, 2024 11:06:57 GMT -8
Mike
Praise God Almighty!
1,532
July 2011
riccetts
|
Post by Mike on Feb 26, 2018 13:14:58 GMT -8
Thanks BrianThat works but I think i'm going to use this thread as a ref so I won't ask about this again. Another thing can I use prepend instead of html $('#shelf').html(bod_man); will this take the place of the Place holder div?
|
|
#eb7100
33409
0
1
May 3, 2024 16:38:41 GMT -8
Brian
48,129
November 2004
smashmaster3
|
Post by Brian on Feb 26, 2018 13:21:38 GMT -8
Using html() on an element will replace the entirety of its inner HTML with what you specify. api.jquery.com/html/Using prepend() will add whatever HTML you specify to the beginning of the element's existing inner HTML. api.jquery.com/prepend/
|
|
inherit
169267
0
May 3, 2024 11:06:57 GMT -8
Mike
Praise God Almighty!
1,532
July 2011
riccetts
|
Post by Mike on Feb 26, 2018 13:46:01 GMT -8
|
|