Skip to content

Commit

Permalink
Add Meteor support in 3 lines of code, make test independent of Compo…
Browse files Browse the repository at this point in the history
…nent
  • Loading branch information
dandv committed May 3, 2014
1 parent a210284 commit dc1289c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "textarea-caret-position",
"repo": "component/textarea-caret-position",
"version": "2.0.0",
"version": "2.1.0",
"description": "(x, y) coordinates of the caret in a textarea or input type='text'",
"development": {
"component/assert": "*"
Expand Down
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ var properties = [
];

var isFirefox = !(window.mozInnerScreenX == null);
module.exports = function (textarea, position, recalculate) {

var getCaretCoordinatesFn = function (element, position, recalculate) {
// mirrored div
var div = document.createElement('div');
div.id = 'input-textarea-caret-position-mirror-div';
Expand Down Expand Up @@ -97,3 +98,9 @@ module.exports = function (textarea, position, recalculate) {

return coordinates;
}

if (typeof Package !== 'undefined') {
getCaretCoordinates = getCaretCoordinatesFn; // Meteor
} else {
module.exports = getCaretCoordinatesFn; // Component
}
7 changes: 4 additions & 3 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>input and textarea caret-position testing ground</title>
<link rel="stylesheet" type="text/css" href="index.css">
<script src="../build/build.js"></script>
<script src="../index.js"></script>
<script src="../index.js"></script> <!-- this will trigger an `Uncaught ReferenceError: module is not defined`, which can be safely ignored -->
</head>
<body>
<p>Click anywhere in the text to see a red vertical line &ndash; a 1-pixel-thick
Expand Down Expand Up @@ -41,8 +41,9 @@
</textarea>

<script>
if (window.require) // if not in Component, allow the bare HTML demo to work
getCaretCoordinates = require('textarea-caret-position');
// if Component is not installed, allow the bare HTML demo to work
getCaretCoordinates = window.require ? require('textarea-caret-position') : getCaretCoordinatesFn;

['input[type="text"]', 'textarea'].forEach(function (selector) {
var element = document.querySelector(selector);
var fontSize = getComputedStyle(element).getPropertyValue('font-size');
Expand Down

0 comments on commit dc1289c

Please sign in to comment.