5 class_exists(
'duzun\\hQuery\\Node',
false) or require_once __DIR__ . DIRECTORY_SEPARATOR . 'Node.php';
15 protected $_ich = NULL;
17 public function toArray($cch=
true) {
18 if($cch && isset($this->_ich) && count($this->ids) === count($this->_ich))
return $this->_ich;
21 foreach($this->ids as $b => $e) {
22 $ret[$b] = isset($this->_ich[$b])
24 : ( $this->_ich[$b] =
new self($this->doc, array($b=>$e)) )
29 foreach($this->ids as $b => $e) {
30 $ret[$b] =
new self($this->doc, array($b=>$e));
37 public function __get($name) {
40 case 'html' :
return $this->
html();
41 case 'outerHtml':
return $this->
outerHtml();
43 case 'text' :
return $this->
text();
44 case 'attr' :
return $this->
attr();
46 case 'val' :
return $this->val();
47 case 'nodeName' :
return $this->
nodeName(
false);
48 case 'parent' :
return $this->parent();
49 case 'children' :
return $this->children();
50 case 'nextElementSibling' :
return $this->nextElementSibling();
51 case 'previousElementSibling' :
return $this->previousElementSibling();
52 case 'className': $name =
'class';
break;
56 if($this->_prop && array_key_exists($name, $this->_prop))
return $this->_prop[$name];
72 return $this->
attr($name);
78 public function offsetSet($offset, $value) {
79 if(is_null($offset)) {
83 $i = array_slice($this->ids, $offset, 1,
true);
87 $this->__set($offset, $value);
91 public function offsetGet($offset) {
92 return is_int($offset)
94 : $this->__get($offset)
98 public function offsetExists($offset) {
100 return 0 <= $offset && $offset < count($this->ids);
102 return $this->__isset($offset);
105 public function offsetUnset($offset) {
106 if(is_int($offset)) {
107 $i = array_slice($this->ids, $offset, 1,
true);
110 unset($this->ids[$i], $this->_ich[$i]);
114 unset($this->_prop[$offset]);
125 $k = key($this->ids);
126 if($k === NULL)
return false;
127 if(count($this->ids) == 1)
return $this;
128 if(!isset($this->_ich[$k])) $this->_ich[$k] =
new self($this->doc, array($k=>$this->ids[$k]));
129 return $this->_ich[$k];
139 $el = count($this) > 1 ? $this->
get(0) : $this;
140 switch(strtoupper($el->nodeName(
false))) {
144 switch(strtoupper($el->attr(
'type'))) {
145 case 'CHECKBOX':
if ( $el->attr(
'checked') === false )
return false;
146 default:
return $el->attr(
'value');
151 default:
return false;
162 $ret = $this->
doc()->hasClass($this, $className);
163 if ( !is_array($ret) )
return $ret;
164 if ( count($this) < 2 )
return reset($ret);
176 public function get($idx) {
177 $i = array_slice($this->ids, $idx, 1,
true);
182 if(isset($this->_ich[$k]))
return $this->_ich[$k];
185 $o =
new self($this->doc, $i);
188 $this->_ich[$k] = $o;
200 public function eq($idx) {
201 $i = array_slice($this->ids, $idx, 1,
true) or
204 $o =
new self($this->doc, $i);
216 public function slice($idx, $len=NULL) {
218 if($idx < $c) $ids = array();
221 if($idx == 0 && $len == $c) {
225 $ids = array_slice($this->ids, $idx, $len,
true);
232 $ids = array_slice($this->ids, $idx, $this->count(),
true);
234 $o =
new self($this->doc, $ids);
235 $o->_ich = &$this->_ich;
245 $p = $this->_parent();
246 return $p ?
new self($this->doc, $p) : NULL;
255 $p = $this->_children();
256 return $p ?
new self($this->doc, $p) : NULL;
266 return $p ?
new self($this->doc, $p) : NULL;
276 return $p ?
new self($this->doc, $p) : NULL;
nodeName($caseFolding=NULL, $id=NULL)
attr($attr=NULL, $to_str=false)