-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Item13883: improved empty jquery plugin
- Loading branch information
1 parent
bd80585
commit 9e23155
Showing
1 changed file
with
33 additions
and
32 deletions.
There are no files selected for viewing
65 changes: 33 additions & 32 deletions
65
JQueryPlugin/pub/System/JQueryPlugin/plugins/empty/jquery.empty.uncompressed.js
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,61 +1,62 @@ | ||
/* | ||
* jQuery Empty plugin 1.0 | ||
* | ||
* Copyright (c) 20xx Your Name http://... | ||
* Copyright (c) 20xx Your Name http://... | ||
* | ||
* Dual licensed under the MIT and GPL licenses: | ||
* http://www.opensource.org/licenses/mit-license.php | ||
* http://www.gnu.org/licenses/gpl.html | ||
* | ||
* How to proceed: | ||
* How to proceed: | ||
* 1 copy this file into a file named jquery.plugin-name.js | ||
* 2 replace the strings "Empty" with "pluginName" in this file | ||
* 2 replace the strings "EmptyPlugin" with the name of your plugin in this file | ||
* 3 edit the global defaults | ||
* 4 refine the init method | ||
* | ||
*/ | ||
|
||
"use strict"; | ||
(function($, window, document) { | ||
(function($) { | ||
|
||
// Create the defaults once | ||
var pluginName = "Empty", | ||
defaults = { | ||
foo: "bar" | ||
}; | ||
var defaults = {}; | ||
|
||
// The actual plugin constructor | ||
function Plugin(elem, options) { | ||
// The actual plugin constructor | ||
function EmptyPlugin(elem, opts) { | ||
var self = this; | ||
|
||
self.$elem = $(elem); | ||
self.$elem = $(elem); | ||
|
||
// gather options by merging global defaults, plugin defaults and element defaults | ||
self.options = $.extend({}, defaults, options, self.$elem.data()); | ||
self.init(); | ||
} | ||
self.opts = $.extend({}, defaults, self.$elem.data(), opts); | ||
self.init(); | ||
} | ||
|
||
Plugin.prototype.init = function () { | ||
EmptyPlugin.prototype.init = function () { | ||
var self = this; | ||
// Place initialization logic here | ||
// You already have access to the DOM element and | ||
// the options via the instance, e.g. this.element | ||
// and this.options | ||
}; | ||
|
||
// A plugin wrapper around the constructor, | ||
// preventing against multiple instantiations | ||
$.fn[pluginName] = function (options) { | ||
return this.each(function () { | ||
if (!$.data(this, pluginName)) { | ||
$.data(this, pluginName, new Plugin(this, options)); | ||
} | ||
}); | ||
|
||
// Place initialization logic here | ||
// You already have access to the DOM element and | ||
// the options via the instance, e.g. this.element | ||
// and this.opts | ||
}; | ||
|
||
// A plugin wrapper around the constructor, | ||
// preventing against multiple instantiations | ||
$.fn.emptyPlugin = function (opts) { | ||
return this.each(function () { | ||
if (!$.data(this, "EmptyPlugin")) { | ||
$.data(this, "EmptyPlugin", new EmptyPlugin(this, opts)); | ||
} | ||
}); | ||
}; | ||
|
||
// Enable declarative widget instanziation | ||
$(".jq"+pluginName).livequery(function() { | ||
// Enable declarative widget instanziation | ||
$(function() { | ||
$(".jqEmptyPlugin:not(.jqEmptyPluginInited)").livequery(function() { | ||
$(this).addClass("jqEmptyPluginInited").emptyPlugin(); | ||
}); | ||
}); | ||
|
||
})(jQuery, window, document); | ||
})(jQuery); | ||
|