Welcome, Guest
Username: Password: Remember me

TOPIC: Adding custom javascript file

Adding custom javascript file 10 months 9 hours ago #104125

  • rvas
  • rvas's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Thank you received: 1
  • Karma: 1
Hi all,

I would like to add auto-hyphenation to matrix questions so that the text stays in the right place when displayed on small resolution devices such as older mobile phones. I am thinking of using Hypher (github.com/bramstein/hypher), but I need to include <script src="jquery.hypher.js"></script> in the page-headers where matrix questions are to be displayed. Do you have any ideas what would be the least intrusive way to implement this, without risking of breaking the survey?

Also, I have added custom made javascript code in several questions that seem to work fine. I haven't disabled XSS, contrary to what the manual suggests; do you think there will there be any unpredicted problems if I leave XSS on while using custom JS inside some questions?

Thanks in advance!
The administrator has disabled public write access.
The following user(s) said Thank You: Ben_V

Adding custom javascript file 10 months 8 hours ago #104126

  • Ben_V
  • Ben_V's Avatar
  • OFFLINE
  • Platinum Lime
  • Posts: 1151
  • Thank you received: 274
  • Karma: 79
Hi,

1) inside templates files:
the better place is probably inside the startpage.pstpl file of your template or endpage.psptl if all functions are working correctly.

An option is to place your link inside question.pstpl file to avoid unnecesary extra resource download in all pages (welcome, completed, assessment etc. )

2) inside the survey
If it's only for matrix question, another approach is to paste your link into the source of the group description, when this group contains a matrix question. The advantage is that if you change the template, you don't have to remember this adaptation... ( obviously your hypher.js file have to belong to the application script folder and not to the template)
.
Benoît

goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
The administrator has disabled public write access.
The following user(s) said Thank You: rvas

Adding custom javascript file 10 months 6 hours ago #104128

  • rvas
  • rvas's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Thank you received: 1
  • Karma: 1
Thank you for your very quick response!

I faced problems trying to put the code in the question group description, so I finally decided to place a modified code in template.js inside the ready function and detect via jquery if <th> tag is present before dynamically loading the necessary hyphen js files. It seems to work perfect. Below is the actual code in case anyone finds this useful:
$(document).ready(function(){
	if ($('th').length){
		$.getScript( "/survey/scripts/jquery.hypher.js" )
			.done(function() {
				$.getScript( "/survey/scripts/en-us.js" )
					.done(function() {
						$('th').hyphenate('en-us');
					})
			})
	}
})

A last question, what is the correct tag to point to the scripts folder instead of hard-coding it? For example, I know that the active template folder is displayed using {TEMPLATEURL}, but what about scripts url?
The administrator has disabled public write access.

Adding custom javascript file 10 months 5 hours ago #104130

  • Ben_V
  • Ben_V's Avatar
  • OFFLINE
  • Platinum Lime
  • Posts: 1151
  • Thank you received: 274
  • Karma: 79
Thanks for sharing your script; it sounds like a good solution ;)

For your last question, I think that this placeholder does not exist...

Note:
1) Some {KEYWORDS} are working only if placed in particulary files (see details in the doc: Roadmap)
2) An existing Jquery folder is available in the scripts/folder. It's the proper place for jquery plugins.
3) there is no problem in hard-coding a custom template (upload/templates) because they won't be affected when updating the software.
Benoît

goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
Last Edit: 10 months 5 hours ago by Ben_V.
The administrator has disabled public write access.
The following user(s) said Thank You: rvas

Adding custom javascript file 10 months 4 hours ago #104132

  • rvas
  • rvas's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Thank you received: 1
  • Karma: 1
I'll leave it as is then, many thanks!

Regarding the XSS protection, is this option only supposed to protect against malicious survey operators or if disabled leaves the survey unprotected against respondents who can place malicious code inside comments and text forms? In my case, I use JS in several questions, but everything seem to work regardless whether this option is on or off. My survey will be open to the web so I want to make sure that I have taken the maximum precautions.
The administrator has disabled public write access.

Adding custom javascript file 10 months 3 hours ago #104133

  • Ben_V
  • Ben_V's Avatar
  • OFFLINE
  • Platinum Lime
  • Posts: 1151
  • Thank you received: 274
  • Karma: 79
Good question...I'm not sure if it changes seriously the security level of text questions. May someone else answer this point.

I personnally used to:

1) Use captcha to take the survey; (I experienced some problems before, but nothing since I use it: my surveys stop to be strangely popular in Nigeria or Philippines :unsure: )

2) Set restrictive validation for all text fields (max. number of characters)

3) Install LS in a subdomain with dedicated robots.txt and .htaccess files (Apache server); If you can, it's better to avoid web-crawlers indexation.
Benoît

goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
The administrator has disabled public write access.

Adding custom javascript file 9 months 4 weeks ago #104149

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6551
  • Thank you received: 869
  • Karma: 257
Hi,

If it's only for modern browser, why not use something like that:
-webkit-hyphens: auto;
   -moz-hyphens: auto;
        hyphens: auto;
www.w3.org/TR/2011/WD-css3-text-20110412/#hyphens ?

Denis
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.227 seconds
Donation Image