More independent.

This commit is contained in:
Hyunje Alex Jun 2015-01-24 15:03:52 +00:00
parent ff5ca3d804
commit 1541f73add
3 changed files with 46 additions and 14 deletions

View File

@ -49,3 +49,27 @@ exports.css = function (element, styleNameOrObject, styleValue) {
} }
} }
}; };
exports.matches = function (element, query) {
if (typeof element.matches !== 'undefined') {
return element.matches(query);
} else {
if (typeof element.matchesSelector !== 'undefined') {
return element.matchesSelector(query);
} else if (element.webkitMatchesSelector !== 'undefined') {
return element.webkitMatchesSelector(query);
} else if (element.mozMatchesSelector !== 'undefined') {
return element.mozMatchesSelector(query);
} else if (element.msMatchesSelector !== 'undefined') {
return element.msMatchesSelector(query);
}
}
};
exports.remove = function (element) {
if (typeof element.remove !== 'undefined') {
element.remove();
} else {
element.parentNode.removeChild(element);
}
};

View File

@ -3,6 +3,8 @@
*/ */
'use strict'; 'use strict';
var d = require('./dom');
exports.toInt = function (x) { exports.toInt = function (x) {
if (typeof x === 'string') { if (typeof x === 'string') {
return parseInt(x, 10); return parseInt(x, 10);
@ -34,3 +36,10 @@ exports.extend = function (original, source) {
} }
return result; return result;
}; };
exports.isEditable = function (el) {
return d.matches(el, "input,[contenteditable]") ||
d.matches(el, "select,[contenteditable]") ||
d.matches(el, "textarea,[contenteditable]") ||
d.matches(el, "button,[contenteditable]");
};

View File

@ -223,7 +223,7 @@ module.exports = function (element, settingOrCommand) {
$(scrollbarX).bind(eventClass('mousedown'), function (e) { $(scrollbarX).bind(eventClass('mousedown'), function (e) {
currentPageX = e.pageX; currentPageX = e.pageX;
currentLeft = $(scrollbarX).position().left; currentLeft = h.toInt(d.css(scrollbarX, 'left'));
cls.add(element, 'ps-in-scrolling'); cls.add(element, 'ps-in-scrolling');
$(ownerDocument).bind(eventClass('mousemove'), mouseMoveHandler); $(ownerDocument).bind(eventClass('mousemove'), mouseMoveHandler);
@ -255,7 +255,7 @@ module.exports = function (element, settingOrCommand) {
$(scrollbarY).bind(eventClass('mousedown'), function (e) { $(scrollbarY).bind(eventClass('mousedown'), function (e) {
currentPageY = e.pageY; currentPageY = e.pageY;
currentTop = $(scrollbarY).position().top; currentTop = h.toInt(d.css(scrollbarY, 'top'));
cls.add(element, 'ps-in-scrolling'); cls.add(element, 'ps-in-scrolling');
$(ownerDocument).bind(eventClass('mousemove'), mouseMoveHandler); $(ownerDocument).bind(eventClass('mousemove'), mouseMoveHandler);
@ -424,7 +424,7 @@ module.exports = function (element, settingOrCommand) {
while (activeElement.shadowRoot) { while (activeElement.shadowRoot) {
activeElement = activeElement.shadowRoot.activeElement; activeElement = activeElement.shadowRoot.activeElement;
} }
if ($(activeElement).is(":input,[contenteditable]")) { if (h.isEditable(activeElement)) {
return; return;
} }
@ -485,7 +485,7 @@ module.exports = function (element, settingOrCommand) {
$(scrollbarY).bind(eventClass('click'), stopPropagation); $(scrollbarY).bind(eventClass('click'), stopPropagation);
$(scrollbarYRail).bind(eventClass('click'), function (e) { $(scrollbarYRail).bind(eventClass('click'), function (e) {
var halfOfScrollbarLength = h.toInt(scrollbarYHeight / 2); var halfOfScrollbarLength = h.toInt(scrollbarYHeight / 2);
var positionTop = e.pageY - $(scrollbarYRail).offset().top - halfOfScrollbarLength; var positionTop = e.pageY - scrollbarYRail.offsetTop - halfOfScrollbarLength;
var maxPositionTop = containerHeight - scrollbarYHeight; var maxPositionTop = containerHeight - scrollbarYHeight;
var positionRatio = positionTop / maxPositionTop; var positionRatio = positionTop / maxPositionTop;
@ -501,7 +501,7 @@ module.exports = function (element, settingOrCommand) {
$(scrollbarX).bind(eventClass('click'), stopPropagation); $(scrollbarX).bind(eventClass('click'), stopPropagation);
$(scrollbarXRail).bind(eventClass('click'), function (e) { $(scrollbarXRail).bind(eventClass('click'), function (e) {
var halfOfScrollbarLength = h.toInt(scrollbarXWidth / 2); var halfOfScrollbarLength = h.toInt(scrollbarXWidth / 2);
var positionLeft = e.pageX - $(scrollbarXRail).offset().left - halfOfScrollbarLength; var positionLeft = e.pageX - scrollbarXRail.offsetLeft - halfOfScrollbarLength;
var maxPositionLeft = containerWidth - scrollbarXWidth; var maxPositionLeft = containerWidth - scrollbarXWidth;
var positionRatio = positionLeft / maxPositionLeft; var positionRatio = positionLeft / maxPositionLeft;
@ -570,12 +570,11 @@ module.exports = function (element, settingOrCommand) {
$(window).bind(eventClass('mousemove'), function (e) { $(window).bind(eventClass('mousemove'), function (e) {
if (isSelected) { if (isSelected) {
var mousePosition = {x: e.pageX, y: e.pageY}; var mousePosition = {x: e.pageX, y: e.pageY};
var containerOffset = $(element).offset();
var containerGeometry = { var containerGeometry = {
left: containerOffset.left, left: element.offsetLeft,
right: containerOffset.left + element.offsetWidth, right: element.offsetLeft + element.offsetWidth,
top: containerOffset.top, top: element.offsetTop,
bottom: containerOffset.top + element.offsetHeight bottom: element.offsetTop + element.offsetHeight
}; };
if (mousePosition.x < containerGeometry.left + 3) { if (mousePosition.x < containerGeometry.left + 3) {
@ -762,10 +761,10 @@ module.exports = function (element, settingOrCommand) {
$(element).data('perfect-scrollbar', null); $(element).data('perfect-scrollbar', null);
$(element).data('perfect-scrollbar-update', null); $(element).data('perfect-scrollbar-update', null);
$(element).data('perfect-scrollbar-destroy', null); $(element).data('perfect-scrollbar-destroy', null);
$(scrollbarX).remove(); d.remove(scrollbarX);
$(scrollbarY).remove(); d.remove(scrollbarY);
$(scrollbarXRail).remove(); d.remove(scrollbarXRail);
$(scrollbarYRail).remove(); d.remove(scrollbarYRail);
// clean all variables // clean all variables
scrollbarXActive = scrollbarXActive =