Roozbeh Pournader![]()
This module provides the part of the Unicode Bidirectional Algorithm missing in browsers.
While the HTML standard requires the direction of every element to be specified or inherited, there are numerous times that a text string is entered by a user or received from a third party with no specified direction.
This module provides a method (Y.Intl.detectDirection) to detect the direction of a string according to the steps P1..P3 of the Unicode Bidirectional Algorithm.
The latest version supports the full range of Unicode 5.2 characters, including non-BMP characters.
Note: an older version of the module provided a method called bidiDirection. Although that method is still available for backward compatibility as an alias, please convert your code to use detectDirection.
<script src="http://yui.yahooapis.com/3.2.0/build/yui/yui-min.js"></script>YUI({
//Last Gallery Build of this module
gallery: 'gallery-2010.09.29-18-36'
}).use('gallery-intl-bidi', function(Y) {
// returns "ltr", since the first letter in the string is a "T", which is LTR.
alert(Y.Intl.detectDirection("The first letter of the Hebrew alphabet is \u05D0."));
// returns "rtl", since the first letter is a Hebrew Alef, which is RTL.
alert(Y.Intl.detectDirection("----\u05D0----"));
// returns "" (for neutral), since the string contains no letters.
alert(Y.Intl.detectDirection("--------"));
// returns "ltr", as that is specified as the fallback return value for neutral strings.
alert(Y.Intl.detectDirection("--------", "ltr"));
// returns "rtl", as that is specified as the fallback return value for neutral strings.
alert(Y.Intl.detectDirection("--------", "rtl"));
// returns "rtl", as although the fallback is specified to be LTR, the string is not neutral.
alert(Y.Intl.detectDirection("----\u05D0----", "ltr"));
});
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info