@@ -26,6 +26,7 @@ window = (typeof window != 'undefined' && window.Math == Math)
26
26
$ . fn . calendar = function ( parameters ) {
27
27
var
28
28
$allModules = $ ( this ) ,
29
+ $document = $ ( document ) ,
29
30
30
31
moduleSelector = $allModules . selector || '' ,
31
32
@@ -67,11 +68,11 @@ $.fn.calendar = function(parameters) {
67
68
68
69
$module = $ ( this ) ,
69
70
$input = $module . find ( selector . input ) ,
70
- $container = $module . find ( selector . popup ) ,
71
71
$activator = $module . find ( selector . activator ) ,
72
72
73
73
element = this ,
74
74
instance = $module . data ( moduleNamespace ) ,
75
+ $container = instance && instance . popupId ? $document . find ( '#' + instance . popupId ) : $module . find ( selector . popup ) ,
75
76
76
77
isTouch ,
77
78
isTouchDown = false ,
@@ -139,11 +140,16 @@ $.fn.calendar = function(parameters) {
139
140
return ;
140
141
}
141
142
if ( ! $container . length ) {
142
- //prepend the popup element to the activator's parent so that it has less chance of messing with
143
- //the styling (eg input action button needs to be the last child to have correct border radius)
144
- var $activatorParent = $activator . parent ( ) ,
145
- domPositionFunction = $activatorParent . closest ( selector . append ) . length !== 0 ? 'appendTo' : 'prependTo' ;
146
- $container = $ ( '<div/>' ) . addClass ( className . popup ) [ domPositionFunction ] ( $activatorParent ) ;
143
+ if ( settings . context ) {
144
+ module . popupId = namespace + '_popup_' + ( Math . random ( ) . toString ( 16 ) + '000000000' ) . slice ( 2 , 10 ) ;
145
+ $container = $ ( '<div/>' , { id :module . popupId } ) . addClass ( className . popup ) . appendTo ( $document . find ( settings . context ) ) ;
146
+ } else {
147
+ //prepend the popup element to the activator's parent so that it has less chance of messing with
148
+ //the styling (eg input action button needs to be the last child to have correct border radius)
149
+ var $activatorParent = $activator . parent ( ) ,
150
+ domPositionFunction = $activatorParent . closest ( selector . append ) . length !== 0 ? 'appendTo' : 'prependTo' ;
151
+ $container = $ ( '<div/>' ) . addClass ( className . popup ) [ domPositionFunction ] ( $activatorParent ) ;
152
+ }
147
153
}
148
154
$container . addClass ( className . calendar ) ;
149
155
if ( isInverted ) {
@@ -175,6 +181,7 @@ $.fn.calendar = function(parameters) {
175
181
var on = module . setting ( 'on' ) ;
176
182
var options = $ . extend ( { } , settings . popupOptions , {
177
183
popup : $container ,
184
+ movePopup : ! settings . context ,
178
185
on : on ,
179
186
hoverable : on === 'hover' ,
180
187
closable : on === 'click' ,
@@ -805,7 +812,7 @@ $.fn.calendar = function(parameters) {
805
812
return null ;
806
813
}
807
814
if ( ! ( selector instanceof $ ) ) {
808
- selector = $ ( document ) . find ( selector ) . first ( ) ;
815
+ selector = $document . find ( selector ) . first ( ) ;
809
816
}
810
817
//assume range related calendars are using the same namespace
811
818
return selector . data ( moduleNamespace ) ;
@@ -1490,6 +1497,8 @@ $.fn.calendar.settings = {
1490
1497
verbose : false ,
1491
1498
performance : true ,
1492
1499
1500
+ context : false ,
1501
+
1493
1502
type : 'datetime' , // picker type, can be 'datetime', 'date', 'time', 'month', or 'year'
1494
1503
firstDayOfWeek : 0 , // day for first day column (0 = Sunday)
1495
1504
constantHeight : true , // add rows to shorter months to keep day calendar height consistent (6 rows)
0 commit comments