Skip to content

Commit

Permalink
fix(css-injection): enable smoother CSS file for none-css files - re: #…
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed Jan 15, 2018
1 parent 2ccd8ac commit fa7e791
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 41 deletions.
53 changes: 34 additions & 19 deletions client/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions client/dist/index.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/index.min.js.map

Large diffs are not rendered by default.

51 changes: 33 additions & 18 deletions client/vendor/Reloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class Reloader {
const elems = Reloader.getMatches(domData.elems, data.basename, domData.attr);

for (var i = 0, n = elems.length; i < n; i += 1) {
this.swapFile(elems[i], domData.attr, options);
this.swapFile(elems[i], domData, options);
}

(cb || function() {})(elems, domData);
Expand All @@ -102,8 +102,9 @@ export class Reloader {
const tagName = options.tagNames[fileExtension];
const attr = options.attrs[tagName];
return {
elems: document.getElementsByTagName(tagName),
attr: attr
attr,
tagName,
elems: document.getElementsByTagName(tagName)
};
}

Expand All @@ -125,32 +126,46 @@ export class Reloader {
return matches;
};

public swapFile(elem, attr, options) {
public swapFile(elem, domData, options) {

const attr = domData.attr;
const currentValue = elem[attr];
const timeStamp = new Date().getTime();
const key = "browsersync-legacy";
const suffix = key + "=" + timeStamp;
const anchor = getLocation(currentValue);
const search = updateSearch(anchor.search, key, suffix);

if (options.timestamps === false) {
elem[attr] = anchor.href;
} else {
elem[attr] = anchor.href.split("?")[0] + search;
}
switch (domData.tagName) {
case 'link': {
this.logger.trace(`replacing LINK ${attr}`);
this.reloadStylesheet(currentValue);
break;
}
case 'img': {
this.reloadImages(currentValue);
break;
}
default: {
if (options.timestamps === false) {
elem[attr] = anchor.href;
} else {
elem[attr] = anchor.href.split("?")[0] + search;
}

this.logger.info(`reloading ${elem[attr]}`);
this.logger.info(`reloading ${elem[attr]}`);

setTimeout(function () {
if (!hiddenElem) {
hiddenElem = document.createElement("DIV");
document.body.appendChild(hiddenElem);
} else {
hiddenElem.style.display = "none";
hiddenElem.style.display = "block";
setTimeout(function () {
if (!hiddenElem) {
hiddenElem = document.createElement("DIV");
document.body.appendChild(hiddenElem);
} else {
hiddenElem.style.display = "none";
hiddenElem.style.display = "block";
}
}, 200);
}
}, 200);
}

return {
elem: elem,
Expand Down

0 comments on commit fa7e791

Please sign in to comment.