JQuery Plugins #2
نویسنده: مجتبی کاویانی
تاریخ: ۱۳۹۱/۱۲/۲۶ ۲۳:۵۵
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
(function( $ ){
$.fn.tooltip = function( options ) {
// این
};
$.fn.tooltipShow = function( ) {
// تعریف
};
$.fn.tooltipHide = function( ) {
// بد است
};
$.fn.tooltipUpdate = function( content ) {
// !
};
})( jQuery );(function( $ ){
var methods = {
init : function( options ) {
// این
},
show : function( ) {
// تعریف
},
hide : function( ) {
// خوب است
},
update : function( content ) {
// !
}
};
$.fn.tooltip = 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 {
$.error( 'Method ' + method + ' does not exist on jQuery.tooltip' );
}
};
})( jQuery );// تابع init صدا زده میشود
$('div').tooltip();// تابع update با پارامتر صدا زده میشود
$('div').tooltip('update', 'This is the new tooltip content!');(function( $ ){
var methods = {
init : function( options ) {
return this.each(function(){
$(window).bind('resize.tooltip', methods.reposition);
});
},
destroy : function( ) {
return this.each(function(){
$(window).unbind('.tooltip');
})
},
reposition : function( ) {
// ...
},
show : function( ) {
// ...
},
hide : function( ) {
// ...
},
update : function( content ) {
// ...
}
};
$.fn.tooltip = 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 {
$.error( 'Method ' + method + ' does not exist on jQuery.tooltip' );
}
};
})( jQuery );$('#fun').tooltip();
// مدتی بعد...
$('#fun').tooltip('destroy');