Skip to content

Commit

Permalink
#93 preventing scrolls if element is already in view. It still has wi…
Browse files Browse the repository at this point in the history
…erd scroll behavior.
  • Loading branch information
telion2 committed Mar 15, 2018
1 parent 8815e46 commit 1ce841c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
32 changes: 22 additions & 10 deletions views/components/analysis/entitiesview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
searched = false;
}
if (query !== '') {
let wordids = []
let wordids = [];
for (let k = 0; k < sortedtokens[i].length; k++) {
wordids.push(sortedtokens[i][k].wordID);
}
Expand Down Expand Up @@ -305,6 +305,17 @@
saveResults: function () {
//console.log('TODO: Trying to save but not implemented.');
},
isElementInViewport: function (el) {
console.log('element here is: ' + el);
let rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
);
},
},
computed: {
numberOfPersons: function () {
Expand Down Expand Up @@ -392,10 +403,11 @@
if (hoverdata.semanticClass === 'PERSON') {
if (typeof this.$refs["personresults"] !== 'undefined' && this.$refs["personresults"].length > 0) {
for (let i = 0; i < this.$refs["personresults"].length; i++) {
let refElement = this.$refs.personresults[i]
let refElement = this.$refs.personresults[i];
if (refElement.researchdata.sourcequery.wordids.indexOf(newwordid) > -1) {
if (hoverdata.hoverstarted == "text")
if (hoverdata.hoverstarted === "text" && !this.isElementInViewport(refElement.$el)) {
refElement.$el.scrollIntoView();
}
bb = refElement.$el.getBoundingClientRect();
wordtomarkonhoverDUMMY = refElement.researchdata.sourcequery.wordids
Expand All @@ -407,9 +419,9 @@
} else if (hoverdata.semanticClass === 'LOCATION') {
if (typeof this.$refs["locationresults"] !== 'undefined' && this.$refs["locationresults"].length > 0) {
for (let i = 0; i < this.$refs["locationresults"].length; i++) {
let refElement = this.$refs.locationresults[i]
let refElement = this.$refs.locationresults[i];
if (refElement.researchdata.sourcequery.wordids.indexOf(newwordid) > -1) {
if (hoverdata.hoverstarted === "text")
if (hoverdata.hoverstarted === "text" && !this.isElementInViewport(refElement.$el))
refElement.$el.scrollIntoView();
bb = refElement.$el.getBoundingClientRect();
Expand All @@ -422,9 +434,9 @@
} else if (hoverdata.semanticClass === "ORGANIZATION") {
if (typeof this.$refs["organisazionresults"] !== 'undefined' && this.$refs["organisazionresults"].length > 0) {
for (let i = 0; i < this.$refs["organisazionresults"].length; i++) {
let refElement = this.$refs.organisazionresults[i]
let refElement = this.$refs.organisazionresults[i];
if (refElement.researchdata.sourcequery.wordids.indexOf(newwordid) > -1) {
if (hoverdata.hoverstarted === "text")
if (hoverdata.hoverstarted === "text" && !this.isElementInViewport(refElement.$el))
refElement.$el.scrollIntoView();
bb = refElement.$el.getBoundingClientRect();
Expand All @@ -437,9 +449,9 @@
} else if (hoverdata.semanticClass === "MISC") {
if (typeof this.$refs["miscresults"] !== 'undefined' && this.$refs["miscresults"].length > 0) {
for (let i = 0; i < this.$refs["miscresults"].length; i++) {
let refElement = this.$refs.miscresults[i]
let refElement = this.$refs.miscresults[i];
if (refElement.researchdata.sourcequery.wordids.indexOf(newwordid) > -1) {
if (hoverdata.hoverstarted === "text")
if (hoverdata.hoverstarted === "text" && !this.isElementInViewport(refElement.$el))
refElement.$el.scrollIntoView();
bb = refElement.$el.getBoundingClientRect();
Expand All @@ -450,7 +462,7 @@
bb = this.$refs["miscresultsparent"].getBoundingClientRect();
}
}
let data = {hoverended: "research", offsetend: bb, wordtomarkonhover: wordtomarkonhoverDUMMY}
let data = {hoverended: "research", offsetend: bb, wordtomarkonhover: wordtomarkonhoverDUMMY};
this.$emit('endhover', data);
}, deep: true
},
Expand Down
3 changes: 2 additions & 1 deletion views/components/analysis/researchresult.vue
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@
editResearch: function () {
console.log('clicked edit Research');
this.$emit('editresearch', this.researchdata);
}
},
},
components: {
googlemap
Expand Down
10 changes: 9 additions & 1 deletion views/components/analysis/text.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
return []
}
},
allowtexttoscroll: {type: Boolean, default: false}
},
data: function () {
return {
Expand All @@ -35,6 +34,15 @@
}
},
computed: {
allowtexttoscroll: function () {
let rect = this.$el.getBoundingClientRect();
return !(
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
);
},
tobejumped: function () {
if (this.index === this.selectedindexes.start) {
return this.index;
Expand Down
9 changes: 1 addition & 8 deletions views/components/analysis/textfeatureviewport.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
v-bind:selectedchain="selectedchain"
v-bind:hoverdata="hoverdata"
v-bind:wordtomarkonhoverdata="wordtomarkonhoverdata"
v-bind:allowtexttoscroll="allowTextToScroll"
v-bind:classestomark="classestomark"
v-bind:contentcontrol="contentcontrol"
v-on:togglesemanticlass="togglesemanticlass($event)"
Expand Down Expand Up @@ -107,13 +106,7 @@
}
},
computed: {
allowTextToScroll:function () {
if(this.$refs["textviewport"] !== undefined) {
return this.$refs["textviewport"].scrollHeight > this.$refs["textviewport"].clientHeight;
} else{
return false;
}
}
},
methods: {
updateclassestomark:function (newClassesToMark) {
Expand Down

0 comments on commit 1ce841c

Please sign in to comment.