mirror of
https://github.com/chinchang/web-maker.git
synced 2025-08-01 11:00:28 +02:00
WIP
This commit is contained in:
@@ -48,6 +48,9 @@
|
|||||||
top: 5px;
|
top: 5px;
|
||||||
margin-left: 7px;
|
margin-left: 7px;
|
||||||
}
|
}
|
||||||
|
a > svg {
|
||||||
|
fill: rgba(255, 255, 255, 0.2)
|
||||||
|
}
|
||||||
input[type="text"] {
|
input[type="text"] {
|
||||||
padding: 3px 5px;
|
padding: 3px 5px;
|
||||||
font-size: inherit;
|
font-size: inherit;
|
||||||
@@ -107,10 +110,13 @@
|
|||||||
height: 33%;
|
height: 33%;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
transition: height 0.30s ease;
|
||||||
|
will-change: height;
|
||||||
/*animation: pop-in 0.4s cubic-bezier(.71,1.7,.77,1.24) forwards 0.2s;*/
|
/*animation: pop-in 0.4s cubic-bezier(.71,1.7,.77,1.24) forwards 0.2s;*/
|
||||||
/*animation: pop-in 0.4s ease forwards 0.2s;*/
|
/*animation: pop-in 0.4s ease forwards 0.2s;*/
|
||||||
/*opacity: 0;*/
|
/*opacity: 0;*/
|
||||||
}
|
}
|
||||||
|
.code-wrap.is-dragging
|
||||||
.layout-2 .code-wrap {
|
.layout-2 .code-wrap {
|
||||||
height: auto;
|
height: auto;
|
||||||
width: 33%;
|
width: 33%;
|
||||||
@@ -123,6 +129,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.code-wrap__header {
|
.code-wrap__header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
padding: 5px 20px;
|
padding: 5px 20px;
|
||||||
background: rgba(0,0,0,0.55);
|
background: rgba(0,0,0,0.55);
|
||||||
color: #888;
|
color: #888;
|
||||||
@@ -220,6 +229,7 @@
|
|||||||
}
|
}
|
||||||
.gutter {
|
.gutter {
|
||||||
background: rgba(0,0,0,0.2);
|
background: rgba(0,0,0,0.2);
|
||||||
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
.gutter-horizontal {
|
.gutter-horizontal {
|
||||||
cursor: ew-resize;
|
cursor: ew-resize;
|
||||||
@@ -502,6 +512,13 @@
|
|||||||
<li><a data-type="html" data-mode="jade">Jade</a></li>
|
<li><a data-type="html" data-mode="jade">Jade</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="code-wrap__header-right-options">
|
||||||
|
<a data-collapse-id="0" class="js-code-collapse-btn">
|
||||||
|
<svg style="width:18px;height:18px" viewBox="0 0 24 24">
|
||||||
|
<path d="M19.5,3.09L15,7.59V4H13V11H20V9H16.41L20.91,4.5L19.5,3.09M4,13V15H7.59L3.09,19.5L4.5,20.91L9,16.41V20H11V13H4Z" />
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="js-css-code" data-type="css" class="code-wrap">
|
<div id="js-css-code" data-type="css" class="code-wrap">
|
||||||
@@ -514,6 +531,13 @@
|
|||||||
<li><a data-type="css" data-mode="less">LESS</a></li>
|
<li><a data-type="css" data-mode="less">LESS</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="code-wrap__header-right-options">
|
||||||
|
<a data-collapse-id="1" class="js-code-collapse-btn">
|
||||||
|
<svg style="width:18px;height:18px" viewBox="0 0 24 24">
|
||||||
|
<path d="M19.5,3.09L15,7.59V4H13V11H20V9H16.41L20.91,4.5L19.5,3.09M4,13V15H7.59L3.09,19.5L4.5,20.91L9,16.41V20H11V13H4Z" />
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="js-js-code" data-type="js" class="code-wrap">
|
<div id="js-js-code" data-type="js" class="code-wrap">
|
||||||
@@ -526,6 +550,13 @@
|
|||||||
<li><a data-type="js" data-mode="es6">ES6 (Babel)</a></li>
|
<li><a data-type="js" data-mode="es6">ES6 (Babel)</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="code-wrap__header-right-options">
|
||||||
|
<a data-collapse-id="2" class="js-code-collapse-btn">
|
||||||
|
<svg style="width:18px;height:18px" viewBox="0 0 24 24">
|
||||||
|
<path d="M19.5,3.09L15,7.59V4H13V11H20V9H16.41L20.91,4.5L19.5,3.09M4,13V15H7.59L3.09,19.5L4.5,20.91L9,16.41V20H11V13H4Z" />
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
316
src/lib/split.js
316
src/lib/split.js
@@ -1,15 +1,39 @@
|
|||||||
|
// The programming goals of Split.js are to deliver readable, understandable and
|
||||||
|
// maintainable code, while at the same time manually optimizing for tiny minified file size,
|
||||||
|
// browser compatibility without additional requirements, graceful fallback (IE8 is supported)
|
||||||
|
// and very few assumptions about the user's page layout.
|
||||||
|
//
|
||||||
|
// Make sure all browsers handle this JS library correctly with ES5.
|
||||||
|
// More information here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
// A wrapper function that does a couple things:
|
||||||
|
//
|
||||||
|
// 1. Doesn't pollute the global namespace. This is important for a library.
|
||||||
|
// 2. Allows us to mount the library in different module systems, as well as
|
||||||
|
// directly in the browser.
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
// Save the global `this` for use later. In this case, since the library only
|
||||||
|
// runs in the browser, it will refer to `window`. Also, figure out if we're in IE8
|
||||||
|
// or not. IE8 will still render correctly, but will be static instead of draggable.
|
||||||
|
//
|
||||||
|
// Save a couple long function names that are used frequently.
|
||||||
|
// This optimization saves around 400 bytes.
|
||||||
var global = this
|
var global = this
|
||||||
|
, isIE8 = global.attachEvent && !global[addEventListener]
|
||||||
|
, document = global.document
|
||||||
, addEventListener = 'addEventListener'
|
, addEventListener = 'addEventListener'
|
||||||
, removeEventListener = 'removeEventListener'
|
, removeEventListener = 'removeEventListener'
|
||||||
, getBoundingClientRect = 'getBoundingClientRect'
|
, getBoundingClientRect = 'getBoundingClientRect'
|
||||||
, isIE8 = global.attachEvent && !global[addEventListener]
|
|
||||||
, document = global.document
|
|
||||||
|
|
||||||
|
// This library only needs two helper functions:
|
||||||
|
//
|
||||||
|
// The first determines which prefixes of CSS calc we need.
|
||||||
|
// We only need to do this once on startup, when this anonymous function is called.
|
||||||
|
//
|
||||||
|
// Tests -webkit, -moz and -o prefixes. Modified from StackOverflow:
|
||||||
|
// http://stackoverflow.com/questions/16625140/js-feature-detection-to-detect-the-usage-of-webkit-calc-over-calc/16625167#16625167
|
||||||
, calc = (function () {
|
, calc = (function () {
|
||||||
var el
|
var el
|
||||||
, prefixes = ["", "-webkit-", "-moz-", "-o-"]
|
, prefixes = ["", "-webkit-", "-moz-", "-o-"]
|
||||||
@@ -23,6 +47,10 @@ var global = this
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
|
|
||||||
|
// The second helper function allows elements and string selectors to be used
|
||||||
|
// interchangeably. In either case an element is returned. This allows us to
|
||||||
|
// do `Split(elem1, elem2)` as well as `Split('#id1', '#id2')`.
|
||||||
, elementOrSelector = function (el) {
|
, elementOrSelector = function (el) {
|
||||||
if (typeof el === 'string' || el instanceof String) {
|
if (typeof el === 'string' || el instanceof String) {
|
||||||
return document.querySelector(el)
|
return document.querySelector(el)
|
||||||
@@ -31,6 +59,38 @@ var global = this
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The main function to initialize a split. Split.js thinks about each pair
|
||||||
|
// of elements as an independant pair. Dragging the gutter between two elements
|
||||||
|
// only changes the dimensions of elements in that pair. This is key to understanding
|
||||||
|
// how the following functions operate, since each function is bound to a pair.
|
||||||
|
//
|
||||||
|
// A pair object is shaped like this:
|
||||||
|
//
|
||||||
|
// {
|
||||||
|
// a: DOM element,
|
||||||
|
// b: DOM element,
|
||||||
|
// aMin: Number,
|
||||||
|
// bMin: Number,
|
||||||
|
// dragging: Boolean,
|
||||||
|
// parent: DOM element,
|
||||||
|
// isFirst: Boolean,
|
||||||
|
// isLast: Boolean,
|
||||||
|
// direction: 'horizontal' | 'vertical'
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// The basic sequence:
|
||||||
|
//
|
||||||
|
// 1. Set defaults to something sane. `options` doesn't have to be passed at all.
|
||||||
|
// 2. Initialize a bunch of strings based on the direction we're splitting.
|
||||||
|
// A lot of the behavior in the rest of the library is paramatized down to
|
||||||
|
// rely on CSS strings and classes.
|
||||||
|
// 3. Define the dragging helper functions, and a few helpers to go with them.
|
||||||
|
// 4. Define a few more functions that "balance" the entire split instance.
|
||||||
|
// Split.js tries it's best to cope with min sizes that don't add up.
|
||||||
|
// 5. Loop through the elements while pairing them off. Every pair gets an
|
||||||
|
// `pair` object, a gutter, and special isFirst/isLast properties.
|
||||||
|
// 6. Actually size the pair elements, insert gutters and attach event listeners.
|
||||||
|
// 7. Balance all of the pairs to accomodate min sizes as best as possible.
|
||||||
, Split = function (ids, options) {
|
, Split = function (ids, options) {
|
||||||
var dimension
|
var dimension
|
||||||
, i
|
, i
|
||||||
@@ -42,8 +102,9 @@ var global = this
|
|||||||
, paddingB
|
, paddingB
|
||||||
, pairs = []
|
, pairs = []
|
||||||
|
|
||||||
// Set defaults
|
// 1. Set defaults to something sane. `options` doesn't have to be passed at all,
|
||||||
|
// so create an options object if none exists. Pixel values 10, 100 and 30 are
|
||||||
|
// arbitrary but feel natural.
|
||||||
options = typeof options !== 'undefined' ? options : {}
|
options = typeof options !== 'undefined' ? options : {}
|
||||||
|
|
||||||
if (typeof options.gutterSize === 'undefined') options.gutterSize = 10
|
if (typeof options.gutterSize === 'undefined') options.gutterSize = 10
|
||||||
@@ -51,6 +112,9 @@ var global = this
|
|||||||
if (typeof options.snapOffset === 'undefined') options.snapOffset = 30
|
if (typeof options.snapOffset === 'undefined') options.snapOffset = 30
|
||||||
if (typeof options.direction === 'undefined') options.direction = 'horizontal'
|
if (typeof options.direction === 'undefined') options.direction = 'horizontal'
|
||||||
|
|
||||||
|
// 2. Initialize a bunch of strings based on the direction we're splitting.
|
||||||
|
// A lot of the behavior in the rest of the library is paramatized down to
|
||||||
|
// rely on CSS strings and classes.
|
||||||
if (options.direction == 'horizontal') {
|
if (options.direction == 'horizontal') {
|
||||||
dimension = 'width'
|
dimension = 'width'
|
||||||
clientDimension = 'clientWidth'
|
clientDimension = 'clientWidth'
|
||||||
@@ -71,25 +135,43 @@ var global = this
|
|||||||
if (!options.cursor) options.cursor = 'ns-resize'
|
if (!options.cursor) options.cursor = 'ns-resize'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event listeners for drag events, bound to a pair object.
|
// 3. Define the dragging helper functions, and a few helpers to go with them.
|
||||||
// Calculate the pair's position and size when dragging starts.
|
// Each helper is bound to a pair object that contains it's metadata. This
|
||||||
// Prevent selection on start and re-enable it when done.
|
// also makes it easy to store references to listeners that that will be
|
||||||
|
// added and removed.
|
||||||
|
//
|
||||||
|
// Even though there are no other functions contained in them, aliasing
|
||||||
|
// this to self saves 50 bytes or so since it's used so frequently.
|
||||||
|
//
|
||||||
|
// The pair object saves metadata like dragging state, position and
|
||||||
|
// event listener references.
|
||||||
|
//
|
||||||
|
// startDragging calls `calculateSizes` to store the inital size in the pair object.
|
||||||
|
// It also adds event listeners for mouse/touch events,
|
||||||
|
// and prevents selection while dragging so avoid the selecting text.
|
||||||
var startDragging = function (e) {
|
var startDragging = function (e) {
|
||||||
|
// Alias frequently used variables to save space. 200 bytes.
|
||||||
var self = this
|
var self = this
|
||||||
, a = self.a
|
, a = self.a
|
||||||
, b = self.b
|
, b = self.b
|
||||||
|
|
||||||
|
// Call the onDragStart callback.
|
||||||
if (!self.dragging && options.onDragStart) {
|
if (!self.dragging && options.onDragStart) {
|
||||||
options.onDragStart()
|
options.onDragStart()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't actually drag the element. We emulate that in the drag function.
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
|
// Set the dragging property of the pair object.
|
||||||
self.dragging = true
|
self.dragging = true
|
||||||
|
|
||||||
|
// Create two event listeners bound to the same pair object and store
|
||||||
|
// them in the pair object.
|
||||||
self.move = drag.bind(self)
|
self.move = drag.bind(self)
|
||||||
self.stop = stopDragging.bind(self)
|
self.stop = stopDragging.bind(self)
|
||||||
|
|
||||||
|
// All the binding. `window` gets the stop events in case we drag out of the elements.
|
||||||
global[addEventListener]('mouseup', self.stop)
|
global[addEventListener]('mouseup', self.stop)
|
||||||
global[addEventListener]('touchend', self.stop)
|
global[addEventListener]('touchend', self.stop)
|
||||||
global[addEventListener]('touchcancel', self.stop)
|
global[addEventListener]('touchcancel', self.stop)
|
||||||
@@ -97,10 +179,11 @@ var global = this
|
|||||||
self.parent[addEventListener]('mousemove', self.move)
|
self.parent[addEventListener]('mousemove', self.move)
|
||||||
self.parent[addEventListener]('touchmove', self.move)
|
self.parent[addEventListener]('touchmove', self.move)
|
||||||
|
|
||||||
a[addEventListener]('selectstart', preventSelection)
|
// Disable selection. Disable!
|
||||||
a[addEventListener]('dragstart', preventSelection)
|
a[addEventListener]('selectstart', noop)
|
||||||
b[addEventListener]('selectstart', preventSelection)
|
a[addEventListener]('dragstart', noop)
|
||||||
b[addEventListener]('dragstart', preventSelection)
|
b[addEventListener]('selectstart', noop)
|
||||||
|
b[addEventListener]('dragstart', noop)
|
||||||
|
|
||||||
a.style.userSelect = 'none'
|
a.style.userSelect = 'none'
|
||||||
a.style.webkitUserSelect = 'none'
|
a.style.webkitUserSelect = 'none'
|
||||||
@@ -112,11 +195,16 @@ var global = this
|
|||||||
b.style.MozUserSelect = 'none'
|
b.style.MozUserSelect = 'none'
|
||||||
b.style.pointerEvents = 'none'
|
b.style.pointerEvents = 'none'
|
||||||
|
|
||||||
|
// Set the cursor, both on the gutter and the parent element.
|
||||||
|
// Doing only a, b and gutter causes flickering.
|
||||||
self.gutter.style.cursor = options.cursor
|
self.gutter.style.cursor = options.cursor
|
||||||
self.parent.style.cursor = options.cursor
|
self.parent.style.cursor = options.cursor
|
||||||
|
|
||||||
|
// Cache the initial sizes of the pair.
|
||||||
calculateSizes.call(self)
|
calculateSizes.call(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stopDragging is very similar to startDragging in reverse.
|
||||||
, stopDragging = function () {
|
, stopDragging = function () {
|
||||||
var self = this
|
var self = this
|
||||||
, a = self.a
|
, a = self.a
|
||||||
@@ -128,6 +216,7 @@ var global = this
|
|||||||
|
|
||||||
self.dragging = false
|
self.dragging = false
|
||||||
|
|
||||||
|
// Remove the stored event listeners. This is why we store them.
|
||||||
global[removeEventListener]('mouseup', self.stop)
|
global[removeEventListener]('mouseup', self.stop)
|
||||||
global[removeEventListener]('touchend', self.stop)
|
global[removeEventListener]('touchend', self.stop)
|
||||||
global[removeEventListener]('touchcancel', self.stop)
|
global[removeEventListener]('touchcancel', self.stop)
|
||||||
@@ -135,13 +224,15 @@ var global = this
|
|||||||
self.parent[removeEventListener]('mousemove', self.move)
|
self.parent[removeEventListener]('mousemove', self.move)
|
||||||
self.parent[removeEventListener]('touchmove', self.move)
|
self.parent[removeEventListener]('touchmove', self.move)
|
||||||
|
|
||||||
|
// Delete them once they are removed. I think this makes a difference
|
||||||
|
// in memory usage with a lot of splits on one page. But I don't know for sure.
|
||||||
delete self.stop
|
delete self.stop
|
||||||
delete self.move
|
delete self.move
|
||||||
|
|
||||||
a[removeEventListener]('selectstart', preventSelection)
|
a[removeEventListener]('selectstart', noop)
|
||||||
a[removeEventListener]('dragstart', preventSelection)
|
a[removeEventListener]('dragstart', noop)
|
||||||
b[removeEventListener]('selectstart', preventSelection)
|
b[removeEventListener]('selectstart', noop)
|
||||||
b[removeEventListener]('dragstart', preventSelection)
|
b[removeEventListener]('dragstart', noop)
|
||||||
|
|
||||||
a.style.userSelect = ''
|
a.style.userSelect = ''
|
||||||
a.style.webkitUserSelect = ''
|
a.style.webkitUserSelect = ''
|
||||||
@@ -156,36 +247,70 @@ var global = this
|
|||||||
self.gutter.style.cursor = ''
|
self.gutter.style.cursor = ''
|
||||||
self.parent.style.cursor = ''
|
self.parent.style.cursor = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// drag, where all the magic happens. The logic is really quite simple:
|
||||||
|
//
|
||||||
|
// 1. Ignore if the pair is not dragging.
|
||||||
|
// 2. Get the offset of the event.
|
||||||
|
// 3. Snap offset to min if within snappable range (within min + snapOffset).
|
||||||
|
// 4. Actually adjust each element in the pair to offset.
|
||||||
|
//
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
// | | <- this.aMin || this.bMin -> | |
|
||||||
|
// | | | <- this.snapOffset || this.snapOffset -> | | |
|
||||||
|
// | | | || | | |
|
||||||
|
// | | | || | | |
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
// | <- this.start this.size -> |
|
||||||
, drag = function (e) {
|
, drag = function (e) {
|
||||||
var offset
|
var offset
|
||||||
|
|
||||||
if (!this.dragging) return
|
if (!this.dragging) return
|
||||||
|
|
||||||
// Get the relative position of the event from the first side of the
|
// Get the offset of the event from the first side of the
|
||||||
// pair.
|
// pair `this.start`. Supports touch events, but not multitouch, so only the first
|
||||||
|
// finger `touches[0]` is counted.
|
||||||
if ('touches' in e) {
|
if ('touches' in e) {
|
||||||
offset = e.touches[0][clientAxis] - this.start
|
offset = e.touches[0][clientAxis] - this.start
|
||||||
} else {
|
} else {
|
||||||
offset = e[clientAxis] - this.start
|
offset = e[clientAxis] - this.start
|
||||||
}
|
}
|
||||||
|
|
||||||
// If within snapOffset of min or max, set offset to min or max
|
// If within snapOffset of min or max, set offset to min or max.
|
||||||
|
// snapOffset buffers aMin and bMin, so logic is opposite for both.
|
||||||
if (offset <= this.aMin + options.snapOffset) {
|
// Include the appropriate gutter sizes to prevent overflows.
|
||||||
offset = this.aMin
|
if (offset <= this.aMin + options.snapOffset + this.aGutterSize) {
|
||||||
} else if (offset >= this.size - this.bMin - options.snapOffset) {
|
offset = this.aMin + this.aGutterSize
|
||||||
offset = this.size - this.bMin
|
} else if (offset >= this.size - (this.bMin + options.snapOffset + this.bGutterSize)) {
|
||||||
|
offset = this.size - (this.bMin + this.bGutterSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actually adjust the size.
|
||||||
adjust.call(this, offset)
|
adjust.call(this, offset)
|
||||||
|
|
||||||
|
// Call the drag callback continously. Don't do anything too intensive
|
||||||
|
// in this callback.
|
||||||
if (options.onDrag) {
|
if (options.onDrag) {
|
||||||
options.onDrag()
|
options.onDrag()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cache some important sizes when drag starts, so we don't have to do that
|
||||||
|
// continously:
|
||||||
|
//
|
||||||
|
// `size`: The total size of the pair. First element + second element + first gutter + second gutter.
|
||||||
|
// `percentage`: The percentage between 0-100 that the pair occupies in the parent.
|
||||||
|
// `start`: The leading side of the first element.
|
||||||
|
//
|
||||||
|
// ------------------------------------------------ - - - - - - - - - - -
|
||||||
|
// | aGutterSize -> ||| | |
|
||||||
|
// | ||| | |
|
||||||
|
// | ||| | |
|
||||||
|
// | ||| <- bGutterSize | |
|
||||||
|
// ------------------------------------------------ - - - - - - - - - - -
|
||||||
|
// | <- start size -> | parentSize -> |
|
||||||
, calculateSizes = function () {
|
, calculateSizes = function () {
|
||||||
// Calculate the pairs size, and percentage of the parent size
|
// Figure out the parent size minus padding.
|
||||||
var computedStyle = global.getComputedStyle(this.parent)
|
var computedStyle = global.getComputedStyle(this.parent)
|
||||||
, parentSize = this.parent[clientDimension] - parseFloat(computedStyle[paddingA]) - parseFloat(computedStyle[paddingB])
|
, parentSize = this.parent[clientDimension] - parseFloat(computedStyle[paddingA]) - parseFloat(computedStyle[paddingB])
|
||||||
|
|
||||||
@@ -193,13 +318,21 @@ var global = this
|
|||||||
this.percentage = Math.min(this.size / parentSize * 100, 100)
|
this.percentage = Math.min(this.size / parentSize * 100, 100)
|
||||||
this.start = this.a[getBoundingClientRect]()[position]
|
this.start = this.a[getBoundingClientRect]()[position]
|
||||||
}
|
}
|
||||||
, adjust = function (offset) {
|
|
||||||
// A size is the same as offset. B size is total size - A size.
|
|
||||||
// Both sizes are calculated from the initial parent percentage.
|
|
||||||
|
|
||||||
|
// Actually adjust the size of elements `a` and `b` to `offset` while dragging.
|
||||||
|
// calc is used to allow calc(percentage + gutterpx) on the whole split instance,
|
||||||
|
// which allows the viewport to be resized without additional logic.
|
||||||
|
// Element a's size is the same as offset. b's size is total size - a size.
|
||||||
|
// Both sizes are calculated from the initial parent percentage, then the gutter size is subtracted.
|
||||||
|
, adjust = function (offset) {
|
||||||
this.a.style[dimension] = calc + '(' + (offset / this.size * this.percentage) + '% - ' + this.aGutterSize + 'px)'
|
this.a.style[dimension] = calc + '(' + (offset / this.size * this.percentage) + '% - ' + this.aGutterSize + 'px)'
|
||||||
this.b.style[dimension] = calc + '(' + (this.percentage - (offset / this.size * this.percentage)) + '% - ' + this.bGutterSize + 'px)'
|
this.b.style[dimension] = calc + '(' + (this.percentage - (offset / this.size * this.percentage)) + '% - ' + this.bGutterSize + 'px)'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 4. Define a few more functions that "balance" the entire split instance.
|
||||||
|
// Split.js tries it's best to cope with min sizes that don't add up.
|
||||||
|
// At some point this should go away since it breaks out of the calc(% - px) model.
|
||||||
|
// Maybe it's a user error if you pass uncomputable minSizes.
|
||||||
, fitMin = function () {
|
, fitMin = function () {
|
||||||
var self = this
|
var self = this
|
||||||
, a = self.a
|
, a = self.a
|
||||||
@@ -237,9 +370,31 @@ var global = this
|
|||||||
fitMinReverse.call(pairs[i])
|
fitMinReverse.call(pairs[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
, preventSelection = function () { return false }
|
, setElementSize = function (el, size, gutterSize) {
|
||||||
|
// Split.js allows setting sizes via numbers (ideally), or if you must,
|
||||||
|
// by string, like '300px'. This is less than ideal, because it breaks
|
||||||
|
// the fluid layout that `calc(% - px)` provides. You're on your own if you do that,
|
||||||
|
// make sure you calculate the gutter size by hand.
|
||||||
|
if (typeof size !== 'string' && !(size instanceof String)) {
|
||||||
|
if (!isIE8) {
|
||||||
|
size = calc + '(' + size + '% - ' + gutterSize + 'px)'
|
||||||
|
} else {
|
||||||
|
size = options.sizes[i] + '%'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
el.style[dimension] = size
|
||||||
|
}
|
||||||
|
|
||||||
|
// No-op function to prevent default. Used to prevent selection.
|
||||||
|
, noop = function () { return false }
|
||||||
|
|
||||||
|
// All DOM elements in the split should have a common parent. We can grab
|
||||||
|
// the first elements parent and hope users read the docs because the
|
||||||
|
// behavior will be whacky otherwise.
|
||||||
, parent = elementOrSelector(ids[0]).parentNode
|
, parent = elementOrSelector(ids[0]).parentNode
|
||||||
|
|
||||||
|
// Set default options.sizes to equal percentages of the parent element.
|
||||||
if (!options.sizes) {
|
if (!options.sizes) {
|
||||||
var percent = 100 / ids.length
|
var percent = 100 / ids.length
|
||||||
|
|
||||||
@@ -250,6 +405,8 @@ var global = this
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Standardize minSize to an array if it isn't already. This allows minSize
|
||||||
|
// to be passed as a number.
|
||||||
if (!Array.isArray(options.minSize)) {
|
if (!Array.isArray(options.minSize)) {
|
||||||
var minSizes = []
|
var minSizes = []
|
||||||
|
|
||||||
@@ -260,17 +417,36 @@ var global = this
|
|||||||
options.minSize = minSizes
|
options.minSize = minSizes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 5. Loop through the elements while pairing them off. Every pair gets a
|
||||||
|
// `pair` object, a gutter, and isFirst/isLast properties.
|
||||||
|
//
|
||||||
|
// Basic logic:
|
||||||
|
//
|
||||||
|
// - Starting with the second element `i > 0`, create `pair` objects with
|
||||||
|
// `a = ids[i - 1]` and `b = ids[i]`
|
||||||
|
// - Set gutter sizes based on the _pair_ being first/last. The first and last
|
||||||
|
// pair have gutterSize / 2, since they only have one half gutter, and not two.
|
||||||
|
// - Create gutter elements and add event listeners.
|
||||||
|
// - Set the size of the elements, minus the gutter sizes.
|
||||||
|
//
|
||||||
|
// -----------------------------------------------------------------------
|
||||||
|
// | i=0 | i=1 | i=2 | i=3 |
|
||||||
|
// | | isFirst | | isLast |
|
||||||
|
// | pair 0 pair 1 pair 2 |
|
||||||
|
// | | | | |
|
||||||
|
// -----------------------------------------------------------------------
|
||||||
for (i = 0; i < ids.length; i++) {
|
for (i = 0; i < ids.length; i++) {
|
||||||
var el = elementOrSelector(ids[i])
|
var el = elementOrSelector(ids[i])
|
||||||
, isFirst = (i == 1)
|
, isFirstPair = (i == 1)
|
||||||
, isLast = (i == ids.length - 1)
|
, isLastPair = (i == ids.length - 1)
|
||||||
, size
|
, size = options.sizes[i]
|
||||||
, gutterSize = options.gutterSize
|
, gutterSize = options.gutterSize
|
||||||
, pair
|
, pair
|
||||||
, parentFlexDirection = window.getComputedStyle(parent).flexDirection
|
, parentFlexDirection = window.getComputedStyle(parent).flexDirection
|
||||||
, temp
|
, temp
|
||||||
|
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
|
// Create the pair object with it's metadata.
|
||||||
pair = {
|
pair = {
|
||||||
a: elementOrSelector(ids[i - 1]),
|
a: elementOrSelector(ids[i - 1]),
|
||||||
b: el,
|
b: el,
|
||||||
@@ -278,21 +454,20 @@ var global = this
|
|||||||
bMin: options.minSize[i],
|
bMin: options.minSize[i],
|
||||||
dragging: false,
|
dragging: false,
|
||||||
parent: parent,
|
parent: parent,
|
||||||
isFirst: isFirst,
|
isFirst: isFirstPair,
|
||||||
isLast: isLast,
|
isLast: isLastPair,
|
||||||
direction: options.direction
|
direction: options.direction
|
||||||
}
|
}
|
||||||
|
|
||||||
// For first and last pairs, first and last gutter width is half.
|
// For first and last pairs, first and last gutter width is half.
|
||||||
|
|
||||||
pair.aGutterSize = options.gutterSize
|
pair.aGutterSize = options.gutterSize
|
||||||
pair.bGutterSize = options.gutterSize
|
pair.bGutterSize = options.gutterSize
|
||||||
|
|
||||||
if (isFirst) {
|
if (isFirstPair) {
|
||||||
pair.aGutterSize = options.gutterSize / 2
|
pair.aGutterSize = options.gutterSize / 2
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLast) {
|
if (isLastPair) {
|
||||||
pair.bGutterSize = options.gutterSize / 2
|
pair.bGutterSize = options.gutterSize / 2
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,8 +479,13 @@ var global = this
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine the size of the current element. IE8 is supported by
|
||||||
|
// staticly assigning sizes without draggable gutters. Assigns a string
|
||||||
|
// to `size`.
|
||||||
|
//
|
||||||
// IE9 and above
|
// IE9 and above
|
||||||
if (!isIE8) {
|
if (!isIE8) {
|
||||||
|
// Create gutter elements for each pair.
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
var gutter = document.createElement('div')
|
var gutter = document.createElement('div')
|
||||||
|
|
||||||
@@ -320,35 +500,62 @@ var global = this
|
|||||||
pair.gutter = gutter
|
pair.gutter = gutter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Half-size gutters for first and last elements.
|
||||||
if (i === 0 || i == ids.length - 1) {
|
if (i === 0 || i == ids.length - 1) {
|
||||||
gutterSize = options.gutterSize / 2
|
gutterSize = options.gutterSize / 2
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof options.sizes[i] === 'string' || options.sizes[i] instanceof String) {
|
|
||||||
size = options.sizes[i]
|
|
||||||
} else {
|
|
||||||
size = calc + '(' + options.sizes[i] + '% - ' + gutterSize + 'px)'
|
|
||||||
}
|
|
||||||
|
|
||||||
// IE8 and below
|
|
||||||
} else {
|
|
||||||
if (typeof options.sizes[i] === 'string' || options.sizes[i] instanceof String) {
|
|
||||||
size = options.sizes[i]
|
|
||||||
} else {
|
|
||||||
size = options.sizes[i] + '%'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
el.style[dimension] = size
|
// Set the element size to our determined size.
|
||||||
|
setElementSize(el, size, gutterSize)
|
||||||
|
|
||||||
|
// After the first iteration, and we have a pair object, append it to the
|
||||||
|
// list of pairs.
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
pairs.push(pair)
|
pairs.push(pair)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Balance the pairs to try to accomodate min sizes.
|
||||||
balancePairs(pairs)
|
balancePairs(pairs)
|
||||||
|
|
||||||
|
return {
|
||||||
|
setSizes: function (sizes) {
|
||||||
|
for (var i = 0; i < sizes.length; i++) {
|
||||||
|
if (i > 0) {
|
||||||
|
var pair = pairs[i - 1]
|
||||||
|
|
||||||
|
setElementSize(pair.a, sizes[i - 1], pair.aGutterSize)
|
||||||
|
setElementSize(pair.b, sizes[i], pair.bGutterSize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
collapse: function (i) {
|
||||||
|
var pair
|
||||||
|
|
||||||
|
if (i === pairs.length) {
|
||||||
|
pair = pairs[i - 1]
|
||||||
|
|
||||||
|
calculateSizes.call(pair)
|
||||||
|
adjust.call(pair, pair.size - pair.bGutterSize)
|
||||||
|
} else {
|
||||||
|
pair = pairs[i]
|
||||||
|
|
||||||
|
calculateSizes.call(pair)
|
||||||
|
adjust.call(pair, pair.aMin)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
destroy: function () {
|
||||||
|
for (var i = 0; i < pairs.length; i++) {
|
||||||
|
pairs[i].parent.removeChild(pairs[i].gutter)
|
||||||
|
pairs[i].a.style[dimension] = ''
|
||||||
|
pairs[i].b.style[dimension] = ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Play nicely with module systems, and the browser too if you include it raw.
|
||||||
if (typeof exports !== 'undefined') {
|
if (typeof exports !== 'undefined') {
|
||||||
if (typeof module !== 'undefined' && module.exports) {
|
if (typeof module !== 'undefined' && module.exports) {
|
||||||
exports = module.exports = Split
|
exports = module.exports = Split
|
||||||
@@ -358,4 +565,5 @@ if (typeof exports !== 'undefined') {
|
|||||||
global.Split = Split
|
global.Split = Split
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Call our wrapper function with the current global. In this case, `window`.
|
||||||
}).call(window);
|
}).call(window);
|
||||||
|
@@ -43,6 +43,8 @@
|
|||||||
, sass
|
, sass
|
||||||
, currentItem
|
, currentItem
|
||||||
, savedItems
|
, savedItems
|
||||||
|
, minCodeWrapSize = 33
|
||||||
|
, splitInstance
|
||||||
// TODO: for legacy reasons when. Will be refactored as global preferences.
|
// TODO: for legacy reasons when. Will be refactored as global preferences.
|
||||||
, prefs = {}
|
, prefs = {}
|
||||||
|
|
||||||
@@ -88,9 +90,9 @@
|
|||||||
$('#js-code-side').setAttribute('style', '');
|
$('#js-code-side').setAttribute('style', '');
|
||||||
$('#js-demo-side').setAttribute('style', '');
|
$('#js-demo-side').setAttribute('style', '');
|
||||||
|
|
||||||
Split(['#js-html-code', '#js-css-code', '#js-js-code'], {
|
splitInstance = Split(['#js-html-code', '#js-css-code', '#js-js-code'], {
|
||||||
direction: (currentLayoutMode === 2 ? 'horizontal' : 'vertical'),
|
direction: (currentLayoutMode === 2 ? 'horizontal' : 'vertical'),
|
||||||
minSize: 34,
|
minSize: minCodeWrapSize,
|
||||||
gutterSize: 6
|
gutterSize: 6
|
||||||
});
|
});
|
||||||
Split(['#js-code-side', '#js-demo-side' ], {
|
Split(['#js-code-side', '#js-demo-side' ], {
|
||||||
@@ -595,6 +597,27 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Collapse btn event listeners
|
||||||
|
var collapseBtns = [].slice.call($all('.js-code-collapse-btn'));
|
||||||
|
collapseBtns.forEach(function (btn) {
|
||||||
|
btn.addEventListener('click', function (e) {
|
||||||
|
if (e.currentTarget.classList.contains('is-minimized')) {
|
||||||
|
e.currentTarget.classList.remove('is-minimized');
|
||||||
|
splitInstance.setSizes([ 33.3, 33.3, 33.3 ]);
|
||||||
|
} else {
|
||||||
|
splitInstance.collapse(e.currentTarget.dataset.collapseId);
|
||||||
|
e.currentTarget.classList.add('is-minimized');
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
/*Split(['#js-html-code', '#js-css-code', '#js-js-code'], {
|
||||||
|
direction: (currentLayoutMode === 2 ? 'horizontal' : 'vertical'),
|
||||||
|
minSize: 34,
|
||||||
|
gutterSize: 6
|
||||||
|
});*/
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
window.addEventListener('keydown', function (event) {
|
window.addEventListener('keydown', function (event) {
|
||||||
if ((event.ctrlKey || event.metaKey) && (event.keyCode === 83)){
|
if ((event.ctrlKey || event.metaKey) && (event.keyCode === 83)){
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
Reference in New Issue
Block a user