﻿if (jQuery) {
	
	// Selectors
	////////////////////////////

	// :containsOnly - will perform a case-sensitive match on elements (excluding their children) containing only the exact specified text
	$.expr[":"].containsOnly = function(obj, index, meta, stack) {
		return ($(obj).textContents() || "") == meta[3];
	}

	// :containsOnly_ci - will perform a case-insensitive match on elements (excluding their children) containing only the exact specified text
	$.expr[":"].containsOnly_ci = function(obj, index, meta, stack) {
		return ($(obj).textContents() || "").toLowerCase() == meta[3].toLowerCase();
	}
	
	// :containsExactly - will perform a case-sensitive match on elements (including their children) containing only the exact specified text
	$.expr[":"].containsExactly = function(obj, index, meta, stack) {
		//return (obj.textContent || obj.innerText || $(obj).text() || "").toLowerCase() == meta[3].toLowerCase();
		return (obj.textContent || obj.innerText || $(obj).text() || "") == meta[3];
	}

	// :containsExactly - will perform a case-insensitive match on elements (including their children) containing only the exact specified text
	$.expr[":"].containsExactly_ci = function(obj, index, meta, stack) {
		return (obj.textContent || obj.innerText || $(obj).text() || "").toLowerCase() == meta[3].toLowerCase();
	}

	// :contains-ci - will perform a case-insensitive match on elements (including their children) containing the specified text anywhere
	$.expr[':'].contains_ci = function(obj, index, meta, stack) {
		return (obj.textContent || obj.innerText || jQuery(obj).text() || '').toLowerCase().indexOf(meta[3].toLowerCase()) >= 0;
	};
	
	// Traversal
	////////////////////////

	$.fn.textContents = function(elem) {
		return elem.contents().filter(function() {
			return this.nodeType == 3;
		});
	}
}
