Add blinkInterval option to cursor
This commit is contained in:
parent
4a38512616
commit
aa9962aafd
1 changed files with 16 additions and 6 deletions
|
|
@ -40,6 +40,7 @@ var Cursor = function(parentEl) {
|
||||||
|
|
||||||
this.isVisible = false;
|
this.isVisible = false;
|
||||||
this.isBlinking = true;
|
this.isBlinking = true;
|
||||||
|
this.blinkInterval = 1000;
|
||||||
|
|
||||||
this.cursors = [];
|
this.cursors = [];
|
||||||
this.cursor = this.addCursor();
|
this.cursor = this.addCursor();
|
||||||
|
|
@ -57,8 +58,17 @@ var Cursor = function(parentEl) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setBlinking = function(blinking) {
|
this.setBlinking = function(blinking) {
|
||||||
this.isBlinking = blinking;
|
if (blinking != this.isBlinking){
|
||||||
this.resetTimer();
|
this.isBlinking = blinking;
|
||||||
|
this.resetTimer();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.setBlinkInterval = function(blinkInterval) {
|
||||||
|
if (blinkInterval != this.blinkInterval){
|
||||||
|
this.blinkInterval = blinkInterval;
|
||||||
|
this.resetTimer();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.addCursor = function() {
|
this.addCursor = function() {
|
||||||
|
|
@ -103,7 +113,7 @@ var Cursor = function(parentEl) {
|
||||||
for (var i = this.cursors.length; i--; )
|
for (var i = this.cursors.length; i--; )
|
||||||
this.cursors[i].style.visibility = "";
|
this.cursors[i].style.visibility = "";
|
||||||
|
|
||||||
if (!this.isBlinking || !this.isVisible)
|
if (!this.isBlinking || !this.blinkInterval || !this.isVisible)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var blink = function(){
|
var blink = function(){
|
||||||
|
|
@ -111,7 +121,7 @@ var Cursor = function(parentEl) {
|
||||||
for (var i = this.cursors.length; i--; ) {
|
for (var i = this.cursors.length; i--; ) {
|
||||||
this.cursors[i].style.visibility = "hidden";
|
this.cursors[i].style.visibility = "hidden";
|
||||||
}
|
}
|
||||||
}.bind(this), 0.6 * 1000);
|
}.bind(this), 0.6 * this.blinkInterval);
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
this.intervalId = setInterval(function() {
|
this.intervalId = setInterval(function() {
|
||||||
|
|
@ -119,7 +129,7 @@ var Cursor = function(parentEl) {
|
||||||
this.cursors[i].style.visibility = "";
|
this.cursors[i].style.visibility = "";
|
||||||
}
|
}
|
||||||
blink();
|
blink();
|
||||||
}.bind(this), 1000);
|
}.bind(this), this.blinkInterval);
|
||||||
|
|
||||||
blink();
|
blink();
|
||||||
};
|
};
|
||||||
|
|
@ -196,7 +206,7 @@ var Cursor = function(parentEl) {
|
||||||
this.destroy = function() {
|
this.destroy = function() {
|
||||||
clearInterval(this.intervalId);
|
clearInterval(this.intervalId);
|
||||||
clearTimeout(this.timeoutId);
|
clearTimeout(this.timeoutId);
|
||||||
}
|
};
|
||||||
|
|
||||||
}).call(Cursor.prototype);
|
}).call(Cursor.prototype);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue