1.1.1 • Published 3 years ago

vue-gdocs v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Vue-GDocs

Vue component to embed Google Docs content.

Features:

  • Works with any published Google Docs URL
  • Fixes up padding / width of the original automatically
  • Removes tracking beacons from URLs
  • Makes all links open in a new tab by default
<script>
import VueGdocs from 'vue-gdocs';

export {
	components: {VueGdocs}
};
</script>

<template>
	<div>
		<vue-gdocs :url="https://docs.google.com/document/d/e/SOME-LONG-HASH/pub"/>
	</div>
</template>

Installation

Install via NPM:

npm install --save vue-gdocs

Import into your app:

<script>
import VueGdocs from 'vue-gdocs';

export {
	components: {VueGdocs}
};
</script>

Use in your template:

<template>
	<div>
		<vue-gdocs :url="https://docs.google.com/document/d/e/SOME-LONG-HASH/pub"/>
	</div>
</template>

API

Properties

The vue-gdocs component accepts the following properties:

PropertyTypeDefaultDescription
urlStringThe URL of the published Google Doc to display
urlOptionsObject{}Additional options to pass to fetch when retrieving the URL
followBooleanfalseHandle all document-to-document links by replacing the current document contents, if false link will act like a regular link
fixesArraySee belowAn array of fixes to apply, in order
customFixesObject{}Additional user defined fixes, see notes below

Notes:

  • Fixes defaults to all available fixes being enabled in a suitable execution order
  • customFixes is a simple lookup object of functions to run. Each function is called as ($doc) (a jQuery wrapped version of the full document. Each function can return undefined (to carry on with processing on the top level document) or a jQuery object as a replacement body
  • Following links only works if the link is a published document link - i.e. should end in /pub

Events

The following events are emitted from the component:

EventPayloadDescription
click-link({url, event})Emitted when a link is clicked within the document, use event.preventDefault() to prevent normal behaviour

Fixes

The following fixes ship with the component and are all enabled by default:

FixDescription
bodyRootAdd the gdoc-root class to the actual body root <div/> wrapper
bodyPaddingRemove main document padding
bodyWidthRemove main document maximum-width restrictions
linkTargetsMake all <a/> links open in a new window
linkUnshortenRemove Google shortner prefixes for all links