1/** 2 * @file 3 * 4 * javascript to cause a popup to appear to invite the user to take a survey 5 */ 6 7var wcmSurveyPopupProcessed = false; 8var wcmSurveyBypassSurvey = false; 9var wcmSurveyPlacedInFooter = false; 10 11(function ($) { 12 13 /** 14 * Log to the console. 15 */ 16 function log(variable, label) { 17 if (typeof drupalSettings.wcmSurvey === 'undefined' || 18 typeof drupalSettings.wcmSurvey.debugMode === 'undefined' || 19 !drupalSettings.wcmSurvey.debugMode) { 20 return; 21 } 22 if (typeof console !== 'undefined' && 23 typeof console.log !== 'undefined') { 24 if (typeof label !== 'undefined') { 25 console.log(label + ' =>'); 26 } 27 console.log(variable); 28 } 29 return; 30 } 31 32 /** 33 * place the survey markup in the footer 34 */ 35 function wcmSurveyPlaceInFooter() { 36 if (wcmSurveyPlacedInFooter) { 37 // this only needs to be done once 38 return; 39 } 40 // put the survey text in the footer, but hidden 41 $('body').append("<a style='position: fixed; top: 0px;' id='wcm-survey-target-id'></a>" + drupalSettings.wcmSurvey.surveyPopup); 42 43 wcmSurveyPlacedInFooter = true; 44 return; 45 } 46 47 /** 48 * determine if a survey invite needs to be popped up and pop it up if necessary 49 */ 50 function wcmSurveyProcess() { 51 log('place in footer'); 52 wcmSurveyPlaceInFooter(); 53 $.cookie.raw = true; 54 var ua = window.navigator.userAgent; // + added by Stephen Mustgrave 55 var msie = ua.indexOf("MSIE"); // + added by Stephen Mustgrave 56 if (wcmSurveyPopupProcessed) { 57 // the survey has already been processed for this page load 58 return false; 59 } else { 60 // prevent the survey from being processed multiple times per page load 61 wcmSurveyPopupProcessed = true; 62 log('wcmSurveyPopupProcessed = true;'); 63 } 64 if ( 65 //The following lines were edited by Stephen Mustgrave 66 window.navigator.userAgent !== 'undefined' && // + first checks that the userAgent variable is not undefined 67 window.navigator.userAgent.indexOf("MSIE") > 0 && // + //if not undefined then get the MSIE index of the userAgent, and if greater than 0 the browser is Internet Explorer 68 parseInt(ua.substring(msie + 5, ua.indexOf(".", msie))) <= 6) // + finally check that the version of internet explorer is greater then 6 69 //.browser method was deprecated in jQuery 1.3 and removed in 1.9, when this module was enabled it was 70 //throwing a TypeError: Cannot read property 'msie' of undefined 71 /* typeof $.browser.msie !== 'undefined' && 72 $.browser.msie && 73 parseInt($.browser.version) <= 6 74 )*/ 75 { 76 // log($.browser.version, 'Wrong IE version'); browser method is deprecated therefore didn't log the version number 77 // we are in Internet Explorer <= 6 which is not currently supported 78 log(parseInt(ua.substring(msie + 5, ua.indexOf(".", msie))), 'Wrong IE version'); 79 return false; 80 } 81 82 if (typeof drupalSettings.wcmSurvey !== 'undefined') { 83 var wcmSurvey = drupalSettings.wcmSurvey; 84 85 // Check to see if we're forcing the survey. 86 var showSurvey = false; 87 if (!drupalSettings.wcmSurvey.force) { 88 // check to see if the cookie has been set to not show the survey again 89 if ($.cookie('wcmSurveyBlockSurvey') && 90 typeof wcmSurvey.surveyRetakeTimeout !== 'undefined' && 91 wcmSurvey.surveyRetakeTimeout > 0) { 92 log('wcmSurveyBlockSurvey exists, so surveys are blocked'); 93 return false; 94 } 95 96 // check to make sure we aren't on the front page 97 log(window.location.pathname, 'window.location.pathname'); 98 if (window.location.pathname !== '/') { 99 // we are not on the front page 100 log('we are not on the front page'); 101 102 // check to see if they have gone the necessary page depth 103 var pageDepth = $.cookie('wcmSurveyPageDepthC', Number, {path: '/'}); 104 105 if (pageDepth === null || isNaN(pageDepth)) { 106 log('pageDepth is empty, so creating it'); 107 pageDepth = 0; 108 } 109 110 // add the current page to the page depth object 111 pageDepth++; 112 113 log(pageDepth, 'pageDepth'); 114 if (pageDepth >= wcmSurvey.pageDepth) { 115 log('User has reached the pageDepth thresh hold of ' + wcmSurvey.pageDepth); 116 // they have reached the necessary page depth for the survey to trigger 117 118 // check to see if they win the survey to be shown to them 119 // var randNumber = Math.floor((Math.random() * 100) + 1); 120 var randNumber = Math.random(); 121 log(randNumber, 'randNumber'); 122 log(wcmSurvey.userPercentage, 'wcmSurvey.userPercentage'); 123 124 // Scale the target by the distance from the trigger, to get diminishing likelihood 125 var twoN = Math.pow(2, pageDepth - wcmSurvey.pageDepth); // 2^(n-1) 126 var x = wcmSurvey.userPercentage / 100.0; 127 var targetPercentage = x / (2.0 * (twoN + x * (1.0 - twoN))); 128 // var targetPercentage = wcmSurvey.userPercentage == 100 ? 100 : wcmSurvey.userPercentage / Math.pow(2, pageDepth - wcmSurvey.pageDepth + 1); 129 log(targetPercentage, 'targetPercentage'); 130 131 if (x == 1 || randNumber <= targetPercentage) { 132 log('the random number fit within the percentage defined by the admin so show the survey'); 133 // the random number fit within the percentage defined by the admin 134 showSurvey = true; 135 } 136 // set the cookie to NOT show the survey again for 137 // wcmSurvey.surveyRetakeTimeout days 138 // Disabled if wcmSurvey.surveyRetakeTimout == 0 139 if (showSurvey && wcmSurvey.surveyRetakeTimeout > 0) { 140 var surveyRetakeTimeout = new Date(); 141 surveyRetakeTimeout.setDate(surveyRetakeTimeout.getDate() + wcmSurvey.surveyRetakeTimeout); 142 $.cookie('wcmSurveyBlockSurvey', true, {expires: surveyRetakeTimeout, path: '/'}); 143 } 144 } else { 145 // they don't get the survey this time... so we will restart the page 146 // depth count 147 // pageDepth = 0; 148 } 149 } 150 151 var expireDate1 = new Date(); 152 expireDate1.setDate(expireDate1.getDate() + 1); 153 $.cookie('wcmSurveyPageDepthC', pageDepth, {expires: expireDate1, path: '/'}); 154 } else { 155 showSurvey = true; 156 } 157 158 if (showSurvey) { 159 let element = $('#wcm-survey-popup'); 160 let settings = { 161 dialogClass: "no-close", 162 closeText: "hide", 163 height: drupalSettings.wcmSurvey.height ? drupalSettings.wcmSurvey.height.replace('px', '')
163: 300, 164 width: drupalSettings.wcmSurvey.width ? drupalSettings.wcmSurvey.width : 500, 165 maxWidth: drupalSettings.wcmSurvey.maxWidth, 166 buttons: [ 167 { 168 text: drupalSettings.wcmSurvey.survey.yeslabel, 169 click: function() { 170 window.open(drupalSettings.wcmSurvey.survey.url, '_blank'); 171 $( this ).dialog( "close" ); 172 } 173 }, 174 { 175 text: drupalSettings.wcmSurvey.survey.nolabel, 176 click: function() { 177 $( this ).dialog( "close" ); 178 } 179 }, 180 ] 181 }; 182 log(settings, 'settings'); 183 let myDialog = Drupal.dialog(element, settings); 184 myDialog.showModal(); 185 186 Drupal.attachBehaviors(); 187 return true; 188 } 189 } 190 return false; 191 } 192 193 Drupal.behaviors.wcmSurvey = { 194 attach: function (context) { 195 wcmSurveyPlaceInFooter(); 196 log(drupalSettings.wcmSurvey); 197 if (typeof drupalSettings.wcmSurvey !== 'undefined' && 198 typeof drupalSettings.wcmSurvey.pageDepth !== 'undefined' && 199 parseInt(drupalSettings.wcmSurvey.pageDepth) > 0) { 200 // we are not waiting until the user exists the site 201 log('wcmSurveyProcess(); line 211'); 202 wcmSurveyProcess(); 203 } 204 205 206 // for links that are on the same domain don't popup survey 207 $('a:not(.survey-processed)') 208 .addClass('survey-processed') 209 .click(function () { 210 var a = document.createElement('a'); 211 a.href = $(this).attr('href'); 212 if (a.hostname == window.location.hostname) { 213 // the user is staying on site and the survey can be bypassed 214 wcmSurveyBypassSurvey = true; 215 } 216 }); 217 218 // for forms don't popup a survey 219 $('form:not(.survey-processed)') 220 .addClass('survey-processed') 221 .submit(function () { 222 var a = document.createElement('a'); 223 a.href = $(this).attr('action'); 224 if (a.hostname == window.location.hostname) { 225 // the user is staying on site and the survey can be bypassed 226 wcmSurveyBypassSurvey = true; 227 } 228 }); 229 } 230 } 231 232 $(document).ready(function () { 233 wcmSurveyPlaceInFooter(); 234 if (typeof drupalSettings.wcmSurvey !== 'undefined' && 235 typeof drupalSettings.wcmSurvey.pageDepth !== 'undefined' && 236 parseInt(drupalSettings.wcmSurvey.pageDepth) == 0) { 237 var pagesLoaded = wcmSurveyPagesLoadedAdd(); 238 239 $(window).bind('beforeunload', function (e) { 240 var pagesLoaded = wcmSurveyPagesLoadedSubtract(); 241 242 if (!wcmSurveyBypassSurvey && 243 pagesLoaded < 1 && 244 wcmSurveyProcess() 245 ) { 246 // all the other pages are closed 247 return '>>>>>' + Drupal.t('Before You Go') + '<<<<<\n\n' + $(drupalSettings.wcmSurvey.survey.body).text() + '\n\n' + Drupal.t('Please stick around and take our survey.'); 248 } 249 // don't stop the page from closing 250 return null 251 }); 252 } 253 }); 254 255 /** 256 * Add another page to the wcmSurveyPagesLoaded cookie 257 */ 258 function wcmSurveyPagesLoadedAdd() { 259 var pagesLoaded = $.cookie('wcmSurveyPagesLoaded'); 260 if (typeof pagesLoaded === 'undefined') { 261 var expireDate1 = new Date(); 262 expireDate1.setDate(expireDate1.getDate() + 1); 263 pagesLoaded = 1; 264 } else { 265 pagesLoaded = parseInt(pagesLoaded) + 1; 266 } 267 $.cookie('wcmSurveyPagesLoaded', pagesLoaded, {expires: expireDate1, path: '/'}); 268 return pagesLoaded; 269 } 270 271 /** 272 * remove a page from the wcmSurveyPagesLoaded cookie 273 */ 274 function wcmSurveyPagesLoadedSubtract() { 275 var pagesLoaded = $.cookie('wcmSurveyPagesLoaded'); 276 if (typeof pagesLoaded === 'undefined') { 277 var expireDate1 = new Date(); 278 expireDate1.setDate(expireDate1.getDate() + 1); 279 280 } else { 281 pagesLoaded = pagesLoaded - 1; 282 } 283 $.cookie('wcmSurveyPagesLoaded', pagesLoaded, {expires: expireDate1, path: '/'}); 284 return pagesLoaded; 285 } 286 287})(jQuery); 288 289/** 290 * figure out the size of an object as if it were an associative array 291 */ 292function object_size(obj) { 293 var size = 0, key; 294 for (key in obj) { 295 if (obj.hasOwnProperty(key)) { 296 size++; 297 } 298 } 299 return size; 300} 301 302/** 303 * sanitize a sting so it can be used as an object property key 304 */ 305function sanitize_path(str) { 306 var args = { 307 '/': '--', 308 '.': '-' 309 }; 310 for (var key in args) { 311 str = str.replace(key, args[key]); 312 } 313 return str; 314} 315 316/** 317 * provide the indexOf function which is a built in property in Ie 9 and later for IE 8 318 */ 319function indexOf(string, array) { 320 for (var i in array) { 321 if (array[i] === string) { 322 return i; 323 } 324 } 325 return false;
326} 327 328/** 329 * Add String.trim() functionality if it doesn't exist 330 * 331 * @see http://stackoverflow.com/questions/2308134/trim-in-javascript-not-working-in-ie 332 */ 333if (typeof String.prototype.trim !== 'function') { 334 String.prototype.trim = function () { 335 return this.replace(/^\s+|\s+$/g, ''); 336 } 337}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.