Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jul 2010
    Posts
    66
    Thanks
    11
    Thanked 0 Times in 0 Posts

    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!

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,216
    Thanks
    75
    Thanked 4,344 Times in 4,310 Posts
    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.

  • Users who have thanked Old Pedant for this post:

    joesruddock (01-18-2013)

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,216
    Thanks
    75
    Thanked 4,344 Times in 4,310 Posts
    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.

  • Users who have thanked Old Pedant for this post:

    joesruddock (01-18-2013)

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,216
    Thanks
    75
    Thanked 4,344 Times in 4,310 Posts
    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.

  • Users who have thanked Old Pedant for this post:

    joesruddock (01-18-2013)

  • #5
    New Coder
    Join Date
    Jul 2010
    Posts
    66
    Thanks
    11
    Thanked 0 Times in 0 Posts
    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!

  • #6
    New Coder
    Join Date
    Jul 2010
    Posts
    66
    Thanks
    11
    Thanked 0 Times in 0 Posts
    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

  • #7
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,302
    Thanks
    10
    Thanked 586 Times in 567 Posts
    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 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •