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:
parent
cfff6616e6
commit
9fc659be67
1 changed files with 5 additions and 4 deletions
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue