コード例 #1
0
ファイル: after.php プロジェクト: Webictbyleo/JqueryPhp
 public function run($str = NULL)
 {
     if ($str == NULL) {
         return $this;
     }
     $dom = $this->node->dom()->get();
     $this->node->_lastDom = $dom->lastdom . $str;
     $rec = new DomDocument();
     $rec->loadHtml($str);
     if ($rec->doctype) {
         $rec->removeChild($rec->doctype);
     }
     $document = jqm_use($this->node->_parentElement);
     $dom = $document->_DOM;
     if ($dom->doctype) {
         $dom->removeChild($dom->doctype);
     }
     $body = $rec->childNodes->item(0)->firstChild;
     $frag = $dom->importNode($body, true);
     $xpath = new DomXpath($dom);
     $find = $this->node->getPathByID($dom);
     $find = $xpath->query($find);
     if ($find->length > 0) {
         $save = $find->item(0)->parentNode->insertBefore($frag->firstChild, $find->item(0)->nextSibling);
         $this->node->_path = $save->previousSibling->getNodePath();
         $document->_DOM = $dom;
     }
     return $this;
 }
コード例 #2
0
ファイル: nextall.php プロジェクト: Webictbyleo/JqueryPhp
 public function run()
 {
     $dom = $this->node->__toDomElement();
     $ns = jqm_use($this->node->_parentElement);
     $done = true;
     $node = $dom;
     while ($done != false) {
         if ($node->nextSibling) {
             $node = $node->nextSibling;
             if ($node->nodeType !== 1) {
                 continue;
             }
             $el = $this->createFragment($dom->ownerDocument->saveHtml($node), false);
             $el->_path = $node->getNodepath();
             $el->_parentElement = $this->node->_parentElement;
             $el->_parent_path = $this->node->_parent_path;
             $el->_prev_path = $this->node->_prev_path;
             $el->_next_path = $this->node->_next_path;
             $el->setDomID($this->node->_parentElement . $this->node->_token);
             $el->selector = $ns->match_selector($node->tagName . '[data-dom-id="' . key($el->_domId) . '"]', $el->_path . '::', false);
             $nodes[] = $el;
         } else {
             $done = false;
             break;
         }
     }
     if (!isset($nodes) || empty($nodes)) {
         return $this->node = new jqueryphp_abstracts_prevObject();
     }
     $this->node = new jqueryphp_abstracts_nodelist($nodes);
     return $this;
 }
コード例 #3
0
ファイル: remove.php プロジェクト: Webictbyleo/JqueryPhp
 public function run()
 {
     $document = jqm_use($this->node->_parentElement);
     $doc = $document->_DOM;
     if ($doc->doctype) {
         $doc->removeChild($doc->doctype);
     }
     $pt = $this->node->getPathByID();
     if ($pt) {
         $path = new DomXpath($doc);
         $get = $path->query($pt);
         if ($get->length > 0) {
             $this->node->_attributes = array();
             $this->node->_innerHtml = NULL;
             $this->node->_name = NULL;
             $this->node->_localName = NULL;
             $this->node->_length = false;
             $save = $get->item(0)->parentNode->removeChild($get->item(0));
             $document->offsetUnset($this->node->_token);
         }
     } else {
         $document->offsetUnset($this->node->_token);
         $this->node->_length = false;
     }
 }
コード例 #4
0
ファイル: on.php プロジェクト: Webictbyleo/JqueryPhp
 public function run($event, $selector = NULL, $data, $callback, $once = false)
 {
     if ($event == NULL) {
         return $this;
     }
     $callable = is_callable($callback) || function_exists($callback);
     if (!$callback) {
         return $this;
     }
     if (!is_a($this->node, jqmel)) {
         return $this;
     }
     $ns = $this->node->data('_parentElement')->get();
     if (empty($ns)) {
         return $this;
     }
     $document = jqm_use($ns);
     if (!isset($document->Window) and !is_a($document->Window, jqmwin)) {
         return false;
     }
     if (!isset($this->node->events)) {
         $this->node->data('events', new stdclass());
     }
     if (!isset($this->node->events->{$event})) {
         $this->node->events->{$event} = array();
     }
     /* if(!isset($this->node->trace)){
     				$this->node->events[$event] = true;
     			} */
     array_unshift($this->node->events->{$event}, array($callback, $data, $selector, $once));
     return $this;
 }
コード例 #5
0
ファイル: before.php プロジェクト: Webictbyleo/JqueryPhp
 public function run($str = NULL)
 {
     if ($str == NULL) {
         return $this;
     }
     $document = jqm_use($this->node->_parentElement);
     $dom = $document->_DOM;
     if ($dom->doctype) {
         $dom->removeChild($dom->doctype);
     }
     $find = $this->node->getPathById($dom);
     if (!$find) {
         $find = $this->node->_path;
     }
     $xpath = new DomXpath($dom);
     $find = $xpath->query($find);
     if ($find->length > 0) {
         $child = new DomDocument();
         $child->loadHtml($str);
         if ($child->doctype) {
             $child->removeChild($child->doctype);
         }
         $child->normalize();
         $frag = $dom->importNode($child->firstChild->firstChild->firstChild, true);
         $save = $find->item(0)->parentNode->insertBefore($frag, $find->item(0));
         $this->node->_path = $save->nextSibling->getNodePath();
         $document->_DOM = $dom;
     }
     return $this;
 }
コード例 #6
0
ファイル: parents.php プロジェクト: Webictbyleo/JqueryPhp
 public function run($query = '*')
 {
     $path = explode('/', $this->node->_path);
     $el = $this->__toDomElement();
     $document = jqm_use($this->node->_parentElement);
     if (count($path) > 0) {
         if ($query === NULL || $query == '*') {
             $query = $el->parentNode->tagName;
         }
         $t = count($path);
         $doc = $document->_DOM;
         if ($doc->doctype) {
             $doc->removeChild($doc->doctype);
         }
         $xpath = new DomXpath($doc);
         for ($i = 0; $t > $i;) {
             array_pop($path);
             ++$i;
             if (empty($path)) {
                 continue;
             }
             $find = $xpath->query(implode('/', $path));
             if ($find->length > 0) {
                 $el = $this->createFragment($doc->saveHtml($find->item(0)), false);
                 $k = key($el->_domId);
                 $is = $el->is($query);
                 if ($is->get() === true) {
                     $el->_path = $find->item(0)->getNodepath();
                     if ($find->item(0)->nextSibling) {
                         $el->_next_path = $find->item(0)->nextSibling->getNodepath();
                     } else {
                         $el->_next_path = NULL;
                     }
                     if ($find->item(0)->previousSibling) {
                         $el->_prev_path = $find->item(0)->previousSibling->getNodepath();
                     } else {
                         $el->_prev_path = NULL;
                     }
                     if ($find->item(0)->parentNode) {
                         $el->_parent_path = $find->item(0)->parentNode->getNodepath();
                     } else {
                         $el->_parent_path = NULL;
                     }
                     $el->selector = $document->match_selector($query);
                     $this->node = $el;
                     $this->node->setDomID($el->_parentElement . $el->_token);
                     return $this;
                     break;
                 }
             }
         }
         $this->node = new jqueryphp_abstracts_prevObject($this->node->_selector . ':parent(*)');
         return $this;
     } else {
         return $this->node = new jqueryphp_abstracts_prevObject($this->node->_selector . ':parent(*)');
     }
 }
コード例 #7
0
ファイル: find.php プロジェクト: Webictbyleo/JqueryPhp
 public function run($query)
 {
     if (!is_null($query)) {
         $regex = '/<([a-z0-9\\-]*)\\b(.*?)>(.*?)(<\\/\\1>)/is';
         $this->node->refreshDom();
         $html = $this->node->data('_innerHtml')->get();
         $document = jqm_use($this->node->_parentElement);
         $selector = $document->match_selector($query, false);
         if ($selector) {
             $jqm = new JqueryBoxManager();
             $tag = '*';
             $doc = $jqm->load($html, $tag);
             if (!is_a($doc, jqmdoc)) {
                 return false;
             }
             if ($this->node->_name === 'select') {
                 //var_dump($doc->count());
             }
             $dom = $doc->search($query);
             if ($dom->count() > 0) {
                 $this->node->_innerHtml = str_ireplace(array('<html>', '<body>', '</html>', '</body>', '<head>', '</head>'), '', $doc->__documentRaw);
                 $this->savehtml();
                 $nodes = array();
                 $t = $dom->count();
                 jqm_use($dom->current()->_parentElement);
                 //$dom->rewind();
                 for ($i = 0; $t > $i; $i++) {
                     $dom->seek($i);
                     $dom->current()->_token = $document->count() + 1;
                     $p = substr($dom->current()->_path, stripos($dom->current()->_path, 'body') + 4);
                     $dom->current()->_path = $this->node->_path . '/' . $p;
                     $dom->current()->_parentElement = $this->node->_parentElement;
                     $dom->current()->_parent_path = $this->node->_path;
                     if ($dom->current()->_prev_path) {
                         $p = substr($dom->current()->_prev_path, stripos($dom->current()->_prev_path, 'body') + 4);
                         $dom->current()->_prev_path = $dom->current()->_parent_path . '/' . $p;
                     }
                     if ($dom->current()->_next_path) {
                         $p = substr($dom->current()->_next_path, stripos($dom->current()->_next_path, 'body') + 4);
                         $dom->current()->_next_path = $dom->current()->_parent_path . '/' . $p;
                     }
                     //$document->offsetSet($document->count()+1,$dom->current());
                     $nodes[] = $dom->current();
                     //$dom->offsetUnset($i);
                 }
                 unset($dom);
                 $this->node = new jqueryphp_abstracts_nodelist($nodes);
             } else {
                 $this->node = new jqueryphp_abstracts_prevObject($selector['selectors']);
             }
         }
     }
     return $this->node;
 }
コード例 #8
0
ファイル: replaceall.php プロジェクト: Webictbyleo/JqueryPhp
 public function run($query)
 {
     if (is_scalar($query)) {
         $query = str_replace(array(':last', ':first'), '', strip_tags($query));
         $query .= ':first';
         $document = jqm_use($this->node->_parentElement);
         $str = $this->node->dom()->get()->lastdom;
         $ele = $document->find($query)->current();
         if (is_a($ele, jqmel)) {
             $ele->replaceWith($str);
         }
     }
 }
コード例 #9
0
ファイル: has.php プロジェクト: Webictbyleo/JqueryPhp
 public function run($ele)
 {
     $document = jqm_use($this->node->_parentElement);
     if (is_scalar($ele) and !is_numeric($ele)) {
         $query = $document->match_selector($ele);
     } elseif (is_a($ele, jqmel)) {
         $ele = $ele->selector->selectors;
         $query = $document->match_selector($ele);
     } else {
         $this->node = new jqueryphp_abstracts_prevObject();
         return;
     }
     if ($query) {
         $this->node = $this->node->find($query['selectors'])->get();
     }
 }
コード例 #10
0
ファイル: children.php プロジェクト: Webictbyleo/JqueryPhp
 public function run($query = '*')
 {
     $dom = $this->node->__toDomElement();
     if ($dom->childNodes->length > 0) {
         if (empty($query)) {
             $query = '*';
         }
         $nodes = array();
         $ns = jqm_use($this->node->_parentElement);
         for ($i = 0; $dom->childNodes->length > $i; $i++) {
             $child = $dom->childNodes->item($i);
             if ($child->nodeType !== 1) {
                 continue;
             }
             $el = $this->createFragment($child->ownerDocument->savehtml($child), false);
             $el->_path = $child->getNodepath();
             $el->setDomID($this->node->_parentElement . $this->node->_token);
             $el->selector = $ns->match_selector($child->tagName . '[data-dom-id="' . key($el->_domId) . '"]', $el->_path . '::', false);
             $is = $el->is($query);
             if ($is->get() !== true) {
                 continue;
             }
             if ($child->nextSibling) {
                 $el->_next_path = $child->nextSibling->getNodepath();
             } else {
                 $el->_next_path = NULL;
             }
             if ($child->previousSibling) {
                 $el->_prev_path = $child->previousSibling->getNodepath();
             } else {
                 $el->_prev_path = NULL;
             }
             if ($child->parentNode) {
                 $el->_parent_path = $child->parentNode->getNodepath();
             } else {
                 $el->_parent_path = NULL;
             }
             $nodes[] = $el;
             unset($el);
         }
         $this->node = new jqueryphp_abstracts_nodelist($nodes);
         return $this;
     } else {
         $this->node = new jqueryphp_abstracts_prevObject($this->node->_selector . ':children(*)');
         return $this;
     }
 }
コード例 #11
0
ファイル: parent.php プロジェクト: Webictbyleo/JqueryPhp
 public function run()
 {
     $path = $this->node->_path;
     $el = $this->__toDomElement();
     $doc = jqm_use($this->node->_parentElement);
     if ($el->parentNode) {
         $content = $el->ownerDocument->saveHtml($el->parentNode);
         $node = $this->createFragment($content, false);
         if (is_a($node, jqmel)) {
             $node->_path = $el->parentNode->getNodePath();
             $node->setDomID($this->node->_parentElement . $this->node->_token);
             $this->node = $node;
             return $this;
         }
     } else {
         return new jqueryphp_abstracts_prevObject($this->node->_selector . ':parent(*)');
     }
 }
コード例 #12
0
ファイル: next.php プロジェクト: Webictbyleo/JqueryPhp
 public function run()
 {
     $dom = $this->__toDomElement();
     if ($dom->nextSibling) {
         $doc = jqm_use($this->node->_parentElement);
         $dom = $dom->nextSibling;
         if ($dom->nodeType !== 1) {
             $dom = $dom->nextSibling;
         }
         if (!$dom) {
             return $this->node = new jqueryphp_abstracts_prevObject($selector['selectors']);
         }
         //Get the search param
         $selector = $doc->match_selector($dom->tagName);
         $path = $dom->getNodePath();
         //Find this ele in the Dom Node
         $node = $this->findRelatedDom(array('_path' => $path));
         $str = $dom->ownerDocument->savehtml($dom);
         if (is_a($node, jqmel)) {
             $n = $node->__toDomElement();
             $this->node = $node;
             unset($node);
             return;
         }
         $dom = $this->createFragment($str, false);
         if (is_a($dom, jqmel)) {
             $dom->_path = $path;
             $dom->selector = new jqueryphp_abstracts_selector($selector);
             $dom->setDomID($dom->_parentElement . $dom->_token);
             return $this->node = $dom;
         } else {
             //notfound
             return $this->node = new jqueryphp_abstracts_prevObject($selector['selectors']);
         }
     } else {
         //notfound
         return $this->node = new jqueryphp_abstracts_prevObject($this->node->_selector . ':next');
     }
 }
コード例 #13
0
ファイル: unwrap.php プロジェクト: Webictbyleo/JqueryPhp
 public function run()
 {
     if (empty($this->node->_localName)) {
         return $this;
     }
     $parent = $this->node->parent()->get();
     if (is_a($parent, jqmel)) {
         $path = $parent->_path;
         $str = $parent->_innerHtml;
         $document = jqm_use($this->node->_parentElement);
         $dom = $document->_DOM;
         if ($dom->doctype) {
             $dom->removeChild($dom->doctype);
         }
         $xpath = new DomXpath($dom);
         $find = $xpath->query($path);
         if ($find->length > 0) {
             $tp = new domdocument();
             $tp->loadHtml($str);
             if ($tp->doctype) {
                 $tp->removeChild($tp->doctype);
             }
             $frag = $dom->importNode($tp->firstChild->firstChild, true);
             $find->item(0)->parentNode->replaceChild($frag, $find->item(0));
             $find = $this->node->getPathByID();
             if ($find) {
                 $this->node->_path = $find;
             } else {
                 $pts = explode('/', $this->node->_path);
                 $ep = array_pop($pts);
                 $pts = explode('/', $frag->getNodepath());
                 array_pop($pts);
                 $pts[] = $ep;
                 $this->node->_path = implode('/', $pts);
             }
         }
     }
 }
コード例 #14
0
ファイル: off.php プロジェクト: Webictbyleo/JqueryPhp
 public function run($event, $selector = NULL)
 {
     if ($event == NULL) {
         return $this;
     }
     if (!is_a($this->node, jqmel)) {
         return $this;
     }
     $ns = $this->node->data('_parentElement')->get();
     if (empty($ns)) {
         return $this;
     }
     $document = jqm_use($ns);
     if (!isset($document->Window) and !is_a($document->Window, jqmwin)) {
         return false;
     }
     if (!array_key_exists($event, $this->node->events)) {
         return false;
     }
     if (empty($selector)) {
         $this->node->events->{$event} = array();
     } else {
         $evs = $this->node->events->{$event};
         $c = count($evs);
         for ($i = 0; $c > $i; $i++) {
             if (!empty($evs[$i][2]) and is_a($this->node, jqmel)) {
                 $is = $this->node->is($selector)->get();
                 if ($is !== true) {
                     continue;
                 }
                 unset($this->node->events->{$event}[$i]);
             }
         }
     }
     return $this;
 }
コード例 #15
0
ファイル: wrap.php プロジェクト: Webictbyleo/JqueryPhp
 public function run($str = nULL)
 {
     if (!is_null($str)) {
         $regex = '/<([a-z0-9\\-]+)(.*?)>(?:(.*?)(<\\/\\1>))?/ix';
         if (is_a($str, jqmel)) {
             $str = $str->dom()->get()->lastdom;
         } elseif (is_callable($str)) {
             $str = call_user_func($str, array());
         }
         $str = preg_replace('/\\s+/', ' ', $str);
         if (preg_match($regex, $str, $match)) {
             $match[2] = rtrim($match[2], '/');
         }
         $document = jqm_use($this->node->_parentElement);
         $np = $this->node->next()->get();
         $npp = $this->node->prev()->get();
         $par = $this->node->parent();
         $wrap = $str;
         if (!is_a($par->get(), jqmel)) {
             return;
         }
         $rec = $document->_DOM;
         if ($rec->doctype) {
             $rec->removeChild($rec->doctype);
         }
         $xpath = new domxpath($rec);
         $find = $xpath->query($this->node->_path);
         if ($find->length > 0) {
             $child = new domDocument();
             $child->loadHtml($wrap);
             if ($child->doctype) {
                 $child->removeChild($child->doctype);
             }
             $chf = $child->getElementsByTagName($match[1]);
             $node = $this->node->__toDomElement();
             $frag = $child->importNode($node, true);
             $depth = $this->getDeepest($chf->item(0));
             $save = $depth->appendChild($frag);
             //Import to document
             $frag = $rec->importNode($chf->item(0), true);
             $newsave = $find->item(0)->parentNode->replaceChild($frag, $find->item(0));
             $new_path = explode('/', $frag->getNodePath());
             $p_path = array_filter(explode('/', $save->getNodePath()));
             //$p_path = array_pop($p_path);
             $htm = array_search('html', $p_path);
             if ($htm) {
                 unset($p_path[$htm]);
                 unset($p_path[$htm + 1]);
             }
             $new_path = array_merge($new_path, $p_path);
             $sh = array_pop($new_path);
             array_pop($new_path);
             $ele_path = ltrim($newsave->getNodePath(), '/');
             $this->node->_parent_path = implode('/', $new_path);
             $this->node->_path = $this->node->_parent_path . '/' . $sh;
             $wrap = $rec->saveHtml($frag->parentNode);
             $wrap = substr($wrap, strpos($wrap, '>') + 1);
             if (!empty($par->get()->_localName)) {
                 $wrap = substr($wrap, 0, strripos($wrap, $par->get()->_localName));
                 $par->get()->html($wrap);
             }
             $find = $this->node->getPathById();
             if ($find) {
                 $this->node->_path = $find;
             }
             if ($this->node->trace) {
                 $key = $this->node->trace->key();
                 $this->node->trace->next();
                 $n = $this->node->trace->current();
                 if ($key > 0) {
                     $this->node->trace->seek($key - 1);
                     $p = $this->node->trace->current();
                 }
                 if ($p and is_a($p, jqmel)) {
                     $find = $p->getPathById();
                     if ($find) {
                         $p->_path = $find;
                         //var_dump($key,$p);
                     }
                 }
                 if ($n and is_a($n, jqmel)) {
                     $find = $n->getPathById();
                     if ($find) {
                         $n->_path = $find;
                     }
                 }
                 unset($p);
                 unset($n);
             }
         }
     }
 }
コード例 #16
0
ファイル: siblings.php プロジェクト: Webictbyleo/JqueryPhp
 public function run($selector = NULL)
 {
     $dom = $this->node->__toDomElement();
     $ns = jqm_use($this->node->_parentElement);
     $done = true;
     $node = $dom;
     $prev = $next = $node;
     while ($done != false) {
         if ($prev->previousSibling) {
             $prev = $prev->previousSibling;
             if ($prev->nodeType == 1) {
                 $el = $this->createFragment($dom->ownerDocument->saveHtml($prev), false);
                 $el->_path = $prev->getNodepath();
                 if (is_a($el, jqmel)) {
                     $el->_parentElement = $this->node->_parentElement;
                     $el->_parent_path = $this->node->_parent_path;
                     $el->_prev_path = $this->node->_prev_path;
                     $el->_next_path = $this->node->_next_path;
                     $el->setDomID($this->node->_parentElement . $this->node->_token);
                     $el->selector = $ns->match_selector($prev->tagName . '[data-dom-id="' . key($el->_domId) . '"]', $el->_path . '::', false);
                     if (!empty($selector)) {
                         $is = $el->is($selector)->get();
                         if ($is === true) {
                             $nodes[] = $el;
                         }
                     } else {
                         $nodes[] = $el;
                     }
                 }
             }
         }
         if ($next->nextSibling) {
             $next = $next->nextSibling;
             if ($next->nodeType == 1) {
                 $el = $this->createFragment($dom->ownerDocument->saveHtml($next), false);
                 $el->_path = $next->getNodepath();
                 if (is_a($el, jqmel)) {
                     $el->_parentElement = $this->node->_parentElement;
                     $el->_parent_path = $this->node->_parent_path;
                     $el->_prev_path = $this->node->_prev_path;
                     $el->_next_path = $this->node->_next_path;
                     $el->setDomID($this->node->_parentElement . $this->node->_token);
                     $el->selector = $ns->match_selector($next->tagName . '[data-dom-id="' . key($el->_domId) . '"]', $el->_path . '::', false);
                     if (!empty($selector)) {
                         $is = $el->is($selector)->get();
                         if ($is === true) {
                             $nodes[] = $el;
                         }
                     } else {
                         $nodes[] = $el;
                     }
                 }
             }
         }
         if (!$prev->previousSibling and !$next->nextSibling) {
             $done = false;
             break;
         }
     }
     unset($next);
     unset($prev);
     if (!isset($nodes) || empty($nodes)) {
         return $this->node = new jqueryphp_abstracts_prevObject();
     }
     $this->node = new jqueryphp_abstracts_nodelist($nodes);
     return $this;
 }
コード例 #17
0
ファイル: element.php プロジェクト: Webictbyleo/JqueryPhp
 public function refreshDom()
 {
     if (get_class() !== __CLASS__) {
         return false;
     }
     $document = jqm_use($this->_parentElement);
     $doc = $document->_DOM;
     $x = new DomXpath($doc);
     $qs = $this->_name . '[@data-dom-id = "' . key($this->_domId) . '"]';
     $find = $x->query('descendant-or-self::' . $qs);
     if ($find->length > 0) {
         $find = $find->item(0);
     }
     if ($find and is_a($find, 'DomElement')) {
         $this->replaceWith($doc->saveHTML($find));
         $this->get_selector();
         return true;
     } else {
         $dom = $this->__toDomElement();
         if (is_a($dom, 'DomElement')) {
             $this->replaceWith($dom->ownerDocument->saveHTML($dom));
             $this->get_selector();
             return true;
         }
         return false;
     }
     return false;
 }
コード例 #18
0
ファイル: trigger.php プロジェクト: Webictbyleo/JqueryPhp
 public function run($eventname)
 {
     if ($eventname == NULL) {
         return $this;
     }
     if (!is_a($this->node->Window, jqmwin)) {
         $ns = $this->node->data('_parentElement')->get();
         if (empty($ns)) {
             return $this;
         }
         $document = jqm_use($ns);
         if (is_a($document->Window, jqmwin)) {
             $this->node->data('Window', $document->Window);
         } else {
             return $this;
         }
     }
     if (!is_a($this->node->Window, jqmwin)) {
         return $this;
     }
     if ($this->node instanceof jqueryphp_abstracts_document) {
         $target = ':root';
     } elseif (is_a($this->node, jqmel)) {
         $domid = key($this->node->data('_domId')->get());
         $target = '[data-dom-id="' . $domid . '"]';
         $tag = $this->node->data('_name')->get();
         if (!empty($tag)) {
             $target = $tag . $target;
         }
     }
     //Preload the default events if loaded
     if (isset($this->node->Window->Event->{$eventname})) {
         if (!isset($this->node->events->{$eventname})) {
             $this->node->events->{$eventname} = $this->node->Window->Event->{$eventname};
         } else {
             $this->node->events->{$eventname} = array_merge($this->node->events->{$eventname}, $this->node->Window->Event->{$eventname});
         }
     }
     if (!array_key_exists($eventname, $this->node->events)) {
         return false;
     }
     $evs = $this->node->events->{$eventname};
     $c = count($evs);
     $keynames = array_keys($evs);
     for ($i = 0; $c > $i; $i++) {
         if (!empty($evs[$keynames[$i]][2]) and is_a($this->node, jqmel)) {
             $selector = $evs[$keynames[$i]][2];
             $is = $this->node->is($selector)->get();
             if ($is == false) {
                 continue;
             }
         }
         $e = new jqueryphp_abstracts_event($eventname, $target, $evs[$keynames[$i]][1]);
         if (self::$isDefaultPrevented[$eventname] === true) {
             $e->preventDefault = true;
         }
         $callback = $evs[$keynames[$i]][0];
         if (is_a($callback, 'Closure')) {
             $callback = Closure::bind($callback, $this->node);
         }
         $result = call_user_func($callback, $e);
         $e->result = $result;
         jqueryphp_methods_trigger::$resultSet[$eventname] = $result;
         $this->node->event = $e;
         self::$isDefaultPrevented[$eventname] = $e->preventDefault;
         if ($evs[$keynames[$i]][3] === true) {
             unset($evs[$keynames[$i]]);
             unset($this->node->events->{$eventname}[$keynames[$i]]);
         }
     }
     return $this;
 }
コード例 #19
0
ファイル: replacewith.php プロジェクト: Webictbyleo/JqueryPhp
 public function run($html = NULL)
 {
     if (!is_null($html)) {
         $new = $this->createFragment($html);
         if (is_a($new, jqmel)) {
             $this->oldnode = clone $this->node;
             $document = jqm_use($this->node->_parentElement);
             $np = $this->node->next()->get();
             $npp = $this->node->prev()->get();
             $this->node->_selector = $new->_selector;
             $this->node->_token = $new->_token;
             $this->node->_nodeLevel = $new->_nodeLevel;
             $this->node->selector = $new->selector;
             $this->node->_name = $new->_name;
             $this->node->_content = $new->_content;
             $this->node->_attrMap = $new->_attrMap;
             $this->node->_innerHtml = $new->_innerHtml;
             $this->node->_innerText = $new->_innerText;
             $this->node->_localName = $new->_localName;
             $this->node->_attributes = $new->_attributes;
             $save = $this->node->saveHtml();
             $k = key($this->node->_domId);
             $this->node->_domId[$k] = end($new->_domId);
             $paths = explode('/', $this->node->_path);
             $sh = array_pop($paths);
             $paths[] = $new->_name;
             $this->node->_path = $save;
             //$save = $this->node->saveHtml();
             $par = $this->node->parent();
             if (is_a($par, jqmel)) {
                 $this->node->_parent_path = $par->get()->_path;
                 if (is_a($npar, jqmel)) {
                     $npar->node = $par->get();
                 }
             }
             //Reconcle paths
             $rec = $document->_DOM;
             if ($rec->doctype) {
                 $rec->removeChild($rec->doctype);
             }
             $xpath = new DomXpath($rec);
             $find = $xpath->query($save);
             if ($find->length > 0) {
                 $wrap = $rec->saveHtml($find->item(0)->parentNode);
                 $wrap = substr($wrap, strpos($wrap, '>') + 1);
                 if (!empty($par->get()->_localName)) {
                     $wrap = substr($wrap, 0, strripos($wrap, $par->get()->_localName));
                     $par->get()->html($wrap);
                     $par->get()->saveHtml();
                 }
                 $this->node->_path = $find->item(0)->getNodePath();
                 if (is_a($np, jqmel)) {
                     if ($find->item(0)->nextSibling) {
                         $this->node->_next_path = $find->item(0)->nextSibling->getNodePath();
                     } else {
                         $this->node->_next_path = NULL;
                     }
                     $np->_path = $this->node->_next_path;
                     $np->_prev_path = $this->node->_path;
                     $npd = $np->__toDomElement();
                     if ($npd->nextSibling) {
                         $np->_next_path = $npd->nextSibling->getNodePath();
                     } else {
                         $np->_next_path = NULL;
                     }
                     unset($npd);
                 }
                 if ($find->item(0)->previousSibling and is_a($npp, jqmel)) {
                     $this->node->_prev_path = $find->item(0)->previousSibling->getNodePath();
                 } else {
                     $this->node->_prev_path = NULL;
                 }
                 $npp->_path = $this->node->_prev_path;
                 $npp->_next_path = $this->node->_path;
                 $npd = $npp->__toDomElement();
                 if ($npd->previousSibling) {
                     $npp->_prev_path = $npd->previousSibling->getNodePath();
                 } else {
                     $npp->_prev_path = NULL;
                 }
                 unset($npd);
             }
             unset($new);
         }
     }
 }
コード例 #20
0
ファイル: is.php プロジェクト: Webictbyleo/JqueryPhp
 public function run($new = Null)
 {
     if (is_a($new, jqmel)) {
         return $this->done = $new === $this->node;
     } elseif (is_callable($new)) {
         return $this->done = call_user_func($new, $this->node) == true;
     } else {
         $query = $this->match_selector($new, 'self::', false);
     }
     $attr = $this->node->data('_attributes')->get();
     $path = $this->node->data('_path')->get();
     $ns = $this->node->data('_parentElement')->get();
     $tag = $this->node->data('_name')->get();
     $done = false;
     $d = jqm_use($ns);
     $this->query_arg = $query;
     if (array_key_exists('button', $query['filters'])) {
         if (!in_array($tag, array('input', 'button'))) {
             return $this->done = false;
         }
         if ($tag == 'input' and !array_key_exists('type', $attr)) {
             return $this->done = false;
         }
         if ($tag == 'input' and $attr['type'] !== 'button') {
             return $this->done = false;
         }
     }
     if (array_key_exists('header', $query['filters'])) {
         $regex = '/h1|h2|h3|h4|h5|h6|h[1-9]/ix';
         if (preg_match($regex, $tag) == false) {
             return $this->done = false;
         }
     }
     if (array_key_exists('first', $query['filters'])) {
         if (!isset($this->node->trace)) {
             $this->done = true;
         } else {
             $i = key($this->node->trace);
             $first = $this->node->trace[$i];
             if ($first !== $this->node) {
                 return $this->done = false;
             }
         }
     }
     if (array_key_exists('last', $query['filters'])) {
         if (!isset($this->node->trace)) {
             $this->done = true;
         } else {
             $last = end($this->node->trace);
             if ($last !== $this->node) {
                 return $this->done = false;
             }
         }
     }
     if (array_key_exists('checked', $query['filters'])) {
         if ($tag !== 'input') {
             return $this->done = false;
         }
         if (!in_array($attr['type'], array('radio', 'checkbox'))) {
             return $this->done = false;
         }
     }
     if (array_key_exists('file', $query['filters'])) {
         if ($tag !== 'input') {
             return $this->done = false;
         }
         if ($attr['type'] !== 'file') {
             return $this->done = false;
         }
     }
     if (array_key_exists('text', $query['filters'])) {
         if ($tag !== 'input') {
             return $this->done = false;
         }
         if ($attr['type'] !== 'text') {
             return $this->done = false;
         }
     }
     if (array_key_exists('submit', $query['filters'])) {
         if (!in_array($tag, array('input', 'button'))) {
             return $this->done = false;
         }
         if ($attr['type'] !== 'submit') {
             return $this->done = false;
         }
     }
     if (array_key_exists('checkbox', $query['filters'])) {
         if ($tag !== 'input') {
             return $this->done = false;
         }
         if ($attr['type'] !== 'checkbox') {
             return $this->done = false;
         }
     }
     if (array_key_exists('radio', $query['filters'])) {
         if ($tag !== 'input') {
             return $this->done = false;
         }
         if ($attr['type'] !== 'radio') {
             return $this->done = false;
         }
     }
     if (array_key_exists('selected', $query['filters'])) {
         if ($tag !== 'option') {
             return $this->done = false;
         }
         if (!array_key_exists('selected', $attr)) {
             return $this->done = false;
         }
         $query['filters']['parent'] = 'select';
     }
     if (array_key_exists('has', $query['filters'])) {
         $html = $this->node->html()->get();
         if (empty($html) || strip_tags($html) == $html) {
             return $this->done = false;
         }
         if (!empty($query['filters']['has'])) {
             if (preg_match('/<(' . $query['filters']['has'] . ')\\b(.*?)>(?:(.*?)(<\\/\\1>))?/ix', $html) == false) {
                 return $this->done = false;
             }
         }
     }
     if (array_key_exists('disabled', $query['filters']) and !array_key_exists('disabled', $attr)) {
         return $this->done = false;
     }
     if (array_key_exists('contains', $query['filters'])) {
         $html = $this->node->html()->get();
         $html = strip_tags($html);
         if (empty($html)) {
             return $this->done = false;
         }
         if (!empty($query['filters']['contains'])) {
             if (strpos($html, jqueryphp_abstracts_element::escape($query['filters']['contains'])) === false) {
                 return $this->done = false;
             }
         }
     }
     if (array_key_exists('visible', $query['filters'])) {
         if ($this->isHidden() === true) {
             return $this->done = false;
         }
     }
     if (array_key_exists('hidden', $query['filters'])) {
         if ($this->isHidden() === false) {
             return $this->done = false;
         }
     }
     if (array_key_exists('only-child', $query['filters'])) {
         $doc = $d->_DOM;
         $xpath = new domXpath($doc);
         $node = $xpath->query($path);
         if ($node->length < 1) {
             return $this->done = false;
         }
         if (!$node->item(0)->parentNode) {
             return $this->done = false;
         }
         if (!$node->item(0)->parentNode->childNodes) {
             return $this->done = false;
         }
         if ($node->item(0)->parentNode->childNodes->length > 1) {
             return $this->done = false;
         }
     }
     if (array_key_exists('nth-child', $query['filters'])) {
         if ($query['filters']['nth-child'] == NULL || strlen($query['filters']['nth-child']) === 0) {
             return $this->done = false;
         }
         $pos = strrpos($path, '[');
         if ($pos === false) {
             return $this->done = false;
         }
         if ($pos == strlen($path) - 1) {
             return $this->done = false;
         }
         $pos = trim(substr($path, $pos), '[]');
         if (!is_numeric($pos)) {
             return $this->done = false;
         }
         $pos = (int) $pos;
         if (is_numeric($query['filters']['nth-child'])) {
             if ((int) $query['filters']['nth-child'] < 1) {
                 return $this->done = false;
             }
             if ($pos !== (int) $query['filters']['nth-child']) {
                 return $this->done = false;
             }
         } elseif ($query['filters']['nth-child'] === 'even') {
             if (($pos % 2 == 0) == false) {
                 return $this->done = false;
             }
         } elseif ($query['filters']['nth-child'] === 'odd') {
             if (($pos % 2 == 0) == true) {
                 return $this->done = false;
             }
         } else {
             return $this->done = false;
         }
     }
     if (array_key_exists('nth-last-child', $query['filters'])) {
         $doc = $d->_DOM;
         $xpath = new domXpath($doc);
         $node = $xpath->query($path);
         if ($node->length < 1) {
             return $this->done = false;
         }
         if (!$node->item(0)->parentNode) {
             return $this->done = false;
         }
         $cht = $node->item(0)->parentNode->childNodes->length;
         if (is_numeric($query['filters']['nth-last-child'])) {
             $pos = (int) $query['filters']['nth-last-child'];
             if ($pos < 1) {
                 return $this->done = false;
             }
             $pos = $cht - $pos;
         } elseif (in_array($query['filters']['nth-last-child'], array('even', 'odd'))) {
             $pos = strrpos($path, '[');
             if ($pos === false) {
                 return $this->done = false;
             }
             if ($pos == strlen($path) - 1) {
                 return $this->done = false;
             }
             $pos = trim(substr($path, $pos), '[]');
             if (!is_numeric($pos)) {
                 return $this->done = false;
             }
             $pos = (int) $pos;
             if ($query['filters']['nth-last-child'] === 'even') {
                 if ((($cht - $pos) % 2 == 0) === true) {
                     return $this->done = false;
                 }
             }
             if ($query['filters']['nth-last-child'] === 'odd') {
                 if ((($cht - $pos) % 2 == 0) === false) {
                     return $this->done = false;
                 }
             }
         } else {
             return $this->done = false;
         }
         if ($pos > $cht) {
             return $this->done = false;
         }
         if ($pos < 0) {
             return $this->done = false;
         }
         $chd = $node->item(0)->parentNode->childNodes->item($pos - 1);
         if (!$chd) {
             return $this->done = false;
         }
         if ($node->item(0)->isSameNode($chd) === false) {
             return $this->done = false;
         }
         unset($chd);
     }
     if (array_key_exists('only-of-type', $query['filters'])) {
         $doc = $d->_DOM;
         $xpath = new domXpath($doc);
         $node = $xpath->query($path);
         if ($node->length < 1) {
             return $this->done = false;
         }
         if ($node->item(0)->childNodes) {
             if ($node->item(0)->childNodes->length > 0 and $node->item(0)->childNodes->item(0)->nodeType !== 3) {
                 return $this->done = false;
             }
         }
     }
     if (array_key_exists('first-child', $query['filters'])) {
         $doc = $d->_DOM;
         $xpath = new domXpath($doc);
         $node = $xpath->query($path);
         if ($node->length < 1) {
             return $this->done = false;
         }
         if (!$node->item(0)->parentNode) {
             return $this->done = false;
         }
         if ($node->item(0)->parentNode->firstChild->isSameNode($node->item(0)) === false) {
             return $this->done = false;
         }
     }
     if (array_key_exists('last-child', $query['filters'])) {
         $doc = $d->_DOM;
         $xpath = new domXpath($doc);
         $node = $xpath->query($path);
         if ($node->length < 1) {
             return $this->done = false;
         }
         if (!$node->item(0)->parentNode) {
             return $this->done = false;
         }
         if ($node->item(0)->parentNode->lastChild->isSameNode($node->item(0)) === false) {
             return $this->done = false;
         }
     }
     if (isset($query['specifier'])) {
         $v = array_intersect_key($query['specifier'], $attr);
         if (isset($query['tag'])) {
             $ipt = explode('|', $query['tag']);
             if (!in_array($this->node->data('_name')->get(), $ipt)) {
                 return $this->done = false;
             }
         }
         if (count($query['specifier']) > 0 and empty($v)) {
             return $this->done = false;
         }
     }
     //Find Has attr
     if (array_key_exists('id', $query['specifier'])) {
         if ($query['specifier']['id'] !== $v['id']) {
             return $this->done = false;
         }
     }
     if (array_key_exists('class', $query['specifier'])) {
         $classes = $v['class'];
         $hasclass = $this->node->hasClass($classes)->get();
         if ($hasclass) {
             $v['class'] = $attr['class'];
         }
     }
     $this->matched = $v;
     $v = count(array_intersect($v, $attr)) >= count($query['specifier']);
     if ($v === false) {
         return $this->false = true;
     }
     if (!empty($query['attributes'])) {
         $found = false;
         $attrkeys = array_keys($attr);
         if (isset($query['attributes']['colExists'])) {
             $validAttr = array_intersect($query['attributes']['colExists'], $attrkeys);
             $found = $validAttr;
             $found = (count($validAttr) > 0 and count($validAttr) === count($query['attributes']['colExists']));
         }
         if (isset($query['attributes']['colNotExists'])) {
             $validAttr = array_diff($query['attributes']['colNotExists'], $attrkeys);
             $found = (!empty($found) and $validAttr == $query['attributes']['colNotExists']);
         }
         $check = $query['attributes'];
         unset($check['colNotExists']);
         unset($check['colExists']);
         if (isset($check) and is_array($check) and !empty($check)) {
             $found = $this->matchAttributeSelectors($check, $attr);
         }
         if (!$found) {
             $this->done = false;
             return;
         }
     }
     if (!empty($query['filters'])) {
         $path = $this->node->data('_path')->get();
         if (array_key_exists('empty', $query['filters'])) {
             $inner = $this->node->data('_innerHtml')->get();
             if (!empty($inner)) {
                 return $this->done = false;
             }
         }
         if (array_key_exists('parent', $query['filters'])) {
             if (isset($query['filters']['parent']) and !empty($query['filters']['parent'])) {
                 $parents = explode('/', $path);
                 array_pop($parents);
                 $ps = strpos(end($parents), $query['filters']['parent']);
                 if ($ps === false) {
                     $this->done = false;
                 }
                 return;
                 if ($ps !== 0) {
                     $this->done = false;
                     return;
                 }
             }
             $inner = $this->node->data('_innerHtml')->get();
             if (empty($inner)) {
                 return $this->done = false;
             }
             if (strlen($inner) < 1) {
                 $this->done = false;
                 return;
             }
             $this->done = true;
         }
         if (strripos($path, ']') == strlen($path) - 1) {
             $path = substr($path, strripos($path, '['));
             if (preg_match('/\\[(\\d)\\]/', $path, $match)) {
                 $path = $match[1];
             } else {
                 $path = 1;
             }
         } else {
             $path = 1;
         }
         if (is_numeric($path)) {
             $i = (int) $path - 1;
             unset($path);
             if ($i < 0) {
                 $this->done = false;
                 return;
             }
             if (array_key_exists('eq', $query['filters']) and is_numeric($query['filters']['eq'])) {
                 if ($query['filters']['eq'] != $i) {
                     $this->done = false;
                     return;
                 }
             }
             if (array_key_exists('gt', $query['filters']) and is_numeric($query['filters']['gt'])) {
                 if ($i > (int) $query['filters']['gt'] == false) {
                     $this->done = false;
                     return;
                 }
             }
             if (array_key_exists('lt', $query['filters']) and is_numeric($query['filters']['lt'])) {
                 if ($i < (int) $query['filters']['lt'] == false) {
                     $this->done = false;
                     return;
                 }
             }
             if (array_key_exists('odd', $query['filters'])) {
                 if (($i % 2 == 0) == true) {
                     $this->done = false;
                     return;
                 }
             }
             if (array_key_exists('even', $query['filters'])) {
                 if (($i % 2 == 0) == false) {
                     $this->done = false;
                     return;
                 }
             }
         }
     }
     return $this->done = true;
 }