結構前から収集していた海外エントリから面白いcustom eventの使い方を紹介
jQueryでは非DOMオブジェクトにもeventをbind/triggerできる
Binding Events To Non-DOM Objects With jQuery
この例だとwindow.location.hrefが変化しているかどうかTimerで監視し続け、
変化したタイミングで$( window.location ).trigger('change',data);で変更前後の情報を通知している。
なので、$( window.location ).bind('change',function(ev,data){});で通知を受け取る事ができる。
hashで状態を管理しているAjaxアプリで有効そうなテクニック。
select boxでcustom eventを活用
http://trulyevil.com/2009/05/07/custom-events-in-jquery/
$('select.test').change( function() { $(this).trigger('update', $(this).val()); });
このコードでselect boxのchange eventを値を通知するupdate eventとして再発火する。
$('select.test').bind('update', function(e, data) { console.log(data); )};
こういうコードで取れる。
formのこういう類のeventを値を通知するeventとしてtriggerするとか、
ブラウザ毎に動作が違うeventを他の方法で検知してtriggerなど便利そうだ。