Coder Social home page Coder Social logo

madapaja / jquery.selection Goto Github PK

View Code? Open in Web Editor NEW
191.0 191.0 38.0 755 KB

selection text/caret operation - jQuery pulgin | 選択範囲のテキスト操作 / キャレット操作

Home Page: http://madapaja.github.com/jquery.selection/

JavaScript 100.00%

jquery.selection's People

Contributors

ajaxsys avatar madapaja avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery.selection's Issues

Uncaught TypeError: Cannot read property 'substr' of undefined

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>

minimized version missing

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

Being able to select/change contentEditable Div

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

that has its attribute set for contentEditable.

Please let me know when you've got that working.

Again: Awesome Job. Utterly clean code!

John

Implement undo/redo when changing the content of the textarea

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! ;)

[enhancement] Add missing bower.json.

Hey, maintainer(s) of madapaja/jquery.selection!

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!

Get selection text with nothing

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.