67 lines
2.5 KiB
JavaScript
67 lines
2.5 KiB
JavaScript
/* Copyright (c) 2015 Hyunje Alex Jun and other contributors
|
|
* Licensed under the MIT License
|
|
*/
|
|
'use strict';
|
|
|
|
var d = require('../lib/dom')
|
|
, defaultSettings = require('./default-setting')
|
|
, EventManager = require('../lib/event-manager')
|
|
, guid = require('../lib/guid')
|
|
, h = require('../lib/helper');
|
|
|
|
var instances = {};
|
|
|
|
function Instance(element) {
|
|
var i = this;
|
|
|
|
i.settings = h.clone(defaultSettings);
|
|
i.containerWidth = null;
|
|
i.containerHeight = null;
|
|
i.contentWidth = null;
|
|
i.contentHeight = null;
|
|
|
|
i.isRtl = d.css(element, 'direction') === "rtl";
|
|
i.event = new EventManager();
|
|
i.ownerDocument = element.ownerDocument || document;
|
|
|
|
i.scrollbarXRail = d.appendTo(d.e('div', 'ps-scrollbar-x-rail'), element);
|
|
i.scrollbarX = d.appendTo(d.e('div', 'ps-scrollbar-x'), i.scrollbarXRail);
|
|
i.scrollbarXActive = null;
|
|
i.scrollbarXWidth = null;
|
|
i.scrollbarXLeft = null;
|
|
i.scrollbarXBottom = h.toInt(d.css(i.scrollbarXRail, 'bottom'));
|
|
i.isScrollbarXUsingBottom = i.scrollbarXBottom === i.scrollbarXBottom; // !isNaN
|
|
i.scrollbarXTop = i.isScrollbarXUsingBottom ? null : h.toInt(d.css(i.scrollbarXRail, 'top'));
|
|
i.railBorderXWidth = h.toInt(d.css(i.scrollbarXRail, 'borderLeftWidth')) + h.toInt(d.css(i.scrollbarXRail, 'borderRightWidth'));
|
|
i.railXMarginWidth = h.toInt(d.css(i.scrollbarXRail, 'marginLeft')) + h.toInt(d.css(i.scrollbarXRail, 'marginRight'));
|
|
i.railXWidth = null;
|
|
|
|
i.scrollbarYRail = d.appendTo(d.e('div', 'ps-scrollbar-y-rail'), element);
|
|
i.scrollbarY = d.appendTo(d.e('div', 'ps-scrollbar-y'), i.scrollbarYRail);
|
|
i.scrollbarYActive = null;
|
|
i.scrollbarYHeight = null;
|
|
i.scrollbarYTop = null;
|
|
i.scrollbarYRight = h.toInt(d.css(i.scrollbarYRail, 'right'));
|
|
i.isScrollbarYUsingRight = i.scrollbarYRight === i.scrollbarYRight; // !isNaN
|
|
i.scrollbarYLeft = i.isScrollbarYUsingRight ? null : h.toInt(d.css(i.scrollbarYRail, 'left'));
|
|
i.railBorderYWidth = h.toInt(d.css(i.scrollbarYRail, 'borderTopWidth')) + h.toInt(d.css(i.scrollbarYRail, 'borderBottomWidth'));
|
|
i.railYMarginHeight = h.toInt(d.css(i.scrollbarYRail, 'marginTop')) + h.toInt(d.css(i.scrollbarYRail, 'marginBottom'));
|
|
i.railYHeight = null;
|
|
}
|
|
|
|
exports.add = function (element) {
|
|
var newId = guid();
|
|
element.dataset.psId = newId;
|
|
instances[newId] = new Instance(element);
|
|
return instances[newId];
|
|
};
|
|
|
|
exports.remove = function (element) {
|
|
delete instances[element.dataset.psId];
|
|
delete element.dataset.psId;
|
|
};
|
|
|
|
exports.get = function (element) {
|
|
return instances[element.dataset.psId];
|
|
};
|