jQuery e funzioni personalizzate: su cosa si basa this?
Ho trovato un plug-in molto utile, ma non riesco a capire come personalizzarlo per poterlo implementare in base alle mie esigenze.
Il plug ha questa struttura:
Codice:
(function ($)
{
$.extend({
name: function(selector, callback)
{
// Listen for any anchor tag call
$(selector).live('click', function (e)
{
// prevent the default reloading the page
e.preventDefault();
var new_var = this.href;
});
callback();
}
});
})(jQuery);
Quindi, avendo un codice simile (che attualmente non funziona come dovrebbe):
Codice:
var element = 'div a';
var content = $('#content');
$.name(element + ':not([href^=http]', function(other_var)
{
if (!($(element).hasClass('active')))
{
$(element + '.active').removeClass('active');
content.load(other_var);
}
/*
questa č una stringa esemplificativa su quali elementi devo lavorare
*/
$(this).addClass('active');
return false;
});
come dovrei fare per poter assegnare this al primo valore passato alla funzione name piuttosto che a other_var per poterci lavorare?
:wink: