diff --git a/ChangeLog b/ChangeLog index 5655fdb8..96f5e487 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/client.js b/client.js index cb2bf16f..9884d564 100644 --- a/client.js +++ b/client.js @@ -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(){ diff --git a/lib/client/ie.js b/lib/client/ie.js index e9642c01..2b18a590 100644 --- a/lib/client/ie.js +++ b/lib/client/ie.js @@ -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); + } + }; })(); \ No newline at end of file