forked from wordpress-mobile/AztecEditor-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewController.swift
More file actions
117 lines (88 loc) · 4.19 KB
/
Copy pathViewController.swift
File metadata and controls
117 lines (88 loc) · 4.19 KB
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
import UIKit
///
///
class ViewController: UITableViewController
{
let cellIdentifier = "CellIdentifier"
var sections: [DemoSection]!
// MARK: LifeCycle Methods
override func viewDidLoad() {
super.viewDidLoad()
sections = [
DemoSection(title: "Plain HTML Editor", rows: [
DemoRow(title: "Standard Demo", action: { self.showEditorDemo(filename: "content") }),
DemoRow(title: "Captions Demo", action: { self.showEditorDemo(filename: "captions") }),
DemoRow(title: "Image Overlays", action: { self.showEditorDemo(filename: "imagesOverlays") }),
DemoRow(title: "Video Demo", action: { self.showEditorDemo(filename: "video", wordPressMode: false) }),
DemoRow(title: "Failed Media", action: { self.showEditorDemo(filename: "failedMedia") }),
DemoRow(title: "Big Lists", action: { self.showEditorDemo(filename: "bigLists") }),
DemoRow(title: "Underline NBSP", action: { self.showEditorDemo(filename: "underline")}),
DemoRow(title: "Empty Demo", action: { self.showEditorDemo() })
]
),
DemoSection(title: "WordPressEditor (Calypso & Gutenberg)", rows: [
DemoRow(title: "Gutenberg Demo", action: { self.showEditorDemo(filename: "gutenberg", wordPressMode: true) }),
DemoRow(title: "Video Shortcode Demo", action: { self.showEditorDemo(filename: "videoShortcodes", wordPressMode: true) }),
DemoRow(title: "Gutenberg Gallery", action: { self.showEditorDemo(filename: "gallery", wordPressMode: true) }),
DemoRow(title: "Empty Demo", action: { self.showEditorDemo(wordPressMode: true) })
]
),
]
}
// MARK: Actions
func showEditorDemo(filename: String? = nil, wordPressMode: Bool = false) {
let controller: EditorDemoController
if let filename = filename {
let sampleHTML = getSampleHTML(fromHTMLFileNamed: filename)
controller = EditorDemoController(withSampleHTML: sampleHTML, wordPressMode: wordPressMode)
} else {
controller = EditorDemoController(wordPressMode: wordPressMode)
}
navigationController?.pushViewController(controller, animated: true)
}
// MARK: Sample HTML
func getSampleHTML(fromHTMLFileNamed fileName: String) -> String {
let htmlFilePath = Bundle.main.path(forResource: fileName, ofType: "html")!
let fileContents: String
do {
fileContents = try String(contentsOfFile: htmlFilePath)
} catch {
fatalError("Could not load the sample HTML. Check the file exists in the target and that it has the correct name.")
}
return fileContents
}
// MARK: TableView Methods
override func numberOfSections(in tableView: UITableView) -> Int {
return sections.count
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return sections[section].rows.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)!
cell.accessoryType = .disclosureIndicator
//cell.backgroundColor = UIColor.
let row = sections[indexPath.section].rows[indexPath.row]
cell.textLabel?.text = row.title
return cell
}
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 40
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return sections[section].title
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
sections[indexPath.section].rows[indexPath.row].action()
}
}
typealias RowAction = () -> Void
struct DemoSection {
var title: String
var rows: [DemoRow]
}
struct DemoRow {
var title: String
var action: RowAction
}