inherit
229600
0
Sept 7, 2022 11:09:51 GMT -8
Ben Goodman
96
February 2016
benhun
|
Post by Ben Goodman on May 25, 2018 1:45:51 GMT -8
Maybe an if checking that the message contents are the same?
|
|
inherit
140147
0
May 15, 2024 5:30:22 GMT -8
Nscalerr 🐺
Throw me to the wolves and I'll return leading the pack!
3,008
May 2009
nscalerr
|
Post by Nscalerr 🐺 on May 26, 2018 9:06:18 GMT -8
Not sure what you could search on, since I don't think the contents would be stored anywhere, except in the post itself.
|
|
inherit
229600
0
Sept 7, 2022 11:09:51 GMT -8
Ben Goodman
96
February 2016
benhun
|
Post by Ben Goodman on May 28, 2018 1:21:08 GMT -8
|
|
#00AF33
Official Code Helper
19529
0
1
Nov 19, 2012 14:18:28 GMT -8
Todge
**
17,290
January 2004
todge
|
Post by Todge on May 28, 2018 3:14:27 GMT -8
I'm really not sure what you're trying to achieve, and the way you're going about it is not the way I would.. I've only just realised that the JS script is being included in the theme layout and is including the theme elements to target aspects of the mini-profile.. Very possible, but you will run into issues because the script will multiple times, hence the multiple posts being displayed. It would be better if the script part at least was moved into a plugin, that would only be run once, when the screen was loaded... But I'll try. Maybe an if checking that the message contents are the same? Not sure what you could search on, since I don't think the contents would be stored anywhere, except in the post itself. Both of the above quotes are true, but a JS script can only work with what is currently on the screen, it cannot see the posts that are not displayed, so I'm unsure of what the issue is here.. And rather that comparing post content.. Each post has an ID, it may be better to use that to check to see if any post has already been included in your list.
|
|
inherit
140147
0
May 15, 2024 5:30:22 GMT -8
Nscalerr 🐺
Throw me to the wolves and I'll return leading the pack!
3,008
May 2009
nscalerr
|
Post by Nscalerr 🐺 on May 28, 2018 3:22:00 GMT -8
I was begining to think a plugin, (for the script) was the way to go, rather than having it in the templates and running multiple times.
|
|
#00AF33
Official Code Helper
19529
0
1
Nov 19, 2012 14:18:28 GMT -8
Todge
**
17,290
January 2004
todge
|
Post by Todge on May 28, 2018 3:27:39 GMT -8
I was begining to think a plugin, (for the script) was the way to go, rather than having it in the templates and running multiple times. I'm sure you'd find it better in the long run. You can still use the theme layout to add the <div> you want the posts listed into etc. to make things a little less tedious if you prefer.
|
|
inherit
229600
0
Sept 7, 2022 11:09:51 GMT -8
Ben Goodman
96
February 2016
benhun
|
Post by Ben Goodman on May 29, 2018 6:27:12 GMT -8
Todge this is what I am trying to achieve. As I imagined, when I click on the button, the div appaers with the post content in it. But for some reason, it appaears 3 times.
|
|
#00AF33
Official Code Helper
19529
0
1
Nov 19, 2012 14:18:28 GMT -8
Todge
**
17,290
January 2004
todge
|
Post by Todge on May 29, 2018 12:15:30 GMT -8
Todge this is what I am trying to achieve. As I imagined, when I click on the button, the div appaers with the post content in it. But for some reason, it appaears 3 times. So you want each post that contains a <div> to be displayed in the sidebox? Nscalerr 🐺, how are you doing converting this to a plugin?
|
|
inherit
229600
0
Sept 7, 2022 11:09:51 GMT -8
Ben Goodman
96
February 2016
benhun
|
Post by Ben Goodman on May 29, 2018 12:46:17 GMT -8
yes, thats what I want.
|
|
inherit
140147
0
May 15, 2024 5:30:22 GMT -8
Nscalerr 🐺
Throw me to the wolves and I'll return leading the pack!
3,008
May 2009
nscalerr
|
Post by Nscalerr 🐺 on May 29, 2018 20:03:18 GMT -8
Not very well, beginning to think a key might be needed before it will pick up what is in a post.
I know nothing about using keys, or how to add them.
Otherwise things are going fairly well with it.
Something to close the window would be nice too.
|
|
#00AF33
Official Code Helper
19529
0
1
Nov 19, 2012 14:18:28 GMT -8
Todge
**
17,290
January 2004
todge
|
Post by Todge on May 30, 2018 8:11:13 GMT -8
You will not need a key. All the info you need to should be on the current page, so there's no storage required.
Start off by putting the cell you want the posts displayed in, and the button, directly into the layout. That will mean you'll have no issues trying to add them to the page with the script.
The rest should be pretty close to what you did before.. Create a function that will be triggered with th button is clicked on.. Search for the posts and copy the contents into the new cell.
|
|
inherit
140147
0
May 15, 2024 5:30:22 GMT -8
Nscalerr 🐺
Throw me to the wolves and I'll return leading the pack!
3,008
May 2009
nscalerr
|
Post by Nscalerr 🐺 on May 31, 2018 1:52:56 GMT -8
Ok, so $[post], $[post.created_by] and $[post.message] don't work in a plugin, so I need to come up with another way of doing it, which I think needs to be a $.get() for the contents of the new cell.
|
|
#00AF33
Official Code Helper
19529
0
1
Nov 19, 2012 14:18:28 GMT -8
Todge
**
17,290
January 2004
todge
|
Post by Todge on May 31, 2018 13:42:06 GMT -8
Ok, so $[post], $[post.created_by] and $[post.message] don't work in a plugin, so I need to come up with another way of doing it, which I think needs to be a $.get() for the contents of the new cell. the way you can search for posts was mentioned before.. $('.message') will target all posts currently displayed on the page, and you can cycle through them with the '.each()' method.. So, to find each post you could use... $('.message').each(function(){
// Code to check content for <div> tags and copy content to new cell if they exist...
});
|
|
inherit
140147
0
May 15, 2024 5:30:22 GMT -8
Nscalerr 🐺
Throw me to the wolves and I'll return leading the pack!
3,008
May 2009
nscalerr
|
Post by Nscalerr 🐺 on Jun 1, 2018 6:41:12 GMT -8
Plugin is almost there. Just need to work out the changes needed for the two var lines.
$(document).ready(function(){ function my_code() { $('.message').each(function(){ if($(this).find('div').length > 0) { var div = $('<div>$[post] $[post.created_by]:<br /><br /><br />$[post.message]</div>').attr('id','side-post').addClass('post-list'); $('#post_list').append(div); } else { var div = $('<div>$[post] $[post.created_by]:<br /><br /><br />$[post.message]</div>').attr('id','side-post').addClass('post-list'); $('#post_list').append(div); } }); }; $('#run_code').click(function(){ my_code(); }); });
|
|
#00AF33
Official Code Helper
19529
0
1
Nov 19, 2012 14:18:28 GMT -8
Todge
**
17,290
January 2004
todge
|
Post by Todge on Jun 1, 2018 14:35:02 GMT -8
Plugin is almost there. Just need to work out the changes needed for the two var lines. $(document).ready(function(){ function my_code() { $('.message').each(function(){ if($(this).find('div').length > 0) { var div = $('<div>$[post] $[post.created_by]:<br /><br /><br />$[post.message]</div>').attr('id','side-post').addClass('post-list'); $('#post_list').append(div); } else { var div = $('<div>$[post] $[post.created_by]:<br /><br /><br />$[post.message]</div>').attr('id','side-post').addClass('post-list'); $('#post_list').append(div); } }); }; $('#run_code').click(function(){ my_code(); }); }); $('<div>$[post] $[post.created_by]:<br /><br /><br />$[post.message]</div>') is not recognisable JS.. It is a mixture of JS and PBs layout elements.. $('<div></div>') creates the <div>, to add content you use html(). Yoy can also use html() to target the content of a cell, so... var cell_content = $(this).html() would add the posts content to the cell_content variable.. you can then use.. $('<div></div>').html(cell_content) to create a <div> cell containg an copy of the posts' content.
|
|