]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/ex-mode/node_modules/space-pen/node_modules/jquery/src/sizzle/test/unit/extending.js
4b4c6e8419af8239f4da2da4c7137c74a51d79bb
[rbdr/dotfiles] / atom / packages / ex-mode / node_modules / space-pen / node_modules / jquery / src / sizzle / test / unit / extending.js
1 module("extending", { teardown: moduleTeardown });
2
3 test("custom pseudos", function() {
4 expect( 6 );
5
6 Sizzle.selectors.filters.foundation = Sizzle.selectors.filters.root;
7 deepEqual( Sizzle(":foundation"), [ document.documentElement ], "Copy element filter with new name" );
8 delete Sizzle.selectors.filters.foundation;
9
10 Sizzle.selectors.setFilters.primary = Sizzle.selectors.setFilters.first;
11 t( "Copy set filter with new name", "div:primary", ["qunit"] );
12 delete Sizzle.selectors.setFilters.primary;
13
14 Sizzle.selectors.filters.aristotlean = Sizzle.selectors.createPseudo(function() {
15 return function( elem ) {
16 return !!elem.id;
17 };
18 });
19 t( "Custom element filter", "#foo :aristotlean", [ "sndp", "en", "yahoo", "sap", "anchor2", "simon" ] );
20 delete Sizzle.selectors.filters.aristotlean;
21
22 Sizzle.selectors.filters.endswith = Sizzle.selectors.createPseudo(function( text ) {
23 return function( elem ) {
24 return Sizzle.getText( elem ).slice( -text.length ) === text;
25 };
26 });
27 t( "Custom element filter with argument", "a:endswith(ogle)", ["google"] );
28 delete Sizzle.selectors.filters.endswith;
29
30 Sizzle.selectors.setFilters.second = Sizzle.selectors.createPseudo(function() {
31 return Sizzle.selectors.createPseudo(function( seed, matches ) {
32 if ( seed[1] ) {
33 matches[1] = seed[1];
34 seed[1] = false;
35 }
36 });
37 });
38 t( "Custom set filter", "#qunit-fixture p:second", ["ap"] );
39 delete Sizzle.selectors.filters.second;
40
41 Sizzle.selectors.setFilters.slice = Sizzle.selectors.createPseudo(function( argument ) {
42 var bounds = argument.split(":");
43 return Sizzle.selectors.createPseudo(function( seed, matches ) {
44 var i = bounds[1];
45
46 // Match elements found at the specified indexes
47 while ( --i >= bounds[0] ) {
48 if ( seed[i] ) {
49 matches[i] = seed[i];
50 seed[i] = false;
51 }
52 }
53 });
54 });
55 t( "Custom set filter with argument", "#qunit-fixture p:slice(1:3)", [ "ap", "sndp" ] );
56 delete Sizzle.selectors.filters.slice;
57 });
58
59 test("backwards-compatible custom pseudos", function() {
60 expect( 3 );
61
62 Sizzle.selectors.filters.icontains = function( elem, i, match ) {
63 return Sizzle.getText( elem ).toLowerCase().indexOf( (match[3] || "").toLowerCase() ) > -1;
64 };
65 t( "Custom element filter with argument", "a:icontains(THIS BLOG ENTRY)", ["simon1"] );
66 delete Sizzle.selectors.filters.icontains;
67
68 Sizzle.selectors.setFilters.podium = function( elements, argument ) {
69 var count = argument == null || argument === "" ? 3 : +argument;
70 return elements.slice( 0, count );
71 };
72 // Using TAG as the first token here forces this setMatcher into a fail state
73 // Where the descendent combinator was lost
74 t( "Custom setFilter", "form#form :PODIUM", ["label-for", "text1", "text2"] );
75 t( "Custom setFilter with argument", "#form input:Podium(1)", ["text1"] );
76 delete Sizzle.selectors.setFilters.podium;
77 });
78
79 test("custom attribute getters", function() {
80 expect( 2 );
81
82 var original = Sizzle.selectors.attrHandle.hreflang,
83 selector = "a:contains('mark')[hreflang='http://diveintomark.org/en']";
84
85 Sizzle.selectors.attrHandle.hreflang = function( elem, name ) {
86 var href = elem.getAttribute("href"),
87 lang = elem.getAttribute( name );
88 return lang && ( href + lang );
89 };
90
91 deepEqual( Sizzle(selector, createWithFriesXML()), [], "Custom attrHandle (preferred document)" );
92 t( "Custom attrHandle (preferred document)", selector, ["mark"] );
93
94 Sizzle.selectors.attrHandle.hreflang = original;
95 });