5 // Created by Kevin Jantzer on 12/30/15.
11 // Media Overlay Documentation
12 // http://www.idpf.org/accessibility/guidelines/content/overlays/overview.php#mo005-samp
15 class FRSmilElement: NSObject {
16 var name: String // the name of the tag: <seq>, <par>, <text>, <audio>
17 var attributes: [String: String]!
18 var children: [FRSmilElement]
20 init(name: String, attributes: [String:String]!) {
22 self.attributes = attributes
23 self.children = [FRSmilElement]()
26 // MARK: - Element attributes
28 func getId() -> String! {
29 return getAttribute("id")
32 func getSrc() -> String! {
33 return getAttribute("src")
37 Returns array of Strings if `epub:type` attribute is set. An array is returned as there can be multiple types specified, seperated by a whitespace
39 func getType() -> [String]! {
40 let type = getAttribute("epub:type", defaultVal: "")
41 return type!.components(separatedBy: " ")
45 Use to determine if this element matches a given type
49 epub:type="bodymatter chapter"
50 isType("bodymatter") -> true
52 func isType(_ aType:String) -> Bool {
53 return getType().contains(aType)
56 func getAttribute(_ name: String, defaultVal: String!) -> String! {
57 return attributes[name] != nil ? attributes[name] : defaultVal;
60 func getAttribute(_ name: String ) -> String! {
61 return getAttribute(name, defaultVal: nil)
64 // MARK: - Retrieving children elements
66 // if <par> tag, a <text> is required (http://www.idpf.org/epub/301/spec/epub-mediaoverlays.html#sec-smil-par-elem)
67 func textElement() -> FRSmilElement! {
68 return childWithName("text")
71 func audioElement() -> FRSmilElement! {
72 return childWithName("audio")
75 func videoElement() -> FRSmilElement! {
76 return childWithName("video")
79 func childWithName(_ name:String) -> FRSmilElement! {
81 if( el.name == name ){
88 func childrenWithNames(_ name:[String]) -> [FRSmilElement]! {
89 var matched = [FRSmilElement]()
91 if( name.contains(el.name) ){
98 func childrenWithName(_ name:String) -> [FRSmilElement]! {
99 return childrenWithNames([name])
102 // MARK: - Audio clip info
104 func clipBegin() -> Double {
105 let val = audioElement().getAttribute("clipBegin", defaultVal: "")
106 return val!.clockTimeToSeconds()
109 func clipEnd() -> Double {
110 let val = audioElement().getAttribute("clipEnd", defaultVal: "")
111 return val!.clockTimeToSeconds()