LS3.x and javascript

More
1 week 6 days ago - 1 week 6 days 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
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):
$(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:
function imgzoom (){
if($('.minimized')[0]) {
    $('.minimized').attr('class','minimized2');
<...>
}};
setInterval( imgzoom, 3000 );
Last edit: 1 week 6 days ago by vkuzmin.

Please Log in or Create an account to join the conversation.

LimeSurvey Partners
More
1 week 6 days 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.

Cheers,
Gabriel - www.Encuesta.Biz - Authorized Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?)....[img]
The following user(s) said Thank You: DenisChenu

Please Log in or Create an account to join the conversation.

More
1 week 6 days 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.

Please Log in or Create an account to join the conversation.

More
1 week 6 days ago - 1 week 5 days ago #185495 by tpartner
Replied by tpartner on topic LS3.x and javascript
I strongly suggest you disable JavaScript 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.
Official LimeSurvey Partner - partnersurveys.com
Last edit: 1 week 5 days ago by tpartner.

Please Log in or Create an account to join the conversation.

More
1 week 6 days ago #185496 by vkuzmin
Replied by vkuzmin on topic LS3.x and javascript
i've got it, thank you.
$(document).on('ready pjax:scriptcomplete',function() {
 
		setTimeout(function() {
			alert(1);
		},10);
	});

Please Log in or Create an account to join the conversation.

More
1 week 6 days 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

Cheers,
Gabriel - www.Encuesta.Biz - Authorized Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?)....[img]

Please Log in or Create an account to join the conversation.

More
1 week 5 days ago - 1 week 5 days 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.
Official LimeSurvey Partner - partnersurveys.com
Attachments:
Last edit: 1 week 5 days ago by tpartner.
The following user(s) said Thank You: holch

Please Log in or Create an account to join the conversation.

More
1 week 5 days 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'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in or Create an account to join the conversation.

More
1 week 5 days ago #185562 by gabrieljenik
Replied by gabrieljenik on topic LS3.x and javascript
Thanks!

Cheers,
Gabriel - www.Encuesta.Biz - Authorized Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?)....[img]

Please Log in or Create an account to join the conversation.

More
1 week 5 days 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 .
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in or Create an account to join the conversation.

More
1 week 4 days 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
document.getElementById("answerxxxxx").onkeyup();

Survey example:
self.NAOK: {self.NAOK}
<script>
function typeRandomNum () {
  var sgq="{SGQ}";
  document.getElementById("answer"+sgq).value=Math.random();
}
 
  setInterval(typeRandomNum, 1000);
</script>
Attachments:

Please Log in or Create an account to join the conversation.

More
1 week 4 days 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.
Official LimeSurvey Partner - partnersurveys.com

Please Log in or Create an account to join the conversation.

More
1 week 4 days ago #185591 by vkuzmin
Replied by vkuzmin on topic LS3.x and javascript
in that example input field was changed by js but self.NAOK wasnt changed. Sometimes it is necessary for Limesurvey and LEM* to know that the input field has been changed.

Please Log in or Create an account to join the conversation.

More
1 week 4 days ago #185593 by DenisChenu
Replied by DenisChenu on topic LS3.x and javascript
Replace
document.getElementById("answer"+sgq).value=Math.random();
by
$("#answer"+sgq).val(Math.random()).trigger("keyup");

Jquery is here to help you

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand .
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in or Create an account to join the conversation.

More
1 week 4 days ago #185594 by vkuzmin
Replied by vkuzmin on topic LS3.x and javascript
$("#answer"+sgq).val(Math.random()).trigger("keyup");
Thank you, it works!
As i said early in LS2 I've used document.getElementById("answerxxxxx").onkeyup(); but in LS3 it wont work

All issues are solved now.

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!