This bookmarklet opens a modal with a search form, allowing you to query the available indexes on a Sitevision website. Results are displayed in a table, where each row represents a search hit. Clicking a row reveals all the indexed data for that specific entry.
Perfect for exploring and debugging indexed content on Sitevision websites.
(async(window, document)=>{ // Bail early if envision is not found. if(!window.envision){ console.warn('Envision not found. Exiting since most likely not Sitevision.'); return; }
Events.onKeydown(searchField,(event)=>{ // Prevent Escape from hiding modal if clearing filter input by escape key. // When the filter input is empty, act as normal. if(event.key ==='Escape'&&!!event.target.value){ event.stopImmediatePropagation(); } });
/** * Creates the HTML markup for an envision dialog. * * @param {object} options An object literal with options. * @param {string} options.dialogId A unique html ID for the dialog. * @param {string} options.title * @returns {string} */
/** * Shortcut for Document.getElementById() for improved minification. * * @param {string} id An identifier for an HTMLElement. * @returns {(HTMLElement|null)} */ el(id){ returnDOCUMENT.getElementById(id); }
/** * Initializes the dialog if it hasn't already been initialized. * * @param {(Function|String|HTMLElement)} initialContent * @returns {Dialog} Returns self for chainability. */ asyncinit(initialContent){ const dialogId =this.id; const titleId =this.tid;
onClose(callback){ if(typeof callback ==='function'){ // TODO: should probably start using new Dialog api instead of old ModalDialog so we can // remove jQuery as a dependency. jQuery('#'+this.id).on('hide.env-modal-dialog',(e)=>{ callback.call(null,this, e); }); }
returnthis; }
onClosed(callback){ if(typeof callback ==='function'){ // TODO: should probably start using new Dialog api instead of old ModalDialog so we can // remove jQuery as a dependency. jQuery('#'+this.id).on('hidden.env-modal-dialog',(e)=>{ callback.call(null,this, e); }); }
// Update columns with data for the row for(const[ columnIndex, columnKey ]ofthis.cols.entries()){ rowCells[columnIndex].textContent =this.data[rowIndex][columnKey]; }
row.dataset.rowIndex = rowIndex; row.style.transform =`translateY(${rowIndex *this.rowHeight}px)`; row.style.display ='';// TODO: Do I really need to hide/show these anymore? Should always only be 2 extra. }else{ this.pool[i].style.display ='none';// TODO: Same here. Needed? } } } }
/** * Performs a fetch request to the Sitevision Rest API. * * @param {object} options An object literal with options. * @param {string} options.nodeId The node identifier to perform the api request on. * @param {string} options.path The path to perform the api request on. * @param {string} options.siteName The site's name. Required when using path. * @param {number} [options.version=ONLINE] The version to use. * @param {string} [options.apiMethod='nodes'] The API method to call. (Usually one of: 'nodes', 'properties', 'contentNodes', 'headless') * @param {object} [options.options={}] Options to be passed to the API method. * @param {string} [options.origin=window.location.origin] The origin to send the request to. * @returns {Response} */ exportdefaultasyncfunctionsitevisionApi({ nodeId, path, siteName, version =ONLINE, apiMethod ='nodes', options ={}, origin = window.location.origin, returnError =false}){ if(!nodeId &&!(path && siteName)){ throw'Api needs either a nodeId or a path.'; }
let response; let data ={}; try{ response =awaitfetch(url, fetchOpts); data =await response.json(); }catch(e){ response ={ok:false,status: response.status }; data ={message:String(e)}; }
let e =null; if(!response.ok){ e =[ `Status ${response.status}`, data?.description, data?.message, ].filter(v=>!!v).join(', ');
if(!returnError){ throw e; } }
if(returnError){ return[ data, e ]; }
return data; }
toasts.js
constDOCUMENT= window.document;
/** * @typedef {Object} ToastOptions * @property {"success" | "primary" | ""} [type=""] The type of toast to emit. * @property {number} [ttl=4] (time to live) in seconds for toast to be shown. * @property {Function} [callback] A callback function executed when toast is removed. * @property {Boolean} [checkmark=undefined] Boolean value if checkmark should be shown. * @property {string} [heading=""] A header string, (not required), will be <strong>. * @property {string} message A message string. */