/**
* Attach the Imple object to a javascript event.
+ * Assume that if the 'container' parameter is empty then we want a
+ * traditional autocompleter, otherwise we get a spiffy pretty one.
+ *
*/
public function attach()
{
+ global $registry;
parent::attach();
Horde::addScriptFile('autocomplete.js', 'horde', true);
- $params = array(
- '"' . $this->_params['triggerId'] . '"',
- '"' . $this->_params['resultsId'] . '"',
- '"' . Horde::url($GLOBALS['registry']->get('webroot', 'kronolith') . '/imple.php?imple=TagAutoCompleter/input=' . rawurlencode($this->_params['triggerId']), true) . '"'
- );
+ if ($pretty = !empty($this->_params['container'])) {
+ Horde::addScriptFile('taggerAutoCompleter.js', 'kronolith', true);
+ }
+ $this->_params['uri'] = Horde::url($GLOBALS['registry']->get('webroot', 'kronolith') . '/imple.php?imple=TagAutoCompleter/input=' . rawurlencode($this->_params['triggerId']), true);
+
+ if (!$pretty) {
+ $params = array(
+ '"' . $this->_params['triggerId'] . '"',
+ '"' . $this->_params['resultsId'] . '"',
+ '"' . $this->_params['uri'] . '"'
+ );
+ }
$js_params = array(
'tokens: [","]',
'indicator: "' . $this->_params['triggerId'] . '_loading_img"'
);
- if (!empty($this->_params['updateElement'])) {
+ // The pretty version needs to set this callback itself...
+ if (!$pretty && !empty($this->_params['updateElement'])) {
$js_params[] = 'updateElement: ' . $this->_params['updateElement'];
}
$params[] = '{' . implode(',', $js_params) . '}';
- Kronolith::addInlineScript('new Ajax.Autocompleter(' . implode(',', $params) . ')', 'dom');
+ if ($pretty) {
+ $js_vars = array('resultsId' => $this->_params['resultsId'],
+ 'uri' => $this->_params['uri'],
+ 'selectedTags' => array(),
+ 'trigger' => $this->_params['triggerId'],
+ 'tags' => $this->_params['tags'],
+ 'container' => $this->_params['container'],
+ 'URI_IMG_HORDE' => $registry->getImageDir('horde'),
+ 'params' => $params);
+ // These are optional
+ if ($this->_params['debug']) {
+ $js_vars['debug'] = $this->_params['debug'];
+ }
+
+ if ($this->_params['existing']) {
+ $js_vars['existing'] = $this->_params['existing'];
+ }
+
+ $script = array('new KronolithTagger(' . Horde_Serialize::serialize($js_vars, Horde_Serialize::JSON, NLS::getCharset()) . ')');
+ } else {
+ $script = array('new Ajax.Autocompleter(' . implode(',', $params) . ')');
+ }
+
+ Kronolith::addInlineScript($script, 'dom');
}
/**