app.addSetter('brickwall.toggleHiddenBoards', (data) => { data.showHiddenBoards = !data.showHiddenBoards; window.localStorage.showHiddenBoards = data.showHiddenBoards; }); app.addSetter("brickwall.editPin", (data) => { let index = getLightGalleryIndex(); data.editPinModal.pin = store.data.board.pins[index]; store.do('editPinModal.open'); closeLightGallery(); }); app.addSetter("brickwall.deletePin", async (data) => { if ( !confirm("Are you sure you want to delete this pin?" ) ){ return; } store.do('loader.show'); let index = getLightGalleryIndex(); let pinId = data.board.pins[index].id; data.board.pins.splice(index,1); // store.do("pinZoomModal.close"); closeLightGallery(); let res = await fetch(`api/pins/${pinId}`, { method: 'DELETE' }); if ( res.status == 200 ){ console.log(`deleted pin#${pinId}`); } else { console.error(`error deleting pin#${pinId}`); } store.do('loader.hide'); }); function openOriginal(el){ let data = store.data; let index = getLightGalleryIndex(); let pin = data.board.pins[index]; // alert(pin.id); let path = getImagePath(pin.id, 'o'); // alert(path); window.location = "https://sktp.quikstorm.net/" + path; } async function iosShare(){ let data = store.data; let index = getLightGalleryIndex(); let pin = data.board.pins[index]; let result = await fetch("/api/pins/" + pin.id + "/otl", {method: 'POST'}); let obj = await result.json(); let t = obj.t; let url = "https://sktp.quikstorm.net/otl/" + t; window.location = "shortcuts://run-shortcut?name=Open%20In&input=" + encodeURIComponent(url); } let lightgalleryElement = document.getElementById("lightgallery"); let lightgalleryOpen = false; function openLightGallery(pinId){ let data = store.data; let elements = []; let index = 0; let maxWidth = window.innerWidth * window.devicePixelRatio; let maxHeight = window.innerHeight * window.devicePixelRatio; for ( let i = 0; i < data.board.pins.length; ++i ){ let pin = data.board.pins[i]; let item = {}; item.subHtml = pin.description; item.siteUrl = pin.siteUrl; const THUMBNAIL_IMAGE_SIZE = 400; const IMAGE_SIZES = [400,800,1280,1920,2560]; //TODO: make this dynamic to share the server-side setting // couldn't get srcset and sizes to work right with a vertical bounding box, so we'll just push the right image for the screen size. This won't refresh on resize until closing & re-opening the lightgallery. let maxSize = maxWidth; let isPortrait = "n"; // portrait if ( pin.originalHeight > pin.originalWidth ){ maxSize = maxHeight; isPortrait = "y"; } maxSize = maxSize * 0.74; // take an image 74% smaller than the physical pixel count, we have 10% borders + prefer the smaller size file if it will be enlarged < 10% by the browser (74% just bumps ipad pro portrait into the 2048 size) let bestSize = -1; for ( let s = 0; s < IMAGE_SIZES.length; ++s ){ if ( maxSize <= IMAGE_SIZES[s] ){ bestSize = IMAGE_SIZES[s]; break; } } if ( bestSize < 0 ){ bestSize = 'o'; } item.src = getImagePath(pin.id, bestSize); item.originalUrl = getImagePath(pin.id, 'o'); elements.push(item); if ( data.board.pins[i].id == pinId ){ index = i; } } let options = { speed: 333, loop: false, hideControlOnEnd: true, preload: 3, slideEndAnimatoin: false, dynamic: true, dynamicEl: elements, index: index, download: false, startClass: '', // disable zoom backdropDuration: 0 // disable animate in }; // disable automatically hiding controls on touch devices, they can tap to hide. if ( window.isTouch ){ options.hideBarsDelay = 0; } lightGallery(lightgalleryElement, options ); lightgalleryOpen = true; } function closeLightGallery(){ lightgalleryOpen = false; let uid = lightgalleryElement.getAttribute("lg-uid"); window.lgData[uid].destroy(); } function getLightGalleryIndex(){ let uid = lightgalleryElement.getAttribute("lg-uid"); return window.lgData[uid].index; } document.getElementById("lightgallery").addEventListener("onCloseAfter", () => { let uid = lightgalleryElement.getAttribute("lg-uid"); if ( uid ){ window.lgData[uid].destroy(true); } }); document.getElementById("lightgallery").addEventListener("onSlideClick", () => { let lgOuter = document.querySelector(".lg-outer"); if ( lgOuter.classList.contains("lg-touch-hide-items") ){ lgOuter.classList.remove("lg-touch-hide-items"); } else { lgOuter.classList.add("lg-touch-hide-items"); } }); app.addComponent('brickwall', (store) => { return new Reef('#brickwall', { store: store, template: (data, el) => { // if the hash says we are supposed to be drawing a board, but it hasn't loaded yet... draw an empty div. if ( !data.initialized || (data.hash.board && !data.board) ){ return '
'; } if ( data.hash.board && data.board.pins.length == 0 ){ return `