Bug fixes, aria, cross platform support.
This commit is contained in:
@@ -12,6 +12,7 @@ public protocol IGlobalContainer {
|
||||
var globalAttributes:Dictionary<GlobalAttributeKey, String> { get set }
|
||||
var globalEvents:Dictionary<GlobalEventKey, String> { get set }
|
||||
var dataAttributes:Dictionary<String, String> { get set }
|
||||
var ariaAttributes:Dictionary<String, String> { get set }
|
||||
}
|
||||
|
||||
extension IGlobalContainer {
|
||||
@@ -29,6 +30,10 @@ extension IGlobalContainer {
|
||||
dataAttributes[key] = value
|
||||
return true
|
||||
}
|
||||
if key[..<key.index(key.startIndex, offsetBy: 5)] == "aria-" {
|
||||
ariaAttributes[key] = value
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -53,23 +58,27 @@ public struct GlobalAttributesBuilder : IGlobalContainer{
|
||||
public var globalAttributes:Dictionary<GlobalAttributeKey, String> = [:]
|
||||
public var globalEvents:Dictionary<GlobalEventKey, String> = [:]
|
||||
public var dataAttributes:Dictionary<String, String> = [:]
|
||||
public var ariaAttributes:Dictionary<String, String> = [:]
|
||||
|
||||
public init(globalAttributes: Dictionary<GlobalAttributeKey, String>, globalEvents: Dictionary<GlobalEventKey, String>, dataAttributes: Dictionary<String, String>) {
|
||||
public init(globalAttributes: Dictionary<GlobalAttributeKey, String>, globalEvents: Dictionary<GlobalEventKey, String>, dataAttributes: Dictionary<String, String>, ariaAttributes: Dictionary<String, String> = [:]) {
|
||||
self.globalAttributes = globalAttributes
|
||||
self.globalEvents = globalEvents
|
||||
self.dataAttributes = dataAttributes
|
||||
self.ariaAttributes = ariaAttributes
|
||||
}
|
||||
|
||||
public init() {
|
||||
self.globalAttributes = [:]
|
||||
self.globalEvents = [:]
|
||||
self.dataAttributes = [:]
|
||||
self.ariaAttributes = [:]
|
||||
}
|
||||
|
||||
public init(_ attributes: [String: String]) throws {
|
||||
self.globalAttributes = [:]
|
||||
self.globalEvents = [:]
|
||||
self.dataAttributes = [:]
|
||||
self.ariaAttributes = [:]
|
||||
for (key, value) in attributes {
|
||||
if self.trySetGlobalAttribute(key, value) {
|
||||
continue
|
||||
@@ -101,6 +110,7 @@ public class HTMLNode : XMLNode, IGlobalContainer {
|
||||
|
||||
public var globalAttributes:Dictionary<GlobalAttributeKey, String> = [:]
|
||||
public var globalEvents:Dictionary<GlobalEventKey, String> = [:]
|
||||
public var ariaAttributes:Dictionary<String, String> = [:]
|
||||
|
||||
public var children:[HTMLNode] = []
|
||||
|
||||
@@ -115,23 +125,31 @@ public class HTMLNode : XMLNode, IGlobalContainer {
|
||||
globalEvents[attr] = value
|
||||
continue
|
||||
}
|
||||
if key[..<key.index(key.startIndex, offsetBy: 5)] == "data-" {
|
||||
dataAttributes[key] = value
|
||||
continue
|
||||
if key.count >= 5 {
|
||||
if key[..<key.index(key.startIndex, offsetBy: 5)] == "data-" {
|
||||
dataAttributes[key] = value
|
||||
continue
|
||||
}
|
||||
if key[..<key.index(key.startIndex, offsetBy: 5)] == "aria-" {
|
||||
ariaAttributes[key] = value
|
||||
continue
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
public init(globalAttributes:Dictionary<GlobalAttributeKey, String>, globalEvents:Dictionary<GlobalEventKey, String>, dataAttributes:Dictionary<String, String>) {
|
||||
public init(globalAttributes:Dictionary<GlobalAttributeKey, String>, globalEvents:Dictionary<GlobalEventKey, String>, dataAttributes:Dictionary<String, String>, ariaAttributes:Dictionary<String, String> = [:]) {
|
||||
self.globalAttributes = globalAttributes
|
||||
self.globalEvents = globalEvents
|
||||
self.ariaAttributes = ariaAttributes
|
||||
super.init(dataAttributes: dataAttributes)
|
||||
}
|
||||
|
||||
public init(_ builder:GlobalAttributesBuilder, _ children:[HTMLNode] = []) {
|
||||
self.globalAttributes = builder.globalAttributes
|
||||
self.globalEvents = builder.globalEvents
|
||||
self.ariaAttributes = builder.ariaAttributes
|
||||
self.children = children
|
||||
super.init(dataAttributes: builder.dataAttributes)
|
||||
}
|
||||
@@ -213,6 +231,18 @@ public class HTMLNode : XMLNode, IGlobalContainer {
|
||||
result += "\(eachAttr.key)"
|
||||
}
|
||||
}
|
||||
|
||||
for eachAttr in ariaAttributes {
|
||||
if (!first) {
|
||||
result += " "
|
||||
}
|
||||
first = false
|
||||
if (eachAttr.value.count > 0) {
|
||||
result += "\(eachAttr.key)='\(eachAttr.value)'"
|
||||
} else {
|
||||
result += "\(eachAttr.key)"
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
@@ -369,8 +399,13 @@ func isGlobalHTMLAttribute(_ key:String) -> Bool {
|
||||
if let _ = GlobalEventKey(rawValue: key.asSubstring()) {
|
||||
return true
|
||||
}
|
||||
if key[..<key.index(key.startIndex, offsetBy: 5)] == "data-" {
|
||||
return true
|
||||
if key.count >= 5 {
|
||||
if key[..<key.index(key.startIndex, offsetBy: 5)] == "data-" {
|
||||
return true
|
||||
}
|
||||
if key[..<key.index(key.startIndex, offsetBy: 5)] == "aria-" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user