return $position;
},
+ /**
+ * Sets the caret position of current element. If the element
+ * does not equal input[type=text], input[type=password] or
+ * textarea, false is returned.
+ *
+ * @param integer position
+ * @return boolean
+ */
+ setCaret: function (position) {
+ if (this.getTagName() == 'input') {
+ if (this.attr('type') != 'text' && this.attr('type') != 'password') {
+ return false;
+ }
+ }
+ else if (this.getTagName() != 'textarea') {
+ return false;
+ }
+
+ var $element = this.get(0);
+
+ // set focus to enable caret on this element
+ this.focus();
+ if (document.selection) { // IE 8
+ var $selection = document.selection.createRange();
+ $selection.moveStart('character', position);
+ $selection.moveEnd('character', 0);
+ $selection.select();
+ }
+ else if ($element.selectionStart || $element.selectionStart == '0') { // Opera, Chrome, Firefox, Safari, IE 9+
+ $element.selectionStart = position;
+ $element.selectionEnd = position;
+ }
+
+ return true;
+ },
+
/**
* Shows an element by sliding and fading it into viewport.
*