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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104 |
16x
16x
16x
16x
18x
16x
8x
8x
| /*
Copyright 2017 OCAD University
Licensed under the Educational Community License (ECL), Version 2.0 or the New
BSD license. You may not use this file except in compliance with one these
Licenses.
You may obtain a copy of the ECL 2.0 License and BSD License at
https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
*/
var fluid_3_0_0 = fluid_3_0_0 || {};
(function ($, fluid) {
"use strict";
/**********
* Switch *
**********/
fluid.defaults("fluid.switchUI", {
gradeNames: ["fluid.viewComponent"],
selectors: {
on: ".flc-switchUI-on",
off: ".flc-switchUI-off",
control: ".flc-switchUI-control"
},
strings: {
// Specified by implementor
// text of label to apply the switch, must add to "aria-label" in the attrs block
label: "",
on: "on",
off: "off"
},
attrs: {
// Specified by implementor
// ID of an element to use as a label for the switch
// "aria-labelledby": "",
// Should specify either "aria-label" or "aria-labelledby"
// "aria-label": "{that}.options.strings.label",
// ID of an element that is controlled by the switch.
// "aria-controls": ""
role: "switch",
tabindex: 0
},
model: {
enabled: false
},
modelListeners: {
enabled: {
"this": "{that}.dom.control",
method: "attr",
args: ["aria-checked", "{change}.value"]
}
},
listeners: {
"onCreate.addAttrs": {
"this": "{that}.dom.control",
method: "attr",
args: ["{that}.options.attrs"]
},
"onCreate.addOnText": {
"this": "{that}.dom.on",
method: "text",
args: ["{that}.options.strings.on"]
},
"onCreate.addOffText": {
"this": "{that}.dom.off",
method: "text",
args: ["{that}.options.strings.off"]
},
"onCreate.activateable": {
listener: "fluid.activatable",
args: ["{that}.dom.control", "{that}.activateHandler"]
},
"onCreate.bindClick": {
"this": "{that}.dom.control",
method: "on",
args: ["click", "{that}.toggleModel"]
}
},
invokers: {
toggleModel: {
funcName: "fluid.switchUI.toggleModel",
args: ["{that}"]
},
activateHandler: {
funcName: "fluid.switchUI.activateHandler",
args: ["{arguments}.0", "{that}.toggleModel"]
}
}
});
fluid.switchUI.toggleModel = function (that) {
that.applier.change("enabled", !that.model.enabled);
};
fluid.switchUI.activateHandler = function (event, fn) {
event.preventDefault();
fn();
};
})(jQuery, fluid_3_0_0);
|