Skip to content

Commit

Permalink
v1.5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
nathancahill committed Oct 26, 2018
1 parent 8e99b9a commit ca044c7
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<img alt="Split.js" title="Split.js" src="https://cdn.rawgit.com/nathancahill/Split.js/master/logo.svg" width="430">
<br><br>
<a href="https://travis-ci.org/nathancahill/Split.js"><img src="https://travis-ci.org/nathancahill/Split.js.svg" alt="Build Status"></a>
<a href="https://raw.githubusercontent.com/nathancahill/Split.js/master/split.min.js"><img src="https://badge-size.herokuapp.com/nathancahill/Split.js/master/split.min.js.svg?compression=gzip&label=size&v=1.5.6" alt="File Size"></a>
<a href="https://raw.githubusercontent.com/nathancahill/Split.js/master/split.min.js"><img src="https://badge-size.herokuapp.com/nathancahill/Split.js/master/split.min.js.svg?compression=gzip&label=size&v=1.5.7" alt="File Size"></a>
<img src="https://badge.fury.io/js/split.js.svg" alt="npm version">
<img src="https://david-dm.org/nathancahill/Split.js/status.svg" alt="Dependencies">
<img src = "https://opencollective.com/splitjs/backers/badge.svg" alt="Backers on Open Collective"/>
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Split.js",
"main": "split.js",
"version": "1.5.6",
"version": "1.5.7",
"homepage": "https://github.com/nathancahill/Split.js",
"authors": [
"Nathan Cahill <[email protected]>"
Expand Down
4 changes: 2 additions & 2 deletions docs/split.min.js

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "split.js",
"version": "1.5.6",
"version": "1.5.7",
"description": "2kb unopinionated utility for resizeable split views",
"main": "split.js",
"minified:main": "split.min.js",
Expand Down
71 changes: 68 additions & 3 deletions split.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! Split.js - v1.5.6 */
/*! Split.js - v1.5.7 */

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
Expand Down Expand Up @@ -149,6 +149,7 @@
var clientAxis;
var position;
var positionEnd;
var clientSize;
var elements;

// Allow HTMLCollection to be used as an argument when supported
Expand Down Expand Up @@ -191,11 +192,13 @@
clientAxis = 'clientX';
position = 'left';
positionEnd = 'right';
clientSize = 'clientWidth';
} else if (direction === 'vertical') {
dimension = 'height';
clientAxis = 'clientY';
position = 'top';
positionEnd = 'bottom';
clientSize = 'clientHeight';
}

// 3. Define the dragging helper functions, and a few helpers to go with them.
Expand Down Expand Up @@ -333,6 +336,63 @@
this.end = aBounds[positionEnd];
}

// When specifying percentage sizes that are less than the computed
// size of the element minus the gutter, the lesser percentages must be increased
// (and decreased from the other elements) to make space for the pixels
// subtracted by the gutters.
function trimToMin (sizesToTrim) {
// Keep track of the excess pixels, the amount of pixels over the desired percentage
// Also keep track of the elements with pixels to spare, to decrease after if needed
var excessPixels = 0;
var toSpare = [];

var pixelSizes = sizesToTrim.map(function (size, i) {
// Convert requested percentages to pixel sizes
var pixelSize = (parent[clientSize] * size) / 100;
var elementGutterSize = getGutterSize(
gutterSize,
i === 0,
i === sizesToTrim.length - 1,
gutterAlign
);
var elementMinSize = minSizes[i] + elementGutterSize;

// If element is too smal, increase excess pixels by the difference
// and mark that it has no pixels to spare
if (pixelSize < elementMinSize) {
excessPixels += (elementMinSize - pixelSize);
toSpare.push(0);
return elementMinSize
}

// Otherwise, mark the pixels it has to spare and return it's original size
toSpare.push(pixelSize - elementMinSize);
return pixelSize
});

// If nothing was adjusted, return the original sizes
if (excessPixels === 0) {
return sizesToTrim
}

return pixelSizes.map(function (pixelSize, i) {
var newPixelSize = pixelSize;

// While there's still pixels to take, and there's enough pixels to spare,
// take as many as possible up to the total excess pixels
if ((excessPixels > 0) && (toSpare[i] - excessPixels) > 0) {
var takenPixels = Math.min(excessPixels, (toSpare[i] - excessPixels));

// Subtract the amount taken for the next iteration
excessPixels -= takenPixels;
newPixelSize = pixelSize - takenPixels;
}

// Return the pixel size adjusted as a percentage
return (newPixelSize / parent[clientSize]) * 100
})
}

// stopDragging is very similar to startDragging in reverse.
function stopDragging () {
var self = this;
Expand Down Expand Up @@ -441,6 +501,9 @@
self.dragOffset = getMousePosition(e) - self.end;
}

// adjust sizes to ensure percentage is within min size and gutter.
sizes = trimToMin(sizes);

// 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
Expand Down Expand Up @@ -557,13 +620,15 @@
});

function setSizes (newSizes) {
newSizes.forEach(function (newSize, i) {
var trimmed = trimToMin(newSizes);
trimmed.forEach(function (newSize, i) {
if (i > 0) {
var pair = pairs[i - 1];

var a = elements[pair.a];
var b = elements[pair.b];

a.size = newSizes[i - 1];
a.size = trimmed[i - 1];
b.size = newSize;

setElementSize(a.element, a.size, pair[aGutterSize]);
Expand Down
Loading

0 comments on commit ca044c7

Please sign in to comment.