Add js code to create layout in controller in magento - magento

I am creating a blocks in my controller using
$this->_addContent($this->getLayout()->createBlock('mymodule/mymodule_newpage')
Is there any way how I can embed js code into the addcontent function. I dont want to add complete js but a chunk of code.
Thanks

You can add that particular js file in your static block (mymodule/mymodule_newpage) by writing it under content tab.
<script type="text/javascript" src="http://your_site.com/js/your_js_file.js"></script>
Though I am not 100% sure.Give a try.Goodluck.

You can try:
$this->_addContent($this->getLayout()->createBlock('core/text')->setText('your script here'));
Obs: I could not make sintax highlight fpr PHP work anymore...

Related

Google code prettify thinks css #id's are line comment. What am I doing wrong?

Example CSS
#wrap{margin:20px}
Code prettify wraps the whole line in .com
<span class="com">#wrap{margin:20px}</span>
Somebody has a similar issue here.
Where someone answers "Are you loading lang-css.js?".
Here's what I'm loading in the footer.
<script src="/js/google-code-prettify/lang-css.js"></script>
<script src="/js/google-code-prettify/prettify.js"></script>
I can see both of them with web inspector. I tried changing the order and loading them from the header. I'm using the latest version.
All help is greatly appreciated :)
Thanks!
The order you link to the javascript files matters. You need to call the base code (prettify.js) first followed by the css specific code (lang-css.js). You can place the script tags either in the head section or at the end of the document... both work but placing at the end of the document will speed up the page load.
<script src="/js/google-code-prettify/prettify.js"></script>
<script src="/js/google-code-prettify/lang-css.js"></script>
You will also need to ensure that you are linking the stylesheet in the head of your document.
<link rel="stylesheet" type="text/css" href="/css/prettify.css">
You also need to add the correct classes your pre tag(s). The syntax-highlighting functions contained in lang-css.js will not be called without adding the class "lang-css" to the <pre> tag.
<pre class="prettyprint lang-css linenums">
Finally, make sure you call the "prettyPrint()" function on page load.
<body onload="prettyPrint()">

jQuery conflict while using jslider with prototype and noConflict

Trying to resolve $ conflict between prototype.js and jQuery.js because I need to use jSlider which requires the jQuery library.
I add jQuery.noConflict() at the end of the jquery.js file then in the jslider.js file I change $._roundNumber to jQuery._roundNumber. Yet I still get an error which says jQuery._roundNumber is not a function. Please help.
Here is the example of integrating prototype and jquery...May check you did the right thing or not.?
<script src="prototype.js"></script>
<script src="effects.js"></script>
<script src="jquery.js"></script>
jQuery.noConflict();
jQuery(document).ready(function($){
jQuery("a").click(function(){
Effect.Shake('shake_demo');
});
});
<div id="shake_demo" style="width:150px; height:40px; background:#ccc; text-align:center;">
Click me to shake!
</div>
And now for rounding the number you can use this code:
var txt=jQuery('#txtBox').val());
var amt = parseFloat(txt);
alert(amt.toFixed(2);
https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Number/toFixed
Fixed. Just realised that the reason jQuery.noConflict() was not working was because jQuery was already being used in the template page that I was including in my current page so the problem was two fold:
'$()' which is the default jQuery selector was clashing with prototype.js which Tapestry includes by default
when I added jQuery.noConflict() at the end of my jquery.new.js file then tried using 'jQuery()' as the selector it did not work either because a different version of jquery (let's call this jquery.old.js) was already included in the template page (which I was including in my current page). To get the jquery.old.js to work with prototype.js, the previous developer already used jQuery.noConflict() so the 'jQuery()' selector was already taken as well.
Fix: I added $j2 = jQuery.noConflict() at the end of jquery.new.js file then I used '$j2()' selector in my new library that uses the jSlider and I also modified the selector in the jSlider.js file. It all works well now.
I am leaving both jquery.new.js and jquery.old.js file in the project (rather than using just one) because the template page which uses the older jquery version is used all over the site (I don't want to test the entire site after changing this) while the new component I'm adding needs the new version of jquery (jquery.new.js) file. And yes I know it's better to add the no conflict commands at the top of my html page rather than at the end of the js library files - will change that after this update on stack overflow :)

Add Infinity Scroll Down in Joomla

How do I integrate Jquery code for Infinity/Autopager Scroll down in Joomla. And If possible the scroller to work on Chosen Articles.
if you want to add jQuery into your joomla made site then it is easy to load a jquery file like:
Add the following codes into your index.php file you will find this file in your template directory like : joomla/templates/rhuk_milkyway/index.php now simple open it and add the following code after <link> tab
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
now before starting your own jquery codes it is must to make your codes without conflicting with mootools and other, and for this just simple add jQuery.noConflict(); and place jQuery instead of $ for example:
<script>
jQuery.noConflict();
// now your codes like
jQuery('#someid').each(function(i, e){});
</script>

Where to put jQuery code for DOM manipulation in Codeigniter

I have some jQuery code that deals with DOM manipulation, simple stuff like fadeIn(), etc...
Is the best practice to put
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
and any script associated with manipulating the HTML on a CI view right on the view.php file?
Thanks
That's eminently reasonable. If you're using jQuery you should probably wrap your manipulation code in a ready call.

dojo.xhrGet(): how to execute inline javascript?

simple question: How do I execute inline javascript in a HTML page snippet loaded with dojo.xhrGet()?
Being new to dojo I'm a bit confused this doesn't just work like in JQuery ...
Can anyone help??
Thanks,
thomas
We need more details! If you don't provide enough info you'll never get the right answer.
Anyway, if the HTML snippet is loaded inside a ContentPane, use a dojox.layout.ContentPane (is an extension to dijit.layout.ContentPane providing script execution).Or you could use one of the script tags that dojo accept. E.g:
<div dojoType=...>
<script type="dojo/connect" event="functionToConnectTo">
//javascript here
</script>
</div>
More valuable information about script tags on dojo parser reference.

Resources