aboutsummaryrefslogtreecommitdiff
path: root/point/data/html.js
diff options
context:
space:
mode:
Diffstat (limited to 'point/data/html.js')
-rw-r--r--point/data/html.js86
1 files changed, 86 insertions, 0 deletions
diff --git a/point/data/html.js b/point/data/html.js
new file mode 100644
index 0000000..66448cc
--- /dev/null
+++ b/point/data/html.js
@@ -0,0 +1,86 @@
1/*
2 * This file is part of "What's The Point" <https://github.com/Pacien/WhatsThePoint>
3 * Copyright (C) 2014 Pacien TRAN-GIRARD
4 *
5 * "What's The Point" is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * "What's The Point" is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19define(function () {
20
21 var xml = {
22
23 init: function () {
24 return;
25 },
26
27 getProp: function (object, dom, property, method) {
28 var elements = dom.getElementsByTagName(property);
29 if (elements.length > 0) {
30 object[property] = method(elements[0]);
31 }
32 return object;
33 },
34
35 getInnerText: function (object, dom, property) {
36 return this.getProp(object, dom, property, function (element) {
37 return element.textContent;
38 });
39 },
40
41 getInnerHtml: function (object, dom, property) {
42 return this.getProp(object, dom, property, function (element) {
43 if (window.XMLSerializer !== undefined) {
44 return (new window.XMLSerializer()).serializeToString(element);
45 } else if (element.xml !== undefined) {
46 return element.xml;
47 }
48 return element.innerHTML;
49 });
50 },
51
52 parseSlide: function (domSlide) {
53 var slide = {};
54
55 ["type", "title", "subtitle"].forEach(function (tag) {
56 xml.getInnerText(slide, domSlide, tag);
57 });
58
59 ["content", "notes"].forEach(function (tag) {
60 xml.getInnerHtml(slide, domSlide, tag);
61 });
62
63 return slide;
64 },
65
66 parseSlides: function (domSlides) {
67 var slides = [];
68
69 for (var i = 0; i < domSlides.length; i++) {
70 slides.push(this.parseSlide(domSlides[i]));
71 }
72
73 return slides;
74 },
75
76 parse: function (rawData, callback) {
77 var dom = new DOMParser().parseFromString(rawData, "text/xml");
78 var domSlides = dom.getElementsByTagName("slide");
79
80 callback(this.parseSlides(domSlides));
81 },
82 };
83
84 return xml;
85
86});