-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4af11e
commit 994e61b
Showing
3 changed files
with
61 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,55 @@ | ||
<div class="p-4 flex gap-4"> | ||
<div class="w-1/2 flex flex-col"> | ||
<div class="flex gap-[1px] mb-2"> | ||
<button id="addHeading1" class="control-btn"> | ||
H1 | ||
</button> | ||
<button id="addHeading2" class="control-btn"> | ||
H2 | ||
</button> | ||
<button id="addHeading3" class="control-btn"> | ||
H3 | ||
</button> | ||
<button id="addParagraph" class="control-btn"> | ||
<i class="fas fa-paragraph"></i> P | ||
</button> | ||
<button id="addBold" class="control-btn"> | ||
<i class="fas fa-bold"></i> | ||
</button> | ||
<button id="addList" class="control-btn"> | ||
<i class="fas fa-list"></i> | ||
</button> | ||
<button id="addLink" class="control-btn"> | ||
<i class="fas fa-link"></i> | ||
</button> | ||
<button id="addImage" class="control-btn"> | ||
<i class="fas fa-image"></i> | ||
</button> | ||
<div class="hidden"> | ||
<input type="file" accept="image/*" id="image" wire:model="image"> | ||
</div> | ||
</div> | ||
<textarea | ||
id="content" | ||
wire:model.live="content" | ||
type="text" class="border w-full border-gray-300 p-2" | ||
rows="10"></textarea> | ||
<div> | ||
<div> | ||
<input wire:model="title" type="text" placeholder="Enter title"> | ||
@error('title') <span>{{ $message }}</span> @enderror | ||
</div> | ||
|
||
<!-- Preview --> | ||
<div class="w-1/2"> | ||
<h3>Preview:</h3> | ||
<div id="preview" class="markdown-content hidden text-black"> | ||
{{ $markdownContent }} | ||
</div> | ||
{{-- AS inner html | ||
--}} | ||
<div id="render" class="markdown-content-render text-black" wire:ignore> | ||
</div> | ||
<div> | ||
<div id="editor"></div> | ||
@error('content') <span>{{ $message }}</span> @enderror | ||
</div> | ||
</div> | ||
|
||
<script> | ||
document.getElementById('addHeading1').addEventListener('click', function () { | ||
addToContent("\n# H1 "); | ||
}); | ||
document.getElementById('addHeading2').addEventListener('click', function () { | ||
addToContent("\n## H2 "); | ||
}); | ||
document.getElementById('addHeading3').addEventListener('click', function () { | ||
addToContent("\n### H3 "); | ||
}); | ||
document.getElementById('addParagraph').addEventListener('click', function () { | ||
addToContent("\n"); | ||
}); | ||
document.getElementById('addBold').addEventListener('click', function () { | ||
addToContent("\n**bold text** "); | ||
}); | ||
document.getElementById('addList').addEventListener('click', function () { | ||
addToContent("\n- list item"); | ||
}); | ||
document.getElementById('addLink').addEventListener('click', function () { | ||
addToContent("\n[link text](url) "); | ||
}); | ||
document.getElementById('addImage').addEventListener('click', function () { | ||
document.getElementById('image').click(); | ||
setTimeout(() => { | ||
addToContent("\n![alt text](image_url) "); | ||
}, 100) | ||
}); | ||
<button id="save_button" class="btn">Save Blog</button> | ||
|
||
@script | ||
<script> | ||
const textArea = document.querySelector('#content'); | ||
const saveButton = document.querySelector('#save_button'); | ||
const toolbarOptions = [ | ||
['bold', 'italic', 'underline', 'strike'], // toggled buttons | ||
['blockquote', 'code-block'], | ||
function addToContent(text) { | ||
let contentElement = document.getElementById('content'); | ||
[{ 'header': 1 }, { 'header': 2 }, { 'header': 3 }], // custom button values | ||
[{ 'list': 'ordered'}, { 'list': 'bullet' }, { 'list': 'check' }], | ||
[{ 'script': 'sub'}, { 'script': 'super' }], // superscript/subscript | ||
[{ 'indent': '-1'}, { 'indent': '+1' }], // outdent/indent | ||
[{ 'direction': 'rtl' }], // text direction | ||
//if we have nothing remove the new line | ||
if (contentElement.value === '') { | ||
text = text.trim(); | ||
} | ||
[{ 'size': ['small', false, 'large', 'huge'] }], // custom dropdown | ||
[{ 'header': [1, 2, 3, 4, 5, 6, false] }], | ||
//if we have a previous list and we are adding a new item | ||
if (text.includes('-') && contentElement.value.endsWith('-')) { | ||
text = text.trim(); | ||
} | ||
[{ 'color': [] }, { 'background': [] }], // dropdown with defaults from theme | ||
[{ 'font': [] }], | ||
[{ 'align': [] }], | ||
contentElement.value += text; | ||
contentElement.dispatchEvent(new Event('input')); // To trigger Livewire update | ||
} | ||
['clean'] // remove formatting button | ||
]; | ||
// on content change | ||
document.getElementById('content').addEventListener('input', function () { | ||
setTimeout( | ||
function () { | ||
let content = document.getElementById('preview').innerText | ||
let render = document.getElementById('render'); | ||
render.innerHTML = content; | ||
}, 20 | ||
) | ||
}); | ||
</script> | ||
const quill = new Quill('#editor', { | ||
theme: 'snow', | ||
modules: { | ||
toolbar: toolbarOptions | ||
} | ||
}); | ||
saveButton.addEventListener('click', () => { | ||
@this. | ||
set('content', quill.root.innerHTML); | ||
@this. | ||
saveBlog(); | ||
}); | ||
</script> | ||
@endscript | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,8 @@ | |
|
||
<!-- Scripts --> | ||
@vite(['resources/css/app.css', 'resources/js/app.js']) | ||
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/quill.js"></script> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/quill.snow.css" rel="stylesheet"> | ||
</head> | ||
<body class="font-sans antialiased"> | ||
<div class="min-h-screen bg-white"> | ||
|
@@ -26,7 +26,7 @@ | |
<livewire:alerts/> | ||
<div class="flex relative z-40 gap-2 p-2"> | ||
<!-- Page Content --> | ||
<main class="w-full bg-gray-100 text-black/80 overflow-clip rounded-[16px]"> | ||
<main class="w-full bg-gray-100 p-4 text-black/80 overflow-clip rounded-[16px]"> | ||
{{ $slot }} | ||
</main> | ||
</div> | ||
|