1
+ ! function ( $ ) {
2
+
3
+ /* MODAL POPOVER PUBLIC CLASS DEFINITION
4
+ * =============================== */
5
+
6
+ var ModalPopover = function ( element , options ) {
7
+ this . options = options ;
8
+ this . $element = $ ( element )
9
+ . delegate ( '[data-dismiss="modal-popup"]' , 'click.dismiss.modal-popup' , $ . proxy ( this . hide , this ) ) ;
10
+ this . options . remote && this . $element . find ( '.popover-content' ) . load ( this . options . remote ) ;
11
+ this . $parent = options . $parent ; // todo make sure parent is specified
12
+ }
13
+
14
+
15
+ /* NOTE: MODAL POPOVER EXTENDS BOOTSTRAP-MODAL.js
16
+ ========================================== */
17
+
18
+
19
+ ModalPopover . prototype = $ . extend ( { } , $ . fn . modal . Constructor . prototype , {
20
+
21
+ constructor :ModalPopover ,
22
+
23
+
24
+ getPosition :function ( ) {
25
+ var $element = this . $parent ;
26
+ return $ . extend ( { } , ( $element . offset ( ) ) , {
27
+ width :$element [ 0 ] . offsetWidth , height :$element [ 0 ] . offsetHeight
28
+ } ) ;
29
+ } ,
30
+
31
+ show :function ( ) {
32
+ var $dialog = this . $element ;
33
+ $dialog . css ( { top :0 , left :0 , display :'block' , 'z-index' :1050 } ) ;
34
+
35
+ var placement = typeof this . options . placement == 'function' ?
36
+ this . options . placement . call ( this , $tip [ 0 ] , this . $element [ 0 ] ) :
37
+ this . options . placement ;
38
+
39
+ var pos = this . getPosition ( ) ;
40
+
41
+ var actualWidth = $dialog [ 0 ] . offsetWidth ;
42
+ var actualHeight = $dialog [ 0 ] . offsetHeight ;
43
+
44
+ var tp ;
45
+ switch ( placement ) {
46
+ case 'bottom' :
47
+ tp = { top :pos . top + pos . height , left :pos . left + pos . width / 2 - actualWidth / 2 }
48
+ break ;
49
+ case 'top' :
50
+ tp = { top :pos . top - actualHeight , left :pos . left + pos . width / 2 - actualWidth / 2 }
51
+ break ;
52
+ case 'left' :
53
+ tp = { top :pos . top + pos . height / 2 - actualHeight / 2 , left :pos . left - actualWidth }
54
+ break ;
55
+ case 'right' :
56
+ tp = { top :pos . top + pos . height / 2 - actualHeight / 2 , left :pos . left + pos . width }
57
+ break ;
58
+ }
59
+
60
+ $dialog
61
+ . css ( tp )
62
+ . addClass ( placement )
63
+ . addClass ( 'in' ) ;
64
+
65
+
66
+ $ . fn . modal . Constructor . prototype . show . call ( this , arguments ) ; // super
67
+ } ,
68
+
69
+ /** todo entire function was copied just to set the background to 'none'. need a better way */
70
+ backdrop :function ( callback ) {
71
+ var that = this
72
+ , animate = this . $element . hasClass ( 'fade' ) ? 'fade' : ''
73
+
74
+ if ( this . isShown && this . options . backdrop ) {
75
+ var doAnimate = $ . support . transition && animate
76
+
77
+ this . $backdrop = $ ( '<div class="modal-backdrop ' + animate + '" style="background:none" />' )
78
+ . appendTo ( document . body )
79
+
80
+ if ( this . options . backdrop != 'static' ) {
81
+ this . $backdrop . click ( $ . proxy ( this . hide , this ) )
82
+ }
83
+
84
+ if ( doAnimate ) this . $backdrop [ 0 ] . offsetWidth // force reflow
85
+
86
+ this . $backdrop . addClass ( 'in' )
87
+
88
+ doAnimate ?
89
+ this . $backdrop . one ( $ . support . transition . end , callback ) :
90
+ callback ( )
91
+
92
+ } else if ( ! this . isShown && this . $backdrop ) {
93
+ this . $backdrop . removeClass ( 'in' )
94
+
95
+ $ . support . transition && this . $element . hasClass ( 'fade' ) ?
96
+ this . $backdrop . one ( $ . support . transition . end , $ . proxy ( this . removeBackdrop , this ) ) :
97
+ this . removeBackdrop ( )
98
+
99
+ } else if ( callback ) {
100
+ callback ( )
101
+ }
102
+ }
103
+
104
+ } ) ;
105
+
106
+
107
+ /* MODAL POPOVER PLUGIN DEFINITION
108
+ * ======================= */
109
+
110
+ $ . fn . modalPopover = function ( option ) {
111
+ return this . each ( function ( ) {
112
+ var $this = $ ( this ) ;
113
+ var data = $this . data ( 'modal-popover' ) ;
114
+ var options = $ . extend ( { } , $ . fn . modalPopover . defaults , $this . data ( ) , typeof option == 'object' && option ) ;
115
+ // todo need to replace 'parent' with 'target'
116
+ options [ '$parent' ] = ( data && data . $parent ) || option . $parent || $ ( options . target ) ;
117
+
118
+ if ( ! data ) $this . data ( 'modal-popover' , ( data = new ModalPopover ( this , options ) ) )
119
+
120
+ if ( typeof option == 'string' ) data [ option ] ( )
121
+ } )
122
+ }
123
+
124
+ $ . fn . modalPopover . Constructor = ModalPopover
125
+
126
+ $ . fn . modalPopover . defaults = $ . extend ( { } , $ . fn . modal . defaults , {
127
+ placement :'right' ,
128
+ keyboard : true
129
+ } ) ;
130
+
131
+
132
+ $ ( function ( ) {
133
+ $ ( 'body' ) . on ( 'click.modal-popover.data-api' , '[data-toggle="modal-popover"]' , function ( e ) {
134
+ var $this = $ ( this ) ;
135
+ var href = $this . attr ( 'href' ) ;
136
+ var $dialog = $ ( $this . attr ( 'data-target' ) || ( href && href . replace ( / .* (? = # [ ^ \s ] + $ ) / , '' ) ) ) ; //strip for ie7
137
+ var option = $dialog . data ( 'modal-popover' ) ? 'toggle' : $ . extend ( { remote :! / # / . test ( href ) && href } , $dialog . data ( ) , $this . data ( ) ) ;
138
+ option [ '$parent' ] = $this ;
139
+
140
+ e . preventDefault ( ) ;
141
+
142
+ $dialog
143
+ . modalPopover ( option )
144
+ . modalPopover ( 'show' )
145
+ . one ( 'hide' , function ( ) {
146
+ $this . focus ( )
147
+ } )
148
+ } )
149
+ } )
150
+
151
+ } ( window . jQuery ) ;
152
+ //
0 commit comments