Skip to content

Commit

Permalink
feat: optimize inserting base style
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoscaceres committed Oct 31, 2016
1 parent 5f7432f commit 7c43660
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions js/w3c/style.js
Expand Up @@ -23,7 +23,6 @@ define([
// meta viewport to the top of the head - so to make sure it's the first
// thing the browser sees. See js/ui/save-html.js.
function createMetaViewport() {

var meta = document.createElement("meta");
meta.name = "viewport";
var contentProps = {
Expand All @@ -35,6 +34,14 @@ define([
return meta;
}

function createBaseStyle() {
var link = document.createElement("link");
link.rel = "stylesheet";
link.href = "https://www.w3.org/StyleSheets/TR/2016/base.css";
link.classList.add("removeOnSave");
return link;
}

function selectStyleVersion(styleVersion) {
var version = "";
switch (styleVersion) {
Expand Down Expand Up @@ -76,15 +83,18 @@ define([
}
// Collect elements for insertion
var elements = createResourceHints();

// Opportunistically apply base style
elements.appendChild(createBaseStyle());
if (!document.head.querySelector("meta[name=viewport]")) {
// Make meta viewport the first element in the head.
elements.insertBefore(createMetaViewport(), elements.firstChild);
}

document.head.insertBefore(elements, document.head.firstChild);

return {
run: function(conf, doc, cb) {

if (!conf.specStatus) {
var warn = "'specStatus' missing from ReSpec config. Defaulting to 'base'.";
conf.specStatus = "base";
Expand Down

0 comments on commit 7c43660

Please sign in to comment.