mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
fixed scrolling bug on non-webkit based browsers
This commit is contained in:
parent
56c412d2a0
commit
356d9586c2
3 changed files with 63 additions and 32 deletions
|
|
@ -22,6 +22,9 @@ in file tree thrue mouse double click.
|
|||
* Removed property keyBinded. From not it's private
|
||||
member of KeyBinding class.
|
||||
|
||||
* Fixed scrolling bug on non-webkit based browsers.
|
||||
Function scrollIntoViewIfNeeded was polyfilled.
|
||||
|
||||
|
||||
2012.08.24, Version 0.1.6
|
||||
|
||||
|
|
|
|||
|
|
@ -934,7 +934,7 @@ CloudClient._editFileName = (function(pParent){
|
|||
if (lA && lA.textContent !== '..')
|
||||
lA.contentEditable = false;
|
||||
|
||||
KeyBinding.Set();
|
||||
KeyBinding.set();
|
||||
|
||||
/* backs old document.onclick
|
||||
* and call it if it was
|
||||
|
|
@ -1024,7 +1024,7 @@ CloudClient._currentToParent = (function(pDirName){
|
|||
*/
|
||||
if(lRootDir){
|
||||
Util.setCurrentFile(lRootDir);
|
||||
Util.scrollIntoViewIfNeeded(lRootDir);
|
||||
Util.scrollIntoViewIfNeeded(lRootDir, true);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -1038,7 +1038,7 @@ CloudClient.init = (function(){
|
|||
getByClass = Util.getByClass;
|
||||
getById = Util.getById;
|
||||
|
||||
if(!document.body.scrollIntoViewIfNeeded){
|
||||
if(2===2 || !document.body.scrollIntoViewIfNeeded){
|
||||
this.OLD_BROWSER = true;
|
||||
Util.jsload(CloudClient.LIBDIRCLIENT + 'ie.js',
|
||||
function(){
|
||||
|
|
|
|||
|
|
@ -47,38 +47,66 @@ var CloudCommander, $;
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
lUtil.scrollIntoViewIfNeeded = function(el){
|
||||
/*
|
||||
* http://www.performantdesign.com/2009/08/26/scrollintoview-but-only-if-out-of-view/
|
||||
*/
|
||||
var topOfPage = window.pageYOffset ||
|
||||
document.documentElement.scrollTop ||
|
||||
document.body.scrollTop;
|
||||
/* function polyfill webkit standart function */
|
||||
lUtil.scrollIntoViewIfNeeded = function(pElement, centerIfNeeded){
|
||||
/*
|
||||
https://gist.github.com/2581101
|
||||
*/
|
||||
centerIfNeeded = arguments.length === 0 ? true : !!centerIfNeeded;
|
||||
|
||||
var heightOfPage = window.innerHeight ||
|
||||
document.documentElement.clientHeight ||
|
||||
document.body.clientHeight;
|
||||
var parent = pElement.parentNode,
|
||||
parentComputedStyle = window.getComputedStyle(parent, null),
|
||||
parentBorderTopWidth =
|
||||
parseInt(parentComputedStyle.getPropertyValue('border-top-width')),
|
||||
|
||||
parentBorderLeftWidth =
|
||||
parseInt(parentComputedStyle.getPropertyValue('border-left-width')),
|
||||
|
||||
overTop = pElement.offsetTop - parent.offsetTop < parent.scrollTop,
|
||||
overBottom =
|
||||
(pElement.offsetTop -
|
||||
parent.offsetTop +
|
||||
pElement.clientHeight -
|
||||
parentBorderTopWidth) >
|
||||
(parent.scrollTop + parent.clientHeight),
|
||||
|
||||
overLeft = pElement.offsetLeft -
|
||||
parent.offsetLeft < parent.scrollLeft,
|
||||
|
||||
overRight =
|
||||
(pElement.offsetLeft -
|
||||
parent.offsetLeft +
|
||||
pElement.clientWidth -
|
||||
parentBorderLeftWidth) >
|
||||
(parent.scrollLeft + parent.clientWidth),
|
||||
|
||||
alignWithTop = overTop && !overBottom;
|
||||
|
||||
var elY = 0;
|
||||
var elH = 0;
|
||||
if ((overTop || overBottom) && centerIfNeeded) {
|
||||
parent.scrollTop =
|
||||
pElement.offsetTop -
|
||||
parent.offsetTop -
|
||||
parent.clientHeight / 2 -
|
||||
parentBorderTopWidth +
|
||||
pElement.clientHeight / 2;
|
||||
}
|
||||
|
||||
if (document.layers) { // NS4
|
||||
elY = el.y;
|
||||
elH = el.height;
|
||||
}
|
||||
else {
|
||||
for(var p = el; p && p.tagName != 'BODY'; p = p.offsetParent)
|
||||
elY += p.offsetTop;
|
||||
|
||||
elH = el.offsetHeight;
|
||||
}
|
||||
if ((overLeft || overRight) && centerIfNeeded) {
|
||||
parent.scrollLeft =
|
||||
pElement.offsetLeft -
|
||||
parent.offsetLeft -
|
||||
parent.clientWidth / 2 -
|
||||
parentBorderLeftWidth +
|
||||
pElement.clientWidth / 2;
|
||||
}
|
||||
|
||||
if ((topOfPage + heightOfPage) < (elY + elH))
|
||||
el.scrollIntoView(false);
|
||||
|
||||
else if (elY < topOfPage)
|
||||
el.scrollIntoView(true);
|
||||
};
|
||||
if (( overTop ||
|
||||
overBottom ||
|
||||
overLeft ||
|
||||
overRight) &&
|
||||
!centerIfNeeded) {
|
||||
pElement.scrollIntoView(alignWithTop);
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue