matthewwithanm / jquery-icbiacontrol

Style browser controls without losing their native behaviors.
MIT License
12 stars 6 forks source link

adding name attribute of input element as a css class name of the widget #6

Closed ryanbagwell closed 11 years ago

ryanbagwell commented 11 years ago

This is the first time I used this thing. It's pretty baller.

This PR just adds a unique css class to the wrapper so it can be distinguished from others. I had the several select dropdowns in the same form, but wanted a way to target each wrappers.

Not sure if this is the best solution. Perhaps a way to specify a wrapper class name in the options is another way to handle it.

matthewwithanm commented 11 years ago

Thanks Ryan!

I feel like having the name be used automatically by default might be a little surprising and hard to undo but the wrapperClass option sounds good.

This also makes me wonder if we should add a method for getting the wrapper element itself. Like .icbiaControl('wrapper') or .icbiaControl('getWrapper').

ryanbagwell commented 11 years ago

The only downside I see to adding a "wrapperClass" option is that you'd have to call the plugin once for each element. So if I have three select elements, I can't just say $('select').icbiaControl({ wrapperClass:'foo'}), because foo will get applied to each wrapper. If it took a function as an argument, you could presumably check the select element's name attribute and create a new css class based on that attribute.

Or maybe it would be even better to add a general after setup callback function to modify it in other ways too.

matthewwithanm commented 11 years ago

Hm. If we add that function for getting the wrapper, you could do this:

$('select').icbiaControl().each(function (i, el) {
  var $el = $(el);
  $el.icbiaControl('getWrapper').addClass('whatever-' + $el.attr('name'));
});
matthewwithanm commented 11 years ago

Oh, another option would be to let wrapperClass be a function:

$('select').icbiaControl
  wrapperClass: (el) -> "whatever-#{ $(el).attr 'name' }"
ryanbagwell commented 11 years ago

you beat me to it.

On Fri, Jul 26, 2013 at 11:35 AM, Matthew Tretter notifications@github.comwrote:

Oh, another option would be to let wrapperClass be a function:

$('select').icbiaControl wrapperClass: (el) -> "whatever-#{ $(el).attr 'name' }"

— Reply to this email directly or view it on GitHubhttps://github.com/matthewwithanm/jquery-icbiacontrol/pull/6#issuecomment-21632309 .

Ryan Bagwell 5219 Shorecrest Drive Middleton, WI 53562 (608) 466-6195 (v)

ryanbagwell commented 11 years ago

Actually, that's what I was trying to say originally - allow that wrapperClass option to be a function or a string.

On Fri, Jul 26, 2013 at 11:35 AM, Ryan Bagwell ryan@ryanbagwell.com wrote:

you beat me to it.

On Fri, Jul 26, 2013 at 11:35 AM, Matthew Tretter < notifications@github.com> wrote:

Oh, another option would be to let wrapperClass be a function:

$('select').icbiaControl wrapperClass: (el) -> "whatever-#{ $(el).attr 'name' }"

— Reply to this email directly or view it on GitHubhttps://github.com/matthewwithanm/jquery-icbiacontrol/pull/6#issuecomment-21632309 .

Ryan Bagwell 5219 Shorecrest Drive Middleton, WI 53562 (608) 466-6195 (v)

Ryan Bagwell 5219 Shorecrest Drive Middleton, WI 53562 (608) 466-6195 (v)

matthewwithanm commented 11 years ago

:thumbsup: I like that. I still think we should add a method for getting the wrapper, but this is a nice shortcut for a common case.

matthewwithanm commented 11 years ago

Alright, added the wrapperClass option and pushed it as 1.2.0.

matthewwithanm commented 11 years ago

We should document this. I forgot about it!