Change the way to re-attach rails when they're detached.

Instead of destroying and re-initialising the plugin, just re-append
them.
This commit is contained in:
Hyunje Alex Jun 2015-03-11 22:02:38 +09:00
parent 2e071274db
commit 4a7f27356a
2 changed files with 13 additions and 15 deletions

View File

@ -60,6 +60,13 @@ module.exports = function (element) {
i.contentWidth = element.scrollWidth;
i.contentHeight = element.scrollHeight;
if (!element.contains(i.scrollbarXRail)) {
d.appendTo(i.scrollbarXRail, element);
}
if (!element.contains(i.scrollbarYRail)) {
d.appendTo(i.scrollbarYRail, element);
}
if (!i.settings.suppressScrollX && i.containerWidth + i.settings.scrollXMarginOffset < i.contentWidth) {
i.scrollbarXActive = true;
i.railXWidth = i.containerWidth - i.railXMarginWidth;

View File

@ -4,27 +4,18 @@
'use strict';
var d = require('../lib/dom')
, destroy = require('./destroy')
, initialize = require('./initialize')
, instances = require('./instances')
, updateGeometry = require('./update-geometry');
module.exports = function (element) {
var i = instances.get(element);
if (!i.scrollbarXRail || !element.contains(i.scrollbarXRail) ||
!i.scrollbarYRail || !element.contains(i.scrollbarYRail)) {
// If there's something wrong in the plugin, re-initialise.
destroy(element);
initialize(element);
} else {
// Hide scrollbars not to affect scrollWidth and scrollHeight
d.css(i.scrollbarXRail, 'display', 'none');
d.css(i.scrollbarYRail, 'display', 'none');
// Hide scrollbars not to affect scrollWidth and scrollHeight
d.css(i.scrollbarXRail, 'display', 'none');
d.css(i.scrollbarYRail, 'display', 'none');
updateGeometry(element);
updateGeometry(element);
d.css(i.scrollbarXRail, 'display', 'block');
d.css(i.scrollbarYRail, 'display', 'block');
}
d.css(i.scrollbarXRail, 'display', 'block');
d.css(i.scrollbarYRail, 'display', 'block');
};