Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ZeMKI
Mesort
Commits
17e6e2a1
Commit
17e6e2a1
authored
Aug 14, 2019
by
ZeMKI
Browse files
sorting javascript optimization
* quality of life optimization for sorting.vue
parent
1627287b
Changes
3
Hide whitespace changes
Inline
Side-by-side
public/js/app.js
View file @
17e6e2a1
...
...
@@ -2419,29 +2419,29 @@ $(document).keydown(function (event) {
onend: function onend(event) {
// self.drag = false;
var tokenContainer = document.querySelector('.token-container');
var
dropzone
Position = $(tokenContainer).position(),
elementPosition = $(event.target).position(),
x = elementPosition.left -
dropzone
Position.left,
y = elementPosition.top -
dropzone
Position.top;
console.log(elementPosition);
var position = self.get
t
oken
position
(self.get
g
lobal
c
oordinates(event.target));
var
id
d = event.target.id;
var
tokenContainer
Position = $(tokenContainer).position(),
element
New
Position = $(event.target).position(),
x = element
New
Position.left -
tokenContainer
Position.left,
y = element
New
Position.top -
tokenContainer
Position.top;
console.log(element
New
Position);
var position = self.get
T
oken
CircleAndCenterDistance
(self.get
ElementG
lobal
C
oordinates(event.target));
var
currentTokenI
d = event.target.id;
self.tokens[_.findIndex(self.tokens, function (o) {
if (o.id ==
id
d) return o;
if (o.id ==
currentTokenI
d) return o;
})].valutation.distance = position.distance;
self.tokens[_.findIndex(self.tokens, function (o) {
if (o.id ==
id
d) return o;
if (o.id ==
currentTokenI
d) return o;
})].position = {
x: x,
y: y
};
var
s
= x / window.innerWidth * 100;
var
i
= y / window.innerHeight * 100;
var
percentagePositionx
= x / window.innerWidth * 100;
var
percentagePositiony
= y / window.innerHeight * 100;
self.tokens[_.findIndex(self.tokens, function (o) {
if (o.id ==
id
d) return o;
if (o.id ==
currentTokenI
d) return o;
})].percentagePosition = {
x:
s
,
y:
i
x:
percentagePositionx
,
y:
percentagePositiony
};
}
});
...
...
@@ -2452,16 +2452,16 @@ $(document).keydown(function (event) {
x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx,
y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy;
target.style.webkitTransform = target.style.transform = 'translate(' + x + 'px, ' + y + 'px)';
var position = this.get
t
oken
position
(this.get
g
lobal
c
oordinates(event.target));
var
id
d = event.target.id;
var position = this.get
T
oken
CircleAndCenterDistance
(this.get
ElementG
lobal
C
oordinates(event.target));
var
currentTokenI
d = event.target.id;
this.tokens[_.findIndex(this.tokens, function (o) {
if (o.id ==
id
d) return o;
if (o.id ==
currentTokenI
d) return o;
})].valutation.circle = this.circles - position.circle;
this.$forceUpdate();
target.setAttribute('data-x', x);
target.setAttribute('data-y', y);
},
get
g
lobal
c
oordinates: function get
g
lobal
c
oordinates(token) {
get
ElementG
lobal
C
oordinates: function get
ElementG
lobal
C
oordinates(token) {
var childrenPos = token.getBoundingClientRect(),
relativePos = {};
relativePos.top = childrenPos.top - this.parentPos.top, relativePos.right = childrenPos.right - this.parentPos.right, relativePos.bottom = childrenPos.bottom - this.parentPos.bottom, relativePos.left = childrenPos.left - this.parentPos.left;
...
...
@@ -2469,7 +2469,7 @@ $(document).keydown(function (event) {
relativePos.y = childrenPos.y;
return relativePos;
},
get
t
oken
position
: function get
t
oken
position
(position) {
get
T
oken
CircleAndCenterDistance
: function get
T
oken
CircleAndCenterDistance
(position) {
var circle = this.circles;
var distance = 0; // MATH -- FIND IF A POINT BELONGS INSIDE A CIRCLE
// (x - center_x)^2 + (y - center_y)^2 < radius^2
...
...
@@ -2521,26 +2521,29 @@ $(document).keydown(function (event) {
document.querySelector(".round-sorting" + i.toString()).style.height = (i / this.circles * 80).toString() + "vh";
}
},
calculateCircleCenter: function calculateCircleCenter() {
this.center_x = this.offsetbounds_x + document.querySelector(".round-sorting" + this.circles).offsetWidth / 2;
this.center_y = this.offsetbounds_y + document.querySelector(".round-sorting" + this.circles).offsetHeight / 2;
},
getbounds: function getbounds() {
// get the distance from the circle to the window bounds
this.offsetbounds_y = window.pageYOffset - document.querySelector('#navbarBasicExample').offsetHeight + (window.pageYOffset - document.querySelector('#token-container').offsetHeight + 30) + document.querySelector('.round-sorting' + this.circles).getBoundingClientRect().top;
this.offsetbounds_x = window.pageXOffset + document.querySelector('.round-sorting' + this.circles).getBoundingClientRect().left;
this.parentPos = document.querySelector('.sorting-container').getBoundingClientRect();
this.bounds.top = this.getglobalcoordinates(document.querySelector('.round-sorting' + this.circles)).top;
this.bounds.left = this.getglobalcoordinates(document.querySelector('.round-sorting' + this.circles)).left;
this.bounds.right = this.getglobalcoordinates(document.querySelector('.round-sorting' + this.circles)).right;
this.bounds.bottom = this.getglobalcoordinates(document.querySelector('.round-sorting' + this.circles)).bottom;
this.center_x = this.offsetbounds_x + document.querySelector(".round-sorting" + this.circles).offsetWidth / 2;
this.center_y = this.offsetbounds_y + document.querySelector(".round-sorting" + this.circles).offsetHeight / 2;
this.bounds.top = this.getElementGlobalCoordinates(document.querySelector('.round-sorting' + this.circles)).top;
this.bounds.left = this.getElementGlobalCoordinates(document.querySelector('.round-sorting' + this.circles)).left;
this.bounds.right = this.getElementGlobalCoordinates(document.querySelector('.round-sorting' + this.circles)).right;
this.bounds.bottom = this.getElementGlobalCoordinates(document.querySelector('.round-sorting' + this.circles)).bottom;
this.calculateCircleCenter();
var self = this;
setTimeout(function () {
var d = document.getElementById('center');
d.style.position = "absolute";
d.style.backgroundColor = "red";
d.style.width = "
3
px";
d.style.height = "
3
px";
d.style.left = self.center_x + 'px';
d.style.top = self.center_y + 'px';
d.style.width = "
4
px";
d.style.height = "
4
px";
d.style.left = self.center_x
- 2
+ 'px';
d.style.top = self.center_y
- 2
+ 'px';
}, 100);
},
createtokens: function createtokens() {
...
...
@@ -15711,7 +15714,7 @@ var render = function() {
domProps: {
innerHTML: _vm._s(
"Position Y" +
t.position.
x
+
t.position.
y
+
" " +
t.position.y
)
public/mix-manifest.json
View file @
17e6e2a1
{
"/js/app.js"
:
"/js/app.js?id=
b43fc7edbcbb73a1c
c7
7
"
,
"/js/app.js"
:
"/js/app.js?id=
ae086bf49dbc84368
c7
1
"
,
"/css/app.css"
:
"/css/app.css?id=33e8c8db759d1aed6c23"
,
"/css/app_dompdf.css"
:
"/css/app_dompdf.css?id=225174786ee9d00fe897"
,
"/js/manifest.js"
:
"/js/manifest.js?id=844cdbfe9e6b6b56ae8f"
,
...
...
resources/js/components/sorting.vue
View file @
17e6e2a1
...
...
@@ -16,7 +16,7 @@
<div
v-if=
"t.drag"
class=
"tag is-dark "
style=
"display:block;"
v-html=
"'Position X'+t.position.x + ' ' + t.position.x"
></div>
<div
v-if=
"t.drag"
class=
"tag is-dark "
style=
"display:block;"
v-html=
"'Position Y'+t.position.
x
+ ' ' + t.position.y"
></div>
v-html=
"'Position Y'+t.position.
y
+ ' ' + t.position.y"
></div>
<div
v-if=
"t.drag && t.percentagePosition"
class=
"tag is-dark "
style=
"display:block;"
v-html=
"'P position X'+t.percentagePosition.x"
></div>
<div
v-if=
"t.drag && t.percentagePosition"
class=
"tag is-dark "
style=
"display:block;"
...
...
@@ -111,31 +111,31 @@
// self.drag = false;
var
tokenContainer
=
document
.
querySelector
(
'
.token-container
'
);
var
dropzone
Position
=
$
(
tokenContainer
).
position
(),
elementPosition
=
$
(
event
.
target
).
position
(),
x
=
elementPosition
.
left
-
dropzone
Position
.
left
,
y
=
elementPosition
.
top
-
dropzone
Position
.
top
;
console
.
log
(
elementPosition
);
var
tokenContainer
Position
=
$
(
tokenContainer
).
position
(),
element
New
Position
=
$
(
event
.
target
).
position
(),
x
=
element
New
Position
.
left
-
tokenContainer
Position
.
left
,
y
=
element
New
Position
.
top
-
tokenContainer
Position
.
top
;
console
.
log
(
element
New
Position
);
let
position
=
self
.
get
t
oken
position
(
self
.
get
g
lobal
c
oordinates
(
event
.
target
));
let
id
d
=
event
.
target
.
id
;
let
position
=
self
.
get
T
oken
CircleAndCenterDistance
(
self
.
get
ElementG
lobal
C
oordinates
(
event
.
target
));
let
currentTokenI
d
=
event
.
target
.
id
;
self
.
tokens
[
_
.
findIndex
(
self
.
tokens
,
function
(
o
)
{
if
(
o
.
id
==
id
d
)
return
o
;
if
(
o
.
id
==
currentTokenI
d
)
return
o
;
})].
valutation
.
distance
=
position
.
distance
;
self
.
tokens
[
_
.
findIndex
(
self
.
tokens
,
function
(
o
)
{
if
(
o
.
id
==
id
d
)
return
o
;
if
(
o
.
id
==
currentTokenI
d
)
return
o
;
})].
position
=
{
x
:
x
,
y
:
y
};
let
s
=
(
x
/
window
.
innerWidth
)
*
100
;
let
i
=
(
y
/
window
.
innerHeight
)
*
100
;
let
percentagePositionx
=
(
x
/
window
.
innerWidth
)
*
100
;
let
percentagePositiony
=
(
y
/
window
.
innerHeight
)
*
100
;
self
.
tokens
[
_
.
findIndex
(
self
.
tokens
,
function
(
o
)
{
if
(
o
.
id
==
id
d
)
return
o
;
})].
percentagePosition
=
{
x
:
s
,
y
:
i
};
if
(
o
.
id
==
currentTokenI
d
)
return
o
;
})].
percentagePosition
=
{
x
:
percentagePositionx
,
y
:
percentagePositiony
};
}
...
...
@@ -152,18 +152,18 @@
'
translate(
'
+
x
+
'
px,
'
+
y
+
'
px)
'
;
let
position
=
this
.
get
t
oken
position
(
this
.
get
g
lobal
c
oordinates
(
event
.
target
));
let
id
d
=
event
.
target
.
id
;
let
position
=
this
.
get
T
oken
CircleAndCenterDistance
(
this
.
get
ElementG
lobal
C
oordinates
(
event
.
target
));
let
currentTokenI
d
=
event
.
target
.
id
;
this
.
tokens
[
_
.
findIndex
(
this
.
tokens
,
function
(
o
)
{
if
(
o
.
id
==
id
d
)
return
o
;
if
(
o
.
id
==
currentTokenI
d
)
return
o
;
})].
valutation
.
circle
=
this
.
circles
-
position
.
circle
;
this
.
$forceUpdate
();
target
.
setAttribute
(
'
data-x
'
,
x
);
target
.
setAttribute
(
'
data-y
'
,
y
);
},
get
g
lobal
c
oordinates
:
function
(
token
)
{
get
ElementG
lobal
C
oordinates
:
function
(
token
)
{
let
childrenPos
=
token
.
getBoundingClientRect
(),
relativePos
=
{};
...
...
@@ -176,7 +176,7 @@
return
relativePos
;
},
get
t
oken
position
:
function
(
position
)
{
get
T
oken
CircleAndCenterDistance
:
function
(
position
)
{
let
circle
=
this
.
circles
;
let
distance
=
0
;
...
...
@@ -185,7 +185,10 @@
// (x - center_x)^2 + (y - center_y)^2
<
radius
^
2
for
(
var
i
=
0
;
i
<
this
.
circles
;
i
++
)
{
if
((
Math
.
pow
(((
position
.
left
+
25
)
-
this
.
center_x
),
2
)
+
Math
.
pow
(((
position
.
top
+
25
)
-
this
.
center_y
),
2
))
<
Math
.
pow
((
this
.
center_x
-
this
.
offsetbounds_x
)
*
((
this
.
circles
-
i
)
/
this
.
circles
),
2
))
{
if
((
Math
.
pow
(((
position
.
left
+
25
)
-
this
.
center_x
),
2
)
+
Math
.
pow
(((
position
.
top
+
25
)
-
this
.
center_y
),
2
))
<
Math
.
pow
((
this
.
center_x
-
this
.
offsetbounds_x
)
*
((
this
.
circles
-
i
)
/
this
.
circles
),
2
))
{
distance
=
Math
.
hypot
((
position
.
top
+
25
)
-
(
this
.
center_y
),
(
position
.
left
+
25
)
-
(
this
.
center_x
));
circle
=
i
;
}
...
...
@@ -232,37 +235,38 @@
}
},
getbounds
:
function
()
{
calculateCircleCenter
:
function
()
{
this
.
center_x
=
this
.
offsetbounds_x
+
(
document
.
querySelector
(
"
.round-sorting
"
+
this
.
circles
).
offsetWidth
/
2
);
this
.
center_y
=
this
.
offsetbounds_y
+
(
document
.
querySelector
(
"
.round-sorting
"
+
this
.
circles
).
offsetHeight
/
2
);
},
getbounds
:
function
()
{
// get the distance from the circle to the window bounds
this
.
offsetbounds_y
=
(
window
.
pageYOffset
-
document
.
querySelector
(
'
#navbarBasicExample
'
).
offsetHeight
)
+
(
window
.
pageYOffset
-
document
.
querySelector
(
'
#token-container
'
).
offsetHeight
+
30
)
+
document
.
querySelector
(
'
.round-sorting
'
+
this
.
circles
).
getBoundingClientRect
().
top
;
this
.
offsetbounds_x
=
window
.
pageXOffset
+
document
.
querySelector
(
'
.round-sorting
'
+
this
.
circles
).
getBoundingClientRect
().
left
;
this
.
parentPos
=
document
.
querySelector
(
'
.sorting-container
'
).
getBoundingClientRect
();
this
.
bounds
.
top
=
this
.
get
g
lobal
c
oordinates
(
document
.
querySelector
(
'
.round-sorting
'
+
this
.
circles
)).
top
;
this
.
bounds
.
left
=
this
.
get
g
lobal
c
oordinates
(
document
.
querySelector
(
'
.round-sorting
'
+
this
.
circles
)).
left
;
this
.
bounds
.
right
=
this
.
get
g
lobal
c
oordinates
(
document
.
querySelector
(
'
.round-sorting
'
+
this
.
circles
)).
right
;
this
.
bounds
.
bottom
=
this
.
get
g
lobal
c
oordinates
(
document
.
querySelector
(
'
.round-sorting
'
+
this
.
circles
)).
bottom
;
this
.
bounds
.
top
=
this
.
get
ElementG
lobal
C
oordinates
(
document
.
querySelector
(
'
.round-sorting
'
+
this
.
circles
)).
top
;
this
.
bounds
.
left
=
this
.
get
ElementG
lobal
C
oordinates
(
document
.
querySelector
(
'
.round-sorting
'
+
this
.
circles
)).
left
;
this
.
bounds
.
right
=
this
.
get
ElementG
lobal
C
oordinates
(
document
.
querySelector
(
'
.round-sorting
'
+
this
.
circles
)).
right
;
this
.
bounds
.
bottom
=
this
.
get
ElementG
lobal
C
oordinates
(
document
.
querySelector
(
'
.round-sorting
'
+
this
.
circles
)).
bottom
;
this
.
center_x
=
this
.
offsetbounds_x
+
(
document
.
querySelector
(
"
.round-sorting
"
+
this
.
circles
).
offsetWidth
/
2
);
this
.
center_y
=
this
.
offsetbounds_y
+
(
document
.
querySelector
(
"
.round-sorting
"
+
this
.
circles
).
offsetHeight
/
2
);
this
.
calculateCircleCenter
();
let
self
=
this
;
setTimeout
(
function
(){
setTimeout
(
function
()
{
var
d
=
document
.
getElementById
(
'
center
'
);
d
.
style
.
position
=
"
absolute
"
;
d
.
style
.
backgroundColor
=
"
red
"
;
d
.
style
.
width
=
"
3
px
"
;
d
.
style
.
height
=
"
3
px
"
;
d
.
style
.
width
=
"
4
px
"
;
d
.
style
.
height
=
"
4
px
"
;
d
.
style
.
left
=
self
.
center_x
+
'
px
'
;
d
.
style
.
top
=
self
.
center_y
+
'
px
'
;
d
.
style
.
left
=
(
self
.
center_x
-
2
)
+
'
px
'
;
d
.
style
.
top
=
(
self
.
center_y
-
2
)
+
'
px
'
;
},
100
);
},
createtokens
:
function
()
{
this
.
tokens
=
this
.
availabletokens
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment