-
Notifications
You must be signed in to change notification settings - Fork 0
/
blog-feed-widget.js
93 lines (88 loc) · 4.19 KB
/
blog-feed-widget.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
var siteDomain = document.domain;
var currentPath = document.location.pathname;
var blogFeed;
//var dataCategory = "bedroom";
// check domain and set the feed
if(siteDomain.indexOf("valuecityfurniture.com") != -1) {
if (currentPath.match("/bedroom")) {
var blogFeed = "http://www.valuecityfurniture.com/blog/space-planning-tips/bedroom/feed/";
}
else if (currentPath.match("/living-room")) {
var blogFeed = "http://www.valuecityfurniture.com/blog/space-planning-tips/living-room/feed/";
}
else if (currentPath.match("/dining-room")) {
var blogFeed = "http://www.valuecityfurniture.com/blog/space-planning-tips/dining-room/feed/";
}
else if (currentPath.match("/accents")) {
var blogFeed = "http://www.valuecityfurniture.com/blog/tags/accents/feed/";
}
else if (currentPath.match("/mattress")) {
var blogFeed = "http://www.valuecityfurniture.com/blog/tags/mattress/feed/";
}
else if (currentPath.match("/black-friday")) {
var blogFeed = "http://www.valuecityfurniture.com/blog/tags/the-holidays/feed/";
}
}
else {
if (currentPath.match("/bedroom")) {
var blogFeed = "http://www.americansignaturefurniture.com/blog/space-planning-tips/bedroom/feed/";
}
else if (currentPath.match("/living-room")) {
var blogFeed = "http://www.americansignaturefurniture.com/blog/space-planning-tips/living-room/feed/";
}
else if (currentPath.match("/dining-room")) {
var blogFeed = "http://www.americansignaturefurniture.com/blog/space-planning-tips/dining-room/feed/";
}
else if (currentPath.match("/accents")) {
var blogFeed = "http://www.americansignaturefurniture.com/blog/tags/accents/feed/";
}
else if (currentPath.match("/mattress")) {
var blogFeed = "http://www.americansignaturefurniture.com/blog/tags/mattress/feed/";
}
else if (currentPath.match("/black-friday")) {
var blogFeed = "http://www.americansignaturefurniture.com/blog/tags/the-holidays/feed/";
}
}
// create click handler, send GA the events
$(document).ready(function() {
//console.log("document is ready!");
$(document).on('click','#hawkcustomhtml a', function(event){
var eventCategory = "click";
var ePosition = $(this).attr('data-position');
var eAction = this.text;
var eLabel = this.href+':pos='+ePosition;
if(!eAction){
var eAction = $(this).find('img').attr('alt');
}
//console.log("eventCategory: click, eventAction: "+eAction+", eventLabel: "+eLabel);
ga('send', { hitType: 'event', eventCategory: 'click', eventAction: eAction, eventLabel: eLabel })
});
});
// parse the feed, prepend to DOM
$.ajax({
url : 'http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&callback=?&q=' + encodeURIComponent(blogFeed),
dataType : 'json',
success : function (data) {
var entry = data.responseData.feed.entries;
// for loop must start at entry.length index 9 and work down to 0
// in order to parse the blog entries in the right order
// and ensure that the latest blog posts are loaded first
for (var i = 9; i < entry.length; i--) {
var postTitle = entry[i].title;
var postSnippet = entry[i].contentSnippet;
var postLead = jQuery.trim(postSnippet).substring(0, 100).split(" ").slice(0, -1).join(" ");
var postLink = entry[i].link;
var postContent = entry[i].content;
var publishedDate = entry[i].publishedDate;
var imgContent = entry[i].content;
var imgDiv = document.createElement('div');
imgDiv.innerHTML = postContent;
var postImage = imgDiv.getElementsByTagName('img')[0];
var postImgSrc = postImage ? postImage.getAttribute("src") : "";
$("#blog-feed").prepend('<div class="panel panel-default blog-panel" style="box-shadow:none;margin-top:0;margin-bottom:0;margin-left:0.375em;margin-right:0.75em;"><div class="panel-body blog-panel-body"><a data-position="bottom-feed" href="'+postLink+'" target="_self" class="thumbnail" style="padding-bottom:15px;"><img src="'+postImgSrc+'" class="img-responsive center-block"><h4>'+postTitle+'</h4><p style="padding:0px 10px;font-size:14px;">'+postLead+'...<span style="color:#cc0000;">read more</span></p></a></div></div>');
}
},
error : function (data){
// var uhoh!;
}
});