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.contentWidth = element.scrollWidth;
i.contentHeight = element.scrollHeight; 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) { if (!i.settings.suppressScrollX && i.containerWidth + i.settings.scrollXMarginOffset < i.contentWidth) {
i.scrollbarXActive = true; i.scrollbarXActive = true;
i.railXWidth = i.containerWidth - i.railXMarginWidth; i.railXWidth = i.containerWidth - i.railXMarginWidth;

View File

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