Activity Stream
48,167 MEMBERS
61003 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 4 of 4
  1.     
    #1
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com

    Default Creating a jQuery plugin

    Thought i would share my knowledge of jQuery plugins !

    Ok so lets get started!

    Information:
    jQuery plugins are functions that are stored within jQuery and calledwhen the function is used on an element, jQuery also passes in the DOM element into the function so you can directly work with that element!

    Plugin Structure:
    The structure that i like to uses is like so..
    PHP Code: 
    (function(){
        $.
    fn.#PLUGIN_NAME# = function(){
        
    }
    })($) 
    Ok so first lets just create a sample plugin so you can see how to do the
    basics

    PHP Code: 
    (function(){
        $.
    fn.changeVal = function(newVal){
           $(
    this).val(newVal);
        }
    })($) 
    Ok so looking at the above block of code you will notice the following:
    1. The plugin is called changeVal
    2. Were getting 1 parameter newVal
    3. Were using the keyword this to select the element
    4. then were using regular jQuery functions to change the val


    and this would be used like so

    PHP Code: 
    $('a.changeMe').changeVal('New Value here'); 
    ok so lets say we have a little more complex function!, lets do it!

    PHP Code: 
    (function(){
        $.
    fn.externalLinks = function(){
            $(
    this).each(function(){ //As were dealing with multiple itesm we loop this
            //here this is now the single a element.
                
    if($(this).attr('href').match(/http\:\ /\ //gi))
                
    {
                     
    //The link has http:// within it! so we add some external attrubutes.
                    
    $(this).attr('target','_blank').addClass('external_link');
                }
            });
        }
    })($) 
    Ok so above you can see that its getting a little more complicated.

    the usage of this is really simple
    PHP Code: 
    $('a').externalLinks(); 
    This should get you started of with jQuery plugins and before you go take a look at this plugin I created for Litewarez.

    This will give you a little more idea of what you can do with plugins!

    PHP Code: 
    (function($){
        $.
    fn.lwcookie = function(namevalueoptions){
        if (
    typeof value != 'undefined') { // name and value given, set cookie
            
    options options || {};
            if (
    value === null) {
                
    value '';
                
    options.expires = -1;
            }
            var 
    expires '';
            if (
    options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
                var 
    date;
                if (
    typeof options.expires == 'number') {
                    
    date = new Date();
                    
    date.setTime(date.getTime() + (options.expires 24 60 60 1000));
                } else {
                    
    date options.expires;
                }
                
    expires '; expires=' date.toUTCString(); // use expires attribute, max-age is not supported by IE
            
    }

            var 
    path options.path '; path=' + (options.path) : '';
            var 
    domain options.domain '; domain=' + (options.domain) : '';
            var 
    secure options.secure '; secure' '';
            
    document .cookie = [name'='encodeURIComponent(value), expirespathdomainsecure].join('');
        } else { 
    // only name given, get cookie
            
    var cookieValue null;
            if (
    document cookie && document .cookie* != '') {
                var 
    cookies document .cookie.split(';');
                for (var 
    0cookies.lengthi++) {
                    var 
    cookie jQuery.trim(cookies[i]);
                    
    // Does this cookie string begin with the name we want?
                    
    if (cookie.substring(0name.length 1) == (name '=')){
                        
    cookieValue decodeURIComponent(cookie.substring(name.length 1));
                        break;
                    }
                }
            }
            return 
    cookieValue;
        }
    };
    })($ || 
    jQuery
    the usage of this function is not $().NAME but $.NAME as its not using any attributes !

    Hope this helps you - Say thanks
    litewarez Reviewed by litewarez on . Creating a jQuery plugin Thought i would share my knowledge of jQuery plugins ! Ok so lets get started! Information: jQuery plugins are functions that are stored within jQuery and calledwhen the function is used on an element, jQuery also passes in the DOM element into the function so you can directly work with that element! Plugin Structure: The structure that i like to uses is like so.. Rating: 5
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  2.   Sponsored Links

  3.     
    #2
    Member
    Seems alittle advanced for the new people this might be useful to them

    http://www.ilovecolors.com.ar/create-jquery-plugin/
    Signature too big, removed by staff.

  4.     
    #3
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    Advanced :/ its basics :/ cant get any basic'er
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  5.     
    #4
    Member
    :\ ok :\ well i was just sayin :\
    Signature too big, removed by staff.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. JQuery and RegExr Help :|
    By Porsche_maniak in forum Web Development Area
    Replies: 4
    Last Post: 1st Jun 2012, 12:26 AM
  2. JQuery help
    By xElliex in forum Web Development Area
    Replies: 5
    Last Post: 25th Aug 2011, 10:38 PM
  3. Anyone who knows Javascript / jquery / Css
    By Czechi in forum Completed Transactions
    Replies: 5
    Last Post: 17th Aug 2010, 06:41 AM
  4. jQuery tooltip help
    By devilzkrazy in forum Technical Help Desk Support
    Replies: 0
    Last Post: 22nd May 2010, 04:24 PM
  5. Introduction to jQuery
    By litewarez in forum Tutorials and Guides
    Replies: 4
    Last Post: 14th Jan 2010, 02:51 AM

Tags for this Thread

BE SOCIAL