public function script($with_ele=1)
	{
    $this->update();
		$r = '';
		if ( isset($this->attr['id']) ){
      if ( isset($this->cfg['events']) ){
        foreach ( $this->cfg['events'] as $event => $fn ){
          $r .= '.'.$event.'('.
                  ( strpos($fn, 'function') === 0 ? $fn : 'function(e){'.$fn.'}' ).
                  ')';
        }
      }
      if ( isset($this->cfg['widget'], $this->cfg['widget']['name']) ){
        $r .= '.'.$this->cfg['widget']['name'].'(';
        if ( isset($this->cfg['widget']['options']) ){
          $r .= '{';
          foreach ( $this->cfg['widget']['options'] as $n => $o ){
            $r .= '"'.$n.'":';
            if ( \is_string($o) ){
              $o = trim($o);
              if ( (strpos($o, 'function(') === 0) ){
                $r .= $o;
              }
              else{
                $r .= '"'.bbn\str::escape_dquotes($o).'"';
              }
            }
            else if ( \is_bool($o) ){
              $r .= $o ? 'true' : 'false';
            }
            else{
              $r .= json_encode($o);
            }
            $r .= ',';
          }
          $r .= '}';
        }
        $r .= ')';
      }
      if ( !empty($this->help) ){
        // tooltip
      }
      if ( !empty($r) ){
        if ( $with_ele ){
          $r = '$("#'.$this->attr['id'].'")'.$r.';'.PHP_EOL;
        }
        else{
          $r = $r.';'.PHP_EOL;
        }
      }
		}
    if ( !empty($this->script) ){
      $r .= $this->script.PHP_EOL;
    }
    if ( \is_array($this->content) ){
      foreach ( $this->content as $c ){
        if ( \is_array($c) ){
          $c = new bbn\html\element($c);
        }
        if (\is_object($c) && method_exists($c, 'script') ){
          $r .= $c->script();
        }
      }
    }
		return $r;
	}