ember-inject-scripts
Advanced tools
Comparing version
{ | ||
"name": "ember-inject-scripts", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Seamlessly inject any sort of scripts inside your ember application", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -1,12 +0,70 @@ | ||
# ember-inject-scripts | ||
# ember-inject-scripts | ||
Seamlessly inject any sort of scripts inside your ember application | ||
This README outlines the details of collaborating on this Ember addon. | ||
## Features | ||
- Inject multiple scripts | ||
- Get onload and onerror callbacks for induvidual scripts | ||
- Inject scripts with attributes | ||
- Inject inline scripts | ||
- Get all scripts cached events on done. | ||
## Installation | ||
## Installation | ||
* `git clone <repository-url>` this repository | ||
* `cd ember-inject-scripts` | ||
* `npm install` | ||
* `bower install` | ||
npm install --save ember-inject-scripts | ||
## Usage | ||
let scripts = [ | ||
{ | ||
id: 'vuejs', | ||
src: 'https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.js', | ||
attributes: [ | ||
{ | ||
name: 'data-library', | ||
value: 'vuejs' | ||
} | ||
] | ||
}, | ||
{ | ||
id: 'inline', | ||
inline: `console.log('inline script rendered')`, | ||
attributes: [ | ||
{ | ||
name: 'data-inline', | ||
value: 'true' | ||
} | ||
] | ||
} | ||
] | ||
injectScripts(scripts).then(() => { | ||
console.log ( "🤟Yay ! scripts injected" ); | ||
}); | ||
----> | ||
<script type="text/javascript" id="vuejs" data-test-script="vuejs" data-library="vuejs" | ||
src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.js"></script> | ||
<script type="text/javascript" id="inline" data-test-script="inline" data-inline="true"> | ||
console.log('inline script rendered'); | ||
</script> | ||
**injectScripts** function expects **array of objects as parameter**, the object items are, | ||
| name | type | description | | ||
| ------------- |:-------------:| -----| | ||
| id | string : optional | Adds an id attribute to the script element `id=id` and also creates a test selector `data-test-script=id` | | ||
| type | string : optional : default `text/javascript` | Adds type to the script element | | ||
| src | string : optional | Adds a source to the script element `src=src`| | ||
| inline | string : optional | Adds inline contents to the script element `<script> inline </script>` | | ||
| attributes | Array of object : optional `{ name: 'data-inline', value: 'true' }`| Adds attribute contents to the script element `<script data-inline="true"> inline </script>` | | ||
| onload | function : optional | Callback function for successive load of script. **not available for inline scripts** | | ||
| onerror | function : optional | Callback function for failure while loading of script. **not available for inline scripts** | | ||
**injectScripts.then()** will return all the cacheable event values as array for all passed script elements. | ||
**inline** scripts will have only **target** as the event value. | ||
## Running | ||
@@ -13,0 +71,0 @@ |
17604
15.48%86
207.14%