Created
August 26, 2014 00:39
-
-
Save alanhogan/1657b3a6c8e58079a4a2 to your computer and use it in GitHub Desktop.
CoffeeScript Require.js Module for jQuery-based element selection on click
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ = require 'jquery' | |
module.exports = do -> | |
init = -> | |
$(document).on 'click', '.js-autoselect', (e) -> | |
range = document.createRange() | |
selection = window.getSelection() | |
range.selectNodeContents this | |
selection.removeAllRanges() | |
selection.addRange range | |
return | |
{ | |
init: init | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IE9+, I believe, and of course Chrome, Safari, Firefox are supported
Note this does not work on at least some mobile browsers, including Mobile Safari (as of iOS 7.0) as they seem to not support programmatic selection of non-editable text (including
<input readonly>
)