* Dave Methvin <[EMAIL PROTECTED]> [2006-11-30 17:10]: > This will be a short thread--NOT! :-) > > > Controller set of methods is returned.. > > > > $('#grid').grid().data(data).drig().show() > > $('#grid').grid().scrollToRow(6).drig().css("border", "1px") > > Uh, drig()? So if I want to return to I was before scrollToRow(6), should I > use (6)woRoTllorsc? ;-)
This is indeed the implementation. Somewhere else, I suggeted using jQuery to return to the jQuery method chain. $('div.grid').grid() .columns(2, 3, 4).select().grid() .rowHeight(22) .jQuery().show() Now it would be possible to perform the above on every grid in the document, using method chaining. > I don't know if this a good idiom; changing the object type within the chain > might be be too tricky. It might be too tricky as a one off, but if it becomes a convention, then I don't think it will be so tricky. There are a few tricky things about jQuery already... $('#e').css('height', '100px').scrollTop = 20 ...really needs to be... $('#e').css('height', '100px').get(0).scrollTop = 20 ...or... $('#e').css('height', '100px').each(funciton () { this.scrollTop = 20 }) ...or maybe not chained at all. If chaining is a convention, then chain switching could also be a convention. > Also, would the plugin itself have a need for chained methods to > change its internal state? Still, to make your object chainable > like that, I think your $().grid method would just need to save > its jQuery "this" in your Grid object before returning: > jQuery.fn.grid = function() { > var gridObject = // ... get your grid object ... > gridObject.jQuery = this; > return gridObject; > } > jQuery.fn.drig = function() { > return this.jQuery; > } This is how I'd propose it would be implemented. > As Jörn mentioned, you could still use $("#grid").grid() to create and/or > retrieve a Grid object, even if it wasn't chainable. It seems like you'd > want some way to determine whether it was a Grid creation or just getting an > existing object; you could have a separate $().createGrid() method or maybe > the $().grid() argument could be required on creation. (Also, should the > core should a standard way for plugins to associate object data with an > element, like it does with events?) I'm using something along these lines... if (!Acme) var Acme = {} Acme.Grids = {} Acme.NextGrid = 1 Acme.GridBuilder = function (jQuery, options) { this.jQuery = jQuery this.options = options } Acme.GridBuilder.prototype = { rowHieght: function (height) { jQuery.each(function() { var options = Acme.Grids[this.AcmeGridID] options.height = height }) }, render() { // long and complicated... }, jQuery: function() { this.render() return this.jQuery } } jQuery.fn.grid = function () { this.each(function () { if (!this.AcmeGridID) { this.AcmeGridID = 'G' + (Acme.NextGrid++) Acme.Grids[this.AcmeGridID] = {} } }) return new GridBuilder(this) } ...and so, grid() creates if not already created. > Whatever results from this discussion should go to the plugins authoring > page on the wiki, http://jquery.com/plugins/Authoring/ If it becomes a convention then I don't think that it's going to be to difficult to say that the method switches chains, and termiantes with so and so, and this creates a convention for both storing data and resettting properties. -- Alan Gutierrez - 504 717 1428 - [EMAIL PROTECTED] - http://blogometer.com/ Think New Orleans - http://thinknola.com/ _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/