Skip to content

Commit f754e50

Browse files
committed
- Added JavaScript to add placeholders to input fields and text areas with a click.
1 parent 0f603d7 commit f754e50

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

interface/web/js/scrigo.js.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,3 +582,36 @@ function getRandomInt(min, max){
582582
return Math.floor(Math.random() * (max - min + 1)) + min;
583583
}
584584

585+
jQuery('.addPlaceholder').live("click", function(){
586+
var placeholderText = jQuery(this).text();
587+
var template = jQuery(this).siblings(':input');
588+
template.insertAtCaret(placeholderText);
589+
});
590+
591+
jQuery.fn.extend({
592+
insertAtCaret: function(myValue){
593+
return this.each(function(i) {
594+
if (document.selection) {
595+
//For browsers like Internet Explorer
596+
this.focus();
597+
sel = document.selection.createRange();
598+
sel.text = myValue;
599+
this.focus();
600+
} else if (this.selectionStart || this.selectionStart == '0') {
601+
//For browsers like Firefox and Webkit based
602+
var startPos = this.selectionStart;
603+
var endPos = this.selectionEnd;
604+
var scrollTop = this.scrollTop;
605+
this.value = this.value.substring(0, startPos)+myValue+this.value.substring(endPos,this.value.length);
606+
this.focus();
607+
this.selectionStart = startPos + myValue.length;
608+
this.selectionEnd = startPos + myValue.length;
609+
this.scrollTop = scrollTop;
610+
} else {
611+
this.value += myValue;
612+
this.focus();
613+
}
614+
})
615+
}
616+
});
617+

0 commit comments

Comments
 (0)