Skip to content

Commit 45d39a0

Browse files
committed
Merge branch 'radiolips-style'
2 parents 12e3d5f + 1527485 commit 45d39a0

File tree

11 files changed

+1263
-887
lines changed

11 files changed

+1263
-887
lines changed

.jscsrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"preset": "google",
3+
"validateIndentation": "\t",
4+
"maximumLineLength": 120,
5+
"jsDoc": {
6+
"checkAnnotations": {
7+
"preset": "jsdoc3",
8+
"extra": {
9+
"preserve": true
10+
}
11+
}
12+
},
13+
"requireCamelCaseOrUpperCaseIdentifiers": true
14+
}

README.md

Lines changed: 60 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Join gridstack.js on Slack: https://gridstackjs.troolee.com
1919
- [Requirements](#requirements)
2020
- [Install](#install)
2121
- [Basic usage](#basic-usage)
22+
- [Migrating to v0.2.5](#migrating-to-v025)
2223
- [Options](#options)
2324
- [Grid attributes](#grid-attributes)
2425
- [Item attributes](#item-attributes)
@@ -31,30 +32,30 @@ Join gridstack.js on Slack: https://gridstackjs.troolee.com
3132
- [disable(event)](#disableevent)
3233
- [enable(event)](#enableevent)
3334
- [API](#api)
34-
- [add_widget(el, x, y, width, height, auto_position)](#add_widgetel-x-y-width-height-auto_position)
35-
- [make_widget(el)](#make_widgetel)
36-
- [batch_update()](#batch_update)
37-
- [cell_height()](#cell_height)
38-
- [cell_height(val)](#cell_heightval)
39-
- [cell_width()](#cell_width)
35+
- [addWidget(el, x, y, width, height, autoPosition)](#addwidgetel-x-y-width-height-autoposition)
36+
- [makeWidget(el)](#makewidgetel)
37+
- [batchUpdate()](#batchupdate)
38+
- [cellHeight()](#cellheight)
39+
- [cellHeight(val)](#cellheightval)
40+
- [cellWidth()](#cellwidth)
4041
- [commit()](#commit)
4142
- [destroy()](#destroy)
4243
- [disable()](#disable)
4344
- [enable()](#enable)
44-
- [get_cell_from_pixel(position)](#get_cell_from_pixelposition)
45-
- [is_area_empty(x, y, width, height)](#is_area_emptyx-y-width-height)
45+
- [getCellFromPixel(position)](#getcellfrompixelposition)
46+
- [isAreaEmpty(x, y, width, height)](#isareaemptyx-y-width-height)
4647
- [locked(el, val)](#lockedel-val)
47-
- [min_width(el, val)](#min_widthel-val)
48-
- [min_height(el, val)](#min_heightel-val)
48+
- [minWidth(el, val)](#minwidthel-val)
49+
- [minHeight(el, val)](#minheightel-val)
4950
- [movable(el, val)](#movableel-val)
5051
- [move(el, x, y)](#moveel-x-y)
51-
- [remove_widget(el, detach_node)](#remove_widgetel-detach_node)
52-
- [remove_all()](#remove_all)
52+
- [removeWidget(el, detachNode)](#removewidgetel-detachnode)
53+
- [removeAll()](#removeall)
5354
- [resize(el, width, height)](#resizeel-width-height)
5455
- [resizable(el, val)](#resizableel-val)
55-
- [set_static(static_value)](#set_staticstatic_value)
56+
- [setStatic(static_value)](#setstaticstatic_value)
5657
- [update(el, x, y, width, height)](#updateel-x-y-width-height)
57-
- [will_it_fit(x, y, width, height, auto_position)](#will_it_fitx-y-width-height-auto_position)
58+
- [willItFit(x, y, width, height, autoPosition)](#willitfitx-y-width-height-autoposition)
5859
- [Utils](#utils)
5960
- [GridStackUI.Utils.sort(nodes[, dir[, width]])](#gridstackuiutilssortnodes-dir-width)
6061
- [Touch devices support](#touch-devices-support)
@@ -151,28 +152,34 @@ $(function () {
151152
</script>
152153
```
153154

155+
## Migrating to v0.2.5
156+
157+
As of v0.2.5 all methods and parameters are in camel case to respect [JavaScript Style Guide and Coding Conventions](http://www.w3schools.com/js/js_conventions.asp).
158+
All old methods and parameters are marked as deprecated and still available but a warning will be displayed in js console. They will be available until v1.0
159+
when they will be completely removed.
160+
154161
## Options
155162

156-
- `always_show_resize_handle` - if `true` the resizing handles are shown even if the user is not hovering over the widget
163+
- `alwaysShowResizeHandle` - if `true` the resizing handles are shown even if the user is not hovering over the widget
157164
(default: `false`)
158165
- `animate` - turns animation on (default: `false`)
159166
- `auto` - if `false` gridstack will not initialize existing items (default: `true`)
160-
- `cell_height` - one cell height (default: `60`). Can be:
167+
- `cellHeight` - one cell height (default: `60`). Can be:
161168
- an integer (px)
162169
- a string (ex: '10em', '100px', '10rem')
163170
- 0 or null, in which case the library will not generate styles for rows. Everything will have to be defined in CSS files.
164171
- `draggable` - allows to override jQuery UI draggable options. (default: `{handle: '.grid-stack-item-content', scroll: true, appendTo: 'body'}`)
165172
- `handle` - draggable handle selector (default: `'.grid-stack-item-content'`)
166-
- `handle_class` - draggable handle class (e.g. `'grid-stack-item-content'`). If set `handle` is ignored (default: `null`)
173+
- `handleClass` - draggable handle class (e.g. `'grid-stack-item-content'`). If set `handle` is ignored (default: `null`)
167174
- `height` - maximum rows amount. Default is `0` which means no maximum rows
168175
- `float` - enable floating widgets (default: `false`) See [example](http://troolee.github.io/gridstack.js/demo/float.html)
169-
- `item_class` - widget class (default: `'grid-stack-item'`)
170-
- `min_width` - minimal width. If window width is less, grid will be shown in one-column mode. You need also update your css file (`@media (max-width: 768px) {...}`) with corresponding value (default: `768`)
171-
- `placeholder_class` - class for placeholder (default: `'grid-stack-placeholder'`)
172-
- `placeholder_text` - placeholder default content (default: `''`)
176+
- `itemClass` - widget class (default: `'grid-stack-item'`)
177+
- `minWidth` - minimal width. If window width is less, grid will be shown in one-column mode. You need also update your css file (`@media (max-width: 768px) {...}`) with corresponding value (default: `768`)
178+
- `placeholderClass` - class for placeholder (default: `'grid-stack-placeholder'`)
179+
- `placeholderText` - placeholder default content (default: `''`)
173180
- `resizable` - allows to override jQuery UI resizable options. (default: `{autoHide: true, handles: 'se'}`)
174-
- `static_grid` - makes grid static (default `false`). If true widgets are not movable/resizable. You don't even need jQueryUI draggable/resizable. A CSS class `grid-stack-static` is also added to the container.
175-
- `vertical_margin` - vertical gap size (default: `20`). Can be:
181+
- `staticGrid` - makes grid static (default `false`). If true widgets are not movable/resizable. You don't even need jQueryUI draggable/resizable. A CSS class `grid-stack-static` is also added to the container.
182+
- `verticalMargin` - vertical gap size (default: `20`). Can be:
176183
- an integer (px)
177184
- a string (ex: '2em', '20px', '2rem')
178185
- `width` - amount of columns (default: `12`)
@@ -204,12 +211,12 @@ to completely lock the widget.
204211
Occurs when adding/removing widgets or existing widgets change their position/size
205212

206213
```javascript
207-
var serialize_widget_map = function (items) {
214+
var serializeWidgetMap = function (items) {
208215
console.log(items);
209216
};
210217

211218
$('.grid-stack').on('change', function (e, items) {
212-
serialize_widget_map(items);
219+
serializeWidgetMap(items);
213220
});
214221
```
215222

@@ -267,15 +274,15 @@ $('.grid-stack').on('enable', function(event) {
267274

268275
## API
269276

270-
### add_widget(el, x, y, width, height, auto_position)
277+
### addWidget(el, x, y, width, height, autoPosition)
271278

272279
Creates new widget and returns it.
273280

274281
Parameters:
275282

276283
- `el` - widget to add
277284
- `x`, `y`, `width`, `height` - widget position/dimensions (Optional)
278-
- `auto_position` - if `true` then `x`, `y` parameters will be ignored and widget will be places on the first available
285+
- `autoPosition` - if `true` then `x`, `y` parameters will be ignored and widget will be places on the first available
279286
position
280287

281288
Widget will be always placed even if result height is more than actual grid height. You need to use `will_it_fit` method
@@ -285,10 +292,10 @@ before calling `add_widget` for additional check.
285292
$('.grid-stack').gridstack();
286293

287294
var grid = $('.grid-stack').data('gridstack');
288-
grid.add_widget(el, 0, 0, 3, 2, true);
295+
grid.addWidget(el, 0, 0, 3, 2, true);
289296
```
290297

291-
### make_widget(el)
298+
### makeWidget(el)
292299

293300
If you add elements to your gridstack container by hand, you have to tell gridstack afterwards to make them widgets. If you want gridstack to add the elements for you, use `add_widget` instead.
294301
Makes the given element a widget and returns it.
@@ -302,33 +309,33 @@ $('.grid-stack').gridstack();
302309

303310
$('.grid-stack').append('<div id="gsi-1" data-gs-x="0" data-gs-y="0" data-gs-width="3" data-gs-height="2" data-gs-auto-position="1"></div>')
304311
var grid = $('.grid-stack').data('gridstack');
305-
grid.make_widget('gsi-1');
312+
grid.makeWidget('gsi-1');
306313
```
307314

308-
### batch_update()
315+
### batchUpdate()
309316

310317
Initailizes batch updates. You will see no changes until `commit` method is called.
311318

312-
### cell_height()
319+
### cellHeight()
313320

314321
Gets current cell height.
315322

316-
### cell_height(val)
323+
### cellHeight(val)
317324

318325
Update current cell height. This method rebuilds an internal CSS stylesheet. Note: You can expect performance issues if
319326
call this method too often.
320327

321328
```javascript
322-
grid.cell_height(grid.cell_width() * 1.2);
329+
grid.cellHeight(grid.cell_width() * 1.2);
323330
```
324331

325-
### cell_width()
332+
### cellWidth()
326333

327334
Gets current cell width.
328335

329336
### commit()
330337

331-
Finishes batch updates. Updates DOM nodes. You must call it after `batch_update`.
338+
Finishes batch updates. Updates DOM nodes. You must call it after `batchUpdate`.
332339

333340
### destroy()
334341

@@ -352,7 +359,7 @@ grid.movable('.grid-stack-item', true);
352359
grid.resizable('.grid-stack-item', true);
353360
```
354361

355-
### get_cell_from_pixel(position)
362+
### getCellFromPixel(position)
356363

357364
Get the position of the cell under a pixel on screen.
358365

@@ -362,7 +369,7 @@ Parameters :
362369

363370
Returns an object with properties `x` and `y` i.e. the column and row in the grid.
364371

365-
### is_area_empty(x, y, width, height)
372+
### isAreaEmpty(x, y, width, height)
366373

367374
Checks if specified area is empty.
368375

@@ -373,14 +380,14 @@ Locks/unlocks widget.
373380
- `el` - widget to modify.
374381
- `val` - if `true` widget will be locked.
375382

376-
### min_width(el, val)
383+
### minWidth(el, val)
377384

378385
Set the minWidth for a widget.
379386

380387
- `el` - widget to modify.
381388
- `val` - A numeric value of the number of columns
382389

383-
### min_height(el, val)
390+
### minHeight(el, val)
384391

385392
Set the minHeight for a widget.
386393

@@ -403,16 +410,16 @@ Parameters:
403410
- `el` - widget to move
404411
- `x`, `y` - new position. If value is `null` or `undefined` it will be ignored.
405412

406-
### remove_widget(el, detach_node)
413+
### removeWidget(el, detachNode)
407414

408415
Removes widget from the grid.
409416

410417
Parameters:
411418

412419
- `el` - widget to remove.
413-
- `detach_node` - if `false` DOM node won't be removed from the tree (Optional. Default `true`).
420+
- `detachNode` - if `false` DOM node won't be removed from the tree (Optional. Default `true`).
414421

415-
### remove_all()
422+
### removeAll()
416423

417424
Removes all widgets from the grid.
418425

@@ -432,7 +439,7 @@ Enables/Disables resizing.
432439
- `el` - widget to modify
433440
- `val` - if `true` widget will be resizable.
434441

435-
### set_static(static_value)
442+
### setStatic(static_value)
436443

437444
Toggle the grid static state. Also toggle the `grid-stack-static` class.
438445

@@ -448,14 +455,14 @@ Parameters:
448455

449456
Updates widget position/size.
450457

451-
### will_it_fit(x, y, width, height, auto_position)
458+
### willItFit(x, y, width, height, autoPosition)
452459

453460
Returns `true` if the `height` of the grid will be less the vertical constraint. Always returns `true` if grid doesn't
454461
have `height` constraint.
455462

456463
```javascript
457-
if (grid.will_it_fit(new_node.x, new_node.y, new_node.width, new_node.height, true)) {
458-
grid.add_widget(new_node.el, new_node.x, new_node.y, new_node.width, new_node.height, true);
464+
if (grid.willItFit(newNode.x, newNode.y, newNode.width, newNode.height, true)) {
465+
grid.addWidget(newNode.el, newNode.x, newNode.y, newNode.width, newNode.height, true);
459466
}
460467
else {
461468
alert('Not enough free space to place the widget');
@@ -487,7 +494,7 @@ working on touch-based devices.
487494
<script src="gridstack.js"></script>
488495
```
489496

490-
Also `always_show_resize_handle` option may be useful:
497+
Also `alwaysShowResizeHandle` option may be useful:
491498

492499
```javascript
493500
$(function () {
@@ -517,9 +524,9 @@ ko.components.register('dashboard-grid', {
517524
}
518525

519526
var item = _.find(items, function (i) { return i.nodeType == 1 });
520-
grid.add_widget(item);
527+
grid.addWidget(item);
521528
ko.utils.domNodeDisposal.addDisposeCallback(item, function () {
522-
grid.remove_widget(item);
529+
grid.removeWidget(item);
523530
});
524531
};
525532
};
@@ -695,10 +702,10 @@ var serialization = [
695702
serialization = GridStackUI.Utils.sort(serialization);
696703

697704
var grid = $('.grid-stack').data('gridstack');
698-
grid.remove_all();
705+
grid.removeAll();
699706

700707
_.each(serialization, function (node) {
701-
grid.add_widget($('<div><div class="grid-stack-item-content" /></div>'),
708+
grid.addWidget($('<div><div class="grid-stack-item-content" /></div>'),
702709
node.x, node.y, node.width, node.height);
703710
});
704711
```
@@ -781,6 +788,7 @@ Changes
781788
#### v0.2.5-dev (Development version)
782789

783790
- `cell_height` and `vertical_margin` can now be string (e.g. '3em', '20px') (Thanks to @jlowcs)
791+
- update names to respect js naming convention
784792

785793
#### v0.2.4 (2016-02-15)
786794

demo/float.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,19 @@ <h1>Float grid demo</h1>
6868

6969
this.grid = $('.grid-stack').data('gridstack');
7070

71-
this.add_new_widget = function () {
71+
this.addNewWidget = function () {
7272
var node = this.items.pop() || {
7373
x: 12 * Math.random(),
7474
y: 5 * Math.random(),
7575
width: 1 + 3 * Math.random(),
7676
height: 1 + 3 * Math.random()
7777
};
78-
this.grid.add_widget($('<div><div class="grid-stack-item-content" /><div/>'),
78+
this.grid.addWidget($('<div><div class="grid-stack-item-content" /><div/>'),
7979
node.x, node.y, node.width, node.height);
80+
return false;
8081
}.bind(this);
8182

82-
$('#add-new-widget').click(this.add_new_widget);
83+
$('#add-new-widget').click(this.addNewWidget);
8384
};
8485
});
8586
</script>

demo/knockout.html

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<h1>knockout.js Demo</h1>
3939

4040
<div>
41-
<button data-bind="click: add_new_widget">Add new widget</button>
41+
<button data-bind="click: addNewWidget">Add new widget</button>
4242
</div>
4343

4444
<br>
@@ -64,9 +64,9 @@ <h1>knockout.js Demo</h1>
6464
}
6565

6666
var item = _.find(items, function (i) { return i.nodeType == 1 });
67-
grid.add_widget(item);
67+
grid.addWidget(item);
6868
ko.utils.domNodeDisposal.addDisposeCallback(item, function () {
69-
grid.remove_widget(item);
69+
grid.removeWidget(item);
7070
});
7171
};
7272
};
@@ -78,7 +78,7 @@ <h1>knockout.js Demo</h1>
7878
[
7979
'<div class="grid-stack" data-bind="foreach: {data: widgets, afterRender: afterAddWidget}">',
8080
' <div class="grid-stack-item" data-bind="attr: {\'data-gs-x\': $data.x, \'data-gs-y\': $data.y, \'data-gs-width\': $data.width, \'data-gs-height\': $data.height, \'data-gs-auto-position\': $data.auto_position}">',
81-
' <div class="grid-stack-item-content"><button data-bind="click: $root.delete_widget">Delete me</button></div>',
81+
' <div class="grid-stack-item-content"><button data-bind="click: $root.deleteWidget">Delete me</button></div>',
8282
' </div>',
8383
'</div> '
8484
].join('')
@@ -90,18 +90,20 @@ <h1>knockout.js Demo</h1>
9090

9191
this.widgets = ko.observableArray(widgets);
9292

93-
this.add_new_widget = function () {
93+
this.addNewWidget = function () {
9494
this.widgets.push({
9595
x: 0,
9696
y: 0,
9797
width: Math.floor(1 + 3 * Math.random()),
9898
height: Math.floor(1 + 3 * Math.random()),
9999
auto_position: true
100100
});
101+
return false;
101102
};
102103

103-
this.delete_widget = function (item) {
104+
this.deleteWidget = function (item) {
104105
self.widgets.remove(item);
106+
return false;
105107
};
106108
};
107109

0 commit comments

Comments
 (0)