guy 8 years ago
parent
commit
e94a7376e5
  1. 16
      bi/base.js
  2. 16
      docs/base.js
  3. 228
      src/base/table/table.resizable.cell.js

16
bi/base.js

@ -32473,14 +32473,14 @@ BI.ResizableTableCell = BI.inherit(BI.Widget, {
function optimizeSize(s) { function optimizeSize(s) {
var optSize = BI.clamp(s, o.minSize, o.maxSize || Number.MAX_VALUE); var optSize = BI.clamp(s, o.minSize, o.maxSize || Number.MAX_VALUE);
if (o.suitableSize) { // if (o.suitableSize) {
if (Math.abs(o.suitableSize - optSize) < 5) { // if (Math.abs(o.suitableSize - optSize) < 5) {
optSize = o.suitableSize; // optSize = o.suitableSize;
self.handler.element.addClass("suitable"); // self.handler.element.addClass("suitable");
} else { // } else {
self.handler.element.removeClass("suitable"); // self.handler.element.removeClass("suitable");
} // }
} // }
return optSize; return optSize;
} }

16
docs/base.js

@ -32473,14 +32473,14 @@ BI.ResizableTableCell = BI.inherit(BI.Widget, {
function optimizeSize(s) { function optimizeSize(s) {
var optSize = BI.clamp(s, o.minSize, o.maxSize || Number.MAX_VALUE); var optSize = BI.clamp(s, o.minSize, o.maxSize || Number.MAX_VALUE);
if (o.suitableSize) { // if (o.suitableSize) {
if (Math.abs(o.suitableSize - optSize) < 5) { // if (Math.abs(o.suitableSize - optSize) < 5) {
optSize = o.suitableSize; // optSize = o.suitableSize;
self.handler.element.addClass("suitable"); // self.handler.element.addClass("suitable");
} else { // } else {
self.handler.element.removeClass("suitable"); // self.handler.element.removeClass("suitable");
} // }
} // }
return optSize; return optSize;
} }

228
src/base/table/table.resizable.cell.js

@ -1,115 +1,115 @@
/** /**
* *
* 表格单元格 * 表格单元格
* *
* Created by GUY on 2016/1/12. * Created by GUY on 2016/1/12.
* @class BI.ResizableTableCell * @class BI.ResizableTableCell
* @extends BI.Widget * @extends BI.Widget
*/ */
BI.ResizableTableCell = BI.inherit(BI.Widget, { BI.ResizableTableCell = BI.inherit(BI.Widget, {
_defaultConfig: function () { _defaultConfig: function () {
return BI.extend(BI.ResizableTableCell.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.ResizableTableCell.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-resizable-table-cell", baseCls: "bi-resizable-table-cell",
cell: {}, cell: {},
minSize: 15, minSize: 15,
// suitableSize, // suitableSize,
maxSize: Number.MAX_VALUE, maxSize: Number.MAX_VALUE,
start: BI.emptyFn, start: BI.emptyFn,
resize: BI.emptyFn, resize: BI.emptyFn,
stop: BI.emptyFn stop: BI.emptyFn
}) })
}, },
_init: function () { _init: function () {
BI.ResizableTableCell.superclass._init.apply(this, arguments); BI.ResizableTableCell.superclass._init.apply(this, arguments);
var self = this, o = this.options; var self = this, o = this.options;
this.cell = BI.createWidget(BI.extend({type: "bi.label"}, o.cell, {width: o.width, height: o.height})); this.cell = BI.createWidget(BI.extend({type: "bi.label"}, o.cell, {width: o.width, height: o.height}));
var startDrag = false; var startDrag = false;
var size = 0, offset = 0, defaultSize = o.width; var size = 0, offset = 0, defaultSize = o.width;
function optimizeSize(s) { function optimizeSize(s) {
var optSize = BI.clamp(s, o.minSize, o.maxSize || Number.MAX_VALUE); var optSize = BI.clamp(s, o.minSize, o.maxSize || Number.MAX_VALUE);
if (o.suitableSize) { // if (o.suitableSize) {
if (Math.abs(o.suitableSize - optSize) < 5) { // if (Math.abs(o.suitableSize - optSize) < 5) {
optSize = o.suitableSize; // optSize = o.suitableSize;
self.handler.element.addClass("suitable"); // self.handler.element.addClass("suitable");
} else { // } else {
self.handler.element.removeClass("suitable"); // self.handler.element.removeClass("suitable");
} // }
} // }
return optSize; return optSize;
} }
var mouseMoveTracker = new BI.MouseMoveTracker(function (deltaX, deltaY) { var mouseMoveTracker = new BI.MouseMoveTracker(function (deltaX, deltaY) {
if (mouseMoveTracker.isDragging()) { if (mouseMoveTracker.isDragging()) {
startDrag = true; startDrag = true;
offset += deltaX; offset += deltaX;
size = optimizeSize(defaultSize + offset); size = optimizeSize(defaultSize + offset);
self.handler.element.addClass("dragging"); self.handler.element.addClass("dragging");
o.resize(size); o.resize(size);
} }
}, function () { }, function () {
if (startDrag === true) { if (startDrag === true) {
size = optimizeSize(size); size = optimizeSize(size);
o.stop(size); o.stop(size);
size = 0; size = 0;
offset = 0; offset = 0;
defaultSize = o.width; defaultSize = o.width;
startDrag = false; startDrag = false;
} }
self.handler.element.removeClass("dragging"); self.handler.element.removeClass("dragging");
self.handler.element.removeClass("suitable"); self.handler.element.removeClass("suitable");
mouseMoveTracker.releaseMouseMoves(); mouseMoveTracker.releaseMouseMoves();
}, document); }, document);
this.handler = BI.createWidget({ this.handler = BI.createWidget({
type: "bi.absolute", type: "bi.absolute",
cls: "resizable-table-cell-resizer-container", cls: "resizable-table-cell-resizer-container",
width: 6, width: 6,
items: [{ items: [{
el: { el: {
type: "bi.layout", type: "bi.layout",
cls: "resizable-table-cell-resizer-knob", cls: "resizable-table-cell-resizer-knob",
width: 4 width: 4
}, },
right: 0, right: 0,
top: 0, top: 0,
bottom: 0 bottom: 0
}] }]
}); });
this.handler.element.on("mousedown", function (event) { this.handler.element.on("mousedown", function (event) {
defaultSize = o.width; defaultSize = o.width;
optimizeSize(defaultSize); optimizeSize(defaultSize);
mouseMoveTracker.captureMouseMoves(event); mouseMoveTracker.captureMouseMoves(event);
}); });
BI.createWidget({ BI.createWidget({
type: "bi.absolute", type: "bi.absolute",
element: this, element: this,
items: [{ items: [{
el: this.cell, el: this.cell,
left: 0, left: 0,
right: 0, right: 0,
top: 0, top: 0,
bottom: 0 bottom: 0
}, { }, {
el: this.handler, el: this.handler,
right: 0, right: 0,
top: 0, top: 0,
bottom: 0 bottom: 0
}] }]
}) })
}, },
setWidth: function (width) { setWidth: function (width) {
BI.ResizableTableCell.superclass.setWidth.apply(this, arguments); BI.ResizableTableCell.superclass.setWidth.apply(this, arguments);
var o = this.options; var o = this.options;
this.cell.setWidth(o.width); this.cell.setWidth(o.width);
}, },
setHeight: function (height) { setHeight: function (height) {
BI.ResizableTableCell.superclass.setHeight.apply(this, arguments); BI.ResizableTableCell.superclass.setHeight.apply(this, arguments);
var o = this.options; var o = this.options;
this.cell.setHeight(o.height); this.cell.setHeight(o.height);
} }
}); });
BI.shortcut("bi.resizable_table_cell", BI.ResizableTableCell); BI.shortcut("bi.resizable_table_cell", BI.ResizableTableCell);
Loading…
Cancel
Save