Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81144 views
1
/*
2
* Copyright (C) 2007-2015 Diego Perini
3
* All rights reserved.
4
*
5
* this is just a small example to show
6
* how an extension for NWMatcher could be
7
* adapted to handle WebForms/HTML5 selectors
8
*
9
* Pseudo Selectors
10
* :default, :indeterminate, :optional, :required,
11
* :valid, :invalid, :in-range, :out-of-range,
12
* :read-only, :read-write
13
* :has, :matches (not yet in a defined specification)
14
*
15
*/
16
17
// for UI pseudo-classes extensions (WebForms/HTML5)
18
NW.Dom.registerSelector(
19
'html5:pseudos',
20
/^\:(default|indeterminate|optional|required|valid|invalid|in-range|out-of-range|read-only|read-write)(.*)/,
21
(function(global) {
22
23
return function(match, source) {
24
25
var status = true,
26
27
HTML5PseudoClasses = global.Object({
28
'default': 4, 'indeterminate': 4, 'invalid': 4, 'valid': 4,
29
'optional': 4, 'required': 4, 'read-write': 4, 'read-only': 4
30
});
31
32
switch (match[1]) {
33
34
// HTML5 UI element states (form controls)
35
case 'default':
36
// only radio buttons, check boxes and option elements
37
source = 'if(((typeof e.form!=="undefined"&&(/radio|checkbox/i).test(e.type))||/option/i.test(e.nodeName))&&(e.defaultChecked||e.defaultSelected)){' + source + '}';
38
break;
39
40
case 'indeterminate':
41
// only radio buttons, check boxes and option elements
42
source = 'if(typeof e.form!=="undefined"&&(/radio|checkbox/i).test(e.type)&&s.select("[checked]",e.form).length===0){' + source + '}';
43
break;
44
45
case 'optional':
46
// only fields for which "required" applies
47
source = 'if(typeof e.form!=="undefined"&&typeof e.required!="undefined"&&!e.required){' + source + '}';
48
break;
49
50
case 'required':
51
// only fields for which "required" applies
52
source = 'if(typeof e.form!=="undefined"&&typeof e.required!="undefined"&&e.required){' + source + '}';
53
break;
54
55
case 'read-write':
56
// only fields for which "readOnly" applies
57
source = 'if(typeof e.form!=="undefined"&&typeof e.readOnly!="undefined"&&!e.readOnly){' + source + '}';
58
break;
59
60
case 'read-only':
61
// only fields for which "readOnly" applies
62
source = 'if(typeof e.form!=="undefined"&&typeof e.readOnly!="undefined"&&e.readOnly){' + source + '}';
63
break;
64
65
case 'invalid':
66
// only fields for which validity applies
67
source = 'if(typeof e.form!=="undefined"&&typeof e.validity=="object"&&!e.validity.valid){' + source + '}';
68
break;
69
70
case 'valid':
71
// only fields for which validity applies
72
source = 'if(typeof e.form!=="undefined"&&typeof e.validity=="object"&&e.validity.valid){' + source + '}';
73
break;
74
75
case 'in-range':
76
// only fields for which validity applies
77
source = 'if(typeof e.form!=="undefined"&&' +
78
'(s.getAttribute(e,"min")||s.getAttribute(e,"max"))&&' +
79
'typeof e.validity=="object"&&!e.validity.typeMismatch&&' +
80
'!e.validity.rangeUnderflow&&!e.validity.rangeOverflow){' + source + '}';
81
break;
82
83
case 'out-of-range':
84
// only fields for which validity applies
85
source = 'if(typeof e.form!=="undefined"&&' +
86
'(s.getAttribute(e,"min")||s.getAttribute(e,"max"))&&' +
87
'typeof e.validity=="object"&&(e.validity.rangeUnderflow||e.validity.rangeOverflow)){' + source + '}';
88
break;
89
90
default:
91
status = false;
92
break;
93
94
}
95
96
// compiler will add this to "source"
97
return global.Object({
98
'source': source,
99
'status': status
100
});
101
102
};
103
104
})(this));
105
106