2008-09-17 12 views
1

このコードはjQueryにあり、プロトタイプライブラリで再実装したいと思います。プロトタイプで外部ポップアップjQueryコードを再実装するにはどうすればよいですか?

// make external links open in popups 
// this will apply a window.open() behaviour to all anchor links 
// the not() functions filter iteratively filter out http://www.foo.com 
// and http://foo.com so they don't trigger off the pop-ups 

jQuery("a[href='http://']"). 
     not("a[href^='http://www.foo.com']"). 
     not("a[href^='http://foo.com']"). 
     addClass('external'); 

jQuery("a.external"). 
     not('a[rel="lightbox"]').click(function() { 
     window.open(jQuery(this).attr('href')); 
     return false; 
}); 

どのように反復的にjQueryのここに記載されていない()事業者に相当するものを使用して要素のコレクションをフィルタリングすることができますか?

答えて

4

フィルタリングはそうのようなメソッドを拒否用いて行うことができる。

$$('a').reject(function(element) { return element.getAttribute("href").match(/http:\/\/(www.|)foo.com/); }).invoke("addClassName", "external");