Preview Functionality
This commit is contained in:
104
resources/js/admin.js
vendored
104
resources/js/admin.js
vendored
@@ -1,30 +1,76 @@
|
||||
posts_edit_regexp = new RegExp("/admin/posts/\\d+/edit");
|
||||
now_edit_regexp = new RegExp("/admin/now/\\d+/edit");
|
||||
projects_edit_regexp = new RegExp("/admin/projects/\\d+/edit");
|
||||
setups_edit_regexp = new RegExp("/admin/setups/\\d+/edit");
|
||||
|
||||
if(
|
||||
window.location.pathname === "/admin/posts" ||
|
||||
window.location.pathname === "/admin/posts/create" ||
|
||||
window.location.pathname.match(posts_edit_regexp)
|
||||
){
|
||||
document.getElementById("posts-link").classList.add("menu-highlight");
|
||||
} else if(
|
||||
window.location.pathname === "/admin/now" ||
|
||||
window.location.pathname === "/admin/now/create" ||
|
||||
window.location.pathname.match(now_edit_regexp)
|
||||
){
|
||||
document.getElementById("now-link").classList.add("menu-highlight");
|
||||
} else if(
|
||||
window.location.pathname === "/admin/projects" ||
|
||||
window.location.pathname === "/admin/projects/create" ||
|
||||
window.location.pathname.match(projects_edit_regexp)
|
||||
){
|
||||
document.getElementById("projects-link").classList.add("menu-highlight");
|
||||
} else if(
|
||||
window.location.pathname === "/admin/setups" ||
|
||||
window.location.pathname === "/admin/setups/create" ||
|
||||
window.location.pathname.match(setups_edit_regexp)
|
||||
){
|
||||
document.getElementById("setup-link").classList.add("menu-highlight");
|
||||
function is_admin_post_route() {
|
||||
const posts_edit_regexp = new RegExp("/admin/posts/\\d+/edit");
|
||||
return (
|
||||
window.location.pathname === "/admin/posts" ||
|
||||
window.location.pathname === "/admin/posts/create" ||
|
||||
window.location.pathname.match(posts_edit_regexp)
|
||||
);
|
||||
}
|
||||
|
||||
function is_admin_now_route() {
|
||||
const now_edit_regexp = new RegExp("/admin/now/\\d+/edit");
|
||||
return (
|
||||
window.location.pathname === "/admin/now" ||
|
||||
window.location.pathname === "/admin/now/create" ||
|
||||
window.location.pathname.match(now_edit_regexp)
|
||||
);
|
||||
}
|
||||
|
||||
function is_admin_projects_route() {
|
||||
const projects_edit_regexp = new RegExp("/admin/projects/\\d+/edit");
|
||||
return (
|
||||
window.location.pathname === "/admin/projects" ||
|
||||
window.location.pathname === "/admin/projects/create" ||
|
||||
window.location.pathname.match(projects_edit_regexp)
|
||||
);
|
||||
}
|
||||
|
||||
function is_admin_setups_route() {
|
||||
const setups_edit_regexp = new RegExp("/admin/setups/\\d+/edit");
|
||||
return (
|
||||
window.location.pathname === "/admin/setups" ||
|
||||
window.location.pathname === "/admin/setups/create" ||
|
||||
window.location.pathname.match(setups_edit_regexp)
|
||||
);
|
||||
}
|
||||
|
||||
function admin_highlight() {
|
||||
if(is_admin_post_route()){
|
||||
document.getElementById("posts-link").classList.add("menu-highlight");
|
||||
}
|
||||
if(is_admin_now_route()){
|
||||
document.getElementById("now-link").classList.add("menu-highlight");
|
||||
}
|
||||
if(is_admin_projects_route()){
|
||||
document.getElementById("projects-link").classList.add("menu-highlight");
|
||||
}
|
||||
if(is_admin_setups_route()){
|
||||
document.getElementById("setup-link").classList.add("menu-highlight");
|
||||
}
|
||||
}
|
||||
|
||||
function preview() {
|
||||
const previewButton = document.getElementById("preview");
|
||||
const mainButton = document.getElementById("main");
|
||||
|
||||
if(previewButton == null){
|
||||
return;
|
||||
}
|
||||
|
||||
const form = document.getElementsByTagName("form")[0];
|
||||
|
||||
previewButton.addEventListener("click", (e) => {
|
||||
form.setAttribute("target", "_blank");
|
||||
});
|
||||
|
||||
mainButton.addEventListener("click", (e) => {
|
||||
form.removeAttribute("target");
|
||||
});
|
||||
}
|
||||
|
||||
function main() {
|
||||
admin_highlight();
|
||||
preview();
|
||||
}
|
||||
|
||||
window.onload = main;
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
<textarea id="md" name="md"></textarea>
|
||||
|
||||
<div class="control">
|
||||
<button type="submit" class="pure-button button-black-white">Create</button>
|
||||
<button class="pure-button button-black-white" name="action" id="preview" type="submit" value="preview">Preview</button>
|
||||
<button class="pure-button button-black-white" name="action" id="main" type="submit" value="create">Create</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
<textarea id="md" name="md">{{ old('md', $now->md) }}</textarea>
|
||||
|
||||
<div class="control">
|
||||
<button type="submit" class="pure-button button-black-white">Update</button>
|
||||
<button class="pure-button button-black-white" name="action" id="preview" type="submit" value="preview">Preview</button>
|
||||
<button class="pure-button button-black-white" name="action" id="main" type="submit" value="update">Update</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
<textarea id="md" name="md"></textarea>
|
||||
|
||||
<div class="control">
|
||||
<button class="pure-button button-black-white" type="submit">Create</button>
|
||||
<button class="pure-button button-black-white" name="action" id="preview" type="submit" value="preview">Preview</button>
|
||||
<button class="pure-button button-black-white" name="action" id="main" type="submit" value="create">Create</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
<textarea id="md" name="md">{{ old('md', $post->md) }}</textarea>
|
||||
|
||||
<div class="control">
|
||||
<button type="submit" class="pure-button button-black-white">Update</button>
|
||||
<button class="pure-button button-black-white" name="action" id="preview" type="submit" value="preview">Preview</button>
|
||||
<button class="pure-button button-black-white" name="action" id="main" type="submit" value="update">Update</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
14
resources/views/admin/preview.blade.php
Normal file
14
resources/views/admin/preview.blade.php
Normal file
@@ -0,0 +1,14 @@
|
||||
@extends('base')
|
||||
|
||||
@php
|
||||
$parse = new Parsedown();
|
||||
@endphp
|
||||
|
||||
@section('content')
|
||||
<article>
|
||||
<header>
|
||||
<h1 class="post-title">{{$title}}</h1>
|
||||
</header>
|
||||
{!! $parse->text($md) !!}
|
||||
</article>
|
||||
@endsection
|
||||
@@ -18,7 +18,8 @@
|
||||
<textarea id="md" name="md"></textarea>
|
||||
|
||||
<div class="control">
|
||||
<button class="pure-button button-black-white" type="submit">Create</button>
|
||||
<button class="pure-button button-black-white" name="action" id="preview" type="submit" value="preview">Preview</button>
|
||||
<button class="pure-button button-black-white" name="action" id="main" type="submit" value="create">Create</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
<textarea class="form-input" id="md" name="md">{{ old('md', $project->md) }}</textarea>
|
||||
|
||||
<div class="control">
|
||||
<button type="submit" class="pure-button button-black-white">Back</button>
|
||||
<button class="pure-button button-black-white" name="action" id="preview" type="submit" value="preview">Preview</button>
|
||||
<button class="pure-button button-black-white" name="action" id="main" type="submit" value="update">Update</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
<textarea id="md" name="md"></textarea>
|
||||
|
||||
<div class="control">
|
||||
<button class="pure-button button-black-white" type="submit">Create</button>
|
||||
<button class="pure-button button-black-white" name="action" id="preview" type="submit" value="preview">Preview</button>
|
||||
<button class="pure-button button-black-white" name="action" id="main" type="submit" value="create">Create</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
<textarea id="md" name="md">{{ old('md', $setup->md) }}</textarea>
|
||||
|
||||
<div class="control">
|
||||
<button type="submit" class="pure-button button-black-white">Update</button>
|
||||
<button class="pure-button button-black-white" name="action" id="preview" type="submit" value="preview">Preview</button>
|
||||
<button class="pure-button button-black-white" name="action" id="main" type="submit" value="update">Update</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user