From: Benoît Pin Date: Wed, 12 Jun 2013 14:00:15 +0000 (+0200) Subject: Remise en forme du code en OO et initialisation. X-Git-Url: https://scm.cri.mines-paristech.fr/git/Portfolio.git/commitdiff_plain/10ff1e0196ea513c9e3d29519d2aab9e8680d7dc Remise en forme du code en OO et initialisation. --- diff --git a/skins/fileupload.js b/skins/fileupload.js index d862ad6..97b5443 100644 --- a/skins/fileupload.js +++ b/skins/fileupload.js @@ -1,54 +1,45 @@ -function dragenter(evt) { +// © 2013 Benoît Pin MINES ParisTech +var DDFileUploader; + +(function(){ + +DDFileUploader = function(dropbox) { + this.dropbox = dropbox; + var thisDDFU = this; + addListener(dropbox, 'dragenter', function(evt){thisDDFU.dragenter(evt);}); + addListener(dropbox, 'dragover', function(evt){thisDDFU.dragover(evt);}); + addListener(dropbox, 'drop', function(evt){thisDDFU.drop(evt);}); +}; + +DDFileUploader.prototype.dragenter = function(evt) { disableDefault(evt); disablePropagation(evt); -} +}; -function dragover(evt) { +DDFileUploader.prototype.dragover = function(evt) { disableDefault(evt); disablePropagation(evt); evt = getEventObject(evt); var dt = evt.dataTransfer; dt.dropEffect = 'copy'; -} +}; -function drop(evt) { +DDFileUploader.prototype.drop = function(evt) { disableDefault(evt); disablePropagation(evt); getEventObject(evt); var dt = evt.dataTransfer; dt.dropEffect = 'copy'; - handleFiles(dt.files); -} + this.handleFiles(dt.files); +}; -function handleFiles(files) { - for (var i = 0; i < files.length; i++) { - var file = files[i]; +DDFileUploader.prototype.handleFiles = function(files) { + var file, i; + for (i = 0; i < files.length; i++) { + file = files[i]; console.log(file.type); - // console.log(file); - // var imageType = /image.*/; - // - // if (!file.type.match(imageType)) { - // continue; - // } - // - // var img = document.createElement("img"); - // img.classList.add("obj"); - // img.file = file; - // preview.appendChild(img); - // - // var reader = new FileReader(); - // reader.onload = (function(aImg) { return function(e) { aImg.src = e.target.result; }; })(img); - // reader.readAsDataURL(file); } -} - -function init() { - var dropbox = document.getElementById('dropbox'); - addListener(dropbox, 'dragenter', dragenter); - addListener(dropbox, 'dragover', dragover); - addListener(dropbox, 'drop', drop); -} - +}; -addListener(window, 'load', init); \ No newline at end of file +}()); diff --git a/skins/photo_layout_macros.pt b/skins/photo_layout_macros.pt index 88356b6..849699e 100644 --- a/skins/photo_layout_macros.pt +++ b/skins/photo_layout_macros.pt @@ -85,7 +85,9 @@