From 5cc083f63dbf6d775ee83513a1cc3f407b810ce8 Mon Sep 17 00:00:00 2001 From: Hector Leon Zarco Garcia Date: Mon, 23 Nov 2015 17:11:54 +0100 Subject: [PATCH] Clean content-for method --- lib/ember-addon.js | 14 ++------------ lib/registration.js | 8 ++++++++ package.json | 3 +++ 3 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 lib/registration.js diff --git a/lib/ember-addon.js b/lib/ember-addon.js index 162893e..c2b03d5 100644 --- a/lib/ember-addon.js +++ b/lib/ember-addon.js @@ -2,6 +2,7 @@ var path = require('path'); var fs = require('fs'); var mergeTrees = require('broccoli-merge-trees'); var funnel = require('broccoli-funnel'); +var stringifile = require('stringifile'); var serviceWorker = require('./service-worker.js'); @@ -48,18 +49,7 @@ module.exports = { contentFor: function(type, config) { if (config.environment !== 'test' && type === 'body-footer') { - var lines = []; - lines.push(''); - return lines.join('\n'); + return stringifile('registration.js', 'script', __dirname); } } }; diff --git a/lib/registration.js b/lib/registration.js new file mode 100644 index 0000000..47023f9 --- /dev/null +++ b/lib/registration.js @@ -0,0 +1,8 @@ +if ('serviceWorker' in navigator) { + navigator.serviceWorker.register('./service-worker.js', {scope: './'}) + .catch(function(error) { + alert('Error registering service worker:'+error); + }); +} else { + alert('service worker not supported'); +} \ No newline at end of file diff --git a/package.json b/package.json index d70d0c5..13aaef3 100644 --- a/package.json +++ b/package.json @@ -31,5 +31,8 @@ "broccoli-merge-trees": "~0.1.4", "broccoli-writer": "~0.1.1", "serviceworker-cache-polyfill": "^3.0.0" + }, + "devDependencies": { + "stringifile": "^0.1.1" } }