Created
October 25, 2012 14:02
-
-
Save michaeldelorenzo/3952721 to your computer and use it in GitHub Desktop.
Hootsuite SDK JS fix for HTTPS
This file contains 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
// downloaded from https://d2l6uygi1pgnys.cloudfront.net/jsapi/0-5/hsp.js? | |
// to fix a bug in Hootsuite SDK | |
var hsp = {}; | |
(function () { | |
hsp = new function () { | |
var g = "https:" == document.location.protocol ? "https://" : "http://", | |
q = g + "d2l6uygi1pgnys.cloudfront.net/jsapi/0-5/assets", | |
r = g + "d2l6uygi1pgnys.cloudfront.net/jsapi/json2.js", | |
j = "https:" == document.location.protocol ? "https://" : "http://", | |
l = !0, | |
c = function (b, d, f, e, c) { | |
if ("undefined" == typeof c || null == c) c = ""; | |
var g = "hspframe" + c; | |
if ((c = document.getElementById(g)) && e) document.body.removeChild(c), c = null; | |
c || (c = document.createElement("iframe"), c.id = c.name = g, c.style.cssText = "width: 1px; height: 1px; display: none; position: absolute; top: -999;", document.body.appendChild(c)); | |
b = document.location.protocol + "//" + "hootsuite.com/dc_receiver.html#?action=" + encodeURIComponent(b) + "&p1=" + encodeURIComponent(d) + "&p2=" + encodeURIComponent(f) + "&key=" + encodeURIComponent(a.apiKey) + "&pid=" + encodeURIComponent(a.pid); | |
c.src = b | |
}, i = function (a) { | |
a || (a = function () {}); | |
if ("undefined" === typeof JSON) { | |
var d = document.createElement("script"); | |
d.type = "text/javascript"; | |
d.async = !0; | |
d.src = r; | |
var c = document.getElementsByTagName("script")[0]; | |
c.parentNode.insertBefore(d, c); | |
var e = function () { | |
"undefined" !== typeof JSON ? a() : setTimeout(e, 100) | |
}; | |
setTimeout(e, | |
100) | |
} else a() | |
}, m = function (a) { | |
var d = window.location.href, | |
d = RegExp(a.toLowerCase() + "=[^&]+", "i").exec(d), | |
a = ""; | |
d && d.length && (d = d[0].split("="), 1 < d.length && (a = d[1])); | |
return a | |
}, a = this, | |
k; | |
this.receiverPath = this.pid = this.apiKey = ""; | |
this.boundEvents = []; | |
this.fnOnSendProfileToApp = this.fnOnSendComposedMsgToApp = this.fnOnSendToApp = this.fnOnClosePopUp = this.fnOnDropUser = this.fnOnRefresh = this.fnOnMessageSend = this.fnPhoneHome = this.fnOnGetTwitterAccounts = null; | |
this.init = function (b) { | |
var d = Math.floor(Math.random() * (new Date).getTime()), | |
f = function (c) { | |
a.fnPhoneHome = void 0; | |
parseInt(c) === d && (l = !0, b && b.subtitle && a.updatePlacementSubtitle(b.subtitle)) | |
}; | |
a.pid = m("pid"); | |
if (b) { | |
a.apiKey = b.apiKey || ""; | |
a.receiverPath = b.receiverPath || ""; | |
a.callBack = b.callBack; | |
b.apiKey && (a.pid && b.receiverPath) && (l = !1, this.fnPhoneHome = f, setTimeout(function () { | |
"undefined" != typeof a.fnPhoneHome && a.fnPhoneHome() | |
}, 5E3)); | |
var f = a.apiKey + "_" + a.pid, | |
e = parent.frames[f]; | |
a.apiKeyIsVerified = e && f == e.name ? !0 : !1; | |
if (b.useTheme && "false" !== b.useTheme && "0" !== b.useTheme) { | |
f = "classic"; | |
e = m("theme"); | |
e.match(/^(blue_steel|classic|magnum)$/) && (f = e); | |
var g = h = null, | |
i = 0, | |
k = b.onThemeLoad ? b.onThemeLoad : function () {}, j = function () { | |
k(); | |
g && (clearTimeout(g), g = null); | |
h && (document.body.removeChild(h), h = null) | |
}, p = function () { | |
i++; | |
var a = document.getElementById(n); | |
if (a.currentStyle) var b = a.currentStyle.position; | |
else window.getComputedStyle && (b = document.defaultView.getComputedStyle(a, null).getPropertyValue("position")); | |
"fixed" == b || 10 <= i ? j() : g = setTimeout(p, 100) | |
}, e = document.createElement("link"); | |
e.type = "text/css"; | |
e.rel = "stylesheet"; | |
e.href = q + "/css/ad_" + f + ".css"; | |
e.onload = function () { | |
j() | |
}; | |
f = document.getElementsByTagName("head"); | |
f.length && f[0].appendChild(e); | |
if (b.onThemeLoad) { | |
var n = "hsLoadCheck", | |
h = document.createElement("div"); | |
h.id = n; | |
h.style.cssText = "display:none;"; | |
document.body.appendChild(h); | |
g = setTimeout(p, 100) | |
} | |
} | |
} | |
c("init", a.receiverPath, d, !0); | |
this.fnCallingBack = function (b) { | |
"success" == b && (a.callBackIsVerified = !0) | |
}; | |
a.apiKeyIsVerified ? setTimeout(function () { | |
c("callingback", null); | |
setTimeout(function () { | |
a.callBackIsVerified ? a.callBack && a.callBack("No Error") : a.callBack && a.callBack("Error: App receiver, Call back from dashboard to app failed") | |
}, 200) | |
}, 2E3) : a.callBack && a.callBack("Error: Incorrect API Key"); | |
return a | |
}; | |
this.apiKeyIncorrect = function () { | |
c("statusmsg", "API Key: " + a.apiKey + " is not correct, please check your app settings", "error", null, "status") | |
}; | |
this.composeMessage = function (b, d) { | |
if (!a.apiKeyIsVerified) return this.apiKeyIncorrect(), a; | |
var f, e; | |
try { | |
d && (f = d.shortenLinks, e = d.timestamp) | |
} catch (g) {} | |
c("compose", b, f + "|" + e); | |
return a | |
}; | |
this.showUser = function (b) { | |
if (!a.apiKeyIsVerified) return this.apiKeyIncorrect(), a; | |
b = b.replace("@", ""); | |
c("userinfo", b); | |
return a | |
}; | |
this.quickSearch = function (b) { | |
if (!a.apiKeyIsVerified) return this.apiKeyIncorrect(), a; | |
c("quicksearch", b); | |
return a | |
}; | |
this.showTrends = function () { | |
if (!a.apiKeyIsVerified) return this.apiKeyIncorrect(), a; | |
c("trends"); | |
return a | |
}; | |
this.showStatusMessage = function (b, d) { | |
if (!a.apiKeyIsVerified) return this.apiKeyIncorrect(), a; | |
c("statusmsg", b, d, null, "status"); | |
return a | |
}; | |
this.clearStatusMessage = function () { | |
if (!a.apiKeyIsVerified) return this.apiKeyIncorrect(), a; | |
c("statusmsgclear", null, null, null, "status"); | |
return a | |
}; | |
this.showFollowDialog = function (b, d) { | |
if (!a.apiKeyIsVerified) return this.apiKeyIncorrect(), a; | |
c("showfollowdialog", b, d); | |
return a | |
}; | |
this.customUserInfo = function (b) { | |
if (!a.apiKeyIsVerified) return this.apiKeyIncorrect(), a; | |
i(function () { | |
var a = JSON.stringify(b); | |
a && c("customuserinfo", a) | |
}); | |
return a | |
}; | |
this.showImagePreview = function (b, d) { | |
if (!a.apiKeyIsVerified) return this.apiKeyIncorrect(), a; | |
c("showimagepreview", | |
b, d); | |
return a | |
}; | |
this.startAppTokenAuth = function () { | |
if (!a.apiKeyIsVerified) return this.apiKeyIncorrect(), a; | |
c("startapptokenauth") | |
}; | |
this.editAppAuth = function () { | |
if (!a.apiKeyIsVerified) return this.apiKeyIncorrect(), a; | |
c("editappauth") | |
}; | |
this.reloadApp = function () { | |
if (!a.apiKeyIsVerified) return this.apiKeyIncorrect(), a; | |
c("reloadapp") | |
}; | |
this.updatePlacementSubtitle = function (b) { | |
if (!a.apiKeyIsVerified) return this.apiKeyIncorrect(), a; | |
c("updateplacementsubtitle", b, null, null, "bg") | |
}; | |
this.assignItem = function (b) { | |
if (!a.apiKeyIsVerified) return this.apiKeyIncorrect(), | |
a; | |
i(function () { | |
var a = JSON.stringify(b); | |
a && c("assign", a) | |
}); | |
return a | |
}; | |
this.resolveItem = function (b) { | |
if (!a.apiKeyIsVerified) return this.apiKeyIncorrect(), a; | |
i(function () { | |
var a = JSON.stringify(b); | |
a && c("resolve", a) | |
}); | |
return a | |
}; | |
this.showCustomPopup = function (b, d, f, e) { | |
if (!a.apiKeyIsVerified) return this.apiKeyIncorrect(), a; | |
b = JSON.stringify({ | |
url: b, | |
title: d, | |
w: f, | |
h: e | |
}); | |
c("showCustomPopup", b) | |
}; | |
this.closeCustomPopup = function (a, c) { | |
parent.frames[a + "_" + c].hsp.closeCustomPopupFn() | |
}; | |
this.closeCustomPopupFn = function () { | |
c("closeCustomPopup") | |
}; | |
this.getTwitterAccounts = function (b) { | |
if (!a.apiKeyIsVerified) return this.apiKeyIncorrect(), a; | |
c("gettwitteraccounts", null, null, null, "bg"); | |
a.fnOnGetTwitterAccounts = function (a) { | |
a && "undefined" !== typeof b && b(a.split(",")) | |
} | |
}; | |
this.bind = function (b, d) { | |
if (!a.apiKeyIsVerified) return this.apiKeyIncorrect(), a; | |
if (b && d && "undefined" !== typeof d) { | |
var f = b.toLowerCase(), | |
e; | |
switch (f) { | |
case "refresh": | |
e = "fnOnRefresh"; | |
break; | |
case "dropuser": | |
e = "fnOnDropUser"; | |
break; | |
case "closepopup": | |
e = "fnOnClosePopUp"; | |
break; | |
case "sendtoapp": | |
e = "fnOnSendToApp"; | |
break; | |
case "sendcomposedmsgtoapp": | |
e = "fnOnSendComposedMsgToApp"; | |
break; | |
case "sendprofiletoapp": | |
e = "fnOnSendProfileToApp" | |
} | |
e && (a[e] = function () { | |
l && d.apply(null, arguments) | |
}); | |
0 > this.boundEvents.join("|").indexOf(f) && this.boundEvents.push(f); | |
k && clearTimeout(k); | |
k = setTimeout(function () { | |
c("userbound", a.boundEvents.join("|")) | |
}, 1E3) | |
} | |
return a | |
}; | |
g = m("isSsl"); | |
j = "true" == g || "1" == g ? "https://" : "http://" | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment