Here's my thoughts: 1. Ability to modify default settings It is sometimes nice to set the global defaults. 2. Ability to expose methods. A nice way of calling the someFunc() would be nice. I guess you can do it like this: $(...).data('_wTooltip').someFunc(); but using the data() seems a bit hacky. 3. Use settings from html5 data-attribute, ie data-tooltip='{"foo":"baar"}'. Not really necessary for the example plugin,…
Not sure you should be (ab)using data- attributes like that. They’re already a key/value pair so you markup your data as
Superior jQuery plugin template
11–17 of 17 posts
If you have many options, they are easier to retrieve, just call .data('tooltip') and jQuery will do the parsing of the object. Using separate attributes you would have to call .data() for every attribute. Anyway, I guess any of the two methods would be fine! :-)
Re: Superior jQuery plugin template
#12Crockford must be rolling over in his bed right now
Re: Superior jQuery plugin template
#13Earlier quoted context omitted.
'Untested' and 'superior' are not happy bedfellows!
lol, just a typo ;)
What happens if I type:
$("blah").wTooltip(new String("color"));
In my recent jquery plugin I considered doing a typeof check myself but decided against it since it was too brittle. I instead checked to see if the options was === what I expected it to be first.Re: Superior jQuery plugin template
#14Earlier quoted context omitted.
lol, just a typo ;)
What happens if I type: $("blah").wTooltip(new String("color")); In my recent jquery plugin I considered doing a typeof check myself but decided against it since it was too brittle. I instead checked to see if the options was === what I expected it to be first.
Well, I think this is getting a little nit picky. I would rather have a smaller footprint for my plugin then putting a bunch of checks like this in. I don't think I've ever passed in a string that way, that would seem to me like a very rare condition.
Re: Superior jQuery plugin template
#15A recipe like this (also a tooltip), but approved by the jQuery team and with much more explanation is available at http://docs.jquery.com/Plugins/Authoring
Re: Superior jQuery plugin template
#16A recipe like this (also a tooltip), but approved by the jQuery team and with much more explanation is available at http://docs.jquery.com/Plugins/Authoring
ya, I don't really like their method approach, they don't use prototyping.
Re: Superior jQuery plugin template
#17Just wanted to let you know I used your boilerplate for my first jQuery plugin recently - https://github.com/indyarmy/jQuery.awesomeCloud.plugin/
Thanks a lot, it saved me a pile o'trouble :)