Advertisement
Guest User

sartan_template.js_file

a guest
Sep 5th, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * LimeSurvey
  3.  * Copyright (C) 2007 The LimeSurvey Project Team / Carsten Schmitz
  4.  * All rights reserved.
  5.  * License: GNU/GPL License v2 or later, see LICENSE.php
  6.  * LimeSurvey is free software. This version may have been modified pursuant
  7.  * to the GNU General Public License, and as distributed it includes or
  8.  * is derivative of works licensed under the GNU General Public License or
  9.  * other free or open source software licenses.
  10.  * See COPYRIGHT.php for copyright notices and details.
  11.  *
  12.  *
  13.  * Description: Javascript file for templates. Put JS-functions for your template here.
  14.  *  
  15.  *
  16.  * $Id:$
  17.  */
  18.  
  19.  
  20. /*
  21.  * The function focusFirst puts the Focus on the first non-hidden element in the Survey.
  22.  *
  23.  * Normally this is the first input field (the first answer).
  24.  */
  25. function focusFirst(Event)
  26. {
  27.     $('#limesurvey :input:visible:enabled:first').focus();
  28. }
  29. /*
  30.  * The focusFirst function is added to the eventlistener, when the page is loaded.
  31.  *
  32.  * This can be used to start other functions on pageload as well. Just put it inside the 'ready' function block
  33.  */
  34.  
  35. /* Uncomment below if you want to use the focusFirst function */
  36. /*
  37. $(document).ready(function(){
  38.     focusFirst();
  39. });
  40. */
  41.  
  42.  
  43.  
  44. function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
  45. {
  46.    var arVersion = navigator.appVersion.split("MSIE")
  47.    var version = parseFloat(arVersion[1])
  48.    if ((version >= 5.5) && (version<7) && (document.body.filters))
  49.    {
  50.       for(var i=0; i<document.images.length; i++)
  51.       {
  52.          var img = document.images[i]
  53.          var imgName = img.src.toUpperCase()
  54.          if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
  55.          {
  56.             var imgID = (img.id) ? "id='" + img.id + "' " : "";
  57.             var imgClass = (img.className) ? "class='" + img.className + "' " : "";
  58.             var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
  59.             var imgStyle = "display:inline-block;" + img.style.cssText;
  60.             if (img.align == "left") imgStyle = "float:left;" + imgStyle;
  61.             if (img.align == "right") imgStyle = "float:right;" + imgStyle;
  62.             if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
  63.             var strNewHTML = "<span " + imgID + imgClass + imgTitle
  64.             + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
  65.             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
  66.             + "(src='" + img.src + "', sizingMethod='scale');\"></span>"
  67.             img.outerHTML = strNewHTML
  68.             i = i-1
  69.          }
  70.       }
  71.    }    
  72. }
  73.  
  74.  
  75. $(document).ready(function() {
  76.  
  77.         // A function to add or remove rows of an Array (Multi Flexible)(Text) question
  78.         function varLengthArray(qID) {
  79.       /* 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
  80.       */
  81.      
  82.             if ($('#question'+qID+'').length > 0) {
  83.            
  84.                 // The HTML content of the Add/Remove elements - modify as you wish
  85.                 var addContent = 'Add another organization [+]';
  86.                 var removeContent = 'Remove last row [-]';
  87.                
  88.                 // Create the Add and Remove elements & insert them
  89.                 var el1 = document.createElement('div');
  90.                 el1.setAttribute('id','addButton'+qID);
  91.                 document.body.appendChild(el1);
  92.                 var el2 = document.createElement('div');
  93.                 el2.setAttribute('id','removeButton'+qID);
  94.                 document.body.appendChild(el2);
  95.                 // Move them to after the array
  96.                 $( 'div#addButton'+qID ).appendTo($( '#question' + qID + ' table.question' ).parent());
  97.                 $( 'div#removeButton'+qID ).appendTo($( '#question' + qID + ' table.question' ).parent());
  98.                 // Insert their HTML
  99.                 $( 'div#addButton'+qID ).html( addContent );
  100.                 $( 'div#removeButton'+qID ).html( removeContent );
  101.                 // Style the elements - you can modify here if you wish
  102.                 $( 'div#addButton'+qID ).css({
  103.                     'margin':'10px 0 0 10px',
  104.                     'padding':'1px',
  105.                     'text-align':'center',
  106.                     'font-weight':'bold',
  107.                     'width':'auto',
  108.                     'cursor':'pointer',
  109.                     'float':'left'
  110.                 });
  111.                 $( 'div#removeButton'+qID ).css({
  112.                     'margin':'10px 0 0 10px',
  113.                     'padding':'1px',
  114.                     'text-align':'center',
  115.                     'font-weight':'bold',
  116.                     'width':'auto',
  117.                     'cursor':'pointer',
  118.                     'float':'left'
  119.                 });
  120.                
  121.                 // Initially hide the Remove element
  122.                 $( 'div#removeButton'+qID ).hide();
  123.                
  124.                 // Call the functions below when clicked
  125.                 $( 'div#addButton'+qID ).click(function (event) {
  126.                     addRow(qID);
  127.                 });
  128.                 $( 'div#removeButton'+qID ).click(function (event) {
  129.                     removeRow(qID);
  130.                 });
  131.                
  132.                 // Function to add a row, also shows the Remove element and hides the
  133.                 //Add element if all rows are shown
  134.                 function addRow(qID) {
  135.                     var arrayRow = '#question' + qID + ' table.question tbody';
  136.                     var rowCount = $( arrayRow ).size() - 1;
  137.                     $( arrayRow + '[name="hidden"]:first' ).attr('name', 'visible').show();
  138.                     $( 'div#removeButton'+qID ).show();
  139.                     if ( $( arrayRow + ':eq(' + rowCount + ')' ).attr('name') == 'visible' )  {
  140.                         $( 'div#addButton'+qID ).hide();
  141.                     }
  142.                 }
  143.                 // Function to remove a row, also clears the contents of the removed row,
  144.                 // shows the Add element if the last row is hidden and hides the Remove
  145.                 // element if only the first row is shown
  146.                 function removeRow(qID) {
  147.                     var arrayRow = '#question' + qID + ' table.question tbody';
  148.                     var rowCount = $( arrayRow ).size() - 1;
  149.                     $( arrayRow + '[name="visible"]:last input[type="text"]' ).val('');
  150.                     $( arrayRow + '[name="visible"]:last' ).attr('name', 'hidden').hide();
  151.                     $( 'div#addButton'+qID ).show();
  152.                     if ( $( arrayRow + ':eq(1)' ).attr('name') == 'hidden' )  {
  153.                         $( 'div#removeButton'+qID ).hide();
  154.                     }
  155.                 }
  156.                
  157.                 // Just some initialization stuff
  158.                 var arrayRow = '#question' + qID + ' table.question tbody';
  159.                 var rowCount = '';
  160.                
  161.                 // Initially hide all except first row or any rows with populated inputs
  162.                 $( arrayRow ).each(function(i) {
  163.                     if ( i > 0 ) {
  164.                         // We also need to give the hidden rows a name cause IE doesn't
  165.                         // recognize jQuery :visible selector consistently
  166.                         $( this ).attr('name', 'hidden').hide();
  167.                         $('input[type=text]', this).each(function(i) {
  168.                             if ($(this).attr('value') != '') {
  169.                                 $(this).parents('tbody:eq(0)').attr('name', 'visible').show();
  170.                                 $( 'div#removeButton'+qID ).show();
  171.                             }
  172.                         });
  173.                         rowCount = i;
  174.                     }
  175.                 });
  176.             }
  177.         }
  178.        
  179.         // Call the function with a question ID
  180.         varLengthArray(Associations);
  181.     });
  182. $(document).ready(function(){
  183.  
  184. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement