Skip to content

Commit 5b4b6cb

Browse files
committed
Change the UI for new line options from a button group to a dropdown
1 parent a514492 commit 5b4b6cb

File tree

8 files changed

+37
-17
lines changed

8 files changed

+37
-17
lines changed

src/main/java/com/dencode/web/servlet/pages/DencodeServlet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private static class DencodeRequest {
4646

4747

4848
private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
49-
private static final String DEFAULT_LINE_BREAK = "\r\n";
49+
private static final String DEFAULT_LINE_BREAK = "\n";
5050
private static final ZoneId DEFAULT_ZONE_ID = ZoneId.of("UTC");
5151

5252

src/main/java/com/dencode/web/servlet/pages/IndexServlet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ protected void doGet() throws Exception {
110110
String v = reqres().param("v", "");
111111
String oe = "UTF-8";
112112
String oex = message("oe.ext.default");
113-
String nl = "crlf";
113+
String nl = "lf";
114114
String tz = "UTC";
115115

116116
String type = reqres().attribute("type");

src/main/resources/messages_en.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ label.val.length.chars=chars
792792
label.val.length.byte=byte
793793
label.val.length.bytes=bytes
794794

795+
label.newline=Newline
795796
label.timeZone=TimeZone
796797

797798
label.encoded=Encoded

src/main/resources/messages_ja.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ label.val.length.chars=文字
792792
label.val.length.byte=バイト
793793
label.val.length.bytes=バイト
794794

795+
label.newline=改行
795796
label.timeZone=タイムゾーン
796797

797798
label.encoded=エンコード結果

src/main/resources/messages_ru.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ label.val.length.chars=персонажа
792792
label.val.length.byte=байт
793793
label.val.length.bytes=байтов
794794

795+
label.newline=Разрыв линии
795796
label.timeZone=Часовой пояс
796797

797798
label.encoded=Закодировано

src/main/webapp/WEB-INF/pages/index.jsp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,15 @@
316316
</ul>
317317
</div>
318318
<div id="nlGroup" class="btn-group btn-group-sm" data-default-value="${dc:h(nl)}" style="display: none;">
319-
<button class="btn" data-nl="crlf">CRLF (Win)</button>
320-
<button class="btn" data-nl="lf">LF (UNIX/Mac)</button>
321-
<button class="btn" data-nl="cr">CR (Old Mac)</button>
319+
<button class="btn dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-label="${dc:h(msg['label.newline'])}" aria-expanded="false">
320+
<span id="nl" data-nl=""></span>
321+
<span class="caret"></span>
322+
</button>
323+
<div id="nlMenu" class="dropdown-menu" role="menu">
324+
<span class="dropdown-item" data-nl="lf" tabindex="0">LF (\n)</span>
325+
<span class="dropdown-item" data-nl="crlf" tabindex="0">CRLF (\r\n)</span>
326+
<span class="dropdown-item" data-nl="cr" tabindex="0">CR (\r)</span>
327+
</div>
322328
</div>
323329
<div id="tzGroup" class="btn-group btn-group-sm" data-default-value="${dc:h(tz)}" style="display: none;">
324330
<button class="btn dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-label="${dc:h(msg['label.timeZone'])}" aria-expanded="false">

src/main/webapp/static/css/main.css

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ footer a, footer a:link, footer a:visited, footer a:hover, footer a:active {
193193

194194
.btn-group-sm .btn {
195195
--bs-btn-padding-y: 1px;
196-
--bs-btn-padding-x: 5px;
196+
--bs-btn-padding-x: 1ex;
197197
--bs-btn-font-size: 0.8rem;
198198
}
199199
.btn-group-sm .dropdown-menu {
@@ -349,7 +349,11 @@ footer a, footer a:link, footer a:visited, footer a:hover, footer a:active {
349349
}
350350

351351
#expOptions {
352-
padding: 1px 0;
352+
padding: 2px 0 0;
353+
}
354+
355+
#expOptions .btn-group:not(:last-child) {
356+
margin-right: 1.2ex;
353357
}
354358

355359
#follow {

src/main/webapp/static/js/main.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ $.onReady(function () {
4343
const elOexBtn = $.id("oex");
4444
const elOexMenu = $.id("oexMenu");
4545
const elOexMenuItems = $.all("#oexMenu .dropdown-item");
46+
const elNl = $.id("nl");
4647
const elNlGroup = $.id("nlGroup");
47-
const elNlGroupBtns = $.all("#nlGroup .btn");
48+
const elNlMenuItems = $.all("#nlMenu [data-nl]");
4849
const elTz = $.id("tz");
4950
const elTzGroup = $.id("tzGroup");
5051
const elTzMenuItems = $.all("#tzMenuItems [data-tz]");
@@ -76,7 +77,7 @@ $.onReady(function () {
7677

7778
elOexBtn.setAttribute("data-oe", selectItem(elOexMenuItems, elOexMenu, "oe", "oex"));
7879
selectItem(elOeGroupBtns, elOeGroup, "oe", "oe");
79-
selectItem(elNlGroupBtns, elNlGroup, "nl", "nl");
80+
elNl.setAttribute("data-nl", selectItem(elNlMenuItems, elNlGroup, "nl", "nl"));
8081
elTz.setAttribute("data-tz", selectItem(elTzMenuItems, elTzGroup, "tz", "tz"));
8182

8283
elOptions.forEach((el) => {
@@ -212,16 +213,22 @@ $.onReady(function () {
212213
}
213214

214215
if (dencoderDefs[dencodeMethod].useNl) {
216+
let elNlMenuItem = elNlMenuItems.find((el) => el.classList.contains("active"));
217+
if (!elNlMenuItem) {
218+
elNlMenuItem = elNlMenuItems[0];
219+
}
220+
elNl.textContent = elNlMenuItem.textContent;
221+
elNl.setAttribute("data-nl", elNlMenuItem.getAttribute("data-nl"));
222+
215223
elNlGroup.style.display = "";
216224

217-
$.on(elNlGroupBtns, "click", function () {
218-
if (this.classList.contains("active")) {
219-
return;
220-
}
221-
222-
elNlGroupBtns.forEach((el) => el.classList.remove("active"));
225+
$.on(elNlMenuItems, "click", function () {
226+
elNlMenuItems.forEach((el) => el.classList.remove("active"));
223227
this.classList.add("active");
224228

229+
elNl.textContent = this.textContent;
230+
elNl.setAttribute("data-nl", this.getAttribute("data-nl"));
231+
225232
dencode();
226233
});
227234
}
@@ -775,7 +782,7 @@ $.onReady(function () {
775782
const v = elV.value;
776783
const oe = elOeGroupBtns.find((el) => el.classList.contains("active"))?.getAttribute("data-oe");
777784
const oex = elOexMenuItems.find((el) => el.classList.contains("active"))?.getAttribute("data-oe");
778-
const nl = elNlGroupBtns.find((el) => el.classList.contains("active"))?.getAttribute("data-nl");
785+
const nl = elNl.getAttribute("data-nl");
779786
const tz = elTz.getAttribute("data-tz");
780787
let options = {};
781788
elOptions.forEach((el) => {
@@ -955,7 +962,7 @@ $.onReady(function () {
955962
url += "&oe=" + encodeURIComponent(oe);
956963
}
957964
if (dcDef === null || dcDef.useNl) {
958-
const nl = elNlGroupBtns.find((el) => el.classList.contains("active"))?.getAttribute("data-nl");
965+
const nl = elNl.getAttribute("data-nl");
959966
url += "&nl=" + encodeURIComponent(nl);
960967
}
961968
if (dcDef === null || dcDef.useTz) {

0 commit comments

Comments
 (0)