| 1404 | |
| 1405 | // Get the browser window. |
| 1406 | var browserWindow = new CKEDITOR.dom.window (window), |
| 1407 | browserWinHeight = browserWindow.getViewPaneSize().height; |
| 1408 | |
| 1409 | // Get the editor document |
| 1410 | var editorDocument = this.getDocument(); |
| 1411 | |
| 1412 | //Find the current instance of the editor - is there an easier way to get the current editor instance? |
| 1413 | var ckInstances = CKEDITOR.instances; |
| 1414 | var currentInstance; |
| 1415 | for (var i in ckInstances){ |
| 1416 | if (ckInstances[i].document.equals(editorDocument)){ |
| 1417 | currentInstance = i; |
| 1418 | break; |
| 1419 | } |
| 1420 | } |
| 1421 | |
| 1422 | //find the iframe element of the current instance and gets it's document position i.e. the position of the iframe in the HTML page - is there a better way to get the iframe element? |
| 1423 | var iframePosition = ckInstances[currentInstance].container.getElementsByTag('iframe').getItem(0).getDocumentPosition(); |
1432 | | win.$.scrollTo( 0, offset ); |
| 1449 | win.$.scrollTo( 0, offset > 0 ? offset : 0 ); // offset value might be out of range(nagative), fix it(#3692). |
| 1450 | |
| 1451 | |
| 1452 | // Scroll the browser window to the desired position, if not already visible |
| 1453 | var browserOffset = iframePosition.y + (elementPosition.y - win.getScrollPosition().y); |
| 1454 | var currentBrowserScroll = browserWindow.getScrollPosition().y; |
| 1455 | if (browserOffset < currentBrowserScroll || browserOffset > (currentBrowserScroll + browserWinHeight)) |
| 1456 | browserWindow.$.scrollTo( 0, browserOffset); |
| 1457 | |