Exemple #1
0
 /**
  * Redirect client to the specified url
  * @param string $url page url
  * @param boolean $useJavaScript Optional. Enable page redirection using client-side JavaScript
  */
 public static function redirectTo($url, $useJavaScript = false)
 {
     if (!$useJavaScript) {
         header('Location: ' . $url);
     } else {
         $redirect = 'window.location = "' . self::escapeText($url) . '"';
         RaxanWebPage::$actions = array($redirect);
         RaxanWebPage::controller()->endResponse()->reply();
     }
     exit;
 }
 /**
  * Writes the value of a server-side variable or object to the client-side console
  * @param mixed $var Variable to be displayed inside console
  * @param boolean $halt Halt servide operations
  * @return RaxanClientExtension
  */
 public function console($var, $halt = false)
 {
     $var = $var === null ? 'null' : print_r($var, true);
     $this->chain = ($this->chain == '$()' ? '' : $this->chain . ';') . 'Raxan.log("' . $this->escapeString($var) . '")';
     if (!$halt) {
         return $this;
     } else {
         RaxanWebPage::controller()->endResponse()->reply();
         exit;
     }
 }
Exemple #3
0
 /**
  * RaxanElement(css,context)
  * RaxanElement(html,context)
  * @param mixed $css CSS selector string, array of DOMElements, DOMNode, DOMNodeList or RaxanElement
  * @param DOMNode $context
  * @return RaxanElement
  */
 function __construct($css, $context = null)
 {
     parent::__construct();
     $this->_length = 0;
     // set length to 0
     $this->elms = array();
     // setup elements array
     $c = $context;
     $reservedMethods = array('empty', 'clone');
     // get document
     if ($c == null) {
         $this->doc = null;
     } else {
         if ($c instanceof RaxanDOMDocument) {
             $this->doc = $c;
             $c = null;
             // context is document so set it null
         } else {
             if ($c instanceof DOMNode && $c->ownerDocument instanceof RaxanDOMDocument) {
                 $this->doc = $c->ownerDocument;
             } else {
                 $c = $this->doc = null;
             }
         }
     }
     $this->doc = $this->doc ? $this->doc : RaxanWebPage::controller()->document();
     $this->_rootElm = $this->doc->documentElement;
     $css = $css ? $css : $this->_rootElm;
     $this->_context = $c ? $c : $this->_rootElm;
     // assign context element
     if (is_string($css)) {
         $this->_selector = $css;
         if (!$this->isHTML($css)) {
             $dl = $this->doc->cssQuery($css, $this->_context);
         } else {
             // handle html
             $this->_modifiedStack = true;
             if (!$this->doc->isInit()) {
                 $this->doc->initDOMDocument();
             }
             $n = $this->doc->getElementsByTagName('body');
             if ($n->length) {
                 $n = $n->item(0);
                 $f = $this->page->createFragment('<div>' . $css . '</div>');
                 if ($f) {
                     $f = $n->appendChild($f);
                     // append html to body tag
                     $dl = array();
                     foreach ($f->childNodes as $n1) {
                         if ($n1->nodeType == 1) {
                             $dl[] = $n1->cloneNode(true);
                         }
                     }
                     $n->removeChild($f);
                     // remove element
                 }
             }
         }
     } else {
         if ($css instanceof DOMNode) {
             $this->elms[] = $css;
             $this->_length = 1;
         } else {
             if ($css instanceof DOMNodeList) {
                 $dl = $css;
             } else {
                 if ($css instanceof RaxanElement) {
                     $dl = $css->get();
                 } else {
                     if (is_array($css)) {
                         $dl = $css;
                     }
                 }
             }
         }
     }
     if (isset($dl) && $dl) {
         $lastNode = null;
         foreach ($dl as $n) {
             if ($n->nodeType == 1) {
                 if ($lastNode !== $n) {
                     // use $lastNode to help prevent duplicate nodes
                     $this->elms[] = $n;
                     // from being added to matched elements as reported by Damir - On rare occations duplicated elements where returned when using XPath with PHP 5.2.9
                     $this->_length++;
                 }
                 $lastNode = $n;
             }
         }
     }
     return $this;
 }
Exemple #4
0
 public function __construct($id, $properties = null)
 {
     // configure ui
     $this->_config();
     $autoid = $idIsString = $isArray = false;
     // setup properties
     if ($properties instanceof RaxanDOMDocument) {
         $doc = $properties;
     } else {
         if ($properties instanceof RaxanWebPage) {
             $doc = $properties->document();
         } else {
             $doc = RaxanWebPage::controller()->document();
             $isArray = is_array($properties);
         }
     }
     if ($id instanceof DOMElement) {
         $elm = $id;
         $autoid = true;
     } else {
         if (is_string($id)) {
             $elm = $doc->page->getElementById($id);
             $idIsString = true;
         }
     }
     if (!$elm) {
         $elm = $this->elmMarkup;
         $autoid = true;
     }
     // create instance
     parent::__construct($elm, $doc);
     if ($autoid) {
         // auto id
         if ($idIsString) {
             $this->attr('id', $id);
         } else {
             $this->autoId();
         }
     }
     $this->element = $this->elms[0];
     $this->elmId = $this->element->getAttribute('id');
     // import properties from element attributes
     $xtAttrs = array();
     $propkeys = null;
     foreach ($this->element->attributes as $attr) {
         if (substr($attr->name, 0, 6) == 'xt-ui-') {
             if ($propkeys == null) {
                 // // make properrty names case-insensitive for xt-ui attributes
                 $propkeys = array_keys($this->properties);
                 $propkeys = array_combine($propkeys, $propkeys);
                 $propkeys = array_change_key_case($propkeys);
             }
             $xtKey = substr($attr->name, 6);
             if (isset($propkeys[$xtKey])) {
                 $this->properties[$propkeys[$xtKey]] = $attr->value;
             }
             $xtAttrs[] = $attr->name;
         }
     }
     // remove xt-ui attribs
     foreach ($xtAttrs as $attr) {
         $this->element->removeAttribute($attr);
     }
     // merge properties
     if ($isArray) {
         $this->properties = array_merge($this->properties, $properties);
     }
     $this->_init();
     // init
     $page = $this->doc->page;
     // setup default ui state
     if ($this->preserveState && $elm) {
         if (!$page->isLoaded && !$elm->hasAttribute('xt-preservestate')) {
             $elm->setAttribute('xt-preservestate', $this->preserveState);
         }
     }
     $page->registerUIWidget($this);
 }
Exemple #5
0
 public function __get($name)
 {
     if ($name == 'page') {
         return RaxanWebPage::controller($this->pageId);
     }
 }