CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   Javascript blog problem. (http://www.codingforums.com/showthread.php?t=285906)

joesruddock 01-16-2013 10:45 PM

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!

Old Pedant 01-17-2013 01:04 AM

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.

Old Pedant 01-17-2013 01:19 AM

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, "" );
}


Old Pedant 01-17-2013 01:24 AM

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!

joesruddock 01-18-2013 11:54 AM

Thanks for all your help, it worked perfectly! Agreed, this code is very messy and doesn't help newbies at JS like me :D The BlogSpot platform the gives no option, they really need to update. They only recently started to allow people to code!

joesruddock 04-01-2013 11:33 PM

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 :D

Joe

rnd me 04-02-2013 10:15 PM

are both of these supposed to be true? (they both are when img.length==1)

Code:

if (img.length <= 1) {
if (img.length >= 1) {



All times are GMT +1. The time now is 09:34 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.