Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Commit

Permalink
update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Abbott committed Jan 25, 2020
1 parent b9141a8 commit 8a018e3
Show file tree
Hide file tree
Showing 35 changed files with 6,411 additions and 2,972 deletions.
7,267 changes: 5,374 additions & 1,893 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,32 @@
},
"dependencies": {
"@toba/block-spam-referer": "^2.1.0",
"@toba/develop": "^6.7.5",
"@toba/develop": "^6.8.0",
"@toba/feed": "^3.1.1",
"@toba/handlebars": "^2.1.0",
"@toba/node-tools": "^1.4.13",
"@toba/node-tools": "^1.5.3",
"@trailimage/flickr-provider": "^3.2.0",
"@trailimage/google-provider": "^2.5.0",
"@trailimage/models": "^3.2.1",
"@trailimage/models": "^3.2.2",
"compression": "^1.7.0",
"express": "^4.16.0",
"node-fetch": "^2.2.0",
"uglify-js": "^3.7.2"
"uglify-js": "^3.7.6"
},
"devDependencies": {
"@toba/test": "^4.1.17",
"@toba/test": "^4.2.0",
"@types/compression": "1.0.0",
"@types/core-js": "^2.5.0",
"@types/express": "^4.17.2",
"@types/facebook-js-sdk": "^3.3.0",
"@types/gapi": "0.0.35",
"@types/geojson": "^7946.0.0",
"@types/google.analytics": "^0.0.37",
"@types/googlemaps": "^3.38.1",
"@types/googlemaps": "^3.39.2",
"@types/jquery": "^3.3.0",
"@types/mapbox-gl": "^0.45.0",
"@types/node-fetch": "^2.5.4",
"@types/request": "^2.48.3",
"@types/request": "^2.48.4",
"@types/twitter": "1.7.0",
"@types/uglify-js": "^3.0.0",
"cssnano": "^4.1.10",
Expand All @@ -58,7 +58,7 @@
"merge2": "^1.3.0",
"through2": "^3.0.0",
"ts-node-dev": "^1.0.0-pre.44",
"typescript": "^3.7.3"
"typescript": "^3.7.5"
},
"repository": {
"type": "git",
Expand Down
66 changes: 33 additions & 33 deletions src/client/browser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@
* @see http://www.trailimage.com/js/post-menu-data.js
*/
interface PostMenu {
category: { [key: string]: MenuCategory[] };
post: { [key: string]: MenuPost };
category: { [key: string]: MenuCategory[] }
post: { [key: string]: MenuPost }
}

interface MenuCategory {
title: string;
posts: string[];
title: string
posts: string[]
}

/**
* Post data within menu.
*/
interface MenuPost {
slug: string;
title: string;
icon: string;
description: string;
subTitle?: string;
slug: string
title: string
icon: string
description: string
subTitle?: string
/** Post position if part of a series */
part?: number;
part?: number
}

/**
* Which features to enable on a page — determines which libraries to lazy-load
*/
interface PageFeature {
facebook: boolean;
timestamp: number;
facebook: boolean
timestamp: number
}

/**
Expand All @@ -49,54 +49,54 @@ interface PageFeature {
* GeoJSON properties for post photos.
*/
interface MapPhoto {
url?: string;
title?: string;
partKey?: string;
url?: string
title?: string
partKey?: string
/** Distance from clicked cluster */
distance?: number;
distance?: number
}

/**
* Object generated in `mapbox.hbs` to display post details on the map.
*/
interface MapPost {
key: string;
photoID: number;
key: string
photoID: number
bounds: {
/**
* Southwest corner as lon, lat. For the U.S. this is the smallest
* longitude and latitude values.
*/
sw: number[];
sw: number[]
/**
* Northeast corner as lon, lat. For the U.S. this is the largest
* longitude and latitude values.
*/
ne: number[];
};
ne: number[]
}
}

interface PointCluster {
point_count?: number;
point_count?: number
}

interface UrlPosition {
[key: string]: number | number[];
[key: string]: number | number[]
/** longitude, latitude */
center?: number[];
lon?: number;
lat?: number;
zoom?: number;
center?: number[]
lon?: number
lat?: number
zoom?: number
}
interface FakeEvent {
reason: string;
reason: string
}

interface CssPosition extends JQuery.PlainObject {
top?: number;
left?: number;
right?: number;
bottom?: number;
top?: number
left?: number
right?: number
bottom?: number
}

/**
Expand All @@ -106,4 +106,4 @@ type JQueryResponse = (
responseText: string,
textStatus: string,
XMLHttpRequest: XMLHttpRequest
) => any;
) => any
100 changes: 48 additions & 52 deletions src/client/lazy-load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
/// <reference path="./browser.d.ts"/>

interface LazyLoadOptions {
src: string;
srcset: string;
selector: string;
rootMargin?: string;
root?: Element | null;
threshold?: number | number[];
src: string
srcset: string
selector: string
rootMargin?: string
root?: Element | null
threshold?: number | number[]
/** Milliseconds to delay image load */
delayLoad?: number;
delayLoad?: number
}

const defaultOptions: LazyLoadOptions = {
Expand All @@ -21,114 +21,110 @@ const defaultOptions: LazyLoadOptions = {
rootMargin: '0px',
threshold: 0,
delayLoad: 300
};
}

const timerKey = 'timerid';
const timerKey = 'timerid'

const getTimerID = (el: HTMLElement): number => {
const textID = el.dataset[timerKey];
return textID === undefined ? 0 : parseInt(textID);
};
const textID = el.dataset[timerKey]
return textID === undefined ? 0 : parseInt(textID)
}
const setTimerID = (el: HTMLElement, id: number = 0) => {
if (id == 0) {
delete el.dataset[timerKey];
delete el.dataset[timerKey]
} else {
el.dataset[timerKey] = id.toString();
el.dataset[timerKey] = id.toString()
}
};
}

/**
* Based on Lazy Load plugin by Mika Tuupola.
* @see https://appelsiini.net/projects/lazyload
*/
class LazyLoad {
/** Image references */
images: NodeListOf<Element> | HTMLElement[];
options: LazyLoadOptions;
observer: IntersectionObserver;
images: NodeListOf<Element> | HTMLElement[]
options: LazyLoadOptions
observer: IntersectionObserver

constructor(images: HTMLElement[], options: Partial<LazyLoadOptions> = {}) {
this.options = jQuery.extend({}, options, defaultOptions);
this.options = jQuery.extend({}, options, defaultOptions)
this.images =
images.length > 0
? images
: document.querySelectorAll(this.options.selector);
: document.querySelectorAll(this.options.selector)

if (window.IntersectionObserver) {
this.observe();
this.observe()
} else {
// pre-load all image if no observer available
console.warn('Browser does not support IntersectionObserver');
this.images.forEach(this.loadImage);
console.warn('Browser does not support IntersectionObserver')
this.images.forEach(this.loadImage)
}
}

delayLoad(el: HTMLElement) {
let timerID: number = getTimerID(el);
let timerID: number = getTimerID(el)

if (timerID == 0) {
timerID = setTimeout(() => {
this.observer.unobserve(el);
this.loadImage(el);
setTimerID(el); // remove timer data
}, this.options.delayLoad);
this.observer.unobserve(el)
this.loadImage(el)
setTimerID(el) // remove timer data
}, this.options.delayLoad)

setTimerID(el, timerID);
setTimerID(el, timerID)
}
}

cancelLoad(el: HTMLElement) {
const timerID: number = getTimerID(el);
const timerID: number = getTimerID(el)
if (timerID > 0) {
clearTimeout(timerID);
setTimerID(el); // remove timer data
clearTimeout(timerID)
setTimerID(el) // remove timer data
}
}

observe() {
this.observer = new IntersectionObserver(
entries => {
entries.forEach(e => {
const el = e.target as HTMLElement;
const el = e.target as HTMLElement
if (e.isIntersecting) {
this.delayLoad(el);
this.delayLoad(el)
} else {
this.cancelLoad(el);
this.cancelLoad(el)
}
});
})
},
{
root: this.options.root,
rootMargin: this.options.rootMargin,
threshold: this.options.threshold
}
);
this.images.forEach((el: Element) => this.observer.observe(el));
)
this.images.forEach((el: Element) => this.observer.observe(el))
}

loadImage(el: Element) {
const src = el.getAttribute(this.options.src);
const src = el.getAttribute(this.options.src)

if (el.tagName.toLowerCase() == 'img') {
const img = el as HTMLImageElement;
const srcset = img.getAttribute(this.options.srcset);
const img = el as HTMLImageElement
const srcset = img.getAttribute(this.options.srcset)

if (src !== null) {
img.src = src;
}
if (srcset !== null) {
img.srcset = srcset;
}
if (src !== null) img.src = src
if (srcset !== null) img.srcset = srcset
} else {
(el as HTMLElement).style.backgroundImage = `url(${src})`;
;(el as HTMLElement).style.backgroundImage = `url(${src})`
}
}
}

if (jQuery) {
const $ = jQuery;
const $ = jQuery
$.fn.lazyload = function(options: LazyLoadOptions) {
new LazyLoad($.makeArray(this), options);
return this;
};
new LazyLoad($.makeArray(this), options)
return this
}
}
Loading

0 comments on commit 8a018e3

Please sign in to comment.