Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> RavenNuke(tm) v2.5x
Author Message
hicuxunicorniobestbuildpc
The Mouse Is Extension Of Arm



Joined: Aug 13, 2009
Posts: 1014
Location: Netherland

PostPosted: Fri Oct 11, 2013 6:29 am Reply with quote

I am not so clear how exactly a javascript has be converted in order to load properly.

I have this file called swfobject.js

Code:
function SWFObject(swf, id, w, h, ver, c){

   this.params = new Object();
   this.variables = new Object();
   this.attributes = new Object();
   this.setAttribute("id",id);
   this.setAttribute("name",id);
   this.setAttribute("width",w);
   this.setAttribute("height",h);
   this.setAttribute("version",ver);
   this.setAttribute("swf",swf);   
   this.setAttribute("classid","clsid:D27CDB6E-AE6D-11cf-96B8-444553540000");
   this.addParam("bgcolor",c);
}
SWFObject.prototype.addParam = function(key,value){
   this.params[key] = value;
}
SWFObject.prototype.getParam = function(key){
   return this.params[key];
}
SWFObject.prototype.addVariable = function(key,value){
   this.variables[key] = value;
}
SWFObject.prototype.getVariable = function(key){
   return this.variables[key];
}
SWFObject.prototype.setAttribute = function(key,value){
   this.attributes[key] = value;
}
SWFObject.prototype.getAttribute = function(key){
   return this.attributes[key];
}
SWFObject.prototype.getVariablePairs = function(){
   var variablePairs = new Array();
   for(key in this.variables){
      variablePairs.push(key +"="+ this.variables[key]);
   }
   return variablePairs;
}
SWFObject.prototype.getHTML = function(){
   var con = '';
   if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) {
      con += '<embed type="application/x-shockwave-flash"  pluginspage="http://www.macromedia.com/go/getflashplayer" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'"';
      con += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
      for(var key in this.params){ con += [key] +'="'+ this.params[key] +'" '; }
      var pairs = this.getVariablePairs().join("&");
      if (pairs.length > 0){ con += 'flashvars="'+ pairs +'"'; }
      con += '/>';
   }else{
      con = '<object id="'+ this.getAttribute('id') +'" classid="'+ this.getAttribute('classid') +'"  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+this.setAttribute("version")+',0,0,0" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'">';
      con += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
      for(var key in this.params) {
       con += '<param name="'+ key +'" value="'+ this.params[key] +'" />';
      }
      var pairs = this.getVariablePairs().join("&");
      if(pairs.length > 0) {con += '<param name="flashvars" value="'+ pairs +'" />';}
      con += "</object>";
   }
   return con;
}
SWFObject.prototype.write = function(elementId){   
   if(typeof elementId == 'undefined'){
      document.write(this.getHTML());
   }else{
      var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
      n.innerHTML = this.getHTML();
   }
}



I just created in includes/addon folder a file head-jsobject.php and I inserted this code

addJSToHead('includes/js/swfobject.js', 'file');

Is that the only way to do it?.
Shocked
 
View user's profile Send private message Visit poster's website
nuken
RavenNuke(tm) Development Team



Joined: Mar 11, 2007
Posts: 2024
Location: North Carolina

PostPosted: Fri Oct 11, 2013 6:54 am Reply with quote

There is some info in the wiki here [ Only registered users can see links on this board! Get registered or login! ]

You can load the js site wide or module level through the functions introduce in RN 2.4. The js can also be loaded in the head or body depending on what the script requires. There is no conversion required unless you are including it inline, you would need to escape any single quotes in the js.

_________________
Tricked Out News 
View user's profile Send private message Send e-mail Visit poster's website
hicuxunicorniobestbuildpc







PostPosted: Fri Oct 11, 2013 7:45 am Reply with quote

Quote:
you would need to escape any single quotes in the js


This is what I don't understand!!!! What is the trick. Please give me an example so I can learn. I read the wiki but I don't get it. Sad

I think to create a file in includes/addon/head-example.php is not the best I think 'cause it will always call this file everytime I open the website and other modules. What I want to achieve is user can only call this file when they use the module.
 
nuken







PostPosted: Fri Oct 11, 2013 9:27 am Reply with quote

If you want the file added module level, look in the news module. The index.php and article.php both include js and css when the news module is loaded. To escape the single quotes, add \ before the ' to use it in an inline situation.

Code:



this.getAttribute('swf')
would become
this.getAttribute(\'swf\')
or you could use " like this
this.getAttribute("swf")
 
hicuxunicorniobestbuildpc







PostPosted: Sat Oct 12, 2013 3:15 am Reply with quote

to add single quotes to the file it is complicated. I really don't know how to do it. Well, I think it is better to call the file in the specific module. I did this

Code:
addJSToBody('modules/' . $module_name . '/js/swfobject.js', 'file');


I think every single module must load his own javascript so it doesn't load all the time. What do you think is more efficient?
 
montego
Site Admin



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

PostPosted: Sat Oct 12, 2013 8:18 am Reply with quote

If it is only needed by the module and not blocks, then I completely agree with you, that it is going to be more efficient.

_________________
Where Do YOU Stand?
HTML Newsletter::ShortLinks::Mailer::Downloads and more... 
View user's profile Send private message Visit poster's website
nuken







PostPosted: Sat Oct 12, 2013 8:26 am Reply with quote

If the js only needs to load when the module is called. use it module level. If the js is needed site wide, load it in a file in the addons.
 
spasticdonkey
RavenNuke(tm) Development Team



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

PostPosted: Sat Oct 12, 2013 5:04 pm Reply with quote

in terms of single quotes versus double quotes, they are interchangeable in JavaScript.. you should be able to find/replace all single quotes (within a JavaScript) with double quotes without issue. the only exception being if the code has both single and double quotes in it to start with. In that case you would need to escape in double quotes prior to your find/replace

\"

This is unlike php where single/double quotes are processed differently.

Although this is only really necessary if you are using the JavaScript inline in your page. The only reason to do so would be if you need to dynamically insert data into the JavaScript via PHP. It is always preferable to use an external JavaScript file when you can, as it gets cached by the browser and doesn't have to download everytime the page is loaded.
 
View user's profile Send private message Visit poster's website
montego







PostPosted: Sun Oct 13, 2013 8:23 am Reply with quote

... and, I find it much easier to include JS in PHP using PHP's HEREDOC syntax. For example, my own AddThis inclusion was done within my includes/custom_files/custom_head.php file like this (I've masked some data with asterisks '******'):

Code:


/*
 * Add new AddThis Layer code
 */
    echo <<<_JS_
        <!-- AddThis Smart Layers BEGIN -->
        <!-- Go to http://www.addthis.com/get/smart-layers to customize -->
        <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=******"></script>
        <script type="text/javascript">
          addthis.layers({
            'theme' : 'transparent',
            'follow' : {
              'services' : [
                {'service': 'facebook', 'id': 'pages/********/*******'},
                {'service': 'twitter', 'id': '********'}
              ]
            },
            'whatsnext' : {},
            'recommended' : {
              'title': 'Recommended for you:'
            }
          });
        </script>
        <!-- AddThis Smart Layers END -->
_JS_;


Take special NOTE that the end tag (here: "_JS_") can be almost anything you want but the final line MUST be fully left-aligned!
 
neralex
Site Admin



Joined: Aug 22, 2007
Posts: 1538

PostPosted: Wed Oct 16, 2013 7:56 am Reply with quote

For me are the functions addJSToHead and addJSToBody the best choice. Its very cool to use and flexible.

_________________
Github: RavenNuke 
View user's profile Send private message
hicuxunicorniobestbuildpc







PostPosted: Wed Oct 16, 2013 11:55 am Reply with quote

Montego, if I create a file in includes/custom_files/custom_head.php then I get a blank page.
 
montego







PostPosted: Sat Oct 19, 2013 9:38 am Reply with quote

Then you have a coding error in custom_head.php...
 
southern
Client



Joined: Jan 29, 2004
Posts: 602
Location: Texas

PostPosted: Wed Dec 11, 2013 5:28 pm Reply with quote

montego wrote:
... and, I find it much easier to include JS in PHP using PHP's HEREDOC syntax. For example, my own AddThis inclusion was done within my includes/custom_files/custom_head.php file like this (I've masked some data with asterisks '******'):

Code:


/*
 * Add new AddThis Layer code
 */
    echo <<<_JS_
        <!-- AddThis Smart Layers BEGIN -->
        <!-- Go to http://www.addthis.com/get/smart-layers to customize -->
        <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=******"></script>
        <script type="text/javascript">
          addthis.layers({
            'theme' : 'transparent',
            'follow' : {
              'services' : [
                {'service': 'facebook', 'id': 'pages/********/*******'},
                {'service': 'twitter', 'id': '********'}
              ]
            },
            'whatsnext' : {},
            'recommended' : {
              'title': 'Recommended for you:'
            }
          });
        </script>
        <!-- AddThis Smart Layers END -->
_JS_;


Take special NOTE that the end tag (here: "_JS_") can be almost anything you want but the final line MUST be fully left-aligned!


How would I put in

Code:


<script type="text/javascript" src="snowstorm.js"></script>

for the whole site? I'm a bit confused.

_________________
Computer Science is no more about computers than astronomy is about telescopes.
- E. W. Dijkstra 
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number
nuken







PostPosted: Thu Dec 12, 2013 6:30 am Reply with quote

In your themes theme.php file just under the <?php add this:

Code:



addJSToBody('snowstorm.js', 'file');



this is assuming the file is located in the root of your site. If not, put the correct path to the js file in.
 
southern







PostPosted: Thu Dec 12, 2013 11:56 am Reply with quote

nuken wrote:
In your themes theme.php file just under the <?php add this:

Code:



addJSToBody('snowstorm.js', 'file');



this is assuming the file is located in the root of your site. If not, put the correct path to the js file in.


Just like that? The .js should go in the head, so I should use the form addJSToHead('/scripts/snowstorm.js', 'file');?

Thanks, nuken. Smile
 
southern







PostPosted: Thu Dec 12, 2013 12:10 pm Reply with quote

I tried both and the Body works. It is a script from
[ Only registered users can see links on this board! Get registered or login! ]

in case anyone else wants to use it.
 
hicuxunicorniobestbuildpc







PostPosted: Fri Dec 13, 2013 2:10 am Reply with quote

Very Happy Hi southern

1. Open your ftp
2. Open includes/addons/
3. Create a file called body-Storm_Snowing.php and the copy and paste the code below.

Code:
<?php

// Storm Snowing 1.0
//This addon has been created by bestbuildpc

if (stristr(htmlentities($_SERVER['PHP_SELF']), 'body-Storm_Snowing.php')) {
   Header('Location: ../../index.php');
   die();
}
addJSToBody('js/snowstorm.js', 'file');

$inlineJS = '<script type="text/javascript">
   $(document).ready(function(){

$(\'#snowStorm\').snowColor : "#99ccff";
$(".nowStorm").flakesMaxActive : "96";
$(".nowStorm").useTwinkleEffect : "true";

          });
         
       });
</script>';

addJSToBody($inlineJS , 'inline');


4. In the root where mainfile.php create a folder named js and upload your javascript file snowstorm.js

That's all!

Wink


Last edited by hicuxunicorniobestbuildpc on Fri Dec 13, 2013 9:23 am; edited 1 time in total 
neralex







PostPosted: Fri Dec 13, 2013 7:56 am Reply with quote

hicuxunicorniobestbuildpc, little questions ... from where you have the variable $contact and why don't you use you added variable $inlineJS? :clap:
 
hicuxunicorniobestbuildpc







PostPosted: Fri Dec 13, 2013 9:24 am Reply with quote

you are right neralex, I made a little bit mistake. Thanks for the correction!!

Very Happy
 
southern







PostPosted: Fri Dec 13, 2013 2:09 pm Reply with quote

hicuxunicorniobestbuildpc wrote:
Very Happy Hi southern

1. Open your ftp
2. Open includes/addons/
3. Create a file called body-Storm_Snowing.php and the copy and paste the code below.

Code:
<?php

// Storm Snowing 1.0
//This addon has been created by bestbuildpc

if (stristr(htmlentities($_SERVER['PHP_SELF']), 'body-Storm_Snowing.php')) {
   Header('Location: ../../index.php');
   die();
}
addJSToBody('js/snowstorm.js', 'file');

$inlineJS = '<script type="text/javascript">
   $(document).ready(function(){

$(\'#snowStorm\').snowColor : "#99ccff";
$(".nowStorm").flakesMaxActive : "96";
$(".nowStorm").useTwinkleEffect : "true";

          });
         
       });
</script>';

addJSToBody($inlineJS , 'inline');


4. In the root where mainfile.php create a folder named js and upload your javascript file snowstorm.js

That's all!

Wink


Just like that. Thanks for simplifying it. Smile
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> RavenNuke(tm) v2.5x

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 ©