Remove Layout

This commit is contained in:
Paul Clarke 2016-10-03 13:49:23 +13:00 committed by Damian Mooyman
parent 89c88f0f60
commit 1b0839a8e8
11 changed files with 755 additions and 1765 deletions

File diff suppressed because one or more lines are too long

View File

@ -36,8 +36,6 @@ require('../../../thirdparty/jquery-form/jquery.form.js');
require('../../../thirdparty/jquery-notice/jquery.notice.js'); require('../../../thirdparty/jquery-notice/jquery.notice.js');
// require('../../../thirdparty/jquery-notice/jquery.notice.css'); // require('../../../thirdparty/jquery-notice/jquery.notice.css');
require('jquery-sizes/lib/jquery.sizes.js'); require('jquery-sizes/lib/jquery.sizes.js');
require('../../../thirdparty/jlayout/lib/jlayout.border.js');
require('../../../thirdparty/jlayout/lib/jquery.jlayout.js');
require('../../../thirdparty/jstree/jquery.jstree.js'); require('../../../thirdparty/jstree/jquery.jstree.js');
// require('../../../thirdparty/stree/themes/apple/style.css'); // require('../../../thirdparty/stree/themes/apple/style.css');
require('../../../thirdparty/jquery-hoverIntent/jquery.hoverIntent.js'); require('../../../thirdparty/jquery-hoverIntent/jquery.hoverIntent.js');

View File

@ -1,178 +0,0 @@
/**
* File: LeftAndMain.Layout.js
*/
import $ from 'jQuery';
$.fn.layout.defaults.resize = false;
/**
* Acccess the global variable in the same way the plugin does it.
*/
jLayout = (typeof jLayout === 'undefined') ? {} : jLayout;
/**
* Factory function for generating new type of algorithm for our CMS.
*
* Spec requires a definition of three column elements:
* - `menu` on the left
* - `content` area in the middle (includes the EditForm, side tool panel, actions, breadcrumbs and tabs)
* - `preview` on the right (will be shown if there is enough space)
*
* Required options:
* - `minContentWidth`: minimum size for the content display as long as the preview is visible
* - `minPreviewWidth`: preview will not be displayed below this size
* - `mode`: one of "split", "content" or "preview"
*
* The algorithm first checks which columns are to be visible and which hidden.
*
* In the case where both preview and content should be shown it first tries to assign half of non-menu space to
* preview and the other half to content. Then if there is not enough space for either content or preview, it tries
* to allocate the minimum acceptable space to that column, and the rest to the other one. If the minimum
* requirements are still not met, it falls back to showing content only.
*
* @param spec A structure defining columns and parameters as per above.
*/
jLayout.threeColumnCompressor = function (spec, options) {
// Spec sanity checks.
if (typeof spec.menu==='undefined' ||
typeof spec.content==='undefined' ||
typeof spec.preview==='undefined') {
throw 'Spec is invalid. Please provide "menu", "content" and "preview" elements.';
}
if (typeof options.minContentWidth==='undefined' ||
typeof options.minPreviewWidth==='undefined' ||
typeof options.mode==='undefined') {
throw 'Spec is invalid. Please provide "minContentWidth", "minPreviewWidth", "mode"';
}
if (options.mode!=='split' && options.mode!=='content' && options.mode!=='preview') {
throw 'Spec is invalid. "mode" should be either "split", "content" or "preview"';
}
// Instance of the algorithm being produced.
var obj = {
options: options
};
// Internal column handles, also implementing layout.
var menu = $.jLayoutWrap(spec.menu),
content = $.jLayoutWrap(spec.content),
preview = $.jLayoutWrap(spec.preview);
/**
* Required interface implementations follow.
* Refer to https://github.com/bramstein/jlayout#layout-algorithms for the interface spec.
*/
obj.layout = function (container) {
var size = container.bounds(),
insets = container.insets(),
top = insets.top,
bottom = size.height - insets.bottom,
left = insets.left,
right = size.width - insets.right;
var menuWidth = spec.menu.width(),
contentWidth = 0,
previewWidth = 0;
if (this.options.mode==='preview') {
// All non-menu space allocated to preview.
contentWidth = 0;
previewWidth = right - left - menuWidth;
} else if (this.options.mode==='content') {
// All non-menu space allocated to content.
contentWidth = right - left - menuWidth;
previewWidth = 0;
} else { // ==='split'
// Split view - first try 50-50 distribution.
contentWidth = (right - left - menuWidth) / 2;
previewWidth = right - left - (menuWidth + contentWidth);
// If violating one of the minima, try to readjust towards satisfying it.
if (contentWidth < this.options.minContentWidth) {
contentWidth = this.options.minContentWidth;
previewWidth = right - left - (menuWidth + contentWidth);
} else if (previewWidth < this.options.minPreviewWidth) {
previewWidth = this.options.minPreviewWidth;
contentWidth = right - left - (menuWidth + previewWidth);
}
// If still violating one of the (other) minima, remove the preview and allocate everything to content.
if (contentWidth < this.options.minContentWidth || previewWidth < this.options.minPreviewWidth) {
contentWidth = right - left - menuWidth;
previewWidth = 0;
}
}
// Calculate what columns are already hidden pre-layout
var prehidden = {
content: spec.content.hasClass('column-hidden'),
preview: spec.preview.hasClass('column-hidden')
};
// Calculate what columns will be hidden (zero width) post-layout
var posthidden = {
content: contentWidth === 0,
preview: previewWidth === 0
};
// Apply classes for elements that might not be visible at all.
spec.content.toggleClass('column-hidden', posthidden.content);
spec.preview.toggleClass('column-hidden', posthidden.preview);
// Apply the widths to columns, and call subordinate layouts to arrange the children.
menu.bounds({'x': left, 'y': top, 'height': bottom - top, 'width': menuWidth});
menu.doLayout();
left += menuWidth;
content.bounds({'x': left, 'y': top, 'height': bottom - top, 'width': contentWidth});
if (!posthidden.content) content.doLayout();
left += contentWidth;
preview.bounds({'x': left, 'y': top, 'height': bottom - top, 'width': previewWidth});
if (!posthidden.preview) preview.doLayout();
if (posthidden.content !== prehidden.content) spec.content.trigger('columnvisibilitychanged');
if (posthidden.preview !== prehidden.preview) spec.preview.trigger('columnvisibilitychanged');
// Calculate whether preview is possible in split mode
if (contentWidth + previewWidth < options.minContentWidth + options.minPreviewWidth) {
spec.preview.trigger('disable');
} else {
spec.preview.trigger('enable');
}
return container;
};
/**
* Helper to generate the required `preferred`, `minimum` and `maximum` interface functions.
*/
function typeLayout(type) {
var func = type + 'Size';
return function (container) {
var menuSize = menu[func](),
contentSize = content[func](),
previewSize = preview[func](),
insets = container.insets();
width = menuSize.width + contentSize.width + previewSize.width;
height = Math.max(menuSize.height, contentSize.height, previewSize.height);
return {
'width': insets.left + insets.right + width,
'height': insets.top + insets.bottom + height
};
};
}
// Generate interface functions.
obj.preferred = typeLayout('preferred');
obj.minimum = typeLayout('minimum');
obj.maximum = typeLayout('maximum');
return obj;
};

View File

@ -294,20 +294,6 @@ $.entwine('ss', function($) {
if(window.debug) console.log('redraw', this.attr('class'), this.get(0)); if(window.debug) console.log('redraw', this.attr('class'), this.get(0));
// Reset the algorithm.
this.data('jlayout', jLayout.threeColumnCompressor(
{
menu: this.children('.cms-menu'),
content: this.children('.cms-content'),
preview: this.children('.cms-preview')
},
this.getLayoutOptions()
));
// Trigger layout algorithm once at the top. This also lays out children - we move from outside to
// inside, resizing to fit the parent.
this.layout();
// Redraw on all the children that need it // Redraw on all the children that need it
this.find('.cms-panel-layout').redraw(); this.find('.cms-panel-layout').redraw();
this.find('.cms-content-fields[data-layout-type]').redraw(); this.find('.cms-content-fields[data-layout-type]').redraw();
@ -717,7 +703,6 @@ $.entwine('ss', function($) {
// Set loading state and store element state // Set loading state and store element state
var origStyle = contentEl.attr('style'); var origStyle = contentEl.attr('style');
var origParent = contentEl.parent(); var origParent = contentEl.parent();
var origParentLayoutApplied = (typeof origParent.data('jlayout')!=='undefined');
var layoutClasses = ['east', 'west', 'center', 'north', 'south', 'column-hidden']; var layoutClasses = ['east', 'west', 'center', 'north', 'south', 'column-hidden'];
var elemClasses = contentEl.attr('class'); var elemClasses = contentEl.attr('class');
var origLayoutClasses = []; var origLayoutClasses = [];
@ -741,12 +726,6 @@ $.entwine('ss', function($) {
// Replace panel completely (we need to override the "layout" attribute, so can't replace the child instead) // Replace panel completely (we need to override the "layout" attribute, so can't replace the child instead)
contentEl.replaceWith(newContentEl); contentEl.replaceWith(newContentEl);
// Force jlayout to rebuild internal hierarchy to point to the new elements.
// This is only necessary for elements that are at least 3 levels deep. 2nd level elements will
// be taken care of when we lay out the top level element (.cms-container).
if (!origParent.is('.cms-container') && origParentLayoutApplied) {
origParent.layout();
}
}); });
// Re-init tabs (in case the form tag itself is a tabset) // Re-init tabs (in case the form tag itself is a tabset)

View File

@ -1,8 +0,0 @@
---
format: 1
handler:
commit: b5ff32977e136f519236d29593433e87dadb74d0
branch: master
lock: false
repository_class: Piston::Git::Repository
repository_url: https://github.com/bramstein/jlayout.git

View File

@ -1,143 +0,0 @@
/**
* @preserve jLayout Border Layout - JavaScript Layout Algorithms v0.4
*
* Licensed under the new BSD License.
* Copyright 2008-2009, Bram Stein
* All rights reserved.
*/
/*global jLayout:true */
(function () {
// Customised
// Defining global alias because Browserify adds 'use strict'
// which throws a runtime error if globals are undefined and not declared.
// Original
// jLayout = (typeof jLayout === 'undefined') ? {} : jLayout;
window.jLayout = (typeof window.jLayout === 'undefined') ? {} : window.jLayout;
jLayout.border = function (spec) {
var my = {},
that = {},
east = spec.east,
west = spec.west,
north = spec.north,
south = spec.south,
center = spec.center;
my.hgap = spec.hgap || 0;
my.vgap = spec.vgap || 0;
that.items = function () {
var items = [];
if (east) {
items.push(east);
}
if (west) {
items.push(west);
}
if (north) {
items.push(north);
}
if (south) {
items.push(south);
}
if (center) {
items.push(center);
}
return items;
};
that.layout = function (container) {
var size = container.bounds(),
insets = container.insets(),
top = insets.top,
bottom = size.height - insets.bottom,
left = insets.left,
right = size.width - insets.right,
tmp;
if (north && north.isVisible()) {
tmp = north.preferredSize();
north.bounds({'x': left, 'y': top, 'width': right - left, 'height': tmp.height});
north.doLayout();
top += tmp.height + my.vgap;
}
if (south && south.isVisible()) {
tmp = south.preferredSize();
south.bounds({'x': left, 'y': bottom - tmp.height, 'width': right - left, 'height': tmp.height});
south.doLayout();
bottom -= tmp.height + my.vgap;
}
if (east && east.isVisible()) {
tmp = east.preferredSize();
east.bounds({'x': right - tmp.width, 'y': top, 'width': tmp.width, 'height': bottom - top});
east.doLayout();
right -= tmp.width + my.hgap;
}
if (west && west.isVisible()) {
tmp = west.preferredSize();
west.bounds({'x': left, 'y': top, 'width': tmp.width, 'height': bottom - top});
west.doLayout();
left += tmp.width + my.hgap;
}
if (center && center.isVisible()) {
center.bounds({'x': left, 'y': top, 'width': right - left, 'height': bottom - top});
center.doLayout();
}
return container;
};
function typeLayout(type) {
return function (container) {
var insets = container.insets(),
width = 0,
height = 0,
type_size;
if (east && east.isVisible()) {
type_size = east[type + 'Size']();
width += type_size.width + my.hgap;
height = type_size.height;
}
if (west && west.isVisible()) {
type_size = west[type + 'Size']();
width += type_size.width + my.hgap;
height = Math.max(type_size.height, height);
}
if (center && center.isVisible()) {
type_size = center[type + 'Size']();
width += type_size.width;
height = Math.max(type_size.height, height);
}
if (north && north.isVisible()) {
type_size = north[type + 'Size']();
width = Math.max(type_size.width, width);
height += type_size.height + my.vgap;
}
if (south && south.isVisible()) {
type_size = south[type + 'Size']();
width = Math.max(type_size.width, width);
height += type_size.height + my.vgap;
}
return {
'width': width + insets.left + insets.right,
'height': height + insets.top + insets.bottom
};
};
}
that.preferred = typeLayout('preferred');
that.minimum = typeLayout('minimum');
that.maximum = typeLayout('maximum');
return that;
};
}());

View File

@ -1,88 +0,0 @@
/**
* @preserve jLayout Column Layout - JavaScript Layout Algorithms v0.1
*
* Licensed under the new BSD License.
* Copyright 2008-2009, Bram Stein
* All rights reserved.
*/
/*global jLayout */
/*
(function () {
jLayout = typeof jLayout === 'undefined' ? {} : jLayout;
jLayout.column = function (options) {
var that = {},
my = {};
my.hgap = options.hgap || 0;
my.vgap = options.vgap || 0;
my.columns = options.columns || 2;
my.items = options.items || [];
my.maxHeight = options.maxHeight || -1;
that.items = function () {
var r = [];
Array.prototype.push.apply(r, my.items);
return r;
};
that.layout = function (container) {
var i = 0, j = 1,
insets = container.insets(),
x = insets.left,
y = insets.top,
rows = 0,
width = (container.bounds().width - (insets.left + insets.right) - (my.columns - 1) * my.hgap) / my.columns,
// TODO: if maxHeight is not available the height should be the height that divides the content equally over all columns.
height = my.maxHeight,
itemSize;
// container.bounds({'height': height * 4});
console.log(height);
for (; i < my.items.length; i += 1) {
my.items[i].bounds({'width': width});
}
for (i = 0; i < my.items.length; i += 1) {
itemSize = my.items[i].preferredSize();
if (y + itemSize.height + my.hgap > height) {
if (j === my.columns) {
rows += 1;
y = insets.top + my.hgap + height * rows;
x = insets.left;
j = 1;
} else {
y = insets.top + (rows * height);
x += width + my.vgap;
j += 1;
}
}
my.items[i].bounds({'x': x, 'y': y});
y += itemSize.height + my.hgap;
my.items[i].doLayout();
}
//console.log(width);
return container;
};
function typeLayout(type) {
return function (container) {
return {
width: 800,
height: 600
};
};
}
that.preferred = typeLayout('preferred');
that.minimum = typeLayout('minimum');
that.maximum = typeLayout('maximum');
return that;
};
})();*/

View File

@ -1,108 +0,0 @@
/**
* @preserve jLayout Flex Grid Layout - JavaScript Layout Algorithms v0.4
* Based on: http://www.javaworld.com/javaworld/javatips/jw-javatip121.html
*
* Licensed under the new BSD License.
* Copyright 2008-2009, Bram Stein
* All rights reserved.
*/
/*global jLayout:true */
(function () {
jLayout = (typeof jLayout === 'undefined') ? {} : jLayout;
// The flex grid has a dependency on the grid layout, so please make
// sure you include the grid layout manager before the flex grid
// layout manager.
if (typeof jLayout.grid !== 'undefined') {
jLayout.flexGrid = function (spec) {
var my = {},
that = this.grid(spec, my);
function zeroArray(a, l) {
var i = 0;
for (; i < l; i += 1) {
a[i] = 0;
}
return a;
}
function typeLayout(type) {
return function (container) {
var i = 0, r = 0, c = 0, nw = 0, nh = 0,
w = zeroArray([], my.columns),
h = zeroArray([], my.rows),
type_size,
insets = container.insets();
for (i = 0; i < my.items.length; i += 1) {
r = Math.floor(i / my.columns);
c = i % my.columns;
type_size = my.items[i][type + 'Size']();
if (w[c] < type_size.width) {
w[c] = type_size.width;
}
if (h[r] < type_size.height) {
h[r] = type_size.height;
}
}
for (i = 0; i < my.columns; i += 1) {
nw += w[i];
}
for (i = 0; i < my.rows; i += 1) {
nh += h[i];
}
return {
width: insets.left + insets.right + nw + (my.columns - 1) * my.hgap,
height: insets.top + insets.bottom + nh + (my.rows - 1) * my.vgap
};
};
}
that.preferred = typeLayout('preferred');
that.minimum = typeLayout('minimum');
that.maximum = typeLayout('maximum');
that.layout = function (container) {
var i = 0, c = 0, r = 0,
pd = that.preferred(container),
sw = container.bounds().width / pd.width,
sh = container.bounds().height / pd.height,
w = zeroArray([], my.columns),
h = zeroArray([], my.rows),
insets = container.insets(),
x = insets.left,
y = insets.top,
d;
for (i = 0; i < my.items.length; i += 1) {
r = Math.floor(i / my.columns);
c = i % my.columns;
d = my.items[i].preferredSize();
d.width = sw * d.width;
d.height = sh * d.height;
if (w[c] < d.width) {
w[c] = d.width;
}
if (h[r] < d.height) {
h[r] = d.height;
}
}
for (c = 0; c < my.columns; c += 1) {
for (r = 0, y = insets.top; r < my.rows; r += 1) {
i = r * my.columns + c;
if (i < my.items.length) {
my.items[i].bounds({'x': x, 'y': y, 'width': w[c], 'height': h[r]});
my.items[i].doLayout();
}
y += h[r] + my.vgap;
}
x += w[c] + my.hgap;
}
return container;
};
return that;
};
}
}());

View File

@ -1,127 +0,0 @@
/**
* @preserve jLayout Flow Layout - JavaScript Layout Algorithms v0.12
*
* Licensed under the new BSD License.
* Copyright 2008-2009, Bram Stein
* All rights reserved.
*/
/*global jLayout:true */
(function () {
jLayout = (typeof jLayout === 'undefined') ? {} : jLayout;
jLayout.flow = function (options) {
var my = {},
that = {};
my.hgap = typeof options.hgap === 'number' && !isNaN(options.hgap) ? options.hgap : 5;
my.vgap = typeof options.vgap === 'number' && !isNaN(options.vgap) ? options.vgap : 5;
my.items = options.items || [];
my.alignment = (options.alignment && (options.alignment === 'center' || options.alignment === 'right' || options.alignment === 'left') && options.alignment) || 'left';
that.items = function () {
var r = [];
Array.prototype.push.apply(r, my.items);
return r;
};
function align(row, offset, rowSize, parentSize) {
var location = {
x: offset.x,
y: offset.y
},
i = 0,
len = row.length;
switch (my.alignment) {
case 'center':
location.x += (my.hgap + parentSize.width - rowSize.width) / 2;
break;
case 'right':
location.x += parentSize.width - rowSize.width + my.hgap;
break;
}
for (; i < len; i += 1) {
location.y = offset.y;
row[i].bounds(location);
row[i].doLayout();
location.x += row[i].bounds().width + my.hgap;
}
}
that.layout = function (container) {
var parentSize = container.bounds(),
insets = container.insets(),
i = 0,
len = my.items.length,
itemSize,
currentRow = [],
rowSize = {
width: 0,
height: 0
},
offset = {
x: insets.left,
y: insets.top
};
parentSize.width -= insets.left + insets.right;
parentSize.height -= insets.top + insets.bottom;
for (; i < len; i += 1) {
if (my.items[i].isVisible()) {
itemSize = my.items[i].preferredSize();
if ((rowSize.width + itemSize.width) > parentSize.width) {
align(currentRow, offset, rowSize, parentSize);
currentRow = [];
offset.y += rowSize.height;
offset.x = insets.left;
rowSize.width = 0;
rowSize.height = 0;
}
rowSize.height = Math.max(rowSize.height, itemSize.height + my.vgap);
rowSize.width += itemSize.width + my.hgap;
currentRow.push(my.items[i]);
}
}
align(currentRow, offset, rowSize, parentSize);
return container;
};
function typeLayout(type) {
return function (container) {
var i = 0,
width = 0,
height = 0,
typeSize,
firstComponent = false,
insets = container.insets();
for (; i < my.items.length; i += 1) {
if (my.items[i].isVisible()) {
typeSize = my.items[i][type + 'Size']();
height = Math.max(height, typeSize.height);
width += typeSize.width;
}
}
return {
'width': width + insets.left + insets.right + (my.items.length - 1) * my.hgap,
'height': height + insets.top + insets.bottom
};
};
}
that.preferred = typeLayout('preferred');
that.minimum = typeLayout('minimum');
that.maximum = typeLayout('maximum');
return that;
};
}());

View File

@ -1,99 +0,0 @@
/**
* @preserve jLayout Grid Layout - JavaScript Layout Algorithms v0.41
*
* Licensed under the new BSD License.
* Copyright 2008-2009, Bram Stein
* All rights reserved.
*/
/*global jLayout:true */
(function () {
jLayout = (typeof jLayout === 'undefined') ? {} : jLayout;
jLayout.grid = function (spec, shared) {
var my = shared || {},
that = {};
my.hgap = spec.hgap || 0;
my.vgap = spec.vgap || 0;
// initialize the number of columns to the number of items
// we're laying out.
my.items = spec.items || [];
my.columns = spec.columns || my.items.length;
my.rows = spec.rows || 0;
my.fillVertical = spec.fill && spec.fill === 'vertical';
if (my.rows > 0) {
my.columns = Math.floor((my.items.length + my.rows - 1) / my.rows);
} else {
my.rows = Math.floor((my.items.length + my.columns - 1) / my.columns);
}
that.items = function () {
var r = [];
Array.prototype.push.apply(r, my.items);
return r;
};
that.layout = function (container) {
var i, j,
insets = container.insets(),
x = insets.left,
y = insets.top,
width = (container.bounds().width - (insets.left + insets.right) - (my.columns - 1) * my.hgap) / my.columns,
height = (container.bounds().height - (insets.top + insets.bottom) - (my.rows - 1) * my.vgap) / my.rows;
for (i = 0, j = 1; i < my.items.length; i += 1, j += 1) {
my.items[i].bounds({'x': x, 'y': y, 'width': width, 'height': height});
if (!my.fillVertical) {
if (j >= my.columns) {
y += height + my.vgap;
x = insets.left;
j = 0;
}
else {
x += width + my.hgap;
}
} else {
if (j >= my.rows) {
x += width + my.hgap;
y = insets.top;
j = 0;
} else {
y += height + my.vgap;
}
}
my.items[i].doLayout();
}
return container;
};
function typeLayout(type) {
return function (container) {
var i = 0,
width = 0,
height = 0,
type_size,
insets = container.insets();
for (; i < my.items.length; i += 1) {
type_size = my.items[i][type + 'Size']();
width = Math.max(width, type_size.width);
height = Math.max(height, type_size.height);
}
return {
'width': insets.left + insets.right + my.columns * width + (my.columns - 1) * my.hgap,
'height': insets.top + insets.bottom + my.rows * height + (my.rows - 1) * my.vgap
};
};
}
// this creates the min and preferred size methods, as they
// only differ in the function they call.
that.preferred = typeLayout('preferred');
that.minimum = typeLayout('minimum');
that.maximum = typeLayout('maximum');
return that;
};
}());

View File

@ -1,206 +0,0 @@
/**
* @preserve jLayout JQuery Plugin v0.17
*
* Licensed under the new BSD License.
* Copyright 2008-2009 Bram Stein
* All rights reserved.
*/
/*global jQuery jLayout*/
// Customised
// Defining global alias because Browserify adds 'use strict'
// which throws a runtime error if globals are undefined and not declared.
var jQuery = window.jQuery,
jLayout = window.jLayout;
if (jQuery && jLayout) {
(function ($) {
/**
* This wraps jQuery objects in another object that supplies
* the methods required for the layout algorithms.
*/
// CUSTOM hfriedlander 2012-10-26 for side-by-side editing.
// function wrap(item, resize) {
var wrap = $.jLayoutWrap = function(item, resize) {
// CUSTOM END
var that = {};
// CUSTOM hfriedlander 2012-10-26 for side-by-side editing.
that.item = item;
// CUSTOM END
$.each(['min', 'max'], function (i, name) {
that[name + 'imumSize'] = function (value) {
var l = item.data('jlayout');
if (l) {
return l[name + 'imum'](that);
} else {
return item[name + 'Size'](value);
}
};
});
$.extend(that, {
doLayout: function () {
// CUSTOM hfriedlander 2012-10-26 for side-by-side editing.
//var l = item.data('jlayout');
//
//if (l) {
// l.layout(that);
//}
//
var l = item.data('jlayout');
if (l) l.layout(that);
else if (item.is('[data-layout-type]')) {
item.layout({resize: false});
}
// CUSTOM END
item.css({position: 'absolute'});
},
isVisible: function () {
return item.isVisible();
},
insets: function () {
var p = item.padding(),
b = item.border();
return {
'top': p.top,
'bottom': p.bottom + b.bottom + b.top,
'left': p.left,
'right': p.right + b.right + b.left
};
},
bounds: function (value) {
var tmp = {};
if (value) {
if (typeof value.x === 'number') {
tmp.left = value.x;
}
if (typeof value.y === 'number') {
tmp.top = value.y;
}
if (typeof value.width === 'number') {
tmp.width = (value.width - (item.outerWidth(true) - item.width()));
tmp.width = (tmp.width >= 0) ? tmp.width : 0;
}
if (typeof value.height === 'number') {
tmp.height = value.height - (item.outerHeight(true) - item.height());
tmp.height = (tmp.height >= 0) ? tmp.height : 0;
}
item.css(tmp);
return item;
} else {
tmp = item.position();
return {
'x': tmp.left,
'y': tmp.top,
'width': item.outerWidth(false),
'height': item.outerHeight(false)
};
}
},
preferredSize: function () {
var minSize,
maxSize,
margin = item.margin(),
size = {width: 0, height: 0},
l = item.data('jlayout');
if (l && resize) {
size = l.preferred(that);
minSize = that.minimumSize();
maxSize = that.maximumSize();
size.width += margin.left + margin.right;
size.height += margin.top + margin.bottom;
if (size.width < minSize.width || size.height < minSize.height) {
size.width = Math.max(size.width, minSize.width);
size.height = Math.max(size.height, minSize.height);
} else if (size.width > maxSize.width || size.height > maxSize.height) {
size.width = Math.min(size.width, maxSize.width);
size.height = Math.min(size.height, maxSize.height);
}
} else {
size = that.bounds();
size.width += margin.left + margin.right;
size.height += margin.top + margin.bottom;
}
return size;
}
});
return that;
}
$.fn.layout = function (options) {
var opts = $.extend({}, $.fn.layout.defaults, options);
return $.each(this, function () {
var element = $(this),
o = $.metadata && element.metadata().layout ? $.extend(opts, element.metadata().layout) : opts,
// CUSTOM ischommer 2012-16-02 Allow type setting throgh built-in jQuery HTML5 data getters, to avoid including jQuery.metadata.js
o = element.data('layoutType') ? $.extend(o, {type: element.data('layoutType')}) : o,
// CUSTOM END
elementWrapper = wrap(element, o.resize);
if (o.type === 'border' && typeof jLayout.border !== 'undefined') {
$.each(['north', 'south', 'west', 'east', 'center'], function (i, name) {
if (element.children().hasClass(name)) {
o[name] = wrap(element.children('.' + name + ':first'));
}
});
element.data('jlayout', jLayout.border(o));
} else if (o.type === 'grid' && typeof jLayout.grid !== 'undefined') {
o.items = [];
element.children().each(function (i) {
if (!$(this).hasClass('ui-resizable-handle')) {
o.items[i] = wrap($(this));
}
});
element.data('jlayout', jLayout.grid(o));
} else if (o.type === 'flexGrid' && typeof jLayout.flexGrid !== 'undefined') {
o.items = [];
element.children().each(function (i) {
if (!$(this).hasClass('ui-resizable-handle')) {
o.items[i] = wrap($(this));
}
});
element.data('jlayout', jLayout.flexGrid(o));
} else if (o.type === 'column' && typeof jLayout.column !== 'undefined') {
o.items = [];
element.children().each(function (i) {
if (!$(this).hasClass('ui-resizable-handle')) {
o.items[i] = wrap($(this));
}
});
element.data('jlayout', jLayout.column(o));
} else if (o.type === 'flow' && typeof jLayout.flow !== 'undefined') {
o.items = [];
element.children().each(function (i) {
if (!$(this).hasClass('ui-resizable-handle')) {
o.items[i] = wrap($(this));
}
});
element.data('jlayout', jLayout.flow(o));
}
if (o.resize) {
elementWrapper.bounds(elementWrapper.preferredSize());
}
elementWrapper.doLayout();
element.css({position: 'relative'});
if ($.ui !== undefined) {
element.addClass('ui-widget');
}
});
};
$.fn.layout.defaults = {
resize: true,
type: 'grid'
};
}(jQuery));
}