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
-~----------~----~----~----~------~----~------~--~---