Hi Yaron, On Wed, 19 Jan 2011 09:26:41 -0500, Yaron Koren wrote: > Okay - that sounds like a perfect case where jQuery can let you use > classes instead of IDs. The key is that the buttons have to be > contained within the same div or span as the date input - if you can > get that to happen (or maybe thats how it works already), then its > pretty easy to get each button to affect only its corresponding date > input, without the use of IDs. > > You can see that strategy being used in a few places here: > > > http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/SemanticForms/libs/SemanticForms.js?view=markup > [5] > > [6]For instance, this section of code is the beginning of the > "addInstance" function, which is attached to every "Add another" > button: > > jQuery.fn.addInstance = function() { > > ... > > // Create the new instance > var new_div = this.closest(".multipleTemplateWrapper") > .find(".multipleTemplateStarter") > .clone() > .removeClass(multipleTemplateStarter) > .addClass(multipleTemplateInstance) > .addClass(multipleTemplate) // backwards compatibility > .removeAttr("id") > .css("display", "block"); > > ...and then elsewhere in the code, theres this line: > > jQuery(.multipleTemplateAdder).click( function() { > jQuery(this).addInstance(); } ); > > If I can give a mini-jQuery tutorial: "addInstance" gets defined as a > function for any page element - in this case, it gets used for "Add > another" buttons. When the function is triggered (via a click), the > code looks for the buttons parent div with the appropriate class (the > closest() function), then finds, within that div, the sibling element > that it needs to act on (the find() function), then acts on it (all > the rest). The key to this is that every relevant part of the > structure needs to have its own class. > > It looks a little weird, and it takes a little getting used to this > way of doing things, but it really makes life simpler over the long > run - and theres some good documentation for jQuery online. > > I hope you can get it working...
Ok, thanks for the mini tutorial, I'll see how to migrate my extension to jQuery then. Thanks, Patrick. -- Key ID: 0x86E346D4 http://patrick-nagel.net/key.asc Fingerprint: 7745 E1BE FA8B FBAD 76AB 2BFC C981 E686 86E3 46D4 ------------------------------------------------------------------------------ Protect Your Site and Customers from Malware Attacks Learn about various malware tactics and how to avoid them. Understand malware threats, the impact they can have on your business, and how you can protect your company and customers by using code signing. http://p.sf.net/sfu/oracle-sfdevnl _______________________________________________ Semediawiki-devel mailing list Semediawiki-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/semediawiki-devel