Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-16-2013, 10:45 PM   PM User | #1
joesruddock
New Coder

 
Join Date: Jul 2010
Posts: 56
Thanks: 11
Thanked 0 Times in 0 Posts
joesruddock is an unknown quantity at this point
Javascript blog problem.

Hi all,

Sorry to bother you. I have been really struggling understanding what is probably quite simple. I have been working on BlogSpot coding a theme. Currently, whenever a post is made, on the homepage it gets turned into a 'summary' rather than being shown as a full post. Below is the code which I have identified as handling the task. I have tried changing it and deleting it many times all resulting in the same result - The post is visible but none of the hyperlinked titles or post dates etc show, only the main content. I was hoping if someone could help me solve this so that when I post, a full article is shown on the blog rather than just a summary?

PHP Code:
<script type='text/javascript'>
//<![CDATA[
function removeHtmlTag(strx,chop){
if(
strx.indexOf("<")!=-1)
{
var 
strx.split("<");
for(var 
i=0;i<s.length;i++){
if(
s[i].indexOf(">")!=-1){
s[i] = s[i].substring(s[i].indexOf(">")+1,s[i].length);
}
}
strx s.join("");
}
chop = (chop strx.length-1) ? chop strx.length-2;
while(
strx.charAt(chop-1)!=' ' && strx.indexOf(' ',chop)!=-1chop++;
strx strx.substring(0,chop-1);
return 
strx+'. ';
}
function 
createSummaryAndThumb(pIDpURL,pTITLE){
var 
div document.getElementById(pID);
var 
imgtag "";
var 
img div.getElementsByTagName("img");
var 
summ summary_noimg;
if(
img.length<=1) {
imgtag '<span style="float:left; padding:0px 10px 5px 0px;"><a href="'+pURL+'"><img src="http://2.bp.blogspot.com/-GNUL-jRXlQA/T9J9Vnzbs2I/AAAAAAAADIM/vCpsRcwGbrM/s000/017.jpg" width="'+img_thumb_width+'px"/></a></span>';
summ summary_img;
}
if(
img.length>=1) {
imgtag '<span style="padding:0px 0px 10px 0px;"><a href="'+pURL+'"><img src="'+img[0].src+'" width="'+img_thumb_width+'px"/></a></span>';
summ summary_img;
}
if (
postCount>=1){
if(
img.length<=1) {
imgtag '<span><a href="'+pURL+'"><img src="http://2.bp.blogspot.com/-GNUL-jRXlQA/T9J9Vnzbs2I/AAAAAAAADIM/vCpsRcwGbrM/s000/017.jpg" width="'+img_thumb_width1+'px" height="'+img_thumb_height1+'px"/></a></span>';
summ summary_img1;
}
if(
img.length>=1) {
imgtag '<span><a href="'+pURL+'"><img src="'+img[0].src+'" width="'+img_thumb_width1+'px" height="'+img_thumb_height1+'px"/></a></span>';
summ summary_img1;
}
}
var 
summary imgtag '<div style="text-align:center;">' '<a href="'+pURL+'" style="font-size: 14px;font-weight: normal;line-height: 14px;color:#444751;">' pTITLE '</a>' '</div>' +'<div style="font-size: 13px;font-style: italic;">' removeHtmlTag(div.innerHTML,summ) + '<a href="'+pURL+'" class="morelink">' 'Continue Reading' '</a>' '</div>';
if (
postCount>=1){
var 
summary imgtag '<div style="text-align:center;">' '<a href="'+pURL+'" style="font-size: 14px;font-weight: normal;line-height: 14px;color:#444751;">' pTITLE '</a>' '</div>';
}
div.innerHTML summary;
}
//]]>
</script> 
I hope this makes sense. Thanks very much!
joesruddock is offline   Reply With Quote
Old 01-17-2013, 01:04 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,994 Times in 3,963 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
It makes sense except you haven't said what part of the post you want to *KEEP*.

That code is stripping out *ALL* HTML tags. Is that what you want?

But the code is really really funky.
Code:
if(img.length<=1) 
{ 
    imgtag = '<span style="float:left; padding:0px 10px 5px 0px;">'
           + '<a href="'+pURL+'"><img src=".../017.jpg".../></a></span>'; 
    summ = summary_img; 
} 
if(img.length>=1) 
{ 
    imgtag = '<span style="padding:0px 0px 10px 0px;">'
           + '<a href="'+pURL+'"><img src="'+img[0].src+'" .../></a></span>'; 
    summ = summary_img; 
}
That is *IDIOTIC* code!

If img.length is *exactly* 1 (that is, if there is exactly 1 image within the <div>) then that code will first set imgtag to the one string and then to the other!

And there is similar insanity with the if (postCount>=1) stuff.

On top of that, the code to strip the HTML tags is braindead.

It wouldn't give me much confidence in using this software.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
joesruddock (01-18-2013)
Old 01-17-2013, 01:19 AM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,994 Times in 3,963 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Just to show how UTTERLY BRAINDEAD that code is, try this:
Code:
var txt = "In math, 3 < 5 is true and 10 > 12 is false";
alert( removeHtmlTag( txt, 9999 ) );
using that removeHtmlTag code, as written.

You get an alert of In math, 3 12 is false

The stupid code thinks that "< 5 is true and 10 >" is an HTML tag!!!

*********

Anyway, aside from the code being both braindead and ugly as pig snot, if you don't want to eliminate HTML tags from the blogposts, then you *could* simply change that function to
Code:
function removeHtmlTag( strx, chop ) { return strx; }
If you do want to remove HTML tags, then do it right:
Code:
function removeHtmlTag( strx, chop ) /* ignores chop! */
{
    var re = /\<\/?[a-z][^\>]*\>/ig;
    return strx.replace( re, "" );
}
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
joesruddock (01-18-2013)
Old 01-17-2013, 01:24 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,994 Times in 3,963 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Do note that arbitrarily removing HTML tags can have funny consequences! (Using either their code or mine.)

For example:
Code:
This is a nothing post. <span style="display: none;">This blog owner is a doofus</span>
As written, the stuff in the span doesn't show.

After removing the HTML tags, you get
Code:
This is a nothing post. This blog owner is a doofus
All of this is just really poorly thought out. The blog software *SHOULD* be using a WYSIWYG text editor that does *NOT* allow HTML tags and that, instead, uses pseudo-tags (as does this forum, where we can use [ b] xxx [/ b] tags--without the spaces--to create bold text).

I think I would avoid BlogSpot if it doesn't support something like that!
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
joesruddock (01-18-2013)
Old 01-18-2013, 11:54 AM   PM User | #5
joesruddock
New Coder

 
Join Date: Jul 2010
Posts: 56
Thanks: 11
Thanked 0 Times in 0 Posts
joesruddock is an unknown quantity at this point
Thanks for all your help, it worked perfectly! Agreed, this code is very messy and doesn't help newbies at JS like me The BlogSpot platform the gives no option, they really need to update. They only recently started to allow people to code!
joesruddock is offline   Reply With Quote
Old 04-01-2013, 11:33 PM   PM User | #6
joesruddock
New Coder

 
Join Date: Jul 2010
Posts: 56
Thanks: 11
Thanked 0 Times in 0 Posts
joesruddock is an unknown quantity at this point
Gonna have to blow the dust off this one chaps...

The code now looks like this:
PHP Code:
<script type='text/javascript'>
//<![CDATA[
function removeHtmlTagstrxchop ) { return strx
}
function 
createSummaryAndThumb(pIDpURL,pTITLE){
var 
div document.getElementById(pID);
var 
imgtag "";
var 
img div.getElementsByTagName("img");
var 
summ summary_noimg;
if(
img.length<=1) {
imgtag '<span style="float:left; padding:0px 10px 5px 0px;"><a href="'+pURL+'"><img src="http://2.bp.blogspot.com/-GNUL-jRXlQA/T9J9Vnzbs2I/AAAAAAAADIM/vCpsRcwGbrM/s000/017.jpg" width="'+img_thumb_width+'px"/></a></span>';
summ summary_img;
}
if(
img.length>=1) {
imgtag '<span style="padding:0px 0px 10px 0px;"><a href="'+pURL+'"><img src="'+img[0].src+'" width="'+img_thumb_width+'px"/></a></span>';
summ summary_img;
}
if (
postCount>=1){
if(
img.length<=1) {
imgtag '';
summ summary_img1;
}
if(
img.length>=1) {
imgtag '<span><a href="'+pURL+'"><img src="'+img[0].src+'" width="'+img_thumb_width1+'px" height="'+img_thumb_height1+'px"/></a></span>';
summ summary_img1;
}
}
var 
summary '<div>' '<a href="'+pURL+'" style=" font-family: Droid Serif,arial,serif; font-style: italic; font-weight: normal; font-size: 24px; line-height: 24px; color: #444751;">' pTITLE '</a>' '</div>' +'<div style="margin-top: 10px;">' removeHtmlTag(div.innerHTML,summ) + '<a href="'+pURL+'" class="morelink">' 'Comments' '</a>' '</div>';
if (
postCount>=1){
var 
summary '<div style="text-align:center;">' '<a href="'+pURL+'" style="font-size: 14px;font-weight: normal;line-height: 14px;color:#444751;">' pTITLE '</a>' '</div>';
}
div.innerHTML summary;
}
//]]>
</script> 
The issue is now that the first post shows everything correctly, but any post that followes loses it's title.

Whoever designed this clearly wants to make my life hell... All help appreciated muchly

Joe
joesruddock is offline   Reply With Quote
Old 04-02-2013, 10:15 PM   PM User | #7
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,452
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
are both of these supposed to be true? (they both are when img.length==1)

Code:
if (img.length <= 1) {
if (img.length >= 1) {
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.8% IE9:11.4% IE10:6.5%
rnd me is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:05 PM.


Advertisement
Log in to turn off these ads.