GithubHelp home page GithubHelp logo

isabella232 / rtltextarea Goto Github PK

View Code? Open in Web Editor NEW

This project forked from twitter-archive/rtltextarea

0.0 0.0 0.0 394 KB

Automatically detects RTL and configures a text input

License: MIT License

JavaScript 95.54% CSS 3.59% HTML 0.88%

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

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.