Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt at refactoring. May add more changes yet.
- Loading branch information
1 parent
b68743f
commit b86a402
Showing
5 changed files
with
79 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright (c) 2012 Robby Colvin | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// http://net.tutsplus.com/tutorials/javascript-ajax/14-reason-why-nobody-used-your-jquery-plugin/ | ||
// http://net.tutsplus.com/tutorials/javascript-ajax/meeting-grunt-the-build-tool-for-javascript/ |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,83 @@ | ||
/** | ||
* jQuery PLUGIN_NAME Plugin | ||
* Version: x.x.x | ||
* jQuery Plugin Plugin | ||
* Version: 0.0.0 | ||
* URL: URL | ||
* Description: DESCRIPTION | ||
* Requires: JQUERY_VERSION, OTHER_PLUGIN(S), ETC. | ||
* Author: AUTHOR (AUTHOR_URL) | ||
* Copyright: Copyright 2010 YOUR_NAME | ||
* Copyright: Copyright 2012 YOUR_NAME | ||
* License: LICENSE_INFO | ||
*/ | ||
|
||
// Plugin closure wrapper | ||
(function($) { | ||
|
||
// Main plugin function | ||
// Replace PLUGIN with the name of your desired function | ||
$.fn.PLUGIN = function(options) { | ||
|
||
// Overwrite user options with plugin defaults | ||
var opts = $.extend({}, $.fn.PLUGIN.defaults, options); | ||
|
||
// Iterate through DOM elements and work your magic | ||
// Uses dollar internally, but calls jQuery to prevent conflicts with other libraries | ||
// Semicolon to prevent breakage with concatenation | ||
// Pass in window as local variable for efficiency (could do same for document) | ||
// Pass in undefined to prevent mutation in ES3 | ||
;(function($, document, window, undefined) { | ||
// Optional, but considered best practice by some | ||
"use strict"; | ||
|
||
// Default options for the plugin as a simple object | ||
var defaults = { | ||
property: 'value', | ||
anotherProperty: 10 | ||
}; | ||
|
||
// Plugin constructor | ||
// This is the boilerplate to set up the plugin to keep our actual logic in one place | ||
function Plugin(element, options) { | ||
this.element = element; | ||
|
||
// Merge the options given by the user with the defaults | ||
this.options = $.extend({}, defaults, options) | ||
|
||
// Attach data to the elment | ||
this.$el = $(el); | ||
this.$el.data(name, this); | ||
|
||
this.defaults = {}; | ||
|
||
var meta = this.$el.data(name + '-opts'); | ||
this.opts = $.extend(this.defaults, opts, meta); | ||
|
||
// Initialization code to get the ball rolling | ||
// If your plugin is simple, this may not be necessary and | ||
// you could place your implementation here | ||
this.init(); | ||
} | ||
|
||
// Plugin initializer - prepare your plugin | ||
// This is a public function that users can call | ||
// Prototype methods are shared across all elements | ||
// If your plugin is complex, you can split functionality into more | ||
// methods like this one | ||
Plugin.prototype.init = function() { | ||
// You have access to this.options and this.element | ||
}; | ||
|
||
$.fn.Plugin = function(options) { | ||
// global settings | ||
settings = $.extend({}, $.fn.wTooltip.defaultSettings, settings); | ||
// Iterate through each DOM element and return it | ||
return this.each(function() { | ||
// Assign the current object to a variable for easier use | ||
var $this = $(this); | ||
var element = this; // or $(this) | ||
|
||
// prevent multiple instantiations | ||
if (!$.data(this, 'plugin_' + pluginName)) { | ||
$.data(this, 'plugin_' + pluginName, new Plugin( this, options )); | ||
} | ||
|
||
// This is where most of your plugin functionality resides | ||
new Plugin(this, options); | ||
|
||
}); // end return this.each | ||
|
||
}; // end $.fn.PLUGIN | ||
|
||
// Public plugin function | ||
// Replce PLUGIN with your plugin function's name | ||
// Replace FUNCT with the name of the public function | ||
$.fn.PLUGIN.FUNCT = function() { | ||
// Cool JS action | ||
}; // end $.fn.PLUGIN.FUNCT | ||
|
||
// Default settings for the plugin | ||
$.fn.PLUGIN.defaults = { | ||
property: "value", | ||
anotherProperty: 10 | ||
}; | ||
|
||
// Private function that is used within the plugin | ||
function privateFunction() { | ||
// Cool JS action | ||
// Private function that is only called by the plugin | ||
var privateFunction = function() { | ||
// ... | ||
} | ||
|
||
})(jQuery); // end closure wrapper | ||
})(jQuery, document, window); // end closure wrapper |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "jquery-plugin-template" | ||
} |