Hi Trey, In the end I reverted to an earlier version of your code which seems to be working ok for now. Next time I get the chance I will look into updating to this version.
Cheers L On May 10, 1:00 am, tres <[email protected]> wrote: > Lee, > > I've sent you an email, but here it is for everyone else: > > -- > > Sorry, I didn't see your post. Google groups can be difficult > sometimes. > > Anyways, sorry about that. Since there is no official release yet and > I have yet to document it fully, the code has changed slightly. I've > changed it so that it follows JavaScript's paradigm more closely. > > There are 3 ways to attach plugins to $ or $.fn. The following pass in > Firefox, IE7, Chrome and Safari. IE6, IE8 and Opera haven't been > tested yet. > > I hope this helps. You can also grab the plugin off Google Code > at:http://code.google.com/p/jquery-plugin-dev/source/browse/trunk/jquery.... > > CODE: > > ---------------------------------------------------------------------------------------- > > <script type="text/javascript" src="jquery-1.3.2.js"></script> > <script type="text/javascript" src="jquery.plugin.js"></script> > <script type="text/javascript"> > > ;(function($) { > > /* > * 1st method > * > * Static : No constructor > */ > > // static plugin > $.plugin.add('test1'); > > // then use .fn or .prototype on that plugin to add methods > $.test1.staticMethod = function(arg) { > alert(arg); > > return this; > }; > > // then use .fn or .prototype on that plugin to add methods > $.test1.fn.instanceMethod = function(arg) { > alert(arg); > > return this; > }; > > /* > * 2nd method > * > * Static : Passing an anonymous constructor > */ > > // static plugin > $.plugin.add('test2', function() { > alert('initializing test2...'); > > return this; > }); > > $.test2.staticMethod = function(arg) { > alert(arg); > > return this; > }; > > $.test2.fn.instanceMethod = function(arg) { > alert(arg); > > return this; > }; > > /* > * 3rd method > * > * Static : Passing an already defined constructor > */ > > // create your plugin > var test3 = function() { > alert('initializing test3...'); > > return this; > } > > // a static method > test3.staticMethod = function(arg) { > alert(arg); > > return this; > }; > > // an instance method > // adding via .fn is only available after adding the plugin > test3.prototype.instanceMethod = function(arg) { > alert(arg); > > return this; > }; > > // now add it > $.plugin.add('test3', test3); > > /* > * 4th method > * > * Instance : No constructor > */ > > // static plugin > $.fn.plugin.add('test4'); > > // then use .fn or .prototype on that plugin to add methods > $.fn.test4.staticMethod = function(arg) { > alert(arg); > > return this; > }; > > // then use .fn or .prototype on that plugin to add methods > $.fn.test4.fn.instanceMethod = function() { > alert('test4 instanceMethod\nlength : ' + this.length + > '\nselector : ' + this.selector + '\ncontext : ' + this.context); > > return this; > }; > > /* > * 5th method > * > * Instance : Passing an anonymous constructor > */ > > // static plugin > $.fn.plugin.add('test5', function() { > alert('initializing test5...\nlength : ' + this.length + > '\nselector : ' + this.selector + '\ncontext : ' + this.context); > > return this; > }); > > $.fn.test5.staticMethod = function(arg) { > alert(arg); > > return this; > }; > > $.fn.test5.fn.instanceMethod = function() { > alert('test5 instanceMethod\nlength : ' + this.length + > '\nselector : ' + this.selector + '\ncontext : ' + this.context); > > return this; > }; > > /* > * 6th method > * > * Instance : Passing an already defined constructor > */ > > // create your plugin > function test6() { > alert('initializing test6...\nlength : ' + this.length + > '\nselector : ' + this.selector + '\ncontext : ' + this.context); > > return this; > } > > // a static method > test6.staticMethod = function(arg) { > alert(arg); > > return this; > }; > > // an instance method > // adding via .fn is only available after adding the plugin > test6.prototype.instanceMethod = function(arg) { > alert('test6 instanceMethod\nlength : ' + this.length + > '\nselector : ' + this.selector + '\ncontext : ' + this.context); > > return this; > }; > > // now add it > $.fn.plugin.add('test6', test6); > > })(jQuery); > > jQuery(function($) { > > // construct objects > var > test1 = $.test1('initializing test1...'), // nothing should > happen > test2 = $.test2('initializing test2...'), > test3 = $.test3('initializing test3...'), > test4 = $('div').test4(), // nothing should happen > test5 = $('div').test5(), > test6 = $('div').test6(); > > // test static methods > $.test1.staticMethod('test1 : staticMethod'); > $.test2.staticMethod('test2 : staticMethod'); > $.test3.staticMethod('test3 : staticMethod'); > $.fn.test4.staticMethod('test4 : staticMethod'); > $.fn.test5.staticMethod('test5 : staticMethod'); > $.fn.test6.staticMethod('test6 : staticMethod'); > > // test instance methods, can also be directly called > // i.e. $.test6().instanceMethod(), but saving will allow > // instance reuse > test1.instanceMethod('test1 : instanceMethod'); > test2.instanceMethod('test2 : instanceMethod'); > test3.instanceMethod('test3 : instanceMethod'); > test4.instanceMethod(); > test5.instanceMethod(); > test6.instanceMethod(); > > }); > > </script> > > <div> > <p>Testing html...</p> > </div> > > ---------------------------------------------------------------------------------------- > > On Apr 10, 3:25 am, Lee Henson <[email protected]> wrote: > > > Hi Trey > > > I'm trying to use your jquery.plugin.js as a basis for creating aplugin. > > I've got to : > > > $.plugin.add('plugin_name', { > > init: function(options) { > > return this; > > }, > > > another_method: function() { > > } > > > }); > > > But when I load the page I get a failure inside jquery.plugin.js > > because of this line inside _add(fn, name, func): > > > applyTo[name].fn = applyTo[name].prototype = _constructor.prototype = > > func.fn = func.prototype; > > > func is my object hash of functions, so it does not have a > > func.prototype. This obviously causes all the assignments on that line > > to be undefined, which causes errors when they are referenced. > > > Am I missing something in my code? > > > Cheers > > Lee > > > On Mar 30, 11:50 pm, tres <[email protected]> wrote: > > > > Btw, Daniel, I have changed the API to accomodate this. > > > > jQuery.plugin.add('name', func || objectOfFuncs), will now add a > > > staticpluginand can be called like jQuery.name() or > > > jQuery.name().method1(); > > > > Static methods can be applied also by giving a static keyword with the > > > function name: > > > > jQuery.plugin.add('name', { > > > someInstanceMethod : fucntion() {}, > > > 'static:myStaticMethod' : function() {} > > > > }); > > > > then can be called: jQuery.name().someInstanceMethod() or > > > jQuery.name.myStaticMethod(); > > > > and > > > > jQuery.fn.plugin.add('name', func || objectOfFuncs), will add it to > > > jQuery's prototype and can be called jQuery('selector').name(). > > > > jQuery.plugin.remove('name') and jQuery.fn.plugin.remove('name') work > > > in a similar way. > > > > I'm putting together a full documentation and examples soon. > > > > -Trey > > > > On Mar 5, 1:34 pm, Daniel Friesen <[email protected]> wrote: > > > > > I think it could do with the ability to handle methods on jQuery itself > > > > instead of being limited to just jQuery.fn, perhaps a second > > > > object/function to addPlugin; > > > > > Likewise I'd prefer jQuery.options over jQuery.fn.options; > > > > > ~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://nadir-seen-fire.com] > > > > -Nadir-Point & Wiki-Tools (http://nadir-point.com) > > > > (http://wiki-tools.com) > > > > -MonkeyScript (http://monkeyscript.org) > > > > -Animepedia (http://anime.wikia.com) > > > > -Narutopedia (http://naruto.wikia.com) > > > > -Soul Eater Wiki (http://souleater.wikia.com) > > > > > [email protected] wrote: > > > > > There has been a lot of activity aboutpluginauthoring and how it can > > > > > be more structured and extensible. I've posted a couple of comments on > > > > > some threads and sent an email to John, but I thought I'd create a new > > > > > thread since I haven't had any feedback yet. John, I understand you > > > > > probably get a lot of email and are very busy. > > > > > > I've written apluginthat I'd like to get feedback on from you guys. > > > > > It's still evolving, but should be stable in what it currently is > > > > > designed to do and I have found it invaluable when authoring larger, > > > > > more advanced plugins. It would be nice to see similar functionality > > > > > built into jQuery as I think others would also find it useful. > > > > > > Link:http://plugins.jquery.com/project/plugin-authoring > > > > > > Cheers, > > > > > Trey --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
