-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
65 lines (56 loc) · 2.28 KB
/
script.js
File metadata and controls
65 lines (56 loc) · 2.28 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
$(document).ready(function() {
loadContent();
});
function loadContent() {
$.get('news-feed.csv', function(data) {
var news = parseCSV(data);
console.log(news); // Output the parsed data to the console
var html = '';
for (var i = 0; i < news.length; i++) {
if (news[i].title && news[i].link) { // Check that the required fields are present
html += '<li><a href="#" onclick="openPopup(\'' + news[i].link + '\',\'' + news[i].title + '\')">' + news[i].title + '</a></li>';
} else if (news[i].title || news[i].link) { // Check if either field is present
console.log('Warning: missing data in row ' + (i+1)); // Log a warning message if data is missing
}
}
$('#news-feed').html(html);
}).fail(function() {
console.log('Error: could not load data from CSV file'); // Log an error message if the data could not be loaded
});
}
function openPopup(link,title) {
var popupHTML = '<div class="modal fade" id="popup" tabindex="-1" aria-labelledby="popupLabel" aria-hidden="true">';
popupHTML += '<div class="modal-dialog modal-dialog-centered">';
popupHTML += '<div class="modal-content">';
popupHTML += '<div class="modal-header">';
popupHTML += '<h5 class="modal-title" id="popupLabel">'+title+'</h5>';
popupHTML += '<button type="button" class="close" data-dismiss="modal" aria-label="Close">';
popupHTML += '<span aria-hidden="true">×</span>';
popupHTML += '</button>';
popupHTML += '</div>';
popupHTML += '<div class="modal-body">';
popupHTML += '<p><iframe src="' + link + '"></iframe></p>';
popupHTML += '</div>';
popupHTML += '</div>';
popupHTML += '</div>';
popupHTML += '</div>';
$('body').append(popupHTML);
$('#popup').modal('show');
$('#popup').on('hidden.bs.modal', function() {
$(this).remove();
});
}
function parseCSV(data) {
var lines = data.split('\n');
var headers = lines[0].split(',');
var news = [];
for (var i = 1; i < lines.length; i++) {
var row = {};
var cells = lines[i].split(',');
for (var j = 0; j < cells.length; j++) {
row[headers[j].trim()] = cells[j].trim();
}
news.push(row);
}
return news;
}