feature(edit) add minify

This commit is contained in:
coderaiser 2014-10-24 04:31:57 -04:00
parent 2d9b3a542f
commit ad33e2410e
4 changed files with 34 additions and 5 deletions

View file

@ -158,6 +158,7 @@ Edit
| `Ctrl + h` | replace
| `Ctrl + g` | go to line
| `Ctrl + b` | beautify js, css or html
| `Ctrl + m` | minify js, css or html
| `Esc` | close
For more details see [Ace keyboard shortcuts](https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts "Ace keyboard shortcuts").

View file

@ -247,6 +247,14 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI
}
});
Ace.commands.addCommand({
name : 'minify',
bindKey : { win: 'Ctrl-M', mac: 'Command-M' },
exec : function() {
Edit.minify();
}
});
ace.require('ace/ext/language_tools');
Modelist = ace.require('ace/ext/modelist');
@ -411,6 +419,9 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI
'Beautify Ctrl+B' : function() {
Edit.beautify();
},
'Minify Ctrl+M' : function() {
Edit.minify();
},
'Close Esc' : Edit.hide
};
@ -483,14 +494,24 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI
}
Edit.beautify = function() {
readWithFlag('beautify');
};
Edit.minify = function() {
readWithFlag('minify');
};
function readWithFlag(flag) {
var path = Info.path;
RESTful.read(path + '?beautify', function(data) {
Util.checkArgs(arguments, ['flag']);
RESTful.read(path + '?' + flag, function(data) {
Ace.setValue(data);
Ace.clearSelection();
Ace.moveCursorTo(0, 0);
});
};
}
function onDrop(event) {
var reader, files,

View file

@ -49,7 +49,9 @@ var Util, DOM, CloudFunc, CloudCmd;
this.read = function(url, dataType, callback) {
var isQuery = /\?/.test(url),
isBeautify = /.?beautify$/.test(url),
isBeautify = /\?beautify$/.test(url),
isMinify = /\?minify$/.test(url),
notLog = !isQuery || isBeautify || isMinify,
isFunc = Util.type.function(dataType);
if (!callback && isFunc) {
@ -61,7 +63,7 @@ var Util, DOM, CloudFunc, CloudCmd;
method : 'GET',
url : CloudFunc.FS + url,
callback : callback,
notLog : !isQuery || isBeautify,
notLog : notLog,
dataType : dataType
});
};

View file

@ -9,6 +9,7 @@
hash = require(DIR_SERVER + 'hash'),
mellow = require(DIR_SERVER + 'mellow'),
beautify = require(DIR_SERVER + 'beautify'),
minify = require(DIR_SERVER + 'minify'),
Util = require(DIR + 'util');
module.exports = function(query, name, callback) {
@ -32,7 +33,11 @@
case 'beautify':
beautify(name, callback);
break;
case 'minify':
minify(name, callback);
break;
case 'hash':
hashStream = hash();