@@ -218,25 +218,7 @@ firebaseui.auth.AuthUI.prototype.isPending = function() {
218218 */
219219firebaseui . auth . AuthUI . prototype . start = function ( element , config ) {
220220 var self = this ;
221- var onReady = function ( ) {
222- var resetWarning = 'UI Widget is already rendered on the page and is pen' +
223- 'ding some user interaction. Only one widget instance can be rendere' +
224- 'd per page. The previous instance has been automatically reset.' ;
225- // Only one auth instance can be rendered per page. This is because
226- // accountchooser.com callbacks are set once to the AuthUI instance that
227- // first calls them.
228- if ( firebaseui . auth . AuthUI . widgetAuthUi_ ) {
229- // Already rendered, automatically reset.
230- // First check if there is a pending operation on that widget, if so,
231- // log a reset warning to the console.
232- if ( firebaseui . auth . AuthUI . widgetAuthUi_ . isPending ( ) ) {
233- firebaseui . auth . log . warning ( resetWarning ) ;
234- }
235- firebaseui . auth . AuthUI . widgetAuthUi_ . reset ( ) ;
236- }
237- // Set widget AuthUI as current instance.
238- firebaseui . auth . AuthUI . widgetAuthUi_ = self ;
239- } ;
221+
240222 // There is a problem when config in second call modifies accountchooser.com
241223 // related config. eg. acUiConfig
242224 // These changes will be ignored as only the first accountchooser.com related
@@ -247,31 +229,61 @@ firebaseui.auth.AuthUI.prototype.start = function(element, config) {
247229 // Wrap it in a onload callback to wait for the DOM element is rendered.
248230 // If document already loaded, render immediately.
249231 if ( doc . readyState == 'complete' ) {
250- // Confirm element exists.
251- var container = firebaseui . auth . util . getElement (
252- element , firebaseui . auth . AuthUI . ELEMENT_NOT_FOUND_ ) ;
253- onReady ( ) ;
254- self . widgetElement_ = container ;
255- // Initialize widget page change listener.
256- self . initPageChangeListener_ ( container ) ;
257- // Document already loaded, render on demand.
258- firebaseui . auth . widget . dispatcher . dispatchOperation ( self , element ) ;
232+ this . initElement_ ( element ) ;
259233 } else {
260234 // Document not ready, wait for load before rendering.
261235 goog . events . listenOnce ( window , goog . events . EventType . LOAD , function ( ) {
262- // Confirm element exists.
263- var container = firebaseui . auth . util . getElement (
264- element , firebaseui . auth . AuthUI . ELEMENT_NOT_FOUND_ ) ;
265- onReady ( ) ;
266- self . widgetElement_ = container ;
267- // Initialize widget page change listener.
268- self . initPageChangeListener_ ( container ) ;
269- firebaseui . auth . widget . dispatcher . dispatchOperation ( self , element ) ;
236+ self . initElement_ ( element ) ;
270237 } ) ;
271238 }
272239} ;
273240
274241
242+ /**
243+ * Initializes the FirebaseUI element.
244+ * @param {string|!Element } element The container element or the query selector.
245+ * @private
246+ */
247+ firebaseui . auth . AuthUI . prototype . initElement_ = function ( element ) {
248+ // Confirm element exists.
249+ var container = firebaseui . auth . util . getElement (
250+ element , firebaseui . auth . AuthUI . ELEMENT_NOT_FOUND_ ) ;
251+
252+ // Set the "lang" attribute; without this, there are subtle rendering errors
253+ // like vowel capitalization in Turkish.
254+
255+ // Make sure the locale uses hyphens instead of strings.
256+ var locale = goog . LOCALE . replace ( / _ / g, '-' ) ;
257+ container . setAttribute ( 'lang' , locale ) ;
258+
259+ // Only one auth instance can be rendered per page. This is because
260+ // accountchooser.com callbacks are set once to the AuthUI instance that
261+ // first calls them.
262+ if ( firebaseui . auth . AuthUI . widgetAuthUi_ ) {
263+ // Already rendered, automatically reset.
264+ // First check if there is a pending operation on that widget, if so,
265+ // log a reset warning to the console.
266+ if ( firebaseui . auth . AuthUI . widgetAuthUi_ . isPending ( ) ) {
267+ var resetWarning = 'UI Widget is already rendered on the page and is ' +
268+ 'pending some user interaction. Only one widget instance can be ' +
269+ 'rendered per page. The previous instance has been automatically ' +
270+ 'reset.' ;
271+ firebaseui . auth . log . warning ( resetWarning ) ;
272+ }
273+ firebaseui . auth . AuthUI . widgetAuthUi_ . reset ( ) ;
274+ }
275+
276+ // Set widget AuthUI as current instance.
277+ firebaseui . auth . AuthUI . widgetAuthUi_ = this ;
278+
279+ this . widgetElement_ = container ;
280+ // Initialize widget page change listener.
281+ this . initPageChangeListener_ ( container ) ;
282+ // Document already loaded, render on demand.
283+ firebaseui . auth . widget . dispatcher . dispatchOperation ( this , element ) ;
284+ } ;
285+
286+
275287/**
276288 * Registers a pending promise or reset function.
277289 * @param {?goog.Promise|?firebase.Promise|?function() } p The pending promise.
@@ -304,6 +316,11 @@ firebaseui.auth.AuthUI.prototype.getAuthUiGetter = function() {
304316
305317/** Reset rendered widget and removes it from display. */
306318firebaseui . auth . AuthUI . prototype . reset = function ( ) {
319+ // Remove the "lang" attribute that we set in start().
320+ if ( this . widgetElement_ ) {
321+ this . widgetElement_ . removeAttribute ( 'lang' ) ;
322+ }
323+
307324 // After reset, if the sign-in widget callback is called again, it should not
308325 // resolve with the previous redirect result.
309326 this . getRedirectResult_ =
0 commit comments