Skip to content

Commit

Permalink
Demo: Add debug checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Mottie committed Feb 20, 2016
1 parent fcbb626 commit 85d35b7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
36 changes: 23 additions & 13 deletions test/index.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
input[type="text"], textarea {
font-family: 'Times New Roman'; /* a proportional font makes it more difficult to calculate the position */
font-size: 14px;
line-height: 16px;
padding: 24px 32px 16px 8px; /* different paddings so position computations don't accidentally return a "correct" result */
text-transform: uppercase; /* this drastically changes character width on proportional fonts */
text-indent: 20px;
border: 16px lightblue dotted; /* needs to be accounted for when returning the final position */
border-right-width: 24px; /* discourage naive border arithmetic */
background: lightyellow;
tab-size: 20;
-moz-tab-size: 20;
}
input[type="text"], textarea {
font-family: 'Times New Roman'; /* a proportional font makes it more difficult to calculate the position */
font-size: 14px;
line-height: 16px;
padding: 24px 32px 16px 8px; /* different paddings so position computations don't accidentally return a "correct" result */
text-transform: uppercase; /* this drastically changes character width on proportional fonts */
text-indent: 20px;
border: 16px lightblue dotted; /* needs to be accounted for when returning the final position */
border-right-width: 24px; /* discourage naive border arithmetic */
background: lightyellow;
tab-size: 20;
-moz-tab-size: 20;
}
body {
width: 400px;
position: relative;
}
#input-textarea-caret-position-mirror-div {
background: #ddd;
position: fixed;
top: 150px;
left: 400px;
}
8 changes: 7 additions & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

<input type="text" size="15" maxlength="240" placeholder="Enter text here">

<hr/>
<label>
<input type="checkbox" id="mirrorDivDisplay">Show mirror div
</label>
<hr/>

<textarea rows="25" cols="40">
Expand Down Expand Up @@ -57,7 +61,9 @@

function update() {
// change debug option to true for testing purposes only!
var coordinates = getCaretCoordinates(element, element.selectionEnd, { debug: !true });
var coordinates = getCaretCoordinates(element, element.selectionEnd, {
debug: document.getElementById('mirrorDivDisplay').checked
});
console.log('(top, left) = (%s, %s)', coordinates.top, coordinates.left);
rect.style.top = element.offsetTop
- element.scrollTop
Expand Down

0 comments on commit 85d35b7

Please sign in to comment.