@@ -343,316 +343,3 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
343
343
}
344
344
} ;
345
345
} ) ;
346
-
347
- /* Deprecated dropdown below */
348
-
349
- angular . module ( 'ui.bootstrap.dropdown' )
350
-
351
- . value ( '$dropdownSuppressWarning' , false )
352
-
353
- . service ( 'dropdownService' , [ '$log' , '$dropdownSuppressWarning' , 'uibDropdownService' , function ( $log , $dropdownSuppressWarning , uibDropdownService ) {
354
- if ( ! $dropdownSuppressWarning ) {
355
- $log . warn ( 'dropdownService is now deprecated. Use uibDropdownService instead.' ) ;
356
- }
357
-
358
- angular . extend ( this , uibDropdownService ) ;
359
- } ] )
360
-
361
- . controller ( 'DropdownController' , [ '$scope' , '$element' , '$attrs' , '$parse' , 'uibDropdownConfig' , 'uibDropdownService' , '$animate' , '$uibPosition' , '$document' , '$compile' , '$templateRequest' , '$log' , '$dropdownSuppressWarning' , function ( $scope , $element , $attrs , $parse , dropdownConfig , uibDropdownService , $animate , $position , $document , $compile , $templateRequest , $log , $dropdownSuppressWarning ) {
362
- if ( ! $dropdownSuppressWarning ) {
363
- $log . warn ( 'DropdownController is now deprecated. Use UibDropdownController instead.' ) ;
364
- }
365
-
366
- var self = this ,
367
- scope = $scope . $new ( ) , // create a child scope so we are not polluting original one
368
- templateScope ,
369
- openClass = dropdownConfig . openClass ,
370
- getIsOpen ,
371
- setIsOpen = angular . noop ,
372
- toggleInvoker = $attrs . onToggle ? $parse ( $attrs . onToggle ) : angular . noop ,
373
- appendToBody = false ,
374
- keynavEnabled = false ,
375
- selectedOption = null ;
376
-
377
-
378
- $element . addClass ( 'dropdown' ) ;
379
-
380
- this . init = function ( ) {
381
- if ( $attrs . isOpen ) {
382
- getIsOpen = $parse ( $attrs . isOpen ) ;
383
- setIsOpen = getIsOpen . assign ;
384
-
385
- $scope . $watch ( getIsOpen , function ( value ) {
386
- scope . isOpen = ! ! value ;
387
- } ) ;
388
- }
389
-
390
- appendToBody = angular . isDefined ( $attrs . dropdownAppendToBody ) ;
391
- keynavEnabled = angular . isDefined ( $attrs . uibKeyboardNav ) ;
392
-
393
- if ( appendToBody && self . dropdownMenu ) {
394
- $document . find ( 'body' ) . append ( self . dropdownMenu ) ;
395
- $element . on ( '$destroy' , function handleDestroyEvent ( ) {
396
- self . dropdownMenu . remove ( ) ;
397
- } ) ;
398
- }
399
- } ;
400
-
401
- this . toggle = function ( open ) {
402
- return scope . isOpen = arguments . length ? ! ! open : ! scope . isOpen ;
403
- } ;
404
-
405
- // Allow other directives to watch status
406
- this . isOpen = function ( ) {
407
- return scope . isOpen ;
408
- } ;
409
-
410
- scope . getToggleElement = function ( ) {
411
- return self . toggleElement ;
412
- } ;
413
-
414
- scope . getAutoClose = function ( ) {
415
- return $attrs . autoClose || 'always' ; //or 'outsideClick' or 'disabled'
416
- } ;
417
-
418
- scope . getElement = function ( ) {
419
- return $element ;
420
- } ;
421
-
422
- scope . isKeynavEnabled = function ( ) {
423
- return keynavEnabled ;
424
- } ;
425
-
426
- scope . focusDropdownEntry = function ( keyCode ) {
427
- var elems = self . dropdownMenu ? //If append to body is used.
428
- ( angular . element ( self . dropdownMenu ) . find ( 'a' ) ) :
429
- ( angular . element ( $element ) . find ( 'ul' ) . eq ( 0 ) . find ( 'a' ) ) ;
430
-
431
- switch ( keyCode ) {
432
- case ( 40 ) : {
433
- if ( ! angular . isNumber ( self . selectedOption ) ) {
434
- self . selectedOption = 0 ;
435
- } else {
436
- self . selectedOption = ( self . selectedOption === elems . length - 1 ?
437
- self . selectedOption :
438
- self . selectedOption + 1 ) ;
439
- }
440
- break ;
441
- }
442
- case ( 38 ) : {
443
- if ( ! angular . isNumber ( self . selectedOption ) ) {
444
- self . selectedOption = elems . length - 1 ;
445
- } else {
446
- self . selectedOption = self . selectedOption === 0 ?
447
- 0 : self . selectedOption - 1 ;
448
- }
449
- break ;
450
- }
451
- }
452
- elems [ self . selectedOption ] . focus ( ) ;
453
- } ;
454
-
455
- scope . getDropdownElement = function ( ) {
456
- return self . dropdownMenu ;
457
- } ;
458
-
459
- scope . focusToggleElement = function ( ) {
460
- if ( self . toggleElement ) {
461
- self . toggleElement [ 0 ] . focus ( ) ;
462
- }
463
- } ;
464
-
465
- scope . $watch ( 'isOpen' , function ( isOpen , wasOpen ) {
466
- if ( appendToBody && self . dropdownMenu ) {
467
- var pos = $position . positionElements ( $element , self . dropdownMenu , 'bottom-left' , true ) ;
468
- var css = {
469
- top : pos . top + 'px' ,
470
- display : isOpen ? 'block' : 'none'
471
- } ;
472
-
473
- var rightalign = self . dropdownMenu . hasClass ( 'dropdown-menu-right' ) ;
474
- if ( ! rightalign ) {
475
- css . left = pos . left + 'px' ;
476
- css . right = 'auto' ;
477
- } else {
478
- css . left = 'auto' ;
479
- css . right = ( window . innerWidth - ( pos . left + $element . prop ( 'offsetWidth' ) ) ) + 'px' ;
480
- }
481
-
482
- self . dropdownMenu . css ( css ) ;
483
- }
484
-
485
- $animate [ isOpen ? 'addClass' : 'removeClass' ] ( $element , openClass ) . then ( function ( ) {
486
- if ( angular . isDefined ( isOpen ) && isOpen !== wasOpen ) {
487
- toggleInvoker ( $scope , { open : ! ! isOpen } ) ;
488
- }
489
- } ) ;
490
-
491
- if ( isOpen ) {
492
- if ( self . dropdownMenuTemplateUrl ) {
493
- $templateRequest ( self . dropdownMenuTemplateUrl ) . then ( function ( tplContent ) {
494
- templateScope = scope . $new ( ) ;
495
- $compile ( tplContent . trim ( ) ) ( templateScope , function ( dropdownElement ) {
496
- var newEl = dropdownElement ;
497
- self . dropdownMenu . replaceWith ( newEl ) ;
498
- self . dropdownMenu = newEl ;
499
- } ) ;
500
- } ) ;
501
- }
502
-
503
- scope . focusToggleElement ( ) ;
504
- uibDropdownService . open ( scope ) ;
505
- } else {
506
- if ( self . dropdownMenuTemplateUrl ) {
507
- if ( templateScope ) {
508
- templateScope . $destroy ( ) ;
509
- }
510
- var newEl = angular . element ( '<ul class="dropdown-menu"></ul>' ) ;
511
- self . dropdownMenu . replaceWith ( newEl ) ;
512
- self . dropdownMenu = newEl ;
513
- }
514
-
515
- uibDropdownService . close ( scope ) ;
516
- self . selectedOption = null ;
517
- }
518
-
519
- if ( angular . isFunction ( setIsOpen ) ) {
520
- setIsOpen ( $scope , isOpen ) ;
521
- }
522
- } ) ;
523
-
524
- $scope . $on ( '$locationChangeSuccess' , function ( ) {
525
- if ( scope . getAutoClose ( ) !== 'disabled' ) {
526
- scope . isOpen = false ;
527
- }
528
- } ) ;
529
-
530
- var offDestroy = $scope . $on ( '$destroy' , function ( ) {
531
- scope . $destroy ( ) ;
532
- } ) ;
533
- scope . $on ( '$destroy' , offDestroy ) ;
534
- } ] )
535
-
536
- . directive ( 'dropdown' , [ '$log' , '$dropdownSuppressWarning' , function ( $log , $dropdownSuppressWarning ) {
537
- return {
538
- controller : 'DropdownController' ,
539
- link : function ( scope , element , attrs , dropdownCtrl ) {
540
- if ( ! $dropdownSuppressWarning ) {
541
- $log . warn ( 'dropdown is now deprecated. Use uib-dropdown instead.' ) ;
542
- }
543
-
544
- dropdownCtrl . init ( ) ;
545
- }
546
- } ;
547
- } ] )
548
-
549
- . directive ( 'dropdownMenu' , [ '$log' , '$dropdownSuppressWarning' , function ( $log , $dropdownSuppressWarning ) {
550
- return {
551
- restrict : 'AC' ,
552
- require : '?^dropdown' ,
553
- link : function ( scope , element , attrs , dropdownCtrl ) {
554
- if ( ! dropdownCtrl || angular . isDefined ( attrs . dropdownNested ) ) {
555
- return ;
556
- }
557
-
558
- if ( ! $dropdownSuppressWarning ) {
559
- $log . warn ( 'dropdown-menu is now deprecated. Use uib-dropdown-menu instead.' ) ;
560
- }
561
-
562
- element . addClass ( 'dropdown-menu' ) ;
563
-
564
- var tplUrl = attrs . templateUrl ;
565
- if ( tplUrl ) {
566
- dropdownCtrl . dropdownMenuTemplateUrl = tplUrl ;
567
- }
568
-
569
- if ( ! dropdownCtrl . dropdownMenu ) {
570
- dropdownCtrl . dropdownMenu = element ;
571
- }
572
- }
573
- } ;
574
- } ] )
575
-
576
- . directive ( 'keyboardNav' , [ '$log' , '$dropdownSuppressWarning' , function ( $log , $dropdownSuppressWarning ) {
577
- return {
578
- restrict : 'A' ,
579
- require : '?^dropdown' ,
580
- link : function ( scope , element , attrs , dropdownCtrl ) {
581
- if ( ! $dropdownSuppressWarning ) {
582
- $log . warn ( 'keyboard-nav is now deprecated. Use uib-keyboard-nav instead.' ) ;
583
- }
584
-
585
- element . bind ( 'keydown' , function ( e ) {
586
- if ( [ 38 , 40 ] . indexOf ( e . which ) !== - 1 ) {
587
- e . preventDefault ( ) ;
588
- e . stopPropagation ( ) ;
589
-
590
- var elems = dropdownCtrl . dropdownMenu . find ( 'a' ) ;
591
-
592
- switch ( e . which ) {
593
- case ( 40 ) : { // Down
594
- if ( ! angular . isNumber ( dropdownCtrl . selectedOption ) ) {
595
- dropdownCtrl . selectedOption = 0 ;
596
- } else {
597
- dropdownCtrl . selectedOption = dropdownCtrl . selectedOption === elems . length - 1 ?
598
- dropdownCtrl . selectedOption : dropdownCtrl . selectedOption + 1 ;
599
- }
600
- break ;
601
- }
602
- case ( 38 ) : { // Up
603
- if ( ! angular . isNumber ( dropdownCtrl . selectedOption ) ) {
604
- dropdownCtrl . selectedOption = elems . length - 1 ;
605
- } else {
606
- dropdownCtrl . selectedOption = dropdownCtrl . selectedOption === 0 ?
607
- 0 : dropdownCtrl . selectedOption - 1 ;
608
- }
609
- break ;
610
- }
611
- }
612
- elems [ dropdownCtrl . selectedOption ] . focus ( ) ;
613
- }
614
- } ) ;
615
- }
616
- } ;
617
- } ] )
618
-
619
- . directive ( 'dropdownToggle' , [ '$log' , '$dropdownSuppressWarning' , function ( $log , $dropdownSuppressWarning ) {
620
- return {
621
- require : '?^dropdown' ,
622
- link : function ( scope , element , attrs , dropdownCtrl ) {
623
- if ( ! $dropdownSuppressWarning ) {
624
- $log . warn ( 'dropdown-toggle is now deprecated. Use uib-dropdown-toggle instead.' ) ;
625
- }
626
-
627
- if ( ! dropdownCtrl ) {
628
- return ;
629
- }
630
-
631
- element . addClass ( 'dropdown-toggle' ) ;
632
-
633
- dropdownCtrl . toggleElement = element ;
634
-
635
- var toggleDropdown = function ( event ) {
636
- event . preventDefault ( ) ;
637
-
638
- if ( ! element . hasClass ( 'disabled' ) && ! attrs . disabled ) {
639
- scope . $apply ( function ( ) {
640
- dropdownCtrl . toggle ( ) ;
641
- } ) ;
642
- }
643
- } ;
644
-
645
- element . bind ( 'click' , toggleDropdown ) ;
646
-
647
- // WAI-ARIA
648
- element . attr ( { 'aria-haspopup' : true , 'aria-expanded' : false } ) ;
649
- scope . $watch ( dropdownCtrl . isOpen , function ( isOpen ) {
650
- element . attr ( 'aria-expanded' , ! ! isOpen ) ;
651
- } ) ;
652
-
653
- scope . $on ( '$destroy' , function ( ) {
654
- element . unbind ( 'click' , toggleDropdown ) ;
655
- } ) ;
656
- }
657
- } ;
658
- } ] ) ;
0 commit comments