Completed
Push — dev ( 00844f...8f8cd7 )
by Gray
08:35 queued 01:57
created

app.js ➔ ... ➔ $(document).keydown   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 18
Code Lines 10

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
eloc 10
dl 18
loc 18
rs 8
c 0
b 0
f 0
cc 7
nc 5
nop 1
1 View Code Duplication
/******/ (function(modules) { // webpackBootstrap
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
/******/ 	// The module cache
3
/******/ 	var installedModules = {};
4
/******/
5
/******/ 	// The require function
6
/******/ 	function __webpack_require__(moduleId) {
7
/******/
8
/******/ 		// Check if module is in cache
9
/******/ 		if(installedModules[moduleId])
10
/******/ 			return installedModules[moduleId].exports;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
11
/******/
12
/******/ 		// Create a new module (and put it into the cache)
13
/******/ 		var module = installedModules[moduleId] = {
14
/******/ 			i: moduleId,
15
/******/ 			l: false,
16
/******/ 			exports: {}
17
/******/ 		};
18
/******/
19
/******/ 		// Execute the module function
20
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
21
/******/
22
/******/ 		// Flag the module as loaded
23
/******/ 		module.l = true;
24
/******/
25
/******/ 		// Return the exports of the module
26
/******/ 		return module.exports;
27
/******/ 	}
28
/******/
29
/******/
30
/******/ 	// expose the modules object (__webpack_modules__)
31
/******/ 	__webpack_require__.m = modules;
32
/******/
33
/******/ 	// expose the module cache
34
/******/ 	__webpack_require__.c = installedModules;
35
/******/
36
/******/ 	// identity function for calling harmony imports with the correct context
37
/******/ 	__webpack_require__.i = function(value) { return value; };
38
/******/
39
/******/ 	// define getter function for harmony exports
40
/******/ 	__webpack_require__.d = function(exports, name, getter) {
41
/******/ 		if(!__webpack_require__.o(exports, name)) {
42
/******/ 			Object.defineProperty(exports, name, {
43
/******/ 				configurable: false,
44
/******/ 				enumerable: true,
45
/******/ 				get: getter
46
/******/ 			});
47
/******/ 		}
48
/******/ 	};
49
/******/
50
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
51
/******/ 	__webpack_require__.n = function(module) {
52
/******/ 		var getter = module && module.__esModule ?
53
/******/ 			function getDefault() { return module['default']; } :
54
/******/ 			function getModuleExports() { return module; };
55
/******/ 		__webpack_require__.d(getter, 'a', getter);
56
/******/ 		return getter;
57
/******/ 	};
58
/******/
59
/******/ 	// Object.prototype.hasOwnProperty.call
60
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
61
/******/
62
/******/ 	// __webpack_public_path__
63
/******/ 	__webpack_require__.p = "./";
64
/******/
65
/******/ 	// Load entry module and return exports
66
/******/ 	return __webpack_require__(__webpack_require__.s = 4);
67
/******/ })
68
/************************************************************************/
69
/******/ ([
70
/* 0 */
71 View Code Duplication
/***/ (function(module, exports) {
0 ignored issues
show
Unused Code introduced by
The parameter exports is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter module is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
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) {
0 ignored issues
show
Best Practice introduced by
Comparing modal.find("form").length to 0 using the == operator is not safe. Consider using === instead.
Loading history...
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) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
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) {
0 ignored issues
show
Unused Code introduced by
The parameter trigger is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
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) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
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) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
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) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
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) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
250
                                                                                $(this).parent().addClass("active");
251
                                                            });
252
253
                                                            $("[class*='form__input-wrapper'] input, [class*='form__input-wrapper'] textarea").focusout(function (e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
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) {
0 ignored issues
show
Best Practice introduced by
Comparing $(this).isValid() to true using the == operator is not safe. Consider using === instead.
Loading history...
264
265
                                                                                                    if ($(this).val() == "" || $(this).attr("type") == "password") {
266
                                                                                                                        $(this).parent().removeClass("valid");
267
                                                                                                                        $(this).parent().removeClass("invalid");
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
268
                                                                                                    } else {
269
                                                                                                                        $(this).parent().addClass("valid");
270
                                                                                                                        $(this).parent().removeClass("invalid");
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
271
                                                                                                    }
272
                                                                                } else {
273
274
                                                                                                    if ($(this).attr("type") == "password") {
275
                                                                                                                        return false;
276
                                                                                                    } else {
0 ignored issues
show
Comprehensibility introduced by
else is not necessary here since all if branches return, consider removing it to reduce nesting and make code more readable.
Loading history...
277
                                                                                                                        $(this).parent().addClass("invalid");
278
                                                                                                                        $(this).parent().removeClass("valid");
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
279
                                                                                                    }
280
                                                                                }
281
                                                            });
282
                                        }
283
284
                                        labelHandlers();
285
286
                                        // Individualizing repeater name and id attributes======================
287
288
                                        //Individualize template attributes
289
                                        function appendToAttributes(parent, attribute, suffix) {
0 ignored issues
show
introduced by
The function appendToAttributes does not seem to be used and can be removed.
Loading history...
290
                                                            var conditions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
291
292
                                                            var selector = "*[" + attribute + "]";
293
294
                                                            //If conditions is set, only modify attributes that also
295
                                                            //satisfy that selector
296
                                                            if (conditions) {
297
                                                                                selector = conditions + selector;
298
                                                            }
299
300
                                                            parent.find(selector).each(function () {
301
                                                                                $(this).attr(attribute, $(this).attr(attribute) + suffix);
302
                                                            });
303
                                        }
304
305
                                        //Individualize template attributes
306
                                        function replaceInAttributes(parent, attribute, oldString, newString) {
307
                                                            var conditions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
308
309
                                                            var selector = "*[" + attribute + "]";
310
311
                                                            //If conditions is set, only modify attributes that also
312
                                                            //satisfy that selector
313
                                                            if (conditions) {
314
                                                                                selector = conditions + selector;
315
                                                            }
316
317
                                                            parent.find(selector).each(function () {
318
                                                                                //replaces only the first instance of a match in a string
319
                                                                                $(this).attr(attribute, $(this).attr(attribute).replace(oldString, newString));
320
                                                            });
321
                                        }
322
323
                                        //Return the next unused idAttr value
324
                                        function getNextItemId(parent) {
325
                                                            var idAttr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "data-item-id";
326
327
                                                            var maxId = 0;
328
                                                            parent.find("*[" + idAttr + "]").each(function () {
329
                                                                                var id = parseInt($(this).attr(idAttr));
330
                                                                                if (id > maxId) {
331
                                                                                                    maxId = id;
332
                                                                                }
333
                                                            });
334
                                                            return maxId + 1;
335
                                        }
336
337
                                        //The all in one function to set proper ids and form names
338
                                        function individualizeFormIdsAndNames(template, wrapper) {
339
                                                            // Get New ID
340
                                                            var newId = getNextItemId(wrapper);
341
342
                                                            //Set date-item-id, used to track which newId's are taken
343
                                                            template.attr('data-item-id', newId);
344
345
                                                            //Differentiate real forms from templates
346
347
                                                            // filter, if we only want to affect certain results
348
                                                            var filter = '';
349
350
                                                            replaceInAttributes(template, 'id', ':template', 'new', filter);
351
                                                            replaceInAttributes(template, 'for', ':template', 'new', filter);
352
                                                            replaceInAttributes(template, 'name', ':template', 'new', filter);
353
                                                            replaceInAttributes(template, 'submit', ':template', 'new', filter);
354
                                                            replaceInAttributes(template, 'value', ':template', 'new', filter + '[name=submit]');
355
356
                                                            replaceInAttributes(template, 'id', ':id', newId, filter);
357
                                                            replaceInAttributes(template, 'for', ':id', newId, filter);
358
                                                            replaceInAttributes(template, 'name', ':id', newId, filter);
359
                                                            replaceInAttributes(template, 'submit', ':id', newId, filter);
360
                                                            replaceInAttributes(template, 'value', ':id', newId, filter + '[name=submit]');
361
                                        }
362
363
                                        // Profile List Handlers ===============================================
364
365
                                        // Add Profile Element
366
                                        function addProfileElement(trigger) {
367
368
                                                            // Get Parent
369
                                                            var parent = $(trigger).parents(".profile-list");
370
371
                                                            // Get List Wrapper
372
                                                            var wrapper = parent.find(".profile-element-list");
373
374
                                                            // Set Null to Hidden
375
                                                            parent.find(".profile-null").removeClass("active");
376
377
                                                            // Get Template
378
                                                            var template = parent.find(".profile-element.template").clone();
379
380
                                                            // Remove Template Class
381
                                                            template.removeClass("template");
382
383
                                                            //Set ids and form names to be unique
384
                                                            individualizeFormIdsAndNames(template, wrapper);
385
386
                                                            // Prepend Clone to the Wrapper
387
                                                            wrapper.prepend(template);
388
389
                                                            // Reactivate Required Fields
390
                                                            requiredFields();
391
392
                                                            // Reactivate Labels
393
                                                            labelHandlers();
394
395
                                                            // Reactivate Nested Relatives
396
                                                            loadProfileRelatives();
397
                                        }
398
399
                                        // Click Trigger
400
                                        $(".profile-list__add-element-trigger").on("click", function (e) {
401
402
                                                            // Prevent Default Functions
403
                                                            e.preventDefault();
404
405
                                                            // Add Profile Elements
406
                                                            addProfileElement(this);
407
                                        });
408
409
                                        // Enter Key Trigger
410
                                        $(".profile-list__add-element-trigger").on("keyup", function (e) {
411
412
                                                            if (e.which == 13) {
413
414
                                                                                // Prevent Default Functions
415
                                                                                e.preventDefault();
416
417
                                                                                // Add Profile Elements
418
                                                                                addProfileElement(this);
419
                                                            }
420
                                        });
421
422
                                        // Remove Profile Element
423
424
                                        // Add Profile Relative
425
                                        function addProfileRelative(trigger) {
426
427
                                                            // Get Parent
428
                                                            var parent = $(trigger).parents(".profile-relative-list");
429
430
                                                            // Get List Wrapper
431
                                                            var wrapper = parent.find(".profile-relative-list__wrapper");
432
433
                                                            // Set Null to Hidden
434
                                                            // parent.find(".profile-null").removeClass("active");
435
436
                                                            // Get Template
437
                                                            var template = parent.find(".profile-relative.template").clone();
438
439
                                                            // Remove Template Class
440
                                                            template.removeClass("template");
441
442
                                                            //Set ids and form names to be unique
443
                                                            individualizeFormIdsAndNames(template, wrapper);
444
445
                                                            // Append Clone to the Wrapper
446
                                                            wrapper.append(template);
447
448
                                                            // Reactivate Required Fields
449
                                                            requiredFields();
450
451
                                                            // Reactivate Labels
452
                                                            labelHandlers();
453
454
                                                            // Reactivate Nested Relatives
455
                                                            loadProfileRelativeDeletion();
456
                                        }
457
458
                                        // Load Function
459
                                        function loadProfileRelatives() {
460
461
                                                            // Click Trigger
462
                                                            $(".profile-relative__add-trigger").off("click");
463
464
                                                            $(".profile-relative__add-trigger").on("click", function (e) {
465
466
                                                                                // Prevent Default Functions
467
                                                                                e.preventDefault();
468
469
                                                                                // Add Profile Relative
470
                                                                                addProfileRelative(this);
471
                                                            });
472
473
                                                            // Enter Key Trigger
474
                                                            $(".profile-relative__add-trigger").off("keyup");
475
476
                                                            $(".profile-relative__add-trigger").on("keyup", function (e) {
477
478
                                                                                if (e.which == 13) {
479
480
                                                                                                    // Prevent Default Functions
481
                                                                                                    e.preventDefault();
482
483
                                                                                                    // Add Profile Relative
484
                                                                                                    addProfileRelative(this);
485
                                                                                }
486
                                                            });
487
                                        }
488
489
                                        loadProfileRelatives();
490
491
                                        // Remove Profile Relative
492
                                        function deleteProfileRelative(trigger) {
493
494
                                                            $(trigger).parents(".profile-relative").remove();
495
                                        }
496
497
                                        // Load Function
498
                                        function loadProfileRelativeDeletion() {
499
500
                                                            // Click Trigger
501
                                                            $(".profile-relative__remove-trigger").on("click", function (e) {
502
503
                                                                                // Prevent Default Functions
504
                                                                                e.preventDefault();
505
506
                                                                                // Delete Profile Relative
507
                                                                                deleteProfileRelative(this);
508
                                                            });
509
510
                                                            // Enter Key Trigger
511
                                                            $(".profile-relative__remove-trigger").on("keyup", function (e) {
512
513
                                                                                if (e.which == 13) {
514
515
                                                                                                    // Prevent Default Functions
516
                                                                                                    e.preventDefault();
517
518
                                                                                                    // Delete Profile Relative
519
                                                                                                    deleteProfileRelative(this);
520
                                                                                }
521
                                                            });
522
                                        }
523
524
                                        loadProfileRelativeDeletion();
525
526
                                        // Experience Handlers =================================================
527
528
                                        // Degrees
529
530
                                        function addDegree(trigger) {
0 ignored issues
show
Unused Code introduced by
The parameter trigger is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
531
532
                                                            // Get Wrapper
533
                                                            var wrapper = $(".application-post__experience-wrapper");
534
535
                                                            // Get Template
536
                                                            var template = $(".application-post__accordion--degree.template").clone();
537
538
                                                            // Remove Template Class
539
                                                            template.removeClass("template");
540
541
                                                            //Set ids and form names to be unique
542
                                                            individualizeFormIdsAndNames(template, wrapper);
543
544
                                                            // Append Clone to the Wrapper
545
                                                            wrapper.append(template);
546
547
                                                            requiredFields();
548
                                                            labelHandlers();
549
                                        }
550
551
                                        $("#addDegreeButton").on("click", function (e) {
552
553
                                                            e.preventDefault();
554
555
                                                            addDegree(this);
556
                                        });
557
558
                                        $("#addDegreeButton").on("keyup", function (e) {
559
560
                                                            if (e.which == 13) {
561
                                                                                e.preventDefault();
562
                                                                                addDegree(this);
563
                                                            }
564
                                        });
565
566
                                        // Courses
567
568
                                        function addCourse(trigger) {
0 ignored issues
show
Unused Code introduced by
The parameter trigger is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
569
570
                                                            // Get Wrapper
571
                                                            var wrapper = $(".application-post__experience-wrapper");
572
573
                                                            // Get Template
574
                                                            var template = $(".application-post__accordion--course.template").clone();
575
576
                                                            // Remove Template Class
577
                                                            template.removeClass("template");
578
579
                                                            //Set ids and form names to be unique
580
                                                            individualizeFormIdsAndNames(template, wrapper);
581
582
                                                            // Append Clone to the Wrapper
583
                                                            wrapper.append(template);
584
585
                                                            requiredFields();
586
                                                            labelHandlers();
587
                                        }
588
589
                                        $("#addCourseButton").on("click", function (e) {
590
591
                                                            e.preventDefault();
592
593
                                                            addCourse(this);
594
                                        });
595
596
                                        $("#addCourseButton").on("keyup", function (e) {
597
598
                                                            if (e.which == 13) {
599
                                                                                e.preventDefault();
600
                                                                                addCourse(this);
601
                                                            }
602
                                        });
603
604
                                        // Work
605
606
                                        function addWork(trigger) {
0 ignored issues
show
Unused Code introduced by
The parameter trigger is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
607
608
                                                            // Get Wrapper
609
                                                            var wrapper = $(".application-post__experience-wrapper");
610
611
                                                            // Get Template
612
                                                            var template = $(".application-post__accordion--work.template").clone();
613
614
                                                            // Remove Template Class
615
                                                            template.removeClass("template");
616
617
                                                            //Set ids and form names to be unique
618
                                                            individualizeFormIdsAndNames(template, wrapper);
619
620
                                                            // Append Clone to the Wrapper
621
                                                            wrapper.append(template);
622
623
                                                            requiredFields();
624
                                                            labelHandlers();
625
                                        }
626
627
                                        $("#addWorkButton").on("click", function (e) {
628
629
                                                            e.preventDefault();
630
631
                                                            addWork(this);
632
                                        });
633
634
                                        $("#addWorkButton").on("keyup", function (e) {
635
636
                                                            if (e.which == 13) {
637
                                                                                e.preventDefault();
638
                                                                                addWork(this);
639
                                                            }
640
                                        });
641
642
                                        // Create Job Handlers =================================================
643
644
                                        // Tasks
645
646
                                        function addTask(trigger) {
0 ignored issues
show
Unused Code introduced by
The parameter trigger is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
647
648
                                                            // Get Wrapper
649
                                                            var wrapper = $(".manager-jobs__create-task-wrapper");
650
651
                                                            // Get Template
652
                                                            var template = $(".manager-jobs__create-task.template").clone();
653
654
                                                            console.log(wrapper.find(".manager-jobs__create-task"));
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
655
656
                                                            // Get New ID
657
                                                            if (wrapper.find(".manager-jobs__create-task").length == 0) {
0 ignored issues
show
Best Practice introduced by
Comparing wrapper.find(".manager-jobs__create-task").length to 0 using the == operator is not safe. Consider using === instead.
Loading history...
658
                                                                                var newID = parseInt(template.attr("data-task-id")) + 1;
659
                                                            } else {
660
                                                                                var newID = parseInt(wrapper.find("[class*='manager-jobs__create-task']").last().attr("data-task-id")) + 1;
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable newID already seems to be declared on line 658. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
661
                                                            }
662
663
                                                            // Remove Template Class
664
                                                            template.removeClass("template");
665
666
                                                            //TODO: replace with call to individualizeFormIdsAndNames(template, wrapper);
667
                                                            //TODO: This requires changes to JobController@create, because the id would change places
668
669
                                                            // Assign the New ID
670
                                                            template.attr("data-task-id", newID);
671
672
                                                            // Add newID as suffix to all "id" and "for" attributes
673
                                                            template.find("*[id]").each(function () {
674
                                                                                $(this).attr("id", this.id + newID);
675
                                                            });
676
                                                            template.find("*[for]").each(function () {
677
                                                                                $(this).attr("for", $(this).attr("for") + newID);
678
                                                            });
679
680
                                                            // Replace :id with newID in all form names
681
                                                            template.find("*[name]").each(function () {
682
                                                                                $(this).attr('name', $(this).attr("name").replace(":id", newID));
683
                                                            });
684
685
                                                            // Task (English)
686
                                                            //template.find("[data-form-id*='task-english']").find("label").attr("for", "taskEN" + newID);
687
                                                            //template.find("[data-form-id*='task-english']").find("input").attr("id", "taskEN" + newID);
688
689
                                                            // Task (French)
690
                                                            //template.find("[data-form-id*='task-french']").find("label").attr("for", "taskFR" + newID);
691
                                                            //template.find("[data-form-id*='task-french']").find("input").attr("id", "taskFR" + newID);
692
693
                                                            // Append Clone to the Wrapper
694
                                                            wrapper.append(template);
695
696
                                                            requiredFields();
697
                                                            labelHandlers();
698
                                                            deleteTaskTrigger();
699
                                        }
700
701
                                        $("#addTaskButton").on("click", function (e) {
702
703
                                                            e.preventDefault();
704
705
                                                            addTask(this);
706
                                        });
707
708
                                        $("#addTaskButton").on("keyup", function (e) {
709
710
                                                            if (e.which == 13) {
711
                                                                                e.preventDefault();
712
                                                                                addTask(this);
713
                                                            }
714
                                        });
715
716
                                        // Task Deletion
717
718
                                        function deleteTask(trigger) {
719
720
                                                            $(trigger).parents(".manager-jobs__create-task").remove();
721
                                        }
722
723
                                        function deleteTaskTrigger() {
724
725
                                                            $(".manager-jobs__delete-task-button").on("click", function (e) {
726
727
                                                                                e.preventDefault();
728
729
                                                                                deleteTask(this);
730
                                                            });
731
732
                                                            $(".manager-jobs__delete-task-button").on("keyup", function (e) {
733
734
                                                                                if (e.which == 13) {
735
                                                                                                    e.preventDefault();
736
                                                                                                    deleteTask(this);
737
                                                                                }
738
                                                            });
739
                                        }
740
741
                                        deleteTaskTrigger();
742
743
                                        // Skills
744
745
                                        function addSkill(trigger) {
746
747
                                                            // Get Parent
748
                                                            var parent = $(trigger).parents(".manager-jobs__skill-wrapper");
749
750
                                                            // Get Wrapper
751
                                                            var wrapper = parent.find(".manager-jobs__create-skill-wrapper");
752
753
                                                            // Get Template
754
                                                            var template = parent.find(".manager-jobs__create-skill.template").clone();
755
756
                                                            console.log(wrapper.find(".manager-jobs__create-skill"));
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
757
758
                                                            // Remove Template Class
759
                                                            template.removeClass("template");
760
761
                                                            //Set ids and form names to be unique
762
                                                            individualizeFormIdsAndNames(template, wrapper);
763
764
                                                            // Append Clone to the Wrapper
765
                                                            wrapper.append(template);
766
767
                                                            requiredFields();
768
                                                            labelHandlers();
769
                                                            deleteSkillTrigger();
770
                                        }
771
772
                                        $(".manager-jobs__add-skill-button").on("click", function (e) {
773
774
                                                            e.preventDefault();
775
776
                                                            addSkill(this);
777
                                        });
778
779
                                        $(".manager-jobs__add-skill-button").on("keyup", function (e) {
780
781
                                                            if (e.which == 13) {
782
                                                                                e.preventDefault();
783
                                                                                addSkill(this);
784
                                                            }
785
                                        });
786
787
                                        // Skill Deletion
788
789
                                        function deleteSkill(trigger) {
790
791
                                                            $(trigger).parents(".manager-jobs__create-skill").remove();
792
                                        }
793
794
                                        function deleteSkillTrigger() {
795
796
                                                            $(".manager-jobs__delete-skill-button").on("click", function (e) {
797
798
                                                                                e.preventDefault();
799
800
                                                                                deleteSkill(this);
801
                                                            });
802
803
                                                            $(".manager-jobs__delete-skill-button").on("keyup", function (e) {
804
805
                                                                                if (e.which == 13) {
806
                                                                                                    e.preventDefault();
807
                                                                                                    deleteSkill(this);
808
                                                                                }
809
                                                            });
810
                                        }
811
812
                                        deleteSkillTrigger();
813
814
                                        // Questions
815
816
                                        function addQuestion(trigger) {
0 ignored issues
show
Unused Code introduced by
The parameter trigger is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
817
818
                                                            // Get Wrapper
819
                                                            var wrapper = $(".manager-jobs__create-question-wrapper");
820
821
                                                            // Get Template
822
                                                            var template = $(".manager-jobs__create-question.template").clone();
823
824
                                                            console.log(wrapper.find(".manager-jobs__create-question"));
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
825
826
                                                            // Get New ID
827
                                                            if (wrapper.find(".manager-jobs__create-question").length == 0) {
0 ignored issues
show
Best Practice introduced by
Comparing wrapper.find(".manager-j...reate-question").length to 0 using the == operator is not safe. Consider using === instead.
Loading history...
828
                                                                                var newID = parseInt(template.attr("data-question-id")) + 1;
829
                                                            } else {
830
                                                                                var newID = parseInt(wrapper.find("[class*='manager-jobs__create-question']").last().attr("data-question-id")) + 1;
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable newID already seems to be declared on line 828. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
831
                                                            }
832
833
                                                            // Remove Template Class
834
                                                            template.removeClass("template");
835
836
                                                            //TODO: replace with call to individualizeFormIdsAndNames(template, wrapper);
837
                                                            //TODO: This requires changes to JobController@create, because the id would change places
838
839
                                                            // Assign the New ID
840
                                                            template.attr("data-question-id", newID);
841
842
                                                            // Add newID as suffix to all "id" and "for" attributes
843
                                                            template.find("*[id]").each(function () {
844
                                                                                $(this).attr("id", this.id + newID);
845
                                                            });
846
                                                            template.find("*[for]").each(function () {
847
                                                                                $(this).attr("for", $(this).attr("for") + newID);
848
                                                            });
849
850
                                                            // Replace :id with newID in all form names
851
                                                            template.find("*[name]").each(function () {
852
                                                                                $(this).attr('name', $(this).attr("name").replace(":id", newID));
853
                                                            });
854
855
                                                            // Edit Form IDs
856
                                                            //
857
                                                            // // Queestion (English)
858
                                                            // template.find("[data-form-id*='question-english']").find("label").attr("for", "questionEN" + newID);
859
                                                            // template.find("[data-form-id*='question-english']").find("input").attr("id", "questionEN" + newID);
860
                                                            //
861
                                                            // // Queestion (French)
862
                                                            // template.find("[data-form-id*='question-french']").find("label").attr("for", "questionFR" + newID);
863
                                                            // template.find("[data-form-id*='question-french']").find("input").attr("id", "questionFR" + newID);
864
865
                                                            // Append Clone to the Wrapper
866
                                                            wrapper.append(template);
867
868
                                                            requiredFields();
869
                                                            labelHandlers();
870
                                                            deleteQuestionTrigger();
871
                                        }
872
873
                                        $("#addQuestionButton").on("click", function (e) {
874
875
                                                            e.preventDefault();
876
877
                                                            addQuestion(this);
878
                                        });
879
880
                                        $("#addQuestionButton").on("keyup", function (e) {
881
882
                                                            if (e.which == 13) {
883
                                                                                e.preventDefault();
884
                                                                                addQuestion(this);
885
                                                            }
886
                                        });
887
888
                                        // Question Deletion
889
890
                                        function deleteQuestion(trigger) {
891
892
                                                            $(trigger).parents(".manager-jobs__create-question").remove();
893
                                        }
894
895
                                        function deleteQuestionTrigger() {
896
897
                                                            $(".manager-jobs__delete-question-button").on("click", function (e) {
898
899
                                                                                e.preventDefault();
900
901
                                                                                deleteQuestion(this);
902
                                                            });
903
904
                                                            $(".manager-jobs__delete-question-button").on("keyup", function (e) {
905
906
                                                                                if (e.which == 13) {
907
                                                                                                    e.preventDefault();
908
                                                                                                    deleteQuestion(this);
909
                                                                                }
910
                                                            });
911
                                        }
912
913
                                        deleteQuestionTrigger();
914
                    });
915
})(jQuery);
916
917
/***/ }),
918
/* 1 */,
0 ignored issues
show
Bug introduced by
The variable seems to be never declared. If this is a global, consider adding a /** global: */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
919
/* 2 */,
920
/* 3 */
921
/***/ (function(module, exports) {
0 ignored issues
show
Unused Code introduced by
The parameter exports is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter module is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
922
923
// removed by extract-text-webpack-plugin
924
925
/***/ }),
926
/* 4 */
927
/***/ (function(module, exports, __webpack_require__) {
928
929
__webpack_require__(0);
930
module.exports = __webpack_require__(3);
931
932
933
/***/ })
934
/******/ ]);