Skip to content

Commit

Permalink
Update code style (#587)
Browse files Browse the repository at this point in the history
* Use camelcase for filenames

* Use const in webpack config

* Add tsc command; also remove duplicate package

* Do not use underscore for private methods

* Fix source maps

* Build

* Update typescript to 3.7

* Use optional chaining

* Remove js files from src_test

* Build
  • Loading branch information
mbraak committed Jan 10, 2020
1 parent bbc5bd4 commit d03f063
Show file tree
Hide file tree
Showing 55 changed files with 1,877 additions and 2,764 deletions.
714 changes: 390 additions & 324 deletions build/test.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/test.js.map

Large diffs are not rendered by default.

426 changes: 245 additions & 181 deletions build/tree.jquery.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/tree.jquery.js.map

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion lib/data_loader.js → lib/dataLoader.js
Expand Up @@ -73,7 +73,11 @@ var DataLoader = /** @class */ (function () {
};
DataLoader.prototype.parseData = function (data) {
var dataFilter = this.treeWidget.options.dataFilter;
var parsedData = data instanceof Array || typeof data === "object" ? data : data != null ? jQuery.parseJSON(data) : [];
var parsedData = data instanceof Array || typeof data === "object"
? data
: data != null
? jQuery.parseJSON(data)
: [];
return dataFilter ? dataFilter(parsedData) : parsedData;
};
return DataLoader;
Expand Down
20 changes: 15 additions & 5 deletions lib/drag_and_drop_handler.js → lib/dragAndDropHandler.js
Expand Up @@ -30,7 +30,8 @@ var DragAndDropHandler = /** @class */ (function () {
if (!this.mustCaptureElement($element)) {
return null;
}
if (this.treeWidget.options.onIsMoveHandle && !this.treeWidget.options.onIsMoveHandle($element)) {
if (this.treeWidget.options.onIsMoveHandle &&
!this.treeWidget.options.onIsMoveHandle($element)) {
return null;
}
var nodeElement = this.treeWidget._getNodeElement($element);
Expand All @@ -52,7 +53,9 @@ var DragAndDropHandler = /** @class */ (function () {
}
};
DragAndDropHandler.prototype.mouseStart = function (positionInfo) {
if (!this.currentItem || positionInfo.pageX === undefined || positionInfo.pageY === undefined) {
if (!this.currentItem ||
positionInfo.pageX === undefined ||
positionInfo.pageY === undefined) {
return false;
}
else {
Expand All @@ -61,7 +64,9 @@ var DragAndDropHandler = /** @class */ (function () {
var left = offset ? offset.left : 0;
var top_1 = offset ? offset.top : 0;
var node = this.currentItem.node;
var nodeName = this.treeWidget.options.autoEscape ? util_1.htmlEscape(node.name) : node.name;
var nodeName = this.treeWidget.options.autoEscape
? util_1.htmlEscape(node.name)
: node.name;
this.dragElement = new DragElement(nodeName, positionInfo.pageX - left, positionInfo.pageY - top_1, this.treeWidget.element);
this.isDragging = true;
this.positionInfo = positionInfo;
Expand Down Expand Up @@ -174,7 +179,10 @@ var DragAndDropHandler = /** @class */ (function () {
};
DragAndDropHandler.prototype.findHoveredArea = function (x, y) {
var dimensions = this.getTreeDimensions();
if (x < dimensions.left || y < dimensions.top || x > dimensions.right || y > dimensions.bottom) {
if (x < dimensions.left ||
y < dimensions.top ||
x > dimensions.right ||
y > dimensions.bottom) {
return null;
}
var low = 0;
Expand All @@ -196,7 +204,9 @@ var DragAndDropHandler = /** @class */ (function () {
};
DragAndDropHandler.prototype.mustOpenFolderTimer = function (area) {
var node = area.node;
return node.isFolder() && !node.is_open && area.position === node_1.Position.Inside;
return (node.isFolder() &&
!node.is_open &&
area.position === node_1.Position.Inside);
};
DragAndDropHandler.prototype.updateDropHint = function () {
if (!this.hoveredArea) {
Expand Down
10 changes: 7 additions & 3 deletions lib/elements_renderer.js → lib/elementsRenderer.js
Expand Up @@ -72,8 +72,10 @@ var ElementsRenderer = /** @class */ (function () {
return ul;
};
ElementsRenderer.prototype.createLi = function (node, level) {
var isSelected = Boolean(this.treeWidget.selectNodeHandler && this.treeWidget.selectNodeHandler.isNodeSelected(node));
var mustShowFolder = node.isFolder() || (node.isEmptyFolder && this.treeWidget.options.showEmptyFolder);
var isSelected = Boolean(this.treeWidget.selectNodeHandler &&
this.treeWidget.selectNodeHandler.isNodeSelected(node));
var mustShowFolder = node.isFolder() ||
(node.isEmptyFolder && this.treeWidget.options.showEmptyFolder);
var li = mustShowFolder
? this.createFolderLi(node, level, isSelected)
: this.createNodeLi(node, level, isSelected);
Expand All @@ -85,7 +87,9 @@ var ElementsRenderer = /** @class */ (function () {
ElementsRenderer.prototype.createFolderLi = function (node, level, isSelected) {
var buttonClasses = this.getButtonClasses(node);
var folderClasses = this.getFolderClasses(node, isSelected);
var iconElement = node.is_open ? this.openedIconElement : this.closedIconElement;
var iconElement = node.is_open
? this.openedIconElement
: this.closedIconElement;
// li
var li = document.createElement("li");
li.className = "jqtree_common " + folderClasses;
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 6 additions & 2 deletions lib/key_handler.js → lib/keyHandler.js
Expand Up @@ -99,11 +99,15 @@ var KeyHandler = /** @class */ (function () {
}
};
KeyHandler.prototype.canHandleKeyboard = function () {
return (this.treeWidget.options.keyboardSupport && this.isFocusOnTree() && this.treeWidget.getSelectedNode() != null);
return (this.treeWidget.options.keyboardSupport &&
this.isFocusOnTree() &&
this.treeWidget.getSelectedNode() != null);
};
KeyHandler.prototype.isFocusOnTree = function () {
var activeElement = document.activeElement;
return Boolean(activeElement && activeElement.tagName === "SPAN" && this.treeWidget._containsElement(activeElement));
return Boolean(activeElement &&
activeElement.tagName === "SPAN" &&
this.treeWidget._containsElement(activeElement));
};
KeyHandler.LEFT = 37;
KeyHandler.UP = 38;
Expand Down
50 changes: 27 additions & 23 deletions lib/mouse.widget.js
Expand Up @@ -26,44 +26,48 @@ var MouseWidget = /** @class */ (function (_super) {
if (e.which !== 1) {
return;
}
var result = _this._handleMouseDown(_this._getPositionInfo(e));
var result = _this.handleMouseDown(_this.getPositionInfo(e));
if (result) {
e.preventDefault();
}
return result;
};
_this.mouseMove = function (e) { return _this._handleMouseMove(e, _this._getPositionInfo(e)); };
_this.mouseUp = function (e) { return _this._handleMouseUp(_this._getPositionInfo(e)); };
_this.mouseMove = function (e) {
return _this.handleMouseMove(e, _this.getPositionInfo(e));
};
_this.mouseUp = function (e) {
return _this.handleMouseUp(_this.getPositionInfo(e));
};
_this.touchStart = function (e) {
var touchEvent = e.originalEvent;
if (touchEvent.touches.length > 1) {
return;
}
var touch = touchEvent.changedTouches[0];
return _this._handleMouseDown(_this._getPositionInfo(touch));
return _this.handleMouseDown(_this.getPositionInfo(touch));
};
_this.touchMove = function (e) {
var touchEvent = e.originalEvent;
if (touchEvent.touches.length > 1) {
return;
}
var touch = touchEvent.changedTouches[0];
return _this._handleMouseMove(e, _this._getPositionInfo(touch));
return _this.handleMouseMove(e, _this.getPositionInfo(touch));
};
_this.touchEnd = function (e) {
var touchEvent = e.originalEvent;
if (touchEvent.touches.length > 1) {
return;
}
var touch = touchEvent.changedTouches[0];
return _this._handleMouseUp(_this._getPositionInfo(touch));
return _this.handleMouseUp(_this.getPositionInfo(touch));
};
return _this;
}
MouseWidget.prototype.setMouseDelay = function (mouseDelay) {
this.mouseDelay = mouseDelay;
};
MouseWidget.prototype._init = function () {
MouseWidget.prototype.init = function () {
this.$el.on("mousedown.mousewidget", this.mouseDown);
this.$el.on("touchstart.mousewidget", this.touchStart);
this.isMouseStarted = false;
Expand All @@ -72,36 +76,36 @@ var MouseWidget = /** @class */ (function (_super) {
this.isMouseDelayMet = true;
this.mouseDownInfo = null;
};
MouseWidget.prototype._deinit = function () {
MouseWidget.prototype.deinit = function () {
this.$el.off("mousedown.mousewidget");
this.$el.off("touchstart.mousewidget");
var $document = jQuery(document);
$document.off("mousemove.mousewidget");
$document.off("mouseup.mousewidget");
};
MouseWidget.prototype._handleMouseDown = function (positionInfo) {
MouseWidget.prototype.handleMouseDown = function (positionInfo) {
// We may have missed mouseup (out of window)
if (this.isMouseStarted) {
this._handleMouseUp(positionInfo);
this.handleMouseUp(positionInfo);
}
this.mouseDownInfo = positionInfo;
if (!this._mouseCapture(positionInfo)) {
if (!this.mouseCapture(positionInfo)) {
return;
}
this._handleStartMouse();
this.handleStartMouse();
return true;
};
MouseWidget.prototype._handleStartMouse = function () {
MouseWidget.prototype.handleStartMouse = function () {
var $document = jQuery(document);
$document.on("mousemove.mousewidget", this.mouseMove);
$document.on("touchmove.mousewidget", this.touchMove);
$document.on("mouseup.mousewidget", this.mouseUp);
$document.on("touchend.mousewidget", this.touchEnd);
if (this.mouseDelay) {
this._startMouseDelayTimer();
this.startMouseDelayTimer();
}
};
MouseWidget.prototype._startMouseDelayTimer = function () {
MouseWidget.prototype.startMouseDelayTimer = function () {
var _this = this;
if (this.mouseDelayTimer) {
clearTimeout(this.mouseDelayTimer);
Expand All @@ -111,42 +115,42 @@ var MouseWidget = /** @class */ (function (_super) {
}, this.mouseDelay);
this.isMouseDelayMet = false;
};
MouseWidget.prototype._handleMouseMove = function (e, positionInfo) {
MouseWidget.prototype.handleMouseMove = function (e, positionInfo) {
if (this.isMouseStarted) {
this._mouseDrag(positionInfo);
this.mouseDrag(positionInfo);
return e.preventDefault();
}
if (this.mouseDelay && !this.isMouseDelayMet) {
return true;
}
if (this.mouseDownInfo) {
this.isMouseStarted = this._mouseStart(this.mouseDownInfo) !== false;
this.isMouseStarted = this.mouseStart(this.mouseDownInfo) !== false;
}
if (this.isMouseStarted) {
this._mouseDrag(positionInfo);
this.mouseDrag(positionInfo);
}
else {
this._handleMouseUp(positionInfo);
this.handleMouseUp(positionInfo);
}
return !this.isMouseStarted;
};
MouseWidget.prototype._getPositionInfo = function (e) {
MouseWidget.prototype.getPositionInfo = function (e) {
return {
pageX: e.pageX,
pageY: e.pageY,
target: e.target,
originalEvent: e
};
};
MouseWidget.prototype._handleMouseUp = function (positionInfo) {
MouseWidget.prototype.handleMouseUp = function (positionInfo) {
var $document = jQuery(document);
$document.off("mousemove.mousewidget");
$document.off("touchmove.mousewidget");
$document.off("mouseup.mousewidget");
$document.off("touchend.mousewidget");
if (this.isMouseStarted) {
this.isMouseStarted = false;
this._mouseStop(positionInfo);
this.mouseStop(positionInfo);
}
};
return MouseWidget;
Expand Down
41 changes: 28 additions & 13 deletions lib/node.js
Expand Up @@ -126,7 +126,7 @@ var Node = /** @class */ (function () {
*/
Node.prototype.addChild = function (node) {
this.children.push(node);
node._setParent(this);
node.setParent(this);
};
/*
Add child at position. Index starts at 0.
Expand All @@ -138,7 +138,7 @@ var Node = /** @class */ (function () {
*/
Node.prototype.addChildAtPosition = function (node, index) {
this.children.splice(index, 0, node);
node._setParent(this);
node.setParent(this);
};
/*
Remove child. This also removes the children of the node.
Expand All @@ -148,7 +148,7 @@ var Node = /** @class */ (function () {
Node.prototype.removeChild = function (node) {
// remove children from the index
node.removeChildren();
this._removeChild(node);
this.doRemoveChild(node);
};
/*
Get child index.
Expand Down Expand Up @@ -217,7 +217,7 @@ var Node = /** @class */ (function () {
return;
}
else {
movedNode.parent._removeChild(movedNode);
movedNode.parent.doRemoveChild(movedNode);
if (position === Position.After) {
if (targetNode.parent) {
targetNode.parent.addChildAtPosition(movedNode, targetNode.parent.getChildIndex(targetNode) + 1);
Expand All @@ -243,7 +243,13 @@ var Node = /** @class */ (function () {
return nodes.map(function (node) {
var tmpNode = {};
for (var k in node) {
if (["parent", "children", "element", "tree", "isEmptyFolder"].indexOf(k) === -1 &&
if ([
"parent",
"children",
"element",
"tree",
"isEmptyFolder"
].indexOf(k) === -1 &&
Object.prototype.hasOwnProperty.call(node, k)) {
var v = node[k];
tmpNode[k] = v;
Expand Down Expand Up @@ -286,7 +292,9 @@ var Node = /** @class */ (function () {
var node = new this.tree.nodeClass(nodeInfo);
var childIndex = this.parent.getChildIndex(this);
this.parent.addChildAtPosition(node, childIndex + 1);
if (typeof nodeInfo === "object" && nodeInfo["children"] && nodeInfo["children"].length) {
if (typeof nodeInfo === "object" &&
nodeInfo["children"] &&
nodeInfo["children"].length) {
node.loadFromData(nodeInfo["children"]);
}
return node;
Expand All @@ -300,7 +308,9 @@ var Node = /** @class */ (function () {
var node = new this.tree.nodeClass(nodeInfo);
var childIndex = this.parent.getChildIndex(this);
this.parent.addChildAtPosition(node, childIndex);
if (typeof nodeInfo === "object" && nodeInfo["children"] && nodeInfo["children"].length) {
if (typeof nodeInfo === "object" &&
nodeInfo["children"] &&
nodeInfo["children"].length) {
node.loadFromData(nodeInfo["children"]);
}
return node;
Expand All @@ -312,7 +322,7 @@ var Node = /** @class */ (function () {
}
else {
var newParent = new this.tree.nodeClass(nodeInfo);
newParent._setParent(this.tree);
newParent.setParent(this.tree);
var originalParent = this.parent;
for (var _i = 0, _a = originalParent.children; _i < _a.length; _i++) {
var child = _a[_i];
Expand All @@ -332,15 +342,19 @@ var Node = /** @class */ (function () {
Node.prototype.append = function (nodeInfo) {
var node = new this.tree.nodeClass(nodeInfo);
this.addChild(node);
if (typeof nodeInfo === "object" && nodeInfo["children"] && nodeInfo["children"].length) {
if (typeof nodeInfo === "object" &&
nodeInfo["children"] &&
nodeInfo["children"].length) {
node.loadFromData(nodeInfo["children"]);
}
return node;
};
Node.prototype.prepend = function (nodeInfo) {
var node = new this.tree.nodeClass(nodeInfo);
this.addChildAtPosition(node, 0);
if (typeof nodeInfo === "object" && nodeInfo["children"] && nodeInfo["children"].length) {
if (typeof nodeInfo === "object" &&
nodeInfo["children"] &&
nodeInfo["children"].length) {
node.loadFromData(nodeInfo["children"]);
}
return node;
Expand Down Expand Up @@ -456,7 +470,8 @@ var Node = /** @class */ (function () {
else {
var previousSibling = this.getPreviousSibling();
if (previousSibling) {
if (!previousSibling.hasChildren() || !previousSibling.is_open) {
if (!previousSibling.hasChildren() ||
!previousSibling.is_open) {
// Previous sibling
return previousSibling;
}
Expand Down Expand Up @@ -516,12 +531,12 @@ var Node = /** @class */ (function () {
};
addNode(data);
};
Node.prototype._setParent = function (parent) {
Node.prototype.setParent = function (parent) {
this.parent = parent;
this.tree = parent.tree;
this.tree.addNodeToIndex(this);
};
Node.prototype._removeChild = function (node) {
Node.prototype.doRemoveChild = function (node) {
this.children.splice(this.getChildIndex(node), 1);
this.tree.removeNodeFromIndex(node);
};
Expand Down

0 comments on commit d03f063

Please sign in to comment.