jQuery Plugin Boilerplate
来源:互联网 发布:麦萌网络 编辑:程序博客网 时间:2024/05/22 19:18
// jQuery Plugin Boilerplate// A boilerplate for jumpstarting jQuery plugins development// version 1.1, May 14th, 2011// by Stefan Gabos // remember to change every instance of "pluginName" to the name of your plugin!(function($) { // here we go! $.pluginName = function(element, options) { // plugin's default options // this is private property and is accessible only from inside the plugin var defaults = { foo: 'bar', // if your plugin is event-driven, you may provide callback capabilities // for its events. execute these functions before or after events of your // plugin, so that users may customize those particular events without // changing the plugin's code onFoo: function() {} } // to avoid confusions, use "plugin" to reference the // current instance of the object var plugin = this; // this will hold the merged default, and user-provided options // plugin's properties will be available through this object like: // plugin.settings.propertyName from inside the plugin or // element.data('pluginName').settings.propertyName from outside the plugin, // where "element" is the element the plugin is attached to; plugin.settings = {} var $element = $(element), // reference to the jQuery version of DOM element element = element; // reference to the actual DOM element // the "constructor" method that gets called when the object is created plugin.init = function() { // the plugin's final properties are the merged default and // user-provided options (if any) plugin.settings = $.extend({}, defaults, options); // code goes here } // public methods // these methods can be called like: // plugin.methodName(arg1, arg2, ... argn) from inside the plugin or // element.data('pluginName').publicMethod(arg1, arg2, ... argn) from outside // the plugin, where "element" is the element the plugin is attached to; // a public method. for demonstration purposes only - remove it! plugin.foo_public_method = function() { // code goes here } // private methods // these methods can be called only from inside the plugin like: // methodName(arg1, arg2, ... argn) // a private method. for demonstration purposes only - remove it! var foo_private_method = function() { // code goes here } // fire up the plugin! // call the "constructor" method plugin.init(); } // add the plugin to the jQuery.fn object $.fn.pluginName = function(options) { // iterate through the DOM elements we are attaching the plugin to return this.each(function() { // if plugin has not already been attached to the element if (undefined == $(this).data('pluginName')) { // create a new instance of the plugin // pass the DOM element and the user-provided options as arguments var plugin = new $.pluginName(this, options); // in the jQuery version of the element // store a reference to the plugin object // you can later access the plugin and its methods and properties like // element.data('pluginName').publicMethod(arg1, arg2, ... argn) or // element.data('pluginName').settings.propertyName $(this).data('pluginName', plugin); } }); } })(jQuery);
0 0
- jQuery Plugin Boilerplate
- boilerplate
- jquery plugin
- jquery plugin
- Gstreamer插件教程2.1—编写一个插件(Writing a Plugin):构建样板(Constructing the Boilerplate)
- jQuery 对话框 jQuery.plugin
- jQuery / jQuery mvc plugin
- HTML5 Boilerplate
- HTML5 Boilerplate
- HTML5 Boilerplate
- jQuery Form Plugin
- jQuery - plugin插件 - Cookie
- jQuery BlockUI Plugin
- Jquery for table plugin
- Jquery plugin 大全
- Jquery plugin 大全
- jQuery Plugin Container
- manageAjax jquery plugin
- navicat执行sql文件时,中文乱码的处理
- 在Html<span>添加CSS样式
- 个人知识管理
- Velocity宏定义的坑与解决办法
- ORALCE 的字符串转换为列表
- jQuery Plugin Boilerplate
- UINavigationController 复习知识
- 统计频率【map的用法】【字典序】
- Qt事件过滤
- 第7周作业1-循环大战(DO-WHILE语句)
- 【Spring】IOC核心源码学习:容器初始化过程
- 存储数据のSharedPreferences
- Oracle:Dynamic SQL Enhancements
- xcode command line tools