/
var
/
www
/
html
/
lgpd
/
lib
/
amd
/
build
/
Upload File
HOME
function _typeof(a){if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("core/sortable_list",["jquery","core/log","core/autoscroll","core/str","core/modal_factory","core/modal_events","core/notification"],function(b,a,c,d,e,f,g){var h={targetListSelector:null,moveHandlerSelector:"[data-drag-type=move]",isHorizontal:!1,autoScroll:!0},j={keyboardDragClass:"dragdrop-keyboard-drag",isDraggedClass:"sortable-list-is-dragged",currentPositionClass:"sortable-list-current-position",sourceListClass:"sortable-list-source",targetListClass:"sortable-list-target",overElementClass:"sortable-list-over-element"},k=function(a){return{setup:function setup(b,c,d){if(c.includes("notPassive")){this.addEventListener(a,d,{passive:!1});return!0}else{return!1}}}};if(function eventListenerOptionsSupported(){var a=!1,b;try{b=Object.defineProperty({},"passive",{get:function get(){a=!0}});document.addEventListener("testpassiveeventoptions",b,b);document.removeEventListener("testpassiveeventoptions",b,b)}catch(b){a=!1}return a}){b.event.special.touchstart=k("touchstart");b.event.special.touchmove=k("touchmove");b.event.special.touchend=k("touchend")}var l=function(a,c){this.info=null;this.proxy=null;this.proxyDelta=null;this.dragCounter=0;this.lastEvent=null;this.config=b.extend({},h,c||{});this.config.listSelector=a;if(!this.config.targetListSelector){this.config.targetListSelector=a}if("object"===_typeof(this.config.listSelector)){b(this.config.listSelector).on("mousedown touchstart.notPassive",b.proxy(this.dragStartHandler,this))}else{b("body").on("mousedown touchstart.notPassive",this.config.listSelector,b.proxy(this.dragStartHandler,this))}if(null!==this.config.moveHandlerSelector){b("body").on("click keypress",this.config.moveHandlerSelector,b.proxy(this.clickHandler,this))}};l.EVENTS={DRAGSTART:"sortablelist-dragstart",DRAG:"sortablelist-drag",DROP:"sortablelist-drop",DRAGEND:"sortablelist-dragend"};l.prototype.resetDraggedClasses=function(){var a=[j.isDraggedClass,j.currentPositionClass,j.overElementClass,j.targetListClass];for(var c in a){b("."+a[c]).removeClass(a[c])}if(this.proxy){this.proxy.remove();this.proxy=b()}};l.prototype.calculatePositionOnPage=function(a){if(a.originalEvent&&a.originalEvent.touches&&a.originalEvent.touches[0]!==void 0){var c=a.originalEvent.touches[0];a.pageX=c.pageX;a.pageY=c.pageY}if(a.pageX===void 0){a.pageX=this.lastEvent.pageX;a.pageY=this.lastEvent.pageY}else{this.lastEvent=a}if(a.clientX===void 0){a.clientX=Math.round(a.pageX-b(window).scrollLeft());a.clientY=Math.round(a.pageY-b(window).scrollTop())}};l.prototype.dragStartHandler=function(a){if(null!==this.info){if("click"===this.info.type||"touchend"===this.info.type){return}this.moveElement(this.info.sourceList,this.info.sourceNextElement);this.finishDragging()}if("mousedown"===a.type&&1!==a.which){return}this.calculatePositionOnPage(a);var d=b(a.target).closest(b(a.currentTarget).children());if(!d.length){return}if(null!==this.config.moveHandlerSelector){if(!b(a.target).closest(this.config.moveHandlerSelector,d).length){return}}a.stopPropagation();a.preventDefault();this.dragCounter++;this.info={element:d,sourceNextElement:d.next(),sourceList:d.parent(),targetNextElement:d.next(),targetList:d.parent(),type:a.type,dropped:!1,startX:a.pageX,startY:a.pageY,startTime:new Date().getTime()};b(this.config.targetListSelector).addClass(j.targetListClass);var e=d.offset();d.addClass(j.currentPositionClass);this.proxyDelta={x:e.left-a.pageX,y:e.top-a.pageY};this.proxy=b();var f=this.dragCounter;setTimeout(b.proxy(function(){if(null===this.info||"click"===this.info.type||"keypress"===this.info.type||this.dragCounter!==f){return}this.createProxy()},this),500);b(window).on("mousemove touchmove.notPassive mouseup touchend.notPassive",b.proxy(this.dragHandler,this));b(window).on("keypress",b.proxy(this.dragcancelHandler,this));if(this.config.autoScroll){c.start(function(){b(window).trigger("mousemove")})}this.executeCallback(l.EVENTS.DRAGSTART)};l.prototype.createProxy=function(){this.proxy=this.info.element.clone();this.info.sourceList.append(this.proxy);this.proxy.removeAttr("id").removeClass(j.currentPositionClass).addClass(j.isDraggedClass).css({position:"fixed"});this.proxy.offset({top:this.proxyDelta.y+this.lastEvent.pageY,left:this.proxyDelta.x+this.lastEvent.pageX})};l.prototype.clickHandler=function(a){if("keypress"===a.type&&13!==a.originalEvent.keyCode&&32!==a.originalEvent.keyCode){return}if(null!==this.info){return}var c=b(a.target).closest(this.config.moveHandlerSelector),d=c.closest(this.config.listSelector),e=c.closest(d.children());if(!e.length){return}a.preventDefault();a.stopPropagation();this.dragCounter++;this.info={element:e,sourceNextElement:e.next(),sourceList:d,targetNextElement:e.next(),targetList:d,dropped:!1,type:a.type,startTime:new Date().getTime()};this.executeCallback(l.EVENTS.DRAGSTART);this.displayMoveDialogue(c)};l.prototype.getPositionInNode=function(a,b,c){if(!c.length){return null}var d=c[0],e=d.getBoundingClientRect(),f=b-(e.top+window.scrollY),g=a-(e.left+window.scrollX);if(g>=-0&&g<=e.width+0&&f>=-0&&f<=e.height+0){return{x:g,y:f,xRatio:e.width?g/e.width:0,yRatio:e.height?f/e.height:0}}return null};l.prototype.isListHorizontal=function(a){var b=this.config.isHorizontal;if(!0===b||!1===b){return b}return b(a)};l.prototype.dragHandler=function(a){a.preventDefault();a.stopPropagation();this.calculatePositionOnPage(a);this.proxy.offset({top:-1e3,left:-1e3});var c=b(document.elementFromPoint(a.clientX,a.clientY)),d=this.info.element[0],e=function(){return this!==d},f=c.closest("."+j.targetListClass+" > :not(."+j.isDraggedClass+")").filter(e),g=c.closest("."+j.targetListClass),h=this.proxy,i=function(){return!h||!h.length||this!==h[0]};b("."+j.overElementClass).removeClass(j.overElementClass);f.addClass(j.overElementClass);this.proxy.offset({top:this.proxyDelta.y+a.pageY,left:this.proxyDelta.x+a.pageX});if(g.length&&!g.children().filter(i).length){this.moveElement(g,b())}else if(1===f.length&&!this.info.element.find(f[0]).length){var k=this.getPositionInNode(a.pageX,a.pageY,f);if(k){var m=f.parent(),n=this.isListHorizontal(m)?k.xRatio:k.yRatio,o=f.find("."+j.targetListClass),p=!o.children().filter(i).filter(e).length;if(o.length&&p&&.2<n&&.8>n){this.moveElement(o,b())}else if(.5<n){this.moveElement(m,f.next().filter(i))}else{this.moveElement(m,f)}}}if("mouseup"===a.type||"touchend"===a.type){this.info.endX=a.pageX;this.info.endY=a.pageY;this.info.endTime=new Date().getTime();this.info.dropped=!0;this.info.positionChanged=this.hasPositionChanged(this.info);var q=this.info;this.executeCallback(l.EVENTS.DROP);this.finishDragging();if("touchend"===a.type&&null!==this.config.moveHandlerSelector&&500>q.endTime-q.startTime&&!q.positionChanged){this.clickHandler(a)}}};l.prototype.hasPositionChanged=function(a){return a.sourceList[0]!==a.targetList[0]||a.sourceNextElement.length!==a.targetNextElement.length||a.sourceNextElement.length&&a.sourceNextElement[0]!==a.targetNextElement[0]};l.prototype.moveElement=function(a,b){var c=this.info.element;if(b.length&&b[0]===c[0]){return}if(a[0]===this.info.targetList[0]&&b.length===this.info.targetNextElement.length&&b[0]===this.info.targetNextElement[0]){return}if(b.length){a[0].insertBefore(c[0],b[0])}else if(this.proxy&&this.proxy.parent().length&&this.proxy.parent()[0]===a[0]){a[0].insertBefore(c[0],this.proxy[0])}else{a[0].appendChild(c[0])}this.info.targetList=a;this.info.targetNextElement=b;this.executeCallback(l.EVENTS.DRAG)};l.prototype.finishDragging=function(){this.resetDraggedClasses();if(this.config.autoScroll){c.stop()}b(window).off("mousemove touchmove.notPassive mouseup touchend.notPassive",b.proxy(this.dragHandler,this));b(window).off("keypress",b.proxy(this.dragcancelHandler,this));this.executeCallback(l.EVENTS.DRAGEND);this.info=null};l.prototype.executeCallback=function(a){this.info.element.trigger(a,this.info)};l.prototype.dragcancelHandler=function(a){if("keypress"!==a.type||27!==a.originalEvent.keyCode){return}this.moveElement(this.info.sourceList,this.info.sourceNextElement);this.finishDragging()};l.prototype.getElementName=function(a){return b.Deferred().resolve(a.text())};l.prototype.getDestinationName=function(a,b){if(!b.length){return d.get_string("movecontenttothetop","moodle")}else{return this.getElementName(b).then(function(a){return d.get_string("movecontentafter","moodle",a)})}};l.prototype.getMoveDialogueTitle=function(a,c){if(c.attr("title")){return b.Deferred().resolve(c.attr("title"))}return this.getElementName(a).then(function(a){return d.get_string("movecontent","moodle",a)})};l.prototype.getDestinationsList=function(){var a=[],c=b(this.config.targetListSelector),d=b("<ul/>").addClass(j.keyboardDragClass),e=b.when().then(function(){return d}),f=b.proxy(function(c,f,g){if(f.is(this.info.element)||g.is(this.info.element)){return}if(b.contains(this.info.element[0],c[0])){return}e=e.then(b.proxy(function(){return this.getDestinationName(c,g)},this)).then(function(e){var g=b("<li/>").appendTo(d),h=b("<a href=\"#\"/>").attr("data-core_sortable_list-quickmove",1).appendTo(g);h.data("parent-element",c).data("before-element",f).text(e);return d})},this),g=function(){if(-1!==b.inArray(this,a)){return}a.push(this);var d=b(this),e=d.children();e.each(function(){var a=b(this);f(d,a,a.prev());a.find(c).each(g)});f(d,b(),e.last())};c.each(g);return e};l.prototype.displayMoveDialogue=function(a){e.create({type:e.types.CANCEL,title:this.getMoveDialogueTitle(this.info.element,a),body:this.getDestinationsList()}).then(b.proxy(function(c){var d=b.proxy(function(d){d.preventDefault();d.stopPropagation();this.moveElement(b(d.currentTarget).data("parent-element"),b(d.currentTarget).data("before-element"));this.info.endTime=new Date().getTime();this.info.positionChanged=this.hasPositionChanged(this.info);this.info.dropped=!0;a.focus();this.executeCallback(l.EVENTS.DROP);c.hide()},this);c.getRoot().on("click","[data-core_sortable_list-quickmove]",d);c.getRoot().on(f.hidden,b.proxy(function(){c.getRoot().off("click","[data-core_sortable_list-quickmove]",d);c.destroy();this.finishDragging()},this));c.setLarge();c.show();return c},this)).catch(g.exception)};return l}); //# sourceMappingURL=sortable_list.min.js.map