@@ -89,12 +89,36 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in
8989 return $options . getOption ? $options . getOption ( optionName ) : $options [ optionName ] ;
9090 } ,
9191
92+ /**
93+ * Determines the current 'dir'ectional value based on the value of 'dir'
94+ * attribute of the element. If that is not defined, it will try to use
95+ * a 'dir' attribute of the body or html tag.
96+ *
97+ * @param {Object= } attrs a hash object with key-value pairs of normalized
98+ * attribute names and their corresponding attribute values.
99+ * @returns {boolean } true if the element's passed in attributes,
100+ * the document, or the body indicates RTL mode, false otherwise.
101+ */
102+ isRtl : function ( attrs ) {
103+ var dir = angular . isDefined ( attrs ) && attrs . hasOwnProperty ( 'dir' ) && attrs . dir ;
104+
105+ switch ( dir ) {
106+ case 'ltr' :
107+ return false ;
108+
109+ case 'rtl' :
110+ return true ;
111+ }
112+
113+ return ( $document [ 0 ] . dir === 'rtl' || $document [ 0 ] . body . dir === 'rtl' ) ;
114+ } ,
115+
92116 /**
93117 * Bi-directional accessor/mutator used to easily update an element's
94118 * property based on the current 'dir'ectional value.
95119 */
96- bidi : function ( element , property , lValue , rValue ) {
97- var ltr = ! ( $document [ 0 ] . dir == 'rtl' || $document [ 0 ] . body . dir == 'rtl' ) ;
120+ bidi : function ( element , property , lValue , rValue ) {
121+ var ltr = ! this . isRtl ( ) ;
98122
99123 // If accessor
100124 if ( arguments . length == 0 ) return ltr ? 'ltr' : 'rtl' ;
@@ -111,7 +135,7 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in
111135 } ,
112136
113137 bidiProperty : function ( element , lProperty , rProperty , value ) {
114- var ltr = ! ( $document [ 0 ] . dir == 'rtl' || $document [ 0 ] . body . dir == 'rtl' ) ;
138+ var ltr = ! this . isRtl ( ) ;
115139
116140 var elem = angular . element ( element ) ;
117141
0 commit comments