@@ -3,6 +3,19 @@ describe('gridstack', function() {
33
44 var e ;
55 var w ;
6+ var gridstackHTML =
7+ '<div class="grid-stack">' +
8+ ' <div class="grid-stack-item"' +
9+ ' data-gs-x="0" data-gs-y="0"' +
10+ ' data-gs-width="4" data-gs-height="2">' +
11+ ' <div class="grid-stack-item-content"></div>' +
12+ ' </div>' +
13+ ' <div class="grid-stack-item"' +
14+ ' data-gs-x="4" data-gs-y="0"' +
15+ ' data-gs-width="4" data-gs-height="4">' +
16+ ' <div class="grid-stack-item-content"></div>' +
17+ ' </div>' +
18+ '</div>' ;
619
720 beforeEach ( function ( ) {
821 w = window ;
@@ -87,6 +100,306 @@ describe('gridstack', function() {
87100
88101 } ) ;
89102
103+ describe ( 'grid.setAnimation' , function ( ) {
104+ beforeEach ( function ( ) {
105+ document . body . insertAdjacentHTML (
106+ 'afterbegin' , gridstackHTML ) ;
107+ } ) ;
108+ afterEach ( function ( ) {
109+ document . body . removeChild ( document . getElementsByClassName ( 'grid-stack' ) [ 0 ] ) ;
110+ } ) ;
111+ it ( 'should add class grid-stack-animate to the container.' , function ( ) {
112+ var options = {
113+ cellHeight : 80 ,
114+ verticalMargin : 10
115+ } ;
116+ $ ( '.grid-stack' ) . gridstack ( options ) ;
117+ $ ( '.grid-stack' ) . removeClass ( 'grid-stack-animate' ) ;
118+ var grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
119+ grid . setAnimation ( true ) ;
120+ expect ( $ ( '.grid-stack' ) . hasClass ( 'grid-stack-animate' ) ) . toBe ( true ) ;
121+ } ) ;
122+ it ( 'should remove class grid-stack-animate from the container.' , function ( ) {
123+ var options = {
124+ cellHeight : 80 ,
125+ verticalMargin : 10
126+ } ;
127+ $ ( '.grid-stack' ) . gridstack ( options ) ;
128+ $ ( '.grid-stack' ) . addClass ( 'grid-stack-animate' ) ;
129+ var grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
130+ grid . setAnimation ( false ) ;
131+ expect ( $ ( '.grid-stack' ) . hasClass ( 'grid-stack-animate' ) ) . toBe ( false ) ;
132+ } ) ;
133+ } ) ;
134+
135+ describe ( 'grid._setStaticClass' , function ( ) {
136+ beforeEach ( function ( ) {
137+ document . body . insertAdjacentHTML (
138+ 'afterbegin' , gridstackHTML ) ;
139+ } ) ;
140+ afterEach ( function ( ) {
141+ document . body . removeChild ( document . getElementsByClassName ( 'grid-stack' ) [ 0 ] ) ;
142+ } ) ;
143+ it ( 'should add class grid-stack-static to the container.' , function ( ) {
144+ var options = {
145+ cellHeight : 80 ,
146+ verticalMargin : 10 ,
147+ staticGrid : true
148+ } ;
149+ $ ( '.grid-stack' ) . gridstack ( options ) ;
150+ $ ( '.grid-stack' ) . removeClass ( 'grid-stack-static' ) ;
151+ var grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
152+ grid . _setStaticClass ( ) ;
153+ expect ( $ ( '.grid-stack' ) . hasClass ( 'grid-stack-static' ) ) . toBe ( true ) ;
154+ } ) ;
155+ it ( 'should remove class grid-stack-static from the container.' , function ( ) {
156+ var options = {
157+ cellHeight : 80 ,
158+ verticalMargin : 10 ,
159+ staticGrid : false
160+ } ;
161+ $ ( '.grid-stack' ) . gridstack ( options ) ;
162+ $ ( '.grid-stack' ) . addClass ( 'grid-stack-static' ) ;
163+ var grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
164+ grid . _setStaticClass ( ) ;
165+ expect ( $ ( '.grid-stack' ) . hasClass ( 'grid-stack-static' ) ) . toBe ( false ) ;
166+ } ) ;
167+ } ) ;
168+
169+ describe ( 'grid.getCellFromPixel' , function ( ) {
170+ beforeEach ( function ( ) {
171+ document . body . insertAdjacentHTML (
172+ 'afterbegin' , gridstackHTML ) ;
173+ } ) ;
174+ afterEach ( function ( ) {
175+ document . body . removeChild ( document . getElementsByClassName ( 'grid-stack' ) [ 0 ] ) ;
176+ } ) ;
177+ it ( 'should return {x: 2, y: 1}.' , function ( ) {
178+ var options = {
179+ cellHeight : 80 ,
180+ verticalMargin : 10
181+ } ;
182+ $ ( '.grid-stack' ) . gridstack ( options ) ;
183+ var grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
184+ var pixel = { top : 100 , left : 72 } ;
185+ var cell = grid . getCellFromPixel ( pixel ) ;
186+ expect ( cell . x ) . toBe ( 2 ) ;
187+ expect ( cell . y ) . toBe ( 1 ) ;
188+ } ) ;
189+ it ( 'should return {x: 2, y: 1}.' , function ( ) {
190+ var options = {
191+ cellHeight : 80 ,
192+ verticalMargin : 10
193+ } ;
194+ $ ( '.grid-stack' ) . gridstack ( options ) ;
195+ var grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
196+ var pixel = { top : 100 , left : 72 } ;
197+ var cell = grid . getCellFromPixel ( pixel , false ) ;
198+ expect ( cell . x ) . toBe ( 2 ) ;
199+ expect ( cell . y ) . toBe ( 1 ) ;
200+ } ) ;
201+ it ( 'should return {x: 2, y: 1}.' , function ( ) {
202+ var options = {
203+ cellHeight : 80 ,
204+ verticalMargin : 10
205+ } ;
206+ $ ( '.grid-stack' ) . gridstack ( options ) ;
207+ var grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
208+ var pixel = { top : 100 , left : 72 } ;
209+ var cell = grid . getCellFromPixel ( pixel , true ) ;
210+ expect ( cell . x ) . toBe ( 2 ) ;
211+ expect ( cell . y ) . toBe ( 1 ) ;
212+ } ) ;
213+ } ) ;
214+
215+ describe ( 'grid.cellWidth' , function ( ) {
216+ beforeEach ( function ( ) {
217+ document . body . insertAdjacentHTML (
218+ 'afterbegin' , gridstackHTML ) ;
219+ } ) ;
220+ afterEach ( function ( ) {
221+ document . body . removeChild ( document . getElementsByClassName ( 'grid-stack' ) [ 0 ] ) ;
222+ } ) ;
223+ it ( 'should return 96.' , function ( ) {
224+ var options = {
225+ cellHeight : 80 ,
226+ verticalMargin : 10
227+ } ;
228+ $ ( '.grid-stack' ) . gridstack ( options ) ;
229+ var grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
230+ expect ( grid . cellWidth ( ) ) . toBe ( 96 ) ;
231+ } ) ;
232+ } ) ;
233+
234+ describe ( 'grid.minWidth' , function ( ) {
235+ beforeEach ( function ( ) {
236+ document . body . insertAdjacentHTML (
237+ 'afterbegin' , gridstackHTML ) ;
238+ } ) ;
239+ afterEach ( function ( ) {
240+ document . body . removeChild ( document . getElementsByClassName ( 'grid-stack' ) [ 0 ] ) ;
241+ } ) ;
242+ it ( 'should set data-gs-min-width to 2.' , function ( ) {
243+ var options = {
244+ cellHeight : 80 ,
245+ verticalMargin : 10
246+ } ;
247+ $ ( '.grid-stack' ) . gridstack ( options ) ;
248+ var grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
249+ var items = $ ( '.grid-stack-item' ) ;
250+ for ( var i = 0 ; i < items . length ; i ++ ) {
251+ grid . minWidth ( items [ i ] , 2 ) ;
252+ }
253+ for ( var j = 0 ; j < items . length ; j ++ ) {
254+ expect ( parseInt ( $ ( items [ j ] ) . attr ( 'data-gs-min-width' ) , 10 ) ) . toBe ( 2 ) ;
255+ }
256+ } ) ;
257+ } ) ;
258+
259+ describe ( 'grid.maxWidth' , function ( ) {
260+ beforeEach ( function ( ) {
261+ document . body . insertAdjacentHTML (
262+ 'afterbegin' , gridstackHTML ) ;
263+ } ) ;
264+ afterEach ( function ( ) {
265+ document . body . removeChild ( document . getElementsByClassName ( 'grid-stack' ) [ 0 ] ) ;
266+ } ) ;
267+ it ( 'should set data-gs-min-width to 2.' , function ( ) {
268+ var options = {
269+ cellHeight : 80 ,
270+ verticalMargin : 10
271+ } ;
272+ $ ( '.grid-stack' ) . gridstack ( options ) ;
273+ var grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
274+ var items = $ ( '.grid-stack-item' ) ;
275+ for ( var i = 0 ; i < items . length ; i ++ ) {
276+ grid . maxWidth ( items [ i ] , 2 ) ;
277+ }
278+ for ( var j = 0 ; j < items . length ; j ++ ) {
279+ expect ( parseInt ( $ ( items [ j ] ) . attr ( 'data-gs-max-width' ) , 10 ) ) . toBe ( 2 ) ;
280+ }
281+ } ) ;
282+ } ) ;
283+
284+ describe ( 'grid.minHeight' , function ( ) {
285+ beforeEach ( function ( ) {
286+ document . body . insertAdjacentHTML (
287+ 'afterbegin' , gridstackHTML ) ;
288+ } ) ;
289+ afterEach ( function ( ) {
290+ document . body . removeChild ( document . getElementsByClassName ( 'grid-stack' ) [ 0 ] ) ;
291+ } ) ;
292+ it ( 'should set data-gs-min-height to 2.' , function ( ) {
293+ var options = {
294+ cellHeight : 80 ,
295+ verticalMargin : 10
296+ } ;
297+ $ ( '.grid-stack' ) . gridstack ( options ) ;
298+ var grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
299+ var items = $ ( '.grid-stack-item' ) ;
300+ for ( var i = 0 ; i < items . length ; i ++ ) {
301+ grid . minHeight ( items [ i ] , 2 ) ;
302+ }
303+ for ( var j = 0 ; j < items . length ; j ++ ) {
304+ expect ( parseInt ( $ ( items [ j ] ) . attr ( 'data-gs-min-height' ) , 10 ) ) . toBe ( 2 ) ;
305+ }
306+ } ) ;
307+ } ) ;
308+
309+ describe ( 'grid.maxHeight' , function ( ) {
310+ beforeEach ( function ( ) {
311+ document . body . insertAdjacentHTML (
312+ 'afterbegin' , gridstackHTML ) ;
313+ } ) ;
314+ afterEach ( function ( ) {
315+ document . body . removeChild ( document . getElementsByClassName ( 'grid-stack' ) [ 0 ] ) ;
316+ } ) ;
317+ it ( 'should set data-gs-min-height to 2.' , function ( ) {
318+ var options = {
319+ cellHeight : 80 ,
320+ verticalMargin : 10
321+ } ;
322+ $ ( '.grid-stack' ) . gridstack ( options ) ;
323+ var grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
324+ var items = $ ( '.grid-stack-item' ) ;
325+ for ( var i = 0 ; i < items . length ; i ++ ) {
326+ grid . maxHeight ( items [ i ] , 2 ) ;
327+ }
328+ for ( var j = 0 ; j < items . length ; j ++ ) {
329+ expect ( parseInt ( $ ( items [ j ] ) . attr ( 'data-gs-max-height' ) , 10 ) ) . toBe ( 2 ) ;
330+ }
331+ } ) ;
332+ } ) ;
333+ } ) ;
334+
335+ /*
336+ GridStack.prototype.minWidth = function(el, val) {
337+ el = $(el);
338+ el.each(function(index, el) {
339+ el = $(el);
340+ var node = el.data('_gridstack_node');
341+ if (typeof node === 'undefined' || node === null) {
342+ return;
343+ }
344+
345+ if (!isNaN(val)) {
346+ node.minWidth = (val || false);
347+ el.attr('data-gs-min-width', val);
348+ }
349+ });
350+ return this;
351+ };
90352
91353
92- } ) ;
354+ GridStack.prototype.maxHeight = function(el, val) {
355+ el = $(el);
356+ el.each(function(index, el) {
357+ el = $(el);
358+ var node = el.data('_gridstack_node');
359+ if (typeof node === 'undefined' || node === null) {
360+ return;
361+ }
362+
363+ if (!isNaN(val)) {
364+ node.maxHeight = (val || false);
365+ el.attr('data-gs-max-height', val);
366+ }
367+ });
368+ return this;
369+ };
370+
371+ GridStack.prototype.minHeight = function(el, val) {
372+ el = $(el);
373+ el.each(function(index, el) {
374+ el = $(el);
375+ var node = el.data('_gridstack_node');
376+ if (typeof node === 'undefined' || node === null) {
377+ return;
378+ }
379+
380+ if (!isNaN(val)) {
381+ node.minHeight = (val || false);
382+ el.attr('data-gs-min-height', val);
383+ }
384+ });
385+ return this;
386+ };
387+
388+ GridStack.prototype.maxWidth = function(el, val) {
389+ el = $(el);
390+ el.each(function(index, el) {
391+ el = $(el);
392+ var node = el.data('_gridstack_node');
393+ if (typeof node === 'undefined' || node === null) {
394+ return;
395+ }
396+
397+ if (!isNaN(val)) {
398+ node.maxWidth = (val || false);
399+ el.attr('data-gs-max-width', val);
400+ }
401+ });
402+ return this;
403+ };
404+
405+ */
0 commit comments