Skip to content

Commit

Permalink
v1.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
nathancahill committed Oct 12, 2018
1 parent a809e7d commit 067b927
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 32 deletions.
6 changes: 2 additions & 4 deletions bower.json
@@ -1,12 +1,12 @@
{
"name": "Split.js",
"main": "split.js",
"version": "1.5.2",
"version": "1.5.3",
"homepage": "https://github.com/nathancahill/Split.js",
"authors": [
"Nathan Cahill <nathan@nathancahill.com>"
],
"description": "A lightweight utility for creating adjustable split views",
"description": "< 2kb unopinionated utility for resizeable split views",
"keywords": [
"css",
"split",
Expand All @@ -25,11 +25,9 @@
"AUTHORS.md",
"browserstack.json",
"docs",
"examples",
"Gruntfile.js",
"logo.svg",
"node_modules",
"package.json",
"rollup.config.js",
"src",
"test"
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "split.js",
"version": "1.5.2",
"version": "1.5.3",
"description": "A lightweight utility for creating adjustable split views",
"main": "split.js",
"minified:main": "split.min.js",
Expand Down
68 changes: 43 additions & 25 deletions split.js
@@ -1,4 +1,4 @@
/*! Split.js - v1.5.2 */
/*! Split.js - v1.5.3 */

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
Expand Down Expand Up @@ -67,6 +67,24 @@
return def
};

var getGutterSize = function (gutterSize, isFirst, isLast, gutterAlign) {
if (isFirst) {
if (gutterAlign === 'end') {
return 0
} else if (gutterAlign === 'center') {
return gutterSize / 2
}
} else if (isLast) {
if (gutterAlign === 'start') {
return 0
} else if (gutterAlign === 'center') {
return gutterSize / 2
}
}

return gutterSize
};

// Default options
var defaultGutterFn = function (i, gutterDirection) {
var gut = document.createElement('div');
Expand Down Expand Up @@ -110,8 +128,6 @@
// bMin: Number,
// dragging: Boolean,
// parent: DOM element,
// isFirst: Boolean,
// isLast: Boolean,
// direction: 'horizontal' | 'vertical'
// }
//
Expand All @@ -123,7 +139,7 @@
// rely on CSS strings and classes.
// 3. Define the dragging helper functions, and a few helpers to go with them.
// 4. Loop through the elements while pairing them off. Every pair gets an
// `pair` object, a gutter, and special isFirst/isLast properties.
// `pair` object and a gutter.
// 5. Actually size the pair elements, insert gutters and attach event listeners.
var Split = function (idsOption, options) {
if ( options === void 0 ) options = {};
Expand Down Expand Up @@ -157,7 +173,9 @@
// Get other options
var expandToMin = getOption(options, 'expandToMin', false);
var gutterSize = getOption(options, 'gutterSize', 10);
var gutterAlign = getOption(options, 'gutterAlign', 'center');
var snapOffset = getOption(options, 'snapOffset', 30);
var dragInterval = getOption(options, 'dragInterval', 0);
var direction = getOption(options, 'direction', HORIZONTAL);
var cursor = getOption(options, 'cursor', direction === HORIZONTAL ? 'ew-resize' : 'ns-resize');
var gutter = getOption(options, 'gutter', defaultGutterFn);
Expand Down Expand Up @@ -262,6 +280,16 @@
offset = e[clientAxis] - this.start;
}

if (dragInterval > 0) {
offset = Math.round(offset / dragInterval) * dragInterval;
}

// if (gutterAlign === 'start') {
// offset -= this[aGutterSize]
// } else if (gutterAlign === 'end') {
// offset += this[bGutterSize]
// }

// If within snapOffset of min or max, set offset to min or max.
// snapOffset buffers a.minSize and b.minSize, so logic is opposite for both.
// Include the appropriate gutter sizes to prevent overflows.
Expand Down Expand Up @@ -351,9 +379,9 @@
// It also adds event listeners for mouse/touch events,
// and prevents selection while dragging so avoid the selecting text.
function startDragging (e) {
//Right-clicking can't start dragging.
// Right-clicking can't start dragging.
if (e.button !== 0) {
return;
return
}

// Alias frequently used variables to save space. 200 bytes.
Expand Down Expand Up @@ -412,7 +440,7 @@
// 5. Create pair and element objects. Each pair has an index reference to
// elements `a` and `b` of the pair (first and second elements).
// Loop through the elements while pairing them off. Every pair gets a
// `pair` object, a gutter, and isFirst/isLast properties.
// `pair` object and a gutter.
//
// Basic logic:
//
Expand All @@ -425,7 +453,7 @@
//
// -----------------------------------------------------------------------
// | i=0 | i=1 | i=2 | i=3 |
// | | isFirst | | isLast |
// | | | | |
// | pair 0 pair 1 pair 2 |
// | | | | |
// -----------------------------------------------------------------------
Expand All @@ -447,23 +475,12 @@
a: i - 1,
b: i,
dragging: false,
isFirst: (i === 1),
isLast: (i === ids.length - 1),
direction: direction,
parent: parent,
};

// For first and last pairs, first and last gutter width is half.
pair[aGutterSize] = gutterSize;
pair[bGutterSize] = gutterSize;

if (pair.isFirst) {
pair[aGutterSize] = gutterSize / 2;
}

if (pair.isLast) {
pair[bGutterSize] = gutterSize / 2;
}
pair[aGutterSize] = getGutterSize(gutterSize, i - 1 === 0, false, gutterAlign);
pair[bGutterSize] = getGutterSize(gutterSize, false, i === ids.length - 1, gutterAlign);

// if the parent has a reverse flex-direction, switch the pair elements.
if (parentFlexDirection === 'row-reverse' || parentFlexDirection === 'column-reverse') {
Expand Down Expand Up @@ -497,10 +514,11 @@
}
}

// Set the element size to our determined size.
// Half-size gutters for first and last elements.
var elementGutterSize = (i === 0 || i === ids.length - 1) ? gutterSize / 2 : gutterSize;
setElementSize(element.element, element.size, elementGutterSize);
setElementSize(
element.element,
element.size,
getGutterSize(gutterSize, i === 0, i === ids.length - 1, gutterAlign)
);

// After the first iteration, and we have a pair object, append it to the
// list of pairs.
Expand Down
4 changes: 2 additions & 2 deletions split.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 067b927

Please sign in to comment.