Skip to content

Commit ae95373

Browse files
committed
Merge pull request #347 from radiolips/feature/237/get-cell-from-position-param
Feature/237/get cell from position param
2 parents b67ac87 + 7880314 commit ae95373

File tree

6 files changed

+13
-9
lines changed

6 files changed

+13
-9
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ Changes
453453
- add `setGridWidth` method ([#227](https://github.com/troolee/gridstack.js/issues/227))
454454
- add `removable`/`removeTimeout`
455455
- add `detachGrid` parameter to `destroy` method ([#216](https://github.com/troolee/gridstack.js/issues/216))
456+
- add `useOffset` parameter to `getCellFromPixel` method ([#237](https://github.com/troolee/gridstack.js/issues/237))
456457

457458
#### v0.2.4 (2016-02-15)
458459

dist/gridstack.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,8 +1300,9 @@
13001300
return Math.ceil(o.outerWidth() / o.attr('data-gs-width'));
13011301
};
13021302

1303-
GridStack.prototype.getCellFromPixel = function(position) {
1304-
var containerPos = this.container.position();
1303+
GridStack.prototype.getCellFromPixel = function(position, useOffset) {
1304+
var containerPos = (typeof useOffset != 'undefined' && useOffset) ?
1305+
this.container.offset() : this.container.position();
13051306
var relativeLeft = position.left - containerPos.left;
13061307
var relativeTop = position.top - containerPos.top;
13071308

dist/gridstack.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/gridstack.min.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ gridstack.js API
2828
- [enable()](#enable)
2929
- [enableMove(doEnable, includeNewWidgets)](#enablemovedoenable-includenewwidgets)
3030
- [enableResize(doEnable, includeNewWidgets)](#enableresizedoenable-includenewwidgets)
31-
- [getCellFromPixel(position)](#getcellfrompixelposition)
31+
- [getCellFromPixel(position[, useOffset])](#getcellfrompixelposition-useoffset)
3232
- [isAreaEmpty(x, y, width, height)](#isareaemptyx-y-width-height)
3333
- [locked(el, val)](#lockedel-val)
3434
- [makeWidget(el)](#makewidgetel)
@@ -262,13 +262,14 @@ Enables/disables widget resizing. `includeNewWidgets` will force new widgets to
262262
grid.resizable(this.container.children('.' + this.opts.itemClass), doEnable);
263263
```
264264

265-
### getCellFromPixel(position)
265+
### getCellFromPixel(position[, useOffset])
266266

267267
Get the position of the cell under a pixel on screen.
268268

269269
Parameters :
270270

271-
- `position` - the position of the pixel to resolve in absolute coordinates, as an object with `top` and `left`properties
271+
- `position` - the position of the pixel to resolve in absolute coordinates, as an object with `top` and `left` properties
272+
- `useOffset` - if `true`, value will be based on offset vs position (Optional. Default `false`). Useful when grid is within `position: relative` element.
272273

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

src/gridstack.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,8 +1300,9 @@
13001300
return Math.ceil(o.outerWidth() / o.attr('data-gs-width'));
13011301
};
13021302

1303-
GridStack.prototype.getCellFromPixel = function(position) {
1304-
var containerPos = this.container.position();
1303+
GridStack.prototype.getCellFromPixel = function(position, useOffset) {
1304+
var containerPos = (typeof useOffset != 'undefined' && useOffset) ?
1305+
this.container.offset() : this.container.position();
13051306
var relativeLeft = position.left - containerPos.left;
13061307
var relativeTop = position.top - containerPos.top;
13071308

0 commit comments

Comments
 (0)