That's most of what you need to do, but you also need to reassign the
prototype after overriding the init:

$.prototype.init.prototype = $.prototype;

Check out the last few lines of the livequery plugin to see how to
modify jQuery's init method.


On Aug 31, 1:40 am, moester <[EMAIL PROTECTED]> wrote:
> I had a similar need.  Wanted to override the default load()
> functionality, and needed the original selector.  I tried overriding
> jQuery.init to save the passed in selector, eg,
>
> jQuery.fn.extend(jQuery.fn, {
>
>   _init : jQuery.fn.init,
>   _selector : '',
>
>   init : function (selector, context) {
>
>      if (typeof of selector == 'string')
>        this._selector = selector;
>
>     return this._init(selector, context);
>
>   }
>
> })
>
> But couldn't get it to work.  The init method doesn't seem to be
> (trivially) extendable.  I think it'll be useful to have, and
> hopefully somebody will know the way....
>
> On Aug 30, 2:23 pm, Tzury <[EMAIL PROTECTED]> wrote:
>
> > Say a user called $('div.foo') I would like to get this 'div.foo' from
> > within my plug-in context.
>
> > I look through the code and couldn't find a property which contain
> > this data;
>
> > I was thinking that 'query' is the appropriate name for this property
>
> > example usage:
>
> > $.fn.MyPlugIn = function (){
> >     if (/table|thead|tbody|th|tr|td/.test($.query){
> >         // do the table thing
> >     }
> >     else {
> >        // do the chair thing ;-)
> >     }
>
> > }
>
> > $('table').MyPlugIn();
> > $('div').MyPlugIn

Reply via email to