forked from adamlaska/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagenda_materials.js
More file actions
84 lines (78 loc) · 2.85 KB
/
agenda_materials.js
File metadata and controls
84 lines (78 loc) · 2.85 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
// Copyright The IETF Trust 2021, All Rights Reserved
/*
Javascript support for the materials modal rendered by session_agenda_include.html
Requires jquery be loaded
*/
var agenda_materials; // public interface
(function() {
'use strict';
/**
* Retrieve and display materials for a session
*
* If output_elt exists and has a "data-src" attribute, retrieves the document
* from that URL and displays under output_elt. Handles text/plain, text/markdown,
* and text/html.
*
* @param output_elt Element, probably a div, to hold the output
*/
function retrieve_session_materials(output_elt) {
if (!output_elt) {return;}
output_elt = $(output_elt);
var data_src = output_elt.attr("data-src");
if (!data_src) {
output_elt.html("<p>Error: missing data-src attribute</p>");
} else {
output_elt.html("<p>Loading " + data_src + "...</p>");
var outer_xhr = $.ajax({url:data_src,headers:{'Accept':'text/plain;q=0.8,text/html;q=0.9'}})
outer_xhr.done(function(data, status, xhr) {
var t = xhr.getResponseHeader("content-type");
if (!t) {
data = "<p>Error retrieving " + data_src
+ ": Missing content-type in response header</p>";
} else if (t.indexOf("text/plain") > -1) {
data = "<pre class='agenda'>" + data + "</pre>";
} else if (t.indexOf("text/markdown") > -1) {
data = "<pre class='agenda'>" + data + "</pre>";
} else if(t.indexOf("text/html") > -1) {
// nothing to do here
} else {
data = "<p>Unknown type: " + xhr.getResponseHeader("content-type") + "</p>";
}
output_elt.html(data);
}).fail(function() {
output_elt.html("<p>Error retrieving " + data_src
+ ": (" + outer_xhr.status.toString() + ") "
+ outer_xhr.statusText + "</p>");
})
}
}
/**
* Retrieve contents of a session materials modal
*
* Expects output_elt to exist and have a "data-src" attribute. Retrieves the
* contents of that URL, then attempts to populate the .agenda-frame and
* .minutes-frame elements.
*
* @param output_elt Element, probably a div, to hold the output
*/
function retrieve_session_modal(output_elt) {
if (!output_elt) {return;}
output_elt = $(output_elt);
var data_src = output_elt.attr("data-src");
if (!data_src) {
output_elt.html("<p>Error: missing data-src attribute</p>");
} else {
output_elt.html("<p>Loading...</p>");
$.get(data_src).done(function(data) {
output_elt.html(data);
retrieve_session_materials(output_elt.find(".agenda-frame"));
retrieve_session_materials(output_elt.find(".minutes-frame"));
});
}
}
$(document).ready(function() {
$(".modal").on("show.bs.modal", function () {
retrieve_session_modal($(this).find(".session-materials"));
});
})
})();