client_side_validations 3.1.5 → 3.2.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/client_side_validations.gemspec +1 -9
- data/lib/client_side_validations.rb +6 -2
- data/lib/client_side_validations/action_view/form_builder.rb +4 -2
- data/lib/client_side_validations/action_view/form_helper.rb +15 -7
- data/lib/client_side_validations/active_model.rb +5 -2
- data/lib/client_side_validations/active_record.rb +2 -1
- data/lib/client_side_validations/active_record/middleware.rb +15 -2
- data/lib/client_side_validations/active_record/uniqueness.rb +0 -1
- data/lib/client_side_validations/core_ext/regexp.rb +1 -1
- data/lib/client_side_validations/middleware.rb +40 -16
- data/lib/client_side_validations/version.rb +1 -1
- data/lib/generators/templates/client_side_validations/initializer.rb +0 -3
- data/vendor/assets/javascripts/rails.validations.js +135 -170
- metadata +22 -329
- data/lib/client_side_validations/formtastic.rb +0 -21
- data/lib/client_side_validations/mongo_mapper.rb +0 -9
- data/lib/client_side_validations/mongo_mapper/middleware.rb +0 -20
- data/lib/client_side_validations/mongo_mapper/uniqueness.rb +0 -29
- data/lib/client_side_validations/mongoid.rb +0 -9
- data/lib/client_side_validations/mongoid/format.rb +0 -10
- data/lib/client_side_validations/mongoid/length.rb +0 -24
- data/lib/client_side_validations/mongoid/middleware.rb +0 -20
- data/lib/client_side_validations/mongoid/presence.rb +0 -10
- data/lib/client_side_validations/mongoid/uniqueness.rb +0 -29
- data/lib/client_side_validations/simple_form.rb +0 -24
- data/lib/generators/templates/client_side_validations/README.rails.3.0 +0 -6
- data/test/action_view/cases/helper.rb +0 -176
- data/test/action_view/cases/test_helpers.rb +0 -635
- data/test/action_view/cases/test_legacy_helpers.rb +0 -217
- data/test/action_view/models.rb +0 -3
- data/test/action_view/models/comment.rb +0 -35
- data/test/action_view/models/post.rb +0 -35
- data/test/active_model/cases/helper.rb +0 -4
- data/test/active_model/cases/test_acceptance_validator.rb +0 -16
- data/test/active_model/cases/test_base.rb +0 -11
- data/test/active_model/cases/test_confirmation_validator.rb +0 -16
- data/test/active_model/cases/test_exclusion_validator.rb +0 -20
- data/test/active_model/cases/test_format_validator.rb +0 -21
- data/test/active_model/cases/test_inclusion_validator.rb +0 -21
- data/test/active_model/cases/test_length_validator.rb +0 -61
- data/test/active_model/cases/test_numericality_validator.rb +0 -46
- data/test/active_model/cases/test_presence_validator.rb +0 -16
- data/test/active_model/cases/test_validations.rb +0 -175
- data/test/active_model/models/person.rb +0 -17
- data/test/active_record/cases/helper.rb +0 -12
- data/test/active_record/cases/test_base.rb +0 -11
- data/test/active_record/cases/test_middleware.rb +0 -175
- data/test/active_record/cases/test_uniqueness_validator.rb +0 -56
- data/test/active_record/models/guid.rb +0 -7
- data/test/active_record/models/user.rb +0 -14
- data/test/base_helper.rb +0 -21
- data/test/core_ext/cases/test_core_ext.rb +0 -46
- data/test/formtastic/cases/helper.rb +0 -7
- data/test/formtastic/cases/test_form_builder.rb +0 -11
- data/test/formtastic/cases/test_form_helper.rb +0 -21
- data/test/generators/cases/test_generators.rb +0 -70
- data/test/javascript/config.ru +0 -3
- data/test/javascript/public/test/callbacks/elementAfter.js +0 -54
- data/test/javascript/public/test/callbacks/elementBefore.js +0 -54
- data/test/javascript/public/test/callbacks/elementFail.js +0 -70
- data/test/javascript/public/test/callbacks/elementPass.js +0 -70
- data/test/javascript/public/test/callbacks/formAfter.js +0 -45
- data/test/javascript/public/test/callbacks/formBefore.js +0 -45
- data/test/javascript/public/test/callbacks/formFail.js +0 -51
- data/test/javascript/public/test/callbacks/formPass.js +0 -50
- data/test/javascript/public/test/form_builders/validateForm.js +0 -66
- data/test/javascript/public/test/form_builders/validateFormtastic.js +0 -54
- data/test/javascript/public/test/form_builders/validateNestedForm.js +0 -66
- data/test/javascript/public/test/form_builders/validateSimpleForm.js +0 -57
- data/test/javascript/public/test/settings.js +0 -15
- data/test/javascript/public/test/validateElement.js +0 -179
- data/test/javascript/public/test/validators/acceptance.js +0 -42
- data/test/javascript/public/test/validators/confirmation.js +0 -25
- data/test/javascript/public/test/validators/exclusion.js +0 -41
- data/test/javascript/public/test/validators/format.js +0 -27
- data/test/javascript/public/test/validators/inclusion.js +0 -42
- data/test/javascript/public/test/validators/length.js +0 -76
- data/test/javascript/public/test/validators/numericality.js +0 -158
- data/test/javascript/public/test/validators/presence.js +0 -21
- data/test/javascript/public/test/validators/uniqueness.js +0 -107
- data/test/javascript/public/vendor/jquery.metadata.js +0 -122
- data/test/javascript/public/vendor/qunit.css +0 -196
- data/test/javascript/public/vendor/qunit.js +0 -1374
- data/test/javascript/server.rb +0 -84
- data/test/javascript/views/index.erb +0 -20
- data/test/javascript/views/layout.erb +0 -21
- data/test/middleware/cases/helper.rb +0 -7
- data/test/middleware/cases/test_middleware.rb +0 -8
- data/test/mongo_mapper/cases/helper.rb +0 -9
- data/test/mongo_mapper/cases/test_base.rb +0 -15
- data/test/mongo_mapper/cases/test_middleware.rb +0 -77
- data/test/mongo_mapper/cases/test_uniqueness_validator.rb +0 -55
- data/test/mongo_mapper/models/magazine.rb +0 -11
- data/test/mongoid/cases/helper.rb +0 -12
- data/test/mongoid/cases/test_base.rb +0 -15
- data/test/mongoid/cases/test_format_validator.rb +0 -21
- data/test/mongoid/cases/test_length_validator.rb +0 -60
- data/test/mongoid/cases/test_middleware.rb +0 -77
- data/test/mongoid/cases/test_presence_validator.rb +0 -16
- data/test/mongoid/cases/test_uniqueness_validator.rb +0 -54
- data/test/mongoid/models/book.rb +0 -12
- data/test/simple_form/cases/helper.rb +0 -5
- data/test/simple_form/cases/test_form_builder.rb +0 -14
- data/test/simple_form/cases/test_form_helper.rb +0 -24
- data/test/test_loader.rb +0 -6
@@ -1,158 +0,0 @@
|
|
1
|
-
module('Numericality options');
|
2
|
-
|
3
|
-
test('when value is a number', function() {
|
4
|
-
var element = $('<input type="text" />');
|
5
|
-
var options = { messagess: { numericality: "failed validation" } };
|
6
|
-
element.val('123');
|
7
|
-
equal(clientSideValidations.validators.local.numericality(element, options), undefined);
|
8
|
-
});
|
9
|
-
|
10
|
-
test('when value is a decimal number', function() {
|
11
|
-
var element = $('<input type="text" />');
|
12
|
-
var options = { messages: { numericality: "failed validation" } };
|
13
|
-
element.val('123.456');
|
14
|
-
equal(clientSideValidations.validators.local.numericality(element, options), undefined);
|
15
|
-
});
|
16
|
-
|
17
|
-
test('when value is not a number', function() {
|
18
|
-
var element = $('<input type="text" />');
|
19
|
-
var options = { messages: { numericality: "failed validation" } };
|
20
|
-
element.val('abc123');
|
21
|
-
equal(clientSideValidations.validators.local.numericality(element, options), "failed validation");
|
22
|
-
});
|
23
|
-
|
24
|
-
test('when only allowing integers and value is integer', function() {
|
25
|
-
var element = $('<input type="text" />');
|
26
|
-
var options = { messages: { only_integer: "failed validation" }, only_integer: true };
|
27
|
-
element.val('123');
|
28
|
-
equal(clientSideValidations.validators.local.numericality(element, options), undefined);
|
29
|
-
});
|
30
|
-
|
31
|
-
test('when only allowing integers and value has a negative or positive sign', function() {
|
32
|
-
var element = $('<input type="text" />');
|
33
|
-
var options = { messages: { only_integer: "failed validation"}, only_integer: true };
|
34
|
-
element.val('-23');
|
35
|
-
equal(clientSideValidations.validators.local.numericality(element, options), undefined);
|
36
|
-
element.val('+23');
|
37
|
-
equal(clientSideValidations.validators.local.numericality(element, options), undefined);
|
38
|
-
});
|
39
|
-
|
40
|
-
test('when only allowing integers and value is not integer', function() {
|
41
|
-
var element = $('<input type="text" />');
|
42
|
-
var options = { messages: { only_integer: "failed validation" }, only_integer: true };
|
43
|
-
element.val('123.456');
|
44
|
-
equal(clientSideValidations.validators.local.numericality(element, options), "failed validation");
|
45
|
-
});
|
46
|
-
|
47
|
-
test('when only allowing values greater than 10 and value is greater than 10', function() {
|
48
|
-
var element = $('<input type="text" />');
|
49
|
-
var options = { messages: { greater_than: "failed validation" }, greater_than: 10 };
|
50
|
-
element.val('11');
|
51
|
-
equal(clientSideValidations.validators.local.numericality(element, options), undefined);
|
52
|
-
});
|
53
|
-
|
54
|
-
test('when only allowing values greater than 10 and value is 10', function() {
|
55
|
-
var element = $('<input type="text" />');
|
56
|
-
var options = { messages: { greater_than: "failed validation" }, greater_than: 10 };
|
57
|
-
element.val('10');
|
58
|
-
equal(clientSideValidations.validators.local.numericality(element, options), "failed validation");
|
59
|
-
});
|
60
|
-
|
61
|
-
test('when only allowing values greater than or equal to 10 and value is 10', function() {
|
62
|
-
var element = $('<input type="text" />');
|
63
|
-
var options = { messages: { greater_than_or_equal_to: "failed validation" }, greater_than_or_equal_to: 10 };
|
64
|
-
element.val('10');
|
65
|
-
equal(clientSideValidations.validators.local.numericality(element, options), undefined);
|
66
|
-
});
|
67
|
-
|
68
|
-
test('when only allowing values greater than or equal to 10 and value is 9', function() {
|
69
|
-
var element = $('<input type="text" />');
|
70
|
-
var options = { messages: { greater_than_or_equal_to: "failed validation" }, greater_than_or_equal_to: 10 };
|
71
|
-
element.val('9');
|
72
|
-
equal(clientSideValidations.validators.local.numericality(element, options), "failed validation");
|
73
|
-
});
|
74
|
-
|
75
|
-
test('when only allowing values less than 10 and value is less than 10', function() {
|
76
|
-
var element = $('<input type="text" />');
|
77
|
-
var options = { messages: { less_than: "failed validation" }, less_than: 10 };
|
78
|
-
element.val('9');
|
79
|
-
equal(clientSideValidations.validators.local.numericality(element, options), undefined);
|
80
|
-
});
|
81
|
-
|
82
|
-
test('when only allowing values less than 10 and value is 10', function() {
|
83
|
-
var element = $('<input type="text" />');
|
84
|
-
var options = { messages: { less_than: "failed validation" }, less_than: 10 };
|
85
|
-
element.val('10');
|
86
|
-
equal(clientSideValidations.validators.local.numericality(element, options), "failed validation");
|
87
|
-
});
|
88
|
-
|
89
|
-
test('when only allowing values less than or equal to 10 and value is 10', function() {
|
90
|
-
var element = $('<input type="text" />');
|
91
|
-
var options = { messages: { less_than_or_equal_to: "failed validation" }, less_than_or_equal_to: 10 };
|
92
|
-
element.val('10');
|
93
|
-
equal(clientSideValidations.validators.local.numericality(element, options), undefined);
|
94
|
-
});
|
95
|
-
|
96
|
-
test('when only allowing values less than or equal to 10 and value is 11', function() {
|
97
|
-
var element = $('<input type="text" />');
|
98
|
-
var options = { messages: { less_than_or_equal_to: "failed validation" }, less_than_or_equal_to: 10 };
|
99
|
-
element.val('11');
|
100
|
-
equal(clientSideValidations.validators.local.numericality(element, options), "failed validation");
|
101
|
-
});
|
102
|
-
|
103
|
-
test('when only allowing values equal to 10 and value is 10', function() {
|
104
|
-
var element = $('<input type="text" />');
|
105
|
-
var options = { messages: { equal_to: "failed validation" }, equal_to: 10 };
|
106
|
-
element.val('10');
|
107
|
-
equal(clientSideValidations.validators.local.numericality(element, options), undefined);
|
108
|
-
});
|
109
|
-
|
110
|
-
test('when only allowing values equal to 10 and value is 11', function() {
|
111
|
-
var element = $('<input type="text" />');
|
112
|
-
var options = { messages: { equal_to: "failed validation" }, equal_to: 10 };
|
113
|
-
element.val('11');
|
114
|
-
equal(clientSideValidations.validators.local.numericality(element, options), "failed validation");
|
115
|
-
});
|
116
|
-
|
117
|
-
test('when only allowing value equal to 0 and value is 1', function() {
|
118
|
-
var element = $('<input type="text" />');
|
119
|
-
var options = { messages: { equal_to: "failed validation" }, equal_to: 0 };
|
120
|
-
element.val('1');
|
121
|
-
equal(clientSideValidations.validators.local.numericality(element, options), "failed validation");
|
122
|
-
});
|
123
|
-
|
124
|
-
test('when only allowing odd values and the value is odd', function() {
|
125
|
-
var element = $('<input type="text" />');
|
126
|
-
var options = { messages: { odd: "failed validation" }, odd: true };
|
127
|
-
element.val('11');
|
128
|
-
equal(clientSideValidations.validators.local.numericality(element, options), undefined);
|
129
|
-
});
|
130
|
-
|
131
|
-
test('when only allowing odd values and the value is even', function() {
|
132
|
-
var element = $('<input type="text" />');
|
133
|
-
var options = { messages: { odd: "failed validation" }, odd: true };
|
134
|
-
element.val('10');
|
135
|
-
equal(clientSideValidations.validators.local.numericality(element, options), "failed validation");
|
136
|
-
});
|
137
|
-
|
138
|
-
test('when only allowing even values and the value is even', function() {
|
139
|
-
var element = $('<input type="text" />');
|
140
|
-
var options = { messages: { even: "failed validation" }, even: true };
|
141
|
-
element.val('10');
|
142
|
-
equal(clientSideValidations.validators.local.numericality(element, options), undefined);
|
143
|
-
});
|
144
|
-
|
145
|
-
test('when only allowing even values and the value is odd', function() {
|
146
|
-
var element = $('<input type="text" />');
|
147
|
-
var options = { messages: { even: "failed validation" }, even: true };
|
148
|
-
element.val('11');
|
149
|
-
equal(clientSideValidations.validators.local.numericality(element, options), "failed validation");
|
150
|
-
});
|
151
|
-
|
152
|
-
test('blank values should be evaluated as zero', function() {
|
153
|
-
var element = $('<input type="text" />');
|
154
|
-
var options = { messages: { numericality: "failed validation" } };
|
155
|
-
element.val('');
|
156
|
-
equal(clientSideValidations.validators.local.numericality(element, options), undefined);
|
157
|
-
});
|
158
|
-
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module('Presence options');
|
2
|
-
|
3
|
-
test('when value is not empty', function() {
|
4
|
-
var element = $('<input type="text" />');
|
5
|
-
var options = { message: "failed validation" };
|
6
|
-
element.val('not empty');
|
7
|
-
equal(clientSideValidations.validators.local.presence(element, options), undefined);
|
8
|
-
});
|
9
|
-
|
10
|
-
test('when value is empty', function() {
|
11
|
-
var element = $('<input type="text" />');
|
12
|
-
var options = { message: "failed validation" };
|
13
|
-
equal(clientSideValidations.validators.local.presence(element, options), "failed validation");
|
14
|
-
});
|
15
|
-
|
16
|
-
test('when value is null from non-selected multi-select element', function() {
|
17
|
-
var element = $('<select multiple="multiple />');
|
18
|
-
var options = { message: "failed validation" };
|
19
|
-
equal(clientSideValidations.validators.local.presence(element, options), "failed validation");
|
20
|
-
});
|
21
|
-
|
@@ -1,107 +0,0 @@
|
|
1
|
-
module('Uniqueness options', {
|
2
|
-
setup: function() {
|
3
|
-
window['new_user'] = {
|
4
|
-
type: 'ActionView::Helpers::FormBuilder',
|
5
|
-
input_tag: '<div class="field_with_errors"><span id="input_tag" /><label class="message"></label></div>',
|
6
|
-
label_tag: '<div class="field_with_errors"><label id="label_tag" /></div>',
|
7
|
-
validators: {'user[email]':{"uniqueness":{"message": "must be unique", "scope":{name:"pass"}},"presence":{"message": "must be present"}}}
|
8
|
-
}
|
9
|
-
|
10
|
-
$('#qunit-fixture')
|
11
|
-
.append($('<form />', {
|
12
|
-
action: '/users',
|
13
|
-
'data-validate': true,
|
14
|
-
method: 'post',
|
15
|
-
id: 'new_user'
|
16
|
-
}))
|
17
|
-
.find('form')
|
18
|
-
.append($('<input />', {
|
19
|
-
name: 'user[name]',
|
20
|
-
id: 'user_name',
|
21
|
-
type: 'text'
|
22
|
-
}))
|
23
|
-
.append($('<input />', {
|
24
|
-
name: 'user[email]',
|
25
|
-
id: 'user_email',
|
26
|
-
'data-validate': 'true',
|
27
|
-
type: 'text'
|
28
|
-
}))
|
29
|
-
|
30
|
-
$('form#new_user').validate();
|
31
|
-
}
|
32
|
-
});
|
33
|
-
|
34
|
-
test('when matching uniqueness on a non-nested resource', function() {
|
35
|
-
var element = $('<input type="text" name="user[email]"/>');
|
36
|
-
var options = { 'message': "failed validation" };
|
37
|
-
element.val('nottaken@test.com');
|
38
|
-
equal(clientSideValidations.validators.remote.uniqueness(element, options), undefined);
|
39
|
-
});
|
40
|
-
|
41
|
-
test('when matching uniqueness on a non-nested resource', function() {
|
42
|
-
var element = $('<input type="text" name="user[email]"/>');
|
43
|
-
var options = { 'message': "failed validation" };
|
44
|
-
element.val('taken@test.com');
|
45
|
-
equal(clientSideValidations.validators.remote.uniqueness(element, options), "failed validation");
|
46
|
-
});
|
47
|
-
|
48
|
-
test('when matching uniqueness on a nested singular resource', function() {
|
49
|
-
var element = $('<input type="text" name="profile[user_attributes][email]"/>');
|
50
|
-
var options = { 'message': "failed validation" };
|
51
|
-
element.val('nottaken@test.com');
|
52
|
-
equal(clientSideValidations.validators.remote.uniqueness(element, options), undefined);
|
53
|
-
});
|
54
|
-
|
55
|
-
test('when matching uniqueness on a nested singular resource', function() {
|
56
|
-
var element = $('<input type="text" name="profile[user_attributes][email]"/>');
|
57
|
-
var options = { 'message': "failed validation" };
|
58
|
-
element.val('taken@test.com');
|
59
|
-
equal(clientSideValidations.validators.remote.uniqueness(element, options), "failed validation");
|
60
|
-
});
|
61
|
-
|
62
|
-
test('when using scopes with no replacement', function() {
|
63
|
-
var element = $('<input type="text" name="person[age]" />');
|
64
|
-
var options = { 'message': "failed validation", 'with': /\d+/, 'scope': { 'name': 'test name' } };
|
65
|
-
element.val('test');
|
66
|
-
equal(clientSideValidations.validators.remote.uniqueness(element, options), "failed validation");
|
67
|
-
});
|
68
|
-
|
69
|
-
test('when using scopes with replacement', function() {
|
70
|
-
var element = $('<input type="text" name="person[age]" />');
|
71
|
-
var options = { 'message': "failed validation", 'with': /\d+/, 'scope': { 'name': 'test name' } };
|
72
|
-
element.val('test')
|
73
|
-
$('#qunit-fixture').append('<input type="text" name="person[name]" />').find('input[name="person[name]"]').val('other name');
|
74
|
-
equal(clientSideValidations.validators.remote.uniqueness(element, options), undefined);
|
75
|
-
});
|
76
|
-
|
77
|
-
test('when validating by scope and mixed focus order', function() {
|
78
|
-
var unique_element = $('#user_email'), scope_element = $('#user_name');
|
79
|
-
unique_element.val('free@test.com');
|
80
|
-
unique_element.trigger('change');
|
81
|
-
unique_element.trigger('focusout');
|
82
|
-
equal($('.message[for="user_email"]').text(), '');
|
83
|
-
|
84
|
-
scope_element.val('test name');
|
85
|
-
scope_element.trigger('change');
|
86
|
-
scope_element.trigger('focusout');
|
87
|
-
equal($('.message[for="user_email"]').text(), 'must be unique');
|
88
|
-
});
|
89
|
-
|
90
|
-
test('when matching uniqueness on a resource with a defined class name', function() {
|
91
|
-
var element = $('<input type="text" name="user2[email]"/>');
|
92
|
-
var options = { 'message': "failed validation", 'class': "active_record_test_module/user2" };
|
93
|
-
element.val('nottaken@test.com');
|
94
|
-
equal(clientSideValidations.validators.remote.uniqueness(element, options), 'failed validation');
|
95
|
-
});
|
96
|
-
|
97
|
-
test('when allowing blank', function() {
|
98
|
-
var element = $('<input type="text" name="user2[email]" />');
|
99
|
-
var options = { 'message': "failed validation", 'with': /\d+/, 'allow_blank': true };
|
100
|
-
equal(clientSideValidations.validators.remote.uniqueness(element, options), undefined);
|
101
|
-
});
|
102
|
-
|
103
|
-
test('when not allowing blank', function() {
|
104
|
-
var element = $('<input type="text" name="user2[email]" />');
|
105
|
-
var options = { 'message': "failed validation", 'with': /\d+/ };
|
106
|
-
equal(clientSideValidations.validators.remote.uniqueness(element, options), "failed validation");
|
107
|
-
});
|
@@ -1,122 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Metadata - jQuery plugin for parsing metadata from elements
|
3
|
-
*
|
4
|
-
* Copyright (c) 2006 John Resig, Yehuda Katz, J�örn Zaefferer, Paul McLanahan
|
5
|
-
*
|
6
|
-
* Dual licensed under the MIT and GPL licenses:
|
7
|
-
* http://www.opensource.org/licenses/mit-license.php
|
8
|
-
* http://www.gnu.org/licenses/gpl.html
|
9
|
-
*
|
10
|
-
* Revision: $Id: jquery.metadata.js 4187 2007-12-16 17:15:27Z joern.zaefferer $
|
11
|
-
*
|
12
|
-
*/
|
13
|
-
|
14
|
-
/**
|
15
|
-
* Sets the type of metadata to use. Metadata is encoded in JSON, and each property
|
16
|
-
* in the JSON will become a property of the element itself.
|
17
|
-
*
|
18
|
-
* There are three supported types of metadata storage:
|
19
|
-
*
|
20
|
-
* attr: Inside an attribute. The name parameter indicates *which* attribute.
|
21
|
-
*
|
22
|
-
* class: Inside the class attribute, wrapped in curly braces: { }
|
23
|
-
*
|
24
|
-
* elem: Inside a child element (e.g. a script tag). The
|
25
|
-
* name parameter indicates *which* element.
|
26
|
-
*
|
27
|
-
* The metadata for an element is loaded the first time the element is accessed via jQuery.
|
28
|
-
*
|
29
|
-
* As a result, you can define the metadata type, use $(expr) to load the metadata into the elements
|
30
|
-
* matched by expr, then redefine the metadata type and run another $(expr) for other elements.
|
31
|
-
*
|
32
|
-
* @name $.metadata.setType
|
33
|
-
*
|
34
|
-
* @example <p id="one" class="some_class {item_id: 1, item_label: 'Label'}">This is a p</p>
|
35
|
-
* @before $.metadata.setType("class")
|
36
|
-
* @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
|
37
|
-
* @desc Reads metadata from the class attribute
|
38
|
-
*
|
39
|
-
* @example <p id="one" class="some_class" data="{item_id: 1, item_label: 'Label'}">This is a p</p>
|
40
|
-
* @before $.metadata.setType("attr", "data")
|
41
|
-
* @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
|
42
|
-
* @desc Reads metadata from a "data" attribute
|
43
|
-
*
|
44
|
-
* @example <p id="one" class="some_class"><script>{item_id: 1, item_label: 'Label'}</script>This is a p</p>
|
45
|
-
* @before $.metadata.setType("elem", "script")
|
46
|
-
* @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
|
47
|
-
* @desc Reads metadata from a nested script element
|
48
|
-
*
|
49
|
-
* @param String type The encoding type
|
50
|
-
* @param String name The name of the attribute to be used to get metadata (optional)
|
51
|
-
* @cat Plugins/Metadata
|
52
|
-
* @descr Sets the type of encoding to be used when loading metadata for the first time
|
53
|
-
* @type undefined
|
54
|
-
* @see metadata()
|
55
|
-
*/
|
56
|
-
|
57
|
-
(function($) {
|
58
|
-
|
59
|
-
$.extend({
|
60
|
-
metadata : {
|
61
|
-
defaults : {
|
62
|
-
type: 'class',
|
63
|
-
name: 'metadata',
|
64
|
-
cre: /({.*})/,
|
65
|
-
single: 'metadata'
|
66
|
-
},
|
67
|
-
setType: function( type, name ){
|
68
|
-
this.defaults.type = type;
|
69
|
-
this.defaults.name = name;
|
70
|
-
},
|
71
|
-
get: function( elem, opts ){
|
72
|
-
var settings = $.extend({},this.defaults,opts);
|
73
|
-
// check for empty string in single property
|
74
|
-
if ( !settings.single.length ) settings.single = 'metadata';
|
75
|
-
|
76
|
-
var data = $.data(elem, settings.single);
|
77
|
-
// returned cached data if it already exists
|
78
|
-
if ( data ) return data;
|
79
|
-
|
80
|
-
data = "{}";
|
81
|
-
|
82
|
-
if ( settings.type == "class" ) {
|
83
|
-
var m = settings.cre.exec( elem.className );
|
84
|
-
if ( m )
|
85
|
-
data = m[1];
|
86
|
-
} else if ( settings.type == "elem" ) {
|
87
|
-
if( !elem.getElementsByTagName )
|
88
|
-
return undefined;
|
89
|
-
var e = elem.getElementsByTagName(settings.name);
|
90
|
-
if ( e.length )
|
91
|
-
data = $.trim(e[0].innerHTML);
|
92
|
-
} else if ( elem.getAttribute != undefined ) {
|
93
|
-
var attr = elem.getAttribute( settings.name );
|
94
|
-
if ( attr )
|
95
|
-
data = attr;
|
96
|
-
}
|
97
|
-
|
98
|
-
if ( data.indexOf( '{' ) <0 )
|
99
|
-
data = "{" + data + "}";
|
100
|
-
|
101
|
-
data = eval("(" + data + ")");
|
102
|
-
|
103
|
-
$.data( elem, settings.single, data );
|
104
|
-
return data;
|
105
|
-
}
|
106
|
-
}
|
107
|
-
});
|
108
|
-
|
109
|
-
/**
|
110
|
-
* Returns the metadata object for the first member of the jQuery object.
|
111
|
-
*
|
112
|
-
* @name metadata
|
113
|
-
* @descr Returns element's metadata object
|
114
|
-
* @param Object opts An object contianing settings to override the defaults
|
115
|
-
* @type jQuery
|
116
|
-
* @cat Plugins/Metadata
|
117
|
-
*/
|
118
|
-
$.fn.metadata = function( opts ){
|
119
|
-
return $.metadata.get( this[0], opts );
|
120
|
-
};
|
121
|
-
|
122
|
-
})(jQuery);
|
@@ -1,196 +0,0 @@
|
|
1
|
-
/** Font Family and Sizes */
|
2
|
-
|
3
|
-
#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult {
|
4
|
-
font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial;
|
5
|
-
}
|
6
|
-
|
7
|
-
#qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
|
8
|
-
#qunit-tests { font-size: smaller; }
|
9
|
-
|
10
|
-
|
11
|
-
/** Resets */
|
12
|
-
|
13
|
-
#qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult {
|
14
|
-
margin: 0;
|
15
|
-
padding: 0;
|
16
|
-
}
|
17
|
-
|
18
|
-
|
19
|
-
/** Header */
|
20
|
-
|
21
|
-
#qunit-header {
|
22
|
-
padding: 0.5em 0 0.5em 1em;
|
23
|
-
|
24
|
-
color: #8699a4;
|
25
|
-
background-color: #0d3349;
|
26
|
-
|
27
|
-
font-size: 1.5em;
|
28
|
-
line-height: 1em;
|
29
|
-
font-weight: normal;
|
30
|
-
|
31
|
-
border-radius: 15px 15px 0 0;
|
32
|
-
-moz-border-radius: 15px 15px 0 0;
|
33
|
-
-webkit-border-top-right-radius: 15px;
|
34
|
-
-webkit-border-top-left-radius: 15px;
|
35
|
-
}
|
36
|
-
|
37
|
-
#qunit-header a {
|
38
|
-
text-decoration: none;
|
39
|
-
color: #c2ccd1;
|
40
|
-
}
|
41
|
-
|
42
|
-
#qunit-header a:hover,
|
43
|
-
#qunit-header a:focus {
|
44
|
-
color: #fff;
|
45
|
-
}
|
46
|
-
|
47
|
-
#qunit-banner {
|
48
|
-
height: 5px;
|
49
|
-
}
|
50
|
-
|
51
|
-
#qunit-testrunner-toolbar {
|
52
|
-
padding: 0em 0 0.5em 2em;
|
53
|
-
}
|
54
|
-
|
55
|
-
#qunit-userAgent {
|
56
|
-
padding: 0.5em 0 0.5em 2.5em;
|
57
|
-
background-color: #2b81af;
|
58
|
-
color: #fff;
|
59
|
-
text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
|
60
|
-
}
|
61
|
-
|
62
|
-
|
63
|
-
/** Tests: Pass/Fail */
|
64
|
-
|
65
|
-
#qunit-tests {
|
66
|
-
list-style-position: inside;
|
67
|
-
}
|
68
|
-
|
69
|
-
#qunit-tests li {
|
70
|
-
padding: 0.4em 0.5em 0.4em 2.5em;
|
71
|
-
border-bottom: 1px solid #fff;
|
72
|
-
list-style-position: inside;
|
73
|
-
}
|
74
|
-
|
75
|
-
#qunit-tests li strong {
|
76
|
-
cursor: pointer;
|
77
|
-
}
|
78
|
-
|
79
|
-
#qunit-tests ol {
|
80
|
-
margin-top: 0.5em;
|
81
|
-
padding: 0.5em;
|
82
|
-
|
83
|
-
background-color: #fff;
|
84
|
-
|
85
|
-
border-radius: 15px;
|
86
|
-
-moz-border-radius: 15px;
|
87
|
-
-webkit-border-radius: 15px;
|
88
|
-
|
89
|
-
box-shadow: inset 0px 2px 13px #999;
|
90
|
-
-moz-box-shadow: inset 0px 2px 13px #999;
|
91
|
-
-webkit-box-shadow: inset 0px 2px 13px #999;
|
92
|
-
}
|
93
|
-
|
94
|
-
#qunit-tests table {
|
95
|
-
border-collapse: collapse;
|
96
|
-
margin-top: .2em;
|
97
|
-
}
|
98
|
-
|
99
|
-
#qunit-tests th {
|
100
|
-
text-align: right;
|
101
|
-
vertical-align: top;
|
102
|
-
padding: 0 .5em 0 0;
|
103
|
-
}
|
104
|
-
|
105
|
-
#qunit-tests td {
|
106
|
-
vertical-align: top;
|
107
|
-
}
|
108
|
-
|
109
|
-
#qunit-tests pre {
|
110
|
-
margin: 0;
|
111
|
-
white-space: pre-wrap;
|
112
|
-
word-wrap: break-word;
|
113
|
-
}
|
114
|
-
|
115
|
-
#qunit-tests del {
|
116
|
-
background-color: #e0f2be;
|
117
|
-
color: #374e0c;
|
118
|
-
text-decoration: none;
|
119
|
-
}
|
120
|
-
|
121
|
-
#qunit-tests ins {
|
122
|
-
background-color: #ffcaca;
|
123
|
-
color: #500;
|
124
|
-
text-decoration: none;
|
125
|
-
}
|
126
|
-
|
127
|
-
/*** Test Counts */
|
128
|
-
|
129
|
-
#qunit-tests b.counts { color: black; }
|
130
|
-
#qunit-tests b.passed { color: #5E740B; }
|
131
|
-
#qunit-tests b.failed { color: #710909; }
|
132
|
-
|
133
|
-
#qunit-tests li li {
|
134
|
-
margin: 0.5em;
|
135
|
-
padding: 0.4em 0.5em 0.4em 0.5em;
|
136
|
-
background-color: #fff;
|
137
|
-
border-bottom: none;
|
138
|
-
list-style-position: inside;
|
139
|
-
}
|
140
|
-
|
141
|
-
/*** Passing Styles */
|
142
|
-
|
143
|
-
#qunit-tests li li.pass {
|
144
|
-
color: #5E740B;
|
145
|
-
background-color: #fff;
|
146
|
-
border-left: 26px solid #C6E746;
|
147
|
-
}
|
148
|
-
|
149
|
-
#qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
|
150
|
-
#qunit-tests .pass .test-name { color: #366097; }
|
151
|
-
|
152
|
-
#qunit-tests .pass .test-actual,
|
153
|
-
#qunit-tests .pass .test-expected { color: #999999; }
|
154
|
-
|
155
|
-
#qunit-banner.qunit-pass { background-color: #C6E746; }
|
156
|
-
|
157
|
-
/*** Failing Styles */
|
158
|
-
|
159
|
-
#qunit-tests li li.fail {
|
160
|
-
color: #710909;
|
161
|
-
background-color: #fff;
|
162
|
-
border-left: 26px solid #EE5757;
|
163
|
-
}
|
164
|
-
|
165
|
-
#qunit-tests .fail { color: #000000; background-color: #EE5757; }
|
166
|
-
#qunit-tests .fail .test-name,
|
167
|
-
#qunit-tests .fail .module-name { color: #000000; }
|
168
|
-
|
169
|
-
#qunit-tests .fail .test-actual { color: #EE5757; }
|
170
|
-
#qunit-tests .fail .test-expected { color: green; }
|
171
|
-
|
172
|
-
#qunit-banner.qunit-fail,
|
173
|
-
#qunit-testrunner-toolbar { background-color: #EE5757; }
|
174
|
-
|
175
|
-
|
176
|
-
/** Footer */
|
177
|
-
|
178
|
-
#qunit-testresult {
|
179
|
-
padding: 0.5em 0.5em 0.5em 2.5em;
|
180
|
-
|
181
|
-
color: #2b81af;
|
182
|
-
background-color: #D2E0E6;
|
183
|
-
|
184
|
-
border-radius: 0 0 15px 15px;
|
185
|
-
-moz-border-radius: 0 0 15px 15px;
|
186
|
-
-webkit-border-bottom-right-radius: 15px;
|
187
|
-
-webkit-border-bottom-left-radius: 15px;
|
188
|
-
}
|
189
|
-
|
190
|
-
/** Fixture */
|
191
|
-
|
192
|
-
#qunit-fixture {
|
193
|
-
position: absolute;
|
194
|
-
top: -10000px;
|
195
|
-
left: -10000px;
|
196
|
-
}
|