Created
June 3, 2011 18:38
-
-
Save infynyxx/1006898 to your computer and use it in GitHub Desktop.
horizon.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var a; | |
var b = function(c, d) { | |
return function() { | |
return c.apply(d, arguments) | |
} | |
}; | |
window.Sailthru = window.sailthru = a = (function() { | |
var f, e, g, d; | |
function c() {} | |
d = null; | |
g = {}; | |
e = {}; | |
f = {}; | |
e = {}; | |
c.setup = function(j) { | |
var i, h; | |
if (typeof j.domain === "undefined") { | |
return | |
} | |
if (!(this.__instance instanceof c)) { | |
this.__instance = new this; | |
this.__instance.options = { | |
tags: this.__instance.getContentTags(), | |
spider: true, | |
concierge: false | |
}; | |
for (i in j) { | |
h = j[i]; | |
this.__instance.options[i] = j[i] | |
} | |
if (this.__instance.options.concierge && navigator.cookieEnabled && this.__instance.getCookie("sailthru_recommendation_hidden") !== "true") { | |
this.__instance.options.concierge = { | |
from: "top", | |
threshold: 400 | |
}; | |
this.__instance._recommendationBox() | |
} else { | |
if (typeof this.__instance.options.tags !== "undefined" || this.__instance.options.spider === true) { | |
this.__instance._horizonTrack() | |
} | |
} | |
} | |
return this.__instance | |
}; | |
c.prototype.getContentTags = function() { | |
var n, i, m, l, j, h; | |
n = document.getElementsByTagName("meta"); | |
if (n.length > 0) { | |
for (m = 0, j = n.length; m < j; m++) { | |
i = n[m]; | |
if (typeof i.name !== "undefined" && i.name.toLowerCase() === "sailthru.tags") { | |
return i.content | |
} | |
} | |
for (l = 0, h = n.length; l < h; l++) { | |
i = n[l]; | |
if (typeof i.name !== "undefined" && i.name.toLowerCase() === "keywords") { | |
return i.content | |
} | |
} | |
} | |
return null | |
}; | |
c.prototype.getCookie = function(j) { | |
var n, i, m, l, h; | |
m = j + "="; | |
i = document.cookie.split(";"); | |
for (l = 0, h = i.length; l < h; l++) { | |
n = i[l]; | |
while (n.charAt(0) === " ") { | |
n = n.substring(1, n.length) | |
} | |
if (n.indexOf(m) === 0) { | |
return n.substring(m.length, n.length) | |
} | |
} | |
return null | |
}; | |
c.prototype.setCookie = function(i, j, l) { | |
var h; | |
h = new Date(); | |
h.setDate(h.getDate() + l); | |
document.cookie = i + "=" + escape(j) + (l !== null ? ";expires=" + h.toUTCString() : void 0); | |
return true | |
}; | |
c.prototype.tagsToString = function(i) { | |
var h; | |
h = i instanceof Array ? i.join(",") : i; | |
return h | |
}; | |
c.prototype.recommendationTrack = function(m, j, h, l) { | |
var o, i, n, p, q; | |
if (typeof this.tracked === "undefined") { | |
this.tracked = {} | |
} | |
if (this.tracked[h]) { | |
return | |
} | |
this.tracked[h] = true; | |
i = "http://" + m + "/horizon/recommendtrack?id=" + j; | |
if (h) { | |
i += "&event=" + h | |
} | |
if (l) { | |
for (n = 0, p = l.length; n < p; n++) { | |
q = l[n]; | |
i += "&" + k + "=" + encodeURIComponent(q) | |
} | |
} | |
i += "&cb=" + Math.random(); | |
o = new Image(1, 1); | |
o.src = i; | |
o.onerror = ""; | |
return true | |
}; | |
c.recommendationBoxCallback = function(h) { | |
return c.jq(document).trigger("SailthruDataLoaded", [h]) | |
}; | |
c.prototype.test = function() { | |
console.log("a"); | |
return true | |
}; | |
c.prototype._recommendationBox = function() { | |
var o, l, m, q, h, r, j, p, i, n; | |
this.defaults = { | |
from: "bottom", | |
threshold: 100, | |
delay: null, | |
offsetBottom: 0, | |
url: "http://" + this.options.domain + "/recommend?format=jsonp&callback=?", | |
cssPath: "http://cdn.sailthru.com/assets/css/horizon/recommendation.css", | |
showReadMore: false | |
}; | |
o = c.jq.extend({}, this.defaults, this.options.concierge); | |
h = null; | |
l = false; | |
if (this.options.concierge.filter && this.options.concierge.filter.tags) { | |
o.url = o.url + "&filter[tags]=" + this.tagsToString(this.options.filter.tags) | |
} | |
if (this.options.spider !== true) { | |
o.url += "&nospider=1" | |
} | |
if (this.options.tags) { | |
o.url += "&tags=" + encodeURIComponent(this.tagsToString(this.options.tags)) | |
} | |
this.data = {}; | |
q = this; | |
m = typeof this.options.delay !== "undefined" ? this.options.delay : false; | |
p = function() { | |
i(o.cssPath); | |
c.jq(document).bind("SailthruDataLoaded", b(function(t, s) { | |
this.data = s; | |
this.dataLoaded = true; | |
return r() | |
}, this)); | |
c.jq.getJSON(o.url); | |
c.jq(window).scroll(b(function(w) { | |
var v, t, u, x, s; | |
if (this.dataLoaded === true) { | |
v = c.jq(this); | |
u = v.scrollTop(); | |
t = c.jq(document).height() - c.jq(window).height(); | |
if (o.threshold instanceof jQuery) { | |
s = 0 - (o.threshold.eq(0).offset().top - c.jq(window).height()); | |
x = 0 | |
} else { | |
s = o.from === "bottom" ? o.threshold : -o.threshold; | |
x = o.from === "bottom" ? t : 0 | |
} | |
if (u >= (x - s)) { | |
return n() | |
} else { | |
return j() | |
} | |
} | |
}, this)); | |
if (m) { | |
return h = setTimeout(b(function() { | |
clearTimeout(h); | |
return n() | |
}, this), m) | |
} | |
}; | |
i = function(s) { | |
return c.jq('<link href="' + s + '" type="text/css" rel="stylesheet" />').appendTo("head") | |
}; | |
r = function() { | |
var t, s, B, y, v, A, u, x, D, C, z, w; | |
w = this.data.content; | |
s = c.jq('<div class="recommendation sailthruRecommendation" />'); | |
if (typeof w.html !== "undefined") { | |
s.html(w.html); | |
B = s.find("a.closeRecommendation"); | |
u = s.find("a.openRecommendation"); | |
s.appendTo("body") | |
} else { | |
B = c.jq('<a class="closeRecommendation imgReplace" href="javascript:void(0);"><span>Close</span></a>'); | |
u = c.jq('<a class="openRecommendation imgReplace" href="javascript:void(0);"><span>Open</span></a>'); | |
x = c.jq('<div class="openWrapper" />'); | |
z = c.jq('<div class="recommendationWrapper" />'); | |
C = c.jq('<div class="recommendationThumb" />'); | |
y = c.jq('<div class="recommendationDetails" />'); | |
A = c.jq('<span class="recommendationCategory row">Recommended for You</span>'); | |
t = c.jq('<span class="recommendationTitle row"><a href="' + w.url + '">' + w.title + "</a></span>"); | |
D = c.jq('<a class="recommendationLink" href="' + w.url + '">Read More ></a>'); | |
v = c.jq('<div class="recommendationFooter"><a href="http://sailthru.com/">Powered by Sailthru</a></div>'); | |
x.append(u); | |
y.append(A, t, D); | |
z.append(C, y); | |
s.append(B, x, z, v).appendTo("body"); | |
if (w.thumb) { | |
C.append('<img src="' + w.thumb + '" />') | |
} else { | |
C.hide() | |
} | |
if (!o.showReadMore) { | |
D.hide() | |
} | |
} | |
B.click(b(function(E) { | |
E.preventDefault(); | |
q.setCookie("sailthru_recommendation_hidden", "true", 30); | |
j(); | |
return false | |
}, this)); | |
u.click(b(function(E) { | |
E.preventDefault(); | |
q.setCookie("sailthru_recommendation_hidden", "false", 30); | |
n(); | |
return false | |
}, this)); | |
setTimeout(b(function() { | |
var F, G, E; | |
F = c.jq('<iframe src="" FRAMEBORDER="0" />'); | |
G = { | |
bottom: o.offsetBottom, | |
zIndex: "10000" | |
}; | |
s.css(G); | |
E = { | |
position: "fixed", | |
width: s.outerWidth(), | |
height: s.outerHeight(), | |
zIndex: "9999", | |
right: 0, | |
bottom: o.offsetBottom, | |
display: "none" | |
}; | |
F.css(E); | |
if (c.jq.browser.msie) { | |
s.add(F).addClass("ie"); | |
if (c.jq.browser.version === "6.0") { | |
s.add(F).addClass("ie6") | |
} | |
} | |
if (s.is(".ie6")) { | |
s.add(F).css("position", "absolute") | |
} | |
F.appendTo("body"); | |
this.$elem = s; | |
return this.$iframe = F | |
}, this), 100) | |
}; | |
n = function() { | |
if (!navigator.cookieEnabled) { | |
return false | |
} | |
if (q.getCookie("sailthru_recommendation_hidden" === "true")) { | |
return false | |
} | |
if (this.$elem && !$elem.is(":animated")) { | |
this.$elem.find(".openWrapper").hide(); | |
this.$iframe.show(); | |
this.$elem.show().animate({ | |
right: 0 | |
}, "normal") | |
} | |
return q.recommendationTrack(o.domain, this.data.content.id, "show", this.data.track) | |
}; | |
j = function() { | |
var v, s, u, t; | |
if (this.$elem && !this.$elem.is(":animated")) { | |
s = this.$elem.find(".openWrapper"); | |
v = s.children("a"); | |
u = (this.$elem.outerHeight() / 2) - 11; | |
s.show(); | |
t = this.$elem.outerWidth() - s.outerWidth(); | |
return this.$elem.animate({ | |
right: -t | |
}, "normal", b(function() { | |
return this.$iframe.hide() | |
}, this)) | |
} | |
}; | |
return p() | |
}; | |
c.prototype._horizonTrack = function() { | |
var j, m, l, o, i, n, h; | |
m = parseInt(Math.random() * 10000, 10); | |
l = "http://" + this.options.domain + "/horizon/track?r=" + m + "&url=" + encodeURIComponent(document.location); | |
if (typeof this.options.tag !== "undefined") { | |
this.options.tags = this.options.tag | |
} | |
if (this.options.tags) { | |
if (this.options.tags instanceof Array) { | |
l += "&tags=" + encodeURIComponent(params.tags.join(",")) | |
} else { | |
if (this.options.tags instanceof Object) { | |
n = params.tags; | |
for (o = 0, i = n.length; o < i; o++) { | |
h = n[o]; | |
l += "&tags[" + encodeURIComponent(k) + "]=" + encodeURIComponent(h) | |
} | |
} else { | |
l += "&tags=" + encodeURIComponent(this.options.tags) | |
} | |
} | |
} | |
if (this.options.spider) { | |
l += "&spider=1" | |
} | |
j = new Image(1, 1); | |
j.src = l; | |
j.onerror = ""; | |
return | |
}; | |
return c | |
})(); | |
if (window.$) { | |
a.jq = $ | |
} | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment