<commit_before><?php

/**
 * HTML class for an autocomplete field
 * 
 * @category    HTML
 * @package     HTML_QuickForm
 * @author      <NAME> <<EMAIL>>
 */
class HTML_QuickForm_autocomplete extends HTML_QuickForm_text {
    private $callback;
    private $args = array();
    private $on_hide_js_code = '';
            
    /**
     * Class constructor
     * 
     * @param string    $elementName    (optional)Input field name attribute
     * @param string    $elementLabel   (optional)Input field label
     * @param mixed 	$callback		(optional)Method callback that will be used to populate table
     * @param mixed     $attributes     (optional)Either a typical HTML attribute string 
     *                                      or an associative array
     * @return void
     */
    function __construct($elementName=null, $elementLabel=null, $callback=null, $args=null, $attributes=null) {
        parent::__construct($elementName, $elementLabel, $attributes);
        $this->callback = $callback;
        if (!$args || !is_array($args)) $args = array();
        $this->args = $args;
        $this->_persistantFreeze = true;
        $this->setType('text');
    }
    
    function on_hide_js($js) {
    	$this->on_hide_js_code = $js;
    }

    function toHtml() {
        if ($this->_flagFrozen) {
            return $this->getFrozenHtml();
        } else {
        	$name = $this->getAttribute('name');
        	$id = $this->getAttribute('id');
        	if (!$id) {
        		$id = '__autocomplete_id_'.$name;
        		$this->setAttribute('id', $id);
        	}
			$key = md5(serialize($this->callback).$id);
			$_SESSION['client']['quickform']['autocomplete'][$key] = array('callback'=>$this->callback, 'field'=>$name, 'args'=>$this->args);
			eval_js('var epesi_autocompleter = new Ajax.Autocompleter(\''.$id.'\', \''.$id.'_suggestbox\', \'autocomplete_update.php?'.http_build_query(array('cid'=>CID, 'key'=>$key)).'\', {frequency: 0.6});');

			// TODO: not really neat, need to extend the function automatically
			if ($this->on_hide_js_code) eval_js('epesi_autocompleter.hide=function(){'.
					'this.stopIndicator();'.
				    'if (Element.getStyle(this.update, "display") != "none") {'.
				    '    this.options.onHide(this.element, this.update);'.
				    '}'.
				    'if (this.iefix) {'.
				    '    Element.hide(this.iefix);'.
				    '}'.
					$this->on_hide_js_code.
				'}');

            return '<input' . $this->_getAttrString($this->_attributes) . ' />'.
            		'<div id="'.$id.'_suggestbox" class="autocomplete">&nbsp;</div>';
        }
    } //end func toHtml
	        
}
?><commit_msg>autocomplete - introduce getHtml, use parent toHtml<commit_after><?php

/**
 * HTML class for an autocomplete field
 * 
 * @category    HTML
 * @package     HTML_QuickForm
 * @author      <NAME> <<EMAIL>>
 */
class HTML_QuickForm_autocomplete extends HTML_QuickForm_text {
    private $callback;
    private $args = array();
    private $on_hide_js_code = '';
            
    /**
     * Class constructor
     * 
     * @param string    $elementName    (optional)Input field name attribute
     * @param string    $elementLabel   (optional)Input field label
     * @param mixed 	$callback		(optional)Method callback that will be used to populate table
     * @param mixed     $attributes     (optional)Either a typical HTML attribute string 
     *                                      or an associative array
     * @return void
     */
    function __construct($elementName=null, $elementLabel=null, $callback=null, $args=null, $attributes=null) {
        parent::__construct($elementName, $elementLabel, $attributes);
        $this->callback = $callback;
        if (!$args || !is_array($args)) $args = array();
        $this->args = $args;
        $this->_persistantFreeze = true;
        $this->setType('text');
    }
    
    function on_hide_js($js) {
    	$this->on_hide_js_code = $js;
    }

    /**
     * @return string
     */
    public function getHtml()
    {
        $name = $this->getAttribute('name');
        $id = $this->getAttribute('id');
        if (!$id) {
            $id = '__autocomplete_id_' . $name;
            $this->setAttribute('id', $id);
        }
        $key = md5(serialize($this->callback) . $id);
        $_SESSION['client']['quickform']['autocomplete'][$key] = array('callback' => $this->callback, 'field' => $name, 'args' => $this->args);
        eval_js('var epesi_autocompleter = new Ajax.Autocompleter(\'' . $id . '\', \'' . $id . '_suggestbox\', \'autocomplete_update.php?' . http_build_query(array('cid' => CID, 'key' => $key)) . '\', {frequency: 0.6});');

        // TODO: not really neat, need to extend the function automatically
        if ($this->on_hide_js_code) eval_js('epesi_autocompleter.hide=function(){' .
            'this.stopIndicator();' .
            'if (Element.getStyle(this.update, "display") != "none") {' .
            '    this.options.onHide(this.element, this.update);' .
            '}' .
            'if (this.iefix) {' .
            '    Element.hide(this.iefix);' .
            '}' .
            $this->on_hide_js_code .
            '}');

        return '<input' . $this->_getAttrString($this->_attributes) . ' />' .
            '<div id="' . $id . '_suggestbox" class="autocomplete">&nbsp;</div>';
    } //end func toHtml
	        
}
?>
{'fraction_non_alphanumeric': 0.1668849391955098, 'fraction_numerical': 0.0011225444340505146, 'mean_word_length': 2.4225352112676055, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2481257', 'n_tokens_mistral': 1704, 'n_tokens_neox': 1628, 'n_words': 329}