Skip to main content

Posts

Showing posts from November, 2011

Prevent caching in IE ajax response

You must have noticed that IE will show the cached response for the ajax calls. To prevent this, just add these lines before outputting any content as response: <?php header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); ?>

Using jquery in joomla

Joomla uses mootools by default. If you want to use another javascript library like jquery in your site.... 1. You can use a plugin like SC Jquery and then either add code in the admin panel like: $("#contactus_reset").click(function() { $("[rel=error_label]").css("display","none"); }); or write the code inside your template index.php file, under head tag, like: <script type="text/javascript"> $(function() {     $(".anyClass").jCarouselLite({         btnNext: ".next",         btnPrev: ".prev"     }); }); </script> And better add these lines inside your template index.php file, under head tag to avoid jquery conflicts. <?php $document = &JFactory::getDocument(); $document->addScriptDeclaration ( 'jQuery.noConflict();' ); ?> 2. There is another way to enable jquery support in your site. Here are the steps i did to enable jquery support in my site:

Javascript code in php

An example to write javascript code in php, escaping quotes: Suppose this is your requirement. You have to display an image, which has an onclick event, to some function that must accept dynamic php parameters. This is the static code: <img width="210" border="0" onclick="javascript:load_user('qrp3p0s42ebcsf','local','downloads/882381283.pdf',0);" style="cursor:pointer;" src="images/stories/watch-now.png"> So first what we do is, prepare the javascript onclick part dynamically in php: $img_js = ' onclick="javascript:load_user(\''.$user['id'].'\',\''.$user['access'].'\',\''.$file_path.'\',0);" '; Then add that to the image code. Now this is the final code we write entirely in php: $user_img is the dynamic image url. <?php echo '<img width="210" border="0" style="cursor:pointer;&

Joomla uploading a file in custom component in admin

Did you ever create a custom component in joomla, that has a functionality of admin uploading a file?  Reference There are 3 things that you need to be aware of: First is under your form attribute, please make sure that you have enctype="multipart/form-data". Second thing is when you grab the file at server site, please make sure the name is same as what you named on your HTML. In this case is, $file = JRequest::getVar( 'image', '', 'files', 'array'); Then make sure you include the necessarylibraries in your admin model file: jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); Form code: <form action="index.php" method="post" name="adminForm" id="adminForm" enctype="multipart/form-data">   <input class="inputbox" name="image" type="file" id="upload_file" /> </form> PHP code in your comp

Resize image php

The following code resizes a png image and displays it as a jpg image: <?php     header("content-type: image/jpg");     $file_name = 'img.png';         $srcsize = getimagesize($file_name);         $ext = strrchr($file_name,'.');     $ext = strtolower($ext);               if($ext == ".jpg"){                $new_img_big = imagecreatefromjpeg($file_name);     }elseif($ext == ".png"){                $new_img_big = imagecreatefrompng($file_name);     }elseif($ext == ".gif"){                $new_img_big = imagecreatefromgif($file_name);     }         $resized_img_big = imagecreatetruecolor(100, 100);     imagecopyresized($resized_img_big, $new_img_big, 0, 0, 0, 0, 100, 100, $srcsize[0], $srcsize[1]);              imagejpeg($resized_img_big);                  /*imagedestroy($src_img);     imagedestroy($dst_img);*/ ?>

javascript add attribute to html dom elements

This javascript function hides all the labels in the document, that have a rel attribute: <script type="text/javascript"> function hide_labels() {        var arr = document.getElementsByTagName("label");     var arr2 = [];             for (i = 0; i < arr.length; i++) {     if(arr[i].hasAttribute("rel"))     arr2.push(arr[i]);         }     //console.log(arr2);         for (i = 0; i < arr2.length; i++) {     arr2[i].setAttribute('style', 'display:none;');     } } </script>