Issues (4542)

modul/mod_user/gallery.js (1 issue)

1
/**
2
 * Created by remi on 18/01/15.
3
 */
4 View Code Duplication
(function(){
0 ignored issues
show
This code seems to be duplicated in your project.
Loading history...
5
6
7
8
    function previewImage(file) {
9
        var galleryId = "gallery";
10
11
        var gallery = document.getElementById(galleryId);
12
        var imageType = /image.*/;
13
14
        if (!file.type.match(imageType)) {
15
            throw "File Type must be an image";
16
        }
17
18
        var thumb = document.createElement("div");
19
        thumb.classList.add('thumbnail');
20
21
        var img = document.createElement("img");
22
        img.file = file;
23
        thumb.appendChild(img);
24
        gallery.appendChild(thumb);
25
26
        // Using FileReader to display the image content
27
        var reader = new FileReader();
28
        reader.onload = (function(aImg) { return function(e) { aImg.src = e.target.result; }; })(img);
29
        reader.readAsDataURL(file);
30
    }
31
32
    var uploadfiles = document.querySelector('#fileinput');
33
    uploadfiles.addEventListener('change', function () {
34
        var files = this.files;
35
        for(var i=0; i<files.length; i++){
36
            previewImage(this.files[i]);
37
        }
38
39
    }, false);
40
})();