code cosmetics: entry id prefix => named constant

This commit is contained in:
tophf 2017-06-27 23:13:11 +03:00
parent 65d625fddf
commit 1aa5c11b10
2 changed files with 18 additions and 12 deletions

View File

@ -7,6 +7,9 @@ const filtersSelector = {
unhide: '',
};
const ENTRY_ID_PREFIX_RAW = 'style-';
const ENTRY_ID_PREFIX = '#' + ENTRY_ID_PREFIX_RAW;
const newUI = {
enabled: prefs.get('manage.newUI'),
favicons: prefs.get('manage.newUI.favicons'),
@ -175,7 +178,7 @@ function createStyleElement({style, name}) {
parts.homepage.href = parts.homepage.title = style.url || '';
const entry = parts.entry.cloneNode(true);
entry.id = 'style-' + style.id;
entry.id = ENTRY_ID_PREFIX_RAW + style.id;
entry.styleId = style.id;
entry.styleNameLowerCase = name || style.name.toLocaleLowerCase();
entry.styleMeta = getStyleWithNoCode(style);
@ -400,7 +403,7 @@ Object.assign(handleEvent, {
function handleUpdate(style, {reason, method} = {}) {
let entry;
let oldEntry = $('#style-' + style.id);
let oldEntry = $(ENTRY_ID_PREFIX + style.id);
if (oldEntry && method == 'styleUpdated') {
handleToggledOrCodeOnly();
}
@ -449,7 +452,7 @@ function handleUpdate(style, {reason, method} = {}) {
function handleDelete(id) {
const node = $('#style-' + id);
const node = $(ENTRY_ID_PREFIX + id);
if (node) {
node.remove();
if (node.matches('.can-update')) {
@ -519,7 +522,7 @@ function switchUI({styleOnly} = {}) {
if (missingFavicons) {
getStylesSafe().then(styles => {
for (const style of styles) {
const entry = $('#style-' + style.id);
const entry = $(ENTRY_ID_PREFIX + style.id);
if (entry) {
createStyleTargetsElement({entry, style, postponeFavicons: true});
}
@ -621,7 +624,7 @@ function checkUpdate(entry, {single = true} = {}) {
function reportUpdateState(state, style, details) {
const entry = $('#style-' + style.id);
const entry = $(ENTRY_ID_PREFIX + style.id);
entry.classList.remove('checking-update');
switch (state) {
case BG.updater.UPDATED:

View File

@ -5,6 +5,9 @@ let installed;
let tabURL;
const handleEvent = {};
const ENTRY_ID_PREFIX_RAW = 'style-';
const ENTRY_ID_PREFIX = '#' + ENTRY_ID_PREFIX_RAW;
getActiveTabRealURL().then(url => {
tabURL = URLS.supported.test(url) ? url : '';
Promise.all([
@ -215,7 +218,7 @@ function createStyleElement({
const entry = template.style.cloneNode(true);
entry.setAttribute('style-id', style.id);
Object.assign(entry, {
id: 'style-' + style.id,
id: ENTRY_ID_PREFIX_RAW + style.id,
styleId: style.id,
className: entry.className + ' ' + (style.enabled ? 'enabled' : 'disabled'),
onmousedown: handleEvent.maybeEdit,
@ -223,7 +226,7 @@ function createStyleElement({
const checkbox = $('.checker', entry);
Object.assign(checkbox, {
id: 'style-' + style.id,
id: ENTRY_ID_PREFIX_RAW + style.id,
checked: style.enabled,
onclick: handleEvent.toggle,
});
@ -236,7 +239,7 @@ function createStyleElement({
const styleName = $('.style-name', entry);
Object.assign(styleName, {
htmlFor: 'style-' + style.id,
htmlFor: ENTRY_ID_PREFIX_RAW + style.id,
onclick: handleEvent.name,
});
styleName.checkbox = checkbox;
@ -248,7 +251,7 @@ function createStyleElement({
invokeOrPostpone(!postponeDetect, detectSloppyRegexps, {entry, style});
const oldElement = $('#style-' + style.id);
const oldElement = $(ENTRY_ID_PREFIX + style.id);
if (oldElement) {
oldElement.parentNode.replaceChild(entry, oldElement);
} else {
@ -368,7 +371,7 @@ Object.assign(handleEvent, {
function handleUpdate(style) {
if ($('#style-' + style.id)) {
if ($(ENTRY_ID_PREFIX + style.id)) {
createStyleElement({style});
return;
}
@ -381,7 +384,7 @@ function handleUpdate(style) {
function handleDelete(id) {
$$('#style-' + id).forEach(el => el.remove());
$$(ENTRY_ID_PREFIX + id).forEach(el => el.remove());
}