Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> JavaScript
Author Message
killing-hours
RavenNuke(tm) Development Team



Joined: Oct 01, 2010
Posts: 438
Location: Houston, Tx

PostPosted: Mon Oct 25, 2010 1:19 pm Reply with quote

Hey all-

New question... forget who, but someone turned me onto the

Code:
define('RN_MODULE_HEAD', 'moduleaddonjs.php');


way of adding JS to the head... but here's the catch... with this particular way of doing it... it adds the JS to the entire module in which the "document ready" stuff gets loaded on the index page.

What i'm trying to do is add a floating message to a particular page within the module and using the selector doesn't seem to work unless I'm doing it wrong.

Question is... is there already a way to only load particular pieces of JS to particular pages?

(I know this seems confusing... not really sure how to correctly explain it)

_________________
Money is the measurement of time - Me
"You can all go to hell…I’m going to Texas" -Davy Crockett 
View user's profile Send private message
spasticdonkey
RavenNuke(tm) Development Team



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

PostPosted: Mon Oct 25, 2010 1:52 pm Reply with quote

Yes RN_MODULE_HEAD will add the script to the entire module.. Not sure what you are using for your floating message, but I did one for a PM notification with colorbox

Code:
   $(document).ready(function(){

      $('#floating-message').colorbox({ width: "300px", height: "100px", inline:true, open:true, href:"#your-message" });
   });

and the html
Code:
<div id="floating-message" style="display:none"><div id="your-message">Your Message</div></div>


this will automatically open the hidden div in a modal window if it exists, otherwise does nothing... Smile Maybe that will work for you? It can also be incorporated with cookies if needed, with a little more work... Wink
 
View user's profile Send private message Visit poster's website
killing-hours







PostPosted: Mon Oct 25, 2010 2:11 pm Reply with quote

Spastic, I'm apparently not explaining it right. I can get my message to display n' all that fine... it's "when" it's being displayed that's the issue.

For instance... in this particular situation... the module loads to the "Test.php" as it's index. (default) Now.. using the document ready function... when the "default" page loads... my document ready stuff gets thrown onto the screen. With my needs... that's not going to work because the message doesn't need to show on the default page.

let's call the needed page "Test2.php". So we hit the default page of the module (message box shouldn't show)... then the user clicks the link to go to page 2 (Test2.php). When that page loads... that's when the message box should show.

Since i'm using the RN_M_HEAD way of doing it... when the default page loads... it displays the message box because the message box is within the $(document).ready part of the entire module... hence it loads at the default page.

So what I'm trying to do is only load the message box on Test2.php and not the default page.

Not sure if there's another way to define maybe a page head or adding js to just a single page or even just using a selector to add the JS to that particular page?

I hope that's a bit clearer.

I'm using THIS message plugin

i.e. let's call a Test2.php a form with the id of "t2"
(thinking of selectors as a way to keep all js within one file)
Code:
$("#t2").ready(function(){

           // Do STUFF
});

----------------

Hm.... while I was sitting here re-reading my post... Bright light. Wink

Can I add the "inlineJS" within the page itself so that the needed js only loads on that page?

I.e.
Code:
<?php


$inlineJS = '<script>

// DO STUFF //

</script> '."\n";


addJSToBody($inlineJS,'inline');

// THE REST OF THE PAGE CODING //

?>



----------

Edit... we have a winner! Wink Thanks for you help spastic!
 
spasticdonkey







PostPosted: Mon Oct 25, 2010 2:51 pm Reply with quote

Hmm, it's a little difficult to say for sure without knowing the structure of your module... But it looks like you can load those floating messages in the body of your document, so I would only load the required scripts for the jQuery Floating Message Plugin in your moduleaddonjs.php and then just echo out the message in the body of the document when you need it (on a page, in a function...)

Code:
echo '<script type="text/javascript">

            $(document.body).ready(function(){
                $("<div>Write less do more</div>").floatingMessage();
            });
        </script>';
 
killing-hours







PostPosted: Mon Oct 25, 2010 3:16 pm Reply with quote

Well.. i got it to work by just adding the "inlineJS" within the actual page (Test2.php) Everything seems like it's working fine... but is that wrong or an acceptable way of doing it?

structure would be like this...

1 = folder
2 = file


1: Module - (main dir)
2: moduleaddon
1: forms - (sub dir)
2: Test.php
2: Test2.php

anywho... like I said... it works with just adding the "inlineJS" into the coding of that particular page. All seems well. Thanks!

----------


Ahhhh... took me a second... but I think I see what you're saying. Instead of adding the inline part into the page... just echo it out. Is this a better way of doing it vs. adding the inlineJS to the top of the page?
 
Palbin
Site Admin



Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania

PostPosted: Mon Oct 25, 2010 4:04 pm Reply with quote

killing-hours, yes that is correct. If you want it only on particular pages you would need to add it to just those pages. If you need to add it to more than one page I would put it in a separate file and just include the file.

_________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan. 
View user's profile Send private message
killing-hours







PostPosted: Tue Oct 26, 2010 7:12 am Reply with quote

Palbin wrote:
killing-hours, yes that is correct. If you want it only on particular pages you would need to add it to just those pages. If you need to add it to more than one page I would put it in a separate file and just include the file.


Gotcha Palbin & Spastic... Now I know two different ways to make it happen. Learn something new everyday. Thanks guys.
 
killing-hours







PostPosted: Tue Oct 26, 2010 6:26 pm Reply with quote

Spastic, I need your wisdom buddy.

I am working on making two checkboxes being dependent on each other (only one can be checked) and I've used jquery to do it... but I'm running into a snag.

html:
Code:
echo '<td><input type="checkbox" class="checkbox"  id="chkwind2" name="check[]" value="4" /></td>'."\n";


Jquery:
Code:
$("#chkwind2").click(function(){

   if ($("#chkwind2").is(":checked")){
     $("#chkwind").removeAttr("checked");
   }
});


The snag is this... when the attribute is removed... the form or the browser doesn't seem to recognize it and in IE, crashes the browser... in FF... the submit button no longer submits or is just hung up on something.

So I guess the question is... what am I forgetting/missing or is there a better alternative using a php method?

What i've tried:

.change instead of .click
return; at the end

------------

Put that question on hold... I think I'm being a bit moronic at the moment. Wink Validation is still holding up the form I believe since I'm not removing some rules with that change.


Last edited by killing-hours on Tue Oct 26, 2010 7:16 pm; edited 1 time in total 
spasticdonkey







PostPosted: Tue Oct 26, 2010 7:11 pm Reply with quote

sounds like your form is breaking somehow Sad
do you have the firebug plugin for firefox? [ Only registered users can see links on this board! Get registered or login! ]

You'll also want Html Validator [ Only registered users can see links on this board! Get registered or login! ]

First make sure the form code is compliant. Firebug is nice because you can see the code as it is modified by JS, just right click on anything and select inspect element. Also, what value gets inserted into the name attribute?
name="check[]"
 
killing-hours







PostPosted: Tue Oct 26, 2010 7:17 pm Reply with quote

Sorry... I updated the last response as you responded. See my edit above. About to test it as I write this.

-------

Edit*

Definitely the validation. For some reason... it's not removing 3 added "requireds" once the checkbox attribute is removed. I'm going through the jquery line by line testing every one of the removes to ensure they work.

By the way... thanks for those links. I was searching the forums about an hour ago for where you might have said which validator/plugin you were using.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> JavaScript

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 ©