Thursday, December 12, 2013

Joomla load module anywhere

if (!class_exists( 'CarsModelCars' )){
   JLoader::import( 'cars', JPATH_BASE . DS . 'components' . DS . 'com_cars' . DS . 'models' );
}

Now create an object for that class

Thursday, December 5, 2013

Use JQuery Squeeze box for modal display

To use modal pop up in joomla, there is an in-built javascript plugin Squeeze box based on the mootools library.

JHtml::_('behavior.modal');

This will add the squeeze box modal library.

And then add a class "modal" to the anchor.

Example
<a href="http://www.example.com/somepage.html" 
class="modal" rel="{size: {x: 700, y: 500}, handler:'iframe'}" 
id="modalLink1">
Click here to see this interesting page</a>

The above will load a iframe in modal box.

Reference
http://www.spiralscripts.co.uk/Joomla-Tips/using-modal-windows-with-joomla.html

Monday, December 2, 2013

Check if a var available in jQuery

This functions returns value 1 if var has some value and 0 when var is not present

jQuery.fn.exists = function(){return this.length>0;}

if ($(selector).exists()) {
    // Do something
}

Wednesday, October 30, 2013

Find Base Path using PHP

Find base url path and absolute URL

define('ABSPATH', str_replace('\\', '/', dirname(__FILE__)) . '/');

$tempPath1 = explode('/', str_replace('\\', '/', dirname($_SERVER['SCRIPT_FILENAME'])));
$tempPath2 = explode('/', substr(ABSPATH, 0, -1));
$tempPath3 = explode('/', str_replace('\\', '/', dirname($_SERVER['PHP_SELF'])));

for ($i = count($tempPath2); $i < count($tempPath1); $i++)
    array_pop ($tempPath3);

$urladdr = $_SERVER['HTTP_HOST'] . implode('/', $tempPath3);

if ($urladdr{strlen($urladdr) - 1}== '/')
    define('URLADDR', 'http://' . $urladdr);
else
    define('URLADDR', 'http://' . $urladdr . '/');

unset($tempPath1, $tempPath2, $tempPath3, $urladdr);

Wednesday, October 9, 2013

Filter an array of objects using object's property

Iterate through the array and return true or false based on the condition

$new_array = array_filter($array, function($obj){
    if (isset($obj->admins)) {
        foreach ($obj->admins as $admin) {
            if ($admin->member == 11) return false;
        }
    }
    return true;
});

Disable Native tooltip in HTML with help of JQuery

This will remove the title attribute on mouseover and then adds the title back on mouse out.

$(document).ready(function() {
    $('[title]').mouseover(function () {
        $this = $(this);
        $this.data('title', $this.attr('title'));
        // Using null here wouldn't work in IE, but empty string will work just fine.
        $this.attr('title', '');
    }).mouseout(function () {
        $this = $(this);
        $this.attr('title', $this.data('title'));
    });
});


Friday, August 30, 2013

List of all RSS tags that can be applied

ElementDescription
<author>Specifies the email address of the author of an RSS item.
<category>Specifies a category for an entire RSS feed or for individual RSS items.
<channel>Required. Describes an RSS feed with a title, description, and a URL where the RSS can be found.
<cloud>Sets up processes that are automatically notified when a feed has been updated.
<comments>Specifies a URL where comments about an RSS item can be found.
<copyright>Sets copyright information for an RSS feed.
<description>Required. Sets a description for an RSS feed/item.
<docs>Specifies a URL where the documentation for the RSS version used in the RSS file can be found.
<enclosure>Specifies a media file to be included with an RSS item.
<generator>Specifies the program used to create your RSS feed.
<guid>Stands for Globally Unique Identifier. Sets a string that uniquely identifies an RSS item.
<image>Specifies an image to be displayed with an RSS feed (must be gif, jpeg, or png).
<item>Required. Sets items in an RSS feed.
<language>Specifies the language your RSS feed is written in.
<lastBuildDate>Specifies the most recent time the content of an RSS feed was modified.
<link>Required. Specifies the URL where an RSS feed/item content can be found.
<managingEditor>Specifies the email address of the editor of the content of the feed.
<pubDate>Specifies the publication date for an RSS feed/item.
<source>Specifies the source of an RSS item (if it came from another RSS feed)
<skipDays>Specifies the days of the week when feed readers should not update an RSS feed.
<skipHours>Specifies the hours of the day when feed readers should not update an RSS feed.
<textInput>Specifies a textbox to be displayed with an RSS feed.
<title>Required. Sets the title of an RSS feed/item.
<ttl>Stands for Time To Live. Specifies how many minutes your RSS feed can stay cached before it is refreshed.
<webMaster>Specifies the email address of the webmaster of an RSS feed.

Joomla find current page URL with query string

$uri = & JFactory::getURI();
$pageURL = $uri->toString();
echo $pageURL;


This will find the absolute path, but will not fetch query string
$pageURL = JURI::current();
echo $pageURL;


Thursday, August 8, 2013

Find whether the element in in array JQuery

Use jQuery inArray function

jQuery.inArray('value_to_find', array_var);

Delete a specific element in Javascript Array

TO delete a particular element in javascript array, find the index of that element and the use splice method

For example:

var sample_array = ['one', 'two', 'three'];
var index = sample_array.indexOf(id);
sample_array.splice(index, 1);

Note ; Splice method can be used other different cases of accessing and deleting element with help of parameters. Refer Splice() reference.

Create a Cookie in Javascript

Create a cookie in javascript

document.cookie="unCheckedIds="+c_ids+";path=/";

Here unCheckedIds is the name of the Cookie and c_ids will have the value of the Cookie. Path "\" is used to use the cookie in the domain level and not for the page level.

If path is not given, by default it will opt for page level.

Other parameters like path are expiry and domain.

Get a Cookie in Javascript

This function will return a cookie saved. Just call this function with the name of a cookie as a parameter.


function getCookie(c_name)
    {
        var c_value = document.cookie;
        var c_start = c_value.indexOf(" " + c_name + "=");
        if (c_start == -1)
        {
            c_start = c_value.indexOf(c_name + "=");
        }
        if (c_start == -1)
        {
            c_value = null;
        }
        else
        {
            c_start = c_value.indexOf("=", c_start) + 1;
            var c_end = c_value.indexOf(";", c_start);
            if (c_end == -1)
            {
                c_end = c_value.length;
            }
            c_value = unescape(c_value.substring(c_start,c_end));
        }
        return c_value;
    }     

Find Children of a Class or ID

To find the children of a a specific div or any class or ID in jQuery

trs = $('#jevents_body').find('table.day-list > tbody > tr');

Joomla JEvents Category Filtering

(function ($){
 var ready = (function(){
  setUpCalModule();
 });


 // events calendar category checkbox filtering
 var setUpCalModule = (function(){
   var left, trs;
   left = $('.content-area-left').children('.moduletable');
   if (!left.length) return;

   trs = $('#jevents_body').find('table.day-list > tbody > tr');

   left.on('change','#jevent-mod-cat-checks', function(){
     var checks = $(this).find('input[type="checkbox"]'),
 checked = checks.filter(':checked'),
 notChecked = checks.not(checked);

     checked.each(function(){
      deleteCookieValue(this.value);
trs.filter('[data-cat="'+this.value+'"]').show();
     });

     notChecked.each(function(){
      setCookie(this.value);      
trs.filter('[data-cat="'+this.value+'"]').hide();
     });

   });
 });

 // get ready ... go!
 jQuery(document).ready(ready);

})(jQuery);

Friday, July 19, 2013

Render modukes inside componet - Joomla

<?php
 $modules =& JModuleHelper::getModules('contact');
 foreach ($modules as $module)
 {
echo JModuleHelper::renderModule($module);
 }
 ?>

Where 'contact' is the name of the position