Ajoute la gestion primaire des images

Pour #4
This commit is contained in:
2020-03-05 17:40:24 +01:00
parent 9a30d17fe0
commit ac5afa42e3
5 changed files with 99 additions and 7 deletions

21
resources/js/app.js vendored
View File

@@ -28,6 +28,7 @@ window.Vue = require('vue');
*/
import App from './components/App.vue';
Vue.config.productionTip = false;
/** Function for collapse card */
@@ -41,6 +42,26 @@ document.querySelectorAll('[data-toggle="card-collapse"]').forEach(function(card
});
});
let fileNameChanged = function(element, label) {
let labelVal = label.innerText;
let fileName = '';
if (element.value) {
fileName = element.value.split('\\').pop();
}
if (fileName) {
label.firstChild.nextSibling.classList = "fe fe-check";
label.querySelector('.js-fileName').innerHTML = fileName;
} else {
label.firstChild.nextSibling.classList = "fe fe-upload";
label.querySelector('.js-fileName').innerHTML = labelVal;
}
};
let inputFiles = document.querySelectorAll(".input-file");
for (let i = 0, l = inputFiles.length; i < l; i++) {
inputFiles[i].onchange = fileNameChanged.bind(null, inputFiles[i], inputFiles[i].nextSibling.nextSibling);
}
// new Vue();
const app = new Vue({
render: h => h(App),
}).$mount('#app');

View File

@@ -12,3 +12,36 @@ h1, h2, h3, h4 {
color: #6e7687;
}
}
.btn-tertiary {
color: #555;
padding: 0;
line-height: 40px;
width: 300px;
margin: auto;
display: block;
border: 2px solid #555;
&:hover,
&:focus {
color: lighten(#555, 20%);
border-color: lighten(#555, 20%);
}
}
/* input file style */
.input-file {
width: 0.1px;
height: 0.1px;
opacity: 0;
overflow: hidden;
position: absolute;
z-index: -1;
+ .js-labelFile {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
padding: 0 10px;
cursor: pointer;
}
}

View File

@@ -88,7 +88,7 @@
<h3 class="card-title">{{ strftime('%B %G', $today->format('U')) }}</h3>
</div>
<div class="card-body">
<form action="@if($already) {{ url('edit') }}@else{{ url('store') }}@endif" method="post" accept-charset="utf-8">
<form action="@if($already) {{ url('edit') }}@else{{ url('store') }}@endif" method="post" accept-charset="utf-8" enctype="multipart/form-data">
@csrf
<div class="contact-form">
<div class="form-group">
@@ -96,6 +96,11 @@
<div class="col-sm-10">
<div id="app"></div>
<span class="text-danger">{{ $errors->first('message') }}</span>
<input type="file" name="file" id="file" class="input-file">
<label for="file" class="btn btn-tertiary js-labelFile">
<i class="fe fe-upload"></i>
<span class="js-fileName">Choose a file</span>
</label>
</div>
</div>
<div class="form-group">
@@ -128,6 +133,7 @@
</div>
</div>
<div class="card-body @if($today->format('Y-m-d') === \Carbon\Carbon::instance($post->date_post)->format('Y-m-d')) already @endif ">
@if($post->image != '')<p><img src="{{ Auth::user()->getImageData($post) }}"/></p>@endif
{!! $tag_detector->linkTagFrom($post->content) !!}
</div>
<div class="card-footer">