' + (big ? 'Shop ' + esc(c) + ' →' : '→') + '';
};
var logo = function (l) {
var b = XI.brands && XI.brands[l[0]]; if (!b) return '';
var f = l[1], w = l[2], h = l[3], iw = w / (f[2] - f[0]), ih = h / (f[3] - f[1]);
return '';
};
sec.innerHTML = '
' + svg('', '#00703a', 13) + 'Find it fast
Shop by category
Every piece ships fast, at Emerald Preferred Pricing.
';
(hero || root.firstElementChild).after(sec);
var brandSec = root.querySelector('section.eqs-brand-section'); if (brandSec) { brandSec.id = 'eqm-allbrands'; brandBoxes(brandSec); }
catCounts().then(function (n) { [].slice.call(sec.querySelectorAll('[data-cat]')).forEach(function (a) { var v = n[a.getAttribute('data-cat')]; if (v) a.querySelector('[data-n]').textContent = v.toLocaleString('en-US') + ' pieces'; }); });
preOwned().then(function (d) {
var box = sec.querySelector('.c-pre'); if (!d) { box.querySelector('[data-pics]').innerHTML = ''; return; }
box.querySelector('[data-po]').textContent = d.n + ' pieces';
box.querySelector('[data-pics]').innerHTML = d.pics.map(function (u, k) { return poPic(u, d.boxes && d.boxes[k]); }).join('');
});
var last = sec;
if (specials.length) {
var spec = document.createElement('section'); spec.className = 'eqs-section eqm-sec eqm-specials';
spec.innerHTML = head(esc(cfg.kicker || 'This month only'), TAG, esc(cfg.title || ((cfg.month || '') + ' specials')), 'Emerald Preferred Pricing on popular Quick Ship pieces. While supplies last.') + '';
sec.after(spec); last = spec;
}
var setSec = null;
if (sets.length) {
setSec = document.createElement('section'); setSec.className = 'eqs-section eqm-sec eqm-setsec';
setSec.innerHTML = head('Room-ready sets', BOX, 'Office in a box', 'Everything for a whole room, all Quick Ship, added to your cart in one click.') + '';
last.after(setSec);
// get each item's cart details ahead of time so "Add the set to cart" is quick
var warm = function () { sets.forEach(function (s) { s.items.forEach(function (x) { itemObj(IDX[x[0]]).catch(function () { /* fetched again on click */ }); }); }); };
if ('IntersectionObserver' in window) { var io = new IntersectionObserver(function (es) { if (es.some(function (e) { return e.isIntersecting; })) { io.disconnect(); warm(); } }, { rootMargin: '600px' }); io.observe(setSec); } else setTimeout(warm, 3000);
}
// the landing page content keeps the brand section hidden until the new sections are in place (no flash)
root.classList.add('eqm-ready');
livePrices(all).then(function () {
var g = root.querySelector('.eqm-specials [data-grid]');
if (g) g.innerHTML = specials.map(hcard).join('');
if (setSec) { setSec.querySelector('.eqm-sets').innerHTML = sets.map(setHtml).join(''); layoutAllTiles(); }
bindSets(sets);
});
}
// ---------------- Office in a box ----------------
var asmCode = function (s) { var c = window.EQS_ASM && window.EQS_ASM.codeFor ? window.EQS_ASM.codeFor(s) : null; return c && c !== 'QUOTED' ? c : null; };
var asmPrice = function (c) { return c && window.EQS_ASM && window.EQS_ASM.price ? window.EQS_ASM.price(c) : 0; };
// ---------------- set pictures: one picture per piece, as large as the card allows ----------------
// Where each piece sits inside its product photo (left, top, right, bottom as fractions; photo width/height),
// so the white border can be trimmed. Items not listed show the whole photo.
var CROP = {
'COEDBLFLOS101AE': [0.05, 0.34, 0.96, 0.712, 1], 'COEFINNFLIP25': [0.22, 0.02, 0.8, 0.978, 1], 'COEOS156AE': [0.298, 0.078, 0.7, 0.924, 1],
'COEOS112AE': [0.128, 0.15, 0.88, 0.836, 1], 'COEOS235MW': [0.004, 0.049, 0.986, 0.959, 2.058], 'FLACH197220XJ': [0.212, 0.114, 0.808, 0.934, 1],
'ALUQSFLOWCOSMIC': [0.046, 0.066, 0.948, 0.956, 0.922], 'ALUQSSAVBLACK18': [0.183, 0.06, 0.83, 0.927, 1]
};
// Real height in inches, so pieces sharing a row keep their true size against each other (a 29.5" file next to a 71" bookcase).
var HEIGHT_IN = { 'COEDBLFLOS101AE': 29.5, 'COEFINNFLIP25': 39, 'COEOS156AE': 71, 'COEOS112AE': 29.5, 'COEOS235MW': 29.5, 'FLACH197220XJ': 40,
'ALUQSFLOWCOSMIC': 30, 'ALUQSSAVBLACK18': 31 };
function cropOf(sku, cfg) { var c = (cfg && cfg.crops && cfg.crops[sku]) || CROP[sku]; return c || [0, 0, 1, 1, 1]; }
function tileHtml(sku, qty, cfg) {
var d = IDX[sku], b = cropOf(sku, cfg), cw = b[2] - b[0], ch = b[3] - b[1], ar = cw * b[4] / ch;
var hin = (cfg && cfg.heights && cfg.heights[sku]) || HEIGHT_IN[sku] || 0;
return '' +
(qty > 1 ? '×' + qty + '' : '') + '';
}
// Try every way of putting the pieces (in order) on one or two rows and keep the one with the biggest pictures.
function layoutTiles(box, force) {
var tl = [].slice.call(box.querySelectorAll('.tl')); if (!tl.length) return;
var W = box.clientWidth, H = box.clientHeight, g = 14; if (!W || !H) return;
var place = null; try { place = JSON.parse(box.getAttribute('data-place') || 'null'); } catch (e) { place = null; }
if (place && place.length === tl.length) {
var R = tl.map(function (t, k) { var p = place[k], h = p[2], w = h * (+t.getAttribute('data-ar') || 1); return [p[0], p[1] - h, w, h]; });
var x0 = Math.min.apply(null, R.map(function (r) { return r[0]; })), y0 = Math.min.apply(null, R.map(function (r) { return r[1]; }));
var x1 = Math.max.apply(null, R.map(function (r) { return r[0] + r[2]; })), y1 = Math.max.apply(null, R.map(function (r) { return r[1] + r[3]; }));
var fit = Math.min(W / (x1 - x0), H / (y1 - y0));
if (force === 'fit') return fit;
var sc = force > 0 ? Math.min(force, fit) : fit, ox = (W - (x1 - x0) * sc) / 2, oy = force > 0 ? H - (y1 - y0) * sc - 8 : (H - (y1 - y0) * sc) / 2; // shared scale: all sets stand on the same floor line
R.forEach(function (r, k) { tl[k].style.cssText = 'left:' + (ox + (r[0] - x0) * sc).toFixed(1) + 'px;top:' + (oy + (r[1] - y0) * sc).toFixed(1) + 'px;width:' + (r[2] * sc).toFixed(1) + 'px;height:' + (r[3] * sc).toFixed(1) + 'px'; });
return;
}
var ar = tl.map(function (t) { return +t.getAttribute('data-ar') || 1; }), hin = tl.map(function (t) { return +t.getAttribute('data-h') || 0; }), n = ar.length, best = null;
var plans = [[n]]; for (var k = 1; k < n; k++) plans.push([k, n - k]);
var fixed = (box.getAttribute('data-rows') || '').split(',').map(Number).filter(Boolean);
if (fixed.length && fixed.reduce(function (a, v) { return a + v; }, 0) === n) plans = [fixed];
plans.forEach(function (p) {
var rows = [], fr = [], i = 0;
// each piece's height as a share of the tallest piece in its row (1 when heights are unknown)
p.forEach(function (cnt) {
var hs0 = hin.slice(i, i + cnt), top = Math.max.apply(null, hs0), f = hs0.map(function (h) { return top && h ? h / top : 1; });
fr.push(f); rows.push(ar.slice(i, i + cnt).map(function (a, j) { return a * f[j]; })); i += cnt;
});
var hs = rows.map(function (r) { var S = r.reduce(function (a, v) { return a + v; }, 0); return (W - g * (r.length - 1)) / S; });
var tot = hs.reduce(function (a, v) { return a + v; }, 0), room = H - g * (rows.length - 1);
if (tot > room) hs = hs.map(function (h) { return h * room / tot; });
var area = 0, small = Infinity;
rows.forEach(function (r, ri) { r.forEach(function (a) { var A = hs[ri] * hs[ri] * a; area += A; small = Math.min(small, A); }); });
var score = area * Math.pow(small / (area / n), 0.35);
if (!best || score > best.score) best = { score: score, rows: rows, hs: hs, fr: fr };
});
var used = best.hs.reduce(function (a, v) { return a + v; }, 0) + g * (best.rows.length - 1), y = (H - used) / 2, idx = 0;
best.rows.forEach(function (r, ri) {
var h = best.hs[ri], rw = r.reduce(function (a, v) { return a + v * h; }, 0) + g * (r.length - 1), x = (W - rw) / 2;
r.forEach(function (a, j) { var t = tl[idx++], w = a * h, th = h * best.fr[ri][j]; t.style.cssText = 'left:' + x.toFixed(1) + 'px;top:' + (y + h - th).toFixed(1) + 'px;width:' + w.toFixed(1) + 'px;height:' + th.toFixed(1) + 'px'; x += w + g; });
y += h + g;
});
}
// Placed sets share one scale, so the same kind of piece (a chair) is the same size in every box.
function layoutAllTiles() {
var boxes = [].slice.call(root.querySelectorAll('.eqm-tiles')), placed = boxes.filter(function (b) { return b.hasAttribute('data-place'); });
var fits = placed.map(function (b) { return layoutTiles(b, 'fit'); }).filter(function (v) { return v > 0; });
var common = fits.length ? Math.min.apply(null, fits) : 0;
boxes.forEach(function (b) { layoutTiles(b, b.hasAttribute('data-place') ? common : 0); });
}
window.addEventListener('resize', function () { clearTimeout(layoutAllTiles.t); layoutAllTiles.t = setTimeout(layoutAllTiles, 120); });
function setHtml(s, i) {
var tot = 0, lst = 0, ok = true, pieces = 0;
s.items.forEach(function (x) { var p = price[x[0]]; if (!p) ok = false; tot += (p || 0) * x[1]; lst += IDX[x[0]].l * x[1]; pieces += x[1]; });
// one row per piece type: a single first piece is the big picture, single pieces share a row,
// and a piece bought in quantity is shown once per piece (up to 8) so the whole room is visible
var pic = function (d, tip) { return ''; };
var rows = [], singles = [];
var flush = function () { if (singles.length) { rows.push('
' + singles.join('') + '
'); singles = []; } };
s.items.forEach(function (x, k) {
var d = IDX[x[0]];
if (x[1] === 1 && k === 0) { rows.push('
' + pic(d, d.t) + '
'); return; }
if (x[1] === 1) { singles.push(pic(d, d.t)); return; }
flush();
var reps = []; for (var n = 0; n < Math.min(x[1], 8); n++) reps.push(pic(d, x[1] + ' × ' + d.t));
rows.push('
' + reps.join('') + '
');
});
flush();
var pics = rows.join('');
if (true) {
var days = function (t) { return Math.max.apply(null, (String(t).match(/\d+/g) || ['0']).map(Number)); };
var dl = s.delivery || ''; if (!dl) s.items.forEach(function (x) { var d = IDX[x[0]].d; if (d && (!dl || days(d) > days(dl))) dl = d; });
var pct = ok && lst > tot ? Math.round((1 - tot / lst) * 100) : 0;
var inc = (s.includes || s.items.map(function (x) { return (x[1] > 1 ? x[1] + ' × ' : '') + IDX[x[0]].t.split(',')[0]; })).map(function (t) { return '' + esc(t) + ''; }).join('');
var cfg = window.EQS_HOME_DEALS || {};
var art = s.image ? ''
: '
'; };
var brands = Object.keys(nR).concat(selR).filter(function (v, k, a) { return a.indexOf(v) === k; }).sort(function (a, b) { return (nR[b] || 0) - (nR[a] || 0); });
// categories with nothing in them are left out; on a brand page the Brand list is left out (the page is already that brand)
var subsOf = function (c, k) {
var subs = TD && TD[c] ? TD[c].subs : [];
var h = subs.map(function (sb) { var v = k + ':' + sb[1], on = selS.indexOf(v) >= 0; return nS[v] || on ? opt('s', v, esc(sb[0]), nS[v], on) : ''; }).join('');
return h ? '
No Quick Ship furniture matches “' + esc(selQ) + '”. Quick Ship is our in-stock office furniture. For supplies, technology, breakroom, janitorial and everything else, search all of Emerald Business Supply for “' + esc(selQ) + '” › Looking for furniture? Try a broader word, like chair, desk, file, table or board, or tell us what you need in the form below.
'
: '
No Quick Ship items match these filters. Try removing one, or tell us what you need in the form below.
';
more.hidden = v.length <= shown;
document.dispatchEvent(new CustomEvent('eqs-tiles-replaced', { detail: { count: v.length } }));
}
var arr = { b: selB, c: selC, r: selR, s: selS };
sec.addEventListener('click', function (e) {
var cl = e.target.closest('[data-clear]');
if (cl) { e.preventDefault(); arr[cl.getAttribute('data-clear')].length = 0; if (cl.getAttribute('data-clear') === 'c') selS.length = 0; shown = PAGE; sync(); draw(); return; }
var o = e.target.closest('[data-g]'); if (!o) return;
if (o.getAttribute('data-g') === 'q') { e.preventDefault(); selQ = ''; sync(); location.reload(); return; }
e.preventDefault(); toggle(arr[o.getAttribute('data-g')], o.getAttribute('data-v'));
// V47: ticking a subcategory also ticks its category (so the sub-filter works on brand pages without ticking the category first)
if (o.getAttribute('data-g') === 's') { var sv = o.getAttribute('data-v'), sc = sv.split(':')[0]; if (selS.indexOf(sv) >= 0 && selC.indexOf(sc) < 0) selC.push(sc); if (!selS.some(function (x) { return x.split(':')[0] === sc; }) && (brandPage || oneCatNow())) { var ci = selC.indexOf(sc); if (ci >= 0) selC.splice(ci, 1); } }
shown = PAGE; sync(); draw();
});
sec.querySelector('[data-fbtn]').addEventListener('click', function () { sec.querySelector('.eqm-rwrap').classList.toggle('fopen'); });
sec.querySelector('[data-sort]').addEventListener('change', function (e) { sort = e.target.value; sync(); draw(); });
more.addEventListener('click', function () { shown += PAGE; draw(); });
// infinite scroll: load the next 36 when the bottom of the list comes into view (36 fills whole rows of 2, 3 or 4)
if ('IntersectionObserver' in window) {
more.classList.add('auto');
var near = function () { var r = more.getBoundingClientRect(); return !more.hidden && r.top < innerHeight + 600; };
var grow = function () { if (!near()) return; shown += PAGE; draw(); requestAnimationFrame(function () { setTimeout(grow, 120); }); };
new IntersectionObserver(function (es) { if (es[0].isIntersecting) grow(); }, { rootMargin: '600px 0px' }).observe(more);
}
grid.addEventListener('click', function (e) {
var b = e.target.closest('[data-add]'); if (!b || b.disabled) return;
var card = b.closest('.eqm-fc'), it = IDX[card.getAttribute('data-sku')], msg = card.querySelector('.eqm-msg');
var q = Math.max(1, parseInt(card.querySelector('input').value, 10) || 1);
var lab = b.lastChild; b.disabled = true; msg.className = 'eqm-msg'; msg.textContent = ''; b.classList.remove('ok'); lab.textContent = 'Adding…';
itemObj(it).then(function (o) { return addOne(o, q); }).then(function () {
b.classList.add('ok'); lab.textContent = 'Added to cart'; fcToast('Added to your cart.View cart');
setTimeout(function () { b.classList.remove('ok'); lab.textContent = 'Add to cart'; }, 2500);
}).catch(function () {
lab.textContent = 'Add to cart'; msg.className = 'eqm-msg err'; msg.innerHTML = 'Could not add this item. Open the product';
}).then(function () { b.disabled = false; });
});
draw();
});
}
// Sets that always sit together (lounge sets, Aiden guest seating by finish): the first member reached pulls the rest in behind it
var EQS_CL = [["COEOSGS4012FCGBK","COEOSGS4013FCGBK","COEOSGS4017FCGBK","COEOSGS4012PCGBK","COEOSGS4013PCGBK","COEOSGS4017PCGBK","COEOSGS4012PCGSM","COEOSGS4013PCGSM","COEOSGS4017PCGSM","COEOSGS4007CG"],["COEOSGS4012FMOBK","COEOSGS4013FMOBK","COEOSGS4017FMOBK","COEOSGS4012PMOBK","COEOSGS4013PMOBK","COEOSGS4017PMOBK","COEOSGS4012PMOSM","COEOSGS4013PMOSM","COEOSGS4017PMOSM","COEOSGS4007MO"],["COEOSGS4012FMWBK","COEOSGS4013FMWBK","COEOSGS4017FMWBK","COEOSGS4012PMWBK","COEOSGS4013PMWBK","COEOSGS4017PMWBK","COEOSGS4012PMWSM","COEOSGS4013PMWSM","COEOSGS4017PMWSM","COEOSGS4007MW"],["COEOSGS4012FNABK","COEOSGS4013FNABK","COEOSGS4017FNABK","COEOSGS4012PNABK","COEOSGS4013PNABK","COEOSGS4017PNABK","COEOSGS4012PNASM","COEOSGS4013PNASM","COEOSGS4017PNASM","COEOSGS4007NA"],["COEOSRL3018FBK","COEOSRL3020FBK"],["COEOSRL3018FGT","COEOSRL3020FGT"],["COEOSRL3018FTP","COEOSRL3020FTP"],["OTG13051","OTG13052","OTG13053"],["COEDEFINECLUBGRY","COEDEFINELSEATGRY","COEDEFINESOFAGRY"],["COEHARPERBLK","COEHARPERBLKLS","COEHARPERBLKSOFA"],["COEHARPERSMK","COEHARPERSMKLS","COEHARPERSMKSOFA"],["LLR68952","LLR68953","LLR68951","LLR68950"],["COEMADISONCLUBBK","COEMADISONLSEATBK","COEMADISONSOFABK"],["COEMADISONCLUBGRY","COEMADISONLSEATGRY","COEMADISONSOFAGRY"],["HONVP3LCHRBLK","HONVP3LLOVEBLK","HONVP3LSOFABLK"],["N9N67311ARLOGRY","N9N67331ARLOGRY"],["N9N68211ENZOGRY","N9N68231ENZOGRY"]];
var EQS_CLI = {}; EQS_CL.forEach(function (g, gi) { g.forEach(function (s, k) { EQS_CLI[s] = [gi, k]; }); });
function clusterize(arr, skuF) {
var byG = {}, out = [], done = {};
arr.forEach(function (x) { var c = EQS_CLI[String(skuF(x) || '').toUpperCase()]; if (c) (byG[c[0]] = byG[c[0]] || []).push(x); });
Object.keys(byG).forEach(function (g) { byG[g].sort(function (a, b) { return EQS_CLI[String(skuF(a)).toUpperCase()][1] - EQS_CLI[String(skuF(b)).toUpperCase()][1]; }); });
arr.forEach(function (x) {
var c = EQS_CLI[String(skuF(x) || '').toUpperCase()];
if (!c) { out.push(x); return; }
if (done[c[0]]) return; done[c[0]] = 1; byG[c[0]].forEach(function (y) { out.push(y); });
});
return out;
}
// result cards: one small confirmation at the bottom of the screen (the assembly offer, when there is one, opens on its own)
var fcT = 0;
function fcToast(html) {
var el = document.querySelector('.eqm-fctoast');
if (!el) { el = document.createElement('div'); el.className = 'eqm-fctoast'; el.setAttribute('role', 'status');
el.style.cssText = 'position:fixed;left:50%;bottom:24px;z-index:99999;transform:translateX(-50%);background:#111827;color:#fff;border-radius:10px;padding:11px 16px;font:600 14px/1.3 Arial,sans-serif;box-shadow:0 8px 24px rgba(0,0,0,.25)';
document.body.appendChild(el); }
el.innerHTML = html; clearTimeout(fcT); fcT = setTimeout(function () { el.remove(); }, 4000);
}
// ---------------- start ----------------
Promise.all([
(function () {
var ok = function () { return !!window.EQS_QS_INDEX && window.EQS_QS_INDEX.v >= 3; }, ok2 = function () { return !!window.EQS_QS_INDEX && window.EQS_QS_INDEX.v >= 2; };
return load(window.EQS_QS_INDEX_URL || MEDIA + 'EQS_QS_INDEX_V22.js', ok)
.then(function () { return load(MEDIA + 'EQS_QS_INDEX_V15.js', ok); })
.then(function () { return load(MEDIA + 'EQS_QS_INDEX_V14.js', ok); })
.then(function () { return load(MEDIA + 'EQS_QS_INDEX_V13.js', ok); })
.then(function () { return load(MEDIA + 'EQS_QS_INDEX_V12.js', ok); })
.then(function () { return load(MEDIA + 'EQS_QS_INDEX_V11.js', ok); })
.then(function () { return load(MEDIA + 'EQS_QS_INDEX_V11.txt', ok); })
.then(function () { return load(MEDIA + 'EQS_QS_INDEX_V10.js', ok); })
.then(function () { return load(MEDIA + 'EQS_QS_INDEX_V10.txt', ok); })
.then(function () { return load(MEDIA + 'EQS_QS_INDEX_V9.js', ok); })
.then(function () { return load(MEDIA + 'EQS_QS_INDEX_V9.txt', ok); })
.then(function () { return load(MEDIA + 'EQS_QS_INDEX_V8.js', ok); })
.then(function () { return load(MEDIA + 'EQS_QS_INDEX_V8.txt', ok); })
.then(function () { return load(MEDIA + 'EQS_QS_INDEX_V7.js', ok); })
.then(function () { return load(MEDIA + 'EQS_QS_INDEX_V7.txt', ok); })
.then(function () { return load(MEDIA + 'EQS_QS_INDEX_V6.js', ok); })
.then(function () { return load(MEDIA + 'EQS_QS_INDEX_V5.js', ok); })
.then(function () { return load(MEDIA + 'EQS_QS_INDEX_V4.js', ok); })
.then(function () { return load(MEDIA + 'EQS_QS_INDEX_V3.js', ok); })
.then(function () { return load(MEDIA + 'EQS_QS_INDEX_V2.js', ok2); })
.then(function () { return load(MEDIA + 'EQS_QS_INDEX_V1.js', function () { return !!window.EQS_QS_INDEX; }); });
})(),
MODE === 'home' ? load(MEDIA + (window.EQS_HOME_DEALS_FILE || 'EQS_HOME_DEALS_V4.js') + '?v=' + DAY, function () { return !!window.EQS_HOME_DEALS; }) : Promise.resolve()
]).then(function () {
if (!prep()) { document.documentElement.classList.remove('eqm-results-mode'); return; }
if (MODE === 'results') results(); else if (window.EQS_HOME_DEALS) home(window.EQS_HOME_DEALS);
});
window.EQS_HOME = { active: true, version: VERSION };
})();