Welcome to WordPress. This is your first post. Edit or delete it, then start writing!
/* ============================================================ SIT — Listing list (property cards above the map) v1.2.9 File: /wp-content/mu-plugins/assets/js/sit-listing-list.js Loaded by: /wp-content/mu-plugins/sit-listing-list.php Shortcode: [sit_listing_list] v1.2.9 — 2026-12-05 (ONE CHANGE: placeholder prices go last) - Some agents list at $1 (or another token price) to get offers. These are real listings, so they stay, but "Price: low to high" now starts with the lowest REAL price; placeholder prices go to the END of the row. - Placeholder = sale under $10,000 or lease under $100/month. - Nothing else changed from v1.2.8. v1.2.8 — 2026-12-05 (ONE CHANGE: real total in the counter) - The counter showed at most ~300 (the map loads 3 pages of 100). - Now, after each search, the list asks pins3 (v1.3.0-R4-TOTAL) for the real total of the SAME search the map just made (same filters + area, top=1, only the number is used) and shows it: "3,091 homes for sale in this view". - Until the number arrives (or if it fails) the old count is shown. - The map, pins and cards are unchanged (still up to 300 on the map). - Nothing else changed from v1.2.7. v1.2.7 — 2026-12-03 (ONE CHANGE: no card picked until the visitor picks) - When the cards load (page open or new search), NO card is red and NO pin is marked. Before, the centre card was picked by itself (random). - The red card + marked pin start only when the visitor chooses: hover / click a pin, click a card, or the < > arrows. - Scrolling / swiping the row moves the red card only AFTER the visitor has chosen one (it does not start it). - Nothing else changed from v1.2.6. v1.2.6 — 2026-12-03 (ONE CHANGE: arrows move ONE card) - The round < > arrows beside the row now move exactly one card: the next (or previous) card becomes the red centre card and its pin is marked. Before, an arrow scrolled about one screen (~2 cards). - At the last card, > shows the "Show more" tile. - Swipe / scrollbar / mouse: unchanged. Nothing else changed from v1.2.5. v1.2.5 — 2026-12-02 (ONE CHANGE: phones / touch screens) - Touch screens (no hover): tapping a card only makes it the red centre card (red bubble on its pin), so the visitor sees where the home is on the map first. The red card shows a "View details" button; tapping that button opens the listing window. - PC / mouse: unchanged (click a card = listing window). - Nothing else changed from v1.2.4. v1.2.4 — 2026-12-02 (only these changes) - ONE "current" card = the CENTRE card of the row: RED outline and a bit bigger than the others (was blue). PC: middle of the 3 cards; phone: the one card showing. - Scrolling / swiping the row: the card that ends up in the centre becomes the current card, and its pin on the map is marked (window.SITMapHighlightPin(key, true) — the pin grows + turns red with sit-leaflet-map.js v1.2.4; with v1.2.3 it glows). - Click / tap or hover a pin: its card goes to the CENTRE (a card that was not in the row yet is now put in the 2nd place, not the 1st, so it can be centred) and becomes the current card. Moving the mouse off the pin keeps it (no more flicker back). - Hover a card: its pin is marked; leaving the card marks the current card's pin again. Click a card: it becomes current and opens the listing window (unchanged). - New pins / new search: the centre card of the new row is current. - Nothing else changed from v1.2.3 (hearts in step, sort, 20 per page, note above 30, Saved list). v1.2.3 — 2026-12-02 (only these changes) - CLICK / TAP a pin (main map or Mirror) -> its card moves to the centre of the row and STAYS highlighted (blue outline) until another pin is clicked, the card is opened, or the pins change. On a phone this makes it the one card showing. Hover works as before. (Until sit-leaflet-map.js v1.2.4 the pin click still ALSO opens the listing window — the map file is the next step.) - Hearts stay in step: a home saved / unsaved anywhere (e.g. the ♥ Save button in the listing window, sit-listing-panel.js v1.1.0) now updates that card's heart and the "Saved (N)" count right away (listens to "sit:saved-change"). - Nothing else changed from v1.2.2. v1.2.2 — 2026-11-29 (only this change) - Hovered card: bigger zoom (1.15, was 1.08) and a BLUE outline (was orange). More room above/below the row so it is not cut off. v1.2.1 — 2026-11-29 (only this change) - Hover a pin: its card now scrolls to the CENTRE of the row (was the left edge) and grows a little (zoom effect) with the orange outline. v1.2.0 — 2026-11-28 (only these changes) - Split view (v1.1.0) removed: it was squeezed by the page width. - The cards are now ONE ROW that scrolls sideways, placed right ABOVE the public map (Mirror #sit-mirror-map, else #sit-map). Arrows left / right; swipe on a phone. A "Show more" tile at the end adds 20. - Hover a PIN on the map (main map or Mirror) -> its card scrolls to the front of the row and is highlighted. Hover / tap a card -> its pin glows (unchanged). Uses the pin layers the map already exposes (SIT._cluster, SIT._mirrorPins) — sit-leaflet-map.js is unchanged. - Kept from v1.1.0: only pins in the map view, 20 at a time, price low to high, note above 30 homes. v1.1.0 — 2026-11-28 - SPLIT VIEW: the list places itself beside the public map (the Mirror map #sit-mirror-map when it is on the page, else the main #sit-map): map left (~60%), cards right (~40%) in their own scroll box, same height. Phone / narrow screen: map on top, list below. The map is only moved into the new row and told its new size (invalidateSize) — map code, pins, Boss, Mirror sync are unchanged. - Cards show ONLY the homes whose pins are inside the map view on the screen; moving / zooming the map updates the cards. - 20 cards at a time (was 24), "Show more" adds 20. 2 cards across. - More than 30 homes in view: a note asks to add filters or zoom in. - Default sort: Price low to high (was Newest). v1.0.0 — 2026-11-27 (NEW FILE) - Shows the listings that are on the map as cards (photo, price, address, beds / baths / parking, type, style). - Follows the map: listens to "sit:pins-updated" from sit-leaflet-map.js v1.2.2 (filters, Boss / RMC area, map moves). - Click a card -> the listing preview panel (SITListingOpen, sit-listing-panel.js). Hover a card -> its pin glows on the map (SITMapHighlightPin). - Header: "N homes for sale", Sort (Newest / Price low-high / Price high-low), "Saved" button. - Heart on every card: saves the listing on this device (browser storage "sit_saved_listings_v1"). "Saved" shows only saved homes. window.SITSaved + event "sit:saved-change" are ready for the later step (saves kept on the server per signed-in user, for the CRM). - 24 cards at a time, "Show more" adds 24. - Does NOT change the map, filters, Boss, RMC or Mirror. ============================================================ */ (function () { "use strict"; if (window.SIT_LISTING_LIST_LOADED) return; window.SIT_LISTING_LIST_LOADED = true; const VERSION = "1.2.9"; // v1.2.5: touch screen without hover (phone / tablet) const TOUCH = (function () { try { return window.matchMedia("(hover: none)").matches || window.matchMedia("(pointer: coarse)").matches; } catch (e) { return false; } })(); const THUMB_BASE = "/wp-json/sit/v1/thumb"; const SAVED_KEY = "sit_saved_listings_v1"; const PAGE = 20; // v1.1.0 (was 24) const NARROW_AT = 30; // v1.1.0: note above this many homes in view const THUMB_PARALLEL = 4; function log(...a) { console.log("[SIT LIST]", ...a); } // ------------------------------------------------------------ // v1.2.8: real total — remember the map's last pins3 search (first page) // ------------------------------------------------------------ let lastPinsUrl = ""; const totalCache = new Map(); function notePinsUrl(name) { const u = String(name || ""); if (u.indexOf("/sit/v1/pins3?") === -1) return; if (/[?&]skip=/.test(u)) return; // first page only if (/[?&]top=1(&|$)/.test(u)) return; // our own total request lastPinsUrl = u; } try { if ("PerformanceObserver" in window) { new PerformanceObserver(list => { list.getEntries().forEach(e => notePinsUrl(e.name)); }).observe({ type: "resource", buffered: true }); } } catch (e) {} function askTotal(box) { box.total = null; // small wait so the map's first-page request is recorded setTimeout(() => { const u = lastPinsUrl; if (!u) return; const url = u.replace(/([?&])top=\d+/, "$1top=1"); const done = n => { if (typeof n !== "number" || !isFinite(n)) return; box.total = n; if (!box.savedOnly && !box.loading) updateHeader(box, box.list || []); }; if (totalCache.has(url)) { done(totalCache.get(url)); return; } fetch(url, { credentials: "same-origin" }) .then(r => (r.ok ? r.json() : null)) .then(j => { const n = j && typeof j.total === "number" ? j.total : null; if (n !== null) { totalCache.set(url, n); done(n); log("Real total:", n); } }) .catch(() => {}); }, 50); } // ------------------------------------------------------------ // Helpers // ------------------------------------------------------------ function esc(v) { return String(v == null ? "" : v) .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); } function first(...vals) { for (const v of vals) { if (v === null || v === undefined) continue; const s = String(v).trim(); if (s !== "") return s; } return ""; } function num(v) { const n = Number(v); return Number.isFinite(n) ? n : null; } function money(v) { const n = num(v); if (n === null) return "Price N/A"; return new Intl.NumberFormat("en-CA", { style: "currency", currency: "CAD", maximumFractionDigits: 0 }).format(n); } function count(v, one, many) { const n = num(v); if (n === null) return ""; return n + " " + (n === 1 ? one : many); } function keyOf(item) { return first(item && item.listingKey, item && item.ListingKey, item && item.mlsId, item && item.ListingId); } function priceOf(item) { return num(first(item && item.price, item && item.ListPrice, item && item.list_price)); } function addressOf(item) { return first(item && item.address, item && item.address_full, item && item.UnparsedAddress) || "Listing"; } function typeOf(item) { return first(item && item.propertySubType, item && item.type, item && item.PropertySubType); } function styleOf(item) { return first(item && item.style, item && item.ArchitecturalStyle); } function districtOf(item) { return first(item && item.mlsDistrict, item && item.community); } function isLease(item) { return /LEASE|RENT/i.test(first(item && item.transactionType)); } // v1.1.0: pin position of a listing (null when unknown) function latLngOf(item) { if (!item) return null; const g = item.geo || item.coords || {}; const lat = num(first(item.lat, item.latitude, item.Latitude, g.lat)); const lng = num(first(item.lng, item.lon, item.longitude, item.Longitude, g.lng, g.lon)); if (lat === null || lng === null) return null; return [lat, lng]; } // ------------------------------------------------------------ // Saved homes (this device; server copy comes later) // ------------------------------------------------------------ function readSaved() { try { const raw = window.localStorage.getItem(SAVED_KEY); const arr = raw ? JSON.parse(raw) : []; return Array.isArray(arr) ? arr : []; } catch (e) { return []; } } function writeSaved(arr) { try { window.localStorage.setItem(SAVED_KEY, JSON.stringify(arr)); } catch (e) {} } function savedHas(key) { return !!key && readSaved().some(s => s.key === key); } function savedToggle(key, item) { if (!key) return false; let arr = readSaved(); let on; if (arr.some(s => s.key === key)) { arr = arr.filter(s => s.key !== key); on = false; } else { arr.unshift({ key: key, savedAt: new Date().toISOString(), item: { listingKey: key, mlsId: item && item.mlsId, address: addressOf(item), price: priceOf(item), beds: item && item.beds, baths: item && item.baths, parking: item && item.parking, propertySubType: typeOf(item), style: styleOf(item), mlsDistrict: districtOf(item), transactionType: item && item.transactionType, thumb: item && item.thumb } }); on = true; } writeSaved(arr); try { window.dispatchEvent(new CustomEvent("sit:saved-change", { detail: { key: key, saved: on, count: arr.length } })); } catch (e) {} log(on ? "Saved" : "Unsaved", key, "(" + arr.length + " saved)"); return on; } window.SITSaved = { list: function () { return readSaved(); }, has: savedHas, toggle: savedToggle }; // ------------------------------------------------------------ // Photos (one small request per listing, 4 at a time) // ------------------------------------------------------------ const thumbCache = new Map(); const thumbQueue = []; let thumbActive = 0; function thumbFor(key) { if (!key) return Promise.resolve(""); if (thumbCache.has(key)) return thumbCache.get(key); const p = new Promise(resolve => { thumbQueue.push({ key: key, resolve: resolve }); pumpThumbs(); }); thumbCache.set(key, p); p.then(url => { if (!url) thumbCache.delete(key); }); return p; } function pumpThumbs() { while (thumbActive < THUMB_PARALLEL && thumbQueue.length) { const job = thumbQueue.shift(); thumbActive++; fetch(THUMB_BASE + "?key=" + encodeURIComponent(job.key), { credentials: "same-origin" }) .then(r => (r.ok ? r.json() : null)) .then(j => job.resolve(j && j.ok && j.url ? String(j.url) : "")) .catch(() => job.resolve("")) .then(() => { thumbActive--; pumpThumbs(); }); } } // ------------------------------------------------------------ // Styles (added once) // ------------------------------------------------------------ function addCss() { if (document.getElementById("sit-list-css")) return; const st = document.createElement("style"); st.id = "sit-list-css"; st.textContent = [ ".sit-list{font-family:inherit;color:#111827;}", ".sit-list-bar{display:flex;flex-wrap:wrap;align-items:center;gap:10px;justify-content:space-between;margin:0 0 12px;}", ".sit-list-count{font-weight:800;font-size:18px;}", ".sit-list-tools{display:flex;gap:8px;align-items:center;}", ".sit-list-tools select{padding:6px 8px;border:1px solid #d1d5db;border-radius:8px;background:#fff;font-size:14px;}", ".sit-list-savedbtn{padding:6px 12px;border:1px solid #d1d5db;border-radius:999px;background:#fff;cursor:pointer;font-size:14px;}", ".sit-list-savedbtn.on{background:#fee2e2;border-color:#ef4444;color:#b91c1c;font-weight:700;}", ".sit-list-note{font-size:12px;color:#6b7280;margin:-6px 0 10px;}", ".sit-list-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(240px,1fr));gap:14px;}", ".sit-card{background:#fff;border:1px solid #e5e7eb;border-radius:12px;overflow:hidden;cursor:pointer;transition:box-shadow .15s,transform .15s;}", ".sit-card:hover{box-shadow:0 8px 22px rgba(0,0,0,.16);transform:translateY(-2px);}", ".sit-card-photo{position:relative;height:170px;background:#f3f4f6;}", ".sit-card-photo img{width:100%;height:100%;object-fit:cover;display:block;}", ".sit-card-nophoto{display:flex;align-items:center;justify-content:center;height:100%;color:#9ca3af;font-size:13px;}", ".sit-heart{position:absolute;top:8px;right:8px;width:36px;height:36px;border-radius:50%;border:0;background:rgba(255,255,255,.92);cursor:pointer;font-size:20px;line-height:36px;text-align:center;color:#374151;box-shadow:0 2px 6px rgba(0,0,0,.2);padding:0;}", ".sit-heart.on{color:#ef4444;}", ".sit-card-body{padding:10px 12px 12px;}", ".sit-card-price{font-weight:800;font-size:18px;margin:0 0 4px;}", ".sit-card-addr{font-size:13px;margin:0 0 6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}", ".sit-card-facts{font-size:13px;color:#374151;margin:0 0 4px;}", ".sit-card-type{font-size:12px;color:#6b7280;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}", ".sit-list-more{display:block;margin:16px auto 0;padding:10px 22px;border:1px solid #0b5ed7;border-radius:999px;background:#fff;color:#0b5ed7;font-weight:700;cursor:pointer;}", ".sit-list-empty{padding:30px 10px;text-align:center;color:#6b7280;border:1px dashed #d1d5db;border-radius:12px;}", ".sit-list-warn{font-size:13px;color:#92400e;background:#fffbeb;border:1px solid #fcd34d;border-radius:8px;padding:8px 10px;margin:0 0 10px;}", /* v1.2.0 one sideways-scrolling row above the map */ ".sit-list{margin:0 0 12px;}", ".sit-strip-wrap{position:relative;}", ".sit-list .sit-list-grid{position:relative;display:flex;gap:12px;overflow-x:auto;overflow-y:hidden;scroll-snap-type:x proximity;padding:28px 24px 30px;scroll-behavior:smooth;-webkit-overflow-scrolling:touch;}", ".sit-list .sit-card{flex:0 0 220px;scroll-snap-align:start;position:relative;transition:transform .2s ease,box-shadow .2s ease;}", ".sit-list .sit-card-photo{height:130px;}", ".sit-list .sit-list-empty{flex:1 1 auto;}", ".sit-card.sit-card-hl{outline:3px solid #dc2626;box-shadow:0 0 0 5px rgba(220,38,38,.22),0 14px 32px rgba(0,0,0,.25);transform:scale(1.15);z-index:3;}", /* v1.2.4 red */ ".sit-list .sit-list-more{flex:0 0 140px;margin:0;align-self:stretch;border-radius:12px;display:flex;align-items:center;justify-content:center;text-align:center;}", ".sit-strip-arrow{position:absolute;top:50%;transform:translateY(-60%);z-index:5;width:36px;height:36px;border-radius:50%;border:1px solid #d1d5db;background:rgba(255,255,255,.95);box-shadow:0 2px 8px rgba(0,0,0,.18);cursor:pointer;font-size:20px;line-height:32px;text-align:center;padding:0;color:#111827;}", ".sit-strip-arrow.left{left:-6px;}", ".sit-strip-arrow.right{right:-6px;}", /* v1.2.5 "View details" on the red card (touch screens only) */ ".sit-card-view{display:none;width:100%;margin-top:8px;padding:9px 10px;border:0;border-radius:8px;background:#0b5ed7;color:#fff;font-weight:700;font-size:14px;cursor:pointer;}", ".sit-list.sit-touch .sit-card.sit-card-hl .sit-card-view{display:block;}", "@media (max-width:700px){.sit-list .sit-card{flex-basis:78vw;}.sit-strip-arrow{display:none;}}" ].join("\n"); document.head.appendChild(st); } // ------------------------------------------------------------ // One list box per [sit_listing_list] // ------------------------------------------------------------ const boxes = []; function makeBox(root) { const box = { root: root, items: [], loading: false, shown: 0, sort: "price_asc", // v1.1.0 default (was newest) savedOnly: false, searched: false }; root.classList.add("sit-list"); if (TOUCH) root.classList.add("sit-touch"); // v1.2.5 root.innerHTML = '
' + '' + '' + '