Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: new scripting documentation #4049

Merged
merged 2 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/documentation/sitespeed.io/scripting/Actions.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/AddText.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/AndroidCommand.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/Cache.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/ChromeTrace.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/Click.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/ClickAndHold.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/Commands.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/ContextClick.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/Debug.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/DoubleClick.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/Element.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/GeckoProfiler.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/JavaScript.html

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions docs/documentation/sitespeed.io/scripting/Measure.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/Meta.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/MouseMove.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/Navigation.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/Screenshot.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/Scroll.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/Select.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/Set.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/SingleClick.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/StopWatch.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/Switch.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/Wait.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/documentation/sitespeed.io/scripting/data/search.json

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions docs/documentation/sitespeed.io/scripting/index.html

Large diffs are not rendered by default.

1,655 changes: 0 additions & 1,655 deletions docs/documentation/sitespeed.io/scripting/index.md

This file was deleted.

702 changes: 702 additions & 0 deletions docs/documentation/sitespeed.io/scripting/scripts/core.js

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions docs/documentation/sitespeed.io/scripting/scripts/core.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 90 additions & 0 deletions docs/documentation/sitespeed.io/scripting/scripts/resize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* global document */
// This file is @deprecated

var NAVBAR_OPTIONS = {};

(function() {
var NAVBAR_RESIZE_LOCAL_STORAGE_KEY = 'NAVBAR_RESIZE_LOCAL_STORAGE_KEY';

var navbar = document.querySelector('#navbar');
var footer = document.querySelector('#footer');
var mainSection = document.querySelector('#main');
var localStorageResizeObject = JSON.parse(
// eslint-disable-next-line no-undef
localStorage.getItem(NAVBAR_RESIZE_LOCAL_STORAGE_KEY)
);

/**
* Check whether we have any resize value in local storage or not.
* If we have resize value then resize the navbar.
**/
if (localStorageResizeObject) {
navbar.style.width = localStorageResizeObject.width;
mainSection.style.marginLeft = localStorageResizeObject.width;
footer.style.marginLeft = localStorageResizeObject.width;
}

var navbarSlider = document.querySelector('#navbar-resize');

function resizeNavbar(event) {
var pageX = event.pageX,
pageXPlusPx = event.pageX + 'px',
min = Number.parseInt(NAVBAR_OPTIONS.min, 10) || 300,
max = Number.parseInt(NAVBAR_OPTIONS.max, 10) || 600;

/**
* Just to add some checks. If min is smaller than 10 then
* user may accidentally end up reducing the size of navbar
* less than 10. In that case user will not able to resize navbar
* because navbar slider will be hidden.
*/
if (min < 10) {
min = 10;
}

/**
* Only resize if pageX in range between min and max
* allowed value.
*/
if (min < pageX && pageX < max) {
navbar.style.width = pageXPlusPx;
mainSection.style.marginLeft = pageXPlusPx;
footer.style.marginLeft = pageXPlusPx;
}
}

function setupEventListeners() {
// eslint-disable-next-line no-undef
window.addEventListener('mousemove', resizeNavbar);
// eslint-disable-next-line no-undef
window.addEventListener('touchmove', resizeNavbar);
}

function afterRemovingEventListeners() {
// eslint-disable-next-line no-undef
localStorage.setItem(
NAVBAR_RESIZE_LOCAL_STORAGE_KEY,
JSON.stringify({
width: navbar.style.width
})
);
}

function removeEventListeners() {
// eslint-disable-next-line no-undef
window.removeEventListener('mousemove', resizeNavbar);
// eslint-disable-next-line no-undef
window.removeEventListener('touchend', resizeNavbar);
afterRemovingEventListeners();
}

navbarSlider.addEventListener('mousedown', setupEventListeners);
navbarSlider.addEventListener('touchstart', setupEventListeners);
// eslint-disable-next-line no-undef
window.addEventListener('mouseup', removeEventListeners);
})();

// eslint-disable-next-line no-unused-vars
function setupResizeOptions(options) {
NAVBAR_OPTIONS = options;
}
265 changes: 265 additions & 0 deletions docs/documentation/sitespeed.io/scripting/scripts/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
/* global document */

const searchId = 'LiBfqbJVcV';
const searchHash = '#' + searchId;
const searchContainer = document.querySelector('#PkfLWpAbet');
const searchWrapper = document.querySelector('#iCxFxjkHbP');
const searchCloseButton = document.querySelector('#VjLlGakifb');
const searchInput = document.querySelector('#vpcKVYIppa');
const resultBox = document.querySelector('#fWwVHRuDuN');

function showResultText(text) {
resultBox.innerHTML = `<span class="search-result-c-text">${text}</span>`;
}

function hideSearch() {
// eslint-disable-next-line no-undef
if (window.location.hash === searchHash) {
// eslint-disable-next-line no-undef
history.go(-1);
}

// eslint-disable-next-line no-undef
window.onhashchange = null;

if (searchContainer) {
searchContainer.style.display = 'none';
}
}

function listenCloseKey(event) {
if (event.key === 'Escape') {
hideSearch();
// eslint-disable-next-line no-undef
window.removeEventListener('keyup', listenCloseKey);
}
}

function showSearch() {
try {
// Closing mobile menu before opening
// search box.
// It is defined in core.js
// eslint-disable-next-line no-undef
hideMobileMenu();
} catch (error) {
console.error(error);
}

// eslint-disable-next-line no-undef
window.onhashchange = hideSearch;

// eslint-disable-next-line no-undef
if (window.location.hash !== searchHash) {
// eslint-disable-next-line no-undef
history.pushState(null, null, searchHash);
}

if (searchContainer) {
searchContainer.style.display = 'flex';
// eslint-disable-next-line no-undef
window.addEventListener('keyup', listenCloseKey);
}

if (searchInput) {
searchInput.focus();
}
}

async function fetchAllData() {
// eslint-disable-next-line no-undef
const { hostname, protocol, port } = location;

// eslint-disable-next-line no-undef
const base = protocol + '//' + hostname + (port !== '' ? ':' + port : '') + baseURL;
// eslint-disable-next-line no-undef
const url = new URL('data/search.json', base);
const result = await fetch(url);
const { list } = await result.json();

return list;
}

// eslint-disable-next-line no-unused-vars
function onClickSearchItem(event) {
const target = event.currentTarget;

if (target) {
const href = target.getAttribute('href') || '';
let elementId = href.split('#')[1] || '';
let element = document.getElementById(elementId);

if (!element) {
elementId = decodeURI(elementId);
element = document.getElementById(elementId);
}

if (element) {
setTimeout(function() {
// eslint-disable-next-line no-undef
bringElementIntoView(element); // defined in core.js
}, 100);
}
}
}

function buildSearchResult(result) {
let output = '';
const removeHTMLTagsRegExp = /(<([^>]+)>)/ig;

for (const res of result) {
const { title = '', description = '' } = res.item;

const _link = res.item.link.replace('<a href="', '').replace(/">.*/, '');
const _title = title.replace(removeHTMLTagsRegExp, "");
const _description = description.replace(removeHTMLTagsRegExp, "");

output += `
<a onclick="onClickSearchItem(event)" href="${_link}" class="search-result-item">
<div class="search-result-item-title">${_title}</div>
<div class="search-result-item-p">${_description || 'No description available.'}</div>
</a>
`;
}

return output;
}

function getSearchResult(list, keys, searchKey) {
const defaultOptions = {
shouldSort: true,
threshold: 0.4,
location: 0,
distance: 100,
maxPatternLength: 32,
minMatchCharLength: 1,
keys: keys
};

const options = { ...defaultOptions };

// eslint-disable-next-line no-undef
const searchIndex = Fuse.createIndex(options.keys, list);

// eslint-disable-next-line no-undef
const fuse = new Fuse(list, options, searchIndex);

const result = fuse.search(searchKey);

if (result.length > 20) {
return result.slice(0, 20);
}

return result;
}

function debounce(func, wait, immediate) {
let timeout;

return function() {
const args = arguments;

clearTimeout(timeout);
timeout = setTimeout(() => {
timeout = null;
if (!immediate) {
// eslint-disable-next-line consistent-this, no-invalid-this
func.apply(this, args);
}
}, wait);

if (immediate && !timeout) {
// eslint-disable-next-line consistent-this, no-invalid-this
func.apply(this, args);
}
};
}

let searchData;

async function search(event) {
const value = event.target.value;
const keys = ['title', 'description'];

if (!resultBox) {
console.error('Search result container not found');

return;
}

if (!value) {
showResultText('Type anything to view search result');

return;
}

if (!searchData) {
showResultText('Loading...');

try {
// eslint-disable-next-line require-atomic-updates
searchData = await fetchAllData();
} catch (e) {
console.log(e);
showResultText('Failed to load result.');

return;
}
}

const result = getSearchResult(searchData, keys, value);

if (!result.length) {
showResultText('No result found! Try some different combination.');

return;
}

// eslint-disable-next-line require-atomic-updates
resultBox.innerHTML = buildSearchResult(result);
}

function onDomContentLoaded() {
const searchButton = document.querySelectorAll('.search-button');
const debouncedSearch = debounce(search, 300);

if (searchCloseButton) {
searchCloseButton.addEventListener('click', hideSearch);
}

if (searchButton) {
searchButton.forEach(function(item) {
item.addEventListener('click', showSearch);
});
}

if (searchContainer) {
searchContainer.addEventListener('click', hideSearch);
}

if (searchWrapper) {
searchWrapper.addEventListener('click', function(event) {
event.stopPropagation();
});
}

if (searchInput) {
searchInput.addEventListener('keyup', debouncedSearch);
}

// eslint-disable-next-line no-undef
if (window.location.hash === searchHash) {
showSearch();
}
}

// eslint-disable-next-line no-undef
window.addEventListener('DOMContentLoaded', onDomContentLoaded);

// eslint-disable-next-line no-undef
window.addEventListener('hashchange', function() {
// eslint-disable-next-line no-undef
if (window.location.hash === searchHash) {
showSearch();
}
});
Loading