Skip to content

Commit 7a5230b

Browse files
Ivan LiIvan Li
Ivan Li
authored and
Ivan Li
committed
file upload updated
1 parent fbf0e7e commit 7a5230b

File tree

2 files changed

+34
-99
lines changed

2 files changed

+34
-99
lines changed

public/assets/internal/js/html5_file_upload.js

Lines changed: 18 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -141,109 +141,30 @@ function renderImages(dirEntry) {
141141
readDirectory(dirEntry, function (entries) {
142142
// Handle no files case.
143143
if (!entries.length) {
144-
footer.textContent = 'Add some files chief!';
145-
footer.classList.add('nofiles');
146-
return;
144+
/* no files */
147145
}
148146

149-
footer.classList.remove('nofiles');
150-
151-
var frag = document.createDocumentFragment();
152-
153-
var span = document.createElement('span');
154-
span.innerHTML = '«';
155-
span.title = 'Move up a directory;';
156-
span.addEventListener('click', onThumbnailClick);
157-
frag.appendChild(span);
158-
159147
entries.forEach(function (entry, i) {
160148
var div = document.createElement('div');
161149

162150
div.dataset.fullPath = entry.fullPath;
151+
console.info('div.dataset.fullPath', div.dataset.fullPath);
163152

164153
var img = new Image();
165154
if (entry.isDirectory) {
166-
img.src = 'folder.png';
167-
div.dataset.isDirectory = 'true';
155+
/* it's a folder */
168156
} else {
169157
//img.src = window.URL.createObjectURL(files[i]); // Equivalent to item.getAsFile().
170158
entry.file(function (f) {
159+
console.info('entry.toURL()', entry.toURL());
171160
img.src = f.type.match('^image/') ? entry.toURL() : 'file.png';
161+
document.body.appendChild(img);
172162
}, onError);
173163
}
174164

175165
img.title = entry.name;
176166
img.alt = entry.name;
177-
178-
var span = document.createElement('span');
179-
span.textContent = entry.name;
180-
181-
var span2 = document.createElement('span');
182-
span2.textContent = 'X';
183-
span2.classList.add('close');
184-
span2.addEventListener('click', onClose);
185-
186-
div.appendChild(span2);
187-
div.appendChild(img);
188-
div.appendChild(span);
189-
div.addEventListener('click', onThumbnailClick);
190-
191-
frag.appendChild(div);
192-
});
193-
194-
footer.innerHTML = '';
195-
footer.appendChild(frag);
196-
});
197-
}
198-
199-
function onChange(e) {
200-
e.stopPropagation();
201-
e.preventDefault();
202-
203-
var entries = e.target.webkitEntries;
204-
205-
// Dragging and dropping into the file input works fine but onchange doesn't
206-
// populate .webkitEntries when selecting from the file dialog
207-
// (crbug.com/138987). Thus, we need to explicitly write out files.
208-
if (!entries.length) {
209-
var files = e.target.files;
210-
var numWritten = 0;
211-
212-
[].forEach.call(files, function (f, i) {
213-
if (f.type.match('^image/')) {
214-
writeFile(f, cwd, function (e) {
215-
if (++numWritten) {
216-
setLoadingTxt({txt: DONE_MSG + ' writing ' + files.length + ' files.'});
217-
renderImages(cwd);
218-
}
219-
});
220-
} else {
221-
setLoadingTxt({txt: NOT_IMG_MSG, error: true});
222-
}
223167
});
224-
return;
225-
}
226-
227-
[].forEach.call(entries, function (entry) {
228-
229-
if (entry.isDirectory) {
230-
setLoadingTxt({
231-
txt: 'Importing directory: ' + entry.name,
232-
stayOpen: true
233-
});
234-
} else {
235-
setLoadingTxt({
236-
txt: 'Importing file: ' + entry.name,
237-
stayOpen: true
238-
});
239-
}
240-
241-
// Copy entry over to the local filesystem.
242-
entry.copyTo(cwd, null, function (copiedEntry) {
243-
setLoadingTxt({txt: DONE_MSG});
244-
renderImages(cwd);
245-
}, onError);
246-
247168
});
248169
}
249170

@@ -262,33 +183,29 @@ function onDrop(e) {
262183

263184
var entry = item.webkitGetAsEntry();
264185
if (entry.isDirectory) {
265-
setLoadingTxt({
266-
txt: 'Importing directory: ' + entry.name,
267-
stayOpen: true
268-
});
269-
270-
// Copy the dropped DirectoryEntry over to our local filesystem.
271-
entry.copyTo(cwd, null, function (copiedEntry) {
272-
renderImages(cwd);
273-
}, onError);
186+
/* it's a folder */
274187
} else {
275188
if (entry.isFile && files[i].type.match('^image/')) {
276189
// Copy the dropped entry into local filesystem.
277190
entry.copyTo(cwd, null, function (copiedEntry) {
278191
renderImages(cwd);
279192
}, onError);
280193
} else {
281-
setLoadingTxt({txt: NOT_IMG_MSG, error: true});
194+
/* it's not an image */
282195
}
283196
}
284197
}
285198
}
286199

287-
function init() {
288-
$("#new-profile-pic").on("drop", function (e) {
289-
onDrop(e);
200+
function initFileDragDrop() {
201+
$(".lbl-new-profile-pic").on("drop", function (e) {
202+
onDrop(e.originalEvent);
203+
}).on("dragstart", function () {
204+
e.preventDefault();
205+
return false;
290206
}).on("dragover", function (e) {
291207
e.preventDefault();
208+
return false;
292209
}).on("dragenter", function (e) {
293210
e.target.classList.add('active');
294211
}).on("dragleave", function () {
@@ -302,3 +219,7 @@ function init() {
302219
renderImages(cwd);
303220
}, onError);
304221
}
222+
223+
$(function () {
224+
initFileDragDrop();
225+
});

resources/views/user/profile/edit.blade.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@
5959
</div>
6060
<div class="form-group">
6161
{!! Form::label('dob', 'Date of birth') !!}
62-
{!! Form::text('dob', old('dob'), ['class' => 'form-control input-sm', 'placeholder' => 'dob']) !!}
62+
<div class="input-icon datetime-pick date-only">
63+
{!! Form::text('dob', old('dob'), ['class' => 'form-control input-sm', 'placeholder' => 'dob']) !!}
64+
<span class="add-on">
65+
<i class="sa-plus icon-calendar"></i>
66+
</span>
67+
</div>
6368
</div>
6469
<div class="form-group">
6570
{!! Form::label('gender', 'Date of birth') !!} &nbsp;
@@ -111,10 +116,19 @@
111116
@stop
112117
@section('script')
113118
<script type="text/javascript" src="{{asset('assets/external/package/Cropper/cropper.min.js')}}"></script>
119+
<script type="text/javascript" src="{{asset('assets/external/sa/js/datetimepicker.min.js')}}"></script>
114120
<script type="text/javascript">
115121
var cropper = null;
116122
$(function () {
117-
123+
var $dateOnly = $(".date-only");
124+
if($dateOnly.length > 0) {
125+
$dateOnly.datetimepicker({
126+
pickTime: false
127+
});
128+
$('.datetime-pick input:text').on('click', function(){
129+
$(this).closest('.datetime-pick').find('.add-on i').click();
130+
});
131+
}
118132
});
119133
120134
function previewSelectedImage(el) {

0 commit comments

Comments
 (0)