Tuesday, February 21, 2012

jQuery checkbox act like a radio button

This is a simple code to make your checkbox act like a radio button. Try this simple code and find out.
jQuery('.chck').click(function(){
    jQuery('.chck:checked').not(this).removeAttr('checked');
});

How to Use:
html
<input type='checkbox' name='mygroup1' value='1' class='unique'>
<input type='checkbox' name='mygroup2' value='2' class='unique'>
<input type='checkbox' name='mygroup3' value='3' class='unique'>

jQuery
$('input.unique').click(function() {
    $('input.unique:checked').not(this).removeAttr('checked');
});

Friday, February 17, 2012

jQuery bold specific number of word


function boldWord(name,num){
var x=jQuery(name).text();
var splitx=x.split(" ");
var new1="";
var old="";
for(var y=0; y<num;y++){
    old+=splitx[y]+" ";
    new1+="<b>"+splitx[y]+"</b> ";
}
var finalCont=jQuery(name).html().replace(old,new1);
jQuery(name).html(finalCont);
}

boldWord("class or id",3)

jQuery limit word plugin

This is a jquery plug in that limits the number words to display depending on how many words you want to display.

(function($){
    $.fn.limitWord= function(options){
        var defaults={
        /* by default */
            words:5
        }
        var options=$.extend(defaults,options);
        return this.each(function(){
            var paragraph=$(this).text();
            var splitSpace = paragraph.split(" ");
            var holder = options.words;
            var newTexts='';
            for(var i=0;i<holder;i++){
                newTexts += splitSpace[i]+' ';
            }
            $(this).html(newTexts); 
        });
    }
})(jQuery);

How to use:
jQuery("class or id here").limitWord({
words:5 /* please specify the number of words to be displayed */
});

Thursday, February 16, 2012

business catalyst generic secure zone redirect

Generic secure zone in BC doesn't support redirect to other pages.  So here's a solution for your problem.
How to use this function:
/*
Put this after
//<![CDATA[ 
//]]>
*/
function genericRedirect(url){
    var pathName= window.location.pathname;
    var splitThis = pathName.split("?");
    if(splitThis [0]=="/Default.aspx"){
        window.location=(url);
    }
}
/*
Then call or use the function with your landing page's url or link.
*/
genericRedirect("/your url here!!");

Hope this will help.

Wednesday, February 15, 2012

jQuery display url and redirect functions

My own redirect function and get or display site's url. This is to simplify your code by using functions.
function redirectURL(url){
    window.location.href=url;
}

How to use:
jQuery(document).ready(function(){
if(condition){
      redirectURL("http://www.google.com");
}
else{
      redirectURL("http://www.yahoo.com");
});


function getURL(){
    return window.location.href;
}

How to use:

jQuery(document).ready(function(){
  var siteURL=getURL();
  alert(siteURL);
});

Thursday, February 9, 2012

how to make jQuery plug in with options

 This is sample on how to make a jquery plugin with option. This is a multi step plugin and it is very useful in forms. Hope this will help!..



    (function($){
        $.fn.rPrevNext = function(options){
   
            // the default options
            var defaults = {   
                autoNavigation:true,
                prevCaption:'prev',
                nextCaption:'next',
                navImage:false,
                prevImage:'',
                nextImage:'',
                pageContainer:'pageCont',
                pageOf:false,
                pagination:false
            }           
            // to override the defaults of each option
            var options = $.extend(defaults, options);   
           
            return this.each(function(){                                   
                // declaration of variables       
                var cont = $(this);
                var pages = $(this).children();
                var pagef = cont.children().first();
                var pagel = cont.children().last();
               
                //if TRUE - enable auto navigation , if FALSE - manually put the navigation
                //put a class prevP and nextP in your buttons.

                if(options.autoNavigation){
                //set the navigation either pure text/image
                    if(options.navImage){
                        //if TRUE - image

                        cont.append('<a href="javascript:void(0);" class="prevP"><img src="'+ options.prevImage +'"/></a> <a href="javascript:void(0);" class="nextP"><img src="'+ options.nextImage +'"/></a>');   
                    }
                    else{
                        //if false - text
                        cont.append('<a href="javascript:void(0);" class="prevP">'+ options.prevCaption +'</a> <a href="javascript:void(0);" class="nextP">'+ options.nextCaption +'</a>');   
                    }               
                }
                //if TRUE - display example "Page 1 of 5"
                //if FALSE - manually put a <div>,<span>or etc.. and put a class="pageCounter", this will display your current page number
                //if FALSE - manually put a <div>,<span>or etc.. and put a class="pageLength", this will count the number of pages you have

                if(options.pageOf){
                    cont.after('<div class="pageCont">Page <span class="pageCounter"></span> of <span class="pageLength"></span>.</div>');
                }
               
                //if TRUE - automatically display pagination after container       
                //if FALSE - manually put a <div> and class it with pagi

                if(options.pagination){
                    cont.after('<div class="pagi"></div>');
                    var x=pages.length;
                    for(var y=1; y<=x;y++){
                        jQuery(".pagi").append('<a href="javascript:void(0);" class="'+y+'">'+y+'</a>');
                    }
                }
                else{
                    var x=pages.length;
                    for(var y=1; y<=x;y++){
                        jQuery(".pagi").append('<span><a href="javascript:void(0);" rel="'+y+'">'+y+'</a></span>');
                    }
                }
                // set the page containers class
                pages.each(function(){
                    $(this).addClass(''+ options.pageContainer +'').css("display","none");
                });   
               
                // onload functions, css or any codes           
                cont.ready(function(){
                    $(".current").css("display","block");
                    cont.css("clear","both");
                    showFirstPage();
                    navShowHide();
                    pageNumber();
                    $(".pagi a").first().addClass("oncurr");                   
                });
               
                // set onclick for previous
                $("a.prevP").click(function(){  
                    $(".current").hide();
                    $(".current").prev("div").addClass("current").show();
                    $(".current").eq(1).removeClass("current");
                    navShowHide();
                    pageNumber();
                    addCurr();
                });
               
                // set onclick for next
                $("a.nextP").click(function(){  
                    $(".current").hide();
                    $(".current").next("div").addClass("current").show();
                    $(".current").eq(0).removeClass("current");
                    navShowHide();
                    pageNumber();
                    addCurr();
                });       
                // set onclick for the pagination numbers
                $(".pagi a").click(function(){
                    var z=jQuery(this).attr("rel");
                    var disPlay=pages.eq(z-1);
                    $(".pagi a").removeClass("oncurr");
                    $(this).addClass("oncurr");                   
                    pages.removeClass("current").css("display","none");
                    disPlay.addClass("current").css("display","block");
                    navShowHide();
                    pageNumber();
                });
                // -----R-------------------N------ //
                // -----E------FUNCTIONS----E------ //
                // -----Y-------------------IL----- //
               
                // for the navigation(next/previous) either show or hide

                function navShowHide(){
                 var isFirst=pagef.hasClass("current");
                    if(isFirst){
                        $(".prevP").css("display","none");
                    }
                    else{
                        $(".prevP").show();
                    }
                 var isLast=pagel.hasClass("current");
                    if(isLast){
                        $(".nextP").css("display","none");
                    }
                    else{
                        $(".nextP").show();
                    }
                }       
                // to show the first page of the multi-step
                function showFirstPage(){
                    pagef.addClass("current").css("display","block");
                }
                // to display the current page number(must be inside class="pageCounter")
                //and the total number of pages (must be inside class="pageLength")

                function pageNumber(){
                    var pageL=pages.length;
                    pages.each(function(a,b){
                        var found =jQuery(this).hasClass("current");      
                        jQuery(".pageLength").text(pageL);
                        if(found){
                            jQuery(".pageCounter").text(a+1);       
                        }
                    });
                }
                // add class oncurr to the pagination
                function addCurr(){
                    pages.each(function(x,y){
                        var curr=$(this).hasClass("current");                       
                        if(curr){
                            jQuery(".pagi a").removeClass("oncurr");
                            jQuery(".pagi a").eq(x).addClass("oncurr");
                        }
                    });                   
                }
                               
            });   
        };
    })(jQuery);
/*
*    NOTE:Don't put any comma(,) after the last option because
*    it is considered as an error in IE. Therefore leave it
*    blank.
*
*    Default setting of the plug-in
*            autoNavigation:true,
*            prevCaption:'prev',
*            nextCaption:'next',
*            navImage:false,
*            prevImage:'',
*            nextImage:'',
*            pageContainer:'pageCont',
*            pageOf:false,
*            pagination:false
*
*    How to use this plugin.
*    Example:   
*        jQuery("#container").rPrevNext({   
*            autoNavigation:true,   
*            prevCaption:'PREV',
*            nextCaption:'NEXT',
*            navImage:false,
*            pageContainer:'box',
*            prevImage:'images/btnPrevious.png',
*            nextImage:'images/btnNext.png'
*            pageOf:true,
*            pagination:true
*        });
*/

Wednesday, February 8, 2012

javascript open new window

<a href="javascript:void(0);" onclick="window.open('url','windowName','menubar=0,resizable=1,width=350,height=250');">text here</a>

Thursday, February 2, 2012

Wordpress Error and Solutions

Unable to create directory /wp-content/uploads/2009/09. Is its parent directory writable by the server? - wordpress error

Solutions:
1. Change the directory permission to 777. Apply this to its subdirectories or files so that it will become editable or writable.


2. In Media, check if  its "Store uploads in this folder" is “wp-content/uploads“.

3.Also try to add  define(‘UPLOADS’, ‘wp-content/new_folder’); after require_once(ABSPATH.’wp-settings.php’); in your wp-config.php file.