I want to disagree with Danny's first statement... if you're going to create
a jQuery plug-in (re-usable and useful to all) then it's best to follow the
convention of returning the elements it's acted on. If you want it to return
something else (or nothing) don't create a plug-in -- instead create a
separate global object w/methods.

I haven't time to write the innards of the plug-in approach, but I'd
recommend a syntax like:

$('#photo').photo( method, settings ).css(...).attr(...);

var createSettings = { src:uri };
var cropSettings = {width:w,height:h};

$('#photo').photo( 'create', createSettings ).photo( 'crop', cropSettings
).show();

Chaining is one of the most powerful features of jQuery... let it work for
you!

Brian.

On 12/12/07, Danny <[EMAIL PROTECTED]> wrote:
>
>
> If you have no reason to chain your plugin (something like $
> ('#photo').photo(...).css(...).attr(...) then having it return a
> different object makes sense. But then, why put it in the jQuery
> namespace at all? 'return new smaon.photo(...) makes as much sense.
> Danny
>
> On Dec 12, 10:38 am, Smaon <[EMAIL PROTECTED]> wrote:
> > Thank you for your answer Danny.
> >
> > I'm currently trying this way:
> >
> > jQuery.fn.photo = function (...) {
> >         var canvas = $(this).get(0);
> >         return new jQuery.photo(canvas, settings);
> >
> > }
> >
> > jQuery.twistMap = function(canvas, settings){
> >        //create code
> >
> >        this.crop = function(){
> >            ......
> >       }
> >
> > }
> >
> > usable like this:
> >
> > var photo = $("#photo").photo(...);
> > photo.crop();
> >
> > What do you think? For me, while not being perfect, it seems more or
> > less ok...
> >
> > PS: BTW, it there a way to put clean code in this discussion group?
> >
>

Reply via email to