madapaja / jquery.selection Goto Github PK
View Code? Open in Web Editor NEWselection text/caret operation - jQuery pulgin | 選択範囲のテキスト操作 / キャレット操作
Home Page: http://madapaja.github.com/jquery.selection/
selection text/caret operation - jQuery pulgin | 選択範囲のテキスト操作 / キャレット操作
Home Page: http://madapaja.github.com/jquery.selection/
Hi! :)
Great plugin, I'm gonna use it for my project, but I think it's missing something really interesting : the ability to undo/redo (ctrl+z / ctrl+shit+z) from the natural work of the browser.
Let me explain
If you write on a textarea, and then hit ctrl+z, you'll do a undo changes (based on your browser).
But if you do a insert/replace from your code, and then hit ctrl+z, it won't work.
The idea behind it is to not change the val() of the textarea, but use the builtin changes of the browser, like this :
var element = document.getElementById('someTextarea');
var text = 'This text will be inserted in the textarea';
var event = document.createEvent('TextEvent');
event.initTextEvent('textInput', true, true, null, text);
element.dispatchEvent(event); // fire the event on the the textarea
(source: http://stackoverflow.com/questions/7553430/javascript-textarea-undo-redo)
Drawback: this does not work in IE9 and Firefox :/
(Maybe i'm asking for an unicorn feature ?)
Here's a possible implementation :
http://stackoverflow.com/questions/19814465/is-it-possible-to-insert-text-in-textarea-and-update-undo-redo-queue
And for IE (11) : http://stackoverflow.com/questions/20124212/internet-explorer-alternative-to-document-execcommandinserttext-for-tex
In case you have some spare time! ;)
Hi, looks like a nice plugin.
It seems this plugin cannot modify normal html text.
When you select words in the following example, you get an error, Uncaught TypeError: Cannot read property 'substr' of undefined
.
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
<script type="text/javascript" src="src/jquery.selection.js"></script>
</head>
<body>
<div class="content">
<p id="laten-text">Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts.</p>
</div>
<script>
$( document ).ready( function() {
$( '.content p' ).click(function(){
$( this )
.selection('insert', {text: '<strong>', mode: 'before'})
.selection('insert', {text: '</strong>', mode: 'after'});
});
});
</script>
</body>
</html>
Hello madapaja,
is there any chance to have your js included in google apis ?
anyway, source is 13kB, compressed 4kB, compressed version would be really nice on line
best regards
Adam Sida from Prague, Czech rep., Europe
Hi.
I created gem for Ruby on Rails.
https://github.com/camelmasa/jquery-selection-rails
Madapaja,
First and foremost - your code is awesome!
It works beautifully for input text-boxes and text areas.
However, where I'm having a problem is trying to use it for a
Please let me know when you've got that working.
Again: Awesome Job. Utterly clean code!
John
Hi.
I want a method to get the selection text in the page without know if there is a textarea or html text.
Something that:
var text = $(document).selection();
Regards.
We at VersionEye are working hard to keep up the quality of the bower's registry.
We just finished our initial analysis of the quality of the Bower.io registry:
7530 - registered packages, 224 of them doesnt exists anymore;
We analysed 7306 existing packages and 1070 of them don't have bower.json on the master branch ( that's where a Bower client pulls a data ).
Sadly, your library madapaja/jquery.selection
is one of them.
Can you spare 15 minutes to help us to make Bower better?
Just add a new file bower.json
and change attributes.
{
"name": "madapaja/jquery.selection",
"version": "1.0.0",
"main": "path/to/main.css",
"description": "please add it",
"license": "Eclipse",
"ignore": [
".jshintrc",
"**/*.txt"
],
"dependencies": {
"<dependency_name>": "<semantic_version>",
"<dependency_name>": "<Local_folder>",
"<dependency_name>": "<package>"
},
"devDependencies": {
"<test-framework-name>": "<version>"
}
}
Read more about bower.json on the official spefication and nodejs semver library has great examples of proper versioning.
NB! Please validate your bower.json with jsonlint before commiting your updates.
Thank you!
Timo,
twitter: @versioneye
email: [email protected]
VersionEye - no more legacy software!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.