Commit 2dfe5a32 authored by Madhur's avatar Madhur

more changes

parent d4925c47
...@@ -2,4 +2,4 @@ _site/ ...@@ -2,4 +2,4 @@ _site/
.sass-cache/ .sass-cache/
.DS_STORE .DS_STORE
node_modules node_modules
jshint.logs jshint.log
\ No newline at end of file \ No newline at end of file
...@@ -40,8 +40,8 @@ angular.module("myApp", ['emojiApp']); ...@@ -40,8 +40,8 @@ angular.module("myApp", ['emojiApp']);
The module consists of following components: The module consists of following components:
* `emojiForm` Directive - Enclose this directive with a textarea and a button named `emojibtn`. * `emojiForm` - Enclose this directive with a `textarea` and a `button` named `emojibtn`.
This directive adds a contenteditable div and hides the textarea. Anything typed into this conteteditable div is synced with the textarea. It also up the button to show an Emoji popup. This directive adds a `contenteditable` `div` and hides the `textarea`. Anything typed into this `contebteditable` `div` is synced with the `textarea`. It also hooks up the button to show an Emoji popup.
```html ```html
<div emoji-form emoji-message="emojiMessage"> <div emoji-form emoji-message="emojiMessage">
...@@ -93,8 +93,9 @@ For decoding the message string containing either colon style emojis or UTF-8 ch ...@@ -93,8 +93,9 @@ For decoding the message string containing either colon style emojis or UTF-8 ch
Much of the functionality of this module is driven by the map contained in `config.js` file. It contains a mapping of Emoji UTF-8 character and its colon representation. If you encounter any bugs in this mapping, please raise an issue or send a pull request. Much of the functionality of this module is driven by the map contained in `config.js` file. It contains a mapping of Emoji UTF-8 character and its colon representation. If you encounter any bugs in this mapping, please raise an issue or send a pull request.
## Using MySQL for storage
<a name="db"></a> <a name="db"></a>
## Using MySQL for storage
The following text is taken verbatim from [https://github.com/iamcal/js-emoji](https://github.com/iamcal/js-emoji) The following text is taken verbatim from [https://github.com/iamcal/js-emoji](https://github.com/iamcal/js-emoji)
> Some special care may be needed to store emoji in your database. While some characters (e.g. Cloud, U+2601) are > Some special care may be needed to store emoji in your database. While some characters (e.g. Cloud, U+2601) are
......
 Gruntfile.js
3 | var appConfig = grunt.file.readJSON('package.json') ||
^ Missing "use strict" statement.
1 |module.exports = function(grunt)
^ 'module' is not defined.
3 | var appConfig = grunt.file.readJSON('package.json') ||
^ 'appConfig' is defined but never used.
 js/app.js
1 |'use strict';
^ Use the function form of "use strict".
44 | return; // do nothing if no ng-model
^ Expected '{' and instead saw 'return'.
63 | if (attrs.stripBr && html == '<br>') {
^ Expected '===' and instead saw '=='.
14 | for (j = 0; j < Config.EmojiCategories.length; j++)
^ 'Config' is not defined.
16 | totalColumns = Config.EmojiCategorySpritesheetDimens[j][1];
^ 'Config' is not defined.
17 | for (i = 0; i < Config.EmojiCategories[j].length; i++)
^ 'Config' is not defined.
19 | dataItem = Config.Emoji[Config.EmojiCategories[j][i]];
^ 'Config' is not defined.
19 | dataItem = Config.Emoji[Config.EmojiCategories[j][i]];
^ 'Config' is not defined.
30 | $.emojiarea.spritesheetPath = 'img/emojisprite_!.png';
^ '$' is not defined.
31 | $.emojiarea.spritesheetDimens = Config.EmojiCategorySpritesheetDimens;
^ '$' is not defined.
31 | $.emojiarea.spritesheetDimens = Config.EmojiCategorySpritesheetDimens;
^ 'Config' is not defined.
32 | $.emojiarea.iconSize = 20;
^ '$' is not defined.
33 | $.emojiarea.icons = icons;
^ '$' is not defined.
34 | $.emojiarea.reverseIcons = reverseIcons;
^ '$' is not defined.
12 | i, j, hex, name, dataItem, row, column, totalColumns;
^ 'hex' is defined but never used.
38 |emojiApp.directive('contenteditable', [ '$sce', function($sce) {
^ '$sce' is defined but never used.
 js/config.js
1 |'use strict';
^ Use the function form of "use strict".
849 |}
^ Missing semicolon.
3467 | return;
^ Expected '{' and instead saw 'return'.
3477 | var emoticon = i.replace(/\&/g, '&amp;').replace(/\</g, '&lt;')
^ Unexpected escaped character '<' in regular expression.
3481 | continue;
^ Expected '{' and instead saw 'continue'.
3473 | for (var i in Config.emoticons_data)
^ The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.
3492 | return;
^ Expected '{' and instead saw 'return'.
3496 | for (var i in Config.data)
^ The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.
3507 | return;
^ Expected '{' and instead saw 'return'.
3524 | for (var i in Config.emoji_data)
^ The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.
3480 | if (!Config.map.colons[emoji.emoticons_data[i]])
^ 'emoji' is not defined.
3500 | Config.map.colons[emoji.data[i][3][j]] = i;
^ 'emoji' is not defined.
3461 |var a = [];
^ 'a' is defined but never used.
 js/emojiController.js
1 |'use strict';
^ Use the function form of "use strict".
11 | }
^ Missing semicolon.
3 |emojiApp.controller('emojiController', ['$scope', '$log', function($scope, $log) {
^ 'emojiApp' is not defined.
3 |emojiApp.controller('emojiController', ['$scope', '$log', function($scope, $log) {
^ '$log' is defined but never used.
 js/emojiDirectives.js
1 |'use strict';
^ Use the function form of "use strict".
81 | if (e.keyCode == 13)
^ Expected '===' and instead saw '=='.
119 | };
^ Unnecessary semicolon.
150 | if (height != newHeight)
^ Expected '!==' and instead saw '!='.
155 | };
^ Unnecessary semicolon.
164 | if (src.substr(0, 5) == 'data:')
^ Expected '===' and instead saw '=='.
179 | })
^ Missing semicolon.
189 | };
^ Unnecessary semicolon.
202 | if (items[i].kind == 'file')
^ Expected '===' and instead saw '=='.
225 | if (e.keyCode == 9 && !e.shiftKey && !e.ctrlKey && !e.metaKey && !$modalStack.getTop())
^ Expected '===' and instead saw '=='.
249 | $(submitBtn).off('mousedown')
^ Missing semicolon.
4 |emojiApp.directive('emojiForm', ['$timeout', '$http', '$interpolate','$compile', function($timeout, $http, $interpolate, $compile)
^ 'emojiApp' is not defined.
16 | var messageField = $('textarea', element)[0],
^ '$' is not defined.
17 | fileSelects = $('input', element),
^ '$' is not defined.
18 | emojiButton = $('#emojibtn', element)[0],
^ '$' is not defined.
20 | emojiArea = $(messageField).emojiarea(
^ '$' is not defined.
25 | emojiMenu = $('.emoji-menu', element)[0],
^ '$' is not defined.
26 | richTextarea = $(
^ '$' is not defined.
29 | var s = $compile($("#messageDiv"));
^ '$' is not defined.
30 | $("#messageDiv").replaceWith(s($scope));
^ '$' is not defined.
36 | $(richTextarea).addClass('form-control');
^ '$' is not defined.
37 | $(richTextarea)
^ '$' is not defined.
41 | $(messageField).attr(
^ '$' is not defined.
46 | $(richTextarea)
^ '$' is not defined.
72 | $(editorElement).on(
^ '$' is not defined.
100 | return cancelEvent(e);
^ 'cancelEvent' is not defined.
127 | var html = $('<div>').text(
^ '$' is not defined.
130 | $(richTextarea).html(html);
^ '$' is not defined.
131 | lastLength = html.length;
^ 'lastLength' is not defined.
140 | $(richTextarea).trigger('change');
^ '$' is not defined.
167 | var blob = dataUrlToBlob(src);
^ 'dataUrlToBlob' is not defined.
168 | ErrorService.confirm(
^ 'ErrorService' is not defined.
176 | setZeroTimeout(function()
^ 'setZeroTimeout' is not defined.
211 | ErrorService.confirm(
^ 'ErrorService' is not defined.
225 | if (e.keyCode == 9 && !e.shiftKey && !e.ctrlKey && !e.metaKey && !$modalStack.getTop())
^ '$modalStack' is not defined.
228 | return cancelEvent(e);
^ 'cancelEvent' is not defined.
231 | $(document).on('keydown', onKeyDown);
^ '$' is not defined.
232 | $(document).on('paste', onPasteEvent);
^ '$' is not defined.
238 | onContentLoaded(function()
^ 'onContentLoaded' is not defined.
247 | $(document).off('paste', onPasteEvent);
^ '$' is not defined.
248 | $(document).off('keydown', onKeyDown);
^ '$' is not defined.
249 | $(submitBtn).off('mousedown')
^ '$' is not defined.
249 | $(submitBtn).off('mousedown')
^ 'submitBtn' is not defined.
253 | $(richTextarea).off('DOMNodeInserted keyup',
^ '$' is not defined.
256 | $(editorElement).off('keydown');
^ '$' is not defined.
20 | emojiArea = $(messageField).emojiarea(
^ 'emojiArea' is defined but never used.
25 | emojiMenu = $('.emoji-menu', element)[0],
^ 'emojiMenu' is defined but never used.
121 | function updateRichTextarea()
^ 'updateRichTextarea' is defined but never used.
236 | function focusField()
^ 'focusField' is defined but never used.
14 | function link($scope, element, attrs)
^ 'attrs' is defined but never used.
>> Too many errors. (5% scanned).
 js/emojiFilters.js
1 |'use strict';
^ Use the function form of "use strict".
7 | return "";
^ Expected '{' and instead saw 'return'.
10 | Config.init_unified();
^ Expected '{' and instead saw 'Config'.
20 | return "";
^ Expected '{' and instead saw 'return'.
31 | return "";
^ Expected '{' and instead saw 'return'.
34 | Config.init_unified();
^ Expected '{' and instead saw 'Config'.
46 | return "";
^ Expected '{' and instead saw 'return'.
58 | return "";
^ Expected '{' and instead saw 'return'.
61 | Config.init_unified();
^ Expected '{' and instead saw 'Config'.
71 | return "";
^ Expected '{' and instead saw 'return'.
2 |emojiApp.filter('colonToCode', function() {
^ 'emojiApp' is not defined.
9 | if(!Config.rx_colons)
^ 'Config' is not defined.
10 | Config.init_unified();
^ 'Config' is not defined.
12 | return input.replace(Config.rx_colons, function(m)
^ 'Config' is not defined.
14 | var val = Config.mapcolon[m];
^ 'Config' is not defined.
26 |emojiApp.filter('codeToSmiley', function() {
^ 'emojiApp' is not defined.
33 | if(!Config.rx_codes)
^ 'Config' is not defined.
34 | Config.init_unified();
^ 'Config' is not defined.
36 | return input.replace(Config.rx_codes, function(m)
^ 'Config' is not defined.
38 | var val = Config.reversemap[m];
^ 'Config' is not defined.
42 | var $img = $.emojiarea.createIcon($.emojiarea.icons[val]);
^ '$' is not defined.
42 | var $img = $.emojiarea.createIcon($.emojiarea.icons[val]);
^ '$' is not defined.
53 |emojiApp.filter('colonToSmiley', function() {
^ 'emojiApp' is not defined.
60 | if(!Config.rx_colons)
^ 'Config' is not defined.
61 | Config.init_unified();
^ 'Config' is not defined.
63 | return input.replace(Config.rx_colons, function(m)
^ 'Config' is not defined.
67 | var $img = $.emojiarea.createIcon($.emojiarea.icons[m]);
^ '$' is not defined.
67 | var $img = $.emojiarea.createIcon($.emojiarea.icons[m]);
^ '$' is not defined.
 js/jquery.emojiarea.js
24 | var ELEMENT_NODE = 1;
^ Missing "use strict" statement.
58 | && options.wysiwyg !== false) {
^ Bad line breaking before '&&'.
129 | }
^ Missing semicolon.
138 | }
^ Missing semicolon.
145 | if (typeof el.selectionStart != 'undefined'
^ Expected '!==' and instead saw '!='.
146 | && typeof el.selectionEnd != 'undefined') {
^ Bad line breaking before '&&'.
146 | && typeof el.selectionEnd != 'undefined') {
^ Expected '!==' and instead saw '!='.
150 | + val.substring(el.selectionEnd);
^ Bad line breaking before '+'.
152 | } else if (typeof document.selection != 'undefined'
^ Expected '!==' and instead saw '!='.
153 | && typeof document.selection.createRange != 'undefined') {
^ Bad line breaking before '&&'.
153 | && typeof document.selection.createRange != 'undefined') {
^ Expected '!==' and instead saw '!='.
196 | if (pos != -1) {
^ Expected '!==' and instead saw '!='.
207 | })
^ Missing semicolon.
264 | var iconSize = menu && Config.Mobile ? 26 : $.emojiarea.iconSize
^ Missing semicolon.
274 | + xoffset + 'px ' + yoffset + 'px no-repeat;';
^ Bad line breaking before '+'.
276 | + 'px;';
^ Bad line breaking before '+'.
278 | + style + '" alt="' + util.htmlEntities(name) + '">';
^ Bad line breaking before '+'.
304 | return;
^ Expected '{' and instead saw 'return'.
411 | && cData.items || [], i;
^ Bad line breaking before '&&'.
413 | if (items[i].kind == 'file') {
^ Expected '===' and instead saw '=='.
493 | flush();
^ Expected '{' and instead saw 'flush'.
516 | flush();
^ Expected '{' and instead saw 'flush'.
526 | flush();
^ Expected '{' and instead saw 'flush'.
562 | + '<td><a class="emoji-menu-tab icon-recent" ></a></td>'
^ Bad line breaking before '+'.
563 | + '<td><a class="emoji-menu-tab icon-smile" ></a></td>'
^ Bad line breaking before '+'.
564 | + '<td><a class="emoji-menu-tab icon-flower"></a></td>'
^ Bad line breaking before '+'.
565 | + '<td><a class="emoji-menu-tab icon-bell"></a></td>'
^ Bad line breaking before '+'.
566 | + '<td><a class="emoji-menu-tab icon-car"></a></td>'
^ Bad line breaking before '+'.
567 | + '<td><a class="emoji-menu-tab icon-grid"></a></td>'
^ Bad line breaking before '+'.
568 | + '</tr></table>').appendTo(this.$itemsTailWrap);
^ Bad line breaking before '+'.
611 | while (target && target != window) {
^ Expected '!==' and instead saw '!='.
613 | if (target == self.$menu[0] || self.emojiarea
^ Expected '===' and instead saw '=='.
614 | && target == self.emojiarea.$button[0]) {
^ Bad line breaking before '&&'.
614 | && target == self.emojiarea.$button[0]) {
^ Expected '===' and instead saw '=='.
624 | self.reposition();
^ Expected '{' and instead saw 'self'.
727 | }
^ Missing semicolon.
737 | && options[key][0] === (category - 1)) {
^ Bad line breaking before '&&'.
739 | + util.htmlEntities(key) + '">'
^ Bad line breaking before '+'.
740 | + EmojiArea.createIcon(options[key], true)
^ Bad line breaking before '+'.
741 | + '<span class="label">' + util.htmlEntities(key)
^ Bad line breaking before '+'.
742 | + '</span></a>');
^ Bad line breaking before '+'.
751 | key = curEmojis[i]
^ Missing semicolon.
754 | + util.htmlEntities(key) + '">'
^ Bad line breaking before '+'.
755 | + EmojiArea.createIcon(options[key], true)
^ Bad line breaking before '+'.
756 | + '<span class="label">'
^ Bad line breaking before '+'.
757 | + util.htmlEntities(key) + '</span></a>');
^ Bad line breaking before '+'.
794 | return this.hide();
^ Expected '{' and instead saw 'return'.
189 | ConfigStorage.get('emojis_recent', function(curEmojis) {
^ 'ConfigStorage' is not defined.
204 | ConfigStorage.set({
^ 'ConfigStorage' is not defined.
264 | var iconSize = menu && Config.Mobile ? 26 : $.emojiarea.iconSize
^ 'Config' is not defined.
>> Too many errors. (32% scanned).
 js/nanoscroller.js
354 | BROWSER_SCROLLBAR_WIDTH || (BROWSER_SCROLLBAR_WIDTH = getBrowserScrollbarWidth());
^ Expected an assignment or function call and instead saw an expression.
363 | if (this.options.iOSNativeScrolling && (this.el.style.WebkitOverflowScrolling != null || navigator.userAgent.match(/mobi.+Gecko/i))) {
^ Expected '!==' and instead saw '!='.
544 | if (e == null) {
^ Expected '===' and instead saw '=='.
567 | if (e == null) {
^ Expected '===' and instead saw '=='.
642 | paneClass = options.paneClass, sliderClass = options.sliderClass, contentClass = options.contentClass;
^ Expected an assignment or function call and instead saw an expression.
660 | if (cssRule != null) {
^ Expected '!==' and instead saw '!='.
722 | } else if ((this.options.sliderMaxHeight != null) && sliderHeight > this.options.sliderMaxHeight) {
^ Expected '!==' and instead saw '!='.
932 | if (settings.scrollBottom != null) {
^ Expected '!==' and instead saw '!='.
935 | if (settings.scrollTop != null) {
^ Expected '!==' and instead saw '!='.
964 |})(jQuery, window, document);
^ 'jQuery' is not defined.
513 | return function(e) {
^ 'e' is defined but never used.
522 | return function(e) {
^ 'e' is defined but never used.
 js/util.js
1 |'use strict';
^ Use the function form of "use strict".
4 | if (!e || e.target && (e.target.tagName == 'IMG' || e.target.tagName == 'A')) return false;
^ Expected '===' and instead saw '=='.
4 | if (!e || e.target && (e.target.tagName == 'IMG' || e.target.tagName == 'A')) return false;
^ Expected '===' and instead saw '=='.
4 | if (!e || e.target && (e.target.tagName == 'IMG' || e.target.tagName == 'A')) return false;
^ Expected '{' and instead saw 'return'.
7 | if (e.dataTransfer.types[i] == 'Files') {
^ Expected '===' and instead saw '=='.
23 | if (event.stopPropagation) event.stopPropagation();
^ Expected '{' and instead saw 'event'.
24 | if (event.preventDefault) event.preventDefault();
^ Expected '{' and instead saw 'event'.
67 | single = keys.length == 1,
^ Expected '===' and instead saw '=='.
76 | if (key.substr(0, 3) != 'xt_' && cache[key] !== undefined)
^ Expected '!==' and instead saw '!='.
129 | };
^ Unnecessary semicolon.
173 | };
^ Unnecessary semicolon.
210 | };
^ Unnecessary semicolon.
221 |})(this);
^ Possible strict violation.
3 |function checkDragEvent(e) {
^ 'checkDragEvent' is defined but never used.
18 |function cancelEvent (event) {
^ 'cancelEvent' is defined but never used.
>> 193 errors in 9 files
#!/usr/bin/env node
var util = require('util'),
http = require('http'),
fs = require('fs'),
url = require('url'),
events = require('events');
var DEFAULT_PORT = 8001;
var DEFAULT_HOST = 'localhost';
function main(argv) {
new HttpServer({
'GET': createServlet(StaticServlet),
'HEAD': createServlet(StaticServlet)
}).start(Number(argv[2]) || DEFAULT_PORT, argv[3] || DEFAULT_HOST);
}
function escapeHtml(value) {
return value.toString().
replace('<', '&lt;').
replace('>', '&gt;').
replace('"', '&quot;');
}
function createServlet(Class) {
var servlet = new Class();
return servlet.handleRequest.bind(servlet);
}
/**
* An Http server implementation that uses a map of methods to decide
* action routing.
*
* @param {Object} Map of method => Handler function
*/
function HttpServer(handlers) {
this.handlers = handlers;
this.server = http.createServer(this.handleRequest_.bind(this));
}
HttpServer.prototype.start = function(port, host) {
this.port = port;
this.host = host;
this.server.listen(port, host);
util.puts('Http Server running at http://' + host + ':' + port + '/');
};
HttpServer.prototype.parseUrl_ = function(urlString) {
var parsed = url.parse(urlString);
parsed.pathname = url.resolve('/', parsed.pathname);
return url.parse(url.format(parsed), true);
};
HttpServer.prototype.handleRequest_ = function(req, res) {
var logEntry = req.method + ' ' + req.url;
if (req.headers['user-agent']) {
logEntry += ' ' + req.headers['user-agent'];
}
util.puts(logEntry);
req.url = this.parseUrl_(req.url);
var handler = this.handlers[req.method];
if (!handler) {
res.writeHead(501);
res.end();
} else {
handler.call(this, req, res);
}
};
/**
* Handles static content.
*/
function StaticServlet() {}
StaticServlet.MimeMap = {
'txt': 'text/plain',
'html': 'text/html',
'css': 'text/css',
'xml': 'application/xml',
'json': 'application/json',
'js': 'application/javascript',
'manifest': 'text/cache-manifest',
'appcache': 'text/cache-manifest',
'jpg': 'image/jpeg',
'jpeg': 'image/jpeg',
'gif': 'image/gif',
'png': 'image/png',
  'svg': 'image/svg+xml',
  'wav': 'audio/wav',
'ico': 'image/vnd.microsoft.icon',
'pexe': 'application/x-pnacl',
'bc': 'application/x-pnacl'
};
StaticServlet.prototype.handleRequest = function(req, res) {
var self = this;
var path = ('./' + req.url.pathname).replace('//','/').replace(/%(..)/g, function(match, hex){
return String.fromCharCode(parseInt(hex, 16));
});
var parts = path.split('/');
if (parts[parts.length-1].charAt(0) === '.')
return self.sendForbidden_(req, res, path);
fs.stat(path, function(err, stat) {
if (err)
return self.sendMissing_(req, res, path);
if (stat.isDirectory())
return self.sendDirectory_(req, res, path);
return self.sendFile_(req, res, path);
});
}
StaticServlet.prototype.sendError_ = function(req, res, error) {
res.writeHead(500, {
'Content-Type': 'text/html'
});
res.write('<!doctype html>\n');
res.write('<title>Internal Server Error</title>\n');
res.write('<h1>Internal Server Error</h1>');
res.write('<pre>' + escapeHtml(util.inspect(error)) + '</pre>');
util.puts('500 Internal Server Error');
util.puts(util.inspect(error));
};
StaticServlet.prototype.sendMissing_ = function(req, res, path) {
path = path.substring(1);
res.writeHead(404, {
'Content-Type': 'text/html'
});
res.write('<!doctype html>\n');
res.write('<title>404 Not Found</title>\n');
res.write('<h1>Not Found</h1>');
res.write(
'<p>The requested URL ' +
escapeHtml(path) +
' was not found on this server.</p>'
);
res.end();
util.puts('404 Not Found: ' + path);
};
StaticServlet.prototype.sendForbidden_ = function(req, res, path) {
path = path.substring(1);
res.writeHead(403, {
'Content-Type': 'text/html'
});
res.write('<!doctype html>\n');
res.write('<title>403 Forbidden</title>\n');
res.write('<h1>Forbidden</h1>');
res.write(
'<p>You do not have permission to access ' +
escapeHtml(path) + ' on this server.</p>'
);
res.end();
util.puts('403 Forbidden: ' + path);
};
StaticServlet.prototype.sendRedirect_ = function(req, res, redirectUrl) {
res.writeHead(301, {
'Content-Type': 'text/html',
'Location': redirectUrl
});
res.write('<!doctype html>\n');
res.write('<title>301 Moved Permanently</title>\n');
res.write('<h1>Moved Permanently</h1>');
res.write(
'<p>The document has moved <a href="' +
redirectUrl +
'">here</a>.</p>'
);
res.end();
util.puts('301 Moved Permanently: ' + redirectUrl);
};
StaticServlet.prototype.sendFile_ = function(req, res, path) {
var self = this;
var file = fs.createReadStream(path);
res.writeHead(200, {
'Content-Type': StaticServlet.
MimeMap[path.split('.').pop()] || 'text/plain'
});
// console.log(path.split('.').pop(), StaticServlet.MimeMap[path.split('.').pop()] || 'text/plain');
if (req.method === 'HEAD') {
res.end();
} else {
file.on('data', res.write.bind(res));
file.on('close', function() {
res.end();
});
file.on('error', function(error) {
self.sendError_(req, res, error);
});
}
};
StaticServlet.prototype.sendDirectory_ = function(req, res, path) {
var self = this;
if (path.match(/[^\/]$/)) {
req.url.pathname += '/';
var redirectUrl = url.format(url.parse(url.format(req.url)));
return self.sendRedirect_(req, res, redirectUrl);
}
fs.readdir(path, function(err, files) {
if (err)
return self.sendError_(req, res, error);
if (!files.length)
return self.writeDirectoryIndex_(req, res, path, []);
var remaining = files.length;
files.forEach(function(fileName, index) {
fs.stat(path + '/' + fileName, function(err, stat) {
if (err)
return self.sendError_(req, res, err);
if (stat.isDirectory()) {
files[index] = fileName + '/';
}
if (!(--remaining))
return self.writeDirectoryIndex_(req, res, path, files);
});
});
});
};
StaticServlet.prototype.writeDirectoryIndex_ = function(req, res, path, files) {
path = path.substring(1);
res.writeHead(200, {
'Content-Type': 'text/html'
});
if (req.method === 'HEAD') {
res.end();
return;
}
res.write('<!doctype html>\n');
res.write('<title>' + escapeHtml(path) + '</title>\n');
res.write('<style>\n');
res.write(' ol { list-style-type: none; font-size: 1.2em; }\n');
res.write('</style>\n');
res.write('<h1>Directory: ' + escapeHtml(path) + '</h1>');
res.write('<ol>');
files.forEach(function(fileName) {
if (fileName.charAt(0) !== '.') {
res.write('<li><a href="' +
escapeHtml(fileName) + '">' +
escapeHtml(fileName) + '</a></li>');
}
});
res.write('</ol>');
res.end();
};
// Must be last,
main(process.argv);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment