scroll to new file

pull/1/head
d11e9 9 years ago
parent 27a0938cf6
commit a8a879fa40
  1. 39
      assets/js/app.js

@ -226,18 +226,24 @@
}); });
// ----------------- file selector------------- // ----------------- file selector-------------
var $filesEl = $('#files'); var $filesEl = $('#files');
var FILE_SCROLL_DELTA = 300;
$('.newFile').on('click', function() { $('.newFile').on('click', function() {
while (window.localStorage[SOL_CACHE_UNTITLED + untitledCount]) while (window.localStorage[SOL_CACHE_UNTITLED + untitledCount])
untitledCount = (untitledCount - 0) + 1; untitledCount = (untitledCount - 0) + 1;
SOL_CACHE_FILE = SOL_CACHE_UNTITLED + untitledCount; SOL_CACHE_FILE = SOL_CACHE_UNTITLED + untitledCount;
window.localStorage[SOL_CACHE_FILE] = ''; window.localStorage[SOL_CACHE_FILE] = '';
updateFiles(); updateFiles();
});
$filesEl.animate({left: (0 - activeFilePos() + (FILE_SCROLL_DELTA/2)) + "px"}, "slow", function(){
$filesEl.on('click', '.file:not(.active)', showFileHandler); reAdjust();
})
});
$filesEl.on('click', '.file:not(.active)', showFileHandler);
$filesEl.on('click', '.file.active', function(ev) { $filesEl.on('click', '.file.active', function(ev) {
var $fileTabEl = $(this); var $fileTabEl = $(this);
@ -369,6 +375,13 @@
return $filesEl.position().left; return $filesEl.position().left;
}; };
function activeFilePos() {
var el = $filesEl.find('.active');
var l = el.position().left;
console.log("active file left", l, el)
return l;
}
function reAdjust (){ function reAdjust (){
if (widthOfList() + getLeftPosi() > + widthOfVisible()) { if (widthOfList() + getLeftPosi() > + widthOfVisible()) {
$scrollerRight.fadeIn('fast'); $scrollerRight.fadeIn('fast');
@ -385,14 +398,14 @@
} }
$scrollerRight.click(function() { $scrollerRight.click(function() {
var delta = (getLeftPosi() - 200) var delta = (getLeftPosi() - FILE_SCROLL_DELTA)
$filesEl.animate({left: delta + "px"},'slow',function(){ $filesEl.animate({left: delta + "px"},'slow',function(){
reAdjust(); reAdjust();
}); });
}); });
$scrollerLeft.click(function() { $scrollerLeft.click(function() {
var delta = Math.min( (getLeftPosi() + 200), 0 ) var delta = Math.min( (getLeftPosi() + FILE_SCROLL_DELTA), 0 )
$filesEl.animate({left: delta + "px"},'slow',function(){ $filesEl.animate({left: delta + "px"},'slow',function(){
reAdjust(); reAdjust();
}); });

Loading…
Cancel
Save