Skip to content

Commit

Permalink
New feature : add a jquery event after html is updated by expression …
Browse files Browse the repository at this point in the history
…: html:updated

Dev: Fixed issue #11937: Help question start empty, updated after : not shown
  • Loading branch information
Shnoulle committed Nov 23, 2016
1 parent 8076be3 commit db0dc89
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
1 change: 1 addition & 0 deletions application/config/packages.php
Expand Up @@ -18,6 +18,7 @@
'survey.js',
),
'depends' => array(
'jquery',
'fontawesome',
//'bootstrap', //limesurvey in future must work without boostrap
)
Expand Down
19 changes: 9 additions & 10 deletions application/helpers/expressions/em_core_helper.php
Expand Up @@ -1370,20 +1370,19 @@ public function GetJavascriptTestforExpression($expected,$num)

/**
* Generate the function needed to dynamically change the value of a <span> section
* @param string $name - the ID name for the function
* @param string $eqn
* @param integer $questionNum
* @return <type>
* @param integer $questionNum No longer used
* @param string $elementId - the ID name for the function
* @param string $eqn No longer used
* @return string : javascript part
*/
public function GetJavaScriptFunctionForReplacement($questionNum, $name,$eqn)
public function GetJavaScriptFunctionForReplacement($questionNum, $elementId,$eqn)
{
$jsParts = array();
// $jsParts[] = "\n // Tailor Question " . $questionNum . " - " . $name . ": { " . $eqn . " }\n";
$jsParts[] = " try{\n";
$jsParts[] = " document.getElementById('" . $name . "').innerHTML=LEMfixnum(\n ";
$jsParts[] = "jQuery('#{$elementId}').html(LEMfixnum(\n";
$jsParts[] = $this->GetJavaScriptEquivalentOfExpression();
$jsParts[] = ");\n";
$jsParts[] = " } catch (e) { console.log(e); }\n";
$jsParts[] = "));\n";
// Add an event after html is updated (see #11937 and really good helper for template manager)
$jsParts[] = "jQuery('#{$elementId}').trigger('html:updated');\n";// See http://learn.jquery.com/events/introduction-to-custom-events/#naming-custom-events for colons in name
return implode('',$jsParts);
}

Expand Down
15 changes: 8 additions & 7 deletions templates/default/css/template.css
Expand Up @@ -123,6 +123,7 @@ padding-top:1em;padding-bottom:1em;margin-bottom:2em;
line-height: inherit;
height:100%;
}

/* If you want to center the icon */
/*
.ls-questionhelp:before {
Expand All @@ -134,7 +135,7 @@ padding-top:1em;padding-bottom:1em;margin-bottom:2em;
left:-1.1em;
}
.dir-rtl .ls-questionhelp:before {
right:0;
right:-1.1em;
}

/**
Expand Down Expand Up @@ -623,7 +624,7 @@ div.yes-no .btn-group label {
}
}

@media only screen and (max-device-width: 760px){
@media only screen and (max-device-width: 760px){

h1, .h3{
font-size:18px;
Expand Down Expand Up @@ -655,11 +656,11 @@ div.yes-no .btn-group label {
.table-bordered{
border:none;
}

.ls-answers tbody:last-child tr:last-child{
margin-bottom:0;
}

.ls-answers{
padding-top:0;
padding-bottom:0;
Expand All @@ -671,15 +672,15 @@ div.yes-no .btn-group label {
padding-top:10px;
padding-left:28px;
}

.ls-answers.table > tbody + tbody {
border-top: none; /*overriding Bootstrap */
}

.help-block:last-child{
margin-bottom:0;
}

.ls-questionhelp,
.help-block{
font-size:90%;
Expand Down
18 changes: 14 additions & 4 deletions templates/default/scripts/template.js
Expand Up @@ -155,13 +155,23 @@ function addHoverColumn(){
function hideEmptyPart()
{
$(".question-help-container").each(function(){
if($(this).text().trim()==""){/* Only if have only script tag inside */
$(this).hide();
if($(this).text().trim()==""){/* Only if have only script tag inside or empty tag */
$(this).addClass("hidden");
}
});
$(".group-description").each(function(){
if($(this).text().trim()==""){/* Only if have only script tag inside */
$(this).hide();
if($(this).text().trim()==""){/* Only if have only script tag inside or empty tag */
$(this).addClass("hidden");
}
});
$(".question-help-container.hidden").on("html:updated",function(){
if($(this).text().trim()!=""){
$(this).removeClass("hidden");
}
});
$(".question-help-container").on("html:updated",function(){ // .question-help-container:not(.hidden) don't work ?
if($(this).text().trim()==""){
$(this).addClass("hidden");
}
});
}
Expand Down
1 change: 1 addition & 0 deletions templates/default/views/endpage.pstpl
Expand Up @@ -23,5 +23,6 @@
sliderSuffixClone();
fixBodyPadding();
hideQuestionWithRelevanceSubQuestion();
hideEmptyPart();
/*]]>*/
</script>

8 comments on commit db0dc89

@olleharstedt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LouisGac @Shnoulle Hi Denis, we're having some problems with this commit and auto-calculation/type joggling things.

@Shnoulle
Copy link
Collaborator Author

@Shnoulle Shnoulle commented on db0dc89 May 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have near same issue before this commit, no ?

And need a lss file ;)

@olleharstedt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, don't know, Louis was the one working on it. If you're available on Monday you can ask him.

@Shnoulle
Copy link
Collaborator Author

@Shnoulle Shnoulle commented on db0dc89 May 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently : if there are an empty help at start, updated by Expression Manager after ready : there are joggling … (for example : subquestion validation text : {if(is_empty(self.NAOK),"","You enter something")}
But if help content are fixed : i don't think there are joggling …

And more : i move hideEmptyPart function inside HTML : happen before document is ready. I think all of this are moved to ready … after

It's what happen when i fix this issue . But still : need a simple lss example file …

But i think all of this can be broken now : all javascript and html part are updated after i work on it …

@LouisGac
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed it's a Markus bug, that's why I didn't want to ping you before I was sure...

@Shnoulle
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved function to ready / pjax ? Maybe we can add ls-hidden with some {{ processString(strip_tag(EXPRESSION),1) }} (1 for static)

@LouisGac
Copy link
Contributor

@LouisGac LouisGac commented on db0dc89 May 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no it's about changes he did in LEMVal that was too much strong typed. So it blocked the calculation of equation when not set to "number only" (which is a correct behavior indeed... but people expects their calculation that worked in 2.x to work in 3.x )

@Shnoulle
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a lot of issue about this. I'm against at start to compare code as number if it's number … some year ago before you work on LimeSurvey.

If you look on history : on

$bNumericArg1 = !$arg1[0] || strval(floatval($arg1[0])) == strval($arg1[0]);
some year ago : we test if $arg1[2] == "NUMBER" and put only isnumeric if it's the case …

Please sign in to comment.