-
-
Save peet86/a4dff9ac996e731bb9dc to your computer and use it in GitHub Desktop.
Revisions
-
simonsmith revised this gist
Aug 25, 2014 . 1 changed file with 44 additions and 45 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,61 +1,60 @@ // UMD dance - https://github.com/umdjs/umd !function(root, factory) { if (typeof define === 'function' && define.amd) { define(['jquery'], factory); } else { factory(root.jQuery); } }(this, function($) { 'use strict'; // Default options var defaults = { }; // Constructor, initialise everything you need here var Plugin = function(element, options) { this.element = element; this.options = options; }; // Plugin methods and shared properties Plugin.prototype = { // Reset constructor - http://goo.gl/EcWdiy constructor: Plugin, someMethod: function() { } } // Create the jQuery plugin $.fn.plugin = function(options) { // Do a deep copy of the options - http://goo.gl/gOSSrg options = $.extend(true, {}, defaults, options); return this.each(function() { var $this = $(this); // Create a new instance for each element in the matched jQuery set // Also save the instance so it can be accessed later to use methods/properties etc // e.g. // var instance = $('.element').data('plugin'); // instance.someMethod(); $this.data('plugin', new Plugin($this, options)); }); }; // Expose defaults and Constructor (allowing overriding of prototype methods for example) $.fn.plugin.defaults = defaults; $.fn.plugin.Plugin = Plugin; }); // Usage example require(['jquery', 'jquery.plugin'], function($) { $('.test li').plugin({ test: 'option1', test2: 'option2' }); }); -
simonsmith revised this gist
Dec 4, 2013 . 1 changed file with 9 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ // UMD dance - https://github.com/umdjs/umd !function(root, factory) { if (typeof define === 'function' && define.amd) { define(['jquery'], factory); @@ -8,15 +8,18 @@ }(this, function($) { 'use strict'; // Default options var defaults = { }; // Constructor, initialise everything you need here var Plugin = function(element, options) { this.element = element; this.options = options; }; // Plugin methods and shared properties Plugin.prototype = { // Reset constructor - http://goo.gl/EcWdiy constructor: Plugin, @@ -33,7 +36,11 @@ return this.each(function() { var $this = $(this); // Create a new instance for each element in the matched jQuery set // Also save the instance so it can be accessed later to use methods/properties etc // e.g. // var instance = $('.element').data('plugin'); // instance.someMethod(); $this.data('plugin', new Plugin($this, options)); }); }; -
simonsmith revised this gist
Dec 4, 2013 . 1 changed file with 10 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ !function(root, factory) { if (typeof define === 'function' && define.amd) { define(['jquery'], factory); @@ -17,7 +18,8 @@ }; Plugin.prototype = { // Reset constructor - http://goo.gl/EcWdiy constructor: Plugin, someMethod: function() { @@ -26,22 +28,26 @@ // Create the jQuery plugin $.fn.plugin = function(options) { // Do a deep copy of the options - http://goo.gl/gOSSrg options = $.extend(true, {}, defaults, options); return this.each(function() { var $this = $(this); // Save the instance so it can be accessed later to use methods/properties etc $this.data('plugin', new Plugin($this, options)); }); }; // Expose defaults and Constructor (allowing overriding of prototype methods for example) $.fn.plugin.defaults = defaults; $.fn.plugin.Plugin = Plugin; }); // Usage example require(['jquery', 'jquery.plugin'], function($) { $('.test li').plugin({ test: 'option1', test2: 'option2' }); -
simonsmith revised this gist
Dec 4, 2013 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ !function(root, factory) { if (typeof define === 'function' && define.amd) { define(['jquery'], factory); @@ -12,8 +11,8 @@ }; var Plugin = function(element, options) { this.element = element; this.options = options; }; -
simonsmith revised this gist
Dec 4, 2013 . 1 changed file with 37 additions and 47 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,56 +1,46 @@ !function(root, factory) { if (typeof define === 'function' && define.amd) { define(['jquery'], factory); } else { factory(root.jQuery); } }(this, function($) { 'use strict'; var defaults = { }; var Plugin = function(container, options) { this.container = container; this.options = options; }; Plugin.prototype = { constructor: Herotabs, someMethod: function() { } } // Create the jQuery plugin $.fn.plugin = function(options) { options = $.extend(true, {}, defaults, options); return this.each(function() { var $this = $(this); $this.data('plugin', new Plugin($this, options)); }); }; // Expose defaults and Constructor $.fn.plugin.defaults = defaults; $.fn.plugin.Plugin = Plugin; }); // Usage example require(['jquery', 'jquery.foo'], function($) { $('.test li').foo({ test: 'option1', -
Simon revised this gist
Jun 13, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ !function(global) { 'use strict'; var defaults = { 'default': 'yeah', @@ -45,7 +46,6 @@ // Otherwise we assume jQuery was loaded the old fashioned way and just pass the jQuery object to wrap wrap(global.jQuery); } }(this); -
Simon revised this gist
Jun 13, 2013 . 1 changed file with 21 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,32 +1,40 @@ !function(global) { var defaults = { 'default': 'yeah', 'test': 'simon' }; // Wrapper function that allows us to pass it to define later var wrap = function($) { // Standard JS object stuff var Foo = function(element, options) { this.options = options; this.element = element; // Instance specific stuff }; Foo.prototype = { // All your methods here }; // Here is the actual jQuery plugin part. It just creates a new Foo object // for each matched element in the jQuery object. $.fn.foo = function(options) { options = $.extend(true, {}, defaults, options); return this.each(function() { var $this = $(this); // Assign the instance to a data property so the methods can // be used $this.data('foo', new Foo($this, options)); }); }; $.fn.herotabs.defaults = defaults; $.fn.herotabs.Foo = Foo; }; // Check for the presence of an AMD loader and if so pass the wrap function to define @@ -40,9 +48,10 @@ }(this); // Usage require(['jquery', 'jquery.foo'], function($) { $('.test li').foo({ test: 'option1', test2: 'option2' -
Simon renamed this gist
Mar 5, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Simon renamed this gist
Dec 21, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Simon created this gist
Dec 21, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ !function(global) { // Wrapper function that allows us to pass it to define later var wrap = function($) { // Standard JS object stuff var Foo = function(element, options) { this.options = options; this.element = element; }; Foo.prototype = { }; // Here is the actual jQuery plugin part. It just creates a new Foo object // for each matched element in the jQuery object. $.fn.foo = function(options) { options = $.extend({}, $.fn.foo.defaults, options); return this.each(function() { new Foo($(this), options); }); }; // Plugin defaults $.fn.foo.defaults = { 'default': 'yeah', 'test': 'simon' }; }; // Check for the presence of an AMD loader and if so pass the wrap function to define // We can safely assume 'jquery' is the module name as it is a named module already - http://goo.gl/PWyOV if (typeof define === 'function' && define.amd) { define(['jquery'], wrap); } else { // Otherwise we assume jQuery was loaded the old fashioned way and just pass the jQuery object to wrap wrap(global.jQuery); } }(this); // Usage require(['jquery', 'Foo'], function($) { $('.test li').foo({ test: 'option1', test2: 'option2' }); });