",
527 | options: {
528 | disabled: false,
529 |
530 | // callbacks
531 | create: null
532 | },
533 | _createWidget: function( options, element ) {
534 | element = $( element || this.defaultElement || this )[ 0 ];
535 | this.element = $( element );
536 | this.uuid = uuid++;
537 | this.eventNamespace = "." + this.widgetName + this.uuid;
538 | this.options = $.widget.extend( {},
539 | this.options,
540 | this._getCreateOptions(),
541 | options );
542 |
543 | this.bindings = $();
544 | this.hoverable = $();
545 | this.focusable = $();
546 |
547 | if ( element !== this ) {
548 | $.data( element, this.widgetFullName, this );
549 | this._on( true, this.element, {
550 | remove: function( event ) {
551 | if ( event.target === element ) {
552 | this.destroy();
553 | }
554 | }
555 | });
556 | this.document = $( element.style ?
557 | // element within the document
558 | element.ownerDocument :
559 | // element is window or document
560 | element.document || element );
561 | this.window = $( this.document[0].defaultView || this.document[0].parentWindow );
562 | }
563 |
564 | this._create();
565 | this._trigger( "create", null, this._getCreateEventData() );
566 | this._init();
567 | },
568 | _getCreateOptions: $.noop,
569 | _getCreateEventData: $.noop,
570 | _create: $.noop,
571 | _init: $.noop,
572 |
573 | destroy: function() {
574 | this._destroy();
575 | // we can probably remove the unbind calls in 2.0
576 | // all event bindings should go through this._on()
577 | this.element
578 | .unbind( this.eventNamespace )
579 | // 1.9 BC for #7810
580 | // TODO remove dual storage
581 | .removeData( this.widgetName )
582 | .removeData( this.widgetFullName )
583 | // support: jquery <1.6.3
584 | // http://bugs.jquery.com/ticket/9413
585 | .removeData( $.camelCase( this.widgetFullName ) );
586 | this.widget()
587 | .unbind( this.eventNamespace )
588 | .removeAttr( "aria-disabled" )
589 | .removeClass(
590 | this.widgetFullName + "-disabled " +
591 | "ui-state-disabled" );
592 |
593 | // clean up events and states
594 | this.bindings.unbind( this.eventNamespace );
595 | this.hoverable.removeClass( "ui-state-hover" );
596 | this.focusable.removeClass( "ui-state-focus" );
597 | },
598 | _destroy: $.noop,
599 |
600 | widget: function() {
601 | return this.element;
602 | },
603 |
604 | option: function( key, value ) {
605 | var options = key,
606 | parts,
607 | curOption,
608 | i;
609 |
610 | if ( arguments.length === 0 ) {
611 | // don't return a reference to the internal hash
612 | return $.widget.extend( {}, this.options );
613 | }
614 |
615 | if ( typeof key === "string" ) {
616 | // handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
617 | options = {};
618 | parts = key.split( "." );
619 | key = parts.shift();
620 | if ( parts.length ) {
621 | curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
622 | for ( i = 0; i < parts.length - 1; i++ ) {
623 | curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
624 | curOption = curOption[ parts[ i ] ];
625 | }
626 | key = parts.pop();
627 | if ( value === undefined ) {
628 | return curOption[ key ] === undefined ? null : curOption[ key ];
629 | }
630 | curOption[ key ] = value;
631 | } else {
632 | if ( value === undefined ) {
633 | return this.options[ key ] === undefined ? null : this.options[ key ];
634 | }
635 | options[ key ] = value;
636 | }
637 | }
638 |
639 | this._setOptions( options );
640 |
641 | return this;
642 | },
643 | _setOptions: function( options ) {
644 | var key;
645 |
646 | for ( key in options ) {
647 | this._setOption( key, options[ key ] );
648 | }
649 |
650 | return this;
651 | },
652 | _setOption: function( key, value ) {
653 | this.options[ key ] = value;
654 |
655 | if ( key === "disabled" ) {
656 | this.widget()
657 | .toggleClass( this.widgetFullName + "-disabled ui-state-disabled", !!value )
658 | .attr( "aria-disabled", value );
659 | this.hoverable.removeClass( "ui-state-hover" );
660 | this.focusable.removeClass( "ui-state-focus" );
661 | }
662 |
663 | return this;
664 | },
665 |
666 | enable: function() {
667 | return this._setOption( "disabled", false );
668 | },
669 | disable: function() {
670 | return this._setOption( "disabled", true );
671 | },
672 |
673 | _on: function( suppressDisabledCheck, element, handlers ) {
674 | var delegateElement,
675 | instance = this;
676 |
677 | // no suppressDisabledCheck flag, shuffle arguments
678 | if ( typeof suppressDisabledCheck !== "boolean" ) {
679 | handlers = element;
680 | element = suppressDisabledCheck;
681 | suppressDisabledCheck = false;
682 | }
683 |
684 | // no element argument, shuffle and use this.element
685 | if ( !handlers ) {
686 | handlers = element;
687 | element = this.element;
688 | delegateElement = this.widget();
689 | } else {
690 | // accept selectors, DOM elements
691 | element = delegateElement = $( element );
692 | this.bindings = this.bindings.add( element );
693 | }
694 |
695 | $.each( handlers, function( event, handler ) {
696 | function handlerProxy() {
697 | // allow widgets to customize the disabled handling
698 | // - disabled as an array instead of boolean
699 | // - disabled class as method for disabling individual parts
700 | if ( !suppressDisabledCheck &&
701 | ( instance.options.disabled === true ||
702 | $( this ).hasClass( "ui-state-disabled" ) ) ) {
703 | return;
704 | }
705 | return ( typeof handler === "string" ? instance[ handler ] : handler )
706 | .apply( instance, arguments );
707 | }
708 |
709 | // copy the guid so direct unbinding works
710 | if ( typeof handler !== "string" ) {
711 | handlerProxy.guid = handler.guid =
712 | handler.guid || handlerProxy.guid || $.guid++;
713 | }
714 |
715 | var match = event.match( /^(\w+)\s*(.*)$/ ),
716 | eventName = match[1] + instance.eventNamespace,
717 | selector = match[2];
718 | if ( selector ) {
719 | delegateElement.delegate( selector, eventName, handlerProxy );
720 | } else {
721 | element.bind( eventName, handlerProxy );
722 | }
723 | });
724 | },
725 |
726 | _off: function( element, eventName ) {
727 | eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + this.eventNamespace;
728 | element.unbind( eventName ).undelegate( eventName );
729 | },
730 |
731 | _delay: function( handler, delay ) {
732 | function handlerProxy() {
733 | return ( typeof handler === "string" ? instance[ handler ] : handler )
734 | .apply( instance, arguments );
735 | }
736 | var instance = this;
737 | return setTimeout( handlerProxy, delay || 0 );
738 | },
739 |
740 | _hoverable: function( element ) {
741 | this.hoverable = this.hoverable.add( element );
742 | this._on( element, {
743 | mouseenter: function( event ) {
744 | $( event.currentTarget ).addClass( "ui-state-hover" );
745 | },
746 | mouseleave: function( event ) {
747 | $( event.currentTarget ).removeClass( "ui-state-hover" );
748 | }
749 | });
750 | },
751 |
752 | _focusable: function( element ) {
753 | this.focusable = this.focusable.add( element );
754 | this._on( element, {
755 | focusin: function( event ) {
756 | $( event.currentTarget ).addClass( "ui-state-focus" );
757 | },
758 | focusout: function( event ) {
759 | $( event.currentTarget ).removeClass( "ui-state-focus" );
760 | }
761 | });
762 | },
763 |
764 | _trigger: function( type, event, data ) {
765 | var prop, orig,
766 | callback = this.options[ type ];
767 |
768 | data = data || {};
769 | event = $.Event( event );
770 | event.type = ( type === this.widgetEventPrefix ?
771 | type :
772 | this.widgetEventPrefix + type ).toLowerCase();
773 | // the original event may come from any element
774 | // so we need to reset the target on the new event
775 | event.target = this.element[ 0 ];
776 |
777 | // copy original event properties over to the new event
778 | orig = event.originalEvent;
779 | if ( orig ) {
780 | for ( prop in orig ) {
781 | if ( !( prop in event ) ) {
782 | event[ prop ] = orig[ prop ];
783 | }
784 | }
785 | }
786 |
787 | this.element.trigger( event, data );
788 | return !( $.isFunction( callback ) &&
789 | callback.apply( this.element[0], [ event ].concat( data ) ) === false ||
790 | event.isDefaultPrevented() );
791 | }
792 | };
793 |
794 | $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
795 | $.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
796 | if ( typeof options === "string" ) {
797 | options = { effect: options };
798 | }
799 | var hasOptions,
800 | effectName = !options ?
801 | method :
802 | options === true || typeof options === "number" ?
803 | defaultEffect :
804 | options.effect || defaultEffect;
805 | options = options || {};
806 | if ( typeof options === "number" ) {
807 | options = { duration: options };
808 | }
809 | hasOptions = !$.isEmptyObject( options );
810 | options.complete = callback;
811 | if ( options.delay ) {
812 | element.delay( options.delay );
813 | }
814 | if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {
815 | element[ method ]( options );
816 | } else if ( effectName !== method && element[ effectName ] ) {
817 | element[ effectName ]( options.duration, options.easing, callback );
818 | } else {
819 | element.queue(function( next ) {
820 | $( this )[ method ]();
821 | if ( callback ) {
822 | callback.call( element[ 0 ] );
823 | }
824 | next();
825 | });
826 | }
827 | };
828 | });
829 |
830 | })( jQuery );
831 | (function( $, undefined ) {
832 |
833 | var mouseHandled = false;
834 | $( document ).mouseup( function() {
835 | mouseHandled = false;
836 | });
837 |
838 | $.widget("ui.mouse", {
839 | version: "1.10.0",
840 | options: {
841 | cancel: "input,textarea,button,select,option",
842 | distance: 1,
843 | delay: 0
844 | },
845 | _mouseInit: function() {
846 | var that = this;
847 |
848 | this.element
849 | .bind("mousedown."+this.widgetName, function(event) {
850 | return that._mouseDown(event);
851 | })
852 | .bind("click."+this.widgetName, function(event) {
853 | if (true === $.data(event.target, that.widgetName + ".preventClickEvent")) {
854 | $.removeData(event.target, that.widgetName + ".preventClickEvent");
855 | event.stopImmediatePropagation();
856 | return false;
857 | }
858 | });
859 |
860 | this.started = false;
861 | },
862 |
863 | // TODO: make sure destroying one instance of mouse doesn't mess with
864 | // other instances of mouse
865 | _mouseDestroy: function() {
866 | this.element.unbind("."+this.widgetName);
867 | if ( this._mouseMoveDelegate ) {
868 | $(document)
869 | .unbind("mousemove."+this.widgetName, this._mouseMoveDelegate)
870 | .unbind("mouseup."+this.widgetName, this._mouseUpDelegate);
871 | }
872 | },
873 |
874 | _mouseDown: function(event) {
875 | // don't let more than one widget handle mouseStart
876 | if( mouseHandled ) { return; }
877 |
878 | // we may have missed mouseup (out of window)
879 | (this._mouseStarted && this._mouseUp(event));
880 |
881 | this._mouseDownEvent = event;
882 |
883 | var that = this,
884 | btnIsLeft = (event.which === 1),
885 | // event.target.nodeName works around a bug in IE 8 with
886 | // disabled inputs (#7620)
887 | elIsCancel = (typeof this.options.cancel === "string" && event.target.nodeName ? $(event.target).closest(this.options.cancel).length : false);
888 | if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
889 | return true;
890 | }
891 |
892 | this.mouseDelayMet = !this.options.delay;
893 | if (!this.mouseDelayMet) {
894 | this._mouseDelayTimer = setTimeout(function() {
895 | that.mouseDelayMet = true;
896 | }, this.options.delay);
897 | }
898 |
899 | if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
900 | this._mouseStarted = (this._mouseStart(event) !== false);
901 | if (!this._mouseStarted) {
902 | event.preventDefault();
903 | return true;
904 | }
905 | }
906 |
907 | // Click event may never have fired (Gecko & Opera)
908 | if (true === $.data(event.target, this.widgetName + ".preventClickEvent")) {
909 | $.removeData(event.target, this.widgetName + ".preventClickEvent");
910 | }
911 |
912 | // these delegates are required to keep context
913 | this._mouseMoveDelegate = function(event) {
914 | return that._mouseMove(event);
915 | };
916 | this._mouseUpDelegate = function(event) {
917 | return that._mouseUp(event);
918 | };
919 | $(document)
920 | .bind("mousemove."+this.widgetName, this._mouseMoveDelegate)
921 | .bind("mouseup."+this.widgetName, this._mouseUpDelegate);
922 |
923 | event.preventDefault();
924 |
925 | mouseHandled = true;
926 | return true;
927 | },
928 |
929 | _mouseMove: function(event) {
930 | // IE mouseup check - mouseup happened when mouse was out of window
931 | if ($.ui.ie && ( !document.documentMode || document.documentMode < 9 ) && !event.button) {
932 | return this._mouseUp(event);
933 | }
934 |
935 | if (this._mouseStarted) {
936 | this._mouseDrag(event);
937 | return event.preventDefault();
938 | }
939 |
940 | if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
941 | this._mouseStarted =
942 | (this._mouseStart(this._mouseDownEvent, event) !== false);
943 | (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
944 | }
945 |
946 | return !this._mouseStarted;
947 | },
948 |
949 | _mouseUp: function(event) {
950 | $(document)
951 | .unbind("mousemove."+this.widgetName, this._mouseMoveDelegate)
952 | .unbind("mouseup."+this.widgetName, this._mouseUpDelegate);
953 |
954 | if (this._mouseStarted) {
955 | this._mouseStarted = false;
956 |
957 | if (event.target === this._mouseDownEvent.target) {
958 | $.data(event.target, this.widgetName + ".preventClickEvent", true);
959 | }
960 |
961 | this._mouseStop(event);
962 | }
963 |
964 | return false;
965 | },
966 |
967 | _mouseDistanceMet: function(event) {
968 | return (Math.max(
969 | Math.abs(this._mouseDownEvent.pageX - event.pageX),
970 | Math.abs(this._mouseDownEvent.pageY - event.pageY)
971 | ) >= this.options.distance
972 | );
973 | },
974 |
975 | _mouseDelayMet: function(/* event */) {
976 | return this.mouseDelayMet;
977 | },
978 |
979 | // These are placeholder methods, to be overriden by extending plugin
980 | _mouseStart: function(/* event */) {},
981 | _mouseDrag: function(/* event */) {},
982 | _mouseStop: function(/* event */) {},
983 | _mouseCapture: function(/* event */) { return true; }
984 | });
985 |
986 | })(jQuery);
987 | (function( $, undefined ) {
988 |
989 | $.ui = $.ui || {};
990 |
991 | var cachedScrollbarWidth,
992 | max = Math.max,
993 | abs = Math.abs,
994 | round = Math.round,
995 | rhorizontal = /left|center|right/,
996 | rvertical = /top|center|bottom/,
997 | roffset = /[\+\-]\d+%?/,
998 | rposition = /^\w+/,
999 | rpercent = /%$/,
1000 | _position = $.fn.position;
1001 |
1002 | function getOffsets( offsets, width, height ) {
1003 | return [
1004 | parseInt( offsets[ 0 ], 10 ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ),
1005 | parseInt( offsets[ 1 ], 10 ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 )
1006 | ];
1007 | }
1008 |
1009 | function parseCss( element, property ) {
1010 | return parseInt( $.css( element, property ), 10 ) || 0;
1011 | }
1012 |
1013 | function getDimensions( elem ) {
1014 | var raw = elem[0];
1015 | if ( raw.nodeType === 9 ) {
1016 | return {
1017 | width: elem.width(),
1018 | height: elem.height(),
1019 | offset: { top: 0, left: 0 }
1020 | };
1021 | }
1022 | if ( $.isWindow( raw ) ) {
1023 | return {
1024 | width: elem.width(),
1025 | height: elem.height(),
1026 | offset: { top: elem.scrollTop(), left: elem.scrollLeft() }
1027 | };
1028 | }
1029 | if ( raw.preventDefault ) {
1030 | return {
1031 | width: 0,
1032 | height: 0,
1033 | offset: { top: raw.pageY, left: raw.pageX }
1034 | };
1035 | }
1036 | return {
1037 | width: elem.outerWidth(),
1038 | height: elem.outerHeight(),
1039 | offset: elem.offset()
1040 | };
1041 | }
1042 |
1043 | $.position = {
1044 | scrollbarWidth: function() {
1045 | if ( cachedScrollbarWidth !== undefined ) {
1046 | return cachedScrollbarWidth;
1047 | }
1048 | var w1, w2,
1049 | div = $( "
" ),
1050 | innerDiv = div.children()[0];
1051 |
1052 | $( "body" ).append( div );
1053 | w1 = innerDiv.offsetWidth;
1054 | div.css( "overflow", "scroll" );
1055 |
1056 | w2 = innerDiv.offsetWidth;
1057 |
1058 | if ( w1 === w2 ) {
1059 | w2 = div[0].clientWidth;
1060 | }
1061 |
1062 | div.remove();
1063 |
1064 | return (cachedScrollbarWidth = w1 - w2);
1065 | },
1066 | getScrollInfo: function( within ) {
1067 | var overflowX = within.isWindow ? "" : within.element.css( "overflow-x" ),
1068 | overflowY = within.isWindow ? "" : within.element.css( "overflow-y" ),
1069 | hasOverflowX = overflowX === "scroll" ||
1070 | ( overflowX === "auto" && within.width < within.element[0].scrollWidth ),
1071 | hasOverflowY = overflowY === "scroll" ||
1072 | ( overflowY === "auto" && within.height < within.element[0].scrollHeight );
1073 | return {
1074 | width: hasOverflowX ? $.position.scrollbarWidth() : 0,
1075 | height: hasOverflowY ? $.position.scrollbarWidth() : 0
1076 | };
1077 | },
1078 | getWithinInfo: function( element ) {
1079 | var withinElement = $( element || window ),
1080 | isWindow = $.isWindow( withinElement[0] );
1081 | return {
1082 | element: withinElement,
1083 | isWindow: isWindow,
1084 | offset: withinElement.offset() || { left: 0, top: 0 },
1085 | scrollLeft: withinElement.scrollLeft(),
1086 | scrollTop: withinElement.scrollTop(),
1087 | width: isWindow ? withinElement.width() : withinElement.outerWidth(),
1088 | height: isWindow ? withinElement.height() : withinElement.outerHeight()
1089 | };
1090 | }
1091 | };
1092 |
1093 | $.fn.position = function( options ) {
1094 | if ( !options || !options.of ) {
1095 | return _position.apply( this, arguments );
1096 | }
1097 |
1098 | // make a copy, we don't want to modify arguments
1099 | options = $.extend( {}, options );
1100 |
1101 | var atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions,
1102 | target = $( options.of ),
1103 | within = $.position.getWithinInfo( options.within ),
1104 | scrollInfo = $.position.getScrollInfo( within ),
1105 | collision = ( options.collision || "flip" ).split( " " ),
1106 | offsets = {};
1107 |
1108 | dimensions = getDimensions( target );
1109 | if ( target[0].preventDefault ) {
1110 | // force left top to allow flipping
1111 | options.at = "left top";
1112 | }
1113 | targetWidth = dimensions.width;
1114 | targetHeight = dimensions.height;
1115 | targetOffset = dimensions.offset;
1116 | // clone to reuse original targetOffset later
1117 | basePosition = $.extend( {}, targetOffset );
1118 |
1119 | // force my and at to have valid horizontal and vertical positions
1120 | // if a value is missing or invalid, it will be converted to center
1121 | $.each( [ "my", "at" ], function() {
1122 | var pos = ( options[ this ] || "" ).split( " " ),
1123 | horizontalOffset,
1124 | verticalOffset;
1125 |
1126 | if ( pos.length === 1) {
1127 | pos = rhorizontal.test( pos[ 0 ] ) ?
1128 | pos.concat( [ "center" ] ) :
1129 | rvertical.test( pos[ 0 ] ) ?
1130 | [ "center" ].concat( pos ) :
1131 | [ "center", "center" ];
1132 | }
1133 | pos[ 0 ] = rhorizontal.test( pos[ 0 ] ) ? pos[ 0 ] : "center";
1134 | pos[ 1 ] = rvertical.test( pos[ 1 ] ) ? pos[ 1 ] : "center";
1135 |
1136 | // calculate offsets
1137 | horizontalOffset = roffset.exec( pos[ 0 ] );
1138 | verticalOffset = roffset.exec( pos[ 1 ] );
1139 | offsets[ this ] = [
1140 | horizontalOffset ? horizontalOffset[ 0 ] : 0,
1141 | verticalOffset ? verticalOffset[ 0 ] : 0
1142 | ];
1143 |
1144 | // reduce to just the positions without the offsets
1145 | options[ this ] = [
1146 | rposition.exec( pos[ 0 ] )[ 0 ],
1147 | rposition.exec( pos[ 1 ] )[ 0 ]
1148 | ];
1149 | });
1150 |
1151 | // normalize collision option
1152 | if ( collision.length === 1 ) {
1153 | collision[ 1 ] = collision[ 0 ];
1154 | }
1155 |
1156 | if ( options.at[ 0 ] === "right" ) {
1157 | basePosition.left += targetWidth;
1158 | } else if ( options.at[ 0 ] === "center" ) {
1159 | basePosition.left += targetWidth / 2;
1160 | }
1161 |
1162 | if ( options.at[ 1 ] === "bottom" ) {
1163 | basePosition.top += targetHeight;
1164 | } else if ( options.at[ 1 ] === "center" ) {
1165 | basePosition.top += targetHeight / 2;
1166 | }
1167 |
1168 | atOffset = getOffsets( offsets.at, targetWidth, targetHeight );
1169 | basePosition.left += atOffset[ 0 ];
1170 | basePosition.top += atOffset[ 1 ];
1171 |
1172 | return this.each(function() {
1173 | var collisionPosition, using,
1174 | elem = $( this ),
1175 | elemWidth = elem.outerWidth(),
1176 | elemHeight = elem.outerHeight(),
1177 | marginLeft = parseCss( this, "marginLeft" ),
1178 | marginTop = parseCss( this, "marginTop" ),
1179 | collisionWidth = elemWidth + marginLeft + parseCss( this, "marginRight" ) + scrollInfo.width,
1180 | collisionHeight = elemHeight + marginTop + parseCss( this, "marginBottom" ) + scrollInfo.height,
1181 | position = $.extend( {}, basePosition ),
1182 | myOffset = getOffsets( offsets.my, elem.outerWidth(), elem.outerHeight() );
1183 |
1184 | if ( options.my[ 0 ] === "right" ) {
1185 | position.left -= elemWidth;
1186 | } else if ( options.my[ 0 ] === "center" ) {
1187 | position.left -= elemWidth / 2;
1188 | }
1189 |
1190 | if ( options.my[ 1 ] === "bottom" ) {
1191 | position.top -= elemHeight;
1192 | } else if ( options.my[ 1 ] === "center" ) {
1193 | position.top -= elemHeight / 2;
1194 | }
1195 |
1196 | position.left += myOffset[ 0 ];
1197 | position.top += myOffset[ 1 ];
1198 |
1199 | // if the browser doesn't support fractions, then round for consistent results
1200 | if ( !$.support.offsetFractions ) {
1201 | position.left = round( position.left );
1202 | position.top = round( position.top );
1203 | }
1204 |
1205 | collisionPosition = {
1206 | marginLeft: marginLeft,
1207 | marginTop: marginTop
1208 | };
1209 |
1210 | $.each( [ "left", "top" ], function( i, dir ) {
1211 | if ( $.ui.position[ collision[ i ] ] ) {
1212 | $.ui.position[ collision[ i ] ][ dir ]( position, {
1213 | targetWidth: targetWidth,
1214 | targetHeight: targetHeight,
1215 | elemWidth: elemWidth,
1216 | elemHeight: elemHeight,
1217 | collisionPosition: collisionPosition,
1218 | collisionWidth: collisionWidth,
1219 | collisionHeight: collisionHeight,
1220 | offset: [ atOffset[ 0 ] + myOffset[ 0 ], atOffset [ 1 ] + myOffset[ 1 ] ],
1221 | my: options.my,
1222 | at: options.at,
1223 | within: within,
1224 | elem : elem
1225 | });
1226 | }
1227 | });
1228 |
1229 | if ( options.using ) {
1230 | // adds feedback as second argument to using callback, if present
1231 | using = function( props ) {
1232 | var left = targetOffset.left - position.left,
1233 | right = left + targetWidth - elemWidth,
1234 | top = targetOffset.top - position.top,
1235 | bottom = top + targetHeight - elemHeight,
1236 | feedback = {
1237 | target: {
1238 | element: target,
1239 | left: targetOffset.left,
1240 | top: targetOffset.top,
1241 | width: targetWidth,
1242 | height: targetHeight
1243 | },
1244 | element: {
1245 | element: elem,
1246 | left: position.left,
1247 | top: position.top,
1248 | width: elemWidth,
1249 | height: elemHeight
1250 | },
1251 | horizontal: right < 0 ? "left" : left > 0 ? "right" : "center",
1252 | vertical: bottom < 0 ? "top" : top > 0 ? "bottom" : "middle"
1253 | };
1254 | if ( targetWidth < elemWidth && abs( left + right ) < targetWidth ) {
1255 | feedback.horizontal = "center";
1256 | }
1257 | if ( targetHeight < elemHeight && abs( top + bottom ) < targetHeight ) {
1258 | feedback.vertical = "middle";
1259 | }
1260 | if ( max( abs( left ), abs( right ) ) > max( abs( top ), abs( bottom ) ) ) {
1261 | feedback.important = "horizontal";
1262 | } else {
1263 | feedback.important = "vertical";
1264 | }
1265 | options.using.call( this, props, feedback );
1266 | };
1267 | }
1268 |
1269 | elem.offset( $.extend( position, { using: using } ) );
1270 | });
1271 | };
1272 |
1273 | $.ui.position = {
1274 | fit: {
1275 | left: function( position, data ) {
1276 | var within = data.within,
1277 | withinOffset = within.isWindow ? within.scrollLeft : within.offset.left,
1278 | outerWidth = within.width,
1279 | collisionPosLeft = position.left - data.collisionPosition.marginLeft,
1280 | overLeft = withinOffset - collisionPosLeft,
1281 | overRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset,
1282 | newOverRight;
1283 |
1284 | // element is wider than within
1285 | if ( data.collisionWidth > outerWidth ) {
1286 | // element is initially over the left side of within
1287 | if ( overLeft > 0 && overRight <= 0 ) {
1288 | newOverRight = position.left + overLeft + data.collisionWidth - outerWidth - withinOffset;
1289 | position.left += overLeft - newOverRight;
1290 | // element is initially over right side of within
1291 | } else if ( overRight > 0 && overLeft <= 0 ) {
1292 | position.left = withinOffset;
1293 | // element is initially over both left and right sides of within
1294 | } else {
1295 | if ( overLeft > overRight ) {
1296 | position.left = withinOffset + outerWidth - data.collisionWidth;
1297 | } else {
1298 | position.left = withinOffset;
1299 | }
1300 | }
1301 | // too far left -> align with left edge
1302 | } else if ( overLeft > 0 ) {
1303 | position.left += overLeft;
1304 | // too far right -> align with right edge
1305 | } else if ( overRight > 0 ) {
1306 | position.left -= overRight;
1307 | // adjust based on position and margin
1308 | } else {
1309 | position.left = max( position.left - collisionPosLeft, position.left );
1310 | }
1311 | },
1312 | top: function( position, data ) {
1313 | var within = data.within,
1314 | withinOffset = within.isWindow ? within.scrollTop : within.offset.top,
1315 | outerHeight = data.within.height,
1316 | collisionPosTop = position.top - data.collisionPosition.marginTop,
1317 | overTop = withinOffset - collisionPosTop,
1318 | overBottom = collisionPosTop + data.collisionHeight - outerHeight - withinOffset,
1319 | newOverBottom;
1320 |
1321 | // element is taller than within
1322 | if ( data.collisionHeight > outerHeight ) {
1323 | // element is initially over the top of within
1324 | if ( overTop > 0 && overBottom <= 0 ) {
1325 | newOverBottom = position.top + overTop + data.collisionHeight - outerHeight - withinOffset;
1326 | position.top += overTop - newOverBottom;
1327 | // element is initially over bottom of within
1328 | } else if ( overBottom > 0 && overTop <= 0 ) {
1329 | position.top = withinOffset;
1330 | // element is initially over both top and bottom of within
1331 | } else {
1332 | if ( overTop > overBottom ) {
1333 | position.top = withinOffset + outerHeight - data.collisionHeight;
1334 | } else {
1335 | position.top = withinOffset;
1336 | }
1337 | }
1338 | // too far up -> align with top
1339 | } else if ( overTop > 0 ) {
1340 | position.top += overTop;
1341 | // too far down -> align with bottom edge
1342 | } else if ( overBottom > 0 ) {
1343 | position.top -= overBottom;
1344 | // adjust based on position and margin
1345 | } else {
1346 | position.top = max( position.top - collisionPosTop, position.top );
1347 | }
1348 | }
1349 | },
1350 | flip: {
1351 | left: function( position, data ) {
1352 | var within = data.within,
1353 | withinOffset = within.offset.left + within.scrollLeft,
1354 | outerWidth = within.width,
1355 | offsetLeft = within.isWindow ? within.scrollLeft : within.offset.left,
1356 | collisionPosLeft = position.left - data.collisionPosition.marginLeft,
1357 | overLeft = collisionPosLeft - offsetLeft,
1358 | overRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft,
1359 | myOffset = data.my[ 0 ] === "left" ?
1360 | -data.elemWidth :
1361 | data.my[ 0 ] === "right" ?
1362 | data.elemWidth :
1363 | 0,
1364 | atOffset = data.at[ 0 ] === "left" ?
1365 | data.targetWidth :
1366 | data.at[ 0 ] === "right" ?
1367 | -data.targetWidth :
1368 | 0,
1369 | offset = -2 * data.offset[ 0 ],
1370 | newOverRight,
1371 | newOverLeft;
1372 |
1373 | if ( overLeft < 0 ) {
1374 | newOverRight = position.left + myOffset + atOffset + offset + data.collisionWidth - outerWidth - withinOffset;
1375 | if ( newOverRight < 0 || newOverRight < abs( overLeft ) ) {
1376 | position.left += myOffset + atOffset + offset;
1377 | }
1378 | }
1379 | else if ( overRight > 0 ) {
1380 | newOverLeft = position.left - data.collisionPosition.marginLeft + myOffset + atOffset + offset - offsetLeft;
1381 | if ( newOverLeft > 0 || abs( newOverLeft ) < overRight ) {
1382 | position.left += myOffset + atOffset + offset;
1383 | }
1384 | }
1385 | },
1386 | top: function( position, data ) {
1387 | var within = data.within,
1388 | withinOffset = within.offset.top + within.scrollTop,
1389 | outerHeight = within.height,
1390 | offsetTop = within.isWindow ? within.scrollTop : within.offset.top,
1391 | collisionPosTop = position.top - data.collisionPosition.marginTop,
1392 | overTop = collisionPosTop - offsetTop,
1393 | overBottom = collisionPosTop + data.collisionHeight - outerHeight - offsetTop,
1394 | top = data.my[ 1 ] === "top",
1395 | myOffset = top ?
1396 | -data.elemHeight :
1397 | data.my[ 1 ] === "bottom" ?
1398 | data.elemHeight :
1399 | 0,
1400 | atOffset = data.at[ 1 ] === "top" ?
1401 | data.targetHeight :
1402 | data.at[ 1 ] === "bottom" ?
1403 | -data.targetHeight :
1404 | 0,
1405 | offset = -2 * data.offset[ 1 ],
1406 | newOverTop,
1407 | newOverBottom;
1408 | if ( overTop < 0 ) {
1409 | newOverBottom = position.top + myOffset + atOffset + offset + data.collisionHeight - outerHeight - withinOffset;
1410 | if ( ( position.top + myOffset + atOffset + offset) > overTop && ( newOverBottom < 0 || newOverBottom < abs( overTop ) ) ) {
1411 | position.top += myOffset + atOffset + offset;
1412 | }
1413 | }
1414 | else if ( overBottom > 0 ) {
1415 | newOverTop = position.top - data.collisionPosition.marginTop + myOffset + atOffset + offset - offsetTop;
1416 | if ( ( position.top + myOffset + atOffset + offset) > overBottom && ( newOverTop > 0 || abs( newOverTop ) < overBottom ) ) {
1417 | position.top += myOffset + atOffset + offset;
1418 | }
1419 | }
1420 | }
1421 | },
1422 | flipfit: {
1423 | left: function() {
1424 | $.ui.position.flip.left.apply( this, arguments );
1425 | $.ui.position.fit.left.apply( this, arguments );
1426 | },
1427 | top: function() {
1428 | $.ui.position.flip.top.apply( this, arguments );
1429 | $.ui.position.fit.top.apply( this, arguments );
1430 | }
1431 | }
1432 | };
1433 |
1434 | // fraction support test
1435 | (function () {
1436 | var testElement, testElementParent, testElementStyle, offsetLeft, i,
1437 | body = document.getElementsByTagName( "body" )[ 0 ],
1438 | div = document.createElement( "div" );
1439 |
1440 | //Create a "fake body" for testing based on method used in jQuery.support
1441 | testElement = document.createElement( body ? "div" : "body" );
1442 | testElementStyle = {
1443 | visibility: "hidden",
1444 | width: 0,
1445 | height: 0,
1446 | border: 0,
1447 | margin: 0,
1448 | background: "none"
1449 | };
1450 | if ( body ) {
1451 | $.extend( testElementStyle, {
1452 | position: "absolute",
1453 | left: "-1000px",
1454 | top: "-1000px"
1455 | });
1456 | }
1457 | for ( i in testElementStyle ) {
1458 | testElement.style[ i ] = testElementStyle[ i ];
1459 | }
1460 | testElement.appendChild( div );
1461 | testElementParent = body || document.documentElement;
1462 | testElementParent.insertBefore( testElement, testElementParent.firstChild );
1463 |
1464 | div.style.cssText = "position: absolute; left: 10.7432222px;";
1465 |
1466 | offsetLeft = $( div ).offset().left;
1467 | $.support.offsetFractions = offsetLeft > 10 && offsetLeft < 11;
1468 |
1469 | testElement.innerHTML = "";
1470 | testElementParent.removeChild( testElement );
1471 | })();
1472 |
1473 | }( jQuery ) );
1474 | (function( $, undefined ) {
1475 |
1476 | $.widget("ui.draggable", $.ui.mouse, {
1477 | version: "1.10.0",
1478 | widgetEventPrefix: "drag",
1479 | options: {
1480 | addClasses: true,
1481 | appendTo: "parent",
1482 | axis: false,
1483 | connectToSortable: false,
1484 | containment: false,
1485 | cursor: "auto",
1486 | cursorAt: false,
1487 | grid: false,
1488 | handle: false,
1489 | helper: "original",
1490 | iframeFix: false,
1491 | opacity: false,
1492 | refreshPositions: false,
1493 | revert: false,
1494 | revertDuration: 500,
1495 | scope: "default",
1496 | scroll: true,
1497 | scrollSensitivity: 20,
1498 | scrollSpeed: 20,
1499 | snap: false,
1500 | snapMode: "both",
1501 | snapTolerance: 20,
1502 | stack: false,
1503 | zIndex: false,
1504 |
1505 | // callbacks
1506 | drag: null,
1507 | start: null,
1508 | stop: null
1509 | },
1510 | _create: function() {
1511 |
1512 | if (this.options.helper === "original" && !(/^(?:r|a|f)/).test(this.element.css("position"))) {
1513 | this.element[0].style.position = "relative";
1514 | }
1515 | if (this.options.addClasses){
1516 | this.element.addClass("ui-draggable");
1517 | }
1518 | if (this.options.disabled){
1519 | this.element.addClass("ui-draggable-disabled");
1520 | }
1521 |
1522 | this._mouseInit();
1523 |
1524 | },
1525 |
1526 | _destroy: function() {
1527 | this.element.removeClass( "ui-draggable ui-draggable-dragging ui-draggable-disabled" );
1528 | this._mouseDestroy();
1529 | },
1530 |
1531 | _mouseCapture: function(event) {
1532 |
1533 | var o = this.options;
1534 |
1535 | // among others, prevent a drag on a resizable-handle
1536 | if (this.helper || o.disabled || $(event.target).closest(".ui-resizable-handle").length > 0) {
1537 | return false;
1538 | }
1539 |
1540 | //Quit if we're not on a valid handle
1541 | this.handle = this._getHandle(event);
1542 | if (!this.handle) {
1543 | return false;
1544 | }
1545 |
1546 | $(o.iframeFix === true ? "iframe" : o.iframeFix).each(function() {
1547 | $("
")
1548 | .css({
1549 | width: this.offsetWidth+"px", height: this.offsetHeight+"px",
1550 | position: "absolute", opacity: "0.001", zIndex: 1000
1551 | })
1552 | .css($(this).offset())
1553 | .appendTo("body");
1554 | });
1555 |
1556 | return true;
1557 |
1558 | },
1559 |
1560 | _mouseStart: function(event) {
1561 |
1562 | var o = this.options;
1563 |
1564 | //Create and append the visible helper
1565 | this.helper = this._createHelper(event);
1566 |
1567 | this.helper.addClass("ui-draggable-dragging");
1568 |
1569 | //Cache the helper size
1570 | this._cacheHelperProportions();
1571 |
1572 | //If ddmanager is used for droppables, set the global draggable
1573 | if($.ui.ddmanager) {
1574 | $.ui.ddmanager.current = this;
1575 | }
1576 |
1577 | /*
1578 | * - Position generation -
1579 | * This block generates everything position related - it's the core of draggables.
1580 | */
1581 |
1582 | //Cache the margins of the original element
1583 | this._cacheMargins();
1584 |
1585 | //Store the helper's css position
1586 | this.cssPosition = this.helper.css("position");
1587 | this.scrollParent = this.helper.scrollParent();
1588 |
1589 | //The element's absolute position on the page minus margins
1590 | this.offset = this.positionAbs = this.element.offset();
1591 | this.offset = {
1592 | top: this.offset.top - this.margins.top,
1593 | left: this.offset.left - this.margins.left
1594 | };
1595 |
1596 | $.extend(this.offset, {
1597 | click: { //Where the click happened, relative to the element
1598 | left: event.pageX - this.offset.left,
1599 | top: event.pageY - this.offset.top
1600 | },
1601 | parent: this._getParentOffset(),
1602 | relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
1603 | });
1604 |
1605 | //Generate the original position
1606 | this.originalPosition = this.position = this._generatePosition(event);
1607 | this.originalPageX = event.pageX;
1608 | this.originalPageY = event.pageY;
1609 |
1610 | //Adjust the mouse offset relative to the helper if "cursorAt" is supplied
1611 | (o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt));
1612 |
1613 | //Set a containment if given in the options
1614 | if(o.containment) {
1615 | this._setContainment();
1616 | }
1617 |
1618 | //Trigger event + callbacks
1619 | if(this._trigger("start", event) === false) {
1620 | this._clear();
1621 | return false;
1622 | }
1623 |
1624 | //Recache the helper size
1625 | this._cacheHelperProportions();
1626 |
1627 | //Prepare the droppable offsets
1628 | if ($.ui.ddmanager && !o.dropBehaviour) {
1629 | $.ui.ddmanager.prepareOffsets(this, event);
1630 | }
1631 |
1632 |
1633 | this._mouseDrag(event, true); //Execute the drag once - this causes the helper not to be visible before getting its correct position
1634 |
1635 | //If the ddmanager is used for droppables, inform the manager that dragging has started (see #5003)
1636 | if ( $.ui.ddmanager ) {
1637 | $.ui.ddmanager.dragStart(this, event);
1638 | }
1639 |
1640 | return true;
1641 | },
1642 |
1643 | _mouseDrag: function(event, noPropagation) {
1644 |
1645 | //Compute the helpers position
1646 | this.position = this._generatePosition(event);
1647 | this.positionAbs = this._convertPositionTo("absolute");
1648 |
1649 | //Call plugins and callbacks and use the resulting position if something is returned
1650 | if (!noPropagation) {
1651 | var ui = this._uiHash();
1652 | if(this._trigger("drag", event, ui) === false) {
1653 | this._mouseUp({});
1654 | return false;
1655 | }
1656 | this.position = ui.position;
1657 | }
1658 |
1659 | if(!this.options.axis || this.options.axis !== "y") {
1660 | this.helper[0].style.left = this.position.left+"px";
1661 | }
1662 | if(!this.options.axis || this.options.axis !== "x") {
1663 | this.helper[0].style.top = this.position.top+"px";
1664 | }
1665 | if($.ui.ddmanager) {
1666 | $.ui.ddmanager.drag(this, event);
1667 | }
1668 |
1669 | return false;
1670 | },
1671 |
1672 | _mouseStop: function(event) {
1673 |
1674 | //If we are using droppables, inform the manager about the drop
1675 | var element,
1676 | that = this,
1677 | elementInDom = false,
1678 | dropped = false;
1679 | if ($.ui.ddmanager && !this.options.dropBehaviour) {
1680 | dropped = $.ui.ddmanager.drop(this, event);
1681 | }
1682 |
1683 | //if a drop comes from outside (a sortable)
1684 | if(this.dropped) {
1685 | dropped = this.dropped;
1686 | this.dropped = false;
1687 | }
1688 |
1689 | //if the original element is no longer in the DOM don't bother to continue (see #8269)
1690 | element = this.element[0];
1691 | while ( element && (element = element.parentNode) ) {
1692 | if (element === document ) {
1693 | elementInDom = true;
1694 | }
1695 | }
1696 | if ( !elementInDom && this.options.helper === "original" ) {
1697 | return false;
1698 | }
1699 |
1700 | if((this.options.revert === "invalid" && !dropped) || (this.options.revert === "valid" && dropped) || this.options.revert === true || ($.isFunction(this.options.revert) && this.options.revert.call(this.element, dropped))) {
1701 | $(this.helper).animate(this.originalPosition, parseInt(this.options.revertDuration, 10), function() {
1702 | if(that._trigger("stop", event) !== false) {
1703 | that._clear();
1704 | }
1705 | });
1706 | } else {
1707 | if(this._trigger("stop", event) !== false) {
1708 | this._clear();
1709 | }
1710 | }
1711 |
1712 | return false;
1713 | },
1714 |
1715 | _mouseUp: function(event) {
1716 | //Remove frame helpers
1717 | $("div.ui-draggable-iframeFix").each(function() {
1718 | this.parentNode.removeChild(this);
1719 | });
1720 |
1721 | //If the ddmanager is used for droppables, inform the manager that dragging has stopped (see #5003)
1722 | if( $.ui.ddmanager ) {
1723 | $.ui.ddmanager.dragStop(this, event);
1724 | }
1725 |
1726 | return $.ui.mouse.prototype._mouseUp.call(this, event);
1727 | },
1728 |
1729 | cancel: function() {
1730 |
1731 | if(this.helper.is(".ui-draggable-dragging")) {
1732 | this._mouseUp({});
1733 | } else {
1734 | this._clear();
1735 | }
1736 |
1737 | return this;
1738 |
1739 | },
1740 |
1741 | _getHandle: function(event) {
1742 |
1743 | var handle = !this.options.handle || !$(this.options.handle, this.element).length ? true : false;
1744 | $(this.options.handle, this.element)
1745 | .find("*")
1746 | .addBack()
1747 | .each(function() {
1748 | if(this === event.target) {
1749 | handle = true;
1750 | }
1751 | });
1752 |
1753 | return handle;
1754 |
1755 | },
1756 |
1757 | _createHelper: function(event) {
1758 |
1759 | var o = this.options,
1760 | helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event])) : (o.helper === "clone" ? this.element.clone().removeAttr("id") : this.element);
1761 |
1762 | if(!helper.parents("body").length) {
1763 | helper.appendTo((o.appendTo === "parent" ? this.element[0].parentNode : o.appendTo));
1764 | }
1765 |
1766 | if(helper[0] !== this.element[0] && !(/(fixed|absolute)/).test(helper.css("position"))) {
1767 | helper.css("position", "absolute");
1768 | }
1769 |
1770 | return helper;
1771 |
1772 | },
1773 |
1774 | _adjustOffsetFromHelper: function(obj) {
1775 | if (typeof obj === "string") {
1776 | obj = obj.split(" ");
1777 | }
1778 | if ($.isArray(obj)) {
1779 | obj = {left: +obj[0], top: +obj[1] || 0};
1780 | }
1781 | if ("left" in obj) {
1782 | this.offset.click.left = obj.left + this.margins.left;
1783 | }
1784 | if ("right" in obj) {
1785 | this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
1786 | }
1787 | if ("top" in obj) {
1788 | this.offset.click.top = obj.top + this.margins.top;
1789 | }
1790 | if ("bottom" in obj) {
1791 | this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
1792 | }
1793 | },
1794 |
1795 | _getParentOffset: function() {
1796 |
1797 | //Get the offsetParent and cache its position
1798 | this.offsetParent = this.helper.offsetParent();
1799 | var po = this.offsetParent.offset();
1800 |
1801 | // This is a special case where we need to modify a offset calculated on start, since the following happened:
1802 | // 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent
1803 | // 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that
1804 | // the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag
1805 | if(this.cssPosition === "absolute" && this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) {
1806 | po.left += this.scrollParent.scrollLeft();
1807 | po.top += this.scrollParent.scrollTop();
1808 | }
1809 |
1810 | //This needs to be actually done for all browsers, since pageX/pageY includes this information
1811 | //Ugly IE fix
1812 | if((this.offsetParent[0] === document.body) ||
1813 | (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() === "html" && $.ui.ie)) {
1814 | po = { top: 0, left: 0 };
1815 | }
1816 |
1817 | return {
1818 | top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0),
1819 | left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0)
1820 | };
1821 |
1822 | },
1823 |
1824 | _getRelativeOffset: function() {
1825 |
1826 | if(this.cssPosition === "relative") {
1827 | var p = this.element.position();
1828 | return {
1829 | top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(),
1830 | left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.scrollParent.scrollLeft()
1831 | };
1832 | } else {
1833 | return { top: 0, left: 0 };
1834 | }
1835 |
1836 | },
1837 |
1838 | _cacheMargins: function() {
1839 | this.margins = {
1840 | left: (parseInt(this.element.css("marginLeft"),10) || 0),
1841 | top: (parseInt(this.element.css("marginTop"),10) || 0),
1842 | right: (parseInt(this.element.css("marginRight"),10) || 0),
1843 | bottom: (parseInt(this.element.css("marginBottom"),10) || 0)
1844 | };
1845 | },
1846 |
1847 | _cacheHelperProportions: function() {
1848 | this.helperProportions = {
1849 | width: this.helper.outerWidth(),
1850 | height: this.helper.outerHeight()
1851 | };
1852 | },
1853 |
1854 | _setContainment: function() {
1855 |
1856 | var over, c, ce,
1857 | o = this.options;
1858 |
1859 | if(o.containment === "parent") {
1860 | o.containment = this.helper[0].parentNode;
1861 | }
1862 | if(o.containment === "document" || o.containment === "window") {
1863 | this.containment = [
1864 | o.containment === "document" ? 0 : $(window).scrollLeft() - this.offset.relative.left - this.offset.parent.left,
1865 | o.containment === "document" ? 0 : $(window).scrollTop() - this.offset.relative.top - this.offset.parent.top,
1866 | (o.containment === "document" ? 0 : $(window).scrollLeft()) + $(o.containment === "document" ? document : window).width() - this.helperProportions.width - this.margins.left,
1867 | (o.containment === "document" ? 0 : $(window).scrollTop()) + ($(o.containment === "document" ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top
1868 | ];
1869 | }
1870 |
1871 | if(!(/^(document|window|parent)$/).test(o.containment) && o.containment.constructor !== Array) {
1872 | c = $(o.containment);
1873 | ce = c[0];
1874 |
1875 | if(!ce) {
1876 | return;
1877 | }
1878 |
1879 | over = ($(ce).css("overflow") !== "hidden");
1880 |
1881 | this.containment = [
1882 | (parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0),
1883 | (parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0),
1884 | (over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - (parseInt($(ce).css("paddingRight"),10) || 0) - this.helperProportions.width - this.margins.left - this.margins.right,
1885 | (over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - (parseInt($(ce).css("paddingBottom"),10) || 0) - this.helperProportions.height - this.margins.top - this.margins.bottom
1886 | ];
1887 | this.relative_container = c;
1888 |
1889 | } else if(o.containment.constructor === Array) {
1890 | this.containment = o.containment;
1891 | }
1892 |
1893 | },
1894 |
1895 | _convertPositionTo: function(d, pos) {
1896 |
1897 | if(!pos) {
1898 | pos = this.position;
1899 | }
1900 |
1901 | var mod = d === "absolute" ? 1 : -1,
1902 | scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
1903 |
1904 | return {
1905 | top: (
1906 | pos.top + // The absolute mouse position
1907 | this.offset.relative.top * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
1908 | this.offset.parent.top * mod - // The offsetParent's offset without borders (offset + border)
1909 | ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod)
1910 | ),
1911 | left: (
1912 | pos.left + // The absolute mouse position
1913 | this.offset.relative.left * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
1914 | this.offset.parent.left * mod - // The offsetParent's offset without borders (offset + border)
1915 | ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod)
1916 | )
1917 | };
1918 |
1919 | },
1920 |
1921 | _generatePosition: function(event) {
1922 |
1923 | var containment, co, top, left,
1924 | o = this.options,
1925 | scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent,
1926 | scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName),
1927 | pageX = event.pageX,
1928 | pageY = event.pageY;
1929 |
1930 | /*
1931 | * - Position constraining -
1932 | * Constrain the position to a mix of grid, containment.
1933 | */
1934 |
1935 | if(this.originalPosition) { //If we are not dragging yet, we won't check for options
1936 | if(this.containment) {
1937 | if (this.relative_container){
1938 | co = this.relative_container.offset();
1939 | containment = [ this.containment[0] + co.left,
1940 | this.containment[1] + co.top,
1941 | this.containment[2] + co.left,
1942 | this.containment[3] + co.top ];
1943 | }
1944 | else {
1945 | containment = this.containment;
1946 | }
1947 |
1948 | if(event.pageX - this.offset.click.left < containment[0]) {
1949 | pageX = containment[0] + this.offset.click.left;
1950 | }
1951 | if(event.pageY - this.offset.click.top < containment[1]) {
1952 | pageY = containment[1] + this.offset.click.top;
1953 | }
1954 | if(event.pageX - this.offset.click.left > containment[2]) {
1955 | pageX = containment[2] + this.offset.click.left;
1956 | }
1957 | if(event.pageY - this.offset.click.top > containment[3]) {
1958 | pageY = containment[3] + this.offset.click.top;
1959 | }
1960 | }
1961 |
1962 | if(o.grid) {
1963 | //Check for grid elements set to 0 to prevent divide by 0 error causing invalid argument errors in IE (see ticket #6950)
1964 | top = o.grid[1] ? this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1] : this.originalPageY;
1965 | pageY = containment ? ((top - this.offset.click.top >= containment[1] || top - this.offset.click.top > containment[3]) ? top : ((top - this.offset.click.top >= containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top;
1966 |
1967 | left = o.grid[0] ? this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0] : this.originalPageX;
1968 | pageX = containment ? ((left - this.offset.click.left >= containment[0] || left - this.offset.click.left > containment[2]) ? left : ((left - this.offset.click.left >= containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left;
1969 | }
1970 |
1971 | }
1972 |
1973 | return {
1974 | top: (
1975 | pageY - // The absolute mouse position
1976 | this.offset.click.top - // Click offset (relative to the element)
1977 | this.offset.relative.top - // Only for relative positioned nodes: Relative offset from element to offset parent
1978 | this.offset.parent.top + // The offsetParent's offset without borders (offset + border)
1979 | ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))
1980 | ),
1981 | left: (
1982 | pageX - // The absolute mouse position
1983 | this.offset.click.left - // Click offset (relative to the element)
1984 | this.offset.relative.left - // Only for relative positioned nodes: Relative offset from element to offset parent
1985 | this.offset.parent.left + // The offsetParent's offset without borders (offset + border)
1986 | ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
1987 | )
1988 | };
1989 |
1990 | },
1991 |
1992 | _clear: function() {
1993 | this.helper.removeClass("ui-draggable-dragging");
1994 | if(this.helper[0] !== this.element[0] && !this.cancelHelperRemoval) {
1995 | this.helper.remove();
1996 | }
1997 | this.helper = null;
1998 | this.cancelHelperRemoval = false;
1999 | },
2000 |
2001 | // From now on bulk stuff - mainly helpers
2002 |
2003 | _trigger: function(type, event, ui) {
2004 | ui = ui || this._uiHash();
2005 | $.ui.plugin.call(this, type, [event, ui]);
2006 | //The absolute position has to be recalculated after plugins
2007 | if(type === "drag") {
2008 | this.positionAbs = this._convertPositionTo("absolute");
2009 | }
2010 | return $.Widget.prototype._trigger.call(this, type, event, ui);
2011 | },
2012 |
2013 | plugins: {},
2014 |
2015 | _uiHash: function() {
2016 | return {
2017 | helper: this.helper,
2018 | position: this.position,
2019 | originalPosition: this.originalPosition,
2020 | offset: this.positionAbs
2021 | };
2022 | }
2023 |
2024 | });
2025 |
2026 | $.ui.plugin.add("draggable", "connectToSortable", {
2027 | start: function(event, ui) {
2028 |
2029 | var inst = $(this).data("ui-draggable"), o = inst.options,
2030 | uiSortable = $.extend({}, ui, { item: inst.element });
2031 | inst.sortables = [];
2032 | $(o.connectToSortable).each(function() {
2033 | var sortable = $.data(this, "ui-sortable");
2034 | if (sortable && !sortable.options.disabled) {
2035 | inst.sortables.push({
2036 | instance: sortable,
2037 | shouldRevert: sortable.options.revert
2038 | });
2039 | sortable.refreshPositions(); // Call the sortable's refreshPositions at drag start to refresh the containerCache since the sortable container cache is used in drag and needs to be up to date (this will ensure it's initialised as well as being kept in step with any changes that might have happened on the page).
2040 | sortable._trigger("activate", event, uiSortable);
2041 | }
2042 | });
2043 |
2044 | },
2045 | stop: function(event, ui) {
2046 |
2047 | //If we are still over the sortable, we fake the stop event of the sortable, but also remove helper
2048 | var inst = $(this).data("ui-draggable"),
2049 | uiSortable = $.extend({}, ui, { item: inst.element });
2050 |
2051 | $.each(inst.sortables, function() {
2052 | if(this.instance.isOver) {
2053 |
2054 | this.instance.isOver = 0;
2055 |
2056 | inst.cancelHelperRemoval = true; //Don't remove the helper in the draggable instance
2057 | this.instance.cancelHelperRemoval = false; //Remove it in the sortable instance (so sortable plugins like revert still work)
2058 |
2059 | //The sortable revert is supported, and we have to set a temporary dropped variable on the draggable to support revert: "valid/invalid"
2060 | if(this.shouldRevert) {
2061 | this.instance.options.revert = true;
2062 | }
2063 |
2064 | //Trigger the stop of the sortable
2065 | this.instance._mouseStop(event);
2066 |
2067 | this.instance.options.helper = this.instance.options._helper;
2068 |
2069 | //If the helper has been the original item, restore properties in the sortable
2070 | if(inst.options.helper === "original") {
2071 | this.instance.currentItem.css({ top: "auto", left: "auto" });
2072 | }
2073 |
2074 | } else {
2075 | this.instance.cancelHelperRemoval = false; //Remove the helper in the sortable instance
2076 | this.instance._trigger("deactivate", event, uiSortable);
2077 | }
2078 |
2079 | });
2080 |
2081 | },
2082 | drag: function(event, ui) {
2083 |
2084 | var inst = $(this).data("ui-draggable"), that = this;
2085 |
2086 | $.each(inst.sortables, function() {
2087 |
2088 | var innermostIntersecting = false,
2089 | thisSortable = this;
2090 |
2091 | //Copy over some variables to allow calling the sortable's native _intersectsWith
2092 | this.instance.positionAbs = inst.positionAbs;
2093 | this.instance.helperProportions = inst.helperProportions;
2094 | this.instance.offset.click = inst.offset.click;
2095 |
2096 | if(this.instance._intersectsWith(this.instance.containerCache)) {
2097 | innermostIntersecting = true;
2098 | $.each(inst.sortables, function () {
2099 | this.instance.positionAbs = inst.positionAbs;
2100 | this.instance.helperProportions = inst.helperProportions;
2101 | this.instance.offset.click = inst.offset.click;
2102 | if (this !== thisSortable &&
2103 | this.instance._intersectsWith(this.instance.containerCache) &&
2104 | $.ui.contains(thisSortable.instance.element[0], this.instance.element[0])
2105 | ) {
2106 | innermostIntersecting = false;
2107 | }
2108 | return innermostIntersecting;
2109 | });
2110 | }
2111 |
2112 |
2113 | if(innermostIntersecting) {
2114 | //If it intersects, we use a little isOver variable and set it once, so our move-in stuff gets fired only once
2115 | if(!this.instance.isOver) {
2116 |
2117 | this.instance.isOver = 1;
2118 | //Now we fake the start of dragging for the sortable instance,
2119 | //by cloning the list group item, appending it to the sortable and using it as inst.currentItem
2120 | //We can then fire the start event of the sortable with our passed browser event, and our own helper (so it doesn't create a new one)
2121 | this.instance.currentItem = $(that).clone().removeAttr("id").appendTo(this.instance.element).data("ui-sortable-item", true);
2122 | this.instance.options._helper = this.instance.options.helper; //Store helper option to later restore it
2123 | this.instance.options.helper = function() { return ui.helper[0]; };
2124 |
2125 | event.target = this.instance.currentItem[0];
2126 | this.instance._mouseCapture(event, true);
2127 | this.instance._mouseStart(event, true, true);
2128 |
2129 | //Because the browser event is way off the new appended portlet, we modify a couple of variables to reflect the changes
2130 | this.instance.offset.click.top = inst.offset.click.top;
2131 | this.instance.offset.click.left = inst.offset.click.left;
2132 | this.instance.offset.parent.left -= inst.offset.parent.left - this.instance.offset.parent.left;
2133 | this.instance.offset.parent.top -= inst.offset.parent.top - this.instance.offset.parent.top;
2134 |
2135 | inst._trigger("toSortable", event);
2136 | inst.dropped = this.instance.element; //draggable revert needs that
2137 | //hack so receive/update callbacks work (mostly)
2138 | inst.currentItem = inst.element;
2139 | this.instance.fromOutside = inst;
2140 |
2141 | }
2142 |
2143 | //Provided we did all the previous steps, we can fire the drag event of the sortable on every draggable drag, when it intersects with the sortable
2144 | if(this.instance.currentItem) {
2145 | this.instance._mouseDrag(event);
2146 | }
2147 |
2148 | } else {
2149 |
2150 | //If it doesn't intersect with the sortable, and it intersected before,
2151 | //we fake the drag stop of the sortable, but make sure it doesn't remove the helper by using cancelHelperRemoval
2152 | if(this.instance.isOver) {
2153 |
2154 | this.instance.isOver = 0;
2155 | this.instance.cancelHelperRemoval = true;
2156 |
2157 | //Prevent reverting on this forced stop
2158 | this.instance.options.revert = false;
2159 |
2160 | // The out event needs to be triggered independently
2161 | this.instance._trigger("out", event, this.instance._uiHash(this.instance));
2162 |
2163 | this.instance._mouseStop(event, true);
2164 | this.instance.options.helper = this.instance.options._helper;
2165 |
2166 | //Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size
2167 | this.instance.currentItem.remove();
2168 | if(this.instance.placeholder) {
2169 | this.instance.placeholder.remove();
2170 | }
2171 |
2172 | inst._trigger("fromSortable", event);
2173 | inst.dropped = false; //draggable revert needs that
2174 | }
2175 |
2176 | }
2177 |
2178 | });
2179 |
2180 | }
2181 | });
2182 |
2183 | $.ui.plugin.add("draggable", "cursor", {
2184 | start: function() {
2185 | var t = $("body"), o = $(this).data("ui-draggable").options;
2186 | if (t.css("cursor")) {
2187 | o._cursor = t.css("cursor");
2188 | }
2189 | t.css("cursor", o.cursor);
2190 | },
2191 | stop: function() {
2192 | var o = $(this).data("ui-draggable").options;
2193 | if (o._cursor) {
2194 | $("body").css("cursor", o._cursor);
2195 | }
2196 | }
2197 | });
2198 |
2199 | $.ui.plugin.add("draggable", "opacity", {
2200 | start: function(event, ui) {
2201 | var t = $(ui.helper), o = $(this).data("ui-draggable").options;
2202 | if(t.css("opacity")) {
2203 | o._opacity = t.css("opacity");
2204 | }
2205 | t.css("opacity", o.opacity);
2206 | },
2207 | stop: function(event, ui) {
2208 | var o = $(this).data("ui-draggable").options;
2209 | if(o._opacity) {
2210 | $(ui.helper).css("opacity", o._opacity);
2211 | }
2212 | }
2213 | });
2214 |
2215 | $.ui.plugin.add("draggable", "scroll", {
2216 | start: function() {
2217 | var i = $(this).data("ui-draggable");
2218 | if(i.scrollParent[0] !== document && i.scrollParent[0].tagName !== "HTML") {
2219 | i.overflowOffset = i.scrollParent.offset();
2220 | }
2221 | },
2222 | drag: function( event ) {
2223 |
2224 | var i = $(this).data("ui-draggable"), o = i.options, scrolled = false;
2225 |
2226 | if(i.scrollParent[0] !== document && i.scrollParent[0].tagName !== "HTML") {
2227 |
2228 | if(!o.axis || o.axis !== "x") {
2229 | if((i.overflowOffset.top + i.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) {
2230 | i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop + o.scrollSpeed;
2231 | } else if(event.pageY - i.overflowOffset.top < o.scrollSensitivity) {
2232 | i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop - o.scrollSpeed;
2233 | }
2234 | }
2235 |
2236 | if(!o.axis || o.axis !== "y") {
2237 | if((i.overflowOffset.left + i.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) {
2238 | i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft + o.scrollSpeed;
2239 | } else if(event.pageX - i.overflowOffset.left < o.scrollSensitivity) {
2240 | i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft - o.scrollSpeed;
2241 | }
2242 | }
2243 |
2244 | } else {
2245 |
2246 | if(!o.axis || o.axis !== "x") {
2247 | if(event.pageY - $(document).scrollTop() < o.scrollSensitivity) {
2248 | scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
2249 | } else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) {
2250 | scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
2251 | }
2252 | }
2253 |
2254 | if(!o.axis || o.axis !== "y") {
2255 | if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity) {
2256 | scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
2257 | } else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) {
2258 | scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
2259 | }
2260 | }
2261 |
2262 | }
2263 |
2264 | if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) {
2265 | $.ui.ddmanager.prepareOffsets(i, event);
2266 | }
2267 |
2268 | }
2269 | });
2270 |
2271 | $.ui.plugin.add("draggable", "snap", {
2272 | start: function() {
2273 |
2274 | var i = $(this).data("ui-draggable"),
2275 | o = i.options;
2276 |
2277 | i.snapElements = [];
2278 |
2279 | $(o.snap.constructor !== String ? ( o.snap.items || ":data(ui-draggable)" ) : o.snap).each(function() {
2280 | var $t = $(this),
2281 | $o = $t.offset();
2282 | if(this !== i.element[0]) {
2283 | i.snapElements.push({
2284 | item: this,
2285 | width: $t.outerWidth(), height: $t.outerHeight(),
2286 | top: $o.top, left: $o.left
2287 | });
2288 | }
2289 | });
2290 |
2291 | },
2292 | drag: function(event, ui) {
2293 |
2294 | var ts, bs, ls, rs, l, r, t, b, i, first,
2295 | inst = $(this).data("ui-draggable"),
2296 | o = inst.options,
2297 | d = o.snapTolerance,
2298 | x1 = ui.offset.left, x2 = x1 + inst.helperProportions.width,
2299 | y1 = ui.offset.top, y2 = y1 + inst.helperProportions.height;
2300 |
2301 | for (i = inst.snapElements.length - 1; i >= 0; i--){
2302 |
2303 | l = inst.snapElements[i].left;
2304 | r = l + inst.snapElements[i].width;
2305 | t = inst.snapElements[i].top;
2306 | b = t + inst.snapElements[i].height;
2307 |
2308 | //Yes, I know, this is insane ;)
2309 | if(!((l-d < x1 && x1 < r+d && t-d < y1 && y1 < b+d) || (l-d < x1 && x1 < r+d && t-d < y2 && y2 < b+d) || (l-d < x2 && x2 < r+d && t-d < y1 && y1 < b+d) || (l-d < x2 && x2 < r+d && t-d < y2 && y2 < b+d))) {
2310 | if(inst.snapElements[i].snapping) {
2311 | (inst.options.snap.release && inst.options.snap.release.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item })));
2312 | }
2313 | inst.snapElements[i].snapping = false;
2314 | continue;
2315 | }
2316 |
2317 | if(o.snapMode !== "inner") {
2318 | ts = Math.abs(t - y2) <= d;
2319 | bs = Math.abs(b - y1) <= d;
2320 | ls = Math.abs(l - x2) <= d;
2321 | rs = Math.abs(r - x1) <= d;
2322 | if(ts) {
2323 | ui.position.top = inst._convertPositionTo("relative", { top: t - inst.helperProportions.height, left: 0 }).top - inst.margins.top;
2324 | }
2325 | if(bs) {
2326 | ui.position.top = inst._convertPositionTo("relative", { top: b, left: 0 }).top - inst.margins.top;
2327 | }
2328 | if(ls) {
2329 | ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l - inst.helperProportions.width }).left - inst.margins.left;
2330 | }
2331 | if(rs) {
2332 | ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r }).left - inst.margins.left;
2333 | }
2334 | }
2335 |
2336 | first = (ts || bs || ls || rs);
2337 |
2338 | if(o.snapMode !== "outer") {
2339 | ts = Math.abs(t - y1) <= d;
2340 | bs = Math.abs(b - y2) <= d;
2341 | ls = Math.abs(l - x1) <= d;
2342 | rs = Math.abs(r - x2) <= d;
2343 | if(ts) {
2344 | ui.position.top = inst._convertPositionTo("relative", { top: t, left: 0 }).top - inst.margins.top;
2345 | }
2346 | if(bs) {
2347 | ui.position.top = inst._convertPositionTo("relative", { top: b - inst.helperProportions.height, left: 0 }).top - inst.margins.top;
2348 | }
2349 | if(ls) {
2350 | ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l }).left - inst.margins.left;
2351 | }
2352 | if(rs) {
2353 | ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r - inst.helperProportions.width }).left - inst.margins.left;
2354 | }
2355 | }
2356 |
2357 | if(!inst.snapElements[i].snapping && (ts || bs || ls || rs || first)) {
2358 | (inst.options.snap.snap && inst.options.snap.snap.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item })));
2359 | }
2360 | inst.snapElements[i].snapping = (ts || bs || ls || rs || first);
2361 |
2362 | }
2363 |
2364 | }
2365 | });
2366 |
2367 | $.ui.plugin.add("draggable", "stack", {
2368 | start: function() {
2369 |
2370 | var min,
2371 | o = $(this).data("ui-draggable").options,
2372 | group = $.makeArray($(o.stack)).sort(function(a,b) {
2373 | return (parseInt($(a).css("zIndex"),10) || 0) - (parseInt($(b).css("zIndex"),10) || 0);
2374 | });
2375 |
2376 | if (!group.length) { return; }
2377 |
2378 | min = parseInt(group[0].style.zIndex, 10) || 0;
2379 | $(group).each(function(i) {
2380 | this.style.zIndex = min + i;
2381 | });
2382 |
2383 | this[0].style.zIndex = min + group.length;
2384 |
2385 | }
2386 | });
2387 |
2388 | $.ui.plugin.add("draggable", "zIndex", {
2389 | start: function(event, ui) {
2390 | var t = $(ui.helper), o = $(this).data("ui-draggable").options;
2391 | if(t.css("zIndex")) {
2392 | o._zIndex = t.css("zIndex");
2393 | }
2394 | t.css("zIndex", o.zIndex);
2395 | },
2396 | stop: function(event, ui) {
2397 | var o = $(this).data("ui-draggable").options;
2398 | if(o._zIndex) {
2399 | $(ui.helper).css("zIndex", o._zIndex);
2400 | }
2401 | }
2402 | });
2403 |
2404 | })(jQuery);
2405 | (function( $, undefined ) {
2406 |
2407 | function isOverAxis( x, reference, size ) {
2408 | return ( x > reference ) && ( x < ( reference + size ) );
2409 | }
2410 |
2411 | $.widget("ui.droppable", {
2412 | version: "1.10.0",
2413 | widgetEventPrefix: "drop",
2414 | options: {
2415 | accept: "*",
2416 | activeClass: false,
2417 | addClasses: true,
2418 | greedy: false,
2419 | hoverClass: false,
2420 | scope: "default",
2421 | tolerance: "intersect",
2422 |
2423 | // callbacks
2424 | activate: null,
2425 | deactivate: null,
2426 | drop: null,
2427 | out: null,
2428 | over: null
2429 | },
2430 | _create: function() {
2431 |
2432 | var o = this.options,
2433 | accept = o.accept;
2434 |
2435 | this.isover = false;
2436 | this.isout = true;
2437 |
2438 | this.accept = $.isFunction(accept) ? accept : function(d) {
2439 | return d.is(accept);
2440 | };
2441 |
2442 | //Store the droppable's proportions
2443 | this.proportions = { width: this.element[0].offsetWidth, height: this.element[0].offsetHeight };
2444 |
2445 | // Add the reference and positions to the manager
2446 | $.ui.ddmanager.droppables[o.scope] = $.ui.ddmanager.droppables[o.scope] || [];
2447 | $.ui.ddmanager.droppables[o.scope].push(this);
2448 |
2449 | (o.addClasses && this.element.addClass("ui-droppable"));
2450 |
2451 | },
2452 |
2453 | _destroy: function() {
2454 | var i = 0,
2455 | drop = $.ui.ddmanager.droppables[this.options.scope];
2456 |
2457 | for ( ; i < drop.length; i++ ) {
2458 | if ( drop[i] === this ) {
2459 | drop.splice(i, 1);
2460 | }
2461 | }
2462 |
2463 | this.element.removeClass("ui-droppable ui-droppable-disabled");
2464 | },
2465 |
2466 | _setOption: function(key, value) {
2467 |
2468 | if(key === "accept") {
2469 | this.accept = $.isFunction(value) ? value : function(d) {
2470 | return d.is(value);
2471 | };
2472 | }
2473 | $.Widget.prototype._setOption.apply(this, arguments);
2474 | },
2475 |
2476 | _activate: function(event) {
2477 | var draggable = $.ui.ddmanager.current;
2478 | if(this.options.activeClass) {
2479 | this.element.addClass(this.options.activeClass);
2480 | }
2481 | if(draggable){
2482 | this._trigger("activate", event, this.ui(draggable));
2483 | }
2484 | },
2485 |
2486 | _deactivate: function(event) {
2487 | var draggable = $.ui.ddmanager.current;
2488 | if(this.options.activeClass) {
2489 | this.element.removeClass(this.options.activeClass);
2490 | }
2491 | if(draggable){
2492 | this._trigger("deactivate", event, this.ui(draggable));
2493 | }
2494 | },
2495 |
2496 | _over: function(event) {
2497 |
2498 | var draggable = $.ui.ddmanager.current;
2499 |
2500 | // Bail if draggable and droppable are same element
2501 | if (!draggable || (draggable.currentItem || draggable.element)[0] === this.element[0]) {
2502 | return;
2503 | }
2504 |
2505 | if (this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
2506 | if(this.options.hoverClass) {
2507 | this.element.addClass(this.options.hoverClass);
2508 | }
2509 | this._trigger("over", event, this.ui(draggable));
2510 | }
2511 |
2512 | },
2513 |
2514 | _out: function(event) {
2515 |
2516 | var draggable = $.ui.ddmanager.current;
2517 |
2518 | // Bail if draggable and droppable are same element
2519 | if (!draggable || (draggable.currentItem || draggable.element)[0] === this.element[0]) {
2520 | return;
2521 | }
2522 |
2523 | if (this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
2524 | if(this.options.hoverClass) {
2525 | this.element.removeClass(this.options.hoverClass);
2526 | }
2527 | this._trigger("out", event, this.ui(draggable));
2528 | }
2529 |
2530 | },
2531 |
2532 | _drop: function(event,custom) {
2533 |
2534 | var draggable = custom || $.ui.ddmanager.current,
2535 | childrenIntersection = false;
2536 |
2537 | // Bail if draggable and droppable are same element
2538 | if (!draggable || (draggable.currentItem || draggable.element)[0] === this.element[0]) {
2539 | return false;
2540 | }
2541 |
2542 | this.element.find(":data(ui-droppable)").not(".ui-draggable-dragging").each(function() {
2543 | var inst = $.data(this, "ui-droppable");
2544 | if(
2545 | inst.options.greedy &&
2546 | !inst.options.disabled &&
2547 | inst.options.scope === draggable.options.scope &&
2548 | inst.accept.call(inst.element[0], (draggable.currentItem || draggable.element)) &&
2549 | $.ui.intersect(draggable, $.extend(inst, { offset: inst.element.offset() }), inst.options.tolerance)
2550 | ) { childrenIntersection = true; return false; }
2551 | });
2552 | if(childrenIntersection) {
2553 | return false;
2554 | }
2555 |
2556 | if(this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
2557 | if(this.options.activeClass) {
2558 | this.element.removeClass(this.options.activeClass);
2559 | }
2560 | if(this.options.hoverClass) {
2561 | this.element.removeClass(this.options.hoverClass);
2562 | }
2563 | this._trigger("drop", event, this.ui(draggable));
2564 | return this.element;
2565 | }
2566 |
2567 | return false;
2568 |
2569 | },
2570 |
2571 | ui: function(c) {
2572 | return {
2573 | draggable: (c.currentItem || c.element),
2574 | helper: c.helper,
2575 | position: c.position,
2576 | offset: c.positionAbs
2577 | };
2578 | }
2579 |
2580 | });
2581 |
2582 | $.ui.intersect = function(draggable, droppable, toleranceMode) {
2583 |
2584 | if (!droppable.offset) {
2585 | return false;
2586 | }
2587 |
2588 | var draggableLeft, draggableTop,
2589 | x1 = (draggable.positionAbs || draggable.position.absolute).left, x2 = x1 + draggable.helperProportions.width,
2590 | y1 = (draggable.positionAbs || draggable.position.absolute).top, y2 = y1 + draggable.helperProportions.height,
2591 | l = droppable.offset.left, r = l + droppable.proportions.width,
2592 | t = droppable.offset.top, b = t + droppable.proportions.height;
2593 |
2594 | switch (toleranceMode) {
2595 | case "fit":
2596 | return (l <= x1 && x2 <= r && t <= y1 && y2 <= b);
2597 | case "intersect":
2598 | return (l < x1 + (draggable.helperProportions.width / 2) && // Right Half
2599 | x2 - (draggable.helperProportions.width / 2) < r && // Left Half
2600 | t < y1 + (draggable.helperProportions.height / 2) && // Bottom Half
2601 | y2 - (draggable.helperProportions.height / 2) < b ); // Top Half
2602 | case "pointer":
2603 | draggableLeft = ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left);
2604 | draggableTop = ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top);
2605 | return isOverAxis( draggableTop, t, droppable.proportions.height ) && isOverAxis( draggableLeft, l, droppable.proportions.width );
2606 | case "touch":
2607 | return (
2608 | (y1 >= t && y1 <= b) || // Top edge touching
2609 | (y2 >= t && y2 <= b) || // Bottom edge touching
2610 | (y1 < t && y2 > b) // Surrounded vertically
2611 | ) && (
2612 | (x1 >= l && x1 <= r) || // Left edge touching
2613 | (x2 >= l && x2 <= r) || // Right edge touching
2614 | (x1 < l && x2 > r) // Surrounded horizontally
2615 | );
2616 | default:
2617 | return false;
2618 | }
2619 |
2620 | };
2621 |
2622 | /*
2623 | This manager tracks offsets of draggables and droppables
2624 | */
2625 | $.ui.ddmanager = {
2626 | current: null,
2627 | droppables: { "default": [] },
2628 | prepareOffsets: function(t, event) {
2629 |
2630 | var i, j,
2631 | m = $.ui.ddmanager.droppables[t.options.scope] || [],
2632 | type = event ? event.type : null, // workaround for #2317
2633 | list = (t.currentItem || t.element).find(":data(ui-droppable)").addBack();
2634 |
2635 | droppablesLoop: for (i = 0; i < m.length; i++) {
2636 |
2637 | //No disabled and non-accepted
2638 | if(m[i].options.disabled || (t && !m[i].accept.call(m[i].element[0],(t.currentItem || t.element)))) {
2639 | continue;
2640 | }
2641 |
2642 | // Filter out elements in the current dragged item
2643 | for (j=0; j < list.length; j++) {
2644 | if(list[j] === m[i].element[0]) {
2645 | m[i].proportions.height = 0;
2646 | continue droppablesLoop;
2647 | }
2648 | }
2649 |
2650 | m[i].visible = m[i].element.css("display") !== "none";
2651 | if(!m[i].visible) {
2652 | continue;
2653 | }
2654 |
2655 | //Activate the droppable if used directly from draggables
2656 | if(type === "mousedown") {
2657 | m[i]._activate.call(m[i], event);
2658 | }
2659 |
2660 | m[i].offset = m[i].element.offset();
2661 | m[i].proportions = { width: m[i].element[0].offsetWidth, height: m[i].element[0].offsetHeight };
2662 |
2663 | }
2664 |
2665 | },
2666 | drop: function(draggable, event) {
2667 |
2668 | var dropped = false;
2669 | $.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() {
2670 |
2671 | if(!this.options) {
2672 | return;
2673 | }
2674 | if (!this.options.disabled && this.visible && $.ui.intersect(draggable, this, this.options.tolerance)) {
2675 | dropped = this._drop.call(this, event) || dropped;
2676 | }
2677 |
2678 | if (!this.options.disabled && this.visible && this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
2679 | this.isout = true;
2680 | this.isover = false;
2681 | this._deactivate.call(this, event);
2682 | }
2683 |
2684 | });
2685 | return dropped;
2686 |
2687 | },
2688 | dragStart: function( draggable, event ) {
2689 | //Listen for scrolling so that if the dragging causes scrolling the position of the droppables can be recalculated (see #5003)
2690 | draggable.element.parentsUntil( "body" ).bind( "scroll.droppable", function() {
2691 | if( !draggable.options.refreshPositions ) {
2692 | $.ui.ddmanager.prepareOffsets( draggable, event );
2693 | }
2694 | });
2695 | },
2696 | drag: function(draggable, event) {
2697 |
2698 | //If you have a highly dynamic page, you might try this option. It renders positions every time you move the mouse.
2699 | if(draggable.options.refreshPositions) {
2700 | $.ui.ddmanager.prepareOffsets(draggable, event);
2701 | }
2702 |
2703 | //Run through all droppables and check their positions based on specific tolerance options
2704 | $.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() {
2705 |
2706 | if(this.options.disabled || this.greedyChild || !this.visible) {
2707 | return;
2708 | }
2709 |
2710 | var parentInstance, scope, parent,
2711 | intersects = $.ui.intersect(draggable, this, this.options.tolerance),
2712 | c = !intersects && this.isover ? "isout" : (intersects && !this.isover ? "isover" : null);
2713 | if(!c) {
2714 | return;
2715 | }
2716 |
2717 | if (this.options.greedy) {
2718 | // find droppable parents with same scope
2719 | scope = this.options.scope;
2720 | parent = this.element.parents(":data(ui-droppable)").filter(function () {
2721 | return $.data(this, "ui-droppable").options.scope === scope;
2722 | });
2723 |
2724 | if (parent.length) {
2725 | parentInstance = $.data(parent[0], "ui-droppable");
2726 | parentInstance.greedyChild = (c === "isover");
2727 | }
2728 | }
2729 |
2730 | // we just moved into a greedy child
2731 | if (parentInstance && c === "isover") {
2732 | parentInstance.isover = false;
2733 | parentInstance.isout = true;
2734 | parentInstance._out.call(parentInstance, event);
2735 | }
2736 |
2737 | this[c] = true;
2738 | this[c === "isout" ? "isover" : "isout"] = false;
2739 | this[c === "isover" ? "_over" : "_out"].call(this, event);
2740 |
2741 | // we just moved out of a greedy child
2742 | if (parentInstance && c === "isout") {
2743 | parentInstance.isout = false;
2744 | parentInstance.isover = true;
2745 | parentInstance._over.call(parentInstance, event);
2746 | }
2747 | });
2748 |
2749 | },
2750 | dragStop: function( draggable, event ) {
2751 | draggable.element.parentsUntil( "body" ).unbind( "scroll.droppable" );
2752 | //Call prepareOffsets one final time since IE does not fire return scroll events when overflow was caused by drag (see #5003)
2753 | if( !draggable.options.refreshPositions ) {
2754 | $.ui.ddmanager.prepareOffsets( draggable, event );
2755 | }
2756 | }
2757 | };
2758 |
2759 | })(jQuery);
2760 |
--------------------------------------------------------------------------------