@@ -534,8 +534,7 @@ $.widget("ech.multiselect", {
534
534
}
535
535
536
536
var $container = menu . find ( 'ul' ) . last ( ) ,
537
- effect = o . show ,
538
- pos = button . offset ( ) ;
537
+ effect = o . show ;
539
538
540
539
// figure out opening effects/speeds
541
540
if ( $ . isArray ( o . show ) ) {
@@ -552,22 +551,8 @@ $.widget("ech.multiselect", {
552
551
// set the scroll of the checkbox container
553
552
$container . scrollTop ( 0 ) . height ( o . height ) ;
554
553
555
- // position and show menu
556
- if ( $ . ui . position && ! $ . isEmptyObject ( o . position ) ) {
557
- o . position . of = o . position . of || button ;
558
-
559
- menu
560
- . show ( )
561
- . position ( o . position )
562
- . hide ( ) ;
563
-
564
- // if position utility is not available...
565
- } else {
566
- menu . css ( {
567
- top : pos . top + button . outerHeight ( ) ,
568
- left : pos . left
569
- } ) ;
570
- }
554
+ // positon
555
+ this . position ( ) ;
571
556
572
557
// show the menu, maybe with a speed/effect combo
573
558
$ . fn . show . apply ( menu , args ) ;
@@ -654,11 +639,34 @@ $.widget("ech.multiselect", {
654
639
return this . button ;
655
640
} ,
656
641
642
+ position : function ( ) {
643
+ var o = this . options ;
644
+
645
+ // use the position utility if it exists and options are specifified
646
+ if ( $ . ui . position && ! $ . isEmptyObject ( o . position ) ) {
647
+ o . position . of = o . position . of || button ;
648
+
649
+ this . menu
650
+ . show ( )
651
+ . position ( o . position )
652
+ . hide ( ) ;
653
+
654
+ // otherwise fallback to custom positioning
655
+ } else {
656
+ var pos = this . button . offset ( ) ;
657
+
658
+ this . menu . css ( {
659
+ top : pos . top + this . button . outerHeight ( ) ,
660
+ left : pos . left
661
+ } ) ;
662
+ }
663
+ } ,
664
+
657
665
// react to option changes after initialization
658
666
_setOption : function ( key , value ) {
659
667
var menu = this . menu ;
660
668
661
- switch ( key ) {
669
+ switch ( key ) {
662
670
case 'header' :
663
671
menu . find ( 'div.ui-multiselect-header' ) [ value ? 'show' : 'hide' ] ( ) ;
664
672
break ;
@@ -669,10 +677,10 @@ $.widget("ech.multiselect", {
669
677
menu . find ( 'a.ui-multiselect-none span' ) . eq ( - 1 ) . text ( value ) ;
670
678
break ;
671
679
case 'height' :
672
- menu . find ( 'ul' ) . last ( ) . height ( parseInt ( value , 10 ) ) ;
680
+ menu . find ( 'ul' ) . last ( ) . height ( parseInt ( value , 10 ) ) ;
673
681
break ;
674
682
case 'minWidth' :
675
- this . options [ key ] = parseInt ( value , 10 ) ;
683
+ this . options [ key ] = parseInt ( value , 10 ) ;
676
684
this . _setButtonWidth ( ) ;
677
685
this . _setMenuWidth ( ) ;
678
686
break ;
@@ -690,6 +698,8 @@ $.widget("ech.multiselect", {
690
698
this . options . multiple = value ;
691
699
this . element [ 0 ] . multiple = value ;
692
700
this . refresh ( ) ;
701
+ case 'position' :
702
+ this . position ( ) ;
693
703
}
694
704
695
705
$ . Widget . prototype . _setOption . apply ( this , arguments ) ;
0 commit comments