| @@ 7-943 (lines=937) @@ | ||
| 4 | ||
| 5 | // ============================================================================= |
|
| 6 | ||
| 7 | (function($) { |
|
| 8 | ||
| 9 | // Add isValid() |
|
| 10 | ||
| 11 | $.fn.isValid = function(){ |
|
| 12 | return this[0].checkValidity() |
|
| 13 | } |
|
| 14 | ||
| 15 | $(document).ready(function() { |
|
| 16 | ||
| 17 | // Accordion Handlers ================================================== |
|
| 18 | ||
| 19 | function accordionTrigger(trigger) { |
|
| 20 | if ($(trigger).parent(".accordion").hasClass("active")) { |
|
| 21 | $(trigger).attr("aria-expanded", "false"); |
|
| 22 | $(trigger).parent(".accordion").removeClass("active"); |
|
| 23 | $(trigger).parent(".accordion").find(".accordion-content").attr("aria-hidden", "true"); |
|
| 24 | } |
|
| 25 | else { |
|
| 26 | $(trigger).attr("aria-expanded", "true"); |
|
| 27 | $(trigger).parent(".accordion").addClass("active"); |
|
| 28 | $(trigger).parent(".accordion").find(".accordion-content").attr("aria-hidden", "false"); |
|
| 29 | } |
|
| 30 | } |
|
| 31 | ||
| 32 | $(document).on("click", ".accordion-trigger", function(e){ |
|
| 33 | ||
| 34 | accordionTrigger(this); |
|
| 35 | ||
| 36 | }); |
|
| 37 | ||
| 38 | $(document).on("keyup", ".accordion-trigger", function(e){ |
|
| 39 | ||
| 40 | if(e.which == 13) { |
|
| 41 | accordionTrigger(this); |
|
| 42 | } |
|
| 43 | ||
| 44 | }); |
|
| 45 | ||
| 46 | // Modal Handlers ====================================================== |
|
| 47 | ||
| 48 | function openModal(trigger) { |
|
| 49 | ||
| 50 | var modalID = $(trigger).attr("data-modal-id"); |
|
| 51 | var modal = $(".modal[data-modal-id="+modalID+"]"); |
|
| 52 | $(".modal-overlay").addClass("active"); |
|
| 53 | modal.addClass("active"); |
|
| 54 | $("body").css("overflow", "hidden"); |
|
| 55 | ||
| 56 | // Tab Items |
|
| 57 | ||
| 58 | var focusableItems = modal.find(":focusable"); |
|
| 59 | ||
| 60 | var firstInput = focusableItems.first(); |
|
| 61 | var lastInput = focusableItems.last(); |
|
| 62 | ||
| 63 | if (modal.find("form").length == 0) { |
|
| 64 | lastInput.focus(); |
|
| 65 | } |
|
| 66 | else { |
|
| 67 | firstInput.focus(); |
|
| 68 | } |
|
| 69 | ||
| 70 | modalTabHandler(firstInput, lastInput); |
|
| 71 | escapeModalHandler(); |
|
| 72 | ||
| 73 | } |
|
| 74 | ||
| 75 | $(document).on("click", ".modal-trigger", function(e){ |
|
| 76 | ||
| 77 | openModal(this); |
|
| 78 | ||
| 79 | }); |
|
| 80 | ||
| 81 | $(document).on("keyup", ".modal-trigger", function(e){ |
|
| 82 | ||
| 83 | if(e.which == 13) { |
|
| 84 | openModal(this); |
|
| 85 | } |
|
| 86 | ||
| 87 | }); |
|
| 88 | ||
| 89 | ||
| 90 | function closeModal(trigger) { |
|
| 91 | ||
| 92 | $(".modal-overlay").removeClass("active"); |
|
| 93 | $(".modal").removeClass("active"); |
|
| 94 | $("body").css("overflow", "visible"); |
|
| 95 | ||
| 96 | } |
|
| 97 | ||
| 98 | $(document).on("click", ".modal-cancel-trigger", function(e){ |
|
| 99 | ||
| 100 | closeModal(this); |
|
| 101 | ||
| 102 | }); |
|
| 103 | ||
| 104 | $(document).on("keyup", ".modal-cancel-trigger", function(e){ |
|
| 105 | ||
| 106 | if(e.which == 13) { |
|
| 107 | closeModal(this); |
|
| 108 | } |
|
| 109 | ||
| 110 | }); |
|
| 111 | ||
| 112 | // Tab Handler ===================================================== |
|
| 113 | ||
| 114 | function modalTabHandler(first, last) { |
|
| 115 | ||
| 116 | $(document).on("keydown", function(e){ |
|
| 117 | ||
| 118 | var keyCode = e.keyCode || e.which; |
|
| 119 | ||
| 120 | if (keyCode == 9 && !e.shiftKey) { |
|
| 121 | ||
| 122 | if ($(last).is(":focus")) { |
|
| 123 | e.preventDefault(); |
|
| 124 | $(first).focus(); |
|
| 125 | } |
|
| 126 | ||
| 127 | } |
|
| 128 | else if (keyCode == 9 && e.shiftKey) { |
|
| 129 | ||
| 130 | if($(first).is(":focus")) { |
|
| 131 | e.preventDefault(); |
|
| 132 | $(last).focus(); |
|
| 133 | } |
|
| 134 | ||
| 135 | } |
|
| 136 | ||
| 137 | }); |
|
| 138 | ||
| 139 | } |
|
| 140 | ||
| 141 | // Escape Handler ================================================== |
|
| 142 | ||
| 143 | function escapeModalHandler() { |
|
| 144 | ||
| 145 | $(document).on("keyup", function(e){ |
|
| 146 | ||
| 147 | if((e.key==='Escape'||e.key==='Esc'||e.keyCode===27)){ |
|
| 148 | ||
| 149 | $(".modal-overlay").removeClass("active"); |
|
| 150 | $(".modal").removeClass("active"); |
|
| 151 | $("body").css("overflow", "visible"); |
|
| 152 | ||
| 153 | // FF and compatible |
|
| 154 | if (e.stopPropagation) { |
|
| 155 | e.stopPropagation(); |
|
| 156 | e.preventDefault(); |
|
| 157 | } |
|
| 158 | ||
| 159 | } |
|
| 160 | ||
| 161 | }); |
|
| 162 | ||
| 163 | } |
|
| 164 | ||
| 165 | // Form Handlers ======================================================= |
|
| 166 | ||
| 167 | // Required Fields |
|
| 168 | ||
| 169 | function requiredFields() { |
|
| 170 | $("input:required, textarea:required").each(function(e) { |
|
| 171 | $(this).parent().addClass("required"); |
|
| 172 | $(this).parent().find("label").append("<span class='form__required'><i class='fa fa-asterisk' aria-label='Asterisk'></i></span>"); |
|
| 173 | }); |
|
| 174 | } |
|
| 175 | ||
| 176 | requiredFields(); |
|
| 177 | ||
| 178 | // Label Handers =================================================== |
|
| 179 | ||
| 180 | function labelHandlers() { |
|
| 181 | ||
| 182 | $("[class*='form__input-wrapper'] input, [class*='form__input-wrapper'] textarea").focusin(function(e) { |
|
| 183 | $(this).parent().addClass("active"); |
|
| 184 | }); |
|
| 185 | ||
| 186 | $("[class*='form__input-wrapper'] input, [class*='form__input-wrapper'] textarea").focusout(function(e) { |
|
| 187 | ||
| 188 | // Check for existing value. |
|
| 189 | ||
| 190 | if ($(this).val() == "") { |
|
| 191 | $(this).parent().removeClass("active"); |
|
| 192 | } |
|
| 193 | ||
| 194 | // Check Validity |
|
| 195 | ||
| 196 | if ($(this).isValid() == true) { |
|
| 197 | ||
| 198 | if ($(this).val() == "" || $(this).attr("type") == "password") { |
|
| 199 | $(this).parent().removeClass("valid"); |
|
| 200 | $(this).parent().removeClass("invalid"); |
|
| 201 | } |
|
| 202 | else { |
|
| 203 | $(this).parent().addClass("valid"); |
|
| 204 | $(this).parent().removeClass("invalid"); |
|
| 205 | } |
|
| 206 | ||
| 207 | } |
|
| 208 | else { |
|
| 209 | ||
| 210 | if ($(this).attr("type") == "password") { |
|
| 211 | return false; |
|
| 212 | } |
|
| 213 | else { |
|
| 214 | $(this).parent().addClass("invalid"); |
|
| 215 | $(this).parent().removeClass("valid"); |
|
| 216 | } |
|
| 217 | ||
| 218 | } |
|
| 219 | ||
| 220 | }); |
|
| 221 | ||
| 222 | } |
|
| 223 | ||
| 224 | labelHandlers(); |
|
| 225 | ||
| 226 | //Individualize template attributes |
|
| 227 | function appendToAttributes(parent, attribute, suffix, conditions) { |
|
| 228 | var selector = "*[" + attribute + "]"; |
|
| 229 | ||
| 230 | //If conditions is set, only modify attributes that also |
|
| 231 | //satisfy that selector |
|
| 232 | if (conditions) { |
|
| 233 | selector = conditions + selector; |
|
| 234 | } |
|
| 235 | ||
| 236 | parent.find(selector).each(function() { |
|
| 237 | $(this).attr(attribute, $(this).attr(attribute) + suffix); |
|
| 238 | }); |
|
| 239 | } |
|
| 240 | ||
| 241 | //Return the next unused data-item-id value |
|
| 242 | function getNextItemId(parent) { |
|
| 243 | var maxId = 0; |
|
| 244 | parent.find("*[data-item-id]").each(function() { |
|
| 245 | var id = parseInt( $(this).attr('data-item-id') ); |
|
| 246 | if (id > maxId) { |
|
| 247 | maxId = id; |
|
| 248 | } |
|
| 249 | }); |
|
| 250 | return maxId + 1; |
|
| 251 | } |
|
| 252 | ||
| 253 | // Profile List Handlers =============================================== |
|
| 254 | ||
| 255 | // Add Profile Element |
|
| 256 | function addProfileElement(trigger) { |
|
| 257 | ||
| 258 | // Get Parent |
|
| 259 | var parent = $(trigger).parents(".profile-list"); |
|
| 260 | ||
| 261 | // Get List Wrapper |
|
| 262 | var wrapper = parent.find(".profile-element-list"); |
|
| 263 | ||
| 264 | // Set Null to Hidden |
|
| 265 | parent.find(".profile-null").removeClass("active"); |
|
| 266 | ||
| 267 | // Get Template |
|
| 268 | var template = parent.find(".profile-element.template").clone(); |
|
| 269 | ||
| 270 | // Remove Template Class |
|
| 271 | template.removeClass("template"); |
|
| 272 | ||
| 273 | // Get New ID |
|
| 274 | var newId = getNextItemId(wrapper); |
|
| 275 | ||
| 276 | template.attr('data-item-id', newId); |
|
| 277 | ||
| 278 | // Individualize Form IDs and labels |
|
| 279 | appendToAttributes(template, 'id', '_' + newId); |
|
| 280 | appendToAttributes(template, 'for', '_' + newId); |
|
| 281 | ||
| 282 | // Individualize form names, except for submit buttons |
|
| 283 | appendToAttributes(template, 'name', '[' + newId + ']', ':not([name=submit])'); |
|
| 284 | // Individualize values on submit buttons |
|
| 285 | appendToAttributes(template, 'value', '[' + newId + ']', '[name=submit]'); |
|
| 286 | ||
| 287 | // Prepend Clone to the Wrapper |
|
| 288 | wrapper.prepend(template); |
|
| 289 | ||
| 290 | // Reactivate Required Fields |
|
| 291 | requiredFields(); |
|
| 292 | ||
| 293 | // Reactivate Labels |
|
| 294 | labelHandlers(); |
|
| 295 | ||
| 296 | // Reactivate Nested Relatives |
|
| 297 | loadProfileRelatives(); |
|
| 298 | ||
| 299 | } |
|
| 300 | ||
| 301 | // Click Trigger |
|
| 302 | $(".profile-list__add-element-trigger").on("click", function(e) { |
|
| 303 | ||
| 304 | // Prevent Default Functions |
|
| 305 | e.preventDefault(); |
|
| 306 | ||
| 307 | // Add Profile Elements |
|
| 308 | addProfileElement(this); |
|
| 309 | ||
| 310 | }); |
|
| 311 | ||
| 312 | // Enter Key Trigger |
|
| 313 | $(".profile-list__add-element-trigger").on("keyup", function(e) { |
|
| 314 | ||
| 315 | if(e.which == 13) { |
|
| 316 | ||
| 317 | // Prevent Default Functions |
|
| 318 | e.preventDefault(); |
|
| 319 | ||
| 320 | // Add Profile Elements |
|
| 321 | addProfileElement(this); |
|
| 322 | ||
| 323 | } |
|
| 324 | ||
| 325 | }); |
|
| 326 | ||
| 327 | // Remove Profile Element |
|
| 328 | ||
| 329 | // Add Profile Relative |
|
| 330 | function addProfileRelative(trigger) { |
|
| 331 | ||
| 332 | // Get Parent |
|
| 333 | var parent = $(trigger).parents(".profile-relative-list"); |
|
| 334 | ||
| 335 | // Get List Wrapper |
|
| 336 | var wrapper = parent.find(".profile-relative-list__wrapper"); |
|
| 337 | ||
| 338 | // Set Null to Hidden |
|
| 339 | // parent.find(".profile-null").removeClass("active"); |
|
| 340 | ||
| 341 | // Get Template |
|
| 342 | var template = parent.find(".profile-relative.template").clone(); |
|
| 343 | ||
| 344 | // Remove Template Class |
|
| 345 | template.removeClass("template"); |
|
| 346 | ||
| 347 | // Edit Form IDs |
|
| 348 | ||
| 349 | // Tristan, help! x_x |
|
| 350 | ||
| 351 | // Append Clone to the Wrapper |
|
| 352 | wrapper.append(template); |
|
| 353 | ||
| 354 | // Reactivate Required Fields |
|
| 355 | requiredFields(); |
|
| 356 | ||
| 357 | // Reactivate Labels |
|
| 358 | labelHandlers(); |
|
| 359 | ||
| 360 | // Reactivate Nested Relatives |
|
| 361 | loadProfileRelativeDeletion(); |
|
| 362 | ||
| 363 | } |
|
| 364 | ||
| 365 | // Load Function |
|
| 366 | function loadProfileRelatives() { |
|
| 367 | ||
| 368 | // Click Trigger |
|
| 369 | $(".profile-relative__add-trigger").off("click"); |
|
| 370 | ||
| 371 | $(".profile-relative__add-trigger").on("click", function(e) { |
|
| 372 | ||
| 373 | // Prevent Default Functions |
|
| 374 | e.preventDefault(); |
|
| 375 | ||
| 376 | // Add Profile Relative |
|
| 377 | addProfileRelative(this); |
|
| 378 | ||
| 379 | }); |
|
| 380 | ||
| 381 | // Enter Key Trigger |
|
| 382 | $(".profile-relative__add-trigger").off("keyup"); |
|
| 383 | ||
| 384 | $(".profile-relative__add-trigger").on("keyup", function(e) { |
|
| 385 | ||
| 386 | if(e.which == 13) { |
|
| 387 | ||
| 388 | // Prevent Default Functions |
|
| 389 | e.preventDefault(); |
|
| 390 | ||
| 391 | // Add Profile Relative |
|
| 392 | addProfileRelative(this); |
|
| 393 | ||
| 394 | } |
|
| 395 | ||
| 396 | }); |
|
| 397 | ||
| 398 | } |
|
| 399 | ||
| 400 | loadProfileRelatives(); |
|
| 401 | ||
| 402 | // Remove Profile Relative |
|
| 403 | function deleteProfileRelative(trigger) { |
|
| 404 | ||
| 405 | $(trigger).parents(".profile-relative").remove(); |
|
| 406 | ||
| 407 | } |
|
| 408 | ||
| 409 | // Load Function |
|
| 410 | function loadProfileRelativeDeletion() { |
|
| 411 | ||
| 412 | // Click Trigger |
|
| 413 | $(".profile-relative__remove-trigger").on("click", function(e) { |
|
| 414 | ||
| 415 | // Prevent Default Functions |
|
| 416 | e.preventDefault(); |
|
| 417 | ||
| 418 | // Delete Profile Relative |
|
| 419 | deleteProfileRelative(this); |
|
| 420 | ||
| 421 | }); |
|
| 422 | ||
| 423 | // Enter Key Trigger |
|
| 424 | $(".profile-relative__remove-trigger").on("keyup", function(e) { |
|
| 425 | ||
| 426 | if(e.which == 13) { |
|
| 427 | ||
| 428 | // Prevent Default Functions |
|
| 429 | e.preventDefault(); |
|
| 430 | ||
| 431 | // Delete Profile Relative |
|
| 432 | deleteProfileRelative(this); |
|
| 433 | ||
| 434 | } |
|
| 435 | ||
| 436 | }); |
|
| 437 | ||
| 438 | } |
|
| 439 | ||
| 440 | loadProfileRelativeDeletion(); |
|
| 441 | ||
| 442 | // Experience Handlers ================================================= |
|
| 443 | ||
| 444 | // Degrees |
|
| 445 | ||
| 446 | function addDegree(trigger) { |
|
| 447 | ||
| 448 | // Get Wrapper |
|
| 449 | var wrapper = $(".application-post__experience-wrapper"); |
|
| 450 | ||
| 451 | // Get Template |
|
| 452 | var template = $(".application-post__accordion--degree.template").clone(); |
|
| 453 | ||
| 454 | // Get New ID |
|
| 455 | var newID = parseInt(wrapper.find("[class*='application-post__accordion--']").last().attr("data-experience-id")) + 1; |
|
| 456 | ||
| 457 | // Remove Template Class |
|
| 458 | template.removeClass("template"); |
|
| 459 | ||
| 460 | // Assign the New ID |
|
| 461 | template.attr("data-experience-id", newID); |
|
| 462 | ||
| 463 | // Edit Form IDs |
|
| 464 | ||
| 465 | // Degree Type |
|
| 466 | template.find("[data-form-id*='experience-degree']").find("label").attr("for", "degree" + newID); |
|
| 467 | template.find("[data-form-id*='experience-degree']").find("select").attr("id", "degree" + newID); |
|
| 468 | ||
| 469 | // Area of Study |
|
| 470 | template.find("[data-form-id*='experience-aos']").find("label").attr("for", "areaOfStudy" + newID); |
|
| 471 | template.find("[data-form-id*='experience-aos']").find("input").attr("id", "areaOfStudy" + newID); |
|
| 472 | ||
| 473 | // Institution |
|
| 474 | template.find("[data-form-id*='experience-institution']").find("label").attr("for", "institution" + newID); |
|
| 475 | template.find("[data-form-id*='experience-institution']").find("input").attr("id", "institution" + newID); |
|
| 476 | ||
| 477 | // Start Date |
|
| 478 | template.find("[data-form-id*='experience-start-date']").find("label").attr("for", "startDate" + newID); |
|
| 479 | template.find("[data-form-id*='experience-start-date']").find("input").attr("id", "startDate" + newID); |
|
| 480 | ||
| 481 | // End Date |
|
| 482 | template.find("[data-form-id*='experience-end-date']").find("label").attr("for", "endDate" + newID); |
|
| 483 | template.find("[data-form-id*='experience-end-date']").find("input").attr("id", "endDate" + newID); |
|
| 484 | ||
| 485 | // Append Clone to the Wrapper |
|
| 486 | wrapper.append(template); |
|
| 487 | ||
| 488 | requiredFields(); |
|
| 489 | labelHandlers(); |
|
| 490 | ||
| 491 | } |
|
| 492 | ||
| 493 | $("#addDegreeButton").on("click", function(e) { |
|
| 494 | ||
| 495 | e.preventDefault(); |
|
| 496 | ||
| 497 | addDegree(this); |
|
| 498 | ||
| 499 | }); |
|
| 500 | ||
| 501 | $("#addDegreeButton").on("keyup", function(e) { |
|
| 502 | ||
| 503 | if(e.which == 13) { |
|
| 504 | e.preventDefault(); |
|
| 505 | addDegree(this); |
|
| 506 | } |
|
| 507 | ||
| 508 | }); |
|
| 509 | ||
| 510 | // Courses |
|
| 511 | ||
| 512 | function addCourse(trigger) { |
|
| 513 | ||
| 514 | // Get Wrapper |
|
| 515 | var wrapper = $(".application-post__experience-wrapper"); |
|
| 516 | ||
| 517 | // Get Template |
|
| 518 | var template = $(".application-post__accordion--course.template").clone(); |
|
| 519 | ||
| 520 | // Get New ID |
|
| 521 | var newID = parseInt(wrapper.find("[class*='application-post__accordion--']").last().attr("data-experience-id")) + 1; |
|
| 522 | ||
| 523 | // Remove Template Class |
|
| 524 | template.removeClass("template"); |
|
| 525 | ||
| 526 | // Assign the New ID |
|
| 527 | template.attr("data-experience-id", newID); |
|
| 528 | ||
| 529 | // Edit Form IDs |
|
| 530 | ||
| 531 | // Course Name |
|
| 532 | template.find("[data-form-id*='experience-course-name']").find("label").attr("for", "courseName" + newID); |
|
| 533 | template.find("[data-form-id*='experience-course-name']").find("input").attr("id", "courseName" + newID); |
|
| 534 | ||
| 535 | // Institution |
|
| 536 | template.find("[data-form-id*='experience-institution']").find("label").attr("for", "institution" + newID); |
|
| 537 | template.find("[data-form-id*='experience-institution']").find("input").attr("id", "institution" + newID); |
|
| 538 | ||
| 539 | // Start Date |
|
| 540 | template.find("[data-form-id*='experience-start-date']").find("label").attr("for", "startDate" + newID); |
|
| 541 | template.find("[data-form-id*='experience-start-date']").find("input").attr("id", "startDate" + newID); |
|
| 542 | ||
| 543 | // End Date |
|
| 544 | template.find("[data-form-id*='experience-end-date']").find("label").attr("for", "endDate" + newID); |
|
| 545 | template.find("[data-form-id*='experience-end-date']").find("input").attr("id", "endDate" + newID); |
|
| 546 | ||
| 547 | // Append Clone to the Wrapper |
|
| 548 | wrapper.append(template); |
|
| 549 | ||
| 550 | requiredFields(); |
|
| 551 | labelHandlers(); |
|
| 552 | ||
| 553 | } |
|
| 554 | ||
| 555 | $("#addCourseButton").on("click", function(e) { |
|
| 556 | ||
| 557 | e.preventDefault(); |
|
| 558 | ||
| 559 | addCourse(this); |
|
| 560 | ||
| 561 | }); |
|
| 562 | ||
| 563 | $("#addCourseButton").on("keyup", function(e) { |
|
| 564 | ||
| 565 | if(e.which == 13) { |
|
| 566 | e.preventDefault(); |
|
| 567 | addCourse(this); |
|
| 568 | } |
|
| 569 | ||
| 570 | }); |
|
| 571 | ||
| 572 | // Work |
|
| 573 | ||
| 574 | function addWork(trigger) { |
|
| 575 | ||
| 576 | // Get Wrapper |
|
| 577 | var wrapper = $(".application-post__experience-wrapper"); |
|
| 578 | ||
| 579 | // Get Template |
|
| 580 | var template = $(".application-post__accordion--work.template").clone(); |
|
| 581 | ||
| 582 | // Get New ID |
|
| 583 | var newID = parseInt(wrapper.find("[class*='application-post__accordion--']").last().attr("data-experience-id")) + 1; |
|
| 584 | ||
| 585 | // Remove Template Class |
|
| 586 | template.removeClass("template"); |
|
| 587 | ||
| 588 | // Assign the New ID |
|
| 589 | template.attr("data-experience-id", newID); |
|
| 590 | ||
| 591 | // Edit Form IDs |
|
| 592 | ||
| 593 | // Role |
|
| 594 | template.find("[data-form-id*='experience-course-name']").find("label").attr("for", "role" + newID); |
|
| 595 | template.find("[data-form-id*='experience-course-name']").find("input").attr("id", "role" + newID); |
|
| 596 | ||
| 597 | // Group / Company |
|
| 598 | template.find("[data-form-id*='experience-institution']").find("label").attr("for", "group" + newID); |
|
| 599 | template.find("[data-form-id*='experience-institution']").find("input").attr("id", "group" + newID); |
|
| 600 | ||
| 601 | // Description |
|
| 602 | template.find("[data-form-id*='experience-description']").find("label").attr("for", "description" + newID); |
|
| 603 | template.find("[data-form-id*='experience-description']").find("input").attr("id", "description" + newID); |
|
| 604 | ||
| 605 | // Start Date |
|
| 606 | template.find("[data-form-id*='experience-start-date']").find("label").attr("for", "startDate" + newID); |
|
| 607 | template.find("[data-form-id*='experience-start-date']").find("input").attr("id", "startDate" + newID); |
|
| 608 | ||
| 609 | // End Date |
|
| 610 | template.find("[data-form-id*='experience-end-date']").find("label").attr("for", "endDate" + newID); |
|
| 611 | template.find("[data-form-id*='experience-end-date']").find("input").attr("id", "endDate" + newID); |
|
| 612 | ||
| 613 | // Append Clone to the Wrapper |
|
| 614 | wrapper.append(template); |
|
| 615 | ||
| 616 | requiredFields(); |
|
| 617 | labelHandlers(); |
|
| 618 | ||
| 619 | } |
|
| 620 | ||
| 621 | $("#addWorkButton").on("click", function(e) { |
|
| 622 | ||
| 623 | e.preventDefault(); |
|
| 624 | ||
| 625 | addWork(this); |
|
| 626 | ||
| 627 | }); |
|
| 628 | ||
| 629 | $("#addWorkButton").on("keyup", function(e) { |
|
| 630 | ||
| 631 | if(e.which == 13) { |
|
| 632 | e.preventDefault(); |
|
| 633 | addWork(this); |
|
| 634 | } |
|
| 635 | ||
| 636 | }); |
|
| 637 | ||
| 638 | // Create Job Handlers ================================================= |
|
| 639 | ||
| 640 | // Tasks |
|
| 641 | ||
| 642 | function addTask(trigger) { |
|
| 643 | ||
| 644 | // Get Wrapper |
|
| 645 | var wrapper = $(".manager-jobs__create-task-wrapper"); |
|
| 646 | ||
| 647 | // Get Template |
|
| 648 | var template = $(".manager-jobs__create-task.template").clone(); |
|
| 649 | ||
| 650 | console.log(wrapper.find(".manager-jobs__create-task")); |
|
| 651 | ||
| 652 | // Get New ID |
|
| 653 | if (wrapper.find(".manager-jobs__create-task").length == 0) { |
|
| 654 | var newID = parseInt(template.attr("data-task-id")) + 1; |
|
| 655 | } |
|
| 656 | else { |
|
| 657 | var newID = parseInt(wrapper.find("[class*='manager-jobs__create-task']").last().attr("data-task-id")) + 1; |
|
| 658 | } |
|
| 659 | ||
| 660 | // Remove Template Class |
|
| 661 | template.removeClass("template"); |
|
| 662 | ||
| 663 | // Assign the New ID |
|
| 664 | template.attr("data-task-id", newID); |
|
| 665 | ||
| 666 | // Add newID as suffix to all "id" and "for" attributes |
|
| 667 | template.find("*[id]").each(function() { $(this).attr("id", this.id + newID)}); |
|
| 668 | template.find("*[for]").each(function() { $(this).attr("for", $(this).attr("for") + newID)}); |
|
| 669 | ||
| 670 | // Replace :id with newID in all form names |
|
| 671 | template.find("*[name]").each(function() { $(this).attr('name', $(this).attr("name").replace(":id", newID))}); |
|
| 672 | ||
| 673 | // Task (English) |
|
| 674 | //template.find("[data-form-id*='task-english']").find("label").attr("for", "taskEN" + newID); |
|
| 675 | //template.find("[data-form-id*='task-english']").find("input").attr("id", "taskEN" + newID); |
|
| 676 | ||
| 677 | // Task (French) |
|
| 678 | //template.find("[data-form-id*='task-french']").find("label").attr("for", "taskFR" + newID); |
|
| 679 | //template.find("[data-form-id*='task-french']").find("input").attr("id", "taskFR" + newID); |
|
| 680 | ||
| 681 | // Append Clone to the Wrapper |
|
| 682 | wrapper.append(template); |
|
| 683 | ||
| 684 | requiredFields(); |
|
| 685 | labelHandlers(); |
|
| 686 | deleteTaskTrigger(); |
|
| 687 | ||
| 688 | } |
|
| 689 | ||
| 690 | $("#addTaskButton").on("click", function(e) { |
|
| 691 | ||
| 692 | e.preventDefault(); |
|
| 693 | ||
| 694 | addTask(this); |
|
| 695 | ||
| 696 | }); |
|
| 697 | ||
| 698 | $("#addTaskButton").on("keyup", function(e) { |
|
| 699 | ||
| 700 | if(e.which == 13) { |
|
| 701 | e.preventDefault(); |
|
| 702 | addTask(this); |
|
| 703 | } |
|
| 704 | ||
| 705 | }); |
|
| 706 | ||
| 707 | // Task Deletion |
|
| 708 | ||
| 709 | function deleteTask(trigger) { |
|
| 710 | ||
| 711 | $(trigger).parents(".manager-jobs__create-task").remove(); |
|
| 712 | ||
| 713 | } |
|
| 714 | ||
| 715 | function deleteTaskTrigger() { |
|
| 716 | ||
| 717 | $(".manager-jobs__delete-task-button").on("click", function(e) { |
|
| 718 | ||
| 719 | e.preventDefault(); |
|
| 720 | ||
| 721 | deleteTask(this); |
|
| 722 | ||
| 723 | }); |
|
| 724 | ||
| 725 | $(".manager-jobs__delete-task-button").on("keyup", function(e) { |
|
| 726 | ||
| 727 | if(e.which == 13) { |
|
| 728 | e.preventDefault(); |
|
| 729 | deleteTask(this); |
|
| 730 | } |
|
| 731 | ||
| 732 | }); |
|
| 733 | ||
| 734 | } |
|
| 735 | ||
| 736 | deleteTaskTrigger(); |
|
| 737 | ||
| 738 | // Skills |
|
| 739 | ||
| 740 | function addSkill(trigger) { |
|
| 741 | ||
| 742 | // Get Parent |
|
| 743 | var parent = $(trigger).parents(".manager-jobs__skill-wrapper"); |
|
| 744 | ||
| 745 | // Get Wrapper |
|
| 746 | var wrapper = parent.find(".manager-jobs__create-skill-wrapper"); |
|
| 747 | ||
| 748 | // Get Template |
|
| 749 | var template = parent.find(".manager-jobs__create-skill.template").clone(); |
|
| 750 | ||
| 751 | console.log(wrapper.find(".manager-jobs__create-skill")); |
|
| 752 | ||
| 753 | // Get New ID |
|
| 754 | if (wrapper.find(".manager-jobs__create-skill").length == 0) { |
|
| 755 | var newID = parseInt(template.attr("data-skill-id")) + 1; |
|
| 756 | } |
|
| 757 | else { |
|
| 758 | var newID = parseInt(wrapper.find("[class*='manager-jobs__create-skill']").last().attr("data-skill-id")) + 1; |
|
| 759 | } |
|
| 760 | ||
| 761 | // Remove Template Class |
|
| 762 | template.removeClass("template"); |
|
| 763 | ||
| 764 | // Assign the New ID |
|
| 765 | template.attr("data-skill-id", newID); |
|
| 766 | ||
| 767 | // Add newID as suffix to all "id" and "for" attributes |
|
| 768 | template.find("*[id]").each(function() { $(this).attr("id", this.id + newID)}); |
|
| 769 | template.find("*[for]").each(function() { $(this).attr("for", $(this).attr("for") + newID)}); |
|
| 770 | ||
| 771 | // Replace :id with newID in all form names |
|
| 772 | template.find("*[name]").each(function() { $(this).attr('name', $(this).attr("name").replace(":id", newID))}); |
|
| 773 | ||
| 774 | // Edit Form IDs |
|
| 775 | // |
|
| 776 | // // Queestion (English) |
|
| 777 | // template.find("[data-form-id*='question-english']").find("label").attr("for", "questionEN" + newID); |
|
| 778 | // template.find("[data-form-id*='question-english']").find("input").attr("id", "questionEN" + newID); |
|
| 779 | // |
|
| 780 | // // Queestion (French) |
|
| 781 | // template.find("[data-form-id*='question-french']").find("label").attr("for", "questionFR" + newID); |
|
| 782 | // template.find("[data-form-id*='question-french']").find("input").attr("id", "questionFR" + newID); |
|
| 783 | ||
| 784 | // Append Clone to the Wrapper |
|
| 785 | wrapper.append(template); |
|
| 786 | ||
| 787 | requiredFields(); |
|
| 788 | labelHandlers(); |
|
| 789 | deleteSkillTrigger(); |
|
| 790 | ||
| 791 | } |
|
| 792 | ||
| 793 | $(".manager-jobs__add-skill-button").on("click", function(e) { |
|
| 794 | ||
| 795 | e.preventDefault(); |
|
| 796 | ||
| 797 | addSkill(this); |
|
| 798 | ||
| 799 | }); |
|
| 800 | ||
| 801 | $(".manager-jobs__add-skill-button").on("keyup", function(e) { |
|
| 802 | ||
| 803 | if(e.which == 13) { |
|
| 804 | e.preventDefault(); |
|
| 805 | addSkill(this); |
|
| 806 | } |
|
| 807 | ||
| 808 | }); |
|
| 809 | ||
| 810 | // Skill Deletion |
|
| 811 | ||
| 812 | function deleteSkill(trigger) { |
|
| 813 | ||
| 814 | $(trigger).parents(".manager-jobs__create-skill").remove(); |
|
| 815 | ||
| 816 | } |
|
| 817 | ||
| 818 | function deleteSkillTrigger() { |
|
| 819 | ||
| 820 | $(".manager-jobs__delete-skill-button").on("click", function(e) { |
|
| 821 | ||
| 822 | e.preventDefault(); |
|
| 823 | ||
| 824 | deleteSkill(this); |
|
| 825 | ||
| 826 | }); |
|
| 827 | ||
| 828 | $(".manager-jobs__delete-skill-button").on("keyup", function(e) { |
|
| 829 | ||
| 830 | if(e.which == 13) { |
|
| 831 | e.preventDefault(); |
|
| 832 | deleteSkill(this); |
|
| 833 | } |
|
| 834 | ||
| 835 | }); |
|
| 836 | ||
| 837 | } |
|
| 838 | ||
| 839 | deleteSkillTrigger(); |
|
| 840 | ||
| 841 | // Questions |
|
| 842 | ||
| 843 | function addQuestion(trigger) { |
|
| 844 | ||
| 845 | // Get Wrapper |
|
| 846 | var wrapper = $(".manager-jobs__create-question-wrapper"); |
|
| 847 | ||
| 848 | // Get Template |
|
| 849 | var template = $(".manager-jobs__create-question.template").clone(); |
|
| 850 | ||
| 851 | console.log(wrapper.find(".manager-jobs__create-question")); |
|
| 852 | ||
| 853 | // Get New ID |
|
| 854 | if (wrapper.find(".manager-jobs__create-question").length == 0) { |
|
| 855 | var newID = parseInt(template.attr("data-question-id")) + 1; |
|
| 856 | } |
|
| 857 | else { |
|
| 858 | var newID = parseInt(wrapper.find("[class*='manager-jobs__create-question']").last().attr("data-question-id")) + 1; |
|
| 859 | } |
|
| 860 | ||
| 861 | // Remove Template Class |
|
| 862 | template.removeClass("template"); |
|
| 863 | ||
| 864 | // Assign the New ID |
|
| 865 | template.attr("data-question-id", newID); |
|
| 866 | ||
| 867 | // Add newID as suffix to all "id" and "for" attributes |
|
| 868 | template.find("*[id]").each(function() { $(this).attr("id", this.id + newID)}); |
|
| 869 | template.find("*[for]").each(function() { $(this).attr("for", $(this).attr("for") + newID)}); |
|
| 870 | ||
| 871 | // Replace :id with newID in all form names |
|
| 872 | template.find("*[name]").each(function() { $(this).attr('name', $(this).attr("name").replace(":id", newID))}); |
|
| 873 | ||
| 874 | // Edit Form IDs |
|
| 875 | // |
|
| 876 | // // Queestion (English) |
|
| 877 | // template.find("[data-form-id*='question-english']").find("label").attr("for", "questionEN" + newID); |
|
| 878 | // template.find("[data-form-id*='question-english']").find("input").attr("id", "questionEN" + newID); |
|
| 879 | // |
|
| 880 | // // Queestion (French) |
|
| 881 | // template.find("[data-form-id*='question-french']").find("label").attr("for", "questionFR" + newID); |
|
| 882 | // template.find("[data-form-id*='question-french']").find("input").attr("id", "questionFR" + newID); |
|
| 883 | ||
| 884 | // Append Clone to the Wrapper |
|
| 885 | wrapper.append(template); |
|
| 886 | ||
| 887 | requiredFields(); |
|
| 888 | labelHandlers(); |
|
| 889 | deleteQuestionTrigger(); |
|
| 890 | ||
| 891 | } |
|
| 892 | ||
| 893 | $("#addQuestionButton").on("click", function(e) { |
|
| 894 | ||
| 895 | e.preventDefault(); |
|
| 896 | ||
| 897 | addQuestion(this); |
|
| 898 | ||
| 899 | }); |
|
| 900 | ||
| 901 | $("#addQuestionButton").on("keyup", function(e) { |
|
| 902 | ||
| 903 | if(e.which == 13) { |
|
| 904 | e.preventDefault(); |
|
| 905 | addQuestion(this); |
|
| 906 | } |
|
| 907 | ||
| 908 | }); |
|
| 909 | ||
| 910 | // Question Deletion |
|
| 911 | ||
| 912 | function deleteQuestion(trigger) { |
|
| 913 | ||
| 914 | $(trigger).parents(".manager-jobs__create-question").remove(); |
|
| 915 | ||
| 916 | } |
|
| 917 | ||
| 918 | function deleteQuestionTrigger() { |
|
| 919 | ||
| 920 | $(".manager-jobs__delete-question-button").on("click", function(e) { |
|
| 921 | ||
| 922 | e.preventDefault(); |
|
| 923 | ||
| 924 | deleteQuestion(this); |
|
| 925 | ||
| 926 | }); |
|
| 927 | ||
| 928 | $(".manager-jobs__delete-question-button").on("keyup", function(e) { |
|
| 929 | ||
| 930 | if(e.which == 13) { |
|
| 931 | e.preventDefault(); |
|
| 932 | deleteQuestion(this); |
|
| 933 | } |
|
| 934 | ||
| 935 | }); |
|
| 936 | ||
| 937 | } |
|
| 938 | ||
| 939 | deleteQuestionTrigger(); |
|
| 940 | ||
| 941 | }); |
|
| 942 | ||
| 943 | })(jQuery); |
|
| 944 | ||
| @@ 71-960 (lines=890) @@ | ||
| 68 | /************************************************************************/ |
|
| 69 | /******/ ([ |
|
| 70 | /* 0 */ |
|
| 71 | /***/ (function(module, exports) { |
|
| 72 | ||
| 73 | // ============================================================================= |
|
| 74 | ||
| 75 | // Utilities JavaScript (jQuery) |
|
| 76 | ||
| 77 | // ============================================================================= |
|
| 78 | ||
| 79 | (function ($) { |
|
| 80 | ||
| 81 | // Add isValid() |
|
| 82 | ||
| 83 | $.fn.isValid = function () { |
|
| 84 | return this[0].checkValidity(); |
|
| 85 | }; |
|
| 86 | ||
| 87 | $(document).ready(function () { |
|
| 88 | ||
| 89 | // Accordion Handlers ================================================== |
|
| 90 | ||
| 91 | function accordionTrigger(trigger) { |
|
| 92 | if ($(trigger).parent(".accordion").hasClass("active")) { |
|
| 93 | $(trigger).attr("aria-expanded", "false"); |
|
| 94 | $(trigger).parent(".accordion").removeClass("active"); |
|
| 95 | $(trigger).parent(".accordion").find(".accordion-content").attr("aria-hidden", "true"); |
|
| 96 | } else { |
|
| 97 | $(trigger).attr("aria-expanded", "true"); |
|
| 98 | $(trigger).parent(".accordion").addClass("active"); |
|
| 99 | $(trigger).parent(".accordion").find(".accordion-content").attr("aria-hidden", "false"); |
|
| 100 | } |
|
| 101 | } |
|
| 102 | ||
| 103 | $(document).on("click", ".accordion-trigger", function (e) { |
|
| 104 | ||
| 105 | accordionTrigger(this); |
|
| 106 | }); |
|
| 107 | ||
| 108 | $(document).on("keyup", ".accordion-trigger", function (e) { |
|
| 109 | ||
| 110 | if (e.which == 13) { |
|
| 111 | accordionTrigger(this); |
|
| 112 | } |
|
| 113 | }); |
|
| 114 | ||
| 115 | // Modal Handlers ====================================================== |
|
| 116 | ||
| 117 | function openModal(trigger) { |
|
| 118 | ||
| 119 | var modalID = $(trigger).attr("data-modal-id"); |
|
| 120 | var modal = $(".modal[data-modal-id=" + modalID + "]"); |
|
| 121 | $(".modal-overlay").addClass("active"); |
|
| 122 | modal.addClass("active"); |
|
| 123 | $("body").css("overflow", "hidden"); |
|
| 124 | ||
| 125 | // Tab Items |
|
| 126 | ||
| 127 | var focusableItems = modal.find(":focusable"); |
|
| 128 | ||
| 129 | var firstInput = focusableItems.first(); |
|
| 130 | var lastInput = focusableItems.last(); |
|
| 131 | ||
| 132 | if (modal.find("form").length == 0) { |
|
| 133 | lastInput.focus(); |
|
| 134 | } else { |
|
| 135 | firstInput.focus(); |
|
| 136 | } |
|
| 137 | ||
| 138 | modalTabHandler(firstInput, lastInput); |
|
| 139 | escapeModalHandler(); |
|
| 140 | } |
|
| 141 | ||
| 142 | $(document).on("click", ".modal-trigger", function (e) { |
|
| 143 | ||
| 144 | openModal(this); |
|
| 145 | }); |
|
| 146 | ||
| 147 | $(document).on("keyup", ".modal-trigger", function (e) { |
|
| 148 | ||
| 149 | if (e.which == 13) { |
|
| 150 | openModal(this); |
|
| 151 | } |
|
| 152 | }); |
|
| 153 | ||
| 154 | function closeModal(trigger) { |
|
| 155 | ||
| 156 | $(".modal-overlay").removeClass("active"); |
|
| 157 | $(".modal").removeClass("active"); |
|
| 158 | $("body").css("overflow", "visible"); |
|
| 159 | } |
|
| 160 | ||
| 161 | $(document).on("click", ".modal-cancel-trigger", function (e) { |
|
| 162 | ||
| 163 | closeModal(this); |
|
| 164 | }); |
|
| 165 | ||
| 166 | $(document).on("keyup", ".modal-cancel-trigger", function (e) { |
|
| 167 | ||
| 168 | if (e.which == 13) { |
|
| 169 | closeModal(this); |
|
| 170 | } |
|
| 171 | }); |
|
| 172 | ||
| 173 | // Tab Handler ===================================================== |
|
| 174 | ||
| 175 | function modalTabHandler(first, last) { |
|
| 176 | ||
| 177 | $(document).on("keydown", function (e) { |
|
| 178 | ||
| 179 | var keyCode = e.keyCode || e.which; |
|
| 180 | ||
| 181 | if (keyCode == 9 && !e.shiftKey) { |
|
| 182 | ||
| 183 | if ($(last).is(":focus")) { |
|
| 184 | e.preventDefault(); |
|
| 185 | $(first).focus(); |
|
| 186 | } |
|
| 187 | } else if (keyCode == 9 && e.shiftKey) { |
|
| 188 | ||
| 189 | if ($(first).is(":focus")) { |
|
| 190 | e.preventDefault(); |
|
| 191 | $(last).focus(); |
|
| 192 | } |
|
| 193 | } |
|
| 194 | }); |
|
| 195 | } |
|
| 196 | ||
| 197 | // Escape Handler ================================================== |
|
| 198 | ||
| 199 | function escapeModalHandler() { |
|
| 200 | ||
| 201 | $(document).on("keyup", function (e) { |
|
| 202 | ||
| 203 | if (e.key === 'Escape' || e.key === 'Esc' || e.keyCode === 27) { |
|
| 204 | ||
| 205 | $(".modal-overlay").removeClass("active"); |
|
| 206 | $(".modal").removeClass("active"); |
|
| 207 | $("body").css("overflow", "visible"); |
|
| 208 | ||
| 209 | // FF and compatible |
|
| 210 | if (e.stopPropagation) { |
|
| 211 | e.stopPropagation(); |
|
| 212 | e.preventDefault(); |
|
| 213 | } |
|
| 214 | } |
|
| 215 | }); |
|
| 216 | } |
|
| 217 | ||
| 218 | // Form Handlers ======================================================= |
|
| 219 | ||
| 220 | // Required Fields |
|
| 221 | ||
| 222 | function requiredFields() { |
|
| 223 | $("input:required, textarea:required").each(function (e) { |
|
| 224 | $(this).parent().addClass("required"); |
|
| 225 | $(this).parent().find("label").append("<span class='form__required'><i class='fa fa-asterisk' aria-label='Asterisk'></i></span>"); |
|
| 226 | }); |
|
| 227 | } |
|
| 228 | ||
| 229 | requiredFields(); |
|
| 230 | ||
| 231 | // Label Handers =================================================== |
|
| 232 | ||
| 233 | function labelHandlers() { |
|
| 234 | ||
| 235 | $("[class*='form__input-wrapper'] input, [class*='form__input-wrapper'] textarea").focusin(function (e) { |
|
| 236 | $(this).parent().addClass("active"); |
|
| 237 | }); |
|
| 238 | ||
| 239 | $("[class*='form__input-wrapper'] input, [class*='form__input-wrapper'] textarea").focusout(function (e) { |
|
| 240 | ||
| 241 | // Check for existing value. |
|
| 242 | ||
| 243 | if ($(this).val() == "") { |
|
| 244 | $(this).parent().removeClass("active"); |
|
| 245 | } |
|
| 246 | ||
| 247 | // Check Validity |
|
| 248 | ||
| 249 | if ($(this).isValid() == true) { |
|
| 250 | ||
| 251 | if ($(this).val() == "" || $(this).attr("type") == "password") { |
|
| 252 | $(this).parent().removeClass("valid"); |
|
| 253 | $(this).parent().removeClass("invalid"); |
|
| 254 | } else { |
|
| 255 | $(this).parent().addClass("valid"); |
|
| 256 | $(this).parent().removeClass("invalid"); |
|
| 257 | } |
|
| 258 | } else { |
|
| 259 | ||
| 260 | if ($(this).attr("type") == "password") { |
|
| 261 | return false; |
|
| 262 | } else { |
|
| 263 | $(this).parent().addClass("invalid"); |
|
| 264 | $(this).parent().removeClass("valid"); |
|
| 265 | } |
|
| 266 | } |
|
| 267 | }); |
|
| 268 | } |
|
| 269 | ||
| 270 | labelHandlers(); |
|
| 271 | ||
| 272 | //Individualize template attributes |
|
| 273 | function appendToAttributes(parent, attribute, suffix, conditions) { |
|
| 274 | var selector = "*[" + attribute + "]"; |
|
| 275 | ||
| 276 | //If conditions is set, only modify attributes that also |
|
| 277 | //satisfy that selector |
|
| 278 | if (conditions) { |
|
| 279 | selector = conditions + selector; |
|
| 280 | } |
|
| 281 | ||
| 282 | parent.find(selector).each(function () { |
|
| 283 | $(this).attr(attribute, $(this).attr(attribute) + suffix); |
|
| 284 | }); |
|
| 285 | } |
|
| 286 | ||
| 287 | //Return the next unused data-item-id value |
|
| 288 | function getNextItemId(parent) { |
|
| 289 | var maxId = 0; |
|
| 290 | parent.find("*[data-item-id]").each(function () { |
|
| 291 | var id = parseInt($(this).attr('data-item-id')); |
|
| 292 | if (id > maxId) { |
|
| 293 | maxId = id; |
|
| 294 | } |
|
| 295 | }); |
|
| 296 | return maxId + 1; |
|
| 297 | } |
|
| 298 | ||
| 299 | // Profile List Handlers =============================================== |
|
| 300 | ||
| 301 | // Add Profile Element |
|
| 302 | function addProfileElement(trigger) { |
|
| 303 | ||
| 304 | // Get Parent |
|
| 305 | var parent = $(trigger).parents(".profile-list"); |
|
| 306 | ||
| 307 | // Get List Wrapper |
|
| 308 | var wrapper = parent.find(".profile-element-list"); |
|
| 309 | ||
| 310 | // Set Null to Hidden |
|
| 311 | parent.find(".profile-null").removeClass("active"); |
|
| 312 | ||
| 313 | // Get Template |
|
| 314 | var template = parent.find(".profile-element.template").clone(); |
|
| 315 | ||
| 316 | // Remove Template Class |
|
| 317 | template.removeClass("template"); |
|
| 318 | ||
| 319 | // Get New ID |
|
| 320 | var newId = getNextItemId(wrapper); |
|
| 321 | ||
| 322 | template.attr('data-item-id', newId); |
|
| 323 | ||
| 324 | // Individualize Form IDs and labels |
|
| 325 | appendToAttributes(template, 'id', '_' + newId); |
|
| 326 | appendToAttributes(template, 'for', '_' + newId); |
|
| 327 | ||
| 328 | // Individualize form names, except for submit buttons |
|
| 329 | appendToAttributes(template, 'name', '[' + newId + ']', ':not([name=submit])'); |
|
| 330 | // Individualize values on submit buttons |
|
| 331 | appendToAttributes(template, 'value', '[' + newId + ']', '[name=submit]'); |
|
| 332 | ||
| 333 | // Prepend Clone to the Wrapper |
|
| 334 | wrapper.prepend(template); |
|
| 335 | ||
| 336 | // Reactivate Required Fields |
|
| 337 | requiredFields(); |
|
| 338 | ||
| 339 | // Reactivate Labels |
|
| 340 | labelHandlers(); |
|
| 341 | ||
| 342 | // Reactivate Nested Relatives |
|
| 343 | loadProfileRelatives(); |
|
| 344 | } |
|
| 345 | ||
| 346 | // Click Trigger |
|
| 347 | $(".profile-list__add-element-trigger").on("click", function (e) { |
|
| 348 | ||
| 349 | // Prevent Default Functions |
|
| 350 | e.preventDefault(); |
|
| 351 | ||
| 352 | // Add Profile Elements |
|
| 353 | addProfileElement(this); |
|
| 354 | }); |
|
| 355 | ||
| 356 | // Enter Key Trigger |
|
| 357 | $(".profile-list__add-element-trigger").on("keyup", function (e) { |
|
| 358 | ||
| 359 | if (e.which == 13) { |
|
| 360 | ||
| 361 | // Prevent Default Functions |
|
| 362 | e.preventDefault(); |
|
| 363 | ||
| 364 | // Add Profile Elements |
|
| 365 | addProfileElement(this); |
|
| 366 | } |
|
| 367 | }); |
|
| 368 | ||
| 369 | // Remove Profile Element |
|
| 370 | ||
| 371 | // Add Profile Relative |
|
| 372 | function addProfileRelative(trigger) { |
|
| 373 | ||
| 374 | // Get Parent |
|
| 375 | var parent = $(trigger).parents(".profile-relative-list"); |
|
| 376 | ||
| 377 | // Get List Wrapper |
|
| 378 | var wrapper = parent.find(".profile-relative-list__wrapper"); |
|
| 379 | ||
| 380 | // Set Null to Hidden |
|
| 381 | // parent.find(".profile-null").removeClass("active"); |
|
| 382 | ||
| 383 | // Get Template |
|
| 384 | var template = parent.find(".profile-relative.template").clone(); |
|
| 385 | ||
| 386 | // Remove Template Class |
|
| 387 | template.removeClass("template"); |
|
| 388 | ||
| 389 | // Edit Form IDs |
|
| 390 | ||
| 391 | // Tristan, help! x_x |
|
| 392 | ||
| 393 | // Append Clone to the Wrapper |
|
| 394 | wrapper.append(template); |
|
| 395 | ||
| 396 | // Reactivate Required Fields |
|
| 397 | requiredFields(); |
|
| 398 | ||
| 399 | // Reactivate Labels |
|
| 400 | labelHandlers(); |
|
| 401 | ||
| 402 | // Reactivate Nested Relatives |
|
| 403 | loadProfileRelativeDeletion(); |
|
| 404 | } |
|
| 405 | ||
| 406 | // Load Function |
|
| 407 | function loadProfileRelatives() { |
|
| 408 | ||
| 409 | // Click Trigger |
|
| 410 | $(".profile-relative__add-trigger").off("click"); |
|
| 411 | ||
| 412 | $(".profile-relative__add-trigger").on("click", function (e) { |
|
| 413 | ||
| 414 | // Prevent Default Functions |
|
| 415 | e.preventDefault(); |
|
| 416 | ||
| 417 | // Add Profile Relative |
|
| 418 | addProfileRelative(this); |
|
| 419 | }); |
|
| 420 | ||
| 421 | // Enter Key Trigger |
|
| 422 | $(".profile-relative__add-trigger").off("keyup"); |
|
| 423 | ||
| 424 | $(".profile-relative__add-trigger").on("keyup", function (e) { |
|
| 425 | ||
| 426 | if (e.which == 13) { |
|
| 427 | ||
| 428 | // Prevent Default Functions |
|
| 429 | e.preventDefault(); |
|
| 430 | ||
| 431 | // Add Profile Relative |
|
| 432 | addProfileRelative(this); |
|
| 433 | } |
|
| 434 | }); |
|
| 435 | } |
|
| 436 | ||
| 437 | loadProfileRelatives(); |
|
| 438 | ||
| 439 | // Remove Profile Relative |
|
| 440 | function deleteProfileRelative(trigger) { |
|
| 441 | ||
| 442 | $(trigger).parents(".profile-relative").remove(); |
|
| 443 | } |
|
| 444 | ||
| 445 | // Load Function |
|
| 446 | function loadProfileRelativeDeletion() { |
|
| 447 | ||
| 448 | // Click Trigger |
|
| 449 | $(".profile-relative__remove-trigger").on("click", function (e) { |
|
| 450 | ||
| 451 | // Prevent Default Functions |
|
| 452 | e.preventDefault(); |
|
| 453 | ||
| 454 | // Delete Profile Relative |
|
| 455 | deleteProfileRelative(this); |
|
| 456 | }); |
|
| 457 | ||
| 458 | // Enter Key Trigger |
|
| 459 | $(".profile-relative__remove-trigger").on("keyup", function (e) { |
|
| 460 | ||
| 461 | if (e.which == 13) { |
|
| 462 | ||
| 463 | // Prevent Default Functions |
|
| 464 | e.preventDefault(); |
|
| 465 | ||
| 466 | // Delete Profile Relative |
|
| 467 | deleteProfileRelative(this); |
|
| 468 | } |
|
| 469 | }); |
|
| 470 | } |
|
| 471 | ||
| 472 | loadProfileRelativeDeletion(); |
|
| 473 | ||
| 474 | // Experience Handlers ================================================= |
|
| 475 | ||
| 476 | // Degrees |
|
| 477 | ||
| 478 | function addDegree(trigger) { |
|
| 479 | ||
| 480 | // Get Wrapper |
|
| 481 | var wrapper = $(".application-post__experience-wrapper"); |
|
| 482 | ||
| 483 | // Get Template |
|
| 484 | var template = $(".application-post__accordion--degree.template").clone(); |
|
| 485 | ||
| 486 | // Get New ID |
|
| 487 | var newID = parseInt(wrapper.find("[class*='application-post__accordion--']").last().attr("data-experience-id")) + 1; |
|
| 488 | ||
| 489 | // Remove Template Class |
|
| 490 | template.removeClass("template"); |
|
| 491 | ||
| 492 | // Assign the New ID |
|
| 493 | template.attr("data-experience-id", newID); |
|
| 494 | ||
| 495 | // Edit Form IDs |
|
| 496 | ||
| 497 | // Degree Type |
|
| 498 | template.find("[data-form-id*='experience-degree']").find("label").attr("for", "degree" + newID); |
|
| 499 | template.find("[data-form-id*='experience-degree']").find("select").attr("id", "degree" + newID); |
|
| 500 | ||
| 501 | // Area of Study |
|
| 502 | template.find("[data-form-id*='experience-aos']").find("label").attr("for", "areaOfStudy" + newID); |
|
| 503 | template.find("[data-form-id*='experience-aos']").find("input").attr("id", "areaOfStudy" + newID); |
|
| 504 | ||
| 505 | // Institution |
|
| 506 | template.find("[data-form-id*='experience-institution']").find("label").attr("for", "institution" + newID); |
|
| 507 | template.find("[data-form-id*='experience-institution']").find("input").attr("id", "institution" + newID); |
|
| 508 | ||
| 509 | // Start Date |
|
| 510 | template.find("[data-form-id*='experience-start-date']").find("label").attr("for", "startDate" + newID); |
|
| 511 | template.find("[data-form-id*='experience-start-date']").find("input").attr("id", "startDate" + newID); |
|
| 512 | ||
| 513 | // End Date |
|
| 514 | template.find("[data-form-id*='experience-end-date']").find("label").attr("for", "endDate" + newID); |
|
| 515 | template.find("[data-form-id*='experience-end-date']").find("input").attr("id", "endDate" + newID); |
|
| 516 | ||
| 517 | // Append Clone to the Wrapper |
|
| 518 | wrapper.append(template); |
|
| 519 | ||
| 520 | requiredFields(); |
|
| 521 | labelHandlers(); |
|
| 522 | } |
|
| 523 | ||
| 524 | $("#addDegreeButton").on("click", function (e) { |
|
| 525 | ||
| 526 | e.preventDefault(); |
|
| 527 | ||
| 528 | addDegree(this); |
|
| 529 | }); |
|
| 530 | ||
| 531 | $("#addDegreeButton").on("keyup", function (e) { |
|
| 532 | ||
| 533 | if (e.which == 13) { |
|
| 534 | e.preventDefault(); |
|
| 535 | addDegree(this); |
|
| 536 | } |
|
| 537 | }); |
|
| 538 | ||
| 539 | // Courses |
|
| 540 | ||
| 541 | function addCourse(trigger) { |
|
| 542 | ||
| 543 | // Get Wrapper |
|
| 544 | var wrapper = $(".application-post__experience-wrapper"); |
|
| 545 | ||
| 546 | // Get Template |
|
| 547 | var template = $(".application-post__accordion--course.template").clone(); |
|
| 548 | ||
| 549 | // Get New ID |
|
| 550 | var newID = parseInt(wrapper.find("[class*='application-post__accordion--']").last().attr("data-experience-id")) + 1; |
|
| 551 | ||
| 552 | // Remove Template Class |
|
| 553 | template.removeClass("template"); |
|
| 554 | ||
| 555 | // Assign the New ID |
|
| 556 | template.attr("data-experience-id", newID); |
|
| 557 | ||
| 558 | // Edit Form IDs |
|
| 559 | ||
| 560 | // Course Name |
|
| 561 | template.find("[data-form-id*='experience-course-name']").find("label").attr("for", "courseName" + newID); |
|
| 562 | template.find("[data-form-id*='experience-course-name']").find("input").attr("id", "courseName" + newID); |
|
| 563 | ||
| 564 | // Institution |
|
| 565 | template.find("[data-form-id*='experience-institution']").find("label").attr("for", "institution" + newID); |
|
| 566 | template.find("[data-form-id*='experience-institution']").find("input").attr("id", "institution" + newID); |
|
| 567 | ||
| 568 | // Start Date |
|
| 569 | template.find("[data-form-id*='experience-start-date']").find("label").attr("for", "startDate" + newID); |
|
| 570 | template.find("[data-form-id*='experience-start-date']").find("input").attr("id", "startDate" + newID); |
|
| 571 | ||
| 572 | // End Date |
|
| 573 | template.find("[data-form-id*='experience-end-date']").find("label").attr("for", "endDate" + newID); |
|
| 574 | template.find("[data-form-id*='experience-end-date']").find("input").attr("id", "endDate" + newID); |
|
| 575 | ||
| 576 | // Append Clone to the Wrapper |
|
| 577 | wrapper.append(template); |
|
| 578 | ||
| 579 | requiredFields(); |
|
| 580 | labelHandlers(); |
|
| 581 | } |
|
| 582 | ||
| 583 | $("#addCourseButton").on("click", function (e) { |
|
| 584 | ||
| 585 | e.preventDefault(); |
|
| 586 | ||
| 587 | addCourse(this); |
|
| 588 | }); |
|
| 589 | ||
| 590 | $("#addCourseButton").on("keyup", function (e) { |
|
| 591 | ||
| 592 | if (e.which == 13) { |
|
| 593 | e.preventDefault(); |
|
| 594 | addCourse(this); |
|
| 595 | } |
|
| 596 | }); |
|
| 597 | ||
| 598 | // Work |
|
| 599 | ||
| 600 | function addWork(trigger) { |
|
| 601 | ||
| 602 | // Get Wrapper |
|
| 603 | var wrapper = $(".application-post__experience-wrapper"); |
|
| 604 | ||
| 605 | // Get Template |
|
| 606 | var template = $(".application-post__accordion--work.template").clone(); |
|
| 607 | ||
| 608 | // Get New ID |
|
| 609 | var newID = parseInt(wrapper.find("[class*='application-post__accordion--']").last().attr("data-experience-id")) + 1; |
|
| 610 | ||
| 611 | // Remove Template Class |
|
| 612 | template.removeClass("template"); |
|
| 613 | ||
| 614 | // Assign the New ID |
|
| 615 | template.attr("data-experience-id", newID); |
|
| 616 | ||
| 617 | // Edit Form IDs |
|
| 618 | ||
| 619 | // Role |
|
| 620 | template.find("[data-form-id*='experience-course-name']").find("label").attr("for", "role" + newID); |
|
| 621 | template.find("[data-form-id*='experience-course-name']").find("input").attr("id", "role" + newID); |
|
| 622 | ||
| 623 | // Group / Company |
|
| 624 | template.find("[data-form-id*='experience-institution']").find("label").attr("for", "group" + newID); |
|
| 625 | template.find("[data-form-id*='experience-institution']").find("input").attr("id", "group" + newID); |
|
| 626 | ||
| 627 | // Description |
|
| 628 | template.find("[data-form-id*='experience-description']").find("label").attr("for", "description" + newID); |
|
| 629 | template.find("[data-form-id*='experience-description']").find("input").attr("id", "description" + newID); |
|
| 630 | ||
| 631 | // Start Date |
|
| 632 | template.find("[data-form-id*='experience-start-date']").find("label").attr("for", "startDate" + newID); |
|
| 633 | template.find("[data-form-id*='experience-start-date']").find("input").attr("id", "startDate" + newID); |
|
| 634 | ||
| 635 | // End Date |
|
| 636 | template.find("[data-form-id*='experience-end-date']").find("label").attr("for", "endDate" + newID); |
|
| 637 | template.find("[data-form-id*='experience-end-date']").find("input").attr("id", "endDate" + newID); |
|
| 638 | ||
| 639 | // Append Clone to the Wrapper |
|
| 640 | wrapper.append(template); |
|
| 641 | ||
| 642 | requiredFields(); |
|
| 643 | labelHandlers(); |
|
| 644 | } |
|
| 645 | ||
| 646 | $("#addWorkButton").on("click", function (e) { |
|
| 647 | ||
| 648 | e.preventDefault(); |
|
| 649 | ||
| 650 | addWork(this); |
|
| 651 | }); |
|
| 652 | ||
| 653 | $("#addWorkButton").on("keyup", function (e) { |
|
| 654 | ||
| 655 | if (e.which == 13) { |
|
| 656 | e.preventDefault(); |
|
| 657 | addWork(this); |
|
| 658 | } |
|
| 659 | }); |
|
| 660 | ||
| 661 | // Create Job Handlers ================================================= |
|
| 662 | ||
| 663 | // Tasks |
|
| 664 | ||
| 665 | function addTask(trigger) { |
|
| 666 | ||
| 667 | // Get Wrapper |
|
| 668 | var wrapper = $(".manager-jobs__create-task-wrapper"); |
|
| 669 | ||
| 670 | // Get Template |
|
| 671 | var template = $(".manager-jobs__create-task.template").clone(); |
|
| 672 | ||
| 673 | console.log(wrapper.find(".manager-jobs__create-task")); |
|
| 674 | ||
| 675 | // Get New ID |
|
| 676 | if (wrapper.find(".manager-jobs__create-task").length == 0) { |
|
| 677 | var newID = parseInt(template.attr("data-task-id")) + 1; |
|
| 678 | } else { |
|
| 679 | var newID = parseInt(wrapper.find("[class*='manager-jobs__create-task']").last().attr("data-task-id")) + 1; |
|
| 680 | } |
|
| 681 | ||
| 682 | // Remove Template Class |
|
| 683 | template.removeClass("template"); |
|
| 684 | ||
| 685 | // Assign the New ID |
|
| 686 | template.attr("data-task-id", newID); |
|
| 687 | ||
| 688 | // Add newID as suffix to all "id" and "for" attributes |
|
| 689 | template.find("*[id]").each(function () { |
|
| 690 | $(this).attr("id", this.id + newID); |
|
| 691 | }); |
|
| 692 | template.find("*[for]").each(function () { |
|
| 693 | $(this).attr("for", $(this).attr("for") + newID); |
|
| 694 | }); |
|
| 695 | ||
| 696 | // Replace :id with newID in all form names |
|
| 697 | template.find("*[name]").each(function () { |
|
| 698 | $(this).attr('name', $(this).attr("name").replace(":id", newID)); |
|
| 699 | }); |
|
| 700 | ||
| 701 | // Task (English) |
|
| 702 | //template.find("[data-form-id*='task-english']").find("label").attr("for", "taskEN" + newID); |
|
| 703 | //template.find("[data-form-id*='task-english']").find("input").attr("id", "taskEN" + newID); |
|
| 704 | ||
| 705 | // Task (French) |
|
| 706 | //template.find("[data-form-id*='task-french']").find("label").attr("for", "taskFR" + newID); |
|
| 707 | //template.find("[data-form-id*='task-french']").find("input").attr("id", "taskFR" + newID); |
|
| 708 | ||
| 709 | // Append Clone to the Wrapper |
|
| 710 | wrapper.append(template); |
|
| 711 | ||
| 712 | requiredFields(); |
|
| 713 | labelHandlers(); |
|
| 714 | deleteTaskTrigger(); |
|
| 715 | } |
|
| 716 | ||
| 717 | $("#addTaskButton").on("click", function (e) { |
|
| 718 | ||
| 719 | e.preventDefault(); |
|
| 720 | ||
| 721 | addTask(this); |
|
| 722 | }); |
|
| 723 | ||
| 724 | $("#addTaskButton").on("keyup", function (e) { |
|
| 725 | ||
| 726 | if (e.which == 13) { |
|
| 727 | e.preventDefault(); |
|
| 728 | addTask(this); |
|
| 729 | } |
|
| 730 | }); |
|
| 731 | ||
| 732 | // Task Deletion |
|
| 733 | ||
| 734 | function deleteTask(trigger) { |
|
| 735 | ||
| 736 | $(trigger).parents(".manager-jobs__create-task").remove(); |
|
| 737 | } |
|
| 738 | ||
| 739 | function deleteTaskTrigger() { |
|
| 740 | ||
| 741 | $(".manager-jobs__delete-task-button").on("click", function (e) { |
|
| 742 | ||
| 743 | e.preventDefault(); |
|
| 744 | ||
| 745 | deleteTask(this); |
|
| 746 | }); |
|
| 747 | ||
| 748 | $(".manager-jobs__delete-task-button").on("keyup", function (e) { |
|
| 749 | ||
| 750 | if (e.which == 13) { |
|
| 751 | e.preventDefault(); |
|
| 752 | deleteTask(this); |
|
| 753 | } |
|
| 754 | }); |
|
| 755 | } |
|
| 756 | ||
| 757 | deleteTaskTrigger(); |
|
| 758 | ||
| 759 | // Skills |
|
| 760 | ||
| 761 | function addSkill(trigger) { |
|
| 762 | ||
| 763 | // Get Parent |
|
| 764 | var parent = $(trigger).parents(".manager-jobs__skill-wrapper"); |
|
| 765 | ||
| 766 | // Get Wrapper |
|
| 767 | var wrapper = parent.find(".manager-jobs__create-skill-wrapper"); |
|
| 768 | ||
| 769 | // Get Template |
|
| 770 | var template = parent.find(".manager-jobs__create-skill.template").clone(); |
|
| 771 | ||
| 772 | console.log(wrapper.find(".manager-jobs__create-skill")); |
|
| 773 | ||
| 774 | // Get New ID |
|
| 775 | if (wrapper.find(".manager-jobs__create-skill").length == 0) { |
|
| 776 | var newID = parseInt(template.attr("data-skill-id")) + 1; |
|
| 777 | } else { |
|
| 778 | var newID = parseInt(wrapper.find("[class*='manager-jobs__create-skill']").last().attr("data-skill-id")) + 1; |
|
| 779 | } |
|
| 780 | ||
| 781 | // Remove Template Class |
|
| 782 | template.removeClass("template"); |
|
| 783 | ||
| 784 | // Assign the New ID |
|
| 785 | template.attr("data-skill-id", newID); |
|
| 786 | ||
| 787 | // Add newID as suffix to all "id" and "for" attributes |
|
| 788 | template.find("*[id]").each(function () { |
|
| 789 | $(this).attr("id", this.id + newID); |
|
| 790 | }); |
|
| 791 | template.find("*[for]").each(function () { |
|
| 792 | $(this).attr("for", $(this).attr("for") + newID); |
|
| 793 | }); |
|
| 794 | ||
| 795 | // Replace :id with newID in all form names |
|
| 796 | template.find("*[name]").each(function () { |
|
| 797 | $(this).attr('name', $(this).attr("name").replace(":id", newID)); |
|
| 798 | }); |
|
| 799 | ||
| 800 | // Edit Form IDs |
|
| 801 | // |
|
| 802 | // // Queestion (English) |
|
| 803 | // template.find("[data-form-id*='question-english']").find("label").attr("for", "questionEN" + newID); |
|
| 804 | // template.find("[data-form-id*='question-english']").find("input").attr("id", "questionEN" + newID); |
|
| 805 | // |
|
| 806 | // // Queestion (French) |
|
| 807 | // template.find("[data-form-id*='question-french']").find("label").attr("for", "questionFR" + newID); |
|
| 808 | // template.find("[data-form-id*='question-french']").find("input").attr("id", "questionFR" + newID); |
|
| 809 | ||
| 810 | // Append Clone to the Wrapper |
|
| 811 | wrapper.append(template); |
|
| 812 | ||
| 813 | requiredFields(); |
|
| 814 | labelHandlers(); |
|
| 815 | deleteSkillTrigger(); |
|
| 816 | } |
|
| 817 | ||
| 818 | $(".manager-jobs__add-skill-button").on("click", function (e) { |
|
| 819 | ||
| 820 | e.preventDefault(); |
|
| 821 | ||
| 822 | addSkill(this); |
|
| 823 | }); |
|
| 824 | ||
| 825 | $(".manager-jobs__add-skill-button").on("keyup", function (e) { |
|
| 826 | ||
| 827 | if (e.which == 13) { |
|
| 828 | e.preventDefault(); |
|
| 829 | addSkill(this); |
|
| 830 | } |
|
| 831 | }); |
|
| 832 | ||
| 833 | // Skill Deletion |
|
| 834 | ||
| 835 | function deleteSkill(trigger) { |
|
| 836 | ||
| 837 | $(trigger).parents(".manager-jobs__create-skill").remove(); |
|
| 838 | } |
|
| 839 | ||
| 840 | function deleteSkillTrigger() { |
|
| 841 | ||
| 842 | $(".manager-jobs__delete-skill-button").on("click", function (e) { |
|
| 843 | ||
| 844 | e.preventDefault(); |
|
| 845 | ||
| 846 | deleteSkill(this); |
|
| 847 | }); |
|
| 848 | ||
| 849 | $(".manager-jobs__delete-skill-button").on("keyup", function (e) { |
|
| 850 | ||
| 851 | if (e.which == 13) { |
|
| 852 | e.preventDefault(); |
|
| 853 | deleteSkill(this); |
|
| 854 | } |
|
| 855 | }); |
|
| 856 | } |
|
| 857 | ||
| 858 | deleteSkillTrigger(); |
|
| 859 | ||
| 860 | // Questions |
|
| 861 | ||
| 862 | function addQuestion(trigger) { |
|
| 863 | ||
| 864 | // Get Wrapper |
|
| 865 | var wrapper = $(".manager-jobs__create-question-wrapper"); |
|
| 866 | ||
| 867 | // Get Template |
|
| 868 | var template = $(".manager-jobs__create-question.template").clone(); |
|
| 869 | ||
| 870 | console.log(wrapper.find(".manager-jobs__create-question")); |
|
| 871 | ||
| 872 | // Get New ID |
|
| 873 | if (wrapper.find(".manager-jobs__create-question").length == 0) { |
|
| 874 | var newID = parseInt(template.attr("data-question-id")) + 1; |
|
| 875 | } else { |
|
| 876 | var newID = parseInt(wrapper.find("[class*='manager-jobs__create-question']").last().attr("data-question-id")) + 1; |
|
| 877 | } |
|
| 878 | ||
| 879 | // Remove Template Class |
|
| 880 | template.removeClass("template"); |
|
| 881 | ||
| 882 | // Assign the New ID |
|
| 883 | template.attr("data-question-id", newID); |
|
| 884 | ||
| 885 | // Add newID as suffix to all "id" and "for" attributes |
|
| 886 | template.find("*[id]").each(function () { |
|
| 887 | $(this).attr("id", this.id + newID); |
|
| 888 | }); |
|
| 889 | template.find("*[for]").each(function () { |
|
| 890 | $(this).attr("for", $(this).attr("for") + newID); |
|
| 891 | }); |
|
| 892 | ||
| 893 | // Replace :id with newID in all form names |
|
| 894 | template.find("*[name]").each(function () { |
|
| 895 | $(this).attr('name', $(this).attr("name").replace(":id", newID)); |
|
| 896 | }); |
|
| 897 | ||
| 898 | // Edit Form IDs |
|
| 899 | // |
|
| 900 | // // Queestion (English) |
|
| 901 | // template.find("[data-form-id*='question-english']").find("label").attr("for", "questionEN" + newID); |
|
| 902 | // template.find("[data-form-id*='question-english']").find("input").attr("id", "questionEN" + newID); |
|
| 903 | // |
|
| 904 | // // Queestion (French) |
|
| 905 | // template.find("[data-form-id*='question-french']").find("label").attr("for", "questionFR" + newID); |
|
| 906 | // template.find("[data-form-id*='question-french']").find("input").attr("id", "questionFR" + newID); |
|
| 907 | ||
| 908 | // Append Clone to the Wrapper |
|
| 909 | wrapper.append(template); |
|
| 910 | ||
| 911 | requiredFields(); |
|
| 912 | labelHandlers(); |
|
| 913 | deleteQuestionTrigger(); |
|
| 914 | } |
|
| 915 | ||
| 916 | $("#addQuestionButton").on("click", function (e) { |
|
| 917 | ||
| 918 | e.preventDefault(); |
|
| 919 | ||
| 920 | addQuestion(this); |
|
| 921 | }); |
|
| 922 | ||
| 923 | $("#addQuestionButton").on("keyup", function (e) { |
|
| 924 | ||
| 925 | if (e.which == 13) { |
|
| 926 | e.preventDefault(); |
|
| 927 | addQuestion(this); |
|
| 928 | } |
|
| 929 | }); |
|
| 930 | ||
| 931 | // Question Deletion |
|
| 932 | ||
| 933 | function deleteQuestion(trigger) { |
|
| 934 | ||
| 935 | $(trigger).parents(".manager-jobs__create-question").remove(); |
|
| 936 | } |
|
| 937 | ||
| 938 | function deleteQuestionTrigger() { |
|
| 939 | ||
| 940 | $(".manager-jobs__delete-question-button").on("click", function (e) { |
|
| 941 | ||
| 942 | e.preventDefault(); |
|
| 943 | ||
| 944 | deleteQuestion(this); |
|
| 945 | }); |
|
| 946 | ||
| 947 | $(".manager-jobs__delete-question-button").on("keyup", function (e) { |
|
| 948 | ||
| 949 | if (e.which == 13) { |
|
| 950 | e.preventDefault(); |
|
| 951 | deleteQuestion(this); |
|
| 952 | } |
|
| 953 | }); |
|
| 954 | } |
|
| 955 | ||
| 956 | deleteQuestionTrigger(); |
|
| 957 | }); |
|
| 958 | })(jQuery); |
|
| 959 | ||
| 960 | /***/ }), |
|
| 961 | /* 1 */, |
|
| 962 | /* 2 */, |
|
| 963 | /* 3 */ |
|