can't add custom javascript
Permalink
I'm building upon the theme called whitespace.
http://www.concrete5.org/index.php?cID=16512...
My javascript doesn't work.
The theme default.php includes a header.php and a footer.php.
I tried to place my own javascript through:
I tried it on different places like
header.php (before header_required)
footer.php
default.php
Must be simple to solve, but I don't know how.
www.www.clients.alaingroeneweg.com...
Thanks for any hint.
http://www.concrete5.org/index.php?cID=16512...
My javascript doesn't work.
The theme default.php includes a header.php and a footer.php.
I tried to place my own javascript through:
<script type="text/javascript" href="<?=$this->getThemePath()?>myjs.js"></script>
I tried it on different places like
header.php (before header_required)
footer.php
default.php
Must be simple to solve, but I don't know how.
www.www.clients.alaingroeneweg.com...
Thanks for any hint.
It does matter. If you place it after Loader::element('header_required'); there will be problems with edit mode or it might not work all together. I've seen somewhere a little code snippet that puts scripts in conditional statement and they wouldn't load when in edit mode. Neat, but can't find it now...
Hello, I would always place your js underneath your header_required, because the header_required adds jquery to your page and js loads sequentially, so if you need jquery for your custom js you would need to load your js underneath. So the best way to include your header files would be to determine your dependencies. For instance, I always load my custom css before the header_required, then underneath it I will load any custom css that modifies the css loaded by concrete5, and then any js that requires jquery in the order of their respective dependencies.
To disable any scripts or css or anything you would use this code:
To load if IN edit mode:
To load if NOT in edit mode (note the exclamation mark before $c->):
You can also use an else statement to combine the two:
I typically disable any custom js when in edit mode to prevent conflicts, and add custom CSS when in edit mode to customize the editing interface.
Hope that helps!
To disable any scripts or css or anything you would use this code:
To load if IN edit mode:
To load if NOT in edit mode (note the exclamation mark before $c->):
You can also use an else statement to combine the two:
<?php global $c; if (!$c->isEditMode()) { //do code here if NOT in edit mode } else { //do code here if IS in edit mode } ?>
I typically disable any custom js when in edit mode to prevent conflicts, and add custom CSS when in edit mode to customize the editing interface.
Hope that helps!
you could also wrap your js code in the following:
if( !CCM_EDIT_MODE || !CCM_ARRANGE_MODE ){ ... you js code ... }
Wow that's new. What is it?
I should note that I am frantically learning php and js but I am only a few weeks into it, so I know how to use and modify snippets, but I don't know much about what they are exactly. Is this some kind of array or something? How come you don't get the $c variable (scope, right?)?
Thanks.
Thanks.
EDIT: Your code bit doesn't work. I tried it the same way I use my examples (ie, with "print") and it didn't output anything.
that code is javascript not PHP and should be in your .js file.
It's just looks for C5's 2 javascript variables (view source on any page and you'll see them in the head) and checks to see if they are set to true or false. C5 uses those javascript vars for it's own functionality so why not use it for any custom. :)
It's just looks for C5's 2 javascript variables (view source on any page and you'll see them in the head) and checks to see if they are set to true or false. C5 uses those javascript vars for it's own functionality so why not use it for any custom. :)
Aha, thanks. At least there may be some use for that crap concrete5 puts up there. However, since I am also including css in edit mode, I figure it is more intuitive to simply combine the include and uninclude in one statement. I may figure a way to use this in a block though.
You can also grab a version of jquery tools that does not have jQuery built into it meaning you can just add it to your header with no clashing problems
http://flowplayer.org/tools/download/index.html...
just make sure you do not tick include jquery
http://flowplayer.org/tools/download/index.html...
just make sure you do not tick include jquery
True, which is what I have done, but I still deactivate all my custom js because it also makes tabs, which are a pain in the rear to edit the blocks in if I don't revert back to regular sequential blocks, lol. I also am using Cufon, which is more overhead, which can slow down a slower computer if combined with the c5 js. I prefer my stuff working as intended, lol. One major complaint I have is c5 will actually add classes to my dynamically added wrapper divs. I am not sure which of their includes is doing this, but it is a pain. It'll add useless css to my page as well.
/* edit */
I appear to be mixing threads, yes I agree the use of the isEditMode()
is good to prevent the page loading in the extra gubbings.
I often add custom css/code when in EditMode to Disable stuff.
For some reason I was thinking of the other threads that suggest isSuperUser() or that check if the user is Logged in. And do not include these scripts if logged in meaning custom js only works when not logged in, but I agree with the use of isEditMode().
I have never tried cufon (we use font-face) but used to use sifr, can certainly agree with you on the slow computer problems, its the reason I no longer work from home.
I appear to be mixing threads, yes I agree the use of the isEditMode()
is good to prevent the page loading in the extra gubbings.
I often add custom css/code when in EditMode to Disable stuff.
For some reason I was thinking of the other threads that suggest isSuperUser() or that check if the user is Logged in. And do not include these scripts if logged in meaning custom js only works when not logged in, but I agree with the use of isEditMode().
I have never tried cufon (we use font-face) but used to use sifr, can certainly agree with you on the slow computer problems, its the reason I no longer work from home.
That's assuming that your javascript file is in the main theme folder, i.e. the same level as default.php. If it's in another subfolder, you'll need to put that between the getThemePath part and your filename. $this->getThemePath just prints the path to the theme folder, i.e. "/themes/name_of_theme". And so of course, if your javascript file is not in the theme folder, like maybe it's in the top-level /js folder, then you don't need the getThemePath call, just make it src="/js/myjs.js".
The best place to put the script tag is in the <head> section of your header.php. It probably doesn't matter whether it comes before the 'header_required' element or after.