(function () {
/**
* @var Object Default plugin options
*/
var defaultOptions = {
'param1' : 'foo',
'param2' : 'bar'
};
/**
* @param current jQuery element
*/
var $this = null;
/**
* @param all plugin methods
*/
var methods = {
init: function () {
var settings = $.extend(defaultOptions, options);
return this.each(function() {
$this = $(this);
// Write code here
});
}
};
/**
* Plugin constructor
* @param method
*/
jQuery.fn.myNewCoolPlugin = function (method) {
if (methods[method]) {
return methods[ method ].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || ! method) {
return methods.init.apply(this, arguments);
} else {
jQuery.error('Method ' + method + ' does not exist on jQuery.tooltip');
}
};
})(jQuery);
Важный совет: каждый новый плагин должен писаться в своем замыкании.
понедельник, 23 января 2012 г.
jQuery. Каркас для плагина.
Для плагинописания jQuery советуют использовать каркас который примерно таков.
Подписаться на:
Комментарии к сообщению (Atom)
Комментариев нет:
Отправить комментарий