Как я могу переопределить внешний всплывающий код jQuery в Prototype?
-
01-07-2019 - |
Вопрос
У меня есть этот код в 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;
});
Как вы можете итеративно фильтровать коллекцию элементов, используя эквивалент операторов not (), перечисленных здесь, в jQuery?
Решение
Фильтрация может быть выполнена с помощью метода отклонения следующим образом:
$$('a').reject(function(element) { return element.getAttribute("href").match(/http:\/\/(www.|)foo.com/); }).invoke("addClassName", "external");
Не связан с StackOverflow