root / drupal7 / sites / all / modules / token_insert / token_insert.js @ 5a4b9049
1 |
/*jshint strict:true, browser:true, curly:true, eqeqeq:true, expr:true, forin:true, latedef:true, newcap:true, noarg:true, trailing: true, undef:true, unused:true */
|
---|---|
2 |
/*global jQuery: true*/
|
3 |
// General Insert API functions.
|
4 |
(function ($) { |
5 |
"use strict";
|
6 |
$.fn.insertAtCursor = function (tagName) { |
7 |
return this.each(function(){ |
8 |
if (document.selection) {
|
9 |
//IE support
|
10 |
this.focus();
|
11 |
var sel = document.selection.createRange();
|
12 |
sel.text = tagName; |
13 |
this.focus();
|
14 |
} |
15 |
else if (this.selectionStart || this.selectionStart === 0) { |
16 |
//MOZILLA/NETSCAPE support
|
17 |
var startPos = this.selectionStart; |
18 |
var endPos = this.selectionEnd; |
19 |
var scrollTop = this.scrollTop; |
20 |
this.value = this.value.substring(0, startPos) + tagName + this.value.substring(endPos,this.value.length); |
21 |
this.focus();
|
22 |
this.selectionStart = startPos + tagName.length;
|
23 |
this.selectionEnd = startPos + tagName.length;
|
24 |
this.scrollTop = scrollTop;
|
25 |
} else {
|
26 |
this.value += tagName;
|
27 |
this.focus();
|
28 |
} |
29 |
}); |
30 |
}; |
31 |
})(jQuery); |
32 |
|