1 | /*
|
2 | Copyright 2013-2015 ASIAL CORPORATION
|
3 |
|
4 | Licensed under the Apache License, Version 2.0 (the "License");
|
5 | you may not use this file except in compliance with the License.
|
6 | You may obtain a copy of the License at
|
7 |
|
8 | http://www.apache.org/licenses/LICENSE-2.0
|
9 |
|
10 | Unless required by applicable law or agreed to in writing, software
|
11 | distributed under the License is distributed on an "AS IS" BASIS,
|
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 | See the License for the specific language governing permissions and
|
14 | limitations under the License.
|
15 |
|
16 | */
|
17 |
|
18 | import util from './util.js';
|
19 |
|
20 | /**
|
21 | * @object ons.modifier
|
22 | * @category visual
|
23 | * @description
|
24 | * [en]
|
25 | * Utility methods to change modifier attributes of Onsen UI elements..
|
26 | * [/en]
|
27 | * [ja][/ja]
|
28 | * @example
|
29 | * ons.modifier.add(myOnsInputElement, 'underbar');
|
30 | * ons.modifier.toggle(myOnsToastElement, 'custom-modifier');
|
31 | *
|
32 | */
|
33 | export default {
|
34 | /**
|
35 | * @method add
|
36 | * @signature add(element, modifier [, modifier])
|
37 | * @description
|
38 | * [en]Add the specified modifiers to the element if they are not already included.[/en]
|
39 | * [ja][/ja]
|
40 | * @param {HTMLElement} element
|
41 | * [en]Target element.[/en]
|
42 | * [ja][/ja]
|
43 | * @param {String} modifier
|
44 | * [en]Name of the modifier.[/en]
|
45 | * [ja][/ja]
|
46 | */
|
47 | add: (element, ...modifiers) => modifiers.forEach(modifier => util.addModifier(element, modifier)),
|
48 | /**
|
49 | * @method remove
|
50 | * @signature remove(element, modifier [, modifier])
|
51 | * @description
|
52 | * [en]Remove the specified modifiers from the element if they are included.[/en]
|
53 | * [ja][/ja]
|
54 | * @param {HTMLElement} element
|
55 | * [en]Target element.[/en]
|
56 | * [ja][/ja]
|
57 | * @param {String} modifier
|
58 | * [en]Name of the modifier.[/en]
|
59 | * [ja][/ja]
|
60 | */
|
61 | remove: (element, ...modifiers) => modifiers.forEach(modifier => util.removeModifier(element, modifier)),
|
62 | /**
|
63 | * @method contains
|
64 | * @signature contains(element, modifier)
|
65 | * @description
|
66 | * [en]Check whether the specified modifier is included in the element.[/en]
|
67 | * [ja][/ja]
|
68 | * @param {HTMLElement} element
|
69 | * [en]Target element.[/en]
|
70 | * [ja][/ja]
|
71 | * @param {String} modifier
|
72 | * [en]Name of the modifier.[/en]
|
73 | * [ja][/ja]
|
74 | * @return {Boolean}
|
75 | * [en]`true` when the specified modifier is found in the element's `modifier` attribute. `false` otherwise.[/en]
|
76 | * [ja][/ja]
|
77 | */
|
78 | contains: util.hasModifier,
|
79 | /**
|
80 | * @method toggle
|
81 | * @signature toggle(element, modifier [, force])
|
82 | * @description
|
83 | * [en]Toggle the specified modifier.[/en]
|
84 | * [ja][/ja]
|
85 | * @param {HTMLElement} element
|
86 | * [en]Target element.[/en]
|
87 | * [ja][/ja]
|
88 | * @param {String} modifier
|
89 | * [en]Name of the modifier.[/en]
|
90 | * [ja][/ja]
|
91 | * @param {String} force
|
92 | * [en]If it evaluates to true, add specified modifier value, and if it evaluates to false, remove it.[/en]
|
93 | * [ja][/ja]
|
94 | */
|
95 | toggle: util.toggleModifier
|
96 | };
|