RTLtextarea

自动检测 RTL 并配置文本输入。「Automatically detects RTL and configures a text input」

  • 所有者: twitter-archive/RTLtextarea
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

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

主要指标

概览
名称与所有者twitter-archive/RTLtextarea
主编程语言JavaScript
编程语言JavaScript (语言数: 3)
平台
许可证MIT License
所有者活动
创建于2012-12-21 17:35:49
推送于2018-09-14 04:18:09
最后一次提交2015-10-29 14:47:11
发布数1
最新版本名称v1.0.0 (发布于 2012-12-21 09:43:43)
第一版名称v1.0.0 (发布于 2012-12-21 09:43:43)
用户参与
星数169
关注者数117
派生数25
提交数54
已启用问题?
问题数8
打开的问题数2
拉请求数14
打开的拉请求数3
关闭的拉请求数2
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?