Skip to content

Instantly share code, notes, and snippets.

@qhwa
Created November 30, 2012 06:48
Show Gist options
  • Select an option

  • Save qhwa/4174179 to your computer and use it in GitHub Desktop.

Select an option

Save qhwa/4174179 to your computer and use it in GitHub Desktop.
// file: src/grunt-demo-1.js
(function($) {
var ALI_LINK_REG = /^http:\/\/(.+\.)?alibaba\.com/;
// Collection method.
$.fn.alilink = function() {
return this.each(function() {
var self = $(this);
if( isAliLink(this) ){
self.addClass('ali-link');
} else {
self.removeClass('ali-link');
}
});
};
// Custom selector.
$.expr[':'].alilink = function(elem) {
return isAliLink(elem);
};
function isAliLink(el) {
return /A/i.test(el.tagName) && ALI_LINK_REG.test(el.href);
}
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment