Exemplo n.º 1
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);
 }