another example of jquery.gridSplit

by Graham Dixon

HTML

<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script src="https://rawgit.com/assetinfo/jquery.gridSplit/master/dist/jquery.gridsplit.js"></script>
<div id="grid1" class="grid" style="width:600px;height:400px"></div>
<br>
<button id="type1">Variant 1</button>
<button id="btnSplitV">Split V</button>
<button id="btnSplitH">Split H</button>
<button id="type2">Split 2/2</button>
<button id="type3">Reset</button>
<button id="show">Show</button>

CSS

body,
html {
  height: 100%;
  margin: 0;
}

*,
*:after {
  box-sizing: border-box;
}

.grid {
  padding-top: 0px;
  height: 25%;
  background: #bdbdbd;
  overflow: hidden;
  box-sizing: border-box;
}

.innerGrid {
  height: 100%;
  overflow: hidden;
  display: none;
}

.gridColumn {
  position: relative;
  left: 0px;
  height: 100%;
}

.gridCell {
  border: 1px solid #bdbdbd;
  height: 100%;
  display: block;
  background: #f7f7f7;
  -webkit-box-shadow: inset 0 0 2px #000;
  padding: 2px;
}

.gridCell .fillCell {
  height: 100%;
  display: block;
}

.gridCell:after {
  content: ' ';
  border: 1px dashed rgba(190, 190, 190, 0.3);
  width: 100%;
  height: 100%;
  display: block;
}

.gridCell.hasChildren {
  padding: 0px
}

.gridCell.hasContent:after {
  content: none;
  border: 0px;
}

.gridCell.hasChildren>.horizrail {
  margin-top: -2px;
  margin-left: 0px;
}

.vertrail {
  height: 100%;
  width: 4px;
  display: block;
  position: absolute;
  cursor: ew-resize;
  margin-top: 0px;
  margin-left: -2px;
  z-index: 10000;
  padding-left: 1px;
}

.horizrail {
  height: 4px;
  width: 100%;
  display: block;
  position: absolute;
  cursor: ns-resize;
  margin-top: -5px;
  margin-left: -3px;
  padding-left: 1px;
  z-index: 10000;
}

.horizrail:hover:not(.ui-draggable-dragging),
.vertrail:hover:not(.ui-draggable-dragging) {
  background: #848484;
}

.ui-draggable-dragging {
  background: green;
}

.hasFocus {
  background: #ececec;
}


/* Just for demo */

#grid4 {
  padding: 1%;
}

JavaScript

$(function() {
  // keep vars in context
  var grid, splitCell, resetGrid, foucs, focusGrid, focusCell, layout1, split4, showData, intMark;

  resetGrid = function() {
    intMark = 1;
    var gridOptions = {};
    // gridOptions["callSetFocus"] = focus;

    // if we have a grid destroy it first
    if (typeof grid !== "undefined") {
      grid = grid.destroy().gridSplit(gridOptions);
    } else {
      grid = $('#grid1').gridSplit(gridOptions);
    }

    // mark cell 1 and move focus
    addMark(grid, 0, 0);
    focus({
      "x": 0,
      "y": 0
    }, grid);
  }

  focus = function(cell, gridd) {
    $(".hasFocus").removeClass("hasFocus");
    // gridd is current focus grid
    focusGrid = gridd;
    // focusCell['x'] = column and focusCell['y'] = cell
    focusCell = cell;
    // add the focus class
    focusGrid.gridsCells[focusCell['x']][focusCell['y']].addClass("hasFocus");
  }

  addMark = function(gridd, cA, cB) {
    // remove old markers
    gridd.gridsCells[cA][cB].find("h1").remove();
    // add new marker
    gridd.gridsCells[cA][cB]
      .addClass("hasContent")
      // center content horizontally
      .attr("align", "center")
      // append the image
      .append(
        $("<h1>" + intMark + "</h1>", {})
        // center vertically by transforming the v position
        .css({
          "font-size": "40px",
          "color": "#dcd",
          "max-width": "100%",
          "max-height": "100%",
          "position": "relative",
          "top": "50%",
          "transform": "translateY(-50%)"
        })
      );
    intMark++;

  }

  layout1 = function() {
    resetGrid();
    // adds column 1
    grid.splitAt(0);
    // adds cell 1 to column 0
    grid.splitAt(0, 0);
    // splits column 0 cell 1 into two columns - splitCell is .gridSplit() instance
    splitCell = grid.splitAt(0, 1, true);
    // add marker to each cell
    addMark(grid, 1, 0);
    addMark(splitCell, 0, 0);
    addMark(splitCell, 1, 0);
  }

  split4 = function(undf)...