Some thought for ZII dialog widget

I’m excited to see some native support for dialog widget but i find there will be error for “buttons” options as it will quote the function which make it not workable

here is my thought of modifications to the init function which will have it work again.

It might be the same as another JUI in the extensions sections




private function EncodeJavascript($script=array()) {

$returnVal = array();

if(is_array($script)) {

  foreach($script as $key=>$val) {

     $returnVal[] = "'".$key."':".$val;

  }

}

return '{'.implode(',',$returnVal).'}';

}






public function init() {

parent::init();

$button_array = '';

$id=$this->getId();

$this->htmlOptions['id']=$id;

//Added line 1

if(!empty($this->options['buttons'])) {

   $button_array = $this->options['buttons'];

   $this->options['buttons'] = 'NeedSpecialEncodeButtons';

}

$options=empty($this->options) ? '' : CJavaScript::encode($this->options);

//Added line 2

if(!empty($this->options['buttons'])) {

   $options = str_replace("'NeedSpecialEncodeButtons'",$this->EncodeJavascript($button_array),$options);

}

Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').dialog($options);");

echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";

}



Prefix a "js:" in front of the function definition to prevent it from being encoded.

wow never know that… learn a new thing again!