Skip to content

Commit

Permalink
Merge pull request #56 from shgysk8zer0/bug/cal-policy-name
Browse files Browse the repository at this point in the history
Fix name of Google Cal Policy function
  • Loading branch information
shgysk8zer0 committed Jan 12, 2024
2 parents 0fedaa6 + 0b80c63 commit 43f6f73
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [v0.3.1] 2024-01-12

### Fixed
- Fix name of Google Calendar Policy function on import & usage

## [v0.3.0] - 2024-01-08

### Added
Expand Down
6 changes: 3 additions & 3 deletions google/calendar.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* @copyright 2023 Chris Zuber <admin@kernvalley.us>
* @copyright 2023-2024 Chris Zuber <admin@kernvalley.us>
*/

import { createIframe } from '../elements.js';
import { isTrustPolicy } from '../trust.js';
import { GOOGLE_CALENDAR } from './urls.js';
import { createGoogleCalendarPolicy, GOOGLE_CALENDAR_POLICY } from './policies.js';
import { getGoogleCalendarPolicy, GOOGLE_CALENDAR_POLICY } from './policies.js';

// Hate that this requires `allow-same-origin`, but it does...
const sandbox = ['allow-scripts', 'allow-same-origin', 'allow-popups', 'allow-popups-to-escape-sandbox'];
Expand Down Expand Up @@ -107,7 +107,7 @@ export function createGoogleCalendar(calendarId, {
dataset,
styles,
animation,
policy = createGoogleCalendarPolicy(),
policy = getGoogleCalendarPolicy(),
events: { capture, passive, once, signal, ...events } = {},
...attrs
} = {}) {
Expand Down
68 changes: 68 additions & 0 deletions google/maps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* @copyright 2023-2024 Chris Zuber <admin@kernvalley.us>
*/

import { createIframe } from '../elements.js';
import { createPolicy, isTrustPolicy } from '../trust.js';
import { callOnce } from '../utility.js';

const sandbox = ['allow-scripts', 'allow-same-origin', 'allow-popups', 'allow-popups-to-escape-sandbox'];
const policyName = 'goog-maps#script-url';

export const GMAPS_EMBED = 'https://www.google.com/maps/embed';
export const trustPolicies = [policyName];

export const getPolicy = callOnce(() => createPolicy(policyName, {
createScriptURL: input => {
if (input.startsWith(GMAPS_EMBED + '?')) {
return input;
} else {
throw new TypeError(`Invalid Google Maps embed URL: "${input}".`);
}
}
}));

export function createGoogleMapsURL(id, { policy } = {}) {
const url = new URL(GMAPS_EMBED);
url.searchParams.set('pb', id);

if (isTrustPolicy(policy)) {
return policy.createScriptURL(url.href);
} else {
return url.href;
}
}

export function createGoogleMaps(place, {
width = 800,
height = 600,
frameBorder = 0,
loading = 'lazy',
fetchPriority = 'auto',
referrerPolicy = 'no-referrer',
title = 'Google Maps Embed',
credentialless = false,
part = [],
classList = [],
id,
slot,
dataset,
styles,
animation,
policy = getPolicy(),
events: { capture, passive, once, signal, ...events } = {},
...attrs
} = {}) {
const url = createGoogleMapsURL(place, { policy });

return createIframe(url, {
width, height, sandbox, part, slot, loading, animation, dataset, frameBorder,
classList, id, title, credentialless, styles, fetchPriority, referrerPolicy,
events: { capture, passive, once, signal, ...events }, ...attrs,
});
}
//<iframe src="https://www.google.com/maps/embed?pb=!1m14!1m12!1m3!1d12951.152196740677!2d-118.42799294999999!3d35.756013949999996!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!5e0!3m2!1sen!2sus!4v1703701916703!5m2!1sen!2sus" width="400" height="300" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>

// <iframe src="https://www.google.com/maps/embed?pb=!1m14!1m12!1m3!1d12951.152196740677!2d-118.42799294999999!3d35.756013949999996!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!5e0!3m2!1sen!2sus!4v1703701916703!5m2!1sen!2sus" width="600" height="450" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>

// <iframe src="https://www.google.com/maps/embed?pb=!1m14!1m12!1m3!1d12951.152196740677!2d-118.42799294999999!3d35.756013949999996!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!5e0!3m2!1sen!2sus!4v1703701916703!5m2!1sen!2sus" width="800" height="600" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shgysk8zer0/kazoo",
"version": "0.3.0",
"version": "0.3.1",
"private": false,
"type": "module",
"description": "A JavaScript monorepo for all the things!",
Expand Down

0 comments on commit 43f6f73

Please sign in to comment.