jQuery and MouseTrap
Testing MouseTrap
by litespeedtdf
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/mousetrap/1.6.2/mousetrap.js"></script>
<input id="password" class="disabledAutoFillPassword" type="text" />
</br>
</br>
<button id="testIt">
Test It
</button>
</br>
</br>
<button id="clear">
Clear
</button>
</br>
</br>
<textarea id="result" rows="20" cols="50" readonly></textarea >
CSS
input{
color:black;
font-size:14px;
background-color:lightgray;
border-radius:5px;
border:1px solid #d6d6d6;
}
JavaScript
/**
* jquery-textrange
*
* A jQuery plugin for getting, setting and replacing the selected text in input fields and textareas.
* See the [README](https://github.com/dwieeb/jquery-textrange/blob/1.x/README.md) for usage and examples.
*
* (c) 2012-2017 Daniel Imhoff <[email protected]> - dwieeb.com
*/
(function(factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery'], factory);
} else if (typeof exports === 'object') {
factory(require('jquery'));
} else {
factory(jQuery);
}
})(function($) {
var browserType,
textrange = {
/**
* $().textrange() or $().textrange('get')
*
* Retrieves an object containing the start and end location of the text range, the length of the range and the
* substring of the range.
*
* @param (optional) property
* @return An object of properties including position, start, end, length, and text or a specific property.
*/
get: function(property) {
return _textrange[browserType].get.apply(this, [property]);
},
/**
* $().textrange('set')
*
* Sets the selected text of an object by specifying the start and length of the selection.
*
* The start and length parameters are identical to PHP's substr() function with the following changes:
* - excluding start will select all the text in the field.
* - passing 0 for length will set the cursor at start. See $().textrange('setcursor')
*
* @param (optional) start
* @param (optional) length
*
* @see https://secure.php.net/manual/en/function.substr.php
*/
set: function(start, length) {
var s = parseInt(start),
l = parseInt(length),
e;
if (typeof start === 'undefined') {
s = 0;
} else if (start < 0) {
s = this[0].value.length + s;
}
if (typeof length !== 'undefined') {
if (length >= 0) {
e = s + l;
} else {
e = this[0].value.length + l;
}
}
_textrange[browserType].set.apply(this, [s, e]);
return this;
},
/**
*...