Skip to content
This repository was archived by the owner on Apr 23, 2024. It is now read-only.

Commit b49274d

Browse files
author
Adam Miribyan
committed
Start off Techroom Snippets.
0 parents  commit b49274d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## Snippets
2+
Here we gather various snippets, custom plugins or any piece of code that can be reused in several projects.

javascript/file_select.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Namespace.forms.fileSelect = (function() {
2+
// Required HTML markup:
3+
// <div data-behaviour="file-select">
4+
// <ins>+</ins>
5+
// <a href="#">Select a file to upload</a>
6+
// <span class="selected"></span>
7+
// </div>
8+
// <input type="file" name="user_cover_letter" class="hidden" />
9+
var setup = function() {
10+
$("[data-behaviour~=file-select] a").on("click", function(e) {
11+
e.preventDefault();
12+
13+
$(this).parent().siblings("input[type=file].hidden").trigger("click");
14+
});
15+
16+
$("input[type=file].hidden").on("change", function(e) {
17+
$(this).siblings("[data-behaviour~=file-select]").find(".selected").text(e.target.files[0].name);
18+
});
19+
}
20+
21+
return {
22+
setup: setup,
23+
};
24+
})();

0 commit comments

Comments
 (0)