Skip to content

Commit

Permalink
Bug fixing with small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
drakonoved committed Sep 17, 2017
1 parent bc654ab commit 0f3ba32
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
@@ -0,0 +1,2 @@
* linguist-vendored
*.js linguist-vendored=false
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
.idea
*.iml
31 changes: 15 additions & 16 deletions example.html → index.html
Expand Up @@ -20,19 +20,19 @@
}
h1{
font: bold 2em/1em "Optima", serif;
margin:0px;
padding:0px;
margin:0;
padding:0;
text-align: center;
padding-bottom: 25px;
text-shadow: 0px -1px 1px white, 0px 1px 0px #999;
text-shadow: 0 -1px 1px white, 0 1px 0 #999;
}
p{
padding-left: 15px;
padding-right: 15px;
padding-top: 10px;
padding-bottom: 10px;
margin: 0px;
text-shadow: 0px -1px 1px white, 0px 1px 0px #999;
margin: 0;
text-shadow: 0 -1px 1px white, 0 1px 0 #999;
}
b{
font-weight: 500;
Expand Down Expand Up @@ -67,16 +67,16 @@
text-decoration: underline;
}
h2{
margin: 0px;
padding: 0px;
margin: 0;
padding: 0;
padding-top: 30px;
}
h3{
font-size: .6em;
text-align: center;
font-weight: 200;
margin: 0px;
padding: 0px;
margin: 0;
padding: 0;
}
</style>
</head>
Expand All @@ -97,23 +97,22 @@ <h1>jQuery linenumbers plugin</h1>
But havent you ever wanted to have a textarea with fancy line numbers?
Problem? Solved.</textarea>
<p>By simply doing this...</p>
<code>$('document').ready(function(){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$('#line_numbers').linenumbers({col_width:'75px'});
})</code>
<code>&lt;script src="jquery-linenumbers.min.js">&lt;/script></code>
<p>neat huh. Line numbers make it easy to track the size of a text area, and look right at home if your dealing with code. It wraps lines intelligently, just because the textarea wraps doesn't mean it's actually a new line. How wonderful it recognizes that.</p>
<p>Setup is a snap, at it's simplest form all you have to do is call the linenumbers function like this...</p>
<code>.linenumbers()</code>
<p>If you want to get fancy there are some additional options you can pass...</p>
<ol>
<li><b>col_width</b>: <em>Default: 25px</em> The width of the numbers column. Default should be big enough for 4 columns on a text area with no styles applied. This will need to be modified for the number of digits you choose, and the textarea styles.</li>
<li><b>start</b>: <em>Default: 1</em> The number at which line numbering starts.</li>
<li><b>digits</b>: <em>Default 4</em> The number of digits the line numbers should max out at. This si used for calculating leading space, and does not include the colon.</li>
</ol>
<p>For example:</p>
<code>$('textarea').linenumbers({'20px', 1, 1});</code>
<p>You'll need to give your text area a set width, or the two line numbers won't line up right with the text, this has been tested as a px value, but percents should be ok in any format as long as the col_width is the same. Other than that it should work just fine. Internet Explorer has not been fully tested (due to the lack of a machine that can run it) but should work.</p>
<h2><a href="https://github.com/pgooch/jQueryLinenNumbersPlugin/zipball/master" target="_blank">Download</a></h2>
<h3>version 1.0.0 &mdash; May 27, 2012 &mdash; 4.80kb</h3>
<h2><a href="https://github.com/drakonoved/line-numbers/archive/master.zip" target="_blank">Download</a></h2>
<h3>version 1.0.2 &mdash; Sep 17, 2017 &mdash; 4.80kb</h3>
<p>Version History</p>
<ul>
<li><b>1.0.2</b> <em>Sep 17th 2017</em> Bug fixing.</li>
<li><b>1.0.0</b> <em>May 27th 2012</em> Initial release.</li>
</ul>
</body>
Expand Down
12 changes: 8 additions & 4 deletions jquery-linenumbers.js
Expand Up @@ -6,12 +6,15 @@
start: 1,
digits: 4.
},in_opts);
// Remove existing div and the textarea from previous run
$("[data-name='linenumbers']").remove();
// Function run
return this.each(function(){
// Get some numbers sorted out for the CSS changes
var new_textarea_width = (parseInt($(this).css('width'))-parseInt(opt.col_width))+'px';
// Create the div and the new textarea and style it
$(this).before('<div style="width:'+$(this).css('width')+';"><textarea style="width:'+new_textarea_width+';float:left;margin-right:'+'-'+new_textarea_width+';font-family:monospace;white-space:pre;overflow:hidden;" disabled="disabled"></textarea>');
$(this).after('<div style="clear:both;"></div></div>');
$(this).before('<div data-name="linenumbers" style="width:'+$(this).css('width')+';"><textarea data-name="linenumbers" style="width:'+new_textarea_width+';float:left;margin-right:'+'-'+new_textarea_width+';font-family:monospace;white-space:pre;overflow:hidden;" disabled="disabled"></textarea>');
$(this).after('<div data-name="linenumbers" style="clear:both;"></div></div>');
// Edit the existing textarea's styles
$(this).css({'font-family':'monospace','width':new_textarea_width,'float':'right'});
// Define a simple variable for the line-numbers box
Expand Down Expand Up @@ -44,7 +47,7 @@
$(lnbox).val(line_number_output);
// Change scroll position as they type, makes sure they stay in sync
$(lnbox).scrollTop($(this).scrollTop());
})
});
// Lock scrolling together, for mouse-wheel scrolling
$(this).scroll(function(){
$(lnbox).scrollTop($(this).scrollTop());
Expand All @@ -53,4 +56,5 @@
$(this).trigger('keyup');
});
};
})(jQuery);
})(jQuery);
$('textarea').linenumbers();
4 changes: 2 additions & 2 deletions jquery-linenumbers.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion readme.md
@@ -1,10 +1,17 @@
jQueryLineNumbersPlugin
=======================

This jQuery plugin will take any normal text area and give it line numbers. See the example for more infromation
This jQuery plugin will take any normal text area and give it line numbers. See the [example](https://drakonoved.github.io/line-numbers/) for more infromation

Usage
-----

Simple add this code to the head section of your page
```html
<head>
<script src="jquery-linenumbers.min.js"></script>
</head>
```
Simple call the linenumbers function an a text area element like so:
$('textarea').linenumbers();
Options can be passed via a object.
Expand All @@ -15,10 +22,17 @@ Plugin Options
2. start (Default: 1) The starting line number
3. digits (Default: 4) The number of digits the line numbers should max out at, this is used for lead space calculating and does _not_ include the colon.

To change default options run

```javascript
$('textarea').linenumbers({'20px', 1, 1});
```

License
-------
This plugin has been realsed under the GNU General Public License v3.0.

Version History
---------------
+ 1.0.2 • Sep 17th 2017 - _Bug fixing._
+ 1.0.0 • May 27th 2012 - _Initial release._

0 comments on commit 0f3ba32

Please sign in to comment.