Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ff9136c

Browse files
committed
update gridstack
1 parent a652b89 commit ff9136c

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

gridstack.css

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
.grid-stack-item[data-gs-x="2"] { left: 16.66666667% }
8989
.grid-stack-item[data-gs-x="1"] { left: 8.33333333% }
9090

91-
9291
@media (max-width: 768px) {
9392
.grid-stack-item {
9493
position: relative !important;
@@ -102,3 +101,20 @@
102101
height: auto !important;
103102
}
104103
}
104+
105+
.grid-stack.grid-stack-animate .grid-stack-item {
106+
-webkit-transition: left .3s, top .3s, height .3s, width .3s;
107+
-moz-transition: left .3s, top .3s, height .3s, width .3s;
108+
-o-transition: left .3s, top .3s, height .3s, width .3s;
109+
-ms-transition: left .3s, top .3s, height .3s, width .3s;
110+
transition: left .3s, top .3s, height .3s, width .3s;
111+
}
112+
/*Don't animate the placeholder or when dragging/resizing*/
113+
.grid-stack.grid-stack-animate .grid-stack-item.ui-draggable-dragging,
114+
.grid-stack.grid-stack-animate .grid-stack-item.ui-resizable-resizing,
115+
.grid-stack.grid-stack-animate .grid-stack-item.grid-stack-placeholder{
116+
-webkit-transition: left .0s, top .0s, height .0s, width .0s;
117+
-moz-transition: left .0s, top .0s, height .0s, width .0s;
118+
-o-transition: left .0s, top .0s, height .0s, width .0s;
119+
transition: left .0s, top .0s, height .0s, width .0s;
120+
}

gridstack.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@
283283
auto: true,
284284
min_width: 768,
285285
float: false,
286-
_class: 'grid-stack-' + (Math.random() * 10000).toFixed(0)
286+
_class: 'grid-stack-' + (Math.random() * 10000).toFixed(0),
287+
animate: Boolean(this.container.attr('data-gs-animate')) || false
287288
});
288289

289290
this.container.addClass(this.opts._class);
@@ -324,6 +325,8 @@
324325
});
325326
}
326327

328+
this.set_animation(this.opts.animate);
329+
327330
this.placeholder = $('<div class="' + this.opts.placeholder_class + ' ' + this.opts.item_class + '"><div class="placeholder-content" /></div>').hide();
328331
this.container.append(this.placeholder);
329332
this.container.height((this.grid.get_grid_height()) * (this.opts.cell_height + this.opts.vertical_margin) - this.opts.vertical_margin);
@@ -427,10 +430,12 @@
427430
self.grid.end_update();
428431

429432
self.grid._sort_nodes();
430-
_.each(self.grid.nodes, function (node) {
431-
node.el.detach();
432-
self.container.append(node.el);
433-
});
433+
setTimeout(function() { //if animating, delay detaching & reattaching all elements until animation finishes
434+
_.each(self.grid.nodes, function (node) {
435+
node.el.detach();
436+
self.container.append(node.el);
437+
});
438+
}, (self.opts.animate ? 300 : 0));
434439
};
435440

436441
el.draggable({
@@ -477,6 +482,15 @@
477482
}
478483
};
479484

485+
GridStack.prototype.set_animation = function (enable) {
486+
if (enable) {
487+
this.container.addClass('grid-stack-animate');
488+
}
489+
else {
490+
this.container.removeClass('grid-stack-animate');
491+
}
492+
}
493+
480494
GridStack.prototype.add_widget = function (el, x, y, width, height, auto_position) {
481495
el = $(el);
482496
if (typeof x != 'undefined') el.attr('data-gs-x', x);

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ <h2>Demo</h2>
106106
</div>
107107
</div>
108108

109-
<div class="grid-stack" data-gs-width="12">
109+
<div class="grid-stack" data-gs-width="12" data-gs-animate="yes">
110110
<div class="grid-stack-item" data-gs-x="0" data-gs-y="0" data-gs-width="4" data-gs-height="2"><div class="grid-stack-item-content">1</div></div>
111111
<div class="grid-stack-item" data-gs-x="4" data-gs-y="0" data-gs-width="4" data-gs-height="4"><div class="grid-stack-item-content">2</div></div>
112112
<div class="grid-stack-item" data-gs-x="8" data-gs-y="0" data-gs-width="2" data-gs-height="2" data-gs-min-width="2" data-gs-no-resize="yes"><div class="grid-stack-item-content"> <span class="fa fa-hand-o-up"></span> Drag me! </div></div>

0 commit comments

Comments
 (0)