Browse Source

drag and drop

tags/1.0.2^0
Robin Thoni 8 years ago
parent
commit
1a5fc237bc
4 changed files with 35 additions and 3 deletions
  1. 27
    1
      app/app.js
  2. 6
    0
      app/controllers/home.controller.js
  3. 1
    1
      app/index.html
  4. 1
    1
      app/views/home.html

+ 27
- 1
app/app.js View File

@@ -39,4 +39,30 @@ app.config(['$stateProvider', '$urlRouterProvider', '$httpProvider', '$locationP
39 39
         $rootScope.$on('$stateChangeError', function (e, curr, prev) {
40 40
             //$state.go('login');
41 41
         });
42
-    }]);
42
+    }])
43
+    .directive("dropzone", function() {
44
+        return {
45
+            restrict : "A",
46
+            link: function (scope, elem) {
47
+                elem.bind('drop', function(evt) {
48
+                    evt.stopPropagation();
49
+                    evt.preventDefault();
50
+
51
+                    var files = evt.dataTransfer.files;
52
+                    for (var i = 0, f; f = files[i]; i++) {
53
+                        var reader = new FileReader();
54
+                        reader.readAsText(f);
55
+
56
+                        reader.onload = (function(file) {
57
+                            return function(e) {
58
+                                scope.$apply(function() {
59
+
60
+                                    scope.setDraggedContent(e.target.result, file);
61
+                                });
62
+                            };
63
+                        })(f);
64
+                    }
65
+                });
66
+            }
67
+        }
68
+    });

+ 6
- 0
app/controllers/home.controller.js View File

@@ -109,6 +109,12 @@ angular.module('app')
109 109
                 });
110 110
             };
111 111
 
112
+            $scope.setDraggedContent = function(data, file)
113
+            {
114
+                $scope.Data.Input = data;
115
+                $scope.convert();
116
+            };
117
+
112 118
             $scope.addMacro("\\RR", "\\mathbb{R}");
113 119
             $scope.addMacro("\\CC", "\\mathbb{C}");
114 120
             $scope.addMacro("\\QQ", "\\mathbb{Q}");

+ 1
- 1
app/index.html View File

@@ -25,8 +25,8 @@
25 25
 
26 26
     <!-- build:js app.js -->
27 27
     <!-- bower component -->
28
-    <script src="../bower_components/jquery/dist/jquery.js"></script>
29 28
     <script src="../bower_components/angular/angular.js"></script>
29
+    <script src="../bower_components/jquery/dist/jquery.js"></script>
30 30
     <script src="../bower_components/angular-ui-router/release/angular-ui-router.js"></script>
31 31
     <script src="../bower_components/angular-bootstrap/ui-bootstrap.js"></script>
32 32
     <script src="../bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js"></script>

+ 1
- 1
app/views/home.html View File

@@ -1,5 +1,5 @@
1 1
 <!-- Page Content -->
2
-<div class="container">
2
+<div class="container" dropzone>
3 3
 
4 4
     <div class="row">
5 5
 

Loading…
Cancel
Save