Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * LimeSurvey
- * Copyright (C) 2007 The LimeSurvey Project Team / Carsten Schmitz
- * All rights reserved.
- * License: GNU/GPL License v2 or later, see LICENSE.php
- * LimeSurvey is free software. This version may have been modified pursuant
- * to the GNU General Public License, and as distributed it includes or
- * is derivative of works licensed under the GNU General Public License or
- * other free or open source software licenses.
- * See COPYRIGHT.php for copyright notices and details.
- *
- *
- * Description: Javascript file for templates. Put JS-functions for your template here.
- *
- *
- * $Id:$
- */
- /*
- * The function focusFirst puts the Focus on the first non-hidden element in the Survey.
- *
- * Normally this is the first input field (the first answer).
- */
- function focusFirst(Event)
- {
- $('#limesurvey :input:visible:enabled:first').focus();
- }
- /*
- * The focusFirst function is added to the eventlistener, when the page is loaded.
- *
- * This can be used to start other functions on pageload as well. Just put it inside the 'ready' function block
- */
- /* Uncomment below if you want to use the focusFirst function */
- /*
- $(document).ready(function(){
- focusFirst();
- });
- */
- function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
- {
- var arVersion = navigator.appVersion.split("MSIE")
- var version = parseFloat(arVersion[1])
- if ((version >= 5.5) && (version<7) && (document.body.filters))
- {
- for(var i=0; i<document.images.length; i++)
- {
- var img = document.images[i]
- var imgName = img.src.toUpperCase()
- if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
- {
- var imgID = (img.id) ? "id='" + img.id + "' " : "";
- var imgClass = (img.className) ? "class='" + img.className + "' " : "";
- var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
- var imgStyle = "display:inline-block;" + img.style.cssText;
- if (img.align == "left") imgStyle = "float:left;" + imgStyle;
- if (img.align == "right") imgStyle = "float:right;" + imgStyle;
- if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
- var strNewHTML = "<span " + imgID + imgClass + imgTitle
- + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
- + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
- + "(src='" + img.src + "', sizingMethod='scale');\"></span>"
- img.outerHTML = strNewHTML
- i = i-1
- }
- }
- }
- }
- $(document).ready(function() {
- // A function to add or remove rows of an Array (Multi Flexible)(Text) question
- function varLengthArray(qID) {
- /* from http://docs.limesurvey.org/tiki-index.php?page=Workarounds%3A+Manipulating+a+survey+at+runtime+using+Javascript&structure=English+Instructions+for+LimeSurvey#Variable_Length_Array_Multi_Flexible_Text_question
- */
- if ($('#question'+qID+'').length > 0) {
- // The HTML content of the Add/Remove elements - modify as you wish
- var addContent = 'Add another organization [+]';
- var removeContent = 'Remove last row [-]';
- // Create the Add and Remove elements & insert them
- var el1 = document.createElement('div');
- el1.setAttribute('id','addButton'+qID);
- document.body.appendChild(el1);
- var el2 = document.createElement('div');
- el2.setAttribute('id','removeButton'+qID);
- document.body.appendChild(el2);
- // Move them to after the array
- $( 'div#addButton'+qID ).appendTo($( '#question' + qID + ' table.question' ).parent());
- $( 'div#removeButton'+qID ).appendTo($( '#question' + qID + ' table.question' ).parent());
- // Insert their HTML
- $( 'div#addButton'+qID ).html( addContent );
- $( 'div#removeButton'+qID ).html( removeContent );
- // Style the elements - you can modify here if you wish
- $( 'div#addButton'+qID ).css({
- 'margin':'10px 0 0 10px',
- 'padding':'1px',
- 'text-align':'center',
- 'font-weight':'bold',
- 'width':'auto',
- 'cursor':'pointer',
- 'float':'left'
- });
- $( 'div#removeButton'+qID ).css({
- 'margin':'10px 0 0 10px',
- 'padding':'1px',
- 'text-align':'center',
- 'font-weight':'bold',
- 'width':'auto',
- 'cursor':'pointer',
- 'float':'left'
- });
- // Initially hide the Remove element
- $( 'div#removeButton'+qID ).hide();
- // Call the functions below when clicked
- $( 'div#addButton'+qID ).click(function (event) {
- addRow(qID);
- });
- $( 'div#removeButton'+qID ).click(function (event) {
- removeRow(qID);
- });
- // Function to add a row, also shows the Remove element and hides the
- //Add element if all rows are shown
- function addRow(qID) {
- var arrayRow = '#question' + qID + ' table.question tbody';
- var rowCount = $( arrayRow ).size() - 1;
- $( arrayRow + '[name="hidden"]:first' ).attr('name', 'visible').show();
- $( 'div#removeButton'+qID ).show();
- if ( $( arrayRow + ':eq(' + rowCount + ')' ).attr('name') == 'visible' ) {
- $( 'div#addButton'+qID ).hide();
- }
- }
- // Function to remove a row, also clears the contents of the removed row,
- // shows the Add element if the last row is hidden and hides the Remove
- // element if only the first row is shown
- function removeRow(qID) {
- var arrayRow = '#question' + qID + ' table.question tbody';
- var rowCount = $( arrayRow ).size() - 1;
- $( arrayRow + '[name="visible"]:last input[type="text"]' ).val('');
- $( arrayRow + '[name="visible"]:last' ).attr('name', 'hidden').hide();
- $( 'div#addButton'+qID ).show();
- if ( $( arrayRow + ':eq(1)' ).attr('name') == 'hidden' ) {
- $( 'div#removeButton'+qID ).hide();
- }
- }
- // Just some initialization stuff
- var arrayRow = '#question' + qID + ' table.question tbody';
- var rowCount = '';
- // Initially hide all except first row or any rows with populated inputs
- $( arrayRow ).each(function(i) {
- if ( i > 0 ) {
- // We also need to give the hidden rows a name cause IE doesn't
- // recognize jQuery :visible selector consistently
- $( this ).attr('name', 'hidden').hide();
- $('input[type=text]', this).each(function(i) {
- if ($(this).attr('value') != '') {
- $(this).parents('tbody:eq(0)').attr('name', 'visible').show();
- $( 'div#removeButton'+qID ).show();
- }
- });
- rowCount = i;
- }
- });
- }
- }
- // Call the function with a question ID
- varLengthArray(Associations);
- });
- $(document).ready(function(){
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement