mirror of
https://github.com/toptal/haste-server.git
synced 2024-11-26 12:36:21 +01: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:
parent
cfff6616e6
commit
9fc659be67
@ -362,12 +362,13 @@ haste.prototype.configureShortcuts = function() {
|
|||||||
///// Tab behavior in the textarea - 2 spaces per tab
|
///// Tab behavior in the textarea - 2 spaces per tab
|
||||||
$(function() {
|
$(function() {
|
||||||
$('textarea').keydown(function(evt) {
|
$('textarea').keydown(function(evt) {
|
||||||
|
var sel, startPos, endPos, scrollTop,
|
||||||
|
myValue = ' ';
|
||||||
if (evt.ctrlKey || evt.keyCode !== 9) {
|
if (evt.ctrlKey || evt.keyCode !== 9) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
var myValue = ' ';
|
|
||||||
// http://stackoverflow.com/questions/946534/insert-text-into-textarea-with-jquery
|
// http://stackoverflow.com/questions/946534/insert-text-into-textarea-with-jquery
|
||||||
// For browsers like Internet Explorer
|
// For browsers like Internet Explorer
|
||||||
if (document.selection) {
|
if (document.selection) {
|
||||||
@ -378,9 +379,9 @@ $(function() {
|
|||||||
}
|
}
|
||||||
// Mozilla and Webkit
|
// Mozilla and Webkit
|
||||||
else if (this.selectionStart || this.selectionStart == '0') {
|
else if (this.selectionStart || this.selectionStart == '0') {
|
||||||
var startPos = this.selectionStart;
|
startPos = this.selectionStart;
|
||||||
var endPos = this.selectionEnd;
|
endPos = this.selectionEnd;
|
||||||
var scrollTop = this.scrollTop;
|
scrollTop = this.scrollTop;
|
||||||
this.value = this.value.substring(0, startPos) + myValue +
|
this.value = this.value.substring(0, startPos) + myValue +
|
||||||
this.value.substring(endPos,this.value.length);
|
this.value.substring(endPos,this.value.length);
|
||||||
this.focus();
|
this.focus();
|
||||||
|
Loading…
Reference in New Issue
Block a user