working state
This commit is contained in:
parent
d69b8aad67
commit
814adbd334
@ -74,7 +74,7 @@
|
|||||||
|
|
||||||
<footer class="footer">
|
<footer class="footer">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<p>Pastes will be stored for 2 hours only.</p>
|
<p>Pastes are stored for 2 hours only. © 2025 Walzen665</p>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
|
@ -20,7 +20,10 @@ $(document).ready(function() {
|
|||||||
html: `
|
html: `
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 3H3C1.89 3 1 3.89 1 5V19C1 20.11 1.89 21 3 21H21C22.11 21 23 20.11 23 19V5C23 3.89 22.11 3 21 3Z"></path><path d="M7 8L12 13L17 8"></path></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 3H3C1.89 3 1 3.89 1 5V19C1 20.11 1.89 21 3 21H21C22.11 21 23 20.11 23 19V5C23 3.89 22.11 3 21 3Z"></path><path d="M7 8L12 13L17 8"></path></svg>
|
||||||
Format JSON
|
Format JSON
|
||||||
`
|
`,
|
||||||
|
css: {
|
||||||
|
display: $languageSelector.val() === 'json' ? 'inline-flex' : 'none'
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.controls').prepend($formatJsonBtn);
|
$('.controls').prepend($formatJsonBtn);
|
||||||
@ -164,6 +167,7 @@ $(document).ready(function() {
|
|||||||
const detectedLanguage = detectContentType($editor.val());
|
const detectedLanguage = detectContentType($editor.val());
|
||||||
if (detectedLanguage === 'json') {
|
if (detectedLanguage === 'json') {
|
||||||
$languageSelector.val('json');
|
$languageSelector.val('json');
|
||||||
|
$formatJsonBtn.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,10 +249,14 @@ $(document).ready(function() {
|
|||||||
window.history.pushState({}, '', '/'); // Reset URL to homepage
|
window.history.pushState({}, '', '/'); // Reset URL to homepage
|
||||||
$editorContainer.removeClass('viewer-active');
|
$editorContainer.removeClass('viewer-active');
|
||||||
$languageSelector.val('javascript');
|
$languageSelector.val('javascript');
|
||||||
|
$formatJsonBtn.hide(); // Hide JSON button when switching to new paste with JavaScript
|
||||||
});
|
});
|
||||||
|
|
||||||
// Language change
|
// Language change
|
||||||
$languageSelector.on('change', () => {
|
$languageSelector.on('change', () => {
|
||||||
|
// Toggle Format JSON button visibility based on language selection
|
||||||
|
$formatJsonBtn.toggle($languageSelector.val() === 'json');
|
||||||
|
|
||||||
if ($editorContainer.hasClass('viewer-active')) {
|
if ($editorContainer.hasClass('viewer-active')) {
|
||||||
$viewer.attr('class', `language-${$languageSelector.val()}`);
|
$viewer.attr('class', `language-${$languageSelector.val()}`);
|
||||||
hljs.highlightElement($viewer[0]);
|
hljs.highlightElement($viewer[0]);
|
||||||
@ -264,20 +272,16 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
// Format JSON handler
|
// Format JSON handler
|
||||||
$formatJsonBtn.on('click', () => {
|
$formatJsonBtn.on('click', () => {
|
||||||
if ($languageSelector.val() === 'json') {
|
try {
|
||||||
try {
|
const parsed = JSON.parse($editor.val());
|
||||||
const parsed = JSON.parse($editor.val());
|
const formatted = JSON.stringify(parsed, null, 2);
|
||||||
const formatted = JSON.stringify(parsed, null, 2);
|
$editor.val(formatted);
|
||||||
$editor.val(formatted);
|
$viewer.text(formatted);
|
||||||
$viewer.text(formatted);
|
hljs.highlightElement($viewer[0]);
|
||||||
hljs.highlightElement($viewer[0]);
|
updateLineNumbers();
|
||||||
updateLineNumbers();
|
showNotification('JSON formatted successfully!', 'success');
|
||||||
showNotification('JSON formatted successfully!', 'success');
|
} catch (e) {
|
||||||
} catch (e) {
|
showNotification('Invalid JSON: ' + e.message, 'error');
|
||||||
showNotification('Invalid JSON: ' + e.message, 'error');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
showNotification('Select JSON language first', 'error');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user