Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:

THEMA: Adding custom javascript file

Adding custom javascript file 5 Monate 4 Wochen her #104125

  • rvas
  • rvass Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 7
  • Dank erhalten: 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!
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Folgende Benutzer bedankten sich: Ben_V

Adding custom javascript file 5 Monate 4 Wochen her #104126

  • Ben_V
  • Ben_Vs Avatar
  • OFFLINE
  • Platinum Lime
  • Beiträge: 1061
  • Dank erhalten: 234
  • Karma: 74
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...
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Folgende Benutzer bedankten sich: rvas

Adding custom javascript file 5 Monate 4 Wochen her #104128

  • rvas
  • rvass Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 7
  • Dank erhalten: 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?
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Adding custom javascript file 5 Monate 4 Wochen her #104130

  • Ben_V
  • Ben_Vs Avatar
  • OFFLINE
  • Platinum Lime
  • Beiträge: 1061
  • Dank erhalten: 234
  • Karma: 74
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...
Letzte Änderung: 5 Monate 4 Wochen her von Ben_V.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Folgende Benutzer bedankten sich: rvas

Adding custom javascript file 5 Monate 4 Wochen her #104132

  • rvas
  • rvass Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 7
  • Dank erhalten: 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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Adding custom javascript file 5 Monate 4 Wochen her #104133

  • Ben_V
  • Ben_Vs Avatar
  • OFFLINE
  • Platinum Lime
  • Beiträge: 1061
  • Dank erhalten: 234
  • Karma: 74
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...
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Adding custom javascript file 5 Monate 4 Wochen her #104149

  • DenisChenu
  • DenisChenus Avatar
  • OFFLINE
  • Moderator Lime
  • Beiträge: 6207
  • Dank erhalten: 788
  • Karma: 238
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
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Moderatoren: ITEd
Ladezeit der Seite: 0.256 Sekunden
Donation Image