mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
feature(util) add forEach
This commit is contained in:
parent
7554d6c41a
commit
93b22b9fea
3 changed files with 41 additions and 9 deletions
|
|
@ -324,18 +324,17 @@ var Util, DOM, CloudCmd;
|
|||
}
|
||||
|
||||
function dragndrop() {
|
||||
var panelsEl = DOM.getByClassAll('panel'),
|
||||
panels = Util.slice(panelsEl),
|
||||
var panels = DOM.getByClassAll('panel'),
|
||||
preventDefault = function (event) {
|
||||
event.preventDefault();
|
||||
},
|
||||
toggle = function () {
|
||||
panels.forEach(function(panel) {
|
||||
Util.forEach(panels, function(panel) {
|
||||
DOM.toggleClass(panel, 'selected-panel');
|
||||
});
|
||||
},
|
||||
onDrop = function (event) {
|
||||
var filesData, files,
|
||||
var files,
|
||||
func = CloudCmd.refresh,
|
||||
dir = Info.dirPath,
|
||||
load = function(file, callback) {
|
||||
|
|
@ -352,11 +351,10 @@ var Util, DOM, CloudCmd;
|
|||
preventDefault(event);
|
||||
toggle();
|
||||
|
||||
filesData = event.dataTransfer.files;
|
||||
files = Util.slice(filesData);
|
||||
|
||||
files = event.dataTransfer.files;
|
||||
|
||||
if (files.length) {
|
||||
files.forEach(function(file) {
|
||||
Util.forEach(files, function(file) {
|
||||
func = Util.bind(load, file, func);
|
||||
});
|
||||
|
||||
|
|
@ -366,7 +364,7 @@ var Util, DOM, CloudCmd;
|
|||
|
||||
Events.add(['dragenter', 'dragleave'], toggle);
|
||||
|
||||
panels.forEach(function(panel) {
|
||||
Util.forEach(panels, function(panel) {
|
||||
Events.add('dragover', preventDefault, panel);
|
||||
Events.add('drop', onDrop, panel);
|
||||
});
|
||||
|
|
|
|||
14
lib/util.js
14
lib/util.js
|
|
@ -736,6 +736,20 @@
|
|||
return ret;
|
||||
};
|
||||
|
||||
/**
|
||||
* function calls forEach for all array like variables
|
||||
*
|
||||
* @param array
|
||||
*/
|
||||
this.forEach = function(array, callback) {
|
||||
var ret = [];
|
||||
|
||||
if (array)
|
||||
ret = [].forEach.call(array, callback);
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
/**
|
||||
* function execute param function in
|
||||
* try...catch block
|
||||
|
|
|
|||
|
|
@ -138,6 +138,26 @@
|
|||
|
||||
});
|
||||
|
||||
describe('forEach', function() {
|
||||
it('should call arrays forEach on any type', function() {
|
||||
var str = '',
|
||||
obj = {
|
||||
0: 'a',
|
||||
1: 'b',
|
||||
2: 'c',
|
||||
length: 3
|
||||
};
|
||||
|
||||
Util.forEach(obj, function(item) {
|
||||
str += item;
|
||||
});
|
||||
|
||||
str.should.be.equal('abc');
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue