Added EventListener to vc-Element instead to document
Change-Id: I2321f1b2180067b83a9e0579c13010586192de1b
diff --git a/dev/demo/vcdemo.js b/dev/demo/vcdemo.js
index b9a7b1a..e0b9f16 100644
--- a/dev/demo/vcdemo.js
+++ b/dev/demo/vcdemo.js
@@ -129,9 +129,6 @@
['author', 'text']
]).fromJson(json);
- document.addEventListener('vcChange', function (e) {
- KorAP.vc.checkStatActive(e.detail);
- }, false);
document.getElementById('vc-view').appendChild(KorAP.vc.element());
diff --git a/dev/js/spec/statSpec.js b/dev/js/spec/statSpec.js
index 25e55a2..93001bd 100644
--- a/dev/js/spec/statSpec.js
+++ b/dev/js/spec/statSpec.js
@@ -356,11 +356,6 @@
*/
describe ('KorAP.CorpusStat.Disable', function(){
- document.addEventListener('vcChange', function (e) {
- if(KorAP.vc){
- KorAP.vc.checkStatActive(e.detail);
- }
- }, false);
/**
* If the user defines a new vc, the statistic should be disabled,
diff --git a/dev/js/src/init.js b/dev/js/src/init.js
index d94b1b5..cc1d53b 100644
--- a/dev/js/src/init.js
+++ b/dev/js/src/init.js
@@ -91,10 +91,6 @@
var vc = KorAP.vc;
- document.addEventListener('vcChange', function (e) {
- vc.checkStatActive(e.detail);
- }, false);
-
// Add vc name object
if (input) {
input.style.display = 'none';
diff --git a/dev/js/src/vc.js b/dev/js/src/vc.js
index 4bc5e13..fd67863 100644
--- a/dev/js/src/vc.js
+++ b/dev/js/src/vc.js
@@ -329,6 +329,11 @@
// Add panel to display corpus statistic, ...
this.addVcInfPanel();
+ //Adds EventListener for corpus changes
+ this._element.addEventListener('vcChange', function (e) {
+ that.checkStatActive(e.detail);
+ }, false);
+
return this._element;
},
@@ -367,9 +372,10 @@
*/
update : function() {
this._root.update();
- var vcchevent = new CustomEvent('vcChange', {'detail':this});
- document.dispatchEvent(vcchevent);
-
+ if (KorAP.vc){
+ var vcchevent = new CustomEvent('vcChange', {'detail':this});
+ this.element().dispatchEvent(vcchevent);
+ };
return this;
},
/**
diff --git a/dev/js/src/vc/doc.js b/dev/js/src/vc/doc.js
index 132c4a8..b012e1f 100644
--- a/dev/js/src/vc/doc.js
+++ b/dev/js/src/vc/doc.js
@@ -150,10 +150,8 @@
};
if(KorAP.vc){
- //Replaced through Event
- //KorAP.vc.checkGrayingStat(this);
var vcchevent = new CustomEvent('vcChange', {'detail':this});
- document.dispatchEvent(vcchevent);
+ KorAP.vc.element().dispatchEvent(vcchevent);
}
return e;
diff --git a/dev/js/src/vc/docgroup.js b/dev/js/src/vc/docgroup.js
index 858e847..c73a325 100644
--- a/dev/js/src/vc/docgroup.js
+++ b/dev/js/src/vc/docgroup.js
@@ -211,7 +211,7 @@
group.appendChild(op.element());
var vcchevent = new CustomEvent('vcChange', {'detail':this});
- document.dispatchEvent(vcchevent);
+ KorAP.vc.element().dispatchEvent(vcchevent);
return this;
},
diff --git a/dev/js/src/vc/docgroupref.js b/dev/js/src/vc/docgroupref.js
index f72e27a..9425fb3 100644
--- a/dev/js/src/vc/docgroupref.js
+++ b/dev/js/src/vc/docgroupref.js
@@ -111,7 +111,7 @@
};
var vcchevent = new CustomEvent('vcChange', {'detail':this});
- document.dispatchEvent(vcchevent);
+ KorAP.vc.element().dispatchEvent(vcchevent);
return this.element();
},
diff --git a/dev/js/src/view/corpstatv.js b/dev/js/src/view/corpstatv.js
index fa9a135..81c18cd 100644
--- a/dev/js/src/view/corpstatv.js
+++ b/dev/js/src/view/corpstatv.js
@@ -142,19 +142,19 @@
var reloadspan = document.createElement('div');
reloadspan.classList.add('reloadStatB');
reloadspan.classList.add('button-group');
- reloadspan.classList.add('button-panel');
+ reloadspan.classList.add('button-panel');
reloadb = reloadspan.addE('span');
reloadb.classList.add('refresh');
- var that = this;
- reloadb.addEventListener("click", function (e){
+ var that = this;
+ reloadb.addEventListener("click", function (e){
statt.classList.remove('stdisabled');
that.panel.reloadCorpStat();
});
statt.appendChild(reloadspan);
- statt.classList.add('stdisabled');
+ statt.classList.add('stdisabled');
}
},