-
Notifications
You must be signed in to change notification settings - Fork 15
/
attributes.cfc
132 lines (86 loc) · 4.23 KB
/
attributes.cfc
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<cfcomponent name="Attributes">
<cfparam name="variables.attributes" default="" />
<!-------------------------------------------------------------------------------------------- init
Description: Initialize the attributes structure from the Arguments collection. Known arguments
are ignored while unrecognized arguments are added to the attributes structure.
Arguments: A structure containing an arbitrary number of Arguments
Return Value: None
----------------------------------------------------------------------------------------------------->
<cffunction name="init">
<cfargument name="reserved_arguments" default="" />
<!--- Setup a structure to hold the (key,value) attributes for the HTML tag --->
<cfset variables.attributes = StructNew() />
<!--- Loop over the argument collection and place unrecognized keys into the attributes struct --->
<cfloop collection="#Arguments#" item="key">
<cfset key = LCase(key) />
<cfif key NEQ "reserved_arguments" AND NOT ListFind(arguments.reserved_arguments, key)>
<cfset StructInsert(variables.attributes, key, StructFind(Arguments, key), "true") />
</cfif>
</cfloop>
</cffunction>
<!---------------------------------------------------------------------------------------------- add
Description: Add an attribute to the list if it is not already present. If the attribute exists
then it does not get updated.
Arguments: key - The name of the attribute
value - The value of the attribute
Return Value: None
----------------------------------------------------------------------------------------------------->
<cffunction name="add">
<cfargument name="key" />
<cfargument name="value" />
<cfif NOT StructKeyExists(variables.attributes, arguments.key)>
<cfset StructInsert(attributes, arguments.key, arguments.value) />
</cfif>
</cffunction>
<!---------------------------------------------------------------------------------------------- get
Description: Gets the value of an existing attribute.
Arguments: key - The name of the attribute
Return Value: None
----------------------------------------------------------------------------------------------------->
<cffunction name="get">
<cfargument name="key" />
<cfif StructKeyExists(attributes, key)>
<cfreturn StructFind(attributes, key) />
<cfelse>
<cfreturn "" />
</cfif>
</cffunction>
<!---------------------------------------------------------------------------------------------- set
Description: Sets the value of an existing attribute.
Arguments: key - The name of the attribute
value - The value of the attribute
Return Value: None
----------------------------------------------------------------------------------------------------->
<cffunction name="set">
<cfargument name="key" />
<cfargument name="value" />
<cfset StructInsert(attributes, arguments.key, arguments.value, "true") />
</cffunction>
<!---------------------------------------------------------------------------------------------- remove
Description: Sets the value of an existing attribute.
Arguments: key - The name of the attribute
value - The value of the attribute
Return Value: None
----------------------------------------------------------------------------------------------------->
<cffunction name="remove">
<cfargument name="key" />
<cfif StructKeyExists(attributes,arguments.key)>
<cfset StructDelete(attributes, arguments.key) />
</cfif>
</cffunction>
<!------------------------------------------------------------------------------------------- string
Description: Gets the string of attributes. The string is of the form:
attribute1="value1" attribute2="value2" ...
Arguments: None
Return Value: The string of attributes to be placed within the HTML tag
----------------------------------------------------------------------------------------------------->
<cffunction name="string">
<cfset attribute_string = "" />
<cfloop collection="#attributes#" item="key">
<cfif key neq "multiple">
<cfset attribute_string = attribute_string & ' #key#="#StructFind(attributes,key)#"' />
</cfif>
</cfloop>
<cfreturn attribute_string />
</cffunction>
</cfcomponent>