jQuery callback in plugin

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

jQuery callback in plugin

XleiteX

Hi all,

Guys, i have a question about how to pass a value to a callback inside
a plugin...
i figure something like that...
Ex:

$.plugin("[{n:"maria",v:"hh"},{n:"joao",v:"ss"},{n:"obina",v:"ass"}]",
             {resizable:false,function(returnedfromplugin_ithink){alert
(returnedfromplugin_ithink);} });

$.fn.plugin=function(source,opts){
     //definitions
     var defs={
        resizable: true,
        onClick:function(v){}
     }
     //
     var opt=$.extend(defs,opts);
     //when i click on the div
     //it pass a id or innerHTML values to
     //the callback, but i dont know how to do this...
     $.each(source,function(n,obj){
           $.each(obj,function(n2,obj2){
                 //here make some DOM function and the callback
                 //.................................................................so
what do i do here?...
                 $('<DIV></DIV>').attr({id:obj2}).html(obj2).click
(opt.onClick??(obj2)??).appendTo('body');
           });
     });
};

a really apreciate any idea or opnion or either any kinda of
example...
please  help a  jquery noob!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "jQuery Plugins" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/jquery-plugins?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: jQuery callback in plugin

XleiteX

Hi all, i did the trick!....hahahaa

//code solved
 $.plugin("[{n:"maria",v:"hh"},{n:"joao",v:"ss"},
{n:"obina",v:"ass"}]",
              //the callback must have a name... simply "call"
              {resizable:false,call:function(returnedfromplugin_ithink)
{
              alert(returnedfromplugin_ithink);} });

 $.fn.plugin=function(source,opts){
      //definitions
      var defs={
         resizable: true,
         //i dont need it anymore!
         //onClick:function(v){}
      }
      //
      var opt=$.extend(defs,opts);
      //when i click on the div
      //it pass a id or innerHTML values to
      //the callback, but i dont know how to do this...
      $.each(source,function(n,obj){
            $.each(obj,function(n2,obj2){
                  //here make some DOM function and the callback
                  //so i use apply to pass values to callback
                  //
                  $('<DIV></DIV>').attr({id:obj2}).html(obj2)
                    .click(function(){opt.call.apply(this,
                      [obj2]);}).appendTo('body');
            });
      });

 };

i found it here ... http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery
sorry for my poor english...someone here knows the diference of .bind
() and .click() such as speed or better method?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "jQuery Plugins" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/jquery-plugins?hl=en
-~----------~----~----~----~------~----~------~--~---