Refresh Code when Infinite Scroll Is Called - javascript

How to I call a JavaScript function when Tumblr's infinite scroll loads more posts?
I figure it would have to be some sort of listener function for when tumblrAutoPager.init us called. I found the infinite scroll code online and don't really understand it.
var tumblrAutoPager = {
url: "http://proto.jp/",
ver: "0.1.7",
rF: true,
gP: {},
pp: null,
ppId: "",
LN: location.hostname,
init: function () {
if ($("autopagerize_icon") || navigator.userAgent.indexOf('iPhone') != -1) return;
var tAP = tumblrAutoPager;
var p = 1;
var lh = location.href;
var lhp = lh.lastIndexOf("/page/");
var lht = lh.lastIndexOf("/tagged/");
if (lhp != -1) {
p = parseInt(lh.slice(lhp + 6));
tAP.LN = lh.slice(7, lhp);
} else if (lht != -1) {
tAP.LN = lh.slice(7);
if (tAP.LN.slice(tAP.LN.length - 1) == "/") tAP.LN = tAP.LN.slice(0, tAP.LN.length - 1);
} else if ("http://" + tAP.LN + "/" != lh) {
return;
};
var gPFncs = [];
gPFncs[0] = function (aE) {
var r = [];
for (var i = 0, l = aE.length; i < l; i++) {
if (aE[i].className == "autopagerize_page_element") {
r = gCE(aE[i]);
break;
}
}
return r;
};
gPFncs[1] = function (aE) {
var r = [];
for (var i = 0, l = aE.length; i < l; i++) {
var arr = aE[i].className ? aE[i].className.split(" ") : null;
if (arr) {
for (var j = 0; j < arr.length; j++) {
arr[j] == "post" ? r.push(aE[i]) : null;
}
}
}
return r;
};
gPFncs[2] = function (aE) {
var r = [];
var tmpId = tAP.ppId ? [tAP.ppId] : ["posts", "main", "container", "content", "apDiv2", "wrapper", "projects"];
for (var i = 0, l = aE.length; i < l; i++) {
for (var j = 0; j < tmpId.length; j++) {
if (aE[i].id == tmpId[j]) {
r = gCE(aE[i]);
tAP.ppId = aE[i].id;
break;
}
}
}
return r;
};
for (var i = 0; i < gPFncs.length; i++) {
var getElems = gPFncs[i](document.body.getElementsByTagName('*'));
if (getElems.length) {
tAP.gP = gPFncs[i];
tAP.pp = getElems[0].parentNode;
break;
}
}
function gCE(pElem) {
var r = [];
for (var i = 0, l = pElem.childNodes.length; i < l; i++) {
r.push(pElem.childNodes.item(i))
}
return r;
}
if (!tAP.pp) {
return;
}
sendRequest.README = {
license: 'Public Domain',
url: 'http://jsgt.org/lib/ajax/ref.htm',
version: 0.516,
author: 'Toshiro Takahashi'
};
function chkAjaBrowser() {
var A, B = navigator.userAgent;
this.bw = {
safari: ((A = B.split('AppleWebKit/')[1]) ? A.split('(')[0].split('.')[0] : 0) >= 124,
konqueror: ((A = B.split('Konqueror/')[1]) ? A.split(';')[0] : 0) >= 3.3,
mozes: ((A = B.split('Gecko/')[1]) ? A.split(' ')[0] : 0) >= 20011128,
opera: ( !! window.opera) && ((typeof XMLHttpRequest) == 'function'),
msie: ( !! window.ActiveXObject) ? ( !! createHttpRequest()) : false
};
return (this.bw.safari || this.bw.konqueror || this.bw.mozes || this.bw.opera || this.bw.msie)
}
function createHttpRequest() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest()
} else {
if (window.ActiveXObject) {
try {
return new ActiveXObject('Msxml2.XMLHTTP')
} catch (B) {
try {
return new ActiveXObject('Microsoft.XMLHTTP')
} catch (A) {
return null
}
}
} else {
return null
}
}
};
function sendRequest(E, R, C, D, F, G, S, A) {
var Q = C.toUpperCase() == 'GET',
H = createHttpRequest();
if (H == null) {
return null
}
if ((G) ? G : false) {
D += ((D.indexOf('?') == -1) ? '?' : '&') + 't=' + (new Date()).getTime()
}
var P = new chkAjaBrowser(),
L = P.bw.opera,
I = P.bw.safari,
N = P.bw.konqueror,
M = P.bw.mozes;
if (typeof E == 'object') {
var J = E.onload;
var O = E.onbeforsetheader
} else {
var J = E;
var O = null
}
if (L || I || M) {
H.onload = function () {
J(H);
H.abort()
}
} else {
H.onreadystatechange = function () {
if (H.readyState == 4) {
J(H);
H.abort()
}
}
}
R = K(R, D);
if (Q) {
D += ((D.indexOf('?') == -1) ? '?' : (R == '') ? '' : '&') + R
}
H.open(C, D, F, S, A);
if ( !! O) {
O(H)
}
B(H);
H.send(R);
function B(T) {
if (!L || typeof T.setRequestHeader == 'function') {
T.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8')
}
return T
}
function K(X, V) {
var Z = [];
if (typeof X == 'object') {
for (var W in X) {
Y(W, X[W])
}
} else {
if (typeof X == 'string') {
if (X == '') {
return ''
}
if (X.charAt(0) == '&') {
X = X.substring(1, X.length)
}
var T = X.split('&');
for (var W = 0; W < T.length; W++) {
var U = T[W].split('=');
Y(U[0], U[1])
}
}
}
function Y(b, a) {
Z.push(encodeURIComponent(b) + '=' + encodeURIComponent(a))
}
return Z.join('&')
}
return H
}
function addNextPage(oj) {
if (oj.status == 404) {
tAP.remainFlg = false;
return;
}
var d = document.createElement("div");
d.innerHTML = oj.responseText;
var posts = tAP.gP(d.getElementsByTagName("*"));
if (posts.length < 2) {
tAP.rF = false;
return;
}
d = document.createElement("div");
d.className = "tumblrAutoPager_page_info";
tAP.pp.appendChild(d);
for (var i = 0; i < posts.length; i++) {
tAP.pp.appendChild(posts[i]);
}
var footer = $("footer");
footer ? footer.parentNode.appendChild(footer) : null;
tAP.rF = true;
}
watch_scroll();
function watch_scroll() {
var d = document.compatMode == "BackCompat" ? document.body : document.documentElement;
var r = d.scrollHeight - d.clientHeight - (d.scrollTop || document.body.scrollTop);
if (r < d.clientHeight * 2 && tAP.rF) {
tAP.rF = false;
p++;
sendRequest(addNextPage, "", "GET", "http://" + tAP.LN + "/page/" + p, true);
}
setTimeout(arguments.callee, 200);
};
function $(id) {
return document.getElementById(id)
};
},
switchAutoPage: function () {
this.rF = !this.rF;
var aE = document.getElementsByTagName('*');
for (var i = 0, l = aE.length; i < l; i++) {
if (aE[i].className == "tAP_switch") {
aE[i].firstChild.nodeValue = this.rF ? "AutoPage[OFF]" : "AutoPage[ON]";
}
}
}
};
window.addEventListener ? window.addEventListener('load', tumblrAutoPager.init, false) : window.attachEvent ? window.attachEvent("onload", tumblrAutoPager.init) : window.onload = tumblrAutoPager.init;

Related

Export JS fuction to use in other JS not working

This is my the my js:
//aca Z
var Z = (function () {
var i = "#z-overlay {filter: alpha(opacity=50);opacity:0.5;display:inline-block;position:fixed;top:0;left:0;width:100%;height:100%;background-color: #000;z-index: 1001;}";
var u =
"#z-container {border:1px;float:left; overflow: visible; position: absolute;padding: 0px; display: inline-block; top:5%; left:34%; margin: 0 auto;-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius:5px;background-color: #FAFAFA; border:1px solid #FAFAFA;border-top-color:#EDEDED;behavior: url(js/PIE.htc);z-index: 1002;}";
var h = "#z-data {height: 100%; outline: 0px; width: 100%; overflow: visible;display: inline-block;border:1px; -webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius:5px;}";
var t = "#reset{*, *:before, *:after {display: inline-block;-webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box;}}";
var l = "#z_hppm_iframe {background-color: #FAFAFA;vertical-align:bottom;z-index:9999;display:block;padding:0px;margin: 0px; border:0px solid #DDD;}";
var e = "requestPage";
var d;
var s;
var c, o;
var b;
var n;
var w = ["tenantId", "id", "token", "signature", "key", "style", "submitEnabled", "url"];
var j = ["creditCardNumber", "cardSecurityCode", "creditCardExpirationYear", "creditCardExpirationMonth", "bankAccountNumber", "bankAccountName", "ipAddress", "achBankAccountNumber", "achBankABACode"];
var r = false;
var m = {};
var f = null;
var v = null;
function a(x) {
return x && typeof x === "function";
}
function p(x) {
var y = {};
for (var z in x) {
if (x.hasOwnProperty(z)) {
y[z] = x[z];
}
}
return y;
}
function k() {
if (s) {
s();
}
}
function g() {
s = null;
}
function q(x) {
if (x.currentStyle) {
return x.currentStyle.display != "none";
} else {
if (document.defaultView && document.defaultView.getComputedStyle) {
return document.defaultView.getComputedStyle(x, null).getPropertyValue("display") != "none";
} else {
return true;
}
}
}
ZXD.receiveMessage(function (y) {
try {
var x = y.data;
ZLOG.debug("Received message[O]: payload=" + x);
x = JSON.parse(x);
if (x.success) {
if (a(m.init)) {
m.init(x);
}
} else {
if (x.success == false) {
Z.deactivateOverlay("z-overlay");
Z.deactivateOverlay("z-container");
if (m.init) {
m.init(x);
}
} else {
if (x.action == "close") {
Z.deactivateOverlay("z-overlay");
Z.deactivateOverlay("z-container");
} else {
if (x.action == "resize") {
Z.receive(x);
} else {
if (x.action == "allowScroll") {
Z.allowScroll(x);
}
}
}
}
}
if (x.action === "validate" && a(m.validate)) {
m.validate(x);
} else {
if (x.action == "customizeErrorMessage" && a(m.customizeErrorMessage)) {
m.customizeErrorMessage(x.key, x.code, x.message, x.rawGatewayInfo);
} else {
if (x.action && a(m[x.action])) {
m[x.action](x);
}
}
}
} catch (z) {
return;
}
});
return {
validateRequiredParams: function (z) {
var x = w.length;
for (index = 0; index < x; index++) {
if (!z.hasOwnProperty(w[index])) {
if (w[index] == "submitEnabled" && z.style.toLowerCase() == "overlay") {
continue;
} else {
var y = "Param with key [" + w[index] + "] is required.";
alert(y);
if (!Z.isIE()) {
console.log(y);
}
return false;
}
}
}
return true;
},
isIE: function () {
var z = window.navigator.userAgent;
var y = z.indexOf("MSIE ");
var x = z.indexOf("Trident/");
if (y > 0) {
return true;
}
if (x > 0) {
var A = z.indexOf("rv:");
return true;
}
return false;
},
validatePCIParams: function (A) {
var x = j.length;
for (index = 0; index < x; index++) {
if (j[index] == "achBankAccountNumber" || j[index] == "achBankABACode") {
return true;
}
var y = "field_" + j[index];
if (A.hasOwnProperty(y)) {
if (0 < A[y].trim().length && A[y].trim().length < 300) {
var z = "Field [" + y + "] for Credit Card payment method type should be encrypted for pre-population";
alert(z);
if (!Z.isIE()) {
console.log(z);
}
return false;
}
}
}
return true;
},
init: function (C, D) {
c = "?method=requestPage&host=" + encodeURIComponent(document.location.href) + "&";
c = c + "fromHostedPage=true&";
var B = Z.validateRequiredParams(C);
if (!B) {
return false;
}
B = Z.validatePCIParams(C);
if (!B) {
return false;
}
var A = JSON.stringify(C, function (F, G) {
if (F != "") {
if ("key" == F) {
b = G;
} else {
if ("url" == F) {
var E = /^https:\/\/([a-z0-9]+(-[a-z0-9]+)*\.)+zuora\.com\/.+$/;
ZLOG.info("HPM integration[O]: url=" + G);
if (!E.test(G)) {
ZLOG.warn("HPM integration[O]: None-official zuora HPM integration url is detected: " + G);
}
d = G;
} else {
c = c + F + "=" + encodeURIComponent(G) + "&";
}
}
}
return G;
});
n = JSON.parse(A);
m.init = D;
var x = j.length;
if (C) {
for (var z = 0; z < x; z++) {
var y = "field_" + j[z];
if (C.hasOwnProperty(y)) {
C[y] = "";
}
}
}
return true;
},
prepopulate: function (z) {
if (threedRedirected) {
return;
}
var A = Z.createIframeURL();
if (A == document.getElementById(ifrmId).src || (document.getElementById(ifrmId).src.indexOf(A) >= 0 && n.hasOwnProperty("customizeErrorRequired") && n.customizeErrorRequired == "true")) {
var x = JSON.stringify(z, function (B, D) {
if (B != "") {
var C = "setField(" + B + ":" + D + ")";
Z.post(ifrmId, C);
}
return D;
});
var y = "setField(key:" + b + ")";
Z.post(ifrmId, y);
Z.post(ifrmId, "setField(style:" + n.style + ")");
if (n.hasOwnProperty("customizeErrorRequired") && n.customizeErrorRequired == "true") {
Z.post(ifrmId, "customizeErrorRequired");
n.customizeErrorRequired = "false";
}
}
},
contains: function (x, z) {
for (var y = 0; y < x.length; y++) {
if (x[y] === z) {
return true;
}
}
return false;
},
renderWithErrorHandler: function (B, D, C, y, z, x, A) {
B.customizeErrorRequired = "true";
Z.render(B, D, C, z, x);
Z.customizeErrorHandler(y);
Z.removeCoverHandler(A);
},
runAfterRender: function (x) {
s = x;
},
render: function (C, B, H, A, I) {
console.log('testRender');
if (A != null && A != undefined) {
f = A;
}
if (I != null && I != undefined) {
v = I;
}
f = Number(f);
v = Number(v);
f = isNaN(f) ? 0 : f;
v = isNaN(v) ? 0 : v;
var F = j.length;
threedRedirected = false;
if (B && B.creditCardCountry && (B.creditCardCountry === "USA" || B.creditCardCountry === "CAN")) {
B.creditCardState = B.creditCardState || " ";
}
if (B) {
for (index = 0; index < F; index++) {
var D = "field_" + j[index];
if (B.hasOwnProperty(j[index])) {
C[D] = B[j[index]];
}
}
}
var J = Z.init(C, H);
if (!J) {
return;
}
if (B) {
var F = Object.keys(B).length;
o = p(B);
for (index = 0; index < F; index++) {
var z = Object.keys(B)[index];
if (Z.contains(j, z)) {
delete o[z];
}
}
} else {
o = null;
}
var y = document.getElementById("zuora_payment");
if (typeof y == "undefined" || !y) {
return { error: "invalid_request", error_description: "The container you specified does not exist" };
}
y.innerHTML = "";
Z.cleanUp(y, "z-overlay");
Z.cleanUp(y, "z-container");
if (n.style == "inline") {
Z.addInlineStyles();
Z.createIframe(y);
return;
}
if (n.style == "overlay") {
Z.addOverlayStyles();
var x = Z.generateDiv("z-overlay", "z-overlay");
y.appendChild(x);
var E = Z.generateDiv("z-container", "z-container");
y.appendChild(E);
var G = Z.generateDiv("z-data", "z-data");
G.tabindex = "-1";
E.appendChild(G);
Z.createIframe(document.getElementById("z-data"));
Z.activateOverlay("z-overlay");
}
},
cleanUp: function (y, x) {
var z = document.getElementById(x);
if (z != null) {
y.removeChild(z);
}
},
activateOverlay: function (y) {
try {
document.getElementById(y).style.display = "inline";
} catch (x) {}
},
deactivateOverlay: function (y) {
try {
document.getElementById(y).style.display = "none";
} catch (x) {}
},
generateDiv: function (A, y, x) {
var z = document.createElement("div");
z.id = A;
z.className = y;
z.border = "0";
if (z.addEventListener) {
z.addEventListener("click", x, false);
} else {
z.attachEvent("click", x);
}
return z;
},
addOverlayStyles: function () {
var B = document.createElement("style");
B.type = "text/css";
var y = document.createTextNode(i);
var C = document.createTextNode(u);
var x = document.createTextNode(h);
var A = document.createTextNode(l);
var z = document.createTextNode(t);
if (B.styleSheet) {
B.styleSheet.cssText = y.nodeValue + " " + C.nodeValue + " " + x.nodeValue + " " + z.nodeValue + " " + A.nodeValue;
} else {
B.appendChild(y);
B.appendChild(C);
B.appendChild(x);
B.appendChild(A);
B.appendChild(z);
}
document.getElementsByTagName("head")[0].appendChild(B);
},
addInlineStyles: function () {
var y = document.createElement("style");
y.type = "text/css";
var x = document.createTextNode(l);
if (y.styleSheet) {
y.styleSheet.cssText = x.nodeValue;
} else {
y.appendChild(x);
}
document.getElementsByTagName("head")[0].appendChild(y);
},
createIframe: function (y) {
var A = Z.createIframeURL();
var z = document.createElement("iframe");
z.setAttribute("src", A);
z.setAttribute("id", ifrmId);
z.setAttribute("overflow", "visible");
z.setAttribute("scrolling", "no");
z.setAttribute("frameBorder", "0");
z.setAttribute("allowtransparency", "true");
z.setAttribute("class", "z_hppm_iframe");
z.setAttribute("width", "100%");
z.setAttribute("height", "0");
var x = false;
z.addEventListener(
"load",
function () {
Z.prepopulate(o);
k();
g();
function B() {
if (q(y)) {
Z.post(ifrmId, "resize");
if (a(m.onloadCallback)) {
m.onloadCallback();
}
} else {
window.requestAnimationFrame(B);
}
}
if (!x) {
window.requestAnimationFrame(B);
x = true;
}
return false;
},
false
);
if (typeof options != "undefined") {
if (typeof options.vertical != "undefined" && options.vertical) {
z.style.width = "100%";
z.style.height = "100%";
}
}
y.appendChild(z);
},
createIframeURL: function () {
var x = d;
return x.concat(c).concat("zlog_level=" + ZLOG.getLevel());
},
post: function (A, z) {
var x = document.getElementById(A);
var y = encodeURIComponent(document.location.href);
var B = x.src;
if (B.indexOf(y) <= -1) {
x.src = B + "#" + y;
}
ZXD.postMessage(z, B, x.contentWindow);
return false;
},
allowScroll: function (y) {
if (ifrmId) {
var x = document.getElementById(ifrmId);
if (x) {
x.setAttribute("scrolling", "yes");
threedRedirected = true;
}
}
},
receive: function (x) {
ZFB.resizeCaller(ifrmId, x.action, x.height, x.width, f, v);
},
validate: function (z) {
if (z == null || z == undefined) {
Z.closeWindow();
var y = "Validate function required.";
alert(y);
if (!Z.isIE()) {
console.log(y);
}
return false;
}
m.validate = z;
var x = "validate";
Z.post(ifrmId, x);
},
customizeErrorHandler: function (y) {
if (y == null || y == undefined) {
Z.closeWindow();
var x = "Customized error message function required.";
alert(x);
if (!Z.isIE()) {
console.log(x);
}
return false;
}
m.customizeErrorMessage = y;
},
removeCoverHandler: function (x) {
if (x == null || x == undefined) {
return false;
}
m.removeCover = x;
},
sendErrorMessageToHpm: function (A, z) {
var y = { action: "customizeErrorMessage", key: A, message: z };
var x = JSON.stringify(y);
Z.post(ifrmId, x);
},
closeWindow: function () {
Z.deactivateOverlay("z-overlay");
Z.deactivateOverlay("z-container");
},
submit: function () {
var x = document.getElementById(ifrmId).src + "#" + encodeURIComponent(document.location.href);
document.getElementById(ifrmId).src = x;
ZXD.postMessage("postPage", x, document.getElementById(ifrmId).contentWindow);
return true;
},
responseHandler: function (x) {
var y = x.redirectUrl;
if (x.success) {
var z = y + "?refId=" + x.refId + "&success=" + x.success + "&signature=" + x.signature + "&token=" + x.token;
window.location.replace(z);
} else {
var z = y + "?errorCode=" + x.errorCode + "&errorMessage=" + x.errorMessage + "&success=" + x.success + "&signature=" + x.signature + "&token=" + x.token;
window.location.replace(z);
}
},
setEventHandler: function (x, y) {
if (x && y) {
m[x] = y;
}
},
setAgreement: function (A, B, z, y) {
if (!Z.validateAgreement(A, B, z)) {
return false;
}
var x = "mitConsentAgreementSrc";
Z.setFieldValue(x, A);
x = "mitCredentialProfileType";
Z.setFieldValue(x, B);
x = "agreementSupportedBrands";
Z.setFieldValue(x, z);
x = "mitConsentAgreementRef";
Z.setFieldValue(x, y);
return true;
},
setFieldValue: function (x, z) {
var y = "setField(" + x + ":" + z + ")";
Z.post(ifrmId, y);
},
validateAgreement: function (y, z, x) {
if (Z.isEmpty(y) && Z.isEmpty(z) && Z.isEmpty(x)) {
return true;
}
if (Z.isEmpty(y)) {
Z.alertRequired("mitConsentAgreementSrc");
return false;
}
if (Z.isEmpty(z)) {
Z.alertRequired("mitProfileType");
return false;
}
if (Z.isEmpty(x)) {
Z.alertRequired("agreementSupportedBrands");
return false;
}
if (y != "External") {
Z.alertIllegal("mitConsentAgreementSrc");
return false;
}
if (z != "Recurring" && z != "Unscheduled") {
Z.alertIllegal("mitProfileType");
return false;
}
return true;
},
isEmpty: function (x) {
return !x || 0 === x.length;
},
alertRequired: function (y) {
var x = "Param mitConsentAgreementSrc, mitProfileType and agreementSupportedBrands for Z.setAgreement should be all empty or not empty. Param " + y + " is empty.";
alert(x);
},
alertIllegal: function (y) {
var x = "Param " + y + " for Z.setAgreement is illegal.";
alert(x);
},
};
})();
export {Z};
I'm trying to export the render function to use in other js that is in the same folder but is not working.
I tried: put export at the beginning of the function (photo) and I also tried
export {render} from './zouralibrary';
but in thiscase is thorow me: Unexpected compilation error: 'default' is not exported by zouralibrary.js, imported by paymentIframeTest.js (3:7)

Odometer alphanumeric value

I'm using "odometer" and i want to display its value as AB1234, this could be a random value. I tried to change its format but it shows an error if I made changes in format.
Please help me out in this. link of file is:
http://github.hubspot.com/odometer/odometer.js
Please see the code below:
How can I display value on odometer like AB1234??
(function() {
var COUNT_FRAMERATE, COUNT_MS_PER_FRAME, DIGIT_FORMAT, DIGIT_HTML, DIGIT_SPEEDBOOST, DURATION, FORMAT_MARK_HTML, FORMAT_PARSER, FRAMERATE, FRAMES_PER_VALUE, MS_PER_FRAME, MutationObserver, Odometer, RIBBON_HTML, TRANSITION_END_EVENTS, TRANSITION_SUPPORT, VALUE_HTML, addClass, createFromHTML, fractionalPart, now, removeClass, requestAnimationFrame, round, transitionCheckStyles, trigger, truncate, wrapJQuery, _jQueryWrapped, _old, _ref, _ref1,
__slice = [].slice;
VALUE_HTML = '<span class="odometer-value"></span>';
RIBBON_HTML = '<span class="odometer-ribbon"><span class="odometer-ribbon-inner">' + VALUE_HTML + '</span></span>';
DIGIT_HTML = '<span class="odometer-digit"><span class="odometer-digit-spacer">8</span><span class="odometer-digit-inner">' + RIBBON_HTML + '</span></span>';
FORMAT_MARK_HTML = '<span class="odometer-formatting-mark"></span>';
DIGIT_FORMAT = '(ddd).dd';
FORMAT_PARSER = /^\(?([^)]*)\)?(?:(.)(d+))?$/;
FRAMERATE = 30;
DURATION = 3000;
COUNT_FRAMERATE = 20;
FRAMES_PER_VALUE = 2;
DIGIT_SPEEDBOOST = .5;
MS_PER_FRAME = 1000 / FRAMERATE;
COUNT_MS_PER_FRAME = 1000 / COUNT_FRAMERATE;
TRANSITION_END_EVENTS = 'transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd';
transitionCheckStyles = document.createElement('div').style;
TRANSITION_SUPPORT = (transitionCheckStyles.transition != null) || (transitionCheckStyles.webkitTransition != null) || (transitionCheckStyles.mozTransition != null) || (transitionCheckStyles.oTransition != null);
requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
createFromHTML = function(html) {
var el;
el = document.createElement('div');
el.innerHTML = html;
return el.children[0];
};
removeClass = function(el, name) {
return el.className = el.className.replace(new RegExp("(^| )" + (name.split(' ').join('|')) + "( |$)", 'gi'), ' ');
};
addClass = function(el, name) {
removeClass(el, name);
return el.className += " " + name;
};
trigger = function(el, name) {
var evt;
if (document.createEvent != null) {
evt = document.createEvent('HTMLEvents');
evt.initEvent(name, true, true);
return el.dispatchEvent(evt);
}
};
now = function() {
var _ref, _ref1;
return (_ref = (_ref1 = window.performance) != null ? typeof _ref1.now === "function" ? _ref1.now() : void 0 : void 0) != null ? _ref : +(new Date);
};
round = function(val, precision) {
if (precision == null) {
precision = 0;
}
if (!precision) {
return Math.round(val);
}
val *= Math.pow(10, precision);
val += 0.5;
val = Math.floor(val);
return val /= Math.pow(10, precision);
};
truncate = function(val) {
if (val < 0) {
return Math.ceil(val);
} else {
return Math.floor(val);
}
};
fractionalPart = function(val) {
return val - round(val);
};
_jQueryWrapped = false;
(wrapJQuery = function() {
var property, _i, _len, _ref, _results;
if (_jQueryWrapped) {
return;
}
if (window.jQuery != null) {
_jQueryWrapped = true;
_ref = ['html', 'text'];
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
property = _ref[_i];
_results.push((function(property) {
var old;
old = window.jQuery.fn[property];
return window.jQuery.fn[property] = function(val) {
var _ref1;
if ((val == null) || (((_ref1 = this[0]) != null ? _ref1.odometer : void 0) == null)) {
return old.apply(this, arguments);
}
return this[0].odometer.update(val);
};
})(property));
}
return _results;
}
})();
setTimeout(wrapJQuery, 0);
Odometer = (function() {
function Odometer(options) {
var e, k, property, v, _base, _i, _len, _ref, _ref1, _ref2,
_this = this;
this.options = options;
this.el = this.options.el;
if (this.el.odometer != null) {
return this.el.odometer;
}
this.el.odometer = this;
_ref = Odometer.options;
for (k in _ref) {
v = _ref[k];
if (this.options[k] == null) {
this.options[k] = v;
}
}
if ((_base = this.options).duration == null) {
_base.duration = DURATION;
}
this.MAX_VALUES = ((this.options.duration / MS_PER_FRAME) / FRAMES_PER_VALUE) | 0;
this.resetFormat();
this.value = this.cleanValue((_ref1 = this.options.value) != null ? _ref1 : '');
this.renderInside();
this.render();
try {
_ref2 = ['innerHTML', 'innerText', 'textContent'];
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
property = _ref2[_i];
if (this.el[property] != null) {
(function(property) {
return Object.defineProperty(_this.el, property, {
get: function() {
var _ref3;
if (property === 'innerHTML') {
return _this.inside.outerHTML;
} else {
return (_ref3 = _this.inside.innerText) != null ? _ref3 : _this.inside.textContent;
}
},
set: function(val) {
return _this.update(val);
}
});
})(property);
}
}
} catch (_error) {
e = _error;
this.watchForMutations();
}
this;
}
Odometer.prototype.renderInside = function() {
this.inside = document.createElement('div');
this.inside.className = 'odometer-inside';
this.el.innerHTML = '';
return this.el.appendChild(this.inside);
};
Odometer.prototype.watchForMutations = function() {
var e,
_this = this;
if (MutationObserver == null) {
return;
}
try {
if (this.observer == null) {
this.observer = new MutationObserver(function(mutations) {
var newVal;
newVal = _this.el.innerText;
_this.renderInside();
_this.render(_this.value);
return _this.update(newVal);
});
}
this.watchMutations = true;
return this.startWatchingMutations();
} catch (_error) {
e = _error;
}
};
Odometer.prototype.startWatchingMutations = function() {
if (this.watchMutations) {
return this.observer.observe(this.el, {
childList: true
});
}
};
Odometer.prototype.stopWatchingMutations = function() {
var _ref;
return (_ref = this.observer) != null ? _ref.disconnect() : void 0;
};
Odometer.prototype.cleanValue = function(val) {
var _ref;
if (typeof val === 'string') {
val = val.replace((_ref = this.format.radix) != null ? _ref : '.', '<radix>');
val = val.replace(/[.,]/g, '');
val = val.replace('<radix>', '.');
val = parseFloat(val, 10) || 0;
}
return round(val, this.format.precision);
};
Odometer.prototype.bindTransitionEnd = function() {
var event, renderEnqueued, _i, _len, _ref, _results,
_this = this;
if (this.transitionEndBound) {
return;
}
this.transitionEndBound = true;
renderEnqueued = false;
_ref = TRANSITION_END_EVENTS.split(' ');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
event = _ref[_i];
_results.push(this.el.addEventListener(event, function() {
if (renderEnqueued) {
return true;
}
renderEnqueued = true;
setTimeout(function() {
_this.render();
renderEnqueued = false;
return trigger(_this.el, 'odometerdone');
}, 0);
return true;
}, false));
}
return _results;
};
Odometer.prototype.resetFormat = function() {
var format, fractional, parsed, precision, radix, repeating, _ref, _ref1;
format = (_ref = this.options.format) != null ? _ref : DIGIT_FORMAT;
format || (format = 'd');
parsed = FORMAT_PARSER.exec(format);
if (!parsed) {
throw new Error("Odometer: Unparsable digit format");
}
_ref1 = parsed.slice(1, 4), repeating = _ref1[0], radix = _ref1[1], fractional = _ref1[2];
precision = (fractional != null ? fractional.length : void 0) || 0;
return this.format = {
repeating: repeating,
radix: radix,
precision: precision
};
};
Odometer.prototype.render = function(value) {
var classes, cls, match, newClasses, theme, _i, _len;
if (value == null) {
value = this.value;
}
this.stopWatchingMutations();
this.resetFormat();
this.inside.innerHTML = '';
theme = this.options.theme;
classes = this.el.className.split(' ');
newClasses = [];
for (_i = 0, _len = classes.length; _i < _len; _i++) {
cls = classes[_i];
if (!cls.length) {
continue;
}
if (match = /^odometer-theme-(.+)$/.exec(cls)) {
theme = match[1];
continue;
}
if (/^odometer(-|$)/.test(cls)) {
continue;
}
newClasses.push(cls);
}
newClasses.push('odometer');
if (!TRANSITION_SUPPORT) {
newClasses.push('odometer-no-transitions');
}
if (theme) {
newClasses.push("odometer-theme-" + theme);
} else {
newClasses.push("odometer-auto-theme");
}
this.el.className = newClasses.join(' ');
this.ribbons = {};
this.formatDigits(value);
return this.startWatchingMutations();
};
Odometer.prototype.formatDigits = function(value) {
var digit, valueDigit, valueString, wholePart, _i, _j, _len, _len1, _ref, _ref1;
this.digits = [];
if (this.options.formatFunction) {
valueString = this.options.formatFunction(value);
_ref = valueString.split('').reverse();
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
valueDigit = _ref[_i];
if (valueDigit.match(/0-9/)) {
digit = this.renderDigit();
digit.querySelector('.odometer-value').innerHTML = valueDigit;
this.digits.push(digit);
this.insertDigit(digit);
} else {
this.addSpacer(valueDigit);
}
}
} else {
wholePart = !this.format.precision || !fractionalPart(value) || false;
_ref1 = value.toString().split('').reverse();
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
digit = _ref1[_j];
if (digit === '.') {
wholePart = true;
}
this.addDigit(digit, wholePart);
}
}
};
Odometer.prototype.update = function(newValue) {
var diff,
_this = this;
newValue = this.cleanValue(newValue);
if (!(diff = newValue - this.value)) {
return;
}
removeClass(this.el, 'odometer-animating-up odometer-animating-down odometer-animating');
if (diff > 0) {
addClass(this.el, 'odometer-animating-up');
} else {
addClass(this.el, 'odometer-animating-down');
}
this.stopWatchingMutations();
this.animate(newValue);
this.startWatchingMutations();
setTimeout(function() {
_this.el.offsetHeight;
return addClass(_this.el, 'odometer-animating');
}, 0);
return this.value = newValue;
};
Odometer.prototype.renderDigit = function() {
return createFromHTML(DIGIT_HTML);
};
Odometer.prototype.insertDigit = function(digit, before) {
if (before != null) {
return this.inside.insertBefore(digit, before);
} else if (!this.inside.children.length) {
return this.inside.appendChild(digit);
} else {
return this.inside.insertBefore(digit, this.inside.children[0]);
}
};
Odometer.prototype.addSpacer = function(chr, before, extraClasses) {
var spacer;
spacer = createFromHTML(FORMAT_MARK_HTML);
spacer.innerHTML = chr;
if (extraClasses) {
addClass(spacer, extraClasses);
}
return this.insertDigit(spacer, before);
};
Odometer.prototype.addDigit = function(value, repeating) {
var chr, digit, resetted, _ref;
if (repeating == null) {
repeating = true;
}
if (value === '-') {
return this.addSpacer(value, null, 'odometer-negation-mark');
}
if (value === '.') {
return this.addSpacer((_ref = this.format.radix) != null ? _ref : '.', null, 'odometer-radix-mark');
}
if (repeating) {
resetted = false;
while (true) {
if (!this.format.repeating.length) {
if (resetted) {
throw new Error("Bad odometer format without digits");
}
this.resetFormat();
resetted = true;
}
chr = this.format.repeating[this.format.repeating.length - 1];
this.format.repeating = this.format.repeating.substring(0, this.format.repeating.length - 1);
if (chr === 'd') {
break;
}
this.addSpacer(chr);
}
}
digit = this.renderDigit();
digit.querySelector('.odometer-value').innerHTML = value;
this.digits.push(digit);
return this.insertDigit(digit);
};
Odometer.prototype.animate = function(newValue) {
if (!TRANSITION_SUPPORT || this.options.animation === 'count') {
return this.animateCount(newValue);
} else {
return this.animateSlide(newValue);
}
};
Odometer.prototype.animateCount = function(newValue) {
var cur, diff, last, start, tick,
_this = this;
if (!(diff = +newValue - this.value)) {
return;
}
start = last = now();
cur = this.value;
return (tick = function() {
var delta, dist, fraction;
if ((now() - start) > _this.options.duration) {
_this.value = newValue;
_this.render();
trigger(_this.el, 'odometerdone');
return;
}
delta = now() - last;
if (delta > COUNT_MS_PER_FRAME) {
last = now();
fraction = delta / _this.options.duration;
dist = diff * fraction;
cur += dist;
_this.render(Math.round(cur));
}
if (requestAnimationFrame != null) {
return requestAnimationFrame(tick);
} else {
return setTimeout(tick, COUNT_MS_PER_FRAME);
}
})();
};
Odometer.prototype.getDigitCount = function() {
var i, max, value, values, _i, _len;
values = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
for (i = _i = 0, _len = values.length; _i < _len; i = ++_i) {
value = values[i];
values[i] = Math.abs(value);
}
max = Math.max.apply(Math, values);
return Math.ceil(Math.log(max + 1) / Math.log(10));
};
Odometer.prototype.getFractionalDigitCount = function() {
var i, parser, parts, value, values, _i, _len;
values = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
parser = /^\-?\d*\.(\d*?)0*$/;
for (i = _i = 0, _len = values.length; _i < _len; i = ++_i) {
value = values[i];
values[i] = value.toString();
parts = parser.exec(values[i]);
if (parts == null) {
values[i] = 0;
} else {
values[i] = parts[1].length;
}
}
return Math.max.apply(Math, values);
};
Odometer.prototype.resetDigits = function() {
this.digits = [];
this.ribbons = [];
this.inside.innerHTML = '';
return this.resetFormat();
};
Odometer.prototype.animateSlide = function(newValue) {
var boosted, cur, diff, digitCount, digits, dist, end, fractionalCount, frame, frames, i, incr, j, mark, numEl, oldValue, start, _base, _i, _j, _k, _l, _len, _len1, _len2, _m, _ref, _results;
oldValue = this.value;
fractionalCount = this.getFractionalDigitCount(oldValue, newValue);
if (fractionalCount) {
newValue = newValue * Math.pow(10, fractionalCount);
oldValue = oldValue * Math.pow(10, fractionalCount);
}
if (!(diff = newValue - oldValue)) {
return;
}
this.bindTransitionEnd();
digitCount = this.getDigitCount(oldValue, newValue);
digits = [];
boosted = 0;
for (i = _i = 0; 0 <= digitCount ? _i < digitCount : _i > digitCount; i = 0 <= digitCount ? ++_i : --_i) {
start = truncate(oldValue / Math.pow(10, digitCount - i - 1));
end = truncate(newValue / Math.pow(10, digitCount - i - 1));
dist = end - start;
if (Math.abs(dist) > this.MAX_VALUES) {
frames = [];
incr = dist / (this.MAX_VALUES + this.MAX_VALUES * boosted * DIGIT_SPEEDBOOST);
cur = start;
while ((dist > 0 && cur < end) || (dist < 0 && cur > end)) {
frames.push(Math.round(cur));
cur += incr;
}
if (frames[frames.length - 1] !== end) {
frames.push(end);
}
boosted++;
} else {
frames = (function() {
_results = [];
for (var _j = start; start <= end ? _j <= end : _j >= end; start <= end ? _j++ : _j--){ _results.push(_j); }
return _results;
}).apply(this);
}
for (i = _k = 0, _len = frames.length; _k < _len; i = ++_k) {
frame = frames[i];
frames[i] = Math.abs(frame % 10);
}
digits.push(frames);
}
this.resetDigits();
_ref = digits.reverse();
for (i = _l = 0, _len1 = _ref.length; _l < _len1; i = ++_l) {
frames = _ref[i];
if (!this.digits[i]) {
this.addDigit(' ', i >= fractionalCount);
}
if ((_base = this.ribbons)[i] == null) {
_base[i] = this.digits[i].querySelector('.odometer-ribbon-inner');
}
this.ribbons[i].innerHTML = '';
if (diff < 0) {
frames = frames.reverse();
}
for (j = _m = 0, _len2 = frames.length; _m < _len2; j = ++_m) {
frame = frames[j];
numEl = document.createElement('div');
numEl.className = 'odometer-value';
numEl.innerHTML = frame;
this.ribbons[i].appendChild(numEl);
if (j === frames.length - 1) {
addClass(numEl, 'odometer-last-value');
}
if (j === 0) {
addClass(numEl, 'odometer-first-value');
}
}
}
if (start < 0) {
this.addDigit('-');
}
mark = this.inside.querySelector('.odometer-radix-mark');
if (mark != null) {
mark.parent.removeChild(mark);
}
if (fractionalCount) {
return this.addSpacer(this.format.radix, this.digits[fractionalCount - 1], 'odometer-radix-mark');
}
};
return Odometer;
})();
Odometer.options = (_ref = window.odometerOptions) != null ? _ref : {};
setTimeout(function() {
var k, v, _base, _ref1, _results;
if (window.odometerOptions) {
_ref1 = window.odometerOptions;
_results = [];
for (k in _ref1) {
v = _ref1[k];
_results.push((_base = Odometer.options)[k] != null ? (_base = Odometer.options)[k] : _base[k] = v);
}
return _results;
}
}, 0);
Odometer.init = function() {
var el, elements, _i, _len, _ref1, _results;
if (document.querySelectorAll == null) {
return;
}
elements = document.querySelectorAll(Odometer.options.selector || '.odometer');
_results = [];
for (_i = 0, _len = elements.length; _i < _len; _i++) {
el = elements[_i];
_results.push(el.odometer = new Odometer({
el: el,
value: (_ref1 = el.innerText) != null ? _ref1 : el.textContent
}));
}
return _results;
};
if ((((_ref1 = document.documentElement) != null ? _ref1.doScroll : void 0) != null) && (document.createEventObject != null)) {
_old = document.onreadystatechange;
document.onreadystatechange = function() {
if (document.readyState === 'complete' && Odometer.options.auto !== false) {
Odometer.init();
}
return _old != null ? _old.apply(this, arguments) : void 0;
};
} else {
document.addEventListener('DOMContentLoaded', function() {
if (Odometer.options.auto !== false) {
return Odometer.init();
}
}, false);
}
if (typeof define === 'function' && define.amd) {
define([], function() {
return Odometer;
});
} else if (typeof exports !== "undefined" && exports !== null) {
module.exports = Odometer;
} else {
window.Odometer = Odometer;
}
}).call(this);

How to style a cell's children when exporting an html table to XLSX

How do you style cell child elements in the export process?
Given a foo table like this:
<table id="myTableName">
<thead id="myTableNameHdr"><tr><th style="background-color:navy;color:white;">Test<th></tr></thead>
<tbody id="myTableNameBod"><tr><td>
Choose
<span style="color:red">RED </span>
or
<span style="color:blue">BLUE </span>
colors...
<td></tr></tbody>
</table>
How can I render the red and blue text in the cell in a way that translates for excel. Using inline styles works well for the cell level styles as i have it in my foo header row. However, the inner text styles are dropped. I realize this could be a by product of getting the text attribute vs iterating the children in the lib I'm using. Is there an alternative?
I am using a js that I inherited and I do not have the non-minified version :( I'm hoping someone knows who's it is. Maybe someone might recognize it.
Portion of formatted min.js code: (did not include all of it because >35K lines total)
if (!Object.keys) {
Object.keys = (function () {
var hasOwnProperty = Object.prototype.hasOwnProperty,
hasDontEnumBug = !({
toString: null
})
.propertyIsEnumerable("toString"),
dontEnums = ["toString", "toLocaleString", "valueOf", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable", "constructor"],
dontEnumsLength = dontEnums.length;
return function (obj) {
if (typeof obj !== "object" && typeof obj !== "function" || obj === null) {
throw new TypeError("Object.keys called on non-object");
}
var result = [];
for (var prop in obj) {
if (hasOwnProperty.call(obj, prop)) {
result.push(prop);
}
}
if (hasDontEnumBug) {
for (var i = 0; i < dontEnumsLength; i++) {
if (hasOwnProperty.call(obj, dontEnums[i])) {
result.push(dontEnums[i]);
}
}
}
return result;
};
})();
}
if (!Array.prototype.filter) {
Array.prototype.filter = function (fun) {
if (this == null) {
throw new TypeError();
}
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun != "function") {
throw new TypeError();
}
var res = [];
var thisp = arguments[1];
for (var i = 0; i < len; i++) {
if (i in t) {
var val = t[i];
if (fun.call(thisp, val, i, t)) {
res.push(val);
}
}
}
return res;
};
}
if (!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/g, "");
};
}
if (!Array.prototype.forEach) {
Array.prototype.forEach = function (fun) {
if (this === void 0 || this === null) {
throw new TypeError();
}
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun !== "function") {
throw new TypeError();
}
var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
for (var i = 0; i < len; i++) {
if (i in t) {
fun.call(thisArg, t[i], i, t);
}
}
};
}
if (!Array.prototype.map) {
Array.prototype.map = function (callback, thisArg) {
var T, A, k;
if (this == null) {
throw new TypeError(" this is null or not defined");
}
var O = Object(this);
var len = O.length >>> 0;
if (typeof callback !== "function") {
throw new TypeError(callback + " is not a function");
}
if (thisArg) {
T = thisArg;
}
A = new Array(len);
k = 0;
while (k < len) {
var kValue, mappedValue;
if (k in O) {
kValue = O[k];
mappedValue = callback.call(T, kValue, k, O);
A[k] = mappedValue;
}
k++;
}
return A;
};
}
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (searchElement, fromIndex) {
if (this === undefined || this === null) {
throw new TypeError('"this" is null or not defined');
}
var length = this.length >>> 0;
fromIndex = +fromIndex || 0;
if (Math.abs(fromIndex) === Infinity) {
fromIndex = 0;
}
if (fromIndex < 0) {
fromIndex += length;
if (fromIndex < 0) {
fromIndex = 0;
}
}
for (; fromIndex < length; fromIndex++) {
if (this[fromIndex] === searchElement) {
return fromIndex;
}
}
return -1;
};
}
if (!Array.isArray) {
Array.isArray = function (obj) {
return Object.prototype.toString.call(obj) === "[object Array]";
};
}
"use strict";
if (typeof ArrayBuffer !== "undefined" && !ArrayBuffer.prototype.slice) {
ArrayBuffer.prototype.slice = function (begin, end) {
begin = (begin | 0) || 0;
var num = this.byteLength;
end = end === (void 0) ? num : (end | 0);
if (begin < 0) {
begin += num;
Deeper snippet same file:
var HTML_ = (function () {
function html_to_sheet(str, _opts) {
var opts = _opts || {};
if (DENSE != null && opts.dense == null) {
opts.dense = DENSE;
}
var ws = opts.dense ? ([]) : ({});
var i = str.indexOf("<table"),
j = str.indexOf("</table");
if (i == -1 || j == -1) {
throw new Error("Invalid HTML: missing <table> / </table> pair");
}
var rows = str.slice(i, j)
.split(/(:?<tr[^>]*>)/);
var R = -1,
C = 0,
RS = 0,
CS = 0;
var range = {
s: {
r: 10000000,
c: 10000000
},
e: {
r: 0,
c: 0
}
};
var merges = [],
midx = 0;
for (i = 0; i < rows.length; ++i) {
var row = rows[i].trim();
if (row.substr(0, 3) == "<tr") {
++R;
C = 0;
continue;
}
if (row.substr(0, 3) != "<td") {
continue;
}
var cells = row.split("</td>");
for (j = 0; j < cells.length; ++j) {
var cell = cells[j].trim();
if (cell.substr(0, 3) != "<td") {
continue;
}
var m = cell,
cc = 0;
while (m.charAt(0) == "<" && (cc = m.indexOf(">")) > -1) {
m = m.slice(cc + 1);
}
while (m.indexOf(">") > -1) {
m = m.slice(0, m.lastIndexOf("<"));
}
var tag = parsexmltag(cell.slice(0, cell.indexOf(">")));
CS = tag.colspan ? +tag.colspan : 1;
if ((RS = +tag.rowspan) > 0 || CS > 1) {
merges.push({
s: {
r: R,
c: C
},
e: {
r: R + (RS || 1) - 1,
c: C + CS - 1
}
});
}
if (!m.length) {
C += CS;
continue;
}
m = unescapexml(m)
.replace(/[\r\n]/g, "");
if (range.s.r > R) {
range.s.r = R;
}
if (range.e.r < R) {
range.e.r = R;
}
if (range.s.c > C) {
range.s.c = C;
}
if (range.e.c < C) {
range.e.c = C;
}
if (opts.dense) {
if (!ws[R]) {
ws[R] = [];
}
if (Number(m) == Number(m)) {
ws[R][C] = {
t: "n",
v: +m
};
} else {
ws[R][C] = {
t: "s",
v: m
};
}
} else {
var coord = encode_cell({
r: R,
c: C
});
if (Number(m) == Number(m)) {
ws[coord] = {
t: "n",
v: +m
};
} else {
ws[coord] = {
t: "s",
v: m
};
}
}
C += CS;
}
}
ws["!ref"] = encode_range(range);
return ws;
}
The answer is it can be done as long as you pay for the pro version.

Cannot read property 'innerHTML' of undefined

I'm trying to test an app in salesforce lightning component, but when I load the app (I try this app) I got the error
Cannot read property 'innerHTML' of undefined
The associated code is here :
!(function(t, e) {
var r = function(e) {
(t.execScript || function(e) {
t["eval"].call(t, e)
})(e)
},
i = function(t, e) {
return t instanceof(e || Array)
},
s = document,
n = "getElementsByTagName",
a = "length",
c = "readyState",
l = "onreadystatechange",
u = s[n]("script"),
o = u[u[a] - 1],
f = o.innerHTML.replace(/^\s+|\s+$/g, "");
if (!t.ljs) {
var h = o.src.match(/checkLoaded/) ? 1 : 0,
d = s[n]("head")[0] || s.documentElement,
p = function(t) {
var e = {};
e.u = t.replace(/#(=)?([^#]*)?/g, function(t, r, i) {
e[r ? "f" : "i"] = i;
return ""
});
return e
},
v = function(t, e, r) {
var i = s.createElement(t),
n;
if (r) {
if (i[c]) {
i[l] = function() {
if (i[c] === "loaded" || i[c] === "complete") {
i[l] = null;
r()
}
}
} else {
i.onload = r
}
}
for (n in e) {
e[n] && (i[n] = e[n])
}
d.appendChild(i)
},
m = function(t, e) {
if (this.aliases && this.aliases[t]) {
var r = this.aliases[t].slice(0);
i(r) || (r = [r]);
e && r.push(e);
return this.load.apply(this, r)
}
if (i(t)) {
for (var s = t[a]; s--;) {
this.load(t[s])
}
e && t.push(e);
return this.load.apply(this, t)
}
if (t.match(/\.js\b/) || t.match(/\.sfjs\b/)) {
t = t.replace(".sfjs", "");
return this.loadjs(t, e)
} else if (t.match(/\.css\b/) || t.match(/\.sfcss\b/)) {
t = t.replace(".sfcss", "");
return this.loadcss(t, e)
} else {
return this.loadjs(t, e)
}
},
y = {},
g = {
aliases: {},
loadjs: function(t, r) {
var i = p(t);
t = i.u;
if (y[t] === true) {
r && r();
return this
} else if (y[t] !== e) {
if (r) {
y[t] = function(t, e) {
return function() {
t && t();
e && e()
}
}(y[t], r)
}
return this
}
y[t] = function(e) {
return function() {
y[t] = true;
e && e()
}
}(r);
r = function() {
y[t]()
};
v("script", {
type: "text/javascript",
src: t,
id: i.i,
onerror: function(t) {
if (i.f) {
var e = t.currentTarget;
e.parentNode.removeChild(e);
v("script", {
type: "text/javascript",
src: i.f,
id: i.i
}, r)
}
}
}, r);
return this
},
loadcss: function(t, e) {
var r = p(t);
t = r.u;
y[t] || v("link", {
type: "text/css",
rel: "stylesheet",
href: t,
id: r.i
});
y[t] = true;
e && e();
return this
},
load: function() {
var t = arguments,
r = t[a];
if (r === 1 && i(t[0], Function)) {
t[0]();
return this
}
m.call(this, t[0], r <= 1 ? e : function() {
g.load.apply(g, [].slice.call(t, 1))
});
return this
},
addAliases: function(t) {
for (var e in t) {
this.aliases[e] = i(t[e]) ? t[e].slice(0) : t[e]
}
return this
}
};
if (h) {
var j, b, x, A;
for (j = 0, b = u[a]; j < b; j++) {
(A = u[j].getAttribute("src")) && (y[A.replace(/#.*$/, "")] = true)
}
x = s[n]("link");
for (j = 0, b = x[a]; j < b; j++) {
(x[j].rel === "stylesheet" || x[j].type === "text/css") && (y[x[j].getAttribute("href").replace(/#.*$/, "")] = true)
}
}
t.ljs = g
}
f && r(f)
})(window);
But I'm a novice with javascript and I don't know how to fix it (i'd like to test this app)
Thanks !
That just means that the element that you are looking for does not exist:
var elementNotFound = document.getElementById("noSuchId"); // Does not exist
console.log("The element:", elementNotFound);
console.log(elementNotFound.innerHTML);
As you have posted the mimified JavaScript and no HTML, I don't know how to help further then saying: Make use the ID you are using to find the element is correct and has no spelling mistakes, and that the element is actually in the HTML.
Hope this helps.

Function Conflict with Jquery.min.js

currently working on metal website so i need unit conversion tool like in this site
http://www.theunitconverter.com/unit-conversion-widget.html
i try add the code, but its not working.
and its working when i remove this
<script src="https://code.jquery.com/jquery-2.2.1.min.js"></script>
the problem is i need those min.js script for another jquery function.
and i try to add the javascript converter to another file but i couldn't place the correct noconflict function. the js goes like this.
function IsNum(a) {
if (a != null && a != "") {
return !isNaN(a)
}
return false
}
function $(b) {
if (typeof b == "string") {
return document.getElementById(b)
}
return b
}
function v(g) {
var f = $("a").value;
var e = $("b").value;
var j = $("c").value;
var h = $("d").value;
if (g == 0) {
if (!IsNum(f)) {
return false
}
$("c").value = $("a").value * h / e
} else {
if (!IsNum(j)) {
return false
}
$("a").value = $("c").value * e / h
}
}
function o(a) {
var j = $("e").value;
var d = $("f").value;
var c = $("g").value;
var b = $("h").value;
if (a == 0) {
if (!IsNum(j)) {
return false
}
$("g").value = $("e").value * b / d
} else {
if (!IsNum(c)) {
return false
}
$("e").value = $("g").value * d / b
}
}
function r(x) {
var q;
var p;
var ub;
var ud;
var s;
if (x == 1) {
ub = $("b");
ud = $("d");
ua = $("a");
uc = $("c");
s = $("u").value
} else {
ub = $("f");
ud = $("h");
ua = $("e");
uc = $("g");
s = $("s").value
}
var f = eval(s + "f");
var t = eval(s + "t");
var u0 = eval(s + "0");
var u1 = eval(s + "1");
var amount = eval(u0)[t] / eval(u0)[f];
var z = 0;
for (var n in u) {
if (s == u[n]) {
z = 1
}
}
ua.value = "1";
uc.value = amount;
ub.options.length = 0;
ud.options.length = 0;
if (z == 1) {
var o = new Option("Common units", "0");
o.disabled = "false";
var r = new Option("Common units", "0");
r.disabled = "false";
ub.add(o);
ud.add(r);
for (var n in u0) {
p = new Option(n, u0[n]);
if (n == f) {
p.selected = "true"
}
q = new Option(n, u0[n]);
if (n == t) {
q.selected = "true"
}
ub.add(p);
ud.add(q)
}
o = new Option("Other units", "0");
o.disabled = "false";
r = new Option("Other units", "0");
r.disabled = "false";
ub.add(o);
ud.add(r);
for (var n in u1) {
p = new Option(n, u1[n]);
q = new Option(n, u1[n]);
ub.add(p);
ud.add(q)
}
} else {
for (var n in u0) {
p = new Option(n, u0[n]);
q = new Option(n, u0[n]);
if (n == f) {
p.selected = "true"
}
q = new Option(n, u0[n]);
if (n == t) {
q.selected = "true"
}
ub.add(p);
ud.add(q)
}
}
};
Thanks for any kind of help.
Wrap everything inside
(function($) {
...
})(jQuery);
Your code should be
(function($) {
function IsNum(a) {
if (a != null && a != "") {
return !isNaN(a)
}
return false
}
function $(b) {
if (typeof b == "string") {
return document.getElementById(b)
}
return b
}
function v(g) {
var f = $("a").value;
var e = $("b").value;
var j = $("c").value;
var h = $("d").value;
if (g == 0) {
if (!IsNum(f)) {
return false
}
$("c").value = $("a").value * h / e
} else {
if (!IsNum(j)) {
return false
}
$("a").value = $("c").value * e / h
}
}
function o(a) {
var j = $("e").value;
var d = $("f").value;
var c = $("g").value;
var b = $("h").value;
if (a == 0) {
if (!IsNum(j)) {
return false
}
$("g").value = $("e").value * b / d
} else {
if (!IsNum(c)) {
return false
}
$("e").value = $("g").value * d / b
}
}
function r(x) {
var q;
var p;
var ub;
var ud;
var s;
if (x == 1) {
ub = $("b");
ud = $("d");
ua = $("a");
uc = $("c");
s = $("u").value
} else {
ub = $("f");
ud = $("h");
ua = $("e");
uc = $("g");
s = $("s").value
}
var f = eval(s + "f");
var t = eval(s + "t");
var u0 = eval(s + "0");
var u1 = eval(s + "1");
var amount = eval(u0)[t] / eval(u0)[f];
var z = 0;
for (var n in u) {
if (s == u[n]) {
z = 1
}
}
ua.value = "1";
uc.value = amount;
ub.options.length = 0;
ud.options.length = 0;
if (z == 1) {
var o = new Option("Common units", "0");
o.disabled = "false";
var r = new Option("Common units", "0");
r.disabled = "false";
ub.add(o);
ud.add(r);
for (var n in u0) {
p = new Option(n, u0[n]);
if (n == f) {
p.selected = "true"
}
q = new Option(n, u0[n]);
if (n == t) {
q.selected = "true"
}
ub.add(p);
ud.add(q)
}
o = new Option("Other units", "0");
o.disabled = "false";
r = new Option("Other units", "0");
r.disabled = "false";
ub.add(o);
ud.add(r);
for (var n in u1) {
p = new Option(n, u1[n]);
q = new Option(n, u1[n]);
ub.add(p);
ud.add(q)
}
} else {
for (var n in u0) {
p = new Option(n, u0[n]);
q = new Option(n, u0[n]);
if (n == f) {
p.selected = "true"
}
q = new Option(n, u0[n]);
if (n == t) {
q.selected = "true"
}
ub.add(p);
ud.add(q)
}
}
};
})(jQuery);

Categories