Add null-check when updating or destroying an instance.

Throw an error when an instance is not found.
This commit is contained in:
Hyunje Alex Jun 2015-07-07 15:25:16 +09:00
parent 1f082a2e04
commit f9f20eeb6f
2 changed files with 8 additions and 0 deletions

View File

@ -10,6 +10,10 @@ var d = require('../lib/dom')
module.exports = function (element) {
var i = instances.get(element);
if (!i) {
throw new Error('perfect-scrollbar: instance not found');
}
i.event.unbindAll();
d.remove(i.scrollbarX);
d.remove(i.scrollbarY);

View File

@ -11,6 +11,10 @@ var d = require('../lib/dom')
module.exports = function (element) {
var i = instances.get(element);
if (!i) {
throw new Error('perfect-scrollbar: instance not found');
}
// Recalcuate negative scrollLeft adjustment
i.negativeScrollAdjustment = i.isNegativeScroll ? element.scrollWidth - element.clientWidth : 0;