~ahasenack/lazr-js/lazr-js-11.03-packaging

« back to all changes in this revision

Viewing changes to src-js/lazrjs/yui/node-focusmanager/node-focusmanager.js

  • Committer: Sidnei da Silva
  • Date: 2010-04-08 14:44:59 UTC
  • mfrom: (166.8.13 yui-3.1.0)
  • Revision ID: sidnei.da.silva@canonical.com-20100408144459-qozybvnrgr7iee7k
Merged yui-3.1.0 [r=therve,rockstar] [f=558457].

Updates lazr-js to use YUI 3.1.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
 
2
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3
3
Code licensed under the BSD License:
4
 
http://developer.yahoo.net/yui/license.txt
5
 
version: 3.0.0
6
 
build: 1549
 
4
http://developer.yahoo.com/yui/license.html
 
5
version: 3.1.0
 
6
build: 2026
7
7
*/
8
8
YUI.add('node-focusmanager', function(Y) {
9
9
 
312
312
                        nDescendants = descendants.size();
313
313
                        
314
314
 
315
 
                        if (nDescendants > 1) {
316
 
 
317
 
                                for (i = 0; i < nDescendants; i++) {
318
 
 
319
 
                                        oNode = descendants.item(i);
320
 
 
321
 
                                        if (nFirstEnabled === -1 && !oNode.get(DISABLED)) {
322
 
                                                nFirstEnabled = i;
323
 
                                        }
324
 
 
325
 
 
326
 
                                        //      If the user didn't specify a value for the 
327
 
                                        //      "activeDescendant" attribute try to infer it from 
328
 
                                        //      the markup.
329
 
 
330
 
                                        //      Need to pass "2" when using "getAttribute" for IE to get
331
 
                                        //      the attribute value as it is set in the markup.
332
 
                                        //      Need to use "parseInt" because IE always returns the 
333
 
                                        //      value as a number, whereas all other browsers return
334
 
                                        //      the attribute as a string when accessed 
335
 
                                        //      via "getAttribute".
336
 
 
337
 
                                        if (nActiveDescendant < 0 && 
338
 
                                                        parseInt(oNode.getAttribute(TAB_INDEX, 2), 10) === 0) {
339
 
 
340
 
                                                nActiveDescendant = i;
341
 
 
342
 
                                        }
343
 
 
344
 
                                        oNode.set(TAB_INDEX, -1);
345
 
 
346
 
                                        sID = oNode.get(ID);
347
 
 
348
 
                                        if (!sID) {
349
 
                                                sID = Y.guid();
350
 
                                                oNode.set(ID, sID);
351
 
                                        }
352
 
                                        
353
 
                                        descendantsMap[sID] = i;
354
 
                                        
355
 
                                }
356
 
                                
357
 
 
358
 
                                //      If the user didn't specify a value for the  
359
 
                                //      "activeDescendant" attribute and no default value could be 
360
 
                                //      determined from the markup, then default to 0.
361
 
                                
362
 
                                if (nActiveDescendant < 0) {
363
 
                                        nActiveDescendant = 0;
364
 
                                }
365
 
                                
366
 
 
367
 
                                oNode = descendants.item(nActiveDescendant);
368
 
 
369
 
                                //      Check to make sure the active descendant isn't disabled, 
370
 
                                //      and fall back to the first enabled descendant if it is.
371
 
 
372
 
                                if (!oNode || oNode.get(DISABLED)) {
373
 
                                        oNode = descendants.item(nFirstEnabled);
374
 
                                        nActiveDescendant = nFirstEnabled;
375
 
                                }
376
 
 
377
 
                                this._lastNodeIndex = nDescendants - 1;
378
 
                                this._descendants = descendants;
379
 
                                this._descendantsMap = descendantsMap;
380
 
 
381
 
                                this.set(ACTIVE_DESCENDANT, nActiveDescendant);
382
 
 
383
 
                                //      Need to set the "tabIndex" attribute here, since the 
384
 
                                //      "activeDescendantChange" event handler used to manage
385
 
                                //      the setting of the "tabIndex" attribute isn't wired up yet.
386
 
 
387
 
                                oNode.set(TAB_INDEX, 0);
388
 
 
389
 
                        }
 
315
            for (i = 0; i < nDescendants; i++) {
 
316
 
 
317
                oNode = descendants.item(i);
 
318
 
 
319
                if (nFirstEnabled === -1 && !oNode.get(DISABLED)) {
 
320
                    nFirstEnabled = i;
 
321
                }
 
322
 
 
323
 
 
324
                //      If the user didn't specify a value for the 
 
325
                //      "activeDescendant" attribute try to infer it from 
 
326
                //      the markup.
 
327
 
 
328
                //      Need to pass "2" when using "getAttribute" for IE to get
 
329
                //      the attribute value as it is set in the markup.
 
330
                //      Need to use "parseInt" because IE always returns the 
 
331
                //      value as a number, whereas all other browsers return
 
332
                //      the attribute as a string when accessed 
 
333
                //      via "getAttribute".
 
334
 
 
335
                if (nActiveDescendant < 0 && 
 
336
                        parseInt(oNode.getAttribute(TAB_INDEX, 2), 10) === 0) {
 
337
 
 
338
                    nActiveDescendant = i;
 
339
 
 
340
                }
 
341
 
 
342
                if (oNode) {
 
343
                    oNode.set(TAB_INDEX, -1);
 
344
                }
 
345
 
 
346
                sID = oNode.get(ID);
 
347
 
 
348
                if (!sID) {
 
349
                    sID = Y.guid();
 
350
                    oNode.set(ID, sID);
 
351
                }
 
352
                
 
353
                descendantsMap[sID] = i;
 
354
                
 
355
            }
 
356
            
 
357
 
 
358
            //  If the user didn't specify a value for the  
 
359
            //  "activeDescendant" attribute and no default value could be 
 
360
            //  determined from the markup, then default to 0.
 
361
            
 
362
            if (nActiveDescendant < 0) {
 
363
                nActiveDescendant = 0;
 
364
            }
 
365
            
 
366
 
 
367
            oNode = descendants.item(nActiveDescendant);
 
368
 
 
369
            //  Check to make sure the active descendant isn't disabled, 
 
370
            //  and fall back to the first enabled descendant if it is.
 
371
 
 
372
            if (!oNode || oNode.get(DISABLED)) {
 
373
                oNode = descendants.item(nFirstEnabled);
 
374
                nActiveDescendant = nFirstEnabled;
 
375
            }
 
376
 
 
377
            this._lastNodeIndex = nDescendants - 1;
 
378
            this._descendants = descendants;
 
379
            this._descendantsMap = descendantsMap;
 
380
 
 
381
            this.set(ACTIVE_DESCENDANT, nActiveDescendant);
 
382
 
 
383
            //  Need to set the "tabIndex" attribute here, since the 
 
384
            //  "activeDescendantChange" event handler used to manage
 
385
            //  the setting of the "tabIndex" attribute isn't wired up yet.
 
386
 
 
387
            if (oNode) {
 
388
                oNode.set(TAB_INDEX, 0);
 
389
            }
390
390
                        
391
391
                }
392
392
 
578
578
                        oDocument,
579
579
                        handle;
580
580
 
581
 
                if (descendants && descendants.size() > 1) {
 
581
                if (descendants && descendants.size()) {
582
582
 
583
583
                        aHandlers = this._eventHandlers || [];
584
584
                        oDocument = this.get(HOST).get("ownerDocument");
833
833
 
834
834
                        oNode = this._descendants.item(nActiveDescendant);
835
835
                        
836
 
                        if (oNode.get(DISABLED)) {
 
836
                        if (oNode && oNode.get(DISABLED)) {
837
837
                                this._focusNext(event, nActiveDescendant);
838
838
                        }
839
839
                        else {
871
871
 
872
872
                        oNode = this._descendants.item(nActiveDescendant);
873
873
 
874
 
                        if (oNode.get(DISABLED)) {
 
874
                        if (oNode && oNode.get(DISABLED)) {
875
875
                                this._focusPrevious(event, nActiveDescendant);
876
876
                        }
877
877
                        else {
1045
1045
 
1046
1046
                this._initDescendants();
1047
1047
                
 
1048
                if (!this._eventHandlers) {
 
1049
                        this._attachEventHandlers();                
 
1050
                }
 
1051
                
1048
1052
        }
1049
1053
        
1050
1054
});
1057
1061
Y.Plugin.NodeFocusManager = NodeFocusManager;
1058
1062
 
1059
1063
 
1060
 
}, '3.0.0' ,{requires:['attribute', 'node', 'plugin', 'node-event-simulate', 'event-key', 'event-focus']});
 
1064
}, '3.1.0' ,{requires:['attribute', 'node', 'plugin', 'node-event-simulate', 'event-key', 'event-focus']});