Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Converting/Creating Blocks
Author Message
hicuxunicorniobestbuildpc
The Mouse Is Extension Of Arm



Joined: Aug 13, 2009
Posts: 1123

PostPosted: Sun Oct 13, 2013 12:11 pm Reply with quote

Very Happy Guys! I've been taking the time to look into my old HDD I still have and I found this genuine old Moon Phase but unfortunately it doesn't work. Any suggestion or help will be nice from u.

Code:
<?php



if (!defined('BLOCK_FILE')) {Header('Location: ../index.php');  die();}

$content = '<div align="center"><br />';
$content .= '<script type="text/javascript">
    var currentDate  = new Date()
    currentDate.setTime(currentDate.getTime() + (currentDate.getTimezoneOffset()*60000))
    var blueMoonDate = new Date(96, 1, 3, 16, 15, 0)
    var lunarPeriod  = 29*(24*3600*1000) + 12*(3600*1000) + 44.05*(60*1000)
    var moonPhaseTime = (currentDate.getTime() - blueMoonDate.getTime()) % lunarPeriod
    var percentRaw = (moonPhaseTime / lunarPeriod)
    var llena = Math.round(200*percentRaw)
    if (llena > 100) {
   llena = llena - 100
    }
    if (percentRaw > 0.5) {
   if (llena == 100) {
       document.write("<img src="images/moon/moon20.gif" border="0" alt="" />");
   }
   if (llena >= 0 && llena < 11) {
       document.write("<img src="images/moon/moon20.gif" border="0" alt="" />");
   } else if (llena > 9 && llena < 21) {
       document.write("<img src="images/moon/moon1.gif" border="0" alt="" />");
   } else if (llena > 19 && llena < 31) {
       document.write("<img src="images/moon/moon2.gif" border="0" alt="" />");
        } else if (llena > 29 && llena < 41) {
       document.write("<img src="images/moon/moon3.gif" border="0" alt="" />");
   } else if (llena > 39 && llena < 51) {
       document.write("<img src="images/moon/moon4.gif" border="0" alt="" />");
   } else if (llena > 49 && llena < 61) {
       document.write("<img src="images/moon/moon5.gif" border="0" alt="" />");
        } else if (llena > 59 && llena < 71) {
       document.write("<img src="images/moon/moon6.gif" border="0" alt="" />");
   } else if (llena > 69 && llena < 81) {
       document.write("<img src="images/moon/moon7.gif" border="0" alt="" />");
   } else if (llena > 79 && llena < 91) {
       document.write("<img src="images/moon/moon8.gif" border="0" alt="" />");
   } else if (llena > 89 && llena <= 99) {
       document.write("<img src="images/moon/moon9.gif" border="0" alt="" />");
   }
    } else if (percentRaw < 0.5) {
   if (llena == 100) {
       document.write("<img src="images/moon/moon10.gif" border="0" alt="" alt="" />");
   }
   if (llena >= 0 && llena < 11) {
       document.write("<img src="images/moon/moon10.gif" border="0" alt="" />");
   } else if (llena > 9 && llena < 21) {
       document.write("<img src="images/moon/moon11.gif" border="0"  alt="" />");
   } else if (llena > 19 && llena < 31) {
       document.write("<img src="images/moon/moon12.gif" border="0" alt="" />");
   } else if (llena > 29 && llena < 41) {
       document.write("<img src="images/moon/moon13.gif" border="0" alt="" />");
   } else if (llena > 39 && llena < 51) {
           document.write("<img src="images/moon/moon14.gif" border="0" alt="" />");
   } else if (llena > 49 && llena < 61) {
       document.write("<img src="images/moon/moon15.gif" border="0" alt="" />");
   } else if (llena > 59 && llena < 71) {
       document.write("<img src="images/moon/moon16.gif" border="0" alt="" />");
   } else if (llena > 69 && llena < 81) {
       document.write("<img src="images/moon/moon17.gif" border="0" alt="" />");
   } else if (llena > 79 && llena < 91) {
       document.write("<img src="images/moon/moon18.gif" border="0" alt="" />");
   } else if (llena > 89 && llena <= 99) {
       document.write("<img src="images/moon/moon19.gif" border="0" alt="" />");
   }
    }</script>
';
$content .= '</div><br />';
 
View user's profile Send private message
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Mon Oct 14, 2013 7:18 am Reply with quote

hicuxunicorniobestbuildpc, we're not going to just go create this and see what it does... Wink Please elaborate on "it doesn't work"... tell us what is happening...

_________________
Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
hicuxunicorniobestbuildpc







PostPosted: Tue Oct 15, 2013 4:52 pm Reply with quote

I am actually getting a blank block. I don't understand why it doesn't work Montego. I don't get any error.
 
spasticdonkey
RavenNuke(tm) Development Team



Joined: Dec 02, 2006
Posts: 1693
Location: Texas, USA

PostPosted: Tue Oct 15, 2013 7:23 pm Reply with quote

I surprised it ever worked like that. You shouldn't be using document.write at this point in history, but even if you were there are a ton of un-escaped double quotes within the uses of document.write.

this (and all other uses of document.write)
document.write("<img src="images/moon/moon20.gif" border="0" alt="" />");
should be done as
document.write("<img src=\"images/moon/moon20.gif\" border=\"0\" alt=\"\" />");
or you could write as
document.write('<img src="images/moon/moon20.gif" border="0" alt="" />');
but since you are also working within a single quoted string in PHP, the single quotes would need to be escaped
document.write(\'<img src="images/moon/moon20.gif" border="0" alt="" />\');

you get plenty of errors, just not php ones since it is written in JavaScript. Use firebug for firefox or Chrome and it's built in debugging capability.

or even better update to use jquery, and change
<div align="center"> to <div class="moon">

and update all uses of document.write to use jquery html()
$( "div.moon" ).html( "<img src=\"images/moon/moon20.gif\" border=\"0\" alt=\"\" />" );

then add any styling needed via CSS
.moon{text-align:center;margin 10px auto;}

One way JavaScript and PHP are the same, if using a single quoted string escape single quotes, or double quoted string escape double quotes....
 
View user's profile Send private message Visit poster's website
hicuxunicorniobestbuildpc







PostPosted: Wed Oct 16, 2013 4:37 am Reply with quote

It is working properly now. Very Happy Thanks a lot spastic.

Code:
<?php



if (!defined('BLOCK_FILE')) {Header('Location: ../index.php');  die();}

//$content = '<div align="center"><br />';
$content = '<div class="moon"><br />';
$content .= '<script type="text/javascript">
    var currentDate  = new Date()
    currentDate.setTime(currentDate.getTime() + (currentDate.getTimezoneOffset()*60000))
    var blueMoonDate = new Date(96, 1, 3, 16, 15, 0)
    var lunarPeriod  = 29*(24*3600*1000) + 12*(3600*1000) + 44.05*(60*1000)
    var moonPhaseTime = (currentDate.getTime() - blueMoonDate.getTime()) % lunarPeriod
    var percentRaw = (moonPhaseTime / lunarPeriod)
    var llena = Math.round(200*percentRaw)
    if (llena > 100) {
   llena = llena - 100
    }
    if (percentRaw > 0.5) {
   if (llena == 100) {
       document.write(\'<img src="images/moon/moon20.gif" border="0" alt="" />\');
   }
   if (llena >= 0 && llena < 11) {
       document.write(\'<img src="images/moon/moon20.gif" border="0" alt="" />\');
   } else if (llena > 9 && llena < 21) {
       document.write(\'<img src="images/moon/moon1.gif" border="0" alt="" />\');
   } else if (llena > 19 && llena < 31) {
       document.write(\'<img src="images/moon/moon2.gif" border="0" alt="" />\');
        } else if (llena > 29 && llena < 41) {
       document.write(\'<img src="images/moon/moon3.gif" border="0" alt="" />\');
   } else if (llena > 39 && llena < 51) {
       document.write(\'<img src="images/moon/moon4.gif" border="0" alt="" />\');
   } else if (llena > 49 && llena < 61) {
       document.write(\'<img src="images/moon/moon5.gif" border="0" alt="" />\');
        } else if (llena > 59 && llena < 71) {
       document.write(\'<img src="images/moon/moon6.gif" border="0" alt="" />\');
   } else if (llena > 69 && llena < 81) {
       document.write(\'<img src="images/moon/moon7.gif" border="0" alt="" />\');
   } else if (llena > 79 && llena < 91) {
       document.write(\'<img src="images/moon/moon8.gif" border="0" alt="" />\');
   } else if (llena > 89 && llena <= 99) {
       document.write(\'<img src="images/moon/moon9.gif" border="0" alt="" />\');
   }
    } else if (percentRaw < 0.5) {
   if (llena == 100) {
       document.write(\'<img src="images/moon/moon10.gif" border="0" alt="" />\');
   }
   if (llena >= 0 && llena < 11) {
       document.write(\'<img src="images/moon/moon10.gif" border="0" alt="" />\');
   } else if (llena > 9 && llena < 21) {
       document.write(\'<img src="images/moon/moon11.gif" border="0" alt="" />\');
   } else if (llena > 19 && llena < 31) {
       document.write(\'<img src="images/moon/moon12.gif" border="0" alt="" />\');
   } else if (llena > 29 && llena < 41) {
       document.write(\'<img src="images/moon/moon13.gif" border="0" alt="" />\');
   } else if (llena > 39 && llena < 51) {
           document.write(\'<img src="images/moon/moon14.gif" border="0" alt="" />\');
   } else if (llena > 49 && llena < 61) {
       document.write(\'<img src="images/moon/moon15.gif" border="0" alt="" />\');
   } else if (llena > 59 && llena < 71) {
       document.write(\'<img src="images/moon/moon16.gif" border="0" alt="" />\');
   } else if (llena > 69 && llena < 81) {
       document.write(\'<img src="images/moon/moon17.gif" border="0" alt="" />\');
   } else if (llena > 79 && llena < 91) {
       document.write(\'<img src="images/moon/moon18.gif" border="0" alt="" />\');
   } else if (llena > 89 && llena <= 99) {
       document.write(\'<img src="images/moon/moon19.gif" border="0" alt="" />\');
   }
    }</script>
';
$content .= '</div><br />';


Last edited by hicuxunicorniobestbuildpc on Wed Oct 16, 2013 10:55 am; edited 1 time in total 
spasticdonkey







PostPosted: Wed Oct 16, 2013 5:15 am Reply with quote

If you are have more than one ancient block using document.write they might be conflicting.

Do you have the images in their proper place?
 
hicuxunicorniobestbuildpc







PostPosted: Thu Oct 17, 2013 6:44 am Reply with quote

hi spasticdonkey.

I am getting a validation warning error like document type does not allow element "img" her

http://validator.w3.org/check?uri=http%3a%2f%2fwww.bestbuildpc.org%2f. What should I do then?
 
spasticdonkey







PostPosted: Thu Oct 17, 2013 6:54 am Reply with quote

you need to wrap it in cdata or convert the script to an external js file
http://en.wikipedia.org/wiki/CDATA#Use_of_CDATA_in_program_output
 
hicuxunicorniobestbuildpc







PostPosted: Thu Oct 17, 2013 3:48 pm Reply with quote

Thanks a lot!!! U are right!!! Very Happy

Code:
<?php



if (!defined('BLOCK_FILE')) {Header('Location: ../index.php');  die();}

//$content = '<div align="center"><br />';
$content = '<div class="moon"><br />';
$content .= '<script type="text/javascript">
//<![CDATA[
    var currentDate  = new Date()
    currentDate.setTime(currentDate.getTime() + (currentDate.getTimezoneOffset()*60000))
    var blueMoonDate = new Date(96, 1, 3, 16, 15, 0)
    var lunarPeriod  = 29*(24*3600*1000) + 12*(3600*1000) + 44.05*(60*1000)
    var moonPhaseTime = (currentDate.getTime() - blueMoonDate.getTime()) % lunarPeriod
    var percentRaw = (moonPhaseTime / lunarPeriod)
    var llena = Math.round(200*percentRaw)
    if (llena > 100) {
   llena = llena - 100
    }
    if (percentRaw > 0.5) {
   if (llena == 100) {
       document.write(\'<img src="images/moon/moon20.gif" border="0" alt="" />\');
   }
   if (llena >= 0 && llena < 11) {
       document.write(\'<img src="images/moon/moon20.gif" border="0" alt="" />\');
   } else if (llena > 9 && llena < 21) {
       document.write(\'<img src="images/moon/moon1.gif" border="0" alt="" />\');
   } else if (llena > 19 && llena < 31) {
       document.write(\'<img src="images/moon/moon2.gif" border="0" alt="" />\');
        } else if (llena > 29 && llena < 41) {
       document.write(\'<img src="images/moon/moon3.gif" border="0" alt="" />\');
   } else if (llena > 39 && llena < 51) {
       document.write(\'<img src="images/moon/moon4.gif" border="0" alt="" />\');
   } else if (llena > 49 && llena < 61) {
       document.write(\'<img src="images/moon/moon5.gif" border="0" alt="" />\');
        } else if (llena > 59 && llena < 71) {
       document.write(\'<img src="images/moon/moon6.gif" border="0" alt="" />\');
   } else if (llena > 69 && llena < 81) {
       document.write(\'<img src="images/moon/moon7.gif" border="0" alt="" />\');
   } else if (llena > 79 && llena < 91) {
       document.write(\'<img src="images/moon/moon8.gif" border="0" alt="" />\');
   } else if (llena > 89 && llena <= 99) {
       document.write(\'<img src="images/moon/moon9.gif" border="0" alt="" />\');
   }
    } else if (percentRaw < 0.5) {
   if (llena == 100) {
       document.write(\'<img src="images/moon/moon10.gif" border="0" alt="" />\');
   }
   if (llena >= 0 && llena < 11) {
       document.write(\'<img src="images/moon/moon10.gif" border="0" alt="" />\');
   } else if (llena > 9 && llena < 21) {
       document.write(\'<img src="images/moon/moon11.gif" border="0" alt="" />\');
   } else if (llena > 19 && llena < 31) {
       document.write(\'<img src="images/moon/moon12.gif" border="0" alt="" />\');
   } else if (llena > 29 && llena < 41) {
       document.write(\'<img src="images/moon/moon13.gif" border="0" alt="" />\');
   } else if (llena > 39 && llena < 51) {
           document.write(\'<img src="images/moon/moon14.gif" border="0" alt="" />\');
   } else if (llena > 49 && llena < 61) {
       document.write(\'<img src="images/moon/moon15.gif" border="0" alt="" />\');
   } else if (llena > 59 && llena < 71) {
       document.write(\'<img src="images/moon/moon16.gif" border="0" alt="" />\');
   } else if (llena > 69 && llena < 81) {
       document.write(\'<img src="images/moon/moon17.gif" border="0" alt="" />\');
   } else if (llena > 79 && llena < 91) {
       document.write(\'<img src="images/moon/moon18.gif" border="0" alt="" />\');
   } else if (llena > 89 && llena <= 99) {
       document.write(\'<img src="images/moon/moon19.gif" border="0" alt="" />\');
   }
    }//]]></script>
';
$content .= '</div><br />';


Validated 100% Wave

Quote:
convert the script to an external js file


I wonder how I should do that in order to put this apart en convert it to js? This is a very good question! Question
 
spasticdonkey







PostPosted: Thu Oct 17, 2013 6:44 pm Reply with quote

I would convert it to jquery first as mentioned above. then you can "view source" of your page and copy the exact code inside the script tags and save as a JavaScript file.

document.write has to be used within the "flow" of the document or it can potentially overwrite the entire page. i.e. if for some reason the page has completely loaded prior to the JavaScript using document.write being executed.

For example, I haven't tested this but it's likely to overwrite the entire page with "hi there"

$( document ).ready(function() {
document.write( "hi there" );
});


document.write is still widely supported but there are differing opinions regarding it's use. It can definitely cause issues when used improperly
http://stackoverflow.com/questions/802854/why-is-document-write-considered-a-bad-practice
 
hicuxunicorniobestbuildpc







PostPosted: Fri Oct 18, 2013 9:04 am Reply with quote

well, I don't know how to do that but I will try. I read info from your link, thanks
 
spasticdonkey







PostPosted: Fri Oct 18, 2013 10:20 am Reply with quote

spasticdonkey wrote:
or even better update to use jquery, and change
<div align="center"> to <div class="moon">

and update all uses of document.write to use jquery html()
$( "div.moon" ).html( "<img src=\"images/moon/moon20.gif\" border=\"0\" alt=\"\" />" );

then add any styling needed via CSS
.moon{text-align:center;margin 10px auto;}
 
wHiTeHaT
Life Cycles Becoming CPU Cycles



Joined: Jul 18, 2004
Posts: 579

PostPosted: Fri Oct 18, 2013 11:28 am Reply with quote

just found something cool for you..........

https://github.com/jaredstanley/moonphase

Image

if click on the moon you see a calendar:


Image
 
View user's profile Send private message Send e-mail
hicuxunicorniobestbuildpc







PostPosted: Fri Oct 18, 2013 6:21 pm Reply with quote

I love it and I like it. This is much better than what I have. Can you make a module or a block out of this script? Is it possible to use it with RavenNuke 2.5+?

Very Happy It will be fantastic to use it right now but I need to be focus in one thing at a time otherwise I get too much distraction. I need to convert this block in order to make it work without having any js conflict in the future. Wink
 
hicuxunicorniobestbuildpc







PostPosted: Sat Oct 19, 2013 1:52 am Reply with quote

Spastic, this is what I did. Let me know if it is correct.

Code:
<?php



if (!defined('BLOCK_FILE')) {Header('Location: ../index.php');  die();}

//$content = '<div align="center"><br />';
$content = '<div class="moon"><br />';
$content .= '<script type="text/javascript">
//<![CDATA[
    var currentDate  = new Date()
    currentDate.setTime(currentDate.getTime() + (currentDate.getTimezoneOffset()*60000))
    var blueMoonDate = new Date(96, 1, 3, 16, 15, 0)
    var lunarPeriod  = 29*(24*3600*1000) + 12*(3600*1000) + 44.05*(60*1000)
    var moonPhaseTime = (currentDate.getTime() - blueMoonDate.getTime()) % lunarPeriod
    var percentRaw = (moonPhaseTime / lunarPeriod)
    var llena = Math.round(200*percentRaw)
    if (llena > 100) {
   llena = llena - 100
    }
    if (percentRaw > 0.5) {
   if (llena == 100) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon20.gif\" border=\"0\" alt=\"\" />" );
   }
   if (llena >= 0 && llena < 11) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon20.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 9 && llena < 21) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon1.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 19 && llena < 31) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon2.gif\" border=\"0\" alt=\"\" />" );
        } else if (llena > 29 && llena < 41) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon3.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 39 && llena < 51) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon4.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 49 && llena < 61) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon5.gif\" border=\"0\" alt=\"\" />" );
        } else if (llena > 59 && llena < 71) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon6.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 69 && llena < 81) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon7.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 79 && llena < 91) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon8.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 89 && llena <= 99) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon9.gif\" border=\"0\" alt=\"\" />" );
   }
    } else if (percentRaw < 0.5) {
   if (llena == 100) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon10.gif\" border=\"0\" alt=\"\" />" );
   }
   if (llena >= 0 && llena < 11) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon10.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 9 && llena < 21) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon11.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 19 && llena < 31) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon12.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 29 && llena < 41) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon13.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 39 && llena < 51) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon14.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 49 && llena < 61) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon15.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 59 && llena < 71) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon16.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 69 && llena < 81) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon17.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 79 && llena < 91) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon18.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 89 && llena <= 99) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon19.gif\" border=\"0\" alt=\"\" />" );
   }
    }//]]></script>
';
$content .= '</div><br />';
 
spasticdonkey







PostPosted: Sat Oct 19, 2013 10:08 am Reply with quote

I would put the closing script tag and the closing cdata each on it's own line; although it probably works without doing that... Aside from that it looks like what I suggested..

I guess the bigger question is does it work? If it does you should be able to save your script as an external JS file; removing the cdata and script tags, and your block could be as simple as:

$content = '<div class="moon"></div>';
addJSToBody('yourdirectory/moon.js', 'file');
 
hicuxunicorniobestbuildpc







PostPosted: Sun Oct 20, 2013 2:29 am Reply with quote

This is what I did as a block
Code:


<?php


if (!defined('BLOCK_FILE')) {Header('Location: ../index.php');  die();}

//$content = '<div align="center"><br />';
$content = '<div class="moon"><br />';
$content .= '</div><br />';
addJSToBODY('js/moon.js', 'file');


moon.js from page source I got this but unfortunately it doesn't work. BLANC PAGE



Code:
var currentDate  = new Date()

    currentDate.setTime(currentDate.getTime() + (currentDate.getTimezoneOffset()*60000))
    var blueMoonDate = new Date(96, 1, 3, 16, 15, 0)
    var lunarPeriod  = 29*(24*3600*1000) + 12*(3600*1000) + 44.05*(60*1000)
    var moonPhaseTime = (currentDate.getTime() - blueMoonDate.getTime()) % lunarPeriod
    var percentRaw = (moonPhaseTime / lunarPeriod)
    var llena = Math.round(200*percentRaw)
    if (llena > 100) {
   llena = llena - 100
    }
    if (percentRaw > 0.5) {
   if (llena == 100) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon20.gif\" border=\"0\" alt=\"\" />" );
   }
   if (llena >= 0 && llena < 11) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon20.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 9 && llena < 21) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon1.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 19 && llena < 31) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon2.gif\" border=\"0\" alt=\"\" />" );
        } else if (llena > 29 && llena < 41) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon3.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 39 && llena < 51) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon4.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 49 && llena < 61) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon5.gif\" border=\"0\" alt=\"\" />" );
        } else if (llena > 59 && llena < 71) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon6.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 69 && llena < 81) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon7.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 79 && llena < 91) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon8.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 89 && llena <= 99) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon9.gif\" border=\"0\" alt=\"\" />" );
   }
    } else if (percentRaw < 0.5) {
   if (llena == 100) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon10.gif\" border=\"0\" alt=\"\" />" );
   }
   if (llena >= 0 && llena < 11) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon10.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 9 && llena < 21) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon11.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 19 && llena < 31) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon12.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 29 && llena < 41) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon13.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 39 && llena < 51) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon14.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 49 && llena < 61) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon15.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 59 && llena < 71) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon16.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 69 && llena < 81) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon17.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 79 && llena < 91) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon18.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 89 && llena <= 99) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon19.gif\" border=\"0\" alt=\"\" />" );
   }
 
spasticdonkey







PostPosted: Sun Oct 20, 2013 9:54 am Reply with quote

there could be other problems, but you removed the final closing curly brace of your JavaScript
}//]]></script>

also part of the reason why I recommended putting the closing script tag and the closing cdata each on it's own line
 
hicuxunicorniobestbuildpc







PostPosted: Sun Oct 20, 2013 2:12 pm Reply with quote

You're right!!!! I removed the closing curly brace!! Now it is working as it should be!!

Very Happy

Wink Thank you very much for taking the time. I learned something from you today!!!
 
hicuxunicorniobestbuildpc







PostPosted: Sun Oct 20, 2013 2:42 pm Reply with quote

This is the correct file:

Code:
var currentDate  = new Date()

    currentDate.setTime(currentDate.getTime() + (currentDate.getTimezoneOffset()*60000))
    var blueMoonDate = new Date(96, 1, 3, 16, 15, 0)
    var lunarPeriod  = 29*(24*3600*1000) + 12*(3600*1000) + 44.05*(60*1000)
    var moonPhaseTime = (currentDate.getTime() - blueMoonDate.getTime()) % lunarPeriod
    var percentRaw = (moonPhaseTime / lunarPeriod)
    var llena = Math.round(200*percentRaw)
    if (llena > 100) {
   llena = llena - 100
    }
    if (percentRaw > 0.5) {
   if (llena == 100) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon20.gif\" border=\"0\" alt=\"\" />" );
   }
   if (llena >= 0 && llena < 11) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon20.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 9 && llena < 21) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon1.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 19 && llena < 31) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon2.gif\" border=\"0\" alt=\"\" />" );
        } else if (llena > 29 && llena < 41) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon3.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 39 && llena < 51) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon4.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 49 && llena < 61) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon5.gif\" border=\"0\" alt=\"\" />" );
        } else if (llena > 59 && llena < 71) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon6.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 69 && llena < 81) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon7.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 79 && llena < 91) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon8.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 89 && llena <= 99) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon9.gif\" border=\"0\" alt=\"\" />" );
   }
    } else if (percentRaw < 0.5) {
   if (llena == 100) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon10.gif\" border=\"0\" alt=\"\" />" );
   }
   if (llena >= 0 && llena < 11) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon10.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 9 && llena < 21) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon11.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 19 && llena < 31) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon12.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 29 && llena < 41) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon13.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 39 && llena < 51) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon14.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 49 && llena < 61) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon15.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 59 && llena < 71) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon16.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 69 && llena < 81) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon17.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 79 && llena < 91) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon18.gif\" border=\"0\" alt=\"\" />" );
   } else if (llena > 89 && llena <= 99) {
       $( "div.moon" ).html( "<img src=\"images/moon/moon19.gif\" border=\"0\" alt=\"\" />" );
   }
    }


I guess it is not necessary to convert this js file in single quotes right?

This one was single quote
Quote:
document.write(\'<img src="images/moon/moon20.gif" border="0" alt="" />\');


Here you use double quote again. Is it possible to convert it in single quote?
Quote:
and update all uses of document.write to use jquery html()
$( "div.moon" ).html( "<img src=\"images/moon/moon20.gif\" border=\"0\" alt=\"\" />" );
 
spasticdonkey







PostPosted: Sun Oct 20, 2013 3:09 pm Reply with quote

when we were escaping single quotes earlier it was just because we were working within a php single quoted string. since you have converted to an external JavaScript file we only need to escape single quotes within a JavaScript single quoted string. You could write it a number of different ways within a JavaScript file.

$( 'div.moon' ).html( '<img src="images/moon/moon20.gif" border="0" alt="" />' );
$( "div.moon" ).html( "<img src=\"images/moon/moon20.gif\" border=\"0\" alt=\"\" />" );

an example of escaping single quotes
$( 'div.moon' ).html( '<img src=\'images/moon/moon20.gif\' border=\'0\' alt=\'\' />' );

I usually use double quotes with JavaScript when also working within PHP.... and use single quotes when working in a JavaScript file. Not always, but usually whatever method requires the least amount of escaping of quotes.
 
hicuxunicorniobestbuildpc







PostPosted: Sun Oct 20, 2013 5:42 pm Reply with quote

Let me see if I understood correctly

1. In order to use single quotes within javascript files like example.js we always need to escape single quotes

Ex:
Quote:

$( 'div.moon' ).html( '<img src=\'images/moon/moon20.gif\' border=\'0\' alt=\'\' />' );


Ex:
Quote:
$( "div.moon" ).html( "<img src=\"images/moon/moon20.gif\" border=\"0\" alt=\"\" />" );


Note: I use these two above now and worked properly!.

but this one I can use it as well withing example.js file as well?

Quote:
$( 'div.moon' ).html( '<img src="images/moon/moon20.gif" border="0" alt="" />' );


Note: I am writing all this for the future so I don't forget. Please clarify the last above which doesn't have any slash(\)
 
spasticdonkey







PostPosted: Sun Oct 20, 2013 6:51 pm Reply with quote

the examples are all correct and the last example is what I would use in your situation, where you are needing to output html. I prefer to use double-quoted attributes in my html (as was done last 2 examples) although single-quoted html attributes are still valid (first example).

I wouldn't say "In order to use single quotes within javascript files like example.js we always need to escape single quotes". I would say "cannot contain a quote character of the same kind that opened the string". The escaping generally works the same as PHP, although in PHP double-quoted strings have to be parsed for variables and are slower.

echo "<hr class='one' />"; // ok but slower
echo "<hr class=\"one\" />"; // ok but slower
echo "<hr class="one" />"; // broken
echo '<hr class="one" />'; // good

echo "she said he's home"; // ok but slower
echo 'she said he\'s home'; // good
echo 'she said he's home'; // broken


Note that unlike PHP in JavaScript there is no advantage (performance wise) between using single or double quotes.

$('#myDivId').html( '<hr class="one" />' ); // good
$("#myDivId").html( "<hr class=\"one\" />" ); // good
$('#myDivId').html( '<hr class=\'one\' />' ); // good
$('#myDivId').html( '<hr class='one' />' ); // broken
$("#myDivId").html( "<hr class="one" />" ); // broken


Note the last examples apply to working within a JavaScript file. It gets more complex when outputting Javascript via PHP as you need to escape certain quotes for PHP (usually single) and certain quotes for JavaScript (usually double).

echo '$("#myDivId").html( "<hr class="one" />" );'; // broken JavaScript
echo '$('#myDivId').html( '<hr class="one" />' );'; // broken PHP
echo '$(\'#myDivId\').html( \'<hr class="one" />\' );'; // good
echo '$("#myDivId").html( "<hr class=\"one\" />" );'; // good
echo "$('#myDivId').html( '<hr class=\'one\' />' );"; // ok but slower (php)
 
hicuxunicorniobestbuildpc







PostPosted: Mon Oct 21, 2013 3:19 am Reply with quote

Wow! very good understandable examples. I do need to keep these last examples for the future. Thank you very much for the lesson. I think your last post makes me undertand how complex javascript could be.

Now I understand why in lang-English.php we use this

Code:
define('_BIGSTORY','Today\'s most read Story is:');


Cheers Wave
 
neralex
Site Admin



Joined: Aug 22, 2007
Posts: 1775

PostPosted: Tue Oct 22, 2013 8:07 am Reply with quote

hicuxunicorniobestbuildpc, this is not a performance issue of php or an example of the complexibility in javascript in the language-files. One has nothing to do with the other. Without the \ before ' you would get in a php-file an PHP-error and the code would be broken at this point. In php is that a simple mask for the used string. If you are building strings with PHP, so you need this mask to not brake the php code. That could be all - a text-line, JS, HTML etc.

_________________
Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Converting/Creating Blocks

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©