@@ -263,7 +263,7 @@ textAngular.directive("textAngular", [
263
263
scope . displayElements . resize . background . on ( 'click' , function ( e ) {
264
264
scope . displayElements . text [ 0 ] . focus ( ) ;
265
265
} ) ;
266
-
266
+
267
267
// define the show and hide events
268
268
scope . reflowResizeOverlay = function ( _el ) {
269
269
_el = angular . element ( _el ) [ 0 ] ;
@@ -670,9 +670,60 @@ textAngular.directive("textAngular", [
670
670
}
671
671
} ) ;
672
672
673
+ /******************* no working fully
674
+ var distanceFromPoint = function (px, py, x, y) {
675
+ return Math.sqrt((px-x)*(px-x)+(py-y)*(py-y));
676
+ };
677
+ // because each object is a rectangle and we have a single point,
678
+ // we need to give priority if the point is inside the rectangle
679
+ var getPositionDistance = function(el, x, y) {
680
+ var range = document.createRange();
681
+ range.selectNode(el);
682
+ var rect = range.getBoundingClientRect();
683
+ console.log(el, rect);
684
+ range.detach();
685
+ var bcr = rect;
686
+ // top left
687
+ var d1 = distanceFromPoint(bcr.left, bcr.top, x, y);
688
+ // bottom left
689
+ var d2 = distanceFromPoint(bcr.left, bcr.bottom, x, y);
690
+ // top right
691
+ var d3 = distanceFromPoint(bcr.right, bcr.top, x, y);
692
+ // bottom right
693
+ var d4 = distanceFromPoint(bcr.right, bcr.bottom, x, y);
694
+ return Math.min(d1, d2, d3, d4);
695
+ };
696
+ var findClosest = function(el, minElement, maxDistance, x, y) {
697
+ var _d=0;
698
+ for (var i = 0; i < el.childNodes.length; i++) {
699
+ var _n = el.childNodes[i];
700
+ if (!_n.childNodes.length) {
701
+ _d = getPositionDistance(_n, x, y);
702
+ //console.log(_n, _n.childNodes, _d);
703
+ if (_d < maxDistance) {
704
+ maxDistance = _d;
705
+ minElement = _n;
706
+ }
707
+ }
708
+ var res = findClosest(_n, minElement, maxDistance, x, y);
709
+ if (res.max < maxDistance) {
710
+ maxDistance = res.max;
711
+ minElement = res.min;
712
+ }
713
+ }
714
+ return { max: maxDistance, min: minElement };
715
+ };
716
+ var getClosestElement = function (el, x, y) {
717
+ return findClosest(el, null, 12341234124, x, y);
718
+ };
719
+ ****************/
720
+
673
721
scope . $on ( 'ta-drop-event' , function ( event , element , dropEvent , dataTransfer ) {
674
722
if ( dataTransfer && dataTransfer . files && dataTransfer . files . length > 0 ) {
675
723
scope . displayElements . text [ 0 ] . focus ( ) ;
724
+ // we must set the location of the drop!
725
+ //console.log(dropEvent.clientX, dropEvent.clientY, dropEvent.target);
726
+ taSelection . setSelectionToElementEnd ( dropEvent . target ) ;
676
727
angular . forEach ( dataTransfer . files , function ( file ) {
677
728
// taking advantage of boolean execution, if the fileDropHandler returns true, nothing else after it is executed
678
729
// If it is false then execute the defaultFileDropHandler if the fileDropHandler is NOT the default one
0 commit comments