"new Tip('%s',%s);", 'fancy'=>"new Tip('%s',%s,%s);"); /** * @var Array cakephp helpers used by this helper */ var $helpers = array('Html', 'Javascript'); /** * @var Array holds tooltips to be rendered in a block */ var $tips = array(); /** * @public * * @param String $el the id of the element * @param String $content html to show in the tip * @param Array $options the tooltip options * * @return String a formatted tooltip instantiation */ function tooltip($el,$content,$options=array()) { if ( substr($content,0,1)!='$') $content = "'$content'"; if($options) { return $this->Javascript->codeBlock($this->output(sprintf($this->tooltip['fancy'],$el,$content,$this->_parseOptions($options)))); } else { return $this->Javascript->codeBlock($this->output(sprintf($this->tooltip['base'],$el,$content))); } } /** * @public * * @param String $el the id of the element * @param String $content html to show in the tip * @param Array $options the tooltip options * * Adds a formatted tooltip to the $tips array */ function addTooltip($el, $content, $options=array()) { if ( substr($content,0,1)!='$') $content = "'$content'"; if($options) { $this->tips[] = sprintf($this->tooltip['fancy'],$el,$content,$this->_parseOptions($options)); } else { $this->tips[] = sprintf($this->tooltip['base'],$el,$content); } } /** * @public * * Renders the array of tooltips in $tips as a Javascript code block */ function renderTooltips() { $tips_string = "'; return $this->output($tips_string); } /** * @private * * @param Array $options an array of the options available to prototip * * @return String a formatted string of options i.e. {'opt':'value'...} */ function _parseOptions($options=array()) { $opts = "{"; $arr_opts = array(); foreach($options as $key => $value) { if(in_array($key,$this->allowed_options)) { if(in_array($key, $this->sc_options)) { //special case for formatting options if(strpos($value, '{') !== false) { // the option has a tuple...e.g. 'hook:{target:'topLeft',tip:'rightMiddle'} $sc = explode(',' ,$value); $str_sc_opts = "'$key':"; $sc_arr_opts = array(); foreach($sc as $opt => $val) { $sc_arr_opts[] = "$val"; } $arr_opts[] = $str_sc_opts . join(",", $sc_arr_opts); } } else { $arr_opts[] = "'$key':'$value'"; } } } $opts .= join(",", $arr_opts); $opts .="}"; return $opts; } } ?>