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