Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

fix(demos): codepen demos load svg assets #6727

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions docs/app/js/codepen.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@

var LINK_FONTS_ROBOTO = '<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,400italic">';

var ASSET_CACHE_JS = 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-114/assets-cache.js';
var ASSET_CACHE_JS = 'http://ngmaterial.assets.s3.amazonaws.com/svg-assets-cache.js';


return {
translate: translate
Expand All @@ -75,7 +76,7 @@
js: processJs(files.js),
css: mergeFiles( files.css ).join(' '),

js_external: externalScripts.concat([CORE_JS, ASSET_CACHE_JS]).join(';'),
js_external: externalScripts.concat([ASSET_CACHE_JS, CORE_JS]).join(';'),
css_external: [CORE_CSS, DOC_CSS].join(';')
});
}
Expand Down Expand Up @@ -184,18 +185,18 @@
.replace(/&/g, "&amp;");
}

// Required to make codepen work. Demos define their own module when running on the
// docs site. In order to ensure the codepen example can use the asset-cache, the
// Required to make codePen work. Demos define their own module when running on the
// docs site. In order to ensure the codepen example can use the svg-asset-cache.js, the
// module needs to match so that the $templateCache is populated with the necessary
// assets.

function replaceDemoModuleWithCodepenModule(file) {
var matchAngularModule = /\.module\(('[^']*'|"[^"]*")\s*,(\s*\[([^\]]*)\]\s*\))/ig;
var modules = "['ngMaterial', 'ngMessages', 'material.svgAssetsCache']";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a very good way to fix the asset-cache.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx. It was a brain-teaser at first.


// Include 'ngMessages' since the 'assets-cache.js' has the same dependencies
// angular.module('MyApp', ['ngMaterial', 'ngMessages'])
// See scripts.js for list of external Angular libraries used for the demos

return file.replace(matchAngularModule, ".module('MyApp',['ngMaterial', 'ngMessages'])");
return file.replace(matchAngularModule, ".module('MyApp',"+ modules + ")");
}
}
})();
Loading