Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

LS3.x and javascript

  • vkuzmin
  • vkuzmin's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
4 years 9 months ago - 4 years 9 months ago #185489 by vkuzmin
LS3.x and javascript was created by vkuzmin
I have impermanent issues with standalone JS scripts that do something with with question text or answers.

1. In LS2 i can fire
Code:
document.getElementById("answerxxxxx").onkeyup();
to let limesurvey and LEM* scripts know that answer field was changed. How i can do this in LS3?

2. Scripts that i've added to the custom.js or even footer.twig dont work with question text. It work only when i hit F5 and stop working again on the next page. How i should launch them properly? I mean in LS3 you will see exact same page whole time and by default any scripts will try to activate only once on the 1st question instead of every question.

Example of the script (image preview by perfkirill.ru):
Code:
$(function(){
  $('.minimized').click(function(event) {
    var i_path = $(this).attr('src');
    $('body').append('<div id="overlay"></div><div id="magnify"><img src="'+i_path+'"><div id="close-popup"><i></i></div></div>');
    $('#magnify').css({
    left: ($(document).width() - $('#magnify').outerWidth())/2,
    // top: ($(document).height() - $('#magnify').outerHeight())/2 upd: 24.10.2016
            top: ($(window).height() - $('#magnify').outerHeight())/2
  });
    $('#overlay, #magnify').fadeIn('fast');
  });
 
  $('body').on('click', '#close-popup, #overlay', function(event) {
    event.preventDefault();
 
    $('#overlay, #magnify').fadeOut('fast', function() {
      $('#close-popup, #magnify, #overlay').remove();
    });
  });
});

My current (bad) solution:
run scripts every n seconds:
Code:
function imgzoom (){
if($('.minimized')[0]) {
    $('.minimized').attr('class','minimized2');
<...>
}};
setInterval( imgzoom, 3000 );
Last edit: 4 years 9 months ago by vkuzmin.
The topic has been locked.
  • gabrieljenik
  • gabrieljenik's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
4 years 9 months ago #185493 by gabrieljenik
Replied by gabrieljenik on topic LS3.x and javascript
You are using document.ready event. That's why it only works with F5 or Refresh. Either disable pjax on the template or trigger the script on pjax:ready as well.

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Checkout our Reporting Solutions and our plugin shop at www.encuesta.biz .

The following user(s) said Thank You: DenisChenu
The topic has been locked.
  • vkuzmin
  • vkuzmin's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
4 years 9 months ago #185494 by vkuzmin
Replied by vkuzmin on topic LS3.x and javascript
MAy you make example of using "pjax:ready" ? alert(1) for exampe. Thank you.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 9 months ago - 4 years 9 months ago #185495 by tpartner
Replied by tpartner on topic LS3.x and javascript
I strongly suggest you disable [strike]JavaScript[/strike] AJAX but searching the forum for "pjax" should yield many examples.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 9 months ago by tpartner.
The topic has been locked.
  • vkuzmin
  • vkuzmin's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
4 years 9 months ago #185496 by vkuzmin
Replied by vkuzmin on topic LS3.x and javascript
i've got it, thank you.
Code:
$(document).on('ready pjax:scriptcomplete',function() {
 
    setTimeout(function() {
      alert(1);
    },10);
  });
The topic has been locked.
  • gabrieljenik
  • gabrieljenik's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
4 years 9 months ago #185504 by gabrieljenik
Replied by gabrieljenik on topic LS3.x and javascript
Hi, I am just curious. What do you mean by disabling JS? Thanks

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Checkout our Reporting Solutions and our plugin shop at www.encuesta.biz .

The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 9 months ago - 4 years 9 months ago #185523 by tpartner
Replied by tpartner on topic LS3.x and javascript
Sorry, "disable JavaScript" was a typo, I meant AJAX.

I always disable AJAX in the survey theme options. In my custom themes, I do not include it at all.

In my opinion, the benefits of very slightly faster page loading are not worth the problems I have encountered (and seen in the forums) while AJAX is enabled.


Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 9 months ago by tpartner.
The following user(s) said Thank You: holch
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 9 months ago #185553 by holch
Replied by holch on topic LS3.x and javascript

In my opinion, the benefits of very slightly faster page loading are not worth the problems I have encountered (and seen in the forums) while AJAX is enabled.

Agreed. I would suggest to have AJAX mode disabled by default and it can be switched on as an option. But I would also mark it as "experimental", but that is what it is.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • gabrieljenik
  • gabrieljenik's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
4 years 9 months ago #185562 by gabrieljenik
Replied by gabrieljenik on topic LS3.x and javascript
Thanks!

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Checkout our Reporting Solutions and our plugin shop at www.encuesta.biz .

The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 9 months ago #185573 by DenisChenu
Replied by DenisChenu on topic LS3.x and javascript
I think it was disabled by default , but not the case : github.com/LimeSurvey/LimeSurvey/blob/38...nilla/config.xml#L68

Issue is still open : bugs.limesurvey.org/view.php?id=14616

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • vkuzmin
  • vkuzmin's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
4 years 9 months ago #185588 by vkuzmin
Replied by vkuzmin on topic LS3.x and javascript
May someone help with 1st part of the question?
How i can let limesurvey and LEM* scripts know that answer field was changed.
1. In LS2 i can fire
Code:
document.getElementById("answerxxxxx").onkeyup();

Survey example:
Code:
self.NAOK: {self.NAOK}
<script>
function typeRandomNum () {
  var sgq="{SGQ}";
  document.getElementById("answer"+sgq).value=Math.random();
}
 
  setInterval(typeRandomNum, 1000);
</script>
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 9 months ago #185589 by tpartner
Replied by tpartner on topic LS3.x and javascript
I don't understand the question. You say you want to know when an input is changed but then you provide a script that changes an input.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose