Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Using Jquery Plugins  (Read 531 times)

Brian

  • Newbie
  • *
  • Karma: 1
  • Posts: 32
Using Jquery Plugins
« on: August 18, 2012, 06:29:38 pm »

Ive noticed lately when trying to get some Jquery scripts like PrettyPhoto or highslide to work in snews alot of the times they just simply wont work for whatever reason. I have literally cloned my html template as html and loaded local and highslide or prettyphoto typically work but when I apply the code to the live site the scripts just flake out and wont initialize.

Could something like this be due to snews doing the modrewrite to urls and directories or is it possibly jacking up the code in some way when i add it to a page?
Logged

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
Re: Using Jquery Plugins
« Reply #1 on: August 18, 2012, 07:28:51 pm »

You will need to post some code to help you out.

With Javascript, you can use the browser developer tools to help you out if there are issues.  Firebug is good for Firefox and Chrome/Chromium has its own tools as well.
Logged

Brian

  • Newbie
  • *
  • Karma: 1
  • Posts: 32
Re: Using Jquery Plugins
« Reply #2 on: August 18, 2012, 11:08:48 pm »

Ill just give an example as it would be easier than isolating any of the code strings. This is a php script cookie cutter example.

Ive not used mod rewrite all that much and I dont really ever dive in to .htaccess

But lets say I was wanting to add a completely exterior php form processor to the site. I place the 1 file processor in the public_html directory, i then write an extra block containing the form processor code which is posting to the external php form processor. Would mod rewrite cause a major conflict in the direct posting to that processor and would I need to figure out a rule in the .htaccess that tells the site to leave formprocessor.php and any queries to it completely alone and let it just operate?

The answer to this will tell me how to handle the other files in the structure as many of them have nothing to do with the snews core and just assist in building the over all cosmetics however that .htaccess forcing modrewrite has caused issues inside of other folders in the tree.
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: Using Jquery Plugins
« Reply #3 on: August 24, 2012, 11:04:05 pm »

Brian, just speaking from my experience as a user - I've almost never had any problems using jQuery (or other library) plugins with sNews. If you're placing script code in index.php it could be a matter of where you place it. Normally it's said that references to the library script (jQuery in this case) should be placed towards the end of the <head> block while individual plugin scripts should be placed either just before or just after the closing </body> tag. However, sometimes placing the plugin script just before the closing </head> tag (but after the library script reference) is required.

If you're placing script code in an sNews article or page, you need to wrap the code in CDATA tags, like this:
Code: [Select]
//<![CDATA[
...code...
//]]>

The same would most likely be required if you do a script reference in an article or page, even if that page is a stand-alone, physical PHP file, in this way:
Code: [Select]
... page/article text ...
//<![CDATA[
<script type="text/javascript" src="script.js"></script>
//]]>
... more article/page content ...

Mod_rewrite or the htaccess file directives should have no influence on the javascript code, just make sure you get your url's right. The starting point is always the site root, regardless of where you put the script reference. Example: let's say you have a file called "cart.php" within a folder "includes", and you make an include of that file in index.php, like so:

Code: [Select]
<?php include('includes/cart.php'); ?>
referencing a script within "cart.php" still needs to start at the site root, for example like this (assuming the script is in the "js" folder):

Code: [Select]
<!-- In cart.php -->
<script type="text/javascript" src="js/checkout.js"></script>

(You'll notice here that I didn't use the CDATA tags - in index.php, or files included in index.php, it should not be necessary.)
Logged