]> git.mxchange.org Git - simple-upload.git/commitdiff
Added some more JavaScript comments for better readability
authorRoland Häder <roland@mxchange.org>
Tue, 29 Mar 2016 15:09:35 +0000 (17:09 +0200)
committerRoland Häder <roland@mxchange.org>
Tue, 29 Mar 2016 15:09:35 +0000 (17:09 +0200)
index.php

index 72f6cb0bfbacc09fb9d5d666082cc50503244181..e32486df394cb1f9427da0cc6021cc92e9fa6196 100644 (file)
--- a/index.php
+++ b/index.php
                ?>
                <script type="text/javascript">
                <!--
-                       var target_form  = document.getElementById('simpleupload-form');
-                       var target_ul= document.getElementById('simpleupload-ul');
-                       var target_input = document.getElementById('simpleupload-input');
+                       // Init some variales to shorten code
+                       var target_form        = document.getElementById('simpleupload-form');
+                       var target_ul          = document.getElementById('simpleupload-ul');
+                       var target_input       = document.getElementById('simpleupload-input');
                        var settings_listfiles = <?=($settings['listfiles'] ? 'true' : 'false')?>;
 
-                       target_form.addEventListener('dragover', function (event) {
-                               event.preventDefault();
-                       }, false);
+                       /**
+                        * Initializes the upload form
+                        */
+                       function init () {
+                               // Register drag-over event listener
+                               target_form.addEventListener('dragover', function (event) {
+                                       event.preventDefault();
+                               }, false);
+
+                               // ... and the drop event listener
+                               target_form.addEventListener('drop', handleFiles, false);
+
+                               // Register onchange-event function
+                               target_input.onchange = function () {
+                                       addFileLi('Uploading...', '');
+                                       target_form.submit();
+                               };
+                       }
 
+                       /**
+                        * Adds given file in a new li-tag to target_ul list
+                        *
+                        * @param name Name of the file
+                        * @param info Some more informations
+                        */
                        function addFileLi (name, info) {
                                if (settings_listfiles == false) {
                                        return;
                                }
+
                                target_form.style.display = 'none';
 
                                var new_li = document.createElement('li');
                                target_ul.insertBefore(new_li, target_ul.firstChild);
                        }
 
+                       /**
+                        * Handles given event for file upload
+                        *
+                        * @param event Event to handle file upload for
+                        */
                        function handleFiles (event) {
                                event.preventDefault();
 
                                xhr.send(form);
                        }
 
-                       target_form.addEventListener('drop', handleFiles, false);
+                       // Initialize upload form
+                       init();
 
-                       document.getElementById('simpleupload-input').onchange = function () {
-                               addFileLi('Uploading...', '');
-                               target_form.submit();
-                       };
                //-->
                </script>
        </body>