-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from py-package/dev
Dev
Showing
14 changed files
with
496 additions
and
29 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
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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
.file-picker { | ||
min-width: 32px; | ||
padding: 8px; | ||
border: 1px dotted black; | ||
border-radius: 4px; | ||
position: relative; | ||
min-height: 16px; | ||
} | ||
|
||
.file-picker .preview { | ||
width: 100%; | ||
height: 100%; | ||
z-index: 1; | ||
top: 0; | ||
left: 0; | ||
position: absolute; | ||
} | ||
|
||
.file-picker .close { | ||
position: absolute; | ||
right: 2px; | ||
top: 2px; | ||
z-index: 2; | ||
background: white; | ||
padding: 0; | ||
margin: 0; | ||
width: 16px; | ||
height: 16px; | ||
display: flex; | ||
justify-content: center; | ||
line-height: 0.9; | ||
border-radius: 100%; | ||
cursor: pointer; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
(() => { | ||
let index = 0; | ||
const FilePickers = document.querySelectorAll(".file-picker"); | ||
|
||
window.fmanager = function (element, callback) { | ||
if (!element) return; | ||
window.open('/filemanager/picker', 'File Picker', | ||
'height=400,width=1200,toolbar=no,directories=no,status=no, linemenubar=no,scrollbars=no,resizable=no ,modal=yes'); | ||
|
||
if (!window.SetUrl) { | ||
window.SetUrl = function (url) { | ||
callback(url, element); | ||
} | ||
} | ||
} | ||
|
||
const SelectorTemplate = ` | ||
<span class="picker"> | ||
Select File | ||
</span> | ||
`; | ||
|
||
const PreviewTemplate = ` | ||
<span class="preview"> | ||
<img src="IMAGE_URL"> | ||
</span> | ||
<span class="close">x</span> | ||
`; | ||
|
||
const SetPreview = (file) => { | ||
if (FilePickers[index].classList.contains('has-preview')) { | ||
const close = FilePickers[index].querySelector('.close') | ||
if (close) close.remove() | ||
const preview = FilePickers[index].querySelector('.preview') | ||
if (preview) preview.remove() | ||
const PreviewElement = PreviewTemplate.replace("IMAGE_URL", file) | ||
FilePickers[index].insertAdjacentHTML("beforeend", PreviewElement); | ||
} | ||
} | ||
|
||
const PickFile = () => { | ||
fmanager(FilePickers[index], function (file, target) { | ||
FilePickers[index].querySelector('input').value = file; | ||
SetPreview(file); | ||
}); | ||
} | ||
|
||
FilePickers.forEach(function (fp, i) { | ||
fp.insertAdjacentHTML("beforeend", SelectorTemplate) | ||
fp.addEventListener('click', function (e) { | ||
index = i; | ||
if (e.target.classList.contains('close')) { | ||
FilePickers[index].querySelector('.close').remove() | ||
FilePickers[index].querySelector('.preview').remove() | ||
FilePickers[index].querySelector('input').value = ''; | ||
} else { | ||
PickFile(FilePickers[index]) | ||
} | ||
}) | ||
}) | ||
})(); |
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
Oops, something went wrong.