1
0
Fork 0
mirror of https://github.com/seejohnrun/haste-server.git synced 2024-11-01 03:21:21 +00:00

Declare function-local variables properly

Variables inside if-clauses are indeed hoisted to the top of the
enclosing scope. It's bad form to make `var` declarations inside an
if-clause.

sel is now function-local, rather than global :(
This commit is contained in:
Andrew Lorente 2014-07-23 14:21:24 -07:00
parent cfff6616e6
commit 9fc659be67

View file

@ -362,12 +362,13 @@ haste.prototype.configureShortcuts = function() {
///// Tab behavior in the textarea - 2 spaces per tab
$(function() {
$('textarea').keydown(function(evt) {
var sel, startPos, endPos, scrollTop,
myValue = ' ';
if (evt.ctrlKey || evt.keyCode !== 9) {
return true;
}
evt.preventDefault();
var myValue = ' ';
// http://stackoverflow.com/questions/946534/insert-text-into-textarea-with-jquery
// For browsers like Internet Explorer
if (document.selection) {
@ -378,9 +379,9 @@ $(function() {
}
// Mozilla and Webkit
else if (this.selectionStart || this.selectionStart == '0') {
var startPos = this.selectionStart;
var endPos = this.selectionEnd;
var scrollTop = this.scrollTop;
startPos = this.selectionStart;
endPos = this.selectionEnd;
scrollTop = this.scrollTop;
this.value = this.value.substring(0, startPos) + myValue +
this.value.substring(endPos,this.value.length);
this.focus();