Skip to content

Commit

Permalink
functions operating on DOM seperated, optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
noveens committed Apr 8, 2017
1 parent b0443b9 commit 67180f9
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 107 deletions.
46 changes: 34 additions & 12 deletions apps/files/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@
initialized: false,

/**
* fileName of last highlighted row
* @type string
* $tr of last highlighted row
* @type $tr
*/
keyboardHighlight: null,

Expand Down Expand Up @@ -2843,6 +2843,19 @@

},

/**
* Get FileName from given File $tr
* return {string} fileName
*/
getFileNamefromTr: function($tr) {
if ($tr) {
return $tr.data('file');
}
else {
return null;
}
},

/**
* Scroll to the file which is highlighted (has class mouseOver)
* to be called after the scrolling is finished
Expand All @@ -2858,7 +2871,7 @@
}

// the "mouseOver" tr is present in the lower half of the screen
if (this.$el.find('.mouseOver').position().top >= this.$container.height() / 2) {
if (this.getKeyboardHighlight() && this.getKeyboardHighlight().position().top >= this.$container.height() / 2) {
$scrollContainer.animate({
// Scrolling to the top of the highleghted element
scrollTop: this.$el.find('.mouseOver').position().top - this.$container.height() / 2
Expand All @@ -2881,9 +2894,13 @@

// delete the row which is currently selected (has "mouseOver" attr.)
if (countSelected == 0) {
// doing ".first()" just to make sure only one element is selected
var selectedFileName = this.getKeyboardHighlight();
//setting next keyboardHighlight
var toSet = this.getKeyboardHighlight().next();
var selectedFileName = this.getFileNamefromTr(this.getKeyboardHighlight());
this.do_delete(selectedFileName, this.getCurrentDirectory());
if (toSet) {
this.setKeyboardHighlight(toSet);
}
}

// deletion of multiple files selected
Expand Down Expand Up @@ -2915,22 +2932,27 @@
},

/**
* returns currently highlighted file (has attr "")
* returns currently highlighted file
* return {$tr}
*/
getKeyboardHighlight: function() {
var fileRow = this.findFileEl(this.keyboardHighlight);
if (!fileRow.exists()) {
if (this.keyboardHighlight && !this.keyboardHighlight.exists()) {
this.setKeyboardHighlight(null);
return null;
}
return this.keyboardHighlight;
},

/**
* @param string fileName which is highlighted currently
* De-selects all the currently selected files (have class "selected")
* @param {JQuery row object} file which is highlighted currently
* Sets file as current keyboard highlight
*/
setKeyboardHighlight: function(fileName) {
this.keyboardHighlight = fileName;
setKeyboardHighlight: function($tr) {
if ($tr && !$tr.exists()) {
this.setKeyboardHighlight(null);
return null;
}
this.keyboardHighlight = $tr;
},

/**
Expand Down
Loading

0 comments on commit 67180f9

Please sign in to comment.