| | 390 | |
|---|
| | 391 | my $expr = { |
|---|
| | 392 | ":" => { |
|---|
| | 393 | # Position Checks |
|---|
| | 394 | lt => sub { return $_[1] < $_[2][3] }, |
|---|
| | 395 | gt => sub { return $_[1] > $_[2][3] }, |
|---|
| | 396 | nth => sub { return $_[2][3] == $_[1] }, |
|---|
| | 397 | eq => sub { return $_[2][3] == $_[1] }, |
|---|
| | 398 | first => sub { return $_[1] == 0 }, |
|---|
| | 399 | last => sub { return $_[1] == $#{$_[3]} }, |
|---|
| | 400 | even => sub { return $_[1] % 2 == 0 }, |
|---|
| | 401 | odd => sub { return $_[1] % 2 }, |
|---|
| | 402 | |
|---|
| | 403 | # Child Checks |
|---|
| | 404 | "first-child" => sub { |
|---|
| | 405 | return $_[0]->parentNode->getElementsByTagName("*")->[0] == $_[0]; |
|---|
| | 406 | }, |
|---|
| | 407 | "last-child" => sub { |
|---|
| | 408 | return pQuery->_nth( |
|---|
| | 409 | $_[0]->parentNode->lastChildRef, |
|---|
| | 410 | 1, |
|---|
| | 411 | "previousSiblingRef" |
|---|
| | 412 | ) == $_[0]; |
|---|
| | 413 | }, |
|---|
| | 414 | "only-child" => sub { |
|---|
| | 415 | return ! pQuery->_nth( |
|---|
| | 416 | $_[0]->parentNode->lastChildRef, |
|---|
| | 417 | 2, |
|---|
| | 418 | "previousSiblingRef" |
|---|
| | 419 | ); |
|---|
| | 420 | }, |
|---|
| | 421 | |
|---|
| | 422 | # Parent Checks |
|---|
| | 423 | parent => sub { return $_[0]->firstChild ? 1 : 0 }, |
|---|
| | 424 | empty => sub { return $_[0]->firstChild ? 0 : 1 }, |
|---|
| | 425 | |
|---|
| | 426 | # Text Check |
|---|
| | 427 | contains => sub { return index(pQuery($_[0])->text, $_[2][3]) >= 0 }, |
|---|
| | 428 | |
|---|
| | 429 | # // Visibility |
|---|
| | 430 | # visible: function(a){return "hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden";}, |
|---|
| | 431 | # hidden: function(a){return "hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden";}, |
|---|
| | 432 | # |
|---|
| | 433 | # // Form attributes |
|---|
| | 434 | # enabled: function(a){return !a.disabled;}, |
|---|
| | 435 | # disabled: function(a){return a.disabled;}, |
|---|
| | 436 | # checked: function(a){return a.checked;}, |
|---|
| | 437 | # selected: function(a){return a.selected||jQuery.attr(a,"selected");}, |
|---|
| | 438 | # |
|---|
| | 439 | # // Form elements |
|---|
| | 440 | # text: function(a){return "text"==a.type;}, |
|---|
| | 441 | # radio: function(a){return "radio"==a.type;}, |
|---|
| | 442 | # checkbox: function(a){return "checkbox"==a.type;}, |
|---|
| | 443 | # file: function(a){return "file"==a.type;}, |
|---|
| | 444 | # password: function(a){return "password"==a.type;}, |
|---|
| | 445 | # submit: function(a){return "submit"==a.type;}, |
|---|
| | 446 | # image: function(a){return "image"==a.type;}, |
|---|
| | 447 | # reset: function(a){return "reset"==a.type;}, |
|---|
| | 448 | # button: function(a){return "button"==a.type||jQuery.nodeName(a,"button");}, |
|---|
| | 449 | # input: function(a){return /input|select|textarea|button/i.test(a.nodeName);}, |
|---|
| | 450 | |
|---|
| | 451 | |
|---|
| | 452 | # :has() |
|---|
| | 453 | # XXX - The first form should work. Indicates that context is messed up. |
|---|
| | 454 | # has => sub { return pQuery->find($_[2][3], $_[0])->length ? 1 : 0 }, |
|---|
| | 455 | has => sub { return pQuery($_[0])->find($_[2][3])->length ? 1 : 0 }, |
|---|
| | 456 | |
|---|
| | 457 | # :header |
|---|
| | 458 | header => sub { return $_[0]->nodeName =~ /^h[1-6]$/i }, |
|---|
| | 459 | }, |
|---|
| | 460 | }; |
|---|
| | 461 | |
|---|
| | 462 | # The regular expressions that power the parsing engine |
|---|
| | 463 | my $parse = [ |
|---|
| | 464 | # Match: [@value='test'], [@foo] |
|---|
| | 465 | qr/^(\[) *@?([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/, |
|---|
| | 466 | |
|---|
| | 467 | # Match: :contains('foo') |
|---|
| | 468 | qr/^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/, |
|---|
| | 469 | |
|---|
| | 470 | # Match: :even, :last-chlid, #id, .class |
|---|
| | 471 | qr/^([:.#]*)($chars+)/, |
|---|
| | 472 | ]; |
|---|
| | 473 | |
|---|
| | 474 | sub _multiFilter { |
|---|
| | 475 | # XXX - Port me. |
|---|
| | 476 | } |
|---|
| | 477 | |
|---|
| 557 | | # The regular expressions that power the parsing engine |
|---|
| 558 | | my $parse = [ |
|---|
| 559 | | # Match: [@value='test'], [@foo] |
|---|
| 560 | | qr/^(\[) *@?([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/, |
|---|
| 561 | | |
|---|
| 562 | | # Match: :contains('foo') |
|---|
| 563 | | qr/^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/, |
|---|
| 564 | | |
|---|
| 565 | | # Match: :even, :last-chlid, #id, .class |
|---|
| 566 | | qr/^([:.#]*)($chars+)/, |
|---|
| 567 | | ]; |
|---|
| 568 | | |
|---|
| 569 | | my $expr = { |
|---|
| 570 | | ":" => { |
|---|
| 571 | | # Position Checks |
|---|
| 572 | | lt => sub { return $_[1] < $_[2][3] }, |
|---|
| 573 | | gt => sub { return $_[1] > $_[2][3] }, |
|---|
| 574 | | nth => sub { return $_[2][3] == $_[1] }, |
|---|
| 575 | | eq => sub { return $_[2][3] == $_[1] }, |
|---|
| 576 | | first => sub { return $_[1] == 0 }, |
|---|
| 577 | | last => sub { return $_[1] == $#{$_[3]} }, |
|---|
| 578 | | even => sub { return $_[1] % 2 == 0 }, |
|---|
| 579 | | odd => sub { return $_[1] % 2 }, |
|---|
| 580 | | |
|---|
| 581 | | # Child Checks |
|---|
| 582 | | "first-child" => sub { |
|---|
| 583 | | return $_[0]->parentNode->getElementsByTagName("*")->[0] == $_[0]; |
|---|
| 584 | | }, |
|---|
| 585 | | "last-child" => sub { |
|---|
| 586 | | return pQuery->_nth( |
|---|
| 587 | | $_[0]->parentNode->lastChildRef, |
|---|
| 588 | | 1, |
|---|
| 589 | | "previousSiblingRef" |
|---|
| 590 | | ) == $_[0]; |
|---|
| 591 | | }, |
|---|
| 592 | | "only-child" => sub { |
|---|
| 593 | | return ! pQuery->_nth( |
|---|
| 594 | | $_[0]->parentNode->lastChildRef, |
|---|
| 595 | | 2, |
|---|
| 596 | | "previousSiblingRef" |
|---|
| 597 | | ); |
|---|
| 598 | | }, |
|---|
| 599 | | |
|---|
| 600 | | # Text Check |
|---|
| 601 | | contains => sub { return index(pQuery($_[0])->text, $_[2][3]) >= 0 }, |
|---|
| 602 | | |
|---|
| 603 | | # :header |
|---|
| 604 | | header => sub { return $_[0]->nodeName =~ /^h[1-6]$/i }, |
|---|
| 605 | | |
|---|
| 606 | | }, |
|---|
| 607 | | }; |
|---|
| 608 | | |
|---|