Giter VIP home page Giter VIP logo

rtltextarea's Introduction

RTLtextarea Build Status

Automatically detects RTL (right-to-left) languages and appropriately configures the text input, without having to manually specify CSS direction or dir property on page load. Allows automatic switching between LTR and RTL languages.

What it does

This module will set the direction of a textarea to RTL when a threshold of RTL characters has been reached (rtlThreshold). It also applies Twitter- specific RTL rules regarding the placement of @ signs, # tags, and URLs.

Before:

before

After:

before

How to use

Bind keyup and keydown to RTLText.onTextChange. If you have initial text, call RTLText.setText(textarea, initial_string) to set markers on that initial text.

  $(document).ready(function(){
    var $textarea = $('#someTextarea');
    $textarea.on('keyup', RTLText.onTextChange);
    $textarea.on('keydown', RTLText.onTextChange);
    RTLText.setText($textarea.get(0), $textarea.val());
  });

When storing or submitting the text, make sure to extract the unicode markers first:

  var textToSubmit = RTLText.cleanText($("#someTextarea").val());

Get the length of the text minus the control characters:

  var textLength = RTLText.textLength($("#someTextarea").val());

Add markers to a string without affecting the text box:

  var stringWithMarkers = RTLText.addRTLMarkers(string);

Versioning

We use semantic versioning, as described here: http://semver.org/

Releases are numbered and constructed with the following guidelines:

  • Breaking backwards compatibility bumps the major
  • New additions without breaking backwards compatibility bumps the minor
  • Bug fixes and misc changes bump the patch

Testing

Tests use Jasmine and PhantomJS.

Before running the tests for the first time, install the required packages by typing: npm update.

After the packages are installed, you can run the tests by typing: npm test.

Authors

Naoki Takano

Esten Hurtle

License

Copyright 2012 Twitter, Inc.

Licensed under the MIT License

rtltextarea's People

Contributors

alunny avatar amire80 avatar caniszczyk 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  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

rtltextarea's Issues

'twttr' is not defined

The variable twttr is not defined. I suppose that it is loaded in a Twitter library.

It would be nice to make this library independent of Twitter code.

Arabic string not switching to RTL

This string:

أنا عربي

is in Arabic (it says 'I'm Arab'), and does not seem to work as in:

http://jsbin.com/ifiyit/6/edit

The result of calling JavaScripts native escape() passing the previous string to it was:

%u0623%u0646%u0627%20%u0639%u0631%u0628%u064A

Interestingly, it works on twitter tweet box though.

RTLTextarea not working properly or is it correct?

I have built a jsfiddle on http://jsfiddle.net/un92atkn/ , if you enter some arabic text in it, it works great. But when you split an arabic word with 2 spaces and in the middle of the spaces you enter a hash tag followed by a latin character, the caret position jumps to the end of the text. Is this behavior ok or not?

For example. If I enter the word: الجديدة

When I move my cursor to the center and add 2 spaces and move the cursor to the middle of the two spaces and enter a hashtag followed by a character [a-z] , the caret jumps to the end.

rtlHashtag, oldText and getSelection don't seem to be used

JSHint reports the variables rtlHashtag and oldText and the function getSelection() as defined, but never used. It seems to be correct - they aren't used in their scope in the RTLtext function. They should probably be removed, but I may be missing something.

shouldBeRTL function with weird length?

In the shouldBeRTL function the urlMentionsLength measures the length of the url and the mentions so it can be removed from the actual length for determining which characters are rtl or not. But there is also a + 1 and a + 2, can anybody explain why that is? For the length of a mention it could be the extra @ sign, but for the url I can't find a valid explanation.

for (i = 0; i < mentionsLength; i++) { 
    urlMentionsLength += mentions[i].screenName.length + 1; 
}

for (i = 0; i < urlsLength; i++) { 
  urlMentionsLength += urls[i].url.length + 2; 
}

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.