Skip to content

Commit da620d7

Browse files
authored
fix(demo): Change submit button text to say Open Permalink (#308)
1 parent 33ce03b commit da620d7

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/demo/index.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// Get the keys of the first value in the translations array
66
$LOCALES = array_keys($TRANSLATIONS);
77

8+
$darkmode = $_COOKIE["darkmode"] ?? null;
9+
810
/**
911
* Convert a camelCase string to a skewer-case string
1012
* @param string $str The camelCase string
@@ -58,7 +60,7 @@ function gtag() {
5860
<script async defer src="https://buttons.github.io/buttons.js"></script>
5961
</head>
6062

61-
<body <?php echo ($_COOKIE["darkmode"] ?? null) == "on" ? 'data-theme="dark"' : ""; ?>>
63+
<body <?php echo $darkmode === "on" ? 'data-theme="dark"' : ""; ?>>
6264
<h1>🔥 GitHub Readme Streak Stats</h1>
6365

6466
<!-- GitHub badges/links section -->
@@ -76,10 +78,10 @@ function gtag() {
7678
<h2>Properties</h2>
7779
<form class="parameters">
7880
<label for="user">Username<span title="required">*</span></label>
79-
<input class="param" type="text" id="user" name="user" placeholder="DenverCoder1" required pattern="^[A-Za-z\d-]{0,39}[A-Za-z\d]$" title="Up to 40 letters or hyphens but not ending with hyphen">
81+
<input class="param" type="text" id="user" name="user" placeholder="DenverCoder1" pattern="^[A-Za-z\d-]{0,39}[A-Za-z\d]$" title="Up to 40 letters or hyphens but not ending with hyphen">
8082

8183
<label for="theme">Theme</label>
82-
<select class="param" id="theme" name="theme" placeholder="default">
84+
<select class="param" id="theme" name="theme">
8385
<?php foreach ($THEMES as $theme => $options): ?>
8486
<?php
8587
$dataAttrs = "";
@@ -97,7 +99,7 @@ function gtag() {
9799
</select>
98100

99101
<label for="hide_border">Hide Border</label>
100-
<select class="param" id="hide_border" name="hide_border" placeholder="false">
102+
<select class="param" id="hide_border" name="hide_border">
101103
<option>false</option>
102104
<option>true</option>
103105
</select>
@@ -127,7 +129,7 @@ function gtag() {
127129
<summary>⚙ Advanced Options</summary>
128130
<div class="content parameters">
129131
<label for="theme">Add Property</label>
130-
<select id="properties" name="properties" placeholder="background">
132+
<select id="properties" name="properties">
131133
<?php foreach ($THEMES["default"] as $option => $color): ?>
132134
<option><?php echo $option; ?></option>
133135
<?php endforeach; ?>
@@ -136,10 +138,9 @@ function gtag() {
136138
</div>
137139
<button class="btn" type="button" onclick='return preview.exportPhp()'>Export to PHP</button>
138140
<textarea id="exportedPhp" hidden></textarea>
139-
140141
</details>
141142

142-
<input class="btn" type="submit" value="Submit">
143+
<input class="btn" type="submit" value="Open Permalink">
143144
</form>
144145
</div>
145146

@@ -175,7 +176,7 @@ function gtag() {
175176
</div>
176177

177178
<a href="javascript:toggleTheme()" class="darkmode" title="toggle dark mode">
178-
<i class="<?php echo ($_COOKIE["darkmode"] ?? null) == "on" ? "gg-sun" : "gg-moon"; ?>"></i>
179+
<i class="<?php echo $darkmode === "on" ? "gg-sun" : "gg-moon"; ?>"></i>
179180
</a>
180181
</body>
181182

src/demo/js/script.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ const preview = {
1919
// get parameter values from all .param elements
2020
const params = this.objectFromElements(document.querySelectorAll(".param"));
2121
// convert parameters to query string
22-
const encode = encodeURIComponent;
2322
const query = Object.keys(params)
2423
.filter((key) => params[key] !== this.defaults[key])
25-
.map((key) => encode(key) + "=" + encode(params[key]))
24+
.map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
2625
.join("&");
2726
// generate links and markdown
2827
const imageURL = `${window.location.origin}?${query}`;
@@ -35,7 +34,7 @@ const preview = {
3534
document.querySelector(".md code").innerText = md;
3635
// disable copy button if username is invalid
3736
const copyButton = document.querySelector(".copy-button");
38-
copyButton.disabled = Boolean(document.querySelectorAll("#user:invalid").length);
37+
copyButton.disabled = Boolean(document.querySelector("#user:invalid") || !document.querySelector("#user").value);
3938
},
4039

4140
/**
@@ -154,7 +153,7 @@ const preview = {
154153
const params = { ...defaultParams, ...advancedParams };
155154
// convert parameters to PHP code
156155
const mappings = Object.keys(params)
157-
.map((key) => ` "${key}" => "#${params[key]}",`)
156+
.map((key) => ` "${key}" => "#${params[key]}",`)
158157
.join("\n");
159158
const output = `[\n${mappings}\n]`;
160159
// set the textarea value to the output

0 commit comments

Comments
 (0)