-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
An extended and more robust injectScript #5
Open
nolaneo
wants to merge
1
commit into
minutebase:master
Choose a base branch
from
nolaneo:en/0125-more-robust
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,6 @@ | |
"strict": false, | ||
"white": false, | ||
"eqnull": true, | ||
"esnext": true, | ||
"esversion": 6, | ||
"unused": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,40 @@ | ||
--- | ||
language: node_js | ||
node_js: | ||
- "4" | ||
|
||
sudo: false | ||
|
||
cache: | ||
directories: | ||
- node_modules | ||
- $HOME/.npm | ||
- $HOME/.cache # includes bowers cache | ||
|
||
env: | ||
# we recommend testing LTS's and latest stable release (bonus points to beta/canary) | ||
- EMBER_TRY_SCENARIO=ember-lts-2.4 | ||
- EMBER_TRY_SCENARIO=ember-lts-2.8 | ||
- EMBER_TRY_SCENARIO=ember-release | ||
- EMBER_TRY_SCENARIO=ember-beta | ||
- EMBER_TRY_SCENARIO=ember-canary | ||
- EMBER_TRY_SCENARIO=ember-default | ||
|
||
matrix: | ||
fast_finish: true | ||
allow_failures: | ||
- env: EMBER_TRY_SCENARIO=ember-canary | ||
|
||
before_install: | ||
- "npm config set spin false" | ||
- "npm install -g npm@^2" | ||
- npm config set spin false | ||
- npm install -g bower phantomjs-prebuilt | ||
- bower --version | ||
- phantomjs --version | ||
|
||
install: | ||
- npm install -g bower | ||
- npm install | ||
- bower install | ||
|
||
script: | ||
- npm test | ||
# Usually, it's ok to finish the test scenario without reverting | ||
# to the addon's original dependency state, skipping "cleanup". | ||
- node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO test --skip-cleanup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,26 @@ | ||
import Ember from 'ember'; | ||
|
||
export default function injectScript(src) { | ||
return new Ember.RSVP.Promise(function(resolve) { | ||
var script = document.createElement('script'); | ||
script.type = 'text/javascript'; | ||
script.async = true; | ||
script.src = src; | ||
script.onload = function() { resolve(); }; | ||
document.getElementsByTagName('head')[0].appendChild(script); | ||
let removeListenersAndElement = function(element) { | ||
Ember.$(element).off('load'); | ||
Ember.$(element).off('error'); | ||
element.parentNode.removeChild(element); | ||
}; | ||
|
||
export default function(url) { | ||
return new Ember.RSVP.Promise((resolve, reject) => { | ||
let script = document.createElement('script'); | ||
document.head.appendChild(script); | ||
Ember.$(script).on('load', () => { | ||
removeListenersAndElement(script); | ||
resolve(); | ||
}); | ||
Ember.$(script).on('error', (error) => { | ||
removeListenersAndElement(script); | ||
reject(error); | ||
}); | ||
script.asnyc = true; | ||
script.type = 'text/javascript'; | ||
script.classList.add('test__promise-script'); | ||
script.src = url; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,6 @@ | ||
{ | ||
"name": "ember-inject-script", | ||
"dependencies": { | ||
"handlebars": "~1.3.0", | ||
"jquery": "^1.11.1", | ||
"ember": "1.8.1", | ||
"ember-data": "1.0.0-beta.12", | ||
"ember-resolver": "~0.1.11", | ||
"loader.js": "stefanpenner/loader.js#1.0.1", | ||
"ember-cli-shims": "stefanpenner/ember-cli-shims#0.0.3", | ||
"ember-cli-test-loader": "rwjblue/ember-cli-test-loader#0.0.4", | ||
"ember-load-initializers": "stefanpenner/ember-load-initializers#0.0.2", | ||
"ember-qunit": "0.1.8", | ||
"ember-qunit-notifications": "0.0.4", | ||
"qunit": "~1.15.0" | ||
"ember": "2.11.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/*jshint node:true*/ | ||
module.exports = { | ||
scenarios: [ | ||
{ | ||
name: 'ember-lts-2.4', | ||
bower: { | ||
dependencies: { | ||
'ember': 'components/ember#lts-2-4' | ||
}, | ||
resolutions: { | ||
'ember': 'lts-2-4' | ||
} | ||
}, | ||
npm: { | ||
devDependencies: { | ||
'ember-source': null | ||
} | ||
} | ||
}, | ||
{ | ||
name: 'ember-lts-2.8', | ||
bower: { | ||
dependencies: { | ||
'ember': 'components/ember#lts-2-8' | ||
}, | ||
resolutions: { | ||
'ember': 'lts-2-8' | ||
} | ||
}, | ||
npm: { | ||
devDependencies: { | ||
'ember-source': null | ||
} | ||
} | ||
}, | ||
{ | ||
name: 'ember-release', | ||
bower: { | ||
dependencies: { | ||
'ember': 'components/ember#release' | ||
}, | ||
resolutions: { | ||
'ember': 'release' | ||
} | ||
}, | ||
npm: { | ||
devDependencies: { | ||
'ember-source': null | ||
} | ||
} | ||
}, | ||
{ | ||
name: 'ember-beta', | ||
bower: { | ||
dependencies: { | ||
'ember': 'components/ember#beta' | ||
}, | ||
resolutions: { | ||
'ember': 'beta' | ||
} | ||
}, | ||
npm: { | ||
devDependencies: { | ||
'ember-source': null | ||
} | ||
} | ||
}, | ||
{ | ||
name: 'ember-canary', | ||
bower: { | ||
dependencies: { | ||
'ember': 'components/ember#canary' | ||
}, | ||
resolutions: { | ||
'ember': 'canary' | ||
} | ||
}, | ||
npm: { | ||
devDependencies: { | ||
'ember-source': null | ||
} | ||
} | ||
}, | ||
{ | ||
name: 'ember-default', | ||
npm: { | ||
devDependencies: {} | ||
} | ||
} | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/*jshint node:true*/ | ||
'use strict'; | ||
|
||
module.exports = function(/* environment, appConfig */) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/*jshint node:true*/ | ||
/* global require, module */ | ||
var EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); | ||
|
||
module.exports = function(defaults) { | ||
var app = new EmberAddon(defaults, { | ||
// Add options here | ||
}); | ||
|
||
/* | ||
This build file specifies the options for the dummy test app of this | ||
addon, located in `/tests/dummy` | ||
This build file does *not* influence how the addon or the app using it | ||
behave. You most likely want to be modifying `./index.js` or app's build file | ||
*/ | ||
|
||
return app.toTree(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,59 @@ | ||
{ | ||
"name": "ember-inject-script", | ||
"description": "inject 3rd party scripts into your ember-cli apps", | ||
"version": "0.0.2", | ||
"description": "Inject 3rd party scripts into your ember-cli apps", | ||
"version": "0.0.3", | ||
"keywords": [ | ||
"ember-addon", | ||
"inject script", | ||
"promise script", | ||
"promise getScript" | ||
], | ||
"license": "MIT", | ||
"author": { | ||
"name": "Richard Livsey", | ||
"email": "[email protected]" | ||
}, | ||
"directories": { | ||
"doc": "doc", | ||
"test": "tests" | ||
}, | ||
"repository": "https://github.com/minutebase/ember-inject-script", | ||
"scripts": { | ||
"start": "ember server", | ||
"build": "ember build", | ||
"start": "ember server", | ||
"test": "ember test" | ||
}, | ||
"repository": "https://github.com/minutebase/ember-inject-script", | ||
"engines": { | ||
"node": ">= 0.10.0" | ||
}, | ||
"author": { | ||
"name": "Richard Livsey", | ||
"email": "[email protected]" | ||
"dependencies": { | ||
"ember-cli-babel": "^5.1.7" | ||
}, | ||
"license": "MIT", | ||
"devDependencies": { | ||
"broccoli-asset-rev": "^2.0.0", | ||
"broccoli-ember-hbs-template-compiler": "^1.6.1", | ||
"ember-cli": "0.1.5", | ||
"ember-cli-content-security-policy": "0.3.0", | ||
"ember-cli-dependency-checker": "0.0.7", | ||
"ember-cli-esnext": "0.1.1", | ||
"ember-cli-ic-ajax": "0.1.1", | ||
"ember-cli-inject-live-reload": "^1.3.0", | ||
"ember-cli-qunit": "0.1.2", | ||
"ember-data": "1.0.0-beta.12", | ||
"ember-export-application-global": "^1.0.0", | ||
"express": "^4.8.5", | ||
"glob": "^4.0.5" | ||
"broccoli-asset-rev": "^2.4.5", | ||
"ember-ajax": "^2.4.1", | ||
"ember-cli": "2.11.0", | ||
"ember-cli-app-version": "^2.0.0", | ||
"ember-cli-dependency-checker": "^1.3.0", | ||
"ember-cli-htmlbars": "^1.1.1", | ||
"ember-cli-htmlbars-inline-precompile": "^0.3.3", | ||
"ember-cli-inject-live-reload": "^1.4.1", | ||
"ember-cli-jshint": "^2.0.1", | ||
"ember-cli-qunit": "^3.0.1", | ||
"ember-cli-release": "^0.2.9", | ||
"ember-cli-shims": "^1.0.2", | ||
"ember-cli-sri": "^2.1.0", | ||
"ember-cli-test-loader": "^1.1.0", | ||
"ember-cli-uglify": "^1.2.0", | ||
"ember-data": "^2.11.0", | ||
"ember-disable-prototype-extensions": "^1.1.0", | ||
"ember-export-application-global": "^1.0.5", | ||
"ember-load-initializers": "^0.6.0", | ||
"ember-resolver": "^2.0.3", | ||
"ember-source": "^2.11.0", | ||
"ember-welcome-page": "^2.0.2", | ||
"loader.js": "^4.0.10" | ||
}, | ||
"engines": { | ||
"node": ">= 0.12.0" | ||
}, | ||
"keywords": [ | ||
"ember-addon", | ||
"inject script" | ||
], | ||
"ember-addon": { | ||
"configPath": "tests/dummy/config" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/*jshint node:true*/ | ||
module.exports = { | ||
"framework": "qunit", | ||
"test_page": "tests/index.html?hidepassed", | ||
"disable_watching": true, | ||
"launch_in_ci": [ | ||
"PhantomJS" | ||
], | ||
"launch_in_dev": [ | ||
"PhantomJS", | ||
"Chrome" | ||
] | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a typo here