-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathhelpers.js
39 lines (34 loc) · 1.04 KB
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* Setup checkbox context for testing purposes.
*
* @return {Object} The setup context.
*/
function setupContext() {
var context = {};
/**
* The original context.
* @type {Object}
*/
context.original = $('#context');
/**
* The modified context.
* @return {Object}
*/
context.modified = context.original.clone()
.prop('id', 'modified-context')
.insertAfter(context.original);
/**
* Iterate each checkbox from the original and modified context by index.
* @param {Function} fn The function to run for each cycle.
*/
context.each = function (fn) {
context.original.find(':checkbox').each(function (index) {
var original = $(this);
var modified = $(context.modified.find(':checkbox').get(index));
var originalState = original.prop('checked');
var modifiedState = modified.prop('checked');
fn.call(null, original, modified, originalState, modifiedState, index);
});
};
return context;
}