Index: typo3/template.php =================================================================== --- typo3/template.php (revision 4718) +++ typo3/template.php (working copy) @@ -213,11 +213,20 @@ var $sectionFlag=0; // Internal: Indicates if a
-output section is open var $divClass = ''; // (Default) Class for wrapping
-tag of page. Is set in class extensions. + // flags for JS-libraries + protected $addPrototype = false; + protected $addScriptaculous = false; + protected $scriptaculousModules = array ( + 'builder' => false, + 'effects' => false, + 'dragdrop' => false, + 'controls' => false, + 'slider' => false + ); + protected $addExtJS = false; + protected $extJSDebug = false; + - - - - /** * Constructor * Imports relevant parts from global $TBE_STYLES (colorscheme) @@ -681,7 +690,7 @@ '.$generator.' '.htmlspecialchars($title).' '.$this->docStyle().' - '.implode("\n", $this->JScodeLibArray).' + ' . $this->renderJSlibraries() . implode("\n", $this->JScodeLibArray).' '.$this->JScode.' '.$this->wrapScriptTags(implode("\n", $this->JScodeArray)).' @@ -1995,6 +2004,160 @@ $pageInfo = $theIcon . '[pid: ' . $pageRecord['uid'] . ']'; return $pageInfo; } + + + /** + * Following functions are help function for JS library include. + * They enable loading the libraries prototype, scriptaculous and extJS from contrib-directory + */ + + + /** + * Function for render the JS-libraries in header + * Load order is prototype / scriptaculous / extJS + */ + protected function renderJSlibraries() { + $libTags = ''; + if ($this->addPrototype) { + // render prototype inclusion + $libTags .= ''; + $libTags .= chr(10) . ''; + // remove prototype from JScodeLibArray + $this->removeLibFromArray('prototype'); + } + + if ($this->addScriptaculous) { + // render scriptaculous inclusion + $libTags .= chr(10) . ''; + $mods = array(); + foreach ($this->scriptaculousModules as $key => $value) { + if ($this->scriptaculousModules[$key]) { + $mods[] = $key; + } + } + // solve dependencies + if (in_array('dragdrop', $mods) || in_array('controls', $mods)) { + $mods = array_merge(array('effects'), $mods); + } + + if (count($mods)) { + $moduleLoadString = '?load=' . implode(',', $mods); + } + $libTags .= chr(10) . ''; + // remove scriptaculous from JScodeLibArray + $this->removeLibFromArray('scriptaculous'); + } + + if ($this->addExtJS) { + // render extJS inclusion + $libTags .= chr(10) . ''; + if ($this->addPrototype) { + // add prototype adapter + $libTags .= chr(10) . ''; + } else { + // add extJS adapter + $libTags .= chr(10) . ''; + } + if ($this->extJSDebug) { + $libTags .= chr(10) . ''; + } else { + $libTags .= chr(10) . ''; + } + // set clear.gif + $this->extJScode .= 'Ext.BLANK_IMAGE_URL = "' . htmlspecialchars(t3lib_div::locationHeaderUrl('gfx/clear.gif')) . '";'; + // remove extjs from JScodeLibArray + $this->removeLibFromArray('extjs'); + } + + return $libTags ? chr(10) . chr(10) . $libTags . chr(10) . chr(10) : ''; + } + + /** + * + * @param string $lib it will delete loading lib from general JScodeLibArray because lib is loaded already. + */ + protected function removeLibFromArray($lib) { + if (count($this->JScodeLibArray)) { + $scripts = array_keys($this->JScodeLibArray); + foreach ($scripts as $script) { + if (strpos('/' . $lib, $script)) { + unset ($this->JScodeLibArray[$script]); + } + } + } + } + + /** + * call function if you need the prototype library + */ + public function loadPrototype() { + $this->addPrototype = true; + } + + /** + * call function if you need the Scriptaculous library + * @param string $modules add modules you need. use "all" if you need complete modules + */ + public function loadScriptaculous($modules = '') { + $this->addScriptaculous = true; + if ($modules) { + $this->loadScriptaculousModules($modules); + } + } + + /** + * call this function if you need additional modules for scriptaculous library + * @param string $modules + */ + public function loadScriptaculousModules($modules) { + if ($modules) { + if ($modules == 'all') { + foreach ($this->scriptaculousModules as $key => $value) { + $this->scriptaculousModules[$key] = true; + } + } else { + $mods = t3lib_div::trimExplode(',', $modules); + foreach ($mods as $mod) { + if (isset($this->scriptaculousModules[strtolower($mod)])) { + $this->scriptaculousModules[strtolower($mod)] = true; + } + } + } + } + } + + /** + * call this function if you need the extJS library + * @param string $css + */ + public function loadExtJS($css = true, $theme = true) { + if (!$this->addExtJS) { + $this->addExtJS = true; + if ($css) { + if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) { + $this->addStyleSheet('ext-all', $GLOBALS['TBE_STYLES']['extJS']['all'], 'ext-all'); + } else { + $this->addStyleSheet('ext-all', 'contrib/extjs/resources/css/ext-all.css', 'ext-all'); + } + } + if ($theme) { + if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) { + $this->addStyleSheet('ext-theme', $GLOBALS['TBE_STYLES']['extJS']['theme'], 'ext-theme'); + } else { + $this->addStyleSheet('ext-theme', 'contrib/extjs/resources/css/xtheme-gray.css', 'ext-theme'); + } + } + } + } + + /** + * call this function to load debug version of extJS. Use this for development only + */ + public function setExtJSDebug() { + $this->extJSDebug = 1; + } + + }