[jQuery] Re: How to retrieve jQuery.query?
Ah, damn you are right... I havn't looked at the hole code from the livequery plugin... at the end there is a new init method... On 4 Sep., 13:01, Tzury <[EMAIL PROTECTED]> wrote: > On Sep 4, 10:01 am, "[EMAIL PROTECTED]" > > <[EMAIL PROTECTED]> wrote: > > There is allready such an attribute > > try this: > > > $("#myID .MyClass mychildren").myfunction() { > > console.log(this.selector); // "#myID .MyClass mychildren" > > > } > > $.fn.ShowSelector = function () { return this.selector; } > console.log($('input.foo').ShowSelector()); > > yields undefined
[jQuery] Re: How to retrieve jQuery.query?
On Sep 4, 10:01 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > There is allready such an attribute > try this: > > $("#myID .MyClass mychildren").myfunction() { > console.log(this.selector); // "#myID .MyClass mychildren" > > } $.fn.ShowSelector = function () { return this.selector; } console.log($('input.foo').ShowSelector()); yields undefined
[jQuery] Re: How to retrieve jQuery.query?
There is allready such an attribute try this: $("#myID .MyClass mychildren").myfunction() { console.log(this.selector); // "#myID .MyClass mychildren" } On 4 Sep., 01:19, Tzury <[EMAIL PROTECTED]> wrote: > I just released a new version of the HotKeys plug in which was the > reason I needed this new .query property > see more athttp://code.google.com/p/js-hotkeys/wiki/about > > Thank you all, > Tzury > > On Sep 1, 3:46 pm, Ariel Flesler <[EMAIL PROTECTED]> wrote: > > > prevObject is internal, you don't need to know about it. Just use > > end() instead. > > > -- > > Ariel Fleslerhttp://flesler.blogspot.com/ > > > On Sep 1, 9:19 am, Tzury <[EMAIL PROTECTED]> wrote: > > > > > jQuery.fn.find=function( selector ) { > > > > this.query=selector; //this is the only line you have to modify > > > > > var elems = jQuery.map(this, function(elem){ > > > > return jQuery.find( selector, elem ); > > > > }); > > > > return this.pushStack( /[^+>] [^+>]/.test( selector ) || > > > > selector.indexOf("..") > -1 ? > > > > jQuery.unique( elems ) : elems ); > > > > > } > > > > > Now you can get the query string: > > > > $('body .class').prevObject.query //->'body .class' > > > > $('body').find('.class').prevObject.prevObject.query //->'body' > > > > but > > > > $('#id').prevObject.query //->undefined > > > > $().find('#id').prevObject.query //->'#id' > > > > here is the final tweak, > > > (after adding this modified find method) > > > > query = (this.prevObject && this.prevObject.query) || this[0]; > > > > I strongly believe that such property should be added to the main > > > distro of jQuery. > > > After all, the idea of find-and-modify approach - one of jQuery > > > fundamentals.
[jQuery] Re: How to retrieve jQuery.query?
I just released a new version of the HotKeys plug in which was the reason I needed this new .query property see more at http://code.google.com/p/js-hotkeys/wiki/about Thank you all, Tzury On Sep 1, 3:46 pm, Ariel Flesler <[EMAIL PROTECTED]> wrote: > prevObject is internal, you don't need to know about it. Just use > end() instead. > > -- > Ariel Fleslerhttp://flesler.blogspot.com/ > > On Sep 1, 9:19 am, Tzury <[EMAIL PROTECTED]> wrote: > > > > jQuery.fn.find=function( selector ) { > > > this.query=selector; //this is the only line you have to modify > > > > var elems = jQuery.map(this, function(elem){ > > > return jQuery.find( selector, elem ); > > > }); > > > return this.pushStack( /[^+>] [^+>]/.test( selector ) || > > > selector.indexOf("..") > -1 ? > > > jQuery.unique( elems ) : elems ); > > > > } > > > > Now you can get the query string: > > > $('body .class').prevObject.query //->'body .class' > > > $('body').find('.class').prevObject.prevObject.query //->'body' > > > but > > > $('#id').prevObject.query //->undefined > > > $().find('#id').prevObject.query //->'#id' > > > here is the final tweak, > > (after adding this modified find method) > > > query = (this.prevObject && this.prevObject.query) || this[0]; > > > I strongly believe that such property should be added to the main > > distro of jQuery. > > After all, the idea of find-and-modify approach - one of jQuery > > fundamentals.
[jQuery] Re: How to retrieve jQuery.query?
prevObject is internal, you don't need to know about it. Just use end() instead. -- Ariel Flesler http://flesler.blogspot.com/ On Sep 1, 9:19 am, Tzury <[EMAIL PROTECTED]> wrote: > > jQuery.fn.find=function( selector ) { > > this.query=selector; //this is the only line you have to modify > > > var elems = jQuery.map(this, function(elem){ > > return jQuery.find( selector, elem ); > > }); > > return this.pushStack( /[^+>] [^+>]/.test( selector ) || > > selector.indexOf("..") > -1 ? > > jQuery.unique( elems ) : elems ); > > > } > > > Now you can get the query string: > > $('body .class').prevObject.query //->'body .class' > > $('body').find('.class').prevObject.prevObject.query //->'body' > > but > > $('#id').prevObject.query //->undefined > > $().find('#id').prevObject.query //->'#id' > > here is the final tweak, > (after adding this modified find method) > > query = (this.prevObject && this.prevObject.query) || this[0]; > > I strongly believe that such property should be added to the main > distro of jQuery. > After all, the idea of find-and-modify approach - one of jQuery > fundamentals.
[jQuery] Re: How to retrieve jQuery.query?
> jQuery.fn.find=function( selector ) { > this.query=selector; //this is the only line you have to modify > > var elems = jQuery.map(this, function(elem){ > return jQuery.find( selector, elem ); > }); > return this.pushStack( /[^+>] [^+>]/.test( selector ) || > selector.indexOf("..") > -1 ? > jQuery.unique( elems ) : elems ); > > } > > Now you can get the query string: > $('body .class').prevObject.query //->'body .class' > $('body').find('.class').prevObject.prevObject.query //->'body' > but > $('#id').prevObject.query //->undefined > $().find('#id').prevObject.query //->'#id' here is the final tweak, (after adding this modified find method) query = (this.prevObject && this.prevObject.query) || this[0]; I strongly believe that such property should be added to the main distro of jQuery. After all, the idea of find-and-modify approach - one of jQuery fundamentals.
[jQuery] Re: How to retrieve jQuery.query?
SG, thanks for the livequery reference. it was very helpful, -- TBY > On Aug 31, 8:06 pm, Scott González <[EMAIL PROTECTED]> wrote: > 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.
[jQuery] Re: How to retrieve jQuery.query?
It would be good to know why you need this, I can hardly imagine what is this good for. Anyway, here's how you can do it: jQuery.fn.find=function( selector ) { this.query=selector; //this is the only line you have to modify var elems = jQuery.map(this, function(elem){ return jQuery.find( selector, elem ); }); return this.pushStack( /[^+>] [^+>]/.test( selector ) || selector.indexOf("..") > -1 ? jQuery.unique( elems ) : elems ); } Now you can get the query string: $('body .class').prevObject.query //->'body .class' $('body').find('.class').prevObject.prevObject.query //->'body' but $('#id').prevObject.query //->undefined $().find('#id').prevObject.query //->'#id' On Aug 30, 11: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
[jQuery] Re: How to retrieve jQuery.query?
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
[jQuery] Re: How to retrieve jQuery.query?
On Aug 31, 3:35 am, dabear <[EMAIL PROTECTED]> wrote: > Not sure if I answer your question completly, but doing that test on > each elements tagName should do it what will you do in case of $('div > p')?
[jQuery] Re: How to retrieve jQuery.query?
Not sure if I answer your question completly, but doing that test on each elements tagName should do it Tzury skrev: > 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
[jQuery] Re: How to retrieve jQuery.query?
On Aug 31, 12:46 pm, Olivier Percebois-Garve <[EMAIL PROTECTED]> wrote: > the appropriate name is : this sorry sir, bu 'this' does not represents the selector expression at any time I would like to retrieve the selector which initialized the jQuery instantiation. for example $('div.foo') returns jQuery object and I want to retrieve that very 'div.foo' string argument within my code
[jQuery] Re: How to retrieve jQuery.query?
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
[jQuery] Re: How to retrieve jQuery.query?
the appropriate name is : this Tzury 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