|
15 | 15 | $.fn.sortableLists = function( options ) |
16 | 16 | { |
17 | 17 | // Local variables. This scope is available for all the functions in this closure. |
18 | | - var jQBody = $( 'body' ) |
19 | | - .css( 'position', 'relative' ), |
| 18 | + var jQBody = $( 'body' ).css( 'position', 'relative' ), |
20 | 19 |
|
21 | 20 | defaults = { |
22 | 21 | currElClass: '', |
|
58 | 57 | listsClass: '', // Used for hintWrapper and baseElement |
59 | 58 | listsCss: {}, |
60 | 59 | insertZone: 50, |
| 60 | + insertZonePlus: false, |
61 | 61 | scroll: 20, |
62 | 62 | ignoreClass: '', |
63 | 63 | isAllowed: function( cEl, hint, target ) { return true; }, // Params: current el., hint el. |
|
184 | 184 | e.preventDefault(); |
185 | 185 |
|
186 | 186 | // El must be li in jQuery object |
187 | | - var el = target.is( 'li' ) ? target : target.closest( 'li' ), |
| 187 | + var el = target.closest( 'li' ), |
188 | 188 | rEl = $( this ); |
189 | 189 |
|
190 | 190 | // Check if el is not empty |
|
477 | 477 | state.upScroll = state.downScroll = false; |
478 | 478 | } |
479 | 479 |
|
480 | | - /////// Scroll handlers end /////////////////////////////////////////////////////////////////// |
| 480 | + /////// End of Scroll handlers ////////////////////////////////////////////////////////////// |
481 | 481 |
|
482 | 482 | /** |
483 | 483 | * @desc Sets the position of dragged element |
|
555 | 555 |
|
556 | 556 | } |
557 | 557 |
|
| 558 | + //////// Show hint handlers ////////////////////////////////////////////////////// |
| 559 | + |
558 | 560 | /** |
559 | 561 | * @desc Shows or hides or does not show hint element |
560 | 562 | * @param e event |
|
571 | 573 | var oElH = oEl.outerHeight( false ), |
572 | 574 | relY = e.pageY - oEl.offset().top; |
573 | 575 |
|
574 | | - if ( 5 > relY ) // Inserting before |
| 576 | + if ( setting.insertZonePlus ) |
575 | 577 | { |
576 | | - showHintBefore( e, oEl ); |
| 578 | + if ( 14 > relY ) // Inserting on top |
| 579 | + { |
| 580 | + showOnTopPlus( e, oEl, 7 > relY ); // Last bool param express if hint insert outside/inside |
| 581 | + } |
| 582 | + else if ( oElH - 14 < relY ) // Inserting on bottom |
| 583 | + { |
| 584 | + showOnBottomPlus( e, oEl, oElH - 7 < relY ); |
| 585 | + } |
577 | 586 | } |
578 | | - else if ( oElH - 5 < relY ) // Inserting after |
| 587 | + else |
579 | 588 | { |
580 | | - showHintAfter( e, oEl ); |
| 589 | + if ( 5 > relY ) // Inserting on top |
| 590 | + { |
| 591 | + showOnTop( e, oEl ); |
| 592 | + } |
| 593 | + else if ( oElH - 5 < relY ) // Inserting on bottom |
| 594 | + { |
| 595 | + showOnBottom( e, oEl ); |
| 596 | + } |
581 | 597 | } |
582 | | - |
583 | 598 | } |
584 | 599 |
|
585 | 600 | /** |
|
588 | 603 | * @param oEl oElement |
589 | 604 | * @return No value |
590 | 605 | */ |
591 | | - function showHintBefore( e, oEl ) |
| 606 | + function showOnTop( e, oEl ) |
592 | 607 | { |
593 | 608 | if ( $( '#sortableListsHintWrapper', state.rootEl.el ).length ) |
594 | 609 | { |
|
610 | 625 | else |
611 | 626 | { |
612 | 627 | var children = oEl.children(), |
613 | | - list = oEl.children( 'ul' ).first(); |
| 628 | + list = oEl.children( setting.listSelector ).first(); |
614 | 629 |
|
615 | 630 | if ( list.children().first().is( '#sortableListsPlaceholder' ) ) |
616 | 631 | { |
|
633 | 648 | { |
634 | 649 | open( oEl ); // TODO:animation??? .children('ul,ol').css('display', 'block'); |
635 | 650 | } |
| 651 | + |
| 652 | + } |
| 653 | + |
| 654 | + hint.css( 'display', 'block' ); |
| 655 | + // Ensures posible formating of elements. Second call is in the endDrag method. |
| 656 | + state.isAllowed = setting.isAllowed( state.cEl.el, hint, hint.parents( 'li' ).first() ); |
| 657 | + |
| 658 | + } |
| 659 | + |
| 660 | + /** |
| 661 | + * @desc Called from showHint method. Displays or hides hint element |
| 662 | + * @param e event |
| 663 | + * @param oEl oElement |
| 664 | + * @param outside bool |
| 665 | + * @return No value |
| 666 | + */ |
| 667 | + function showOnTopPlus( e, oEl, outside ) |
| 668 | + { |
| 669 | + if ( $( '#sortableListsHintWrapper', state.rootEl.el ).length ) |
| 670 | + { |
| 671 | + hint.unwrap(); // If hint is wrapped by ul/ol #sortableListsHintWrapper |
| 672 | + } |
| 673 | + |
| 674 | + // Hint inside the oEl |
| 675 | + if ( ! outside && e.pageX - oEl.offset().left > setting.insertZone ) |
| 676 | + { |
| 677 | + var children = oEl.children(), |
| 678 | + list = oEl.children( setting.listSelector ).first(); |
| 679 | + |
| 680 | + if ( list.children().first().is( '#sortableListsPlaceholder' ) ) |
| 681 | + { |
| 682 | + hint.css( 'display', 'none' ); |
| 683 | + return; |
| 684 | + } |
| 685 | + |
| 686 | + // Find out if is necessary to wrap hint by hintWrapper |
| 687 | + if ( ! list.length ) |
| 688 | + { |
| 689 | + children.first().after( hint ); |
| 690 | + hint.wrap( hintWrapper ); |
| 691 | + } |
| 692 | + else |
| 693 | + { |
| 694 | + list.prepend( hint ); |
| 695 | + } |
| 696 | + |
| 697 | + if ( state.oEl ) |
| 698 | + { |
| 699 | + open( oEl ); // TODO:animation??? .children('ul,ol').css('display', 'block'); |
| 700 | + } |
| 701 | + } |
| 702 | + // Hint outside the oEl |
| 703 | + else |
| 704 | + { |
| 705 | + // Ensure display:none if hint will be next to the placeholder |
| 706 | + if ( oEl.prev( '#sortableListsPlaceholder' ).length ) |
| 707 | + { |
| 708 | + hint.css( 'display', 'none' ); |
| 709 | + return; |
| 710 | + } |
| 711 | + oEl.before( hint ); |
| 712 | + |
636 | 713 | } |
637 | 714 |
|
638 | 715 | hint.css( 'display', 'block' ); |
|
647 | 724 | * @param oEl oElement |
648 | 725 | * @return No value |
649 | 726 | */ |
650 | | - function showHintAfter( e, oEl ) |
| 727 | + function showOnBottom( e, oEl ) |
651 | 728 | { |
652 | 729 | if ( $( '#sortableListsHintWrapper', state.rootEl.el ).length ) |
653 | 730 | { |
|
701 | 778 |
|
702 | 779 | } |
703 | 780 |
|
| 781 | + /** |
| 782 | + * @desc Called from showHint function. Displays or hides hint element. |
| 783 | + * @param e event |
| 784 | + * @param oEl oElement |
| 785 | + * @param outside bool |
| 786 | + * @return No value |
| 787 | + */ |
| 788 | + function showOnBottomPlus( e, oEl, outside ) |
| 789 | + { |
| 790 | + if ( $( '#sortableListsHintWrapper', state.rootEl.el ).length ) |
| 791 | + { |
| 792 | + hint.unwrap(); // If hint is wrapped by ul/ol sortableListsHintWrapper |
| 793 | + } |
| 794 | + |
| 795 | + // Hint inside the oEl |
| 796 | + if ( ! outside && e.pageX - oEl.offset().left > setting.insertZone ) |
| 797 | + { |
| 798 | + var children = oEl.children(), |
| 799 | + list = oEl.children( setting.listSelector ).last(); // ul/ol || empty jQuery obj |
| 800 | + |
| 801 | + if ( list.children().last().is( '#sortableListsPlaceholder' ) ) |
| 802 | + { |
| 803 | + hint.css( 'display', 'none' ); |
| 804 | + return; |
| 805 | + } |
| 806 | + |
| 807 | + // Find out if is necessary to wrap hint by hintWrapper |
| 808 | + if ( list.length ) |
| 809 | + { |
| 810 | + children.last().append( hint ); |
| 811 | + } |
| 812 | + else |
| 813 | + { |
| 814 | + oEl.append( hint ); |
| 815 | + hint.wrap( hintWrapper ); |
| 816 | + } |
| 817 | + |
| 818 | + if ( state.oEl ) |
| 819 | + { |
| 820 | + open( oEl ); // TODO: animation??? |
| 821 | + } |
| 822 | + |
| 823 | + } |
| 824 | + // Hint outside the oEl |
| 825 | + else |
| 826 | + { |
| 827 | + // Ensure display:none if hint will be next to the placeholder |
| 828 | + if ( oEl.next( '#sortableListsPlaceholder' ).length ) |
| 829 | + { |
| 830 | + hint.css( 'display', 'none' ); |
| 831 | + return; |
| 832 | + } |
| 833 | + oEl.after( hint ); |
| 834 | + |
| 835 | + } |
| 836 | + |
| 837 | + hint.css( 'display', 'block' ); |
| 838 | + // Ensures posible formating of elements. Second call is in the endDrag method. |
| 839 | + state.isAllowed = setting.isAllowed( state.cEl.el, hint, hint.parents( 'li' ).first() ); |
| 840 | + |
| 841 | + } |
| 842 | + |
| 843 | + //////// End of show hint handlers //////////////////////////////////////////////////// |
| 844 | + //////// Open/close handlers ////////////////////////////////////////////////////////// |
| 845 | + |
704 | 846 | /** |
705 | 847 | * @desc Handles opening nested lists |
706 | 848 | * @param li |
|
752 | 894 |
|
753 | 895 | } |
754 | 896 |
|
| 897 | + /////// Enf of open/close handlers ////////////////////////////////////////////// |
| 898 | + |
755 | 899 | /** |
756 | 900 | * @desc Places the currEl to the target place |
757 | 901 | * @param cEl |
|
0 commit comments