-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrss-feed-legal-eagle.js
128 lines (106 loc) · 3.56 KB
/
rss-feed-legal-eagle.js
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
118
119
120
121
122
123
124
125
126
127
128
$(document).ready(function() {
var url = 'https://bclegaleagle.blogspot.com/feeds/posts/default?alt=json';
var defaultImage = 'https://bc.edu/content/dam/bc1/schools/law/js/library/rss-feed/rss-default-500x500.jpg';
var option2Image = 'https://bc.edu/content/dam/bc1/schools/law/js/library/rss-feed/rss-option2-502x502.jpg';
var option3Image = 'https://bc.edu/content/dam/bc1/schools/law/js/library/rss-feed/rss-option3-500x500.jpg';
var imageOptions = [defaultImage, option2Image, option3Image];
var imageOption = 1;
var ImageSize='500';
$.getJSON(
url + '&callback=?')
.done(function(data){
$.each(
data.feed.entry || [],
function(i, e){
if (i<4) {
var title = (e.title.$t || '');
if (title.length>75) {
title=title.replace(/^(.{70}[^\s]*).*/, "$1")+"...";
};
var postContent = (e.content.$t || '');
postContent = postContent.replace(/<br[^>]*>/g, ' ');
content = $.parseHTML(postContent);
var $content = $(content);
var thumbnail;
var url = (e.link || []).pop().href;
var date = new Date(e.updated.$t || Date.now());
if (e.media$thumbnail){
thumbnail = (e.media$thumbnail.url || '');
thumbnail = thumbnail.replace(/(w[0-9]+-h[0-9]+)|(s[0-9]+-c)|(s[0-9]+-w[0-9]+-h[0-9]+-c)/,"s"+ImageSize+"-c");
}
else {
//pull image from post if available
if ($content.find('img').addBack('img').length > 0) {
$content.find('img').addBack('img').each(function(i, value) {
if (!(e.media$thumbnail) || e.media$thumbnail.url.includes('cc-logo.png')) {
if (($(this).attr('height')> 200) && ($(this).attr('width') > 200)) {
e.media$thumbnail = {
url: $(this).attr('src'),
width: $(this).attr('width'),
height: $(this).attr('height')
};
console.log(e.media$thumbnail);
thumbnail = e.media$thumbnail.url;
thumbnail = thumbnail.replace(/(w[0-9]+-h[0-9]+)|(s[0-9]+-c)|(s[0-9]+-w[0-9]+-h[0-9]+-c)/,"s"+ImageSize+"-c");
}
}
})//end each loop
}
//use default image if needed
if (!(e.media$thumbnail)) {
thumbnail=imageOptions[imageOption-1];
if (imageOption < imageOptions.length){
imageOption++;
}
else {
imageOption = 1;
}
}
}
var content = (e.content.$t || '');
if (e.category) {
var category = (e.category[0].term || '');
}
var author = (e.author[0].name.$t || '');
var outerdiv =$('<div>')
.addClass('col-md-3 col-sm-6 col-xs-12');
var innerdiv =$('<div>')
.addClass('blogger-item');
var textdiv =$('<div>')
.addClass('blogger-text');
var imgBox = $('<div>')
.addClass('image-sizer');
var imglink = $('<a>)')
.attr('href', url)
.addClass('blogger-image');
var img = $('<img>')
.attr('src', thumbnail, 'alt', title)
.appendTo(imglink);
$(imglink).appendTo(imgBox);
$(imgBox).appendTo(innerdiv);
var categoryP = $('<p>')
.text(category)
.addClass('blogger-category')
.appendTo(textdiv);
var header = $('<h3>');
var a = $('<a>')
.text(title)
.attr('href', url)
.appendTo(header);
$(header).appendTo(textdiv);
var p = $('<p>')
.text("Posted by " + author)
.addClass('blogger-author')
.appendTo(textdiv);
$(textdiv).appendTo(innerdiv);
$(innerdiv).appendTo(outerdiv);
$(outerdiv).appendTo('#blogger');
$('.blogger-content-div img, .separator').hide();
}
// do your stuff here
});
})
.fail(function(){
// handle failure here
});
});