项目作者: nowzoo

项目描述 :
Load stylesheets dynamically. Also scripts.
高级语言: TypeScript
项目地址: git://github.com/nowzoo/sheetload.git
创建时间: 2018-06-16T16:09:43Z
项目社区:https://github.com/nowzoo/sheetload

开源协议:MIT License

下载


Sheetload

Load stylesheets dynamically. Also scripts.

Quick Start

  1. npm i @nowzoo/sheetload --save

Load a stylesheet…

  1. import { Sheetload } from '@nowzoo/sheetload';
  2. //...
  3. Sheetload.load(url)
  4. .then((el: HTMLLinkElement) => {
  5. //links are disabled at this point...
  6. el.removeAttribute(el, 'disabled')
  7. })
  8. .catch((error: any) => {
  9. //...
  10. })

Load a script…

  1. import { Scriptload } from '@nowzoo/sheetload';
  2. //...
  3. Scriptload.load(url)
  4. .then((el: HTMLScriptElement) => {
  5. //...
  6. })
  7. .catch((error: any) => {
  8. //...
  9. })

API

Sheetload

static load(url: string): Promise<HTMLLinkElement>

Loads a stylesheet, resolving with a newly created link element when it loads.

Note: The element’s disabled attribute is set. You are responsible for enabling it:

  1. this.renderer.removeAttribute(link, 'disabled');

Note: The element is appended to document.head. You are responsible for tracking the link tags yourself to prevent duplication.

Scriptload

static load(url: string): Promise<HTMLScriptElement>

Loads a script, resolving with a newly created script element when the script loads.

Note: The element is appended to document.head. You are responsible for tracking the script elements yourself to prevent duplication.

Elementload

static load(el: HTMLElement): Promise<HTMLElement>

Given an element, listens for load and error events. Resolves on load, rejects on error.

Contributing

Contributions are welcome.

  1. git clone https://github.com/nowzoo/sheetload.git
  2. npm i
  3. ng build sheetload --prod

The library code is located under projects/sheetload.

Testing the library…

  1. ng test sheetload

You can also use Wallaby for testing. Use the config found at projects/sheetload/wallaby.js.

Building the library…

  1. ng build sheetload --prod

The demo code is in src. Run the demo locally…

  1. # Build the current version of the library first...
  2. ng build ngx-highlight-js --prod
  3. ng serve --open

License

MIT