1// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/ 2var emailRegex = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i; 3 4var gridTableHeight = '229'; 5var SELECT_LISTS_DIALOG_WIDTH = 1000; 6var SELECT_LISTS_DIALOG_HEIGHT = 650; 7 8function checkLength(o, n, min, max, tips) { 9 if (o.val().length > max || o.val().length < min) { 10 o.addClass("ui-state-error"); 11 updateTips("Length of " + n + " must be between " + 12 min + " and " + max + ".", tips); 13 return false; 14 } else { 15 return true; 16 } 17} 18 19function checkRegexp(o, regexp, n, tips) { 20 if (!(regexp.test(o.val()))) { 21 o.addClass("ui-state-error"); 22 updateTips(n, tips); 23 return false; 24 } else { 25 return true; 26 } 27} 28 29function checkRequired(o, n, tips) { 30 if (o.val() == '') { 31 o.addClass("ui-state-error"); 32 updateTips(n + " is required", tips); 33 return false; 34 } else { 35 return true; 36 } 37} 38 39function updateTips(t, updateTips) { 40 updateTips 41 .text(t) 42 .addClass("ui-state-highlight"); 43 setTimeout(function () { 44 updateTips.removeClass("ui-state-highlight", 1500); 45 }, 500); 46} 47 48function escapeString(string) { 49 var escaped = ""; 50 if (string != "") { 51 // single quote 52 escaped = string.replace("'", "'"); 53 } 54 return escaped; 55} 56 57/* selected/suggested lists related functions ------------ */ 58 59function is_equal(str1, str2) { 60 str1 = str1.trim().toLowerCase(); 61 str2 = str2.trim().toLowerCase(); 62 return str1 == str2; 63} 64 65function is_unique(description) { 66 var unique = true; 67 $('#box-suggested .opt-div').each(function () { 68 var text = $(this) 69 .clone() //clone the element 70 .children() //select all the children 71 .remove() //remove all the children 72 .end() //again go back to selected element 73 .text(); //get the text of element 74 75 //if (is_equal($(this).text(), description)) { 76 if (is_equal(text, description)) { 77 unique = false 78 return false; // break each loop 79 } 80 }); 81 82 if (unique == true) { 83 $('#box-selected .opt-div').each(function () { 84 if (is_equal($(this).text(), description)) { 85 unique = false; 86 return false; // break each loop 87 } 88 }); 89 } 90 return unique; 91} 92 93/* A global flag for marking the fact an item has been removed */ 94var gSelectedListItemRemoved = false; 95 96function submitSuggestedSelectedLists(formId) { 97 var form = $("#" + formId); 98 99 // if the form validation failed we may have already populated the hidden variables 100 // so remove any existing hiddens before repopulating. 101 // work-around for E#2755 102 $elems = $(form).find(".hidden-suggested,.hidden-selected"); 103 $elems.remove(); 104 105 // select all the options in select boxes and POST 106 107 $("#box-suggested .opt-div").each(function () { 108 if ($(this).attr("group") != "special_questions") { 109 var hiddenEl = $("<input>"); 110 hiddenEl.attr('type', 'hidden'); 111 hiddenEl.attr('name', 'suggested[]'); 112 hiddenEl.addClass("hidden-suggested"); 113 hiddenEl.val($(this).text()); 114 form.append(hiddenEl); 115 } 116 }); 117 118 $("#box-selected .opt-div").each(function () { 119 var hiddenEl = $("<input>"); 120 hiddenEl.attr('type', 'hidden'); 121 hiddenEl.attr('name', 'selected[]'); 122 hiddenEl.addClass("hidden-selected"); 123 var clone = $(this).clone(); // Remove the extra div from the selected question 124 var readingTime = clone.find('.reading-time').val(); 125 clone.find('.extra').remove(); 126 127 // var clone = $(this).clone(); // Remove the extra div from the selected question 128 // var extraDiv = clone.find('.extra'); 129 // var time = $(extraDiv).find(".time_limit").val(); 130 // extraDiv.remove(); 131 // hiddenEl.val(JSON.stringify({"description" : clone.html(), "time" : time})); 132 133 if (clone.attr("custom_question_id")) { 134 clone.find('.delete_custom_question').remove(); 135 } 136 137 if (clone.attr("file-id") !== undefined && clone.attr("file-id").length > 0) { 138 //clone.find('.row').remove(); 139 hiddenEl.val(JSON.stringify({ 140 "description" : clone.html(), 141 //"special_question" : clone.attr("special_question"), 142 "file_id" : clone.attr("file-id"), 143 "file_name" : clone.attr("file-name"), 144 "reading_time" : readingTime 145 })); 146 } else { 147 hiddenEl.val(clone.html()); 148 } 149 150 form.append(hiddenEl); 151 }); 152 153 form.submit(); 154} 155 156function toGroupId(group) { 157 // trim, lowercase, replace white space with underscore 158 id = ""; 159 if (group != '') { 160 id = group.trim(); 161 id = id.toLowerCase(); 162 id = id.replaceAll(/[^A-Za-z0-9 ]/g, ''); 163 id = id.replaceAll(" ", "_"); 164 } 165 return id; 166} 167 168function replaceAll(expression, org, dest) { 169 return expression.split(org).join(dest); 170} 171 172function getQuestionExtraDiv(time_limit, readingMaterial=false) { 173 if (readingMaterial) { 174 var extraDiv = ''; 175 if($('#frmQuestion').length > 0){ 176 // only for employer general question 177 extraDiv = getVideoRetakesDiv(); 178 } 179 return '<div class="extra"><hr>' + getReadDocumentExtraDiv() + extraDiv + '<input type="hidden" name="question_order[]" class="question_order" value=""/><input type="text" name="question_time[]" class="time_limit" value="' + time_limit + '" /><span class="info">
179seconds allocated to answer.</span><a class="blue_button flat compact">REMOVE</a></div>'; 180 } else { 181 return '<div class="extra"><hr><input type="hidden" name="question_order[]" class="question_order" value=""/><input type="text" name="question_time[]" class="time_limit" value="' + time_limit + '" /><span class="info">seconds allocated to answer.</span><a class="blue_button flat compact">REMOVE</a></div>'; 182 } 183} 184 185function getVideoRetakesDiv(){ 186 return '<div class="row" style="margin-bottom:5px"><div class="col"><select name="retake_videos[]" class="retake_videos"><option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></select><span class="info">retake videos.</span></div></div>'; 187} 188 189function getCustomQuestionExtraDiv() { 190 return '<a class="blue_button flat compact delete_custom_question">DELETE</a>'; 191} 192 193function getReadDocumentExtraDiv() { 194 return '<div class="row" style="margin-bottom:5px">'+ 195 '<div class="col">'+ 196 '<label class="file-label btnAddDocument">Add reading material</label>'+ 197 '<div class="select plus"><img src="/images/plus_file.svg" /></div>'+ 198 '</div>'+ 199 '</div>'+ 200 '<div class="row reading-time-container" style="display:none;margin-bottom:5px">'+ 201 '<div class="col">'+ 202 '<input type="text" name="reading_time" class="time_limit reading-time" value="300" />'+ 203 '<span class="info">seconds reading time.</span>'+ 204 '</div>'+ 205 '</div>'; 206} 207 208function setSuggestedSelectedLists(url, isEmployer) { 209 // clear current values 210 $('#box-suggested .opt-div').remove(); 211 $('#box-suggested .group-div').remove(); 212 // $('#box-selected .opt-div').remove(); 213 // $('#box-selected .extra').remove(); 214 215 // load data from server and set lists 216 $.get(url, function (data) { 217 var questions = JSON.parse(data); 218 219 // selected list 220 if (!/search/i.test(url)) { 221 var selected = questions.selected.contents; 222 for (var i = 0; i < selected.length; i++) { 223 var content = selected[i]; 224 225 var group = content.group; 226 var groupId = toGroupId(group); 227 228 var desc = content.description; 229 var optDiv = $("<div>"); 230 optDiv.addClass("opt-div"); 231 232 var hasReadingMaterial = false; 233 var fileName = "Add reading material"; 234 var readingTime = "300"; 235 236 if (desc.startsWith("{")) { 237 try { 238 var descData = JSON.parse(desc); 239 240 if (!descData.file_id) { 241 desc = descData.description; 242 throw "File ID does not exist"; 243 } 244 245 optDiv.text(descData.description); 246 //optDiv.attr("special_question", descData.special_question) 247 optDiv.attr("file-id", descData.file_id); 248 //optDiv.append(getReadDocumentExtraDiv()); 249 optDiv.attr("file-name", descData.file_name); 250 fileName = descData.file_name; 251 readingTime = descData.reading_time; 252 hasReadingMaterial = true; 253 } catch(e) { 254 optDiv.text(desc); 255 } 256 } else { 257 optDiv.text(desc); 258 } 259 260 optDiv.attr('group', groupId); 261 optDiv.append(getQuestionExtraDiv(content.time_limit, isEmployer)); 262 263 if (hasReadingMaterial) { 264 optDiv.find('.file-label').text(fileName); 265 optDiv.find('.reading-time').val(readingTime); 266 optDiv.find('.reading-time-container').css("display", "block"); 267 } 268 269 if(isEmployer && typeof content.retake !== 'undefined'){ 270 optDiv.find('.retake_videos').val(content.retake); 271 } 272 273 $('#box-selected').append(optDiv); 274 $('#box-selected').trigger('sort'); 275 } 276 } 277 278 // suggested list: groups 279 var groups = questions.suggested.groups; 280 for (var i = 0; i < groups.length; i++) { 281 var group = groups[i]; 282 var groupId = toGroupId(group); 283 284 var groupDiv = $("<div>"); 285 groupDiv.addClass("group-div"); 286 groupDiv.attr('id', groupId); 287 288 var groupHeading = $('<label for="'+groupId+'-toggle">'); 289 groupHeading.text(group); 290 groupHeading.addClass('group-heading'); 291 groupHeading.append('<span class="open-close"></span>'); 292 293 groupDiv.append('<input id="'+groupId+'-toggle" type="checkbox" class="question-group-toggle">'); 294 groupDiv.append(groupHeading); 295 296 $("#box-suggested").append(groupDiv); 297 } 298 299 /*if (getUrlParameter("dev")) { 300 var group = "Special Questions"; 301 var groupId = toGroupId(group); 302 var desc = "Read document"; 303 304 var groupDiv = $("<div>"); 305 groupDiv.addClass("group-div"); 306 groupDiv.attr('id', groupId); 307 308 var groupHeading = $('<label for="'+groupId+'-toggle">'); 309 groupHeading.text(group); 310 groupHeading.addClass('group-heading'); 311 groupHeading.append('<span class="open-close"></span>'); 312 313 groupDiv.append('<input id="'+groupId+'-toggle" type="checkbox" class="question-group-toggle">'); 314 groupDiv.append(groupHeading); 315 316 $("#box-suggested").append(groupDiv); 317 318 var optDiv = $("<div>"); 319 optDiv.addClass('opt-div'); 320 optDiv.text(desc); 321 optDiv.attr('group', groupId); 322 323 optDiv.attr('special_question', "read_document"); 324 325 $('.group-div#' + groupId).append(optDiv); 326 $('#box-selected').trigger('sort'); 327 }*/ 328 329 // suggested list 330 var queries = questions.suggested.contents; 331 for (var i = 0; i < queries.length; i++) { 332 var query = queries[i]; 333 var selected = false;
334 335 $('#box-selected .opt-div').each(function (i, item) { 336 if ($(item).text().replace('seconds allocated to answer.REMOVE', '') == query.description) { 337 selected = true; 338 return; 339 } 340 }); 341 342 if (!selected) { 343 var group = query.group; 344 var groupId = toGroupId(group); 345 var desc = query.description; 346 347 var optDiv = $("<div>"); 348 optDiv.addClass('opt-div'); 349 optDiv.text(desc); 350 optDiv.attr('group', groupId); 351 352 if (query.custom_question_id) { 353 optDiv.attr('custom_question_id', query.custom_question_id); 354 optDiv.append(getCustomQuestionExtraDiv()) 355 } 356 357 $('.group-div#' + groupId).append(optDiv); 358 $('#box-selected').trigger('sort'); 359 } 360 } 361 checkIfSelectedBoxIsEmpty() 362 }); 363 364 // button "Add" clicked 365 $("#box-suggested").off('click').on('click', '.opt-div', function () { 366 var el; 367 368 if (isEmployer && $(this).attr("special_question") == "read_document") { 369 el = $(this).clone(); 370 el.append(getReadDocumentExtraDiv()); 371 } else { 372 el = $(this).detach(); 373 } 374 375 var val = $('#job_time_limit').val(); 376 el.append(getQuestionExtraDiv(typeof val !== "undefined" ? val : $('#timeLimit').val(), isEmployer)); 377 $('#box-selected').append(el); 378 checkIfSelectedBoxIsEmpty() 379 }); 380 381 // custom question "Delete" clicked 382 $("#box-suggested").on('click', '.opt-div a', function (e) { 383 e.stopPropagation(); 384 var el = $(this).parent().detach(); 385 var id = el.attr('custom_question_id'); 386 387 $.get("/data/delete_custom.php?id=" + id) 388 .done(function (data) { 389 }); 390 }); 391 392 // button "Remove" clicked 393 $("#box-selected").on('click', '.opt-div a', function () { 394 var el = $(this).parent().parent().detach(); 395 el.attr("file-id", ""); 396 el.attr("file-name", ""); 397 $(el).find('.extra').detach(); 398 var group = el.attr('group') 399 gSelectedListItemRemoved = true; 400 401 if (!$(el).attr("special_question")) { 402 $('.group-div#' + group).append(el); 403 } 404 405 checkIfSelectedBoxIsEmpty() 406 }); 407 408 // Add custom 409 $('#btnAddCustom').click(function () { 410 var url = $.url(document.location); 411 var id = url.param("id"); 412 if (isEmployer && $('#frmQuestion').length > 0 && $('#frmQuestion').attr("data-platform") == "jobadder") { 413 // Request is coming from JobAdder 414 var id = $("#frmQuestion").attr("data-jobid"); 415 } 416 var custom = $('#customQuestion').val(); 417 var group = $('#customGroup').val(); 418 // check if no duplicate in suggested/selected lists 419 if (custom != "") { 420 if (is_unique(custom)) { 421 var newOption = $("<div>"); 422 newOption.attr("group", toGroupId(group ? group : "custom")); 423 newOption.text(custom); 424 newOption.addClass("opt-div"); 425 newOption.append(getQuestionExtraDiv(120, isEmployer)); 426 $('#box-selected').append(newOption); 427 428 $.post("/data/save_custom.php?id=" + id, {'content': custom, 'group': group ? group : null}) 429 .done(function (data) { 430 }); 431 432 } 433 else { 434 alert('"' + custom + '" already exists in list'); 435 } 436 } 437 // remove text 438 $('#customQuestion').val(''); 439 $('#customQuestion').change(); 440 checkIfSelectedBoxIsEmpty() 441 442 443 }); 444 445 //Check if #box-selected empty 446 function checkIfSelectedBoxIsEmpty() { 447 if ($('#box-selected').find(".opt-div").length == 0) { 448 $('#box-selected').addClass("empty"); 449 } 450 else { 451 $('#box-selected').removeClass("empty"); 452 } 453 } 454 455 // Edit question 456 $(document).on("click", ".list .blue_button.edit", function() { 457 var btn = $(this); 458 var questionId = btn.attr('id'); 459 var ele = btn.parent().parent().children().find('.desc'); 460 var btnTxt = btn.html(); 461 if(btnTxt != 'Save') { 462 var desc = ele.html(); 463 var textarea = '<textarea>'+desc+'</textarea>'; 464 ele.html(textarea); 465 btn.html('Save'); 466 } else { 467 var question = ele.find('textarea').val(); 468 if(question == '') { 469 alert('Please enter some text for the question'); 470 return false;
471 } else { 472 // Save question 473 $.post("/data/save_question.php?id=" + questionId, {'desc': question}).done(function (data) { 474 var data = JSON.parse(data); 475 if(data.success == '1') { 476 ele.html(question); 477 btn.html('Edit'); 478 } else { 479 alert('Problem saving the question. Please try again.'); 480 } 481 }); 482 } 483 } 484 }); 485} 486 487/* ------------ selected/suggested lists related functions */ 488 489/* Raty related functions ---------------------- */ 490function setRatyColumn(jqGrid, columnName) { 491 // determine column index 492 var colModel = jqGrid.getGridParam().colModel; 493 var index = -1; 494 for (var i = 0; i < colModel.length; i++) { 495 if (colModel[i].name == columnName) { 496 index = i; 497 break; 498 } 499 } 500 501 if (index >= 0) { 502 setRatyValues(jqGrid, index); 503 } 504} 505 506function setRatyValues(grid, colIndex) { 507 var ids = grid.getDataIDs(); 508 for (var i = 0; i < ids.length; i++) { 509 initRaty(ids[i], colIndex, grid); 510 } 511} 512 513function initRaty(rowid, colIndex, grid) { 514 var rating = grid.getCell(rowid, colIndex); 515 // because we use rownumbers:true the index of the rating column will be 1 higher 516 $('#' + rowid + '> td:nth-child(' + (colIndex + 1) + ') > div').raty({ 517 path: "/images/custom-star/",//'/lib/jquery.raty-2.4.5/img/', 518 hints: ['', '', '', '', ''], 519 score: rating, 520 //number:rating, 521 readOnly: true, 522 }); 523} 524 525/* ---------------------- Raty related functions */ 526 527function getUrlParameter(sParam) { 528 var sPageURL = decodeURIComponent(window.location.search.substring(1)), 529 sURLVariables = sPageURL.split('&'), 530 sParameterName, 531 i; 532 533 for (i = 0; i < sURLVariables.length; i++) { 534 sParameterName = sURLVariables[i].split('='); 535 536 if (sParameterName[0] === sParam) { 537 return sParameterName[1] === undefined ? true : sParameterName[1]; 538 } 539 } 540}
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.