Skip to content

Commit efaa26f

Browse files
committed
explain newStyleAs switching
1 parent 9e8bdfc commit efaa26f

File tree

6 files changed

+24
-6
lines changed

6 files changed

+24
-6
lines changed

src/_locales/en/messages.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,9 @@
10121012
"newStyleAsUserCSS": {
10131013
"message": "Write new style as UserCSS"
10141014
},
1015+
"newStyleAsUserCSSHint": {
1016+
"message": "Toggling the option also switches the current style in the editor if it's new, i.e. just created and not edited or saved yet."
1017+
},
10151018
"noStylesForSite": {
10161019
"message": "No styles installed for this site.",
10171020
"description": "Text displayed when no styles are installed for the current site"
@@ -1524,7 +1527,8 @@
15241527
"description": "Label for the button to restore a removed section"
15251528
},
15261529
"sectionUserCSS": {
1527-
"message": "The classic sectioned editor doesn't support UserCSS syntax. To use it, enable the UserCSS checkbox first in the manager or the popup and then make a new style, then copy your current code by clicking the Export button in this editor."
1530+
"message": "The sectioned editor doesn't support UserCSS syntax.\nYou can use it in a new style:\n1. click the Export button in this editor, copy the text,\n2. create a new style in the style manager or the popup,\n3. enable \"[x] $optUserCSS\",\n4. paste the copied text overwriting the default template,\n5. save the new style, disable or remove the old style.",
1531+
"description": "1) Preserve line breaks for readability. 2) $optUserCSS is replaced with the label of the option e.g. \"[x] Write new style as UserCSS\""
15281532
},
15291533
"sections": {
15301534
"message": "Sections",

src/edit.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ <h1 class="ellipsis"></h1>
3030
href="https://github.com/openstyles/stylus/wiki/Writing-styles">
3131
<i class=i-info></i>
3232
</a>
33-
<a class="usercss-only icon" target="_blank" i18n="title:externalUsercssDocument"
34-
href="https://github.com/openstyles/stylus/wiki/Writing-UserCSS">
33+
<a class="usercss-only icon" target="_blank" id="usercss-docs">
3534
<i class=i-usercss style="font-size: 16px"></i>
3635
</a>
3736
</div>
@@ -46,6 +45,9 @@ <h1 class="ellipsis"></h1>
4645
<label id="new-as" class="hide-if-sticky flex">
4746
<input type="checkbox" id="newStyleAsUsercss">
4847
<span i18n="newStyleAsUserCSS"></span>
48+
<a class=icon tabindex="0" data-cmd="note" style="margin-top: -2px">
49+
<i class=i-info></i>
50+
</a>
4951
</label>
5052
<label id="enabled-label" class="hide-if-sticky"
5153
i18n="+styleEnabledLabel, title:toggleStyle"

src/edit/compact-header.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {$create} from '@/js/dom';
22
import {mqCompact} from '@/js/dom-init';
33
import {important} from '@/js/dom-util';
44
import {template} from '@/js/localization';
5+
import {t} from '@/js/util';
56
import editor from './editor';
67

78
const h = template.body.$('#header');
@@ -24,11 +25,17 @@ export default function CompactHeader() {
2425
const xo = new IntersectionObserver(onScrolled, {root: xoRoot});
2526
const elNewAs = $('#new-as');
2627
const elInfo = [...$$('#heading a')];
28+
const hint = t('newStyleAsUserCSSHint');
29+
const elDocs = $('#usercss-docs');
30+
const docs = elDocs.title = t('externalUsercssDocument');
31+
const docsUrl = elDocs.href = 'https://github.com/openstyles/stylus/wiki/Writing-UserCSS';
2732
elNewAs.on('click', () => {
2833
if (!editor.style.id && !editor.dirty.isDirty()) {
2934
location.reload();
3035
}
3136
});
37+
elNewAs.$('a').title = `${docs}:\n${docsUrl}\n${hint}`;
38+
elNewAs.$('a').dataset.title = `<a href="${docsUrl}">${docs}</a>\n\n${hint}`;
3239
scroller.appendChild(elHeader);
3340
mqCompact(val => {
3441
if (val) {

src/edit/sections-editor-section.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {setupLivePrefs} from '@/js/dom-util';
44
import {templateCache, htmlToTemplate, template} from '@/js/localization';
55
import * as prefs from '@/js/prefs';
66
import {FROM_CSS, TO_CSS} from '@/js/sections-util';
7-
import {debounce} from '@/js/util';
7+
import {debounce, t} from '@/js/util';
88
import {CodeMirror} from '@/cm';
99
import {C_CONTAINER, C_ITEM, C_LIST, C_TYPE, C_VALUE, iconize} from './applies-to';
1010
import {initBeautifyButton} from './beautify';
@@ -15,6 +15,7 @@ import {htmlEditorSettings} from './settings';
1515
import {helpPopup, htmlAppliesTo, trimCommentLabel} from './util';
1616

1717
const RX_META1 = /^!?\s*==userstyle==\s*$/i;
18+
let tplUsercssSection;
1819

1920
export default class EditorSection {
2021
/**
@@ -183,7 +184,10 @@ export default class EditorSection {
183184
if (cmt && RX_META1.test(text)) {
184185
if (elUC) elUC = null;
185186
else {
186-
this.elLabelText.after(elUC = this.elUC = templateCache.usercssSection.cloneNode(true));
187+
tplUsercssSection ??= Object.assign(templateCache.usercssSection, {
188+
title: t('sectionUserCSS', t('newStyleAsUserCSS')),
189+
});
190+
this.elLabelText.after(elUC = this.elUC = tplUsercssSection.cloneNode(true));
187191
}
188192
} else if (elUC) {
189193
elUC.remove();

src/edit/sections-editor.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@
2525
</template>
2626

2727
<template data-id="usercssSection">
28-
<a data-cmd="note" i18n="title:sectionUserCSS" class="icon"><i class=i-info></i></a>
28+
<a data-cmd="note" class="icon"><i class=i-info></i></a>
2929
</template>

src/js/dom-on-load.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ function showTooltipNote(event) {
213213
const note = event.target.closest('[data-cmd=note]');
214214
if (note) {
215215
event.preventDefault();
216+
event.stopPropagation();
216217
const internal = note.dataset.title;
217218
const text = internal || tooltips.get(note) || note.title;
218219
messageBox.show({

0 commit comments

Comments
 (0)