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? On 12 déc, 04:47, Danny <[EMAIL PROTECTED]> wrote: > It sounds like you want a way to create namespaces for plugins. There > isn't an "official" way, but I wrote a small function to create > namespaces that was discussed on a previous > thread:http://www.nabble.com/Re%3A-passing-this-p13540912s27240.html > > Also, it looks like your functions jQuery.Photo.create are actually > meant to be plugins (i.e. they refer to 'this' as a jQuery object) so > they should not be part of the jQuery object itself. Just do > jQuery.fn.extend ({ > photocreate: function(settings){ > .... > }, > photocrop: function(...){ > .... > } > > }); > > Or, if using my namespace plugin, > $.namespace ('photo', { > create: function(settings){ > .... > }, > crop: function(...){ > .... > } > > }); > > Danny > On Dec 11, 6:43 pm, Smaon <[EMAIL PROTECTED]> wrote: > > > Hi everybody, > > > ok, I'm in a big trouble right now. Let me try to explain my > > problem :) > > > I'm trying to create a simple photo editing system. I need to define a > > DIV as the canvas, then to have many methods applicables to this > > object. > > > My first reflex was to create a jQuery extension, something like this > > (just to give the idea): > > > jQuery.Photo = { > > create: function(settings){ > > .... > > }), > > crop: function(...){ > > .... > > } > > > }; > > > jQuery.fn.extend( > > { > > Photo: jQuery.Photo.create, > > crop: jQuery.Photo.crop > > > }); > > > Very well, now I was able to create my editable photo by using $ > > ("#photo").Photo() and to crop by using $("#photo").crop() > > > BUT, the problem is that I need to extend jQuery with every method I > > want to use on my photos. For example crop() is now in the global > > scope, and this is very ugly. To do well I should name it PhotoCrop, > > but this I don't find it's a good solution. What I would like is to > > have methods only usable on instances of the Photo object, in its > > local scope. For ex, in core javascript it would be like that: > > > function Photo(){ > > ... > > > } > > > Photo.prototype.crop = function(){ > > ... > > > } > > > The problem is that I don't find any way to do this properly with > > jQuery. Maybe somebody here could help me? > > > Many thanks in advance! > > > Smaon