Bug 1573473 - Creates global function to make strings kebab-case. r=johannh

Differential Revision: https://phabricator.services.mozilla.com/D41818

--HG--
extra : moz-landing-system : lando
This commit is contained in:
dleblanccyr 2019-08-19 19:44:34 +00:00
Родитель 526e469d17
Коммит d024456be2
4 изменённых файлов: 18 добавлений и 10 удалений

Просмотреть файл

@ -5,6 +5,7 @@
import { updateSelectedItem } from "../certviewer.js";
import { InfoGroup } from "./info-group.js";
import { ErrorSection } from "./error-section.js";
import { normalizeToKebabCase } from "../utils.js";
class CertificateSection extends HTMLElement {
constructor(certs, error) {
@ -125,7 +126,7 @@ class CertificateSection extends HTMLElement {
createTabSection(tabName, i, certificateTabs) {
let tab = document.createElement("button");
tab.textContent = tabName;
tab.setAttribute("id", "tab" + i);
tab.setAttribute("id", normalizeToKebabCase(tabName));
tab.setAttribute("aria-controls", "panel" + i);
tab.setAttribute("idnumber", i);
tab.setAttribute("role", "tab");

Просмотреть файл

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { InfoItem } from "./info-item.js";
import { normalizeToKebabCase } from "../utils.js";
export class InfoGroup extends HTMLElement {
constructor(item) {
@ -24,9 +25,7 @@ export class InfoGroup extends HTMLElement {
// Adds a class with the section title's name, to make
// it easier to find when highlighting errors.
this.classList.add(
this.item.sectionTitle.replace(/\s+/g, "-").toLowerCase()
);
this.classList.add(normalizeToKebabCase(this.item.sectionTitle));
for (let i = 0; i < this.item.sectionItems.length; i++) {
this.shadowRoot.append(new InfoItem(this.item.sectionItems[i]));

Просмотреть файл

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { normalizeToKebabCase } from "../utils.js";
export class InfoItem extends HTMLElement {
constructor(item) {
super();
@ -23,12 +25,7 @@ export class InfoItem extends HTMLElement {
render() {
let label = this.shadowRoot.querySelector("label");
let labelText = this.item.label
.replace(/\s+/g, "-")
.replace(/\./g, "")
.replace(/\//g, "")
.replace(/--/g, "-")
.toLowerCase();
let labelText = normalizeToKebabCase(this.item.label);
label.setAttribute("data-l10n-id", "certificate-viewer-" + labelText);
this.classList.add(labelText);

Просмотреть файл

@ -57,3 +57,14 @@ export const hashify = hash => {
export const pemToDER = pem => {
return stringToArrayBuffer(window.atob(pem));
};
export const normalizeToKebabCase = string => {
let kebabString = string
.replace(/\s+/g, "-")
.replace(/\./g, "")
.replace(/\//g, "")
.replace(/--/g, "-")
.toLowerCase();
return kebabString;
};