Guest User

Untitled

a guest
Oct 16th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 KB | None | 0 0
  1. /**********************************************************/
  2. /********************** Instructions **********************/
  3. /***********************************************************
  4.  
  5. This set of snippets connects two heatmap questions together
  6. by placing one on top of the other, and then swapping the
  7. stacking order depending on if a certain area of the current
  8. image is clicked. My prototype's full menu button is in the
  9. upper left hand corner of the screen, which makes this easy.
  10. If you need to do something with another spot on the page,
  11. that's possible, you'll just need to do some extra math.
  12.  
  13. It's intended to answer questions like "Where would you go
  14. to find information on purchasing a new car?" in a situation
  15. where you have a mega navigation in your design, and want to
  16. find out if people are able to understand that menu is how
  17. you get to information.
  18.  
  19. Your heatmap questions should be the only two questions on
  20. the page, and they should also be named the same/have the
  21. same question. Once you're done, you can look at the heatmap
  22. for your prototype's first state (in my case, nav not open)
  23. as well as the second state (in my case, nav open) and see
  24. where people end up.
  25.  
  26. This will also set two pieces of embedded data to
  27. your first question - whether the final state was open or
  28. closed when the person answered the question, and the total
  29. number of times the menu was open or closed. This is handy
  30. information to have as you can see if people bounced back
  31. and forth between the two states before settling on a final
  32. answer.
  33.  
  34. These are the keys:
  35.  
  36. megaNavFinalState
  37. megaNavTotalTimesOpened
  38.  
  39. You'll need to change the QIDs to match your own questions.
  40.  
  41. ***********************************************************/
  42.  
  43. /**********************************************************/
  44. /********************** Question One **********************/
  45. /*********************** Javascript ***********************/
  46. /**********************************************************/
  47.  
  48. // Global variables for all questions on this page.
  49.  
  50. var initNavWidth = 1630,
  51. initMenuHitWidth = 178,
  52. initMenuHitHeight = 123,
  53. currentMenuWidth = 0,
  54. currentMenuHeight = 0,
  55. menuOpenCount = 0,
  56. finalStateClosed = true;
  57.  
  58. // Gets the offset relative to the current layer for browser compatibility reasons.
  59. // This is important because we want the offset relative to our hotspot image.
  60.  
  61. function getOffset(evt) {
  62. var el = evt.target,
  63. x = 0,
  64. y = 0;
  65.  
  66. while (el && !isNaN(el.offsetLeft) && !isNaN(el.offsetTop)) {
  67. x += el.offsetLeft - el.scrollLeft;
  68. y += el.offsetTop - el.scrollTop;
  69. el = el.offsetParent;
  70. }
  71.  
  72. x = evt.clientX - x;
  73. y = evt.clientY - y;
  74.  
  75. return { x: x, y: y };
  76. }
  77.  
  78. Qualtrics.SurveyEngine.addOnload(function()
  79. {
  80. // Position questions so they overlap.
  81. jQuery('#QID1').css({
  82. "position": "relative",
  83. "top": "0",
  84. "left": "0",
  85. "z-index": "2"
  86. });
  87.  
  88. jQuery('#QID2').css({
  89. "position": "absolute",
  90. "top": "0",
  91. "left": "0",
  92. "z-index": "1"
  93. });
  94.  
  95. var that = this;
  96.  
  97. this.questionclick = function(event,element){
  98. var imageWidth = element.width,
  99. scaleFactor = imageWidth / initNavWidth,
  100. offsetRelativeToClickedLayer = getOffset(event);
  101.  
  102. currentMenuWidth = initMenuHitWidth * scaleFactor;
  103. currentMenuHeight = initMenuHitHeight * scaleFactor;
  104.  
  105. // If in the menu hit area, "open" the menu by placing the menu question on top.
  106. if ( offsetRelativeToClickedLayer.x <= currentMenuWidth && offsetRelativeToClickedLayer.y <= currentMenuHeight ) {
  107. jQuery('#QID2').css({
  108. "z-index": "2"
  109. });
  110.  
  111. finalStateClosed = true;
  112. menuOpenCount++;
  113. }
  114. }
  115. });
  116.  
  117. // Sets embedded data for the final state and total times opened
  118. // when moving to the next question.
  119. Qualtrics.SurveyEngine.addOnPageSubmit(function(type) {
  120. if(type == "next") {
  121. Qualtrics.SurveyEngine.setEmbeddedData( 'megaNavFinalState', finalStateClosed );
  122. Qualtrics.SurveyEngine.setEmbeddedData( 'megaNavTotalTimesOpened', menuOpenCount );
  123. }
  124. });
  125.  
  126. /**********************************************************/
  127. /********************** Question Two **********************/
  128. /*********************** Javascript ***********************/
  129. /**********************************************************/
  130.  
  131. Qualtrics.SurveyEngine.addOnload(function()
  132. {
  133. var that = this;
  134.  
  135. this.questionclick = function(event,element){
  136. var imageWidth = element.width,
  137. scaleFactor = imageWidth / initNavWidth,
  138. offsetRelativeToClickedLayer = getOffset(event);
  139.  
  140. currentMenuWidth = initMenuHitWidth * scaleFactor;
  141. currentMenuHeight = initMenuHitHeight * scaleFactor;
  142.  
  143. // If in the menu close area, "close" the menu by placing the first question on top.
  144. // Not in yet but maybe worth considering: should a click outside the menu close it?
  145. if ( offsetRelativeToClickedLayer.x <= currentMenuWidth && offsetRelativeToClickedLayer.y <= currentMenuHeight ) {
  146. jQuery('#QID2').css({
  147. "z-index": "1"
  148. });
  149.  
  150. finalStateClosed = true;
  151. }
  152. }
  153. });
Add Comment
Please, Sign In to add comment