-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbetterInterface.js
95 lines (61 loc) · 3.11 KB
/
betterInterface.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*global define, brackets, $ */
define( function( require, exports, module ) {
"use strict";
var DocumentManager = brackets.getModule( 'document/DocumentManager' );
function BetterInterface( units ) {
this.units = units;
this.init = function() {
this.buildFolderCloser();
this.buildFileInfo();
};
this.buildFolderCloser = function() {
var closeButton = document.createElement( 'div' ),
projectFilesHeader = document.getElementById( 'project-files-header' );
closeButton.innerHTML = '×';
closeButton.id = 'closeAllFolders';
closeButton.addEventListener( 'click', this.onCloseFolders.bind( this ) );
projectFilesHeader.appendChild( closeButton );
};
this.buildFileInfo = function() {
$( DocumentManager ).on( "currentDocumentChange", this.onCurrentDocumentChange.bind( this ) );
$( document ).on( 'keypress', this.onCurrentDocumentChange.bind( this ) );
$( '#status-language' ).after( '<div id="fileSizeInfo"></div> <div id="fileDateInfo"></div>' );
};
this.onCloseFolders = function() {
$( '.jstree-open' ).addClass( 'jstree-closed' ).removeClass( 'jstree-open' );
$( '.jstree-clicked' ).click();
$( '#project-files-container' ).scrollTop( 0 );
};
this.updateSizeInfo = function() {
var docSize = this.currentDoc.getText().length,
unitLabel = {
'octet': 'O',
'byte': 'B',
'bit': 'b'
};
if ( this.units === 'bit' ) docSize = docSize * 8;
if ( docSize < 1024 ) docSize += ' ' + unitLabel[ this.units ];
else docSize = Math.floor( docSize / 1024 ).toString() + '.' + ( docSize % 1024 ).toString().substring( 0, 2 ) + ' K' + unitLabel[ this.units ];
$( '#fileSizeInfo' ).text( '~ ' + docSize );
};
this.updateDateInfo = function() {
var year = this.currentDoc.diskTimestamp.getFullYear(),
month = this.currentDoc.diskTimestamp.getMonth() + 1,
date = this.currentDoc.diskTimestamp.getDate(),
hours = this.currentDoc.diskTimestamp.getHours(),
minutes = this.currentDoc.diskTimestamp.getMinutes();
month = month < 10 ? '0' + month : month;
date = date < 10 ? '0' + date : date;
hours = hours < 10 ? '0' + hours : hours;
minutes = minutes < 10 ? '0' + minutes : minutes;
$( '#fileDateInfo' ).text( year + '-' + month + '-' + date + ' at ' + hours + ':' + minutes );
};
this.onCurrentDocumentChange = function() {
this.currentDoc = DocumentManager.getCurrentDocument();
if ( this.currentDoc === null ) return false;
this.updateSizeInfo();
this.updateDateInfo();
};
}
exports.BetterInterface = BetterInterface;
} );