jquery-dev
[Prev] Thread [Next] | [Prev] Date [Next]
[jquery-dev] Re: Question on writing a jQuery plugin Bob Spryn Tue Jun 23 10:01:04 2009
Cool. Good suggestion. Very smart.
Thanks,
Bob
On Jun 23, 2:48 am, samer <[EMAIL PROTECTED]> wrote:
> It's not wrong, but to save you all the lines in the switch you could
> implement your functions (init, advance, ...) in an object like
> var jMyPlugin = { init: function()....
>
> or
>
> jMyPlugin.prototype.init
>
> or whatever
>
> so then your switch case could be replaced with
> } else if (typeof options === "string"){
> jMyPlugin[option];
> }
>
> On Jun 23, 2:26 am, Bob Spryn <[EMAIL PROTECTED]> wrote:
>
>
>
> > So here's what I've done and it seems to be working pretty well. Let
> > me know if I'm doing anything weird. (I'm going to provide access to
> > the default options object publicly at some point, but its working for
> > now)
>
> > //Simple screen wizard plugin
> > ;(function($) {
> > $.fn.screenWizard = function (options) {
>
> > var defaultOptions = {
> > size : "100",
> > duration : 1000,
> > defaultLeft : 0
> > };
>
> > if (typeof options === "object") {
> > return init(this, options);
> > } else if (typeof options === "string"){
> > switch (options) {
> > case "advance":
> > return advance(this);
> > break;
> > case "back":
> > return back(this);
> > break;
> > case "reset":
> > default:
> > return reset(this);
> > break;
>
> > }
> > }
>
> > function init(obj, options){
> > obj.settings = $.extend(defaultOptions, options);
> > return obj.each(function(){});
> > };
>
> > function advance(obj){
> > return obj.each(function(){
> > var current = parseInt($(obj).css("left"));
> > $(this).animate({left: (current -
> > obj.settings.size) + "px"},
> > obj.settings.duration);
> > });
> > };
>
> > function back(obj){
> > return obj.each(function(){
> > var current = parseInt($(obj).css("left"));
> > $(this).animate({left: (current +
> > obj.settings.size) + "px"},
> > obj.settings.duration);
> > });
> > };
>
> > function reset(obj){
> > return obj.each(function(){
> > $(this).animate({left:
> > obj.settings.defaultLeft },
> > obj.settings.duration);
> > });
> > };
>
> > };
>
> > })(jQuery);
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [EMAIL PROTECTED]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---
- [jquery-dev] Question on writing a jQuery plugin Bob Spryn
- [jquery-dev] Re: Question on writing a jQuery plugin Bob Spryn
- [jquery-dev] Re: Question on writing a jQuery plugin Bob Spryn
- [jquery-dev] Re: Question on writing a jQuery plugin Damir Zekić
- [jquery-dev] Re: Question on writing a jQuery plugin Bob Spryn
- [jquery-dev] Re: Question on writing a jQuery plugin Bob Spryn
- [jquery-dev] Re: Question on writing a jQuery plugin samer
- [jquery-dev] Re: Question on writing a jQuery plugin Bob Spryn <=
- [jquery-dev] Re: Question on writing a jQuery plugin tres
- [jquery-dev] Re: Question on writing a jQuery plugin Samer