| 18 | | var parentBottom = parent.scrollTop + dojo.marginBox(parent).h; //PORT was getBorderBox |
| 19 | | var nodeBottom = node.offsetTop + dojo.marginBox(node).h; |
| 20 | | if(parentBottom < nodeBottom){ |
| 21 | | parent.scrollTop += (nodeBottom - parentBottom); |
| 22 | | }else if(parent.scrollTop > node.offsetTop){ |
| 23 | | parent.scrollTop -= (parent.scrollTop - node.offsetTop); |
| | 24 | while(parent){ |
| | 25 | var parentBox = null; // cache this since its expensive |
| | 26 | // for both x and y directions |
| | 27 | for (var dir in xy){ |
| | 28 | // find scrollable parent |
| | 29 | var scrollAttr = (dir=="H")? "scrollLeft" : "scrollTop"; |
| | 30 | var scrollableParent = false; |
| | 31 | if(parent[scrollAttr] > 0){ // already scrolled so this 1 is easy |
| | 32 | scrollableParent = true; |
| | 33 | }else{ // scroll start = 0 |
| | 34 | parent[scrollAttr] = 1; |
| | 35 | // of the scroll start could be changed, then its scrollable |
| | 36 | if(parent[scrollAttr] == 1){ |
| | 37 | parent[scrollAttr] = 0; |
| | 38 | scrollableParent = true; |
| | 39 | } |
| | 40 | } |
| | 41 | if(scrollableParent){ |
| | 42 | if(!parentBox){ |
| | 43 | parentBox = dojo._getBorderBox(parent); |
| | 44 | } |
| | 45 | var r2l = (dir=="H" && !dojo._isBodyLtr()); |
| | 46 | var parentSize = { V: parentBox.h, H: parentBox.w }; |
| | 47 | var parentEnd = r2l? (parent.scrollWidth - parent.scrollLeft) : (parent[scrollAttr] + parentSize[dir]); |
| | 48 | var nodeEnd = r2l? (parent.clientWidth - node.offsetLeft) : (nodeStart[dir] + nodeSize[dir]); |
| | 49 | // first see if the parent needs to be scrolled more to encompass the node end |
| | 50 | var scrollAmount = nodeEnd - parentEnd; |
| | 51 | if(scrollAmount > 0){ |
| | 52 | parent[scrollAttr] += r2l? -scrollAmount : scrollAmount; |
| | 53 | }else{ |
| | 54 | var parentScroll; |
| | 55 | if(r2l){ // count from the end instead of from 0 |
| | 56 | nodeStart.H = parent.clientWidth - node.offsetLeft - nodeBox.w; |
| | 57 | parentScroll = parent.scrollWidth - parent.scrollLeft - parent.clientWidth; |
| | 58 | }else{ |
| | 59 | parentScroll = parent[scrollAttr]; |
| | 60 | } |
| | 61 | // see if the parent needs to be scrolled less to reveal the node start |
| | 62 | if(parentScroll > nodeStart[dir]){ |
| | 63 | parent[scrollAttr] = r2l? (parent.scrollWidth - parent.clientWidth - nodeStart[dir]) : nodeStart[dir]; |
| | 64 | } |
| | 65 | } |
| | 66 | delete xy[dir]; // prevent reprocessing as we walk up the parent hierarchy |
| | 67 | } |
| | 68 | } |
| | 69 | // stop looping if both scroll parents have been found |
| | 70 | if(xy.V === undefined && xy.H === undefined){ break; } |
| | 71 | parent = parent.parentNode; |