Browse Source

first releasable version

Bryan Allred 12 years ago
parent
commit
f8b859a24f
4 changed files with 110 additions and 27 deletions
  1. 19 8
      partials/dump.html
  2. 1 1
      scripts/components.js
  3. 30 18
      scripts/controllers.js
  4. 60 0
      styles/hexmeh.css

+ 19 - 8
partials/dump.html

@ -1,9 +1,20 @@
1
<!--<div id="drop-zone" style="height: 5em; width: 80%; border: 1px dashed #000; background-color: #fff;">Drop a file here!</div>-->
1
<div id="drop-zone"><span>{{instructions}}</span></div>
2 2
3
<tabs>
4
    <pane ng-repeat="file in files" title="{{file.name}}">
5
    	<div class="lineNumber" style="display: inline-block;">Line Numbers</div>
6
    	<div class="lineHex" style="display: inline-block;">Line Hex</div>
7
    	<div class="lineCharacters" style="display: inline-block;">Line Characters</div>
8
    </pane>
9
</tabs>
3
<div style="text-align: center; padding: 1em;">
4
    <label>Columns</label>
5
    <select ng-model="columns">
6
        <option>16</option>
7
        <option>32</option>
8
        <option>64</option>
9
        <option>128</option>
10
        <option>256</option>
11
    </select>
12
    <label>Hex Uppercase</label>
13
    <input type="checkbox" ng-model="uppercaseHex" />
14
</div>
15
16
<div id="terminal" class="mono">
17
    <div id="lineNumbers"></div>
18
    <div id="lineHex"></div>
19
    <div id="lineCharacters"></div>
20
</div>

+ 1 - 1
scripts/components.js

@ -22,7 +22,7 @@ angular.module('hexmeh', [])
22 22
                };
23 23
            }
24 24
        };
25
    });
25
    })
26 26
    .directive('tabs', function () {
27 27
        return {
28 28
            restrict: 'E',

+ 30 - 18
scripts/controllers.js

@ -45,27 +45,29 @@ function MainController($scope, $routeParams) {
45 45
function DumpController($scope, $routeParams) {
46 46
  $scope.columns = 16;
47 47
  $scope.fileApi = false;
48
  $scope.files = [];
49
  
50
  $scope.showFiles = function () {
51
    return $scope.files;
52
  };
48
  $scope.instructions = "Drop a file here!";
49
  $scope.uppercaseHex = false;
53 50
  
54 51
  // Check for the various File API support.
55 52
  if (window.File && window.FileReader && window.FileList && window.Blob) {
56 53
    // Great success! All the File APIs are supported.
57
    $(window).bind("dragover", function (e) {
54
    $("#drop-zone").bind("dragover", function (e) {
58 55
      e.stopPropagation();
59 56
      e.preventDefault();
60 57
      e.originalEvent.dataTransfer.dropEffect = 'copy';
61 58
    });
62 59
    
63
    $(window).bind("drop", function(e) {
60
    $("#drop-zone").bind("drop", function(e) {
64 61
      e.stopPropagation();
65 62
      e.preventDefault();
66 63
      
64
      // Remove previous output.
65
      $("#lineNumbers, #lineHex, #lineCharacters").empty();
66
      
67
      // Retrieve the files.
67 68
      var files = e.originalEvent.dataTransfer.files;
68 69
      
70
      // Iterate though each file.
69 71
      for (var i = 0, f; f = files[i]; i++) {
70 72
        var reader = new FileReader();
71 73
        
@ -73,21 +75,30 @@ function DumpController($scope, $routeParams) {
73 75
        reader.onload = (function(theFile) {
74 76
          return function(e) {
75 77
            var bytes = new Uint8Array(e.target.result);
76
            
77
            $scope.files.push({
78
              "name": theFile.name,
79
              "bytes": bytes
80
            });
81 78
82
            /*var c = 0;
83 79
            for (var i = 0; i < bytes.length; i++) {
84
              if (c++ >= 16) {
85
                $("#tabFile1").append("<br>");
86
                c = 0;
80
              if (i % $scope.columns === 0) {
81
                // Add a break line.
82
                $("#lineNumbers, #lineHex, #lineCharacters").append("<br>");
83
                
84
                // Get the line number.
85
                var lineNumber = padLeft(i.toString(16), 6);
86
                if ($scope.uppercaseHex) {
87
                  lineNumber = lineNumber.toUpperCase();
88
                }
89
                $("#lineNumbers").append("<span class='number'>" + lineNumber + "</span><span class='symbol'>:</span>");
90
              }
91
              
92
              // Get the hex string.
93
              var hexString = padLeft(bytes[i].toString(16), 2);
94
              if ($scope.uppercaseHex) {
95
                  hexString = hexString.toUpperCase();
87 96
              }
88 97
              
89
              $("#tabFile1").append(bytes[i].toString(16) + " ");
90
            }*/
98
              // Output the remaining lines.
99
              $("#lineHex").append("<span class='hex'>" + hexString + "</span>&nbsp;");
100
              $("#lineCharacters").append("<span class='char'>" + String.fromCharCode(bytes[i]) + "</span>");
101
            }
91 102
          };
92 103
        })(f);
93 104
        
@ -97,6 +108,7 @@ function DumpController($scope, $routeParams) {
97 108
    });
98 109
  } else {
99 110
    $scope.fileApi = false;
111
    $scope.instructions = "Sorry, your browser needs to go to an old folks home.";
100 112
    alert('The File APIs are not fully supported in this browser.');
101 113
  }
102 114
}

+ 60 - 0
styles/hexmeh.css

@ -79,6 +79,66 @@ div[role="main"] {
79 79
    background-color: #eee;
80 80
}
81 81
82
.mono {
83
    font-family: Fixed, monospace;
84
}
85
86
#drop-zone {
87
    /*width: 80%;*/
88
    border: 1px dashed #000; 
89
    background-color: #fff; 
90
    margin-left: auto; 
91
    margin-right: auto; 
92
    text-align: center; 
93
    padding-top: 2em; 
94
    padding-bottom: 2em;
95
}
96
97
#lineNumbers {
98
    display: inline-block; 
99
    padding-right: 1em;
100
    text-align: left;
101
    vertical-align: text-top;
102
}
103
104
#lineHex {
105
    display: inline-block; 
106
    padding-right: 1em;
107
    text-align: left;
108
    vertical-align: text-top;
109
}
110
111
#lineCharacters {
112
    display: inline-block;
113
    text-align: left;
114
    vertical-align: text-top;
115
}
116
117
#terminal {
118
    text-align: center; 
119
    min-height: 20em;
120
    background-color: #000;
121
    color: #00A300;
122
    border-radius: 24px;
123
    text-shadow: 1px 1px #333;
124
}
125
126
.number {
127
    color: #6B6B6B;
128
}
129
130
.symbol {
131
    color: #A30000;
132
}
133
134
.hex {
135
136
}
137
138
.char {
139
    color: #A35200;
140
}
141
82 142
/**
83 143
 * Buttons
84 144
 */