start: function() {
const $this = this
+ this.isMobile = this.quiz.resize.isMobile()
this.activeScreen = this.quiz.screens.getActiveScreen()
this.list = this.activeScreen.find(".list")
this.listHtml = this.list.html()
createDraggable: function($this) {
Draggable.create($this.item, {
- type: "x,y",
+ type: $this.isMobile ? "y" : "x,y",
edgeResistance: 0.2,
inertia: false,
bounds: "#quiz",
$this.offsetRightItemDragged = $(this.target).offset().left + $(this.target).outerWidth()
let direction = this.getDirection()
- let zone = $this.getZoneOverlap($this.offsetLeftItemDragged,$this.offsetRightItemDragged)
+ //let zone = $this.getZoneOverlap($this.offsetLeftItemDragged,$this.offsetRightItemDragged)
+ let zone = $this.getZoneOverlap(this.target)
// fix bug scale !important from css
gsap.to(this.target, {
immediateRender: true
})
- //set rotation
- $this.rotateItem(this,direction)
+ //set rotation on desktop
+ if(!$this.isMobile) {
+ $this.rotateItem(this, direction)
+ }
// actions when enter in zone
$this.enterZone(zone)
},
onDragEnd: function() {
//
- let zone = $this.getZoneOverlap($this.offsetLeftItemDragged,$this.offsetRightItemDragged)
+ let zone = $this.getZoneOverlap(this.target)
let slot = false
if(zone) {
slot = $this.getSlotInformations(zone)
//
if(slot) {
- gsap.timeline().to(this.target, {
+ let rules = {
width: slot.w,
height: slot.h,
x: slot.x,
fontSize: "14px",
padding: "7px 8px",
borderRadius: "8px",
+ }
+ if($this.isMobile) {
+ rules = {
+ scale: 0.8,
+ duration: .3,
+ autoAlpha: 0,
+ }
+ }
+
+ gsap.timeline()
+ .to(this.target, {
+ ...rules,
onStart: function () {
target.addClass("isValidated")
+ gsap.set(target.next(), {opacity: 1})
},
onComplete: function () {
$this.slapping(zone,target)
$this.leaveZone()
//
- if(!$this.getZoneOverlap($this.offsetLeftItemDragged,$this.offsetRightItemDragged)) {
+ if(!$this.getZoneOverlap(this.target)) {
gsap.to(this.target, {
x: 0,
y: 0,
let text = target.text(),
id = "answer-"+target.data("id")
- $(zone).find(".slot:not(.active)").eq(0).addClass("active").append("<span>"+text+"</span>").attr('data-order',target.data("id"))
+ if(!this.isMobile) {
+ $(zone).find(".slot:not(.active)").eq(0).addClass("active").append("<span>"+text+"</span>").attr('data-order',target.data("id"))
+ }
+
$this.saveAnswer(zone,id)
target.remove()
},
})
},
- getZoneOverlap: function(offsetLeft, offsetRight) {
- let zone = false,
- zone1 = ".zone-1",
- zone2 = ".zone-2"
+ getZoneOverlap: function(target) {
+ let zone = false
+ var rectSelection = target.getBoundingClientRect();
+
+ // Iterate over all LI elements.
+ [].forEach.call(document.querySelectorAll(".zone-content"), function(div) {
+ var rect = div.getBoundingClientRect();
+
+ if(rect.bottom > rectSelection.top
+ && rect.right > rectSelection.left
+ && rect.top < rectSelection.bottom
+ && rect.left < rectSelection.right) {
+ div.classList.add("active")
+ }else {
+ div.classList.remove("active")
+ }
+ });
- if(offsetLeft - 19 < (this.zone1.offset().left + this.zone1.width())) {
- zone = zone1
- }else if(offsetRight + 19 > this.zone2.offset().left) {
- zone = zone2
+ if($(".zone-content.active").length > 0) {
+ zone = "."+$(".zone-content.active").parent().data("zone")
}
return zone
<div class="container-screen none question-draganddrop" data-screen="q-{{$position}}">
- <div class="screen-image zone-1 notDrag">
+ <div class="screen-image zone-1 notDrag" data-zone="zone-1">
<img src="{{$theme->draganddropArea1Image}}" />
<img class="mobile" src="{{$theme->draganddropArea1ImageMobile}}"/>
<div class="zone-content">
<button class="access move-card" aria-keyshortcuts="ARROWRIGHT"><span data-icon="arrow"></span></button>
</div>
</div>
- <div class="screen-image zone-2 notDrag">
+ <div class="screen-image zone-2 notDrag" data-zone="zone-2">
<img src="{{$theme->draganddropArea2Image}}" />
<img class="mobile" src="{{$theme->draganddropArea2ImageMobile}}"/>
<div class="zone-content">