View Issue Details

IDProjectCategoryView StatusLast Update
05807Development Templatespublic2012-08-14 22:44
ReporterDenisChenu Assigned ToDenisChenu  
PrioritynormalSeverityminor 
Status closedResolutionfixed 
Product Version2.00 
Target VersionFixed in Version2.00 
Summary05807: Ability to have some default.css for quick devloppement / Ability to replace survey_runtime.js function in template
Description

1: Ability to have some default.css for quick developpement
Tom have to add a lot of line in a lot of template.
Sometimes, when we want to make some optimisation, there are templating issue

2: some people can want replace survey_runtime.js, but survey_runtime are put at end of head, then need more inline javascript, and inline javascript is evil ( ;) )

3: There are a lot of css file and js file, maybe some day we use some otimisation to have one compressed js file for template, and one compressed css file ( speed optimisation ... ). Or maybe some day, we remove all inline js and we can put js at end of the body

Steps To Reproduce

Look at the source of survey taking

Additional Information

The idea:

replace {TEMPLATE.CSS} by:
jquery-ui.js ( default one or the one included in the template: we can make php test )
default-ls.css
optionnal default-ls-rtl.css
css_header_includes ( optionnaly in template dir ?)
template.css
optionnal template-rtl.css
( maybe some other optionnal css)

Add a new {TEMPLATE.JS} with:
jquery.js
js_header_includes javascript ( optionnaly in template dir ?)
survey_runtime.js ( optionnaly in template dir ?)
template.js ( if exist)

I can go for 2 or 1.92, I think it's a good idea.

TagsNo tags attached.

Activities

DenisChenu

DenisChenu

2012-02-11 10:24

developer   ~17374

Last edited: 2012-02-11 10:24

View 2 revisions

Old template compatibility:

if (stripos($line, "</head>")) {
$startpage_template = file_get_contents($thistpl.'/startpage.pstpl');
if( preg_match( '/{TEMPLATE.JS}/' , $question_template ) === false){
//Include js_header_includes and survey_runtime.js

Same think for template.css : but with
if (stripos($line, "<head>")) {

tpartner

tpartner

2012-02-11 14:12

developer   ~17376

I like it. Particularly the inclusion of template.js after survey_runtime.js. That will hand more control back to the template designer.

DenisChenu

DenisChenu

2012-05-10 12:16

developer  

diff5807.diff (8,323 bytes)
diff --git a/application/controllers/UploaderController.php b/application/controllers/UploaderController.php
index d74dcfb..9d9c0b1 100644
--- a/application/controllers/UploaderController.php
+++ b/application/controllers/UploaderController.php
@@ -240,8 +240,8 @@ class UploaderController extends AdminController {
 		    }
 		return;
 		}
-
-		$meta = '<script type="text/javascript">
+		$meta ='<script type="text/javascript" src="'.Yii::app()->getConfig("generalscripts").'jquery/jquery.js"></script>';
+		$meta .= '<script type="text/javascript">
 		    var uploadurl = "'.$this->createUrl('/uploader/index/mode/upload/').'";
             var imageurl = "'.Yii::app()->getConfig('imageurl').'/";
 		    var surveyid = "'.$surveyid.'";
diff --git a/application/helpers/common_helper.php b/application/helpers/common_helper.php
index 2e70246..924bb56 100644
--- a/application/helpers/common_helper.php
+++ b/application/helpers/common_helper.php
@@ -7123,26 +7123,6 @@ function getHeader($meta = false)
     {
         $languagecode = Yii::app()->getConfig('defaultlang');
     }
-
-    $js_header = ''; $css_header='';
-    if(Yii::app()->getConfig("js_admin_includes"))
-    {
-        foreach (Yii::app()->getConfig("js_admin_includes") as $jsinclude)
-        {
-            if (substr($jsinclude,0,4) == 'http')
-                $js_header .= "<script type=\"text/javascript\" src=\"{$jsinclude}\"></script>\n";
-            else
-                $js_header .= "<script type=\"text/javascript\" src=\"".Yii::app()->baseUrl."{$jsinclude}\"></script>\n";
-        }
-    }
-    if(Yii::app()->getConfig("css_admin_includes"))
-    {
-        foreach (Yii::app()->getConfig("css_admin_includes") as $cssinclude)
-        {
-            $css_header .= "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"".Yii::app()->baseUrl.$cssinclude."\" />\n";
-        }
-    }
-
     if ( !$embedded )
     {
         $header=  "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
@@ -7151,14 +7131,7 @@ function getHeader($meta = false)
         {
             $header.=" dir=\"rtl\" ";
         }
-        $header.= ">\n\t<head>\n"
-        . $css_header
-        . "<script type=\"text/javascript\" src=\"".Yii::app()->getConfig('generalscripts')."jquery/jquery.js\"></script>\n"
-        . "<script type=\"text/javascript\" src=\"".Yii::app()->getConfig('generalscripts')."jquery/jquery-ui.js\"></script>\n"
-        . "<link href=\"".Yii::app()->getConfig('generalscripts')."jquery/css/start/jquery-ui.css\" media=\"all\" type=\"text/css\" rel=\"stylesheet\" />"
-        . "<link href=\"".Yii::app()->getConfig('generalscripts')."jquery/css/start/lime-progress.css\" media=\"all\" type=\"text/css\" rel=\"stylesheet\" />"
-        . $js_header;
-
+        $header.= ">\n\t<head>\n";
         if ($meta)
             $header .= $meta;
 
diff --git a/application/helpers/replacements_helper.php b/application/helpers/replacements_helper.php
index 70d6a86..8c8b00e 100644
--- a/application/helpers/replacements_helper.php
+++ b/application/helpers/replacements_helper.php
@@ -122,14 +122,66 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de
     if(!isset($templatedir)) $templatedir = getTemplatePath($templatename);
     if(!isset($templateurl)) $templateurl = getTemplateURL($templatename)."/";
 
-    if (stripos ($line,"</head>"))
+    // TEMPLATECSS and TEMPLATEJS
+    $_templatecss="";$_templatejs="";
+    if(stripos ($line,"{TEMPLATECSS}"))
     {
-        $line=str_ireplace("</head>",
-        "<script type=\"text/javascript\" src=\"".Yii::app()->getConfig('generalscripts')."survey_runtime.js\"></script>\n"
-        .useFirebug()
-        ."\t</head>", $line);
+        global $css_header_includes;
+        if (file_exists($templatedir . '/jquery-ui-custom.css'))
+        {
+            $_jqueryuicssurl = "{$templateurl}jquery-ui-custom.css";
+        }
+        elseif(file_exists($templatedir . '/jquery-ui.css'))
+        {
+            $_jqueryuicssurl = "{$templateurl}jquery-ui.css";
+        }
+        else
+        {
+            $_jqueryuicssurl =Yii::app()->getConfig('generalscripts')."jquery/css/start/jquery-ui.css";
+        }
+        $_templatecss.= "<link rel='stylesheet' type='text/css' media='all' href='{$_jqueryuicssurl}' />\n";
+        if(Yii::app()->getConfig("css_admin_includes"))
+        {
+            foreach (Yii::app()->getConfig("css_admin_includes") as $cssinclude)
+            {
+                $css_header .= "<link rel='stylesheet' type='text/css' media='all' href='".Yii::app()->baseUrl.$cssinclude."' />\n";
+            }
+        }
+        $_templatecss .= "<link href='".Yii::app()->getConfig('generalscripts')."jquery/css/start/lime-progress.css' media='all' type='text/css' rel='stylesheet' />\n";
+        if($css_header_includes){
+        $css_header_includes = array_unique($css_header_includes);
+            foreach ($css_header_includes as $cssinclude)
+            {
+                $_templatecss .= "<link rel='stylesheet' type='text/css' media='all' href='".Yii::app()->baseUrl.$cssinclude."' />\n";
+            }
+        }
+        $_templatecss.= "<link rel='stylesheet' type='text/css' media='all' href='{$templateurl}template.css' />\n";
+        if (getLanguageRTL($clang->langcode))
+        {
+            $_templatecss.="<link rel='stylesheet' type='text/css' media='all' href='{$templateurl}template-rtl.css' />\n";
+        }
     }
+    if(stripos ($line,"{TEMPLATEJS}"))
+    {
+        global $js_header_includes;
+        $_jqueryuijsurl=Yii::app()->getConfig('generalscripts')."jquery/jquery-ui.js";
+        $_templatejs.= "<script type='text/javascript' src='".Yii::app()->getConfig('generalscripts')."jquery/jquery.js'></script>\n";
+        $_templatejs.= "<script type='text/javascript' src='{$_jqueryuijsurl}'></script>\n";
 
+        if($js_header_includes){
+            $js_header_includes = array_unique($js_header_includes);
+            foreach ($js_header_includes as $jsinclude)
+            {
+                if (substr($jsinclude,0,4) == 'http')
+                    $_templatejs .= "<script type='text/javascript' src='{$jsinclude}'></script>\n";
+                else
+                    $_templatejs .= "<script type='text/javascript' src='".Yii::app()->baseUrl.$jsinclude."'></script>\n";
+            }
+        }
+        $_templatejs.= "<script type='text/javascript' src='".Yii::app()->getConfig('generalscripts')."survey_runtime.js'></script>\n";
+        $_templatejs.= "<script type='text/javascript' src='{$templateurl}template.js'></script>\n";
+        $_templatejs.= useFirebug();
+    }
     // surveyformat
     if (isset($thissurvey['format']))
     {
@@ -402,11 +454,7 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de
         $_saveall = "";
     }
 
-    $_templatecss = "<link rel='stylesheet' type='text/css' href='{$templateurl}template.css' />\n";
-    if (getLanguageRTL($clang->langcode))
-    {
-        $_templatecss.="<link rel='stylesheet' type='text/css' href='{$templateurl}template-rtl.css' />\n";
-    }
+
 
     if(!isset($help)) $help = "";
     if (flattenText($help, true,true) != '')
@@ -776,6 +824,7 @@ EOD;
     $coreReplacements['SURVEYLISTHEADING'] =  (isset($surveylist))?$surveylist['listheading']:'';
     $coreReplacements['SURVEYNAME'] = (isset($thissurvey['name']) ? $thissurvey['name'] : '');
     $coreReplacements['TEMPLATECSS'] = $_templatecss;
+    $coreReplacements['TEMPLATEJS'] = $_templatejs;
     $coreReplacements['TEMPLATEURL'] = $templateurl;
     $coreReplacements['THEREAREXQUESTIONS'] = $_therearexquestions;
     if (!$anonymized) $coreReplacements['TOKEN'] = $_token;
diff --git a/templates/default/startpage.pstpl b/templates/default/startpage.pstpl
index f1c2796..5eda98b 100644
--- a/templates/default/startpage.pstpl
+++ b/templates/default/startpage.pstpl
@@ -22,7 +22,7 @@
             progress-graph .zero, progress-graph .graph, progress-graph .cent { display: none; }
 		</style>
 		
-		<script type="text/javascript" src="{TEMPLATEURL}template.js"></script>
+		{TEMPLATEJS}
 <link rel="shortcut icon" href="{TEMPLATEURL}favicon.ico" />
 {GOOGLE_ANALYTICS_JAVASCRIPT}
 </head>
diff5807.diff (8,323 bytes)
DenisChenu

DenisChenu

2012-05-10 12:19

developer   ~18651

Carsten, i assigned to you for you advice.
I put a diff,

It correct to a bug in "timer attribute'.

If OK, i put in Yii version.

Some other manipulation for templating : use template/uploader.js replacement ( and other .js file replacement).

Denis

DenisChenu

DenisChenu

2012-05-14 15:05

developer   ~18733

http://git.io/DBo3FQ
and http://git.io/fVZCtA

Adding TEMPLATEJS, add a lot of css file in TEMPLATECSS

Issue History

Date Modified Username Field Change
2012-02-11 02:05 DenisChenu New Issue
2012-02-11 10:24 DenisChenu Note Added: 17374
2012-02-11 10:24 DenisChenu Note Edited: 17374 View Revisions
2012-02-11 14:12 tpartner Note Added: 17376
2012-05-10 12:16 DenisChenu Product Version 1.92RC2 => 2.00
2012-05-10 12:16 DenisChenu File Added: diff5807.diff
2012-05-10 12:16 DenisChenu Assigned To => c_schmitz
2012-05-10 12:16 DenisChenu Status new => assigned
2012-05-10 12:19 DenisChenu Note Added: 18651
2012-05-14 10:41 DenisChenu Assigned To c_schmitz => DenisChenu
2012-05-14 15:05 DenisChenu Note Added: 18733
2012-05-14 15:05 DenisChenu Status assigned => resolved
2012-05-14 15:05 DenisChenu Fixed in Version => 2.00
2012-05-14 15:05 DenisChenu Resolution open => fixed
2012-08-14 22:44 c_schmitz Status resolved => closed