maxazan / jquery-ui-droppable-iframe Goto Github PK
View Code? Open in Web Editor NEWUse your droppable zones inside iframe
Home Page: http://maxazan.github.io/jquery-ui-droppable-iframe/
License: MIT License
Use your droppable zones inside iframe
Home Page: http://maxazan.github.io/jquery-ui-droppable-iframe/
License: MIT License
this solution works great until I have nested droppables in iframe.
I've to replace ui.droppable._drop
method, to prevent resetting droppables' offset
attribute, see below:
//修复在iframe中,错误的重置了元素的 offset 的bug
var intersect = $.ui.intersect;
$.widget('ui.droppable', $.ui.droppable, {
_drop: function( event, custom ) {
var draggable = custom || $.ui.ddmanager.current,
childrenIntersection = false;
// Bail if draggable and droppable are same element
if ( !draggable || ( draggable.currentItem ||
draggable.element )[ 0 ] === this.element[ 0 ] ) {
return false;
}
this.element
.find( ":data(ui-droppable)" )
.not( ".ui-draggable-dragging" )
.each( function() {
var inst = $( this ).droppable( "instance" );
///////// !!! 重要修改, 这里如果已经赋值了,就不用再赋值, 解决 iframe 内部droppable元素定位错误的bug !!!!
if( ! inst.offset ){
inst.offset = inst.element.offset();
}
///////////////////////////////
if (
inst.options.greedy &&
!inst.options.disabled &&
inst.options.scope === draggable.options.scope &&
inst.accept.call(
inst.element[ 0 ], ( draggable.currentItem || draggable.element )
) &&
intersect(
draggable,
inst,
inst.options.tolerance, event
)
) {
childrenIntersection = true;
return false; }
} );
if ( childrenIntersection ) {
return false;
}
if ( this.accept.call( this.element[ 0 ],
( draggable.currentItem || draggable.element ) ) ) {
this._removeActiveClass();
this._removeHoverClass();
this._trigger( "drop", event, this.ui( draggable ) );
return this.element;
}
return false;
}
} );
My droppable is inside an iframe that is scaled to 0.4 using CSS transform. It seems that jQuery UI is not able to calculate the offset properly when the droppable area is scaled. Any insight on how to adjust for this scenario?
It's a pity that the jquery-ui team doesn't support cross-window dragging [1] and it's great that you fix that for many people who need that!
I wonder how hard it is to make your solution work for sortables as well. I tried different possibilities now but didn't find a well working solution.
This fiddle shows the offset between the mouse pointer and the dragged element without your library included:
http://jsfiddle.net/e2kgbcbz/10
This is with your library included:
http://jsfiddle.net/e2kgbcbz/13
What do you think?
Best,
Sandro
[1] - just as a reference: https://bugs.jqueryui.com/ticket/7925
I cant use accept in dropable when i drag element of draggable to accepted area it raise an error..
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.