Index: typo3/template.php =================================================================== --- typo3/template.php (revision 5114) +++ typo3/template.php (working copy) @@ -214,11 +214,19 @@ 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. + // internal flags for JS-libraries + protected $addPrototype = false; + protected $addScriptaculousModules = array( + 'builder' => false, + 'effects' => false, + 'dragdrop' => false, + 'controls' => false, + 'slider' => false + ); + protected $addExtJS = false; + protected $addExtJSdebug = false; - - - /** * Constructor * Imports relevant parts from global $TBE_STYLES (colorscheme) @@ -682,7 +690,7 @@ '.$generator.' '.htmlspecialchars($title).' '.$this->docStyle().' - '.implode("\n", $this->JScodeLibArray).' + ' . $this->renderJSlibraries() . ' '.$this->JScode.' '.$this->wrapScriptTags(implode("\n", $this->JScodeArray)). ($this->extJsCode ? $this->wrapScriptTags('Ext.onReady(function() {' . chr(10) . $this->extJsCode . chr(10) . '});') : '') . @@ -1294,19 +1302,34 @@ */ function loadJavascriptLib($lib) { if (!isset($this->JScodeLibArray[$lib])) { - $this->JScodeLibArray[$lib] = ''; + $this->JScodeLibArray[$lib] = ''; } } /** + * + * @param string $lib it will remove lib from general JScodeLibArray because lib is loaded already. + */ + protected function removeJavascriptLib($lib) { + if (count($this->JScodeLibArray)) { + $scripts = array_keys($this->JScodeLibArray); + foreach ($scripts as $script) { + if (strpos($script, '/' . $lib . '/') !== false) { + unset ($this->JScodeLibArray[$script]); + } + } + } + } + + /** * Includes the necessary Javascript function for the clickmenu (context sensitive menus) in the document * * @return array Deprecated: Includes the code already in the doc, so the return array is always empty. * Please just call this function without expecting a return value for future calls */ function getContextMenuCode() { - $this->loadJavascriptLib('contrib/prototype/prototype.js'); + $this->loadPrototype(); $this->loadJavascriptLib('js/clickmenu.js'); $this->JScodeArray['clickmenu'] = ' @@ -1325,7 +1348,7 @@ * @return array If values are present: [0] = A '; + } + + // add other JavascriptLibs and return it + $libs = array_merge($libs, $this->JScodeLibArray); + return count($libs) ? chr(10) . chr(10) . implode(chr(10), $libs) . chr(10) . chr(10) : ''; + } + + /** + * 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) { + // Scriptaculous require prototype, so load prototype too. + $this->addPrototype = true; + $this->addScriptaculous = true; + if ($modules) { + if ($modules == 'all') { + foreach ($this->addScriptaculousModules as $key => $value) { + $this->addScriptaculousModules[$key] = true; + } + } else { + $mods = t3lib_div::trimExplode(',', $modules); + foreach ($mods as $mod) { + if (isset($this->addScriptaculousModules[strtolower($mod)])) { + $this->addScriptaculousModules[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']); + } else { + $this->addStyleSheet('ext-all', $this->backPath . 'contrib/extjs/resources/css/ext-all.css'); + } + } + if ($theme) { + if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) { + $this->addStyleSheet('ext-theme', $GLOBALS['TBE_STYLES']['extJS']['theme']); + } else { + $this->addStyleSheet('ext-theme', $this->backPath . 'contrib/extjs/resources/css/xtheme-gray.css'); + } + } + } + } + + /** + * call this function to load debug version of extJS. Use this for development only + */ + public function setExtJSdebug() { + $this->addExtJSdebug = true; + } + + }