function _assignJavascript($tpl_source, &$smarty) { // load autocompleter css $html = $this->autocompleterCss; // start javascript code $html .= "\n<script type=\"text/javascript\">\n"; // use default url $html .= "var xajaxRequestUri = \"" . YDRequest::getNormalizedUri() . "\";\n"; // check debug option $html .= "var xajaxDebug = " . (YDConfig::get('YD_AJAX_DEBUG') ? "true" : "false") . ";\n"; $html .= "var xajaxStatusMessages = " . (YDConfig::get('YD_AJAX_DEBUG') ? "true" : "false") . ";\n"; $html .= "var xajaxWaitCursor = " . (YDConfig::get('YD_AJAX_DEBUG') ? "true" : "false") . ";\n"; // use post $html .= "var xajaxDefinedGet = 0;\n"; $html .= "var xajaxDefinedPost = 1;\n"; // get standard xajax code $html .= file_get_contents(dirname(__FILE__) . '/js/xajax.js'); // include generic effects lib .. yes, it must be ALWAYS included $html .= "\n" . file_get_contents(dirname(__FILE__) . '/js/prototype.lite.js_moo.fx.js_moo.fx.pack.js'); // send autocompleter code $html .= "\n" . $this->autocompleterCode; // compute ONLOAD code $onload = ''; // export effects js foreach ($this->effects as $eff_name => $eff_code) { $onload .= $eff_code . "\n\t"; } // send js waiting message creation code if ($this->waitingMessageCode != '') { $onload .= $this->waitingMessageCode . "\n\t"; } // send autocompleter functions code $onload .= implode("\n\t", $this->autocompleterCodeFunctions); // if there are on load js just export it if ($onload != '') { $html .= "\nwindow.onload = function() {\n\t" . $onload . "\n}"; } // send js function to hide waiting message $html .= $this->waitingMessageCodeFunction . "\n"; // loop xajax functions created on-the-fly foreach ($this->aFunctions as $sFunction => $bExists) { $html .= $this->_wrap($sFunction, $this->aFunctionRequestTypes[$sFunction]); } // add custom js TOP code if (!empty($this->customjsTop)) { $html .= implode("\n", $this->customjsTop) . "\n"; } // add YDAjax js variables foreach ($this->customjsVariables as $variable => $declaration) { $html .= "var " . $variable . " = " . $declaration . ";\n"; } // add YDAjax js functions foreach ($this->customjs as $function => $declaration) { $html .= "function " . $function . "{" . $declaration . "}\n"; } // add js custom BOTTOM code if (!empty($this->customjsBottom)) { $html .= implode("\n", $this->customjsBottom) . "\n"; } // end javascript code $html .= "</script>\n"; // get html tag to use $tag = YDConfig::get('YD_AJAX_TAG'); // add js code to template if (YDConfig::get('YD_AJAX_AFTERTAG')) { return eregi_replace($tag, $tag . "\n" . $html, $tpl_source); } else { return eregi_replace($tag, $html . "\n" . $tag, $tpl_source); } }
function __assignTemplateCode() { // use default url $html = "var xajaxRequestUri = \"" . YDRequest::getNormalizedUri() . "\";\n"; // check debug option $html .= "var xajaxDebug = " . (YDConfig::get('YD_AJAX_DEBUG') ? "true" : "false") . ";\n"; $html .= "var xajaxStatusMessages = " . (YDConfig::get('YD_AJAX_DEBUG') ? "true" : "false") . ";\n"; $html .= "var xajaxWaitCursor = " . (YDConfig::get('YD_AJAX_DEBUG') ? "true" : "false") . ";\n"; // use post $html .= "var xajaxDefinedGet = 0;\n"; $html .= "var xajaxDefinedPost = 1;\n"; // get standard xajax code $html .= file_get_contents(dirname(__FILE__) . '/js/xajax.js') . "\n"; // include generic effects lib .. yes, it must be ALWAYS included $html .= file_get_contents(dirname(__FILE__) . '/js/prototype.lite.js_moo.fx.js_moo.fx.pack.js') . "\n"; // send autocompleter code $html .= $this->autocompleterCode; // send js function to hide waiting message $html .= $this->waitingMessageCodeFunction; // loop xajax functions created on-the-fly foreach ($this->aFunctions as $sFunction => $bExists) { $html .= $this->_wrap($sFunction, $this->aFunctionRequestTypes[$sFunction]); } // add custom js TOP code if (!empty($this->customjsTop)) { $html .= implode("\n", $this->customjsTop) . "\n"; } // add YDAjax js variables foreach ($this->customjsVariables as $variable => $declaration) { $html .= "var " . $variable . " = " . $declaration . ";\n"; } // add YDAjax js functions foreach ($this->customjs as $function => $declaration) { $html .= "function " . $function . "{" . $declaration . "}\n"; } // add js custom BOTTOM code if (!empty($this->customjsBottom)) { $html .= implode("\n", $this->customjsBottom) . "\n"; } // add all code to template html $this->template->addJavascript(trim($html), true); // compute ONLOAD code $onload = ''; // export effects js foreach ($this->effects as $eff_name => $eff_code) { $onload .= "\n\t" . $eff_code; } // send js waiting message creation code if ($this->waitingMessageCode != '') { $onload .= "\n\t" . $this->waitingMessageCode; } // send autocompleter functions code if (!empty($this->autocompleterCodeFunctions)) { $onload .= "\n\t" . implode("\n\t", $this->autocompleterCodeFunctions); } // add all code to template html $this->template->addJavascript($onload, false, true); }
/** * This function returns the normalized full URL * * @returns The normalized full URL of the current request. */ function getNormalizedCurrentUrl() { $url = 'http://' . strtolower($_SERVER['SERVER_NAME']); if ($_SERVER['SERVER_PORT'] != '80') { $url = $url . ':' . $_SERVER['SERVER_PORT']; } return $url . YDRequest::getNormalizedUri(); }
/** * This is the class constructor for the YDAjax class. * * @param $template Template object. */ function YDAjax(&$template, $url_string = null, $outputFiles = true) { // Setup the module $this->_author = 'Francisco Azevedo'; $this->_version = '3.0b'; $this->_copyright = '(c) Copyright 2002-2006 Francisco Azevedo'; $this->_description = 'This class makes ajax easy for YDF developers'; // prefix string used in js function names $this->prefix = YDConfig::get('YD_AJAX_PREFIX'); // initialize xajax object $this->xajax("", $this->prefix, YDConfig::get('YD_AJAX_ENCODING')); // initilize all possible forms (4) $this->form_0 = null; $this->form_1 = null; $this->form_2 = null; $this->form_3 = null; // initilize template $this->template =& $template; // response object $this->response = new YDAjaxResponse(YDConfig::get('YD_AJAX_ENCODING')); // by default we don't use effects (then js effects lib won't be loaded) $this->effects = array(); // autocompleter code $this->autocompleterCode = ''; $this->autocompleterCss = ''; $this->autocompleterCodeFunctions = array(); // init wysiwyg editors $this->wysiwyg_editorpath = dirname(__FILE__) . '/editors/YDAjaxEditor.php'; $this->wysiwyg_editorclass = 'YDAjaxEditor'; $this->wysiwyg_forms = array(); // check url if (is_null($url_string)) { $url_string = YDRequest::getNormalizedUri(); } // compute default ajax header $html = "var xajaxRequestUri = \"" . $url_string . "\";\n"; $debug = YDConfig::get('YD_AJAX_DEBUG') ? "true" : "false"; // check debug option $html .= "var xajaxDebug = " . $debug . ";\n"; $html .= "var xajaxStatusMessages = " . $debug . ";\n"; $html .= "var xajaxWaitCursor = " . $debug . ";\n"; // use post $html .= "var xajaxDefinedGet = 0;\n"; $html .= "var xajaxDefinedPost = 1;\n"; // get standard xajax code if ($outputFiles) { $html .= file_get_contents(dirname(__FILE__) . '/js/xajax.js') . "\n"; } // add default header to template $this->template->addJavascript($html, true, false); // array to store events already added $this->_eventsAdded = array(); }