[evolvis-commits] r18739: new use_javascript_snippet() which is in-order with use_javascript(); convert jquery_noconflict.js to it

mirabilos at evolvis.org mirabilos at evolvis.org
Mon Nov 5 18:10:18 CET 2012


Author: mirabilos
Date: 2012-11-05 18:10:17 +0100 (Mon, 05 Nov 2012)
New Revision: 18739

Modified:
   trunk/gforge_base/evolvisforge-5.1/src/common/include/datepick.php
   trunk/gforge_base/evolvisforge-5.1/src/common/include/utils.php
   trunk/gforge_base/evolvisforge-5.1/src/www/include/Layout.class.php
   trunk/gforge_base/evolvisforge-5.1/src/www/include/html.php
   trunk/gforge_base/evolvisforge-5.1/src/www/themes/evolvis/Theme.class.php
Log:
new use_javascript_snippet() which is in-order with use_javascript(); convert jquery_noconflict.js to it

this will also save us a file load

Modified: trunk/gforge_base/evolvisforge-5.1/src/common/include/datepick.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/common/include/datepick.php	2012-11-05 17:10:11 UTC (rev 18738)
+++ trunk/gforge_base/evolvisforge-5.1/src/common/include/datepick.php	2012-11-05 17:10:17 UTC (rev 18739)
@@ -130,7 +130,7 @@
 function datepick_prepare() {
 	global $HTML;
 
-	$HTML->addJavascript('/js/datepicker.js');
+	$HTML->addJavascriptEx('/js/datepicker.js', false);
 
 	$HTML->footer_hooks[] = 'datepick__footer_hook';
 }

Modified: trunk/gforge_base/evolvisforge-5.1/src/common/include/utils.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/common/include/utils.php	2012-11-05 17:10:11 UTC (rev 18738)
+++ trunk/gforge_base/evolvisforge-5.1/src/common/include/utils.php	2012-11-05 17:10:17 UTC (rev 18739)
@@ -1283,9 +1283,13 @@
 }
 
 function use_javascript($js) {
-	return $GLOBALS['HTML']->addJavascript($js);
+	return $GLOBALS['HTML']->addJavascriptEx($js, false);
 }
 
+function use_javascript_snippet($jsinline) {
+	return $GLOBALS['HTML']->addJavascriptEx($jsinline, true);
+}
+
 function use_stylesheet($css, $media='') {
 	return $GLOBALS['HTML']->addStylesheet($css, $media);
 }

Modified: trunk/gforge_base/evolvisforge-5.1/src/www/include/Layout.class.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/www/include/Layout.class.php	2012-11-05 17:10:11 UTC (rev 18738)
+++ trunk/gforge_base/evolvisforge-5.1/src/www/include/Layout.class.php	2012-11-05 17:10:17 UTC (rev 18739)
@@ -106,7 +106,7 @@
 
 	var $js = array();
 	var $js_min = array();
-	var $javascripts = array();
+	var $javascriptlets = array();
 	var $css = array();
 	var $css_min = array();
 	var $stylesheets = array();
@@ -166,16 +166,20 @@
 
 		$this->addStylesheet('/themes/css/fusionforge.css');
 
-		$this->addJavascript("/scripts/prototype/prototype.js");
-		$this->addJavascript("/scripts/scriptaculous/scriptaculous.js");
-		$this->addJavascript("/scripts/codendi/Tooltip.js");
-		$this->addJavascript("/scripts/codendi/LayoutManager.js");
-		$this->addJavascript("/scripts/codendi/ReorderColumns.js");
-		$this->addJavascript("/scripts/codendi/validate.js");
-		$this->addJavascript('/js/common.js');
+		$this->addJavascriptEx("/scripts/prototype/prototype.js", false);
+		$this->addJavascriptEx("/scripts/scriptaculous/scriptaculous.js", false);
+		$this->addJavascriptEx("/scripts/codendi/Tooltip.js", false);
+		$this->addJavascriptEx("/scripts/codendi/LayoutManager.js", false);
+		$this->addJavascriptEx("/scripts/codendi/ReorderColumns.js", false);
+		$this->addJavascriptEx("/scripts/codendi/validate.js", false);
+		$this->addJavascriptEx('/js/common.js', false);
 	}
 
-	function addJavascript($js) {
+	function addJavascriptEx($js, $isinline) {
+		if ($isinline) {
+			$this->javascriptlets[] = array($js, true);
+			return;
+		}
 		if (isset($this->js_min[$js])) {
 			$js = $this->js_min[$js];
 		}
@@ -190,7 +194,7 @@
 					$js .= '?'.date ("U", filemtime($filename));
 				}
 			}
-			$this->javascripts[] = $js;
+			$this->javascriptlets[] = array($js, false);
 		}
 	}
 
@@ -215,10 +219,25 @@
 
 	function getJavascripts() {
 		$code = '';
-		foreach ($this->javascripts as $js) {
-			$code .= "\t" .
-			    '<script type="text/javascript" src="' . $js .
-			    '"></script>' . "\n";
+		foreach ($this->javascriptlets as $jsa) {
+			$js = trim($jsa[0]);
+			if ($jsa[1]) {
+				if (!$js) {
+					continue;
+				}
+				$code .= "\t" .
+				    '<script language="JavaScript" type="text/javascript">//<![CDATA[';
+				foreach (explode("\n", $js) as $jsline) {
+					$code .= "\n\t\t" . $jsline;
+				}
+				$code .= "\n\t//]]></script>\n";
+			} else {
+				$code .= "\t" . html_e('script', array(
+					'language' => 'JavaScript',
+					'type' => 'text/javascript',
+					'src' => $js,
+				    ), "", false) . "\n";
+			}
 		}
 		return $code;
 	}

Modified: trunk/gforge_base/evolvisforge-5.1/src/www/include/html.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/www/include/html.php	2012-11-05 17:10:11 UTC (rev 18738)
+++ trunk/gforge_base/evolvisforge-5.1/src/www/include/html.php	2012-11-05 17:10:17 UTC (rev 18739)
@@ -347,7 +347,17 @@
 
 function html_use_jquery() {
 	use_javascript('/scripts/jquery/jquery.js');
-	use_javascript('/js/jquery_noconflict.js');
+	use_javascript_snippet('
+		/*
+		 * switch jQuery into no conflict mode, i.e. do not let
+		 * it possess the dollar sign function; according to the
+		 * docs, this must come after both jQuery and Prototype
+		 * have been loaded, not before (why?) but apparently it
+		 * should come immediately after jQuery…
+		 */
+
+		jQuery.noConflict();
+	    ');
 }
 
 function html_use_tooltips($defaults=false) {

Modified: trunk/gforge_base/evolvisforge-5.1/src/www/themes/evolvis/Theme.class.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/www/themes/evolvis/Theme.class.php	2012-11-05 17:10:11 UTC (rev 18738)
+++ trunk/gforge_base/evolvisforge-5.1/src/www/themes/evolvis/Theme.class.php	2012-11-05 17:10:17 UTC (rev 18739)
@@ -58,8 +58,8 @@
 		$this->addStylesheet('/themes/css/evolvis.css', 'all');
 		// $this->addStylesheet('/themes/css/screen.css', 'screen');
 		$this->addStylesheet('/themes/css/print.css', 'print');
-		$this->addJavascript('/js/common.js');
-		$this->addJavascript('/js/css.js');
+		$this->addJavascriptEx('/js/common.js', false);
+		$this->addJavascriptEx('/js/css.js', false);
 		$this->project = false;
 		$this->emit_forgehead = true;
 		$this->emit_forgefoot = true;



More information about the evolvis-commits mailing list