@@ -20,7 +20,8 @@ $.widget( "ui.draggable", {
20
20
options : {
21
21
helper : false ,
22
22
scrollSensitivity : 20 ,
23
- scrollSpeed : 20
23
+ scrollSpeed : 20 ,
24
+ iframeFix : false
24
25
} ,
25
26
26
27
// dragEl: element being dragged (original or helper)
@@ -33,6 +34,36 @@ $.widget( "ui.draggable", {
33
34
// overflowOffset: offset of scroll parent
34
35
// overflow: object containing width and height keys of scroll parent
35
36
37
+ _blockFrames : function ( ) {
38
+
39
+ var iframes = $ ( 'iframe' ) ,
40
+ widget = this ;
41
+
42
+ this . iframeBlocks = $ ( '' ) ;
43
+
44
+ iframes . each ( function ( ) {
45
+
46
+ var iframe = $ ( this ) ,
47
+ width = iframe . outerWidth ( ) ,
48
+ height = iframe . outerHeight ( ) ,
49
+ iframeOffset = iframe . offset ( ) ,
50
+ block = $ ( '<div />' ) ;
51
+
52
+ block . css ( {
53
+ position : 'absolute' ,
54
+ width : width + 'px' ,
55
+ height : height + 'px' ,
56
+ top : iframeOffset . top + 'px' ,
57
+ left : iframeOffset . left + 'px'
58
+ } )
59
+ . appendTo ( widget . document [ 0 ] . body ) ;
60
+
61
+ widget . iframeBlocks = widget . iframeBlocks . add ( block ) ;
62
+
63
+ } ) ;
64
+
65
+ } ,
66
+
36
67
_create : function ( ) {
37
68
this . scrollParent = this . element . scrollParent ( ) ;
38
69
@@ -78,48 +109,48 @@ $.widget( "ui.draggable", {
78
109
_handleScrolling : function ( event ) {
79
110
var scrollTop = this . scrollParent . scrollTop ( ) ,
80
111
scrollLeft = this . scrollParent . scrollLeft ( ) ;
81
-
112
+
82
113
// overflowOffset is only set when scrollParent is not doc/html
83
114
if ( ! this . overflowOffset ) {
84
-
115
+
85
116
// Handle vertical scrolling
86
117
if ( ( ( this . overflow . height + scrollTop ) - event . pageY ) < this . options . scrollSensitivity ) {
87
118
this . scrollParent . scrollTop ( scrollTop + this . options . scrollSpeed ) ;
88
119
}
89
120
else if ( event . pageY < ( scrollTop + this . options . scrollSensitivity ) ) {
90
121
this . scrollParent . scrollTop ( scrollTop - this . options . scrollSpeed ) ;
91
122
}
92
-
123
+
93
124
// Handle horizontal scrolling
94
125
if ( ( ( this . overflow . width + scrollLeft ) - event . pageX ) < this . options . scrollSensitivity ) {
95
126
this . scrollParent . scrollLeft ( scrollLeft + this . options . scrollSpeed ) ;
96
127
}
97
128
else if ( event . pageX < ( scrollLeft + this . options . scrollSensitivity ) ) {
98
129
this . scrollParent . scrollLeft ( scrollLeft - this . options . scrollSpeed ) ;
99
130
}
100
-
131
+
101
132
} else {
102
-
103
-
133
+
134
+
104
135
// Handle vertical scrolling
105
136
if ( ( event . pageY + this . options . scrollSensitivity ) > ( this . overflow . height + this . overflowOffset . top ) ) {
106
137
this . scrollParent . scrollTop ( scrollTop + this . options . scrollSpeed ) ;
107
138
}
108
139
else if ( ( event . pageY - this . options . scrollSensitivity ) < this . overflowOffset . top ) {
109
140
this . scrollParent . scrollTop ( scrollTop - this . options . scrollSpeed ) ;
110
141
}
111
-
142
+
112
143
// Handle horizontal scrolling
113
144
if ( ( event . pageX + this . options . scrollSensitivity ) > ( this . overflow . width + this . overflowOffset . left ) ) {
114
145
this . scrollParent . scrollLeft ( scrollLeft + this . options . scrollSpeed ) ;
115
146
}
116
147
else if ( ( event . pageX - this . options . scrollSensitivity ) < this . overflowOffset . left ) {
117
148
this . scrollParent . scrollLeft ( scrollLeft - this . options . scrollSpeed ) ;
118
149
}
119
-
120
-
150
+
151
+
121
152
}
122
-
153
+
123
154
} ,
124
155
125
156
_mouseDown : function ( event ) {
@@ -131,6 +162,10 @@ $.widget( "ui.draggable", {
131
162
// The actual dragging element, should always be a jQuery object
132
163
this . dragEl = this . element ;
133
164
165
+ if ( this . options . iframeFix === true ) {
166
+ this . _blockFrames ( ) ;
167
+ }
168
+
134
169
// Helper required
135
170
if ( this . options . helper ) {
136
171
// clone
@@ -151,7 +186,7 @@ $.widget( "ui.draggable", {
151
186
. appendTo ( this . document [ 0 ] . body )
152
187
. offset ( this . element . offset ( ) ) ;
153
188
}
154
-
189
+
155
190
this . cssPosition = this . dragEl . css ( "position" ) ;
156
191
157
192
// Cache starting absolute and relative positions
@@ -183,7 +218,7 @@ $.widget( "ui.draggable", {
183
218
this . _preparePosition ( event ) ;
184
219
185
220
allowed = this . _trigger ( "start" , event , this . _uiHash ( ) ) ;
186
-
221
+
187
222
// If user stops propagation, leave helper there ( if there's one ), disallow any CSS changes
188
223
if ( allowed !== true ) {
189
224
this . document . unbind ( "." + this . widgetName ) ;
@@ -200,12 +235,12 @@ $.widget( "ui.draggable", {
200
235
201
236
_mouseMove : function ( event ) {
202
237
var newLeft , newTop , allowed ;
203
-
238
+
204
239
this . _preparePosition ( event ) ;
205
240
206
241
allowed = this . _trigger ( "drag" , event , this . _uiHash ( ) ) ;
207
-
208
-
242
+
243
+
209
244
// If user stops propagation, leave helper there ( if there's one ), disallow any CSS changes
210
245
if ( allowed !== true ) {
211
246
this . document . unbind ( "." + this . widgetName ) ;
@@ -219,7 +254,7 @@ $.widget( "ui.draggable", {
219
254
} ,
220
255
221
256
_mouseUp : function ( event ) {
222
-
257
+
223
258
var allowed ;
224
259
225
260
this . _preparePosition ( event ) ;
@@ -238,6 +273,11 @@ $.widget( "ui.draggable", {
238
273
}
239
274
240
275
this . document . unbind ( "." + this . widgetName ) ;
276
+
277
+ if ( this . options . iframeFix === true ) {
278
+ this . _unblockFrames ( ) ;
279
+ }
280
+
241
281
} ,
242
282
243
283
// Uses event to determine new position of draggable, before any override from callbacks
@@ -296,13 +336,27 @@ $.widget( "ui.draggable", {
296
336
position : this . position
297
337
// offset: this.offset
298
338
} ;
299
-
339
+
300
340
if ( this . options . helper ) {
301
341
ret . helper = this . dragEl ;
302
342
}
303
-
343
+
304
344
return ret ;
345
+
346
+ } ,
347
+
348
+ _unblockFrames : function ( ) {
349
+
350
+ if ( ! this . iframeBlocks || ! this . iframeBlocks . length ) {
351
+ return ;
352
+ }
305
353
354
+ this . iframeBlocks . each ( function ( ) {
355
+
356
+ $ ( this ) . remove ( ) ;
357
+
358
+ } ) ;
359
+
306
360
}
307
361
} ) ;
308
362
0 commit comments