Skip to content

Commit

Permalink
add loadCss common helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
aorcsik committed Feb 15, 2024
1 parent 5458bc7 commit 7720f2d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"HTMLMetaElement",
"HTMLParagraphElement",
"HTMLSpanElement",
"HTMLStyleElement",
"HTMLUListElement",
"Promise",
"Response",
Expand Down
5 changes: 2 additions & 3 deletions src/js/changelog-topic.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import ChangelogService from "./changelog/ChangelogService";
import { loadCss } from "./common";

const style = document.createElement("style");
document.getElementsByTagName("head")[0].appendChild(style);
style.appendChild(document.createTextNode(require("../css/changelog.css")));
loadCss(require("../css/changelog.css"));

/**
* @param {URL} url
Expand Down
7 changes: 3 additions & 4 deletions src/js/changelog.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import ChangelogList from "./changelog/ChangelogList";
import ChangelogService from "./changelog/ChangelogService";
import { loadCss } from "./common";

const style = document.createElement("style");
document.getElementsByTagName("head")[0].appendChild(style);
style.appendChild(document.createTextNode(require("../css/changelog.css")));
loadCss(require("../css/changelog.css"));

/** @type {string} */
const apiBase = document.location.hostname.match(/(localhost|127\.0\.0\.1)/) ? "" : "https://bitrise.io";
Expand Down Expand Up @@ -42,4 +41,4 @@ if (queryLAstVisit) {
changelogLoadMoreButton.remove();
changelogService.loadTopics("/changelog.json").then(topics => {
changelogList.render(topics, lastVisitedDate);
});
});});
23 changes: 22 additions & 1 deletion src/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,25 @@ function fancyConsoleLog(text) {
console.log('%c' + text, tpl + 'white');
}

export {capitalize, icaseEqual, icaseIncludes, getElementTextContent, getFirstElementByClassname, getMetaTag, setMetaContent, fancyConsoleLog};
/**
* @param {string} cssData
* @returns {HTMLStyleElement}
*/
function loadCss(cssData) {
const style = document.createElement("style");
document.getElementsByTagName("head")[0].appendChild(style);
style.appendChild(document.createTextNode(cssData));
return style;
}

export {
capitalize,
fancyConsoleLog,
getElementTextContent,
getFirstElementByClassname,
getMetaTag,
icaseEqual,
icaseIncludes,
loadCss,
setMetaContent,
};
5 changes: 2 additions & 3 deletions src/js/integrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import IntegrationsService from "./integrations/IntegrationsService";
import StepListSection from "./integrations/StepListSection";
import SidebarSection from "./integrations/SidebarSection";
import { fancyConsoleLog } from "./common";
import { loadCss } from "./common";

const style = document.createElement("style");
document.getElementsByTagName("head")[0].appendChild(style);
style.appendChild(document.createTextNode(require("../css/integrations.css")));
loadCss(require("../css/integrations.css"));

const url = new URL(document.location.href);
const platformFilter = url.searchParams.get("platform");
Expand Down

0 comments on commit 7720f2d

Please sign in to comment.