/ / Il mio widget jQuery personalizzato non funziona dopo l'aggiornamento all'interfaccia utente jQuery 1.10 - jquery, ruby-on-rails, jquery-ui

Il mio widget jQuery personalizzato non funziona dopo l'aggiornamento all'interfaccia utente jQuery 1.10 - jquery, ruby-on-rails, jquery-ui

Ho un semplice widget, la struttura è così:

(function ($, undefined) {
$.ui.newslettersignup = {
_create: function () {
console.log("dosomething");
},
destroy: function () {
// if using jQuery UI 1.8.x
$.Widget.prototype.destroy.call(this);
// if using jQuery UI 1.9.x
//this._destroy();
},
options:{

}
};
$.widget("ui.newslettersignup", $.ui.newslettersignup);
})(jQuery);

Ma dopo aver aggiornato jQuery e JQuery-UI a 1.10 dalla 1.8.3, continuo a ricevere l'errore:

Uncaught TypeError: Cannot read property "length" of undefined jquery.js:632
jQuery.extend.each jquery.js:632
$.widget jquery.ui.widget.js:123
(anonymous function) ui.newslettersignup.js:47
(anonymous function)

Ho provato a guardare le note di aggiornamento, ma non ho visto alcuna menzione di modifiche al jQuery.UI.Widget.

Se eseguo il debug nel browser, posso vedere che $ .ui.newslettersignup è disponibile, ma $ ("qualcosa"). Newslettersignup (); mi dà l'errore:

Object [object Object] has no method "newslettersignup"

NB. L'aggiornamento è fatto attraverso le due gemme di Rails "jquery-rails" e "jquery-ui-rails".

risposte:

0 per risposta № 1

Ho guardato i widget dell'interfaccia utente jQuery e ho modificato la sintassi in:

(function ($, undefined) {
$.widget("ui.newslettersignup", {
_create: function() {
},
options: {}
});
})(jQuery);

e poi ha funzionato. Non riuscivo ancora a trovare le note sul perché fosse cambiato, o perché questo non funzionasse più.