react / wstein / node_modules / jest-cli / node_modules / jsdom / node_modules / nwmatcher / src / modules / nwmatcher-jquery.js
81144 views/*1* Copyright (C) 2007-2015 Diego Perini2* All rights reserved.3*4* this is just a small example to show5* how an extension for NWMatcher could be6* adapted to handle special jQuery selectors7*8* Child Selectors9* :even, :odd, :eq, :lt, :gt, :first, :last, :nth10*11* Pseudo Selectors12* :has, :button, :header, :input, :checkbox, :radio, :file, :image13* :password, :reset, :submit, :text, :hidden, :visible, :parent14*15*/1617// for structural pseudo-classes extensions18NW.Dom.registerSelector(19'jquery:child',20/^\:((?:(nth|eq|lt|gt)\(([^()]*)\))|(?:even|odd|first|last))(.*)/i,21(function(global) {2223return function(match, source, selector) {2425var status = true, ACCEPT_NODE = NW.Dom.ACCEPT_NODE;2627switch (match[1].toLowerCase()) {28case 'odd':29source = source.replace(ACCEPT_NODE, 'if((x=x^1)==0){' + ACCEPT_NODE + '}');30break;31case 'even':32source = source.replace(ACCEPT_NODE, 'if((x=x^1)==1){' + ACCEPT_NODE + '}');33break;34case 'first':35source = 'n=h.getElementsByTagName(e.nodeName);if(n.length&&n[0]===e){' + source + '}';36break;37case 'last':38source = 'n=h.getElementsByTagName(e.nodeName);if(n.length&&n[n.length-1]===e){' + source + '}';39break;40default:41switch (match[2].toLowerCase()) {42case 'nth':43source = 'n=h.getElementsByTagName(e.nodeName);if(n.length&&n[' + match[3] + ']===e){' + source + '}';44break;45case 'eq':46source = source.replace(ACCEPT_NODE, 'if(x++==' + match[3] + '){' + ACCEPT_NODE + '}');47break;48case 'lt':49source = source.replace(ACCEPT_NODE, 'if(x++<' + match[3] + '){' + ACCEPT_NODE + '}');50break;51case 'gt':52source = source.replace(ACCEPT_NODE, 'if(x++>' + match[3] + '){' + ACCEPT_NODE + '}');53break;54default:55status = false;56break;57}58break;59}6061// compiler will add this to "source"62return global.Object({63'source': source,64'status': status65});6667};6869})(this));7071// for element pseudo-classes extensions72NW.Dom.registerSelector(73'jquery:pseudo',74/^\:(has|checkbox|file|image|password|radio|reset|submit|text|button|input|header|hidden|visible|parent)(?:\(\s*(["']*)?([^'"()]*)\2\s*\))?(.*)/i,75(function(global) {7677return function(match, source) {7879var status = true, ACCEPT_NODE = NW.Dom.ACCEPT_NODE;8081switch(match[1].toLowerCase()) {82case 'has':83source = source.replace(ACCEPT_NODE, 'if(e.getElementsByTagName("' + match[3].replace(/^\s|\s$/g, '') + '")[0]){' + ACCEPT_NODE + '}');84break;85case 'checkbox':86case 'file':87case 'image':88case 'password':89case 'radio':90case 'reset':91case 'submit':92case 'text':93// :checkbox, :file, :image, :password, :radio, :reset, :submit, :text94source = 'if(/^' + match[1] + '$/i.test(e.type)){' + source + '}';95break;96case 'button':97case 'input':98source = 'if(e.type||/button/i.test(e.nodeName)){' + source + '}';99break;100case 'header':101source = 'if(/h[1-6]/i.test(e.nodeName)){' + source + '}';102break;103case 'hidden':104source = 'if(!e.offsetWidth&&!e.offsetHeight){' + source + '}';105break;106case 'visible':107source = 'if(e.offsetWidth||e.offsetHeight){' + source + '}';108break;109case 'parent':110source += 'if(e.firstChild){' + source + '}';111break;112default:113status = false;114break;115}116117// compiler will add this to "source"118return global.Object({119'source': source,120'status': status121});122123};124125})(this));126127128