Skip to content

Commit fdac3df

Browse files
authored
Merge pull request #1158 from adumesny/jq
removed jQuery from all API **BREAKING**
2 parents 2648ea9 + 69de624 commit fdac3df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+12830
-1927
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
dist/*.js
22
demo/*
33
spec/*
4+
src/jquery.js
45
src/jquery-ui.js

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: node_js
22
node_js:
3-
- 8.11.1
3+
- 8.17.0
44
dist: trusty
55
sudo: required
66
addons:

Gruntfile.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ module.exports = function(grunt) {
1010
grunt.loadNpmTasks('grunt-contrib-connect');
1111
grunt.loadNpmTasks('grunt-protractor-webdriver');
1212

13+
const sass = require('node-sass');
14+
1315
grunt.initConfig({
1416
sass: {
17+
options: {
18+
implementation: sass,
19+
sourceMap: true
20+
},
1521
dist: {
1622
files: {
1723
'dist/gridstack.css': 'src/gridstack.scss',
@@ -37,8 +43,10 @@ module.exports = function(grunt) {
3743
files: {
3844
'dist/gridstack.js': ['src/gridstack.js'],
3945
'dist/gridstack.d.ts': ['src/gridstack.d.ts'],
46+
'dist/gridstack.all.d.ts': ['src/gridstack.d.ts'],
4047
'dist/gridstack.jQueryUI.js': ['src/gridstack.jQueryUI.js'],
4148
'dist/gridstack-poly.js': ['src/gridstack-poly.js'],
49+
'dist/jquery.js': ['src/jquery.js'],
4250
'dist/jquery-ui.js': ['src/jquery-ui.js'],
4351
}
4452
}
@@ -57,8 +65,9 @@ module.exports = function(grunt) {
5765
'dist/gridstack.min.js': ['src/gridstack.js'],
5866
'dist/gridstack.jQueryUI.min.js': ['src/gridstack.jQueryUI.js'],
5967
'dist/gridstack-poly.min.js': ['src/gridstack-poly.js'],
68+
'dist/jquery.min.js': ['src/jquery.js'],
6069
'dist/jquery-ui.min.js': ['src/jquery-ui.js'],
61-
'dist/gridstack.all.js': ['src/gridstack-poly.js', 'src/gridstack.js', 'src/jquery-ui.js', 'src/gridstack.jQueryUI.js']
70+
'dist/gridstack.all.js': ['src/gridstack-poly.js', 'src/jquery.js', 'src/gridstack.js', 'src/jquery-ui.js', 'src/gridstack.jQueryUI.js']
6271
}
6372
}
6473
},

README.md

Lines changed: 106 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
gridstack.js
22
============
33

4-
[![Build Status](https://travis-ci.org/gridstack/gridstack.js.svg?branch=develop)](https://travis-ci.org/gridstack/gridstack.js)
5-
[![Coverage Status](https://coveralls.io/repos/github/gridstack/gridstack.js/badge.svg?branch=develop)](https://coveralls.io/github/gridstack/gridstack.js?branch=develop)
4+
[![NPM version](https://img.shields.io/npm/v/gridstack.svg)](https://www.npmjs.com/package/gridstack)
65
[![Dependency Status](https://david-dm.org/gridstack/gridstack.js.svg)](https://david-dm.org/gridstack/gridstack.js)
76
[![devDependency Status](https://david-dm.org/gridstack/gridstack.js/dev-status.svg)](https://david-dm.org/gridstack/gridstack.js#info=devDependencies)
7+
[![Coverage Status](https://coveralls.io/repos/github/gridstack/gridstack.js/badge.svg?branch=develop)](https://coveralls.io/github/gridstack/gridstack.js?branch=develop)
8+
[![downloads](https://img.shields.io/npm/dm/gridstack.svg)](https://www.npmjs.com/package/gridstack)
9+
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/alaind831)
810

9-
Mobile-friendly Javascript library for dashboard layout and creation. Making a drag-and-drop, multi-column dashboard has never been easier. Allows you to build draggable, responsive bootstrap v3-friendly layouts. It also has multiple bindings and works great with [React](https://reactjs.org/), [Angular](https://angular.io/), [Knockout.js](http://knockoutjs.com), [Ember](https://www.emberjs.com/) and others, and comes with a Typescript definition out of the box.
11+
Mobile-friendly Javascript library (with Typescript bindings) for dashboard layout and creation. Making a drag-and-drop, multi-column responsive dashboard has never been easier. Allows you to build draggable, responsive bootstrap v4-friendly layouts. It also has multiple bindings and works great with [React](https://reactjs.org/), [Angular](https://angular.io/), [Knockout.js](http://knockoutjs.com), [Ember](https://www.emberjs.com/) and others. Includes Typescript defines.
1012

11-
Inspired by no-longer maintained gridster.js, built with love.
13+
Inspired by no-longer maintained gridster, built with love.
1214

1315
Please visit http://gridstackjs.com and [these demos](http://gridstackjs.com/demo/).
1416

17+
If you find this lib useful, please [donate](https://www.paypal.me/alaind831) and help support it!
18+
1519
Join us on Slack: https://gridstackjs.troolee.com
1620

1721
[![Slack Status](https://gridstackjs.troolee.com/badge.svg)](https://gridstackjs.troolee.com)
@@ -28,12 +32,12 @@ Join us on Slack: https://gridstackjs.troolee.com
2832
- [Requirements](#requirements)
2933
- [API Documentation](#api-documentation)
3034
- [Extend Library](#extend-library)
31-
- [Touch devices support](#touch-devices-support)
3235
- [gridstack.js for specific frameworks](#gridstackjs-for-specific-frameworks)
3336
- [Change grid columns](#change-grid-columns)
3437
- [Custom columns CSS](#custom-columns-css)
3538
- [Override resizable/draggable options](#override-resizabledraggable-options)
36-
- [Migrating to v0.3.0](#migrating-to-v030)
39+
- [Touch devices support](#touch-devices-support)
40+
- [Migrating to v1.0.0](#migrating-to-v100)
3741
- [Changes](#changes)
3842
- [The Team](#the-team)
3943

@@ -43,7 +47,7 @@ Join us on Slack: https://gridstackjs.troolee.com
4347
Demo and examples
4448
====
4549

46-
Please visit http://gridstackjs.com and [these demos](http://gridstackjs.com/demo/).
50+
Please visit http://gridstackjs.com and [these demos](http://gridstackjs.com/demo/)
4751

4852

4953
Usage
@@ -56,39 +60,43 @@ Usage
5660
[![NPM version](https://img.shields.io/npm/v/gridstack.svg)](https://www.npmjs.com/package/gridstack)
5761

5862
```bash
59-
$ yarn install gridstack
63+
yarn install gridstack
64+
or
65+
npm install --save gridstack
6066
```
6167

6268
## Include
6369

6470
* local:
6571

66-
6772
```html
68-
<link rel="stylesheet" href="gridstack.css" />
69-
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
73+
<link rel="stylesheet" href="gridstack.min.css" />
7074
<script src="gridstack.all.js"></script>
7175
```
7276

7377
* Using CDN (minimized):
7478

7579
```html
76-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gridstack@0.6.4/dist/gridstack.min.css" />
77-
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
78-
<script src="https://cdn.jsdelivr.net/npm/gridstack@0.6.4/dist/gridstack.all.js"></script>
80+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gridstack@1.0.0/dist/gridstack.min.css" />
81+
<script src="https://cdn.jsdelivr.net/npm/gridstack@1.0.0/dist/gridstack.all.js"></script>
7982
```
8083

81-
* Using CDN (debug):
84+
if you need to debug, look at the git demo/ examples for non min includes.
85+
86+
## Basic usage
87+
88+
creating items dynamically...
8289

8390
```html
84-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gridstack@0.6.4/dist/gridstack.css" />
85-
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
86-
<script src="https://cdn.jsdelivr.net/npm/gridstack@0.6.4/dist/gridstack.js"></script>
87-
<script src="https://cdn.jsdelivr.net/npm/gridstack@0.6.4/dist/jquery-ui.js"></script>
88-
<script src="https://cdn.jsdelivr.net/npm/gridstack@0.6.4/dist/gridstack.jQueryUI.js"></script>
91+
<div class="grid-stack"></div>
92+
93+
<script type="text/javascript">
94+
var grid = GridStack.init();
95+
grid.addWidget('<div class="grid-stack-item"><div class="grid-stack-item-content"> test </div></div>', {width: 2});
96+
</script>
8997
```
9098

91-
## Basic usage
99+
... or DOM created items
92100

93101
```html
94102
<div class="grid-stack">
@@ -101,27 +109,15 @@ $ yarn install gridstack
101109
</div>
102110

103111
<script type="text/javascript">
104-
$(function () {
105-
$('.grid-stack').gridstack();
106-
});
112+
GridStack.init();
107113
</script>
108114
```
109115

110116
see [jsfiddle sample](https://jsfiddle.net/adumesny/jqhkry7g) as running example too.
111117

112118
## Requirements
113119

114-
* [jQuery](http://jquery.com) (>= 1.8)
115-
* `Array.prototype.find`, and `Number.isNaN()` for IE and older browsers.
116-
* Note: as of v0.5.4 We supply a separate `gridstack-poly.js` for that
117-
(part of `gridstack.all.js`) or you can look at other pollyfills
118-
([core.js](https://github.com/zloirock/core-js#ecmascript-6-array) and [mozilla.org](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)).
119-
120-
Using gridstack.js with jQuery UI
121-
122-
* [jQuery UI](http://jqueryui.com) (>= 1.12.0). Minimum required components: Draggable, Droppable, Resizable (Widget, Mouse, core).
123-
* Note: as of v0.5.4 we include this subset as `jquery-ui.js` (and min.js) which is part of `gridstack.all.js`. If you wish to bring your own lib, include the individual gridstack parts instead of all.js
124-
* (Optional) [jquery-ui-touch-punch](https://github.com/furf/jquery-ui-touch-punch) for touch-based devices support
120+
Gridstack no longer requires external dependencies as of v1.0.0 (lodash was removed in v0.5.0 and jquery API in v1.0.0). All you need to include is `gridstack.all.js` and `gridstack.css` (layouts are done using CSS column based %).
125121

126122
## API Documentation
127123

@@ -132,48 +128,18 @@ Documentation can be found [here](https://github.com/gridstack/gridstack.js/tree
132128

133129
You can easily extend or patch gridstack with code like this:
134130

135-
```javascript
136-
$(function () {
137-
// extend gridstack with our own custom method
138-
window.GridStackUI.prototype.printCount = function() {
139-
console.log('grid has ' + this.grid.nodes.length + ' items');
140-
};
141-
142-
$('.grid-stack').gridstack();
143-
144-
// you can now call on any grid this...
145-
$('.grid-stack').data('gridstack').printCount();
146-
});
147-
```
148-
149-
## Touch devices support
150-
151-
Please use [jQuery UI Touch Punch](https://github.com/furf/jquery-ui-touch-punch) to make jQuery UI Draggable/Resizable
152-
working on touch-based devices.
153-
154-
```html
155-
<script src="core-js/client/shim.min.js"></script>
156-
<script src="jquery.min.js"></script>
157-
<script src="jquery-ui.min.js"></script>
158-
<script src="jquery.ui.touch-punch.min.js"></script>
131+
```js
132+
// extend gridstack with our own custom method
133+
GridStack.prototype.printCount = function() {
134+
console.log('grid has ' + this.grid.nodes.length + ' items');
135+
};
159136

160-
<script src="gridstack.js"></script>
161-
```
137+
var grid = GridStack.init();
162138

163-
Also `alwaysShowResizeHandle` option may be useful:
164-
165-
```javascript
166-
$(function () {
167-
var options = {
168-
alwaysShowResizeHandle: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
169-
};
170-
$('.grid-stack').gridstack(options);
171-
});
139+
// you can now call
140+
grid.printCount();
172141
```
173142

174-
If you're still experiencing issues on touch devices please check [#444](https://github.com/gridstack/gridstack.js/issues/444)
175-
176-
177143
## gridstack.js for specific frameworks
178144

179145
search for ['gridstack' under NPM](https://www.npmjs.com/search?q=gridstack&ranking=popularity) for latest, more to come...
@@ -190,7 +156,7 @@ GridStack makes it very easy if you need [1-12] columns out of the box (default
190156

191157
1) Change the `column` grid option when creating a grid to your number N
192158
```js
193-
$('.grid-stack').gridstack( {column: N} );
159+
GridStack.init( {column: N} );
194160
```
195161

196162
2) include `gridstack-extra.css` if **N < 12** (else custom CSS - see next). Without these, things will not render/work correctly.
@@ -260,32 +226,85 @@ and also have the `.grid-stack-N` prefix to support letting the user change colu
260226
You can override default `resizable`/`draggable` options. For instance to enable other then bottom right resizing handle
261227
you can init gridstack like:
262228

263-
```javascript
264-
$('.grid-stack').gridstack({
229+
```js
230+
GridStack.init({
265231
resizable: {
266232
handles: 'e, se, s, sw, w'
267233
}
268234
});
269235
```
270236

271-
Note: It's not recommended to enable `nw`, `n`, `ne` resizing handles. Their behaviour may be unexpected.
272-
273-
## Migrating to v0.3.0
237+
Note: It's not recommended to enable `nw`, `n`, `ne` resizing handles. Their behavior may be unexpected.
274238

275-
As of v0.3.0, gridstack introduces a new plugin system. The drag'n'drop functionality has been modified to take advantage of this system. Because of this, and to avoid dependency on core code from jQuery UI, the plugin functionality was moved to a separate file.
239+
## Touch devices support
276240

277-
To ensure gridstack continues to work, either include the additional `gridstack.jQueryUI.js` file into your HTML or use `gridstack.all.js`:
241+
Please use [jQuery UI Touch Punch](https://github.com/furf/jquery-ui-touch-punch) to make jQuery UI Draggable/Resizable
242+
working on touch-based devices.
278243

279-
```html
280-
<script src="gridstack.js"></script>
281-
<script src="gridstack.jQueryUI.js"></script>
282-
```
283-
or
284244
```html
285245
<script src="gridstack.all.js"></script>
246+
<script src="jquery.ui.touch-punch.min.js"></script>
286247
```
287248

288-
We're working on implementing support for other drag'n'drop libraries through the new plugin system.
249+
Also `alwaysShowResizeHandle` option may be useful:
250+
251+
```js
252+
var options = {
253+
alwaysShowResizeHandle: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
254+
};
255+
GridStack.init(options);
256+
```
257+
258+
If you're still experiencing issues on touch devices please check [#444](https://github.com/gridstack/gridstack.js/issues/444)
259+
260+
261+
## Migrating to v1.0.0
262+
263+
v1.0.0 removed Jquery from the API and external dependencies, which will require some code changes. Here is a list of the changes:
264+
265+
1. your code only needs to include `gridstack.all.js` and `gristack.css` (don't include other) and is recommended you do that as internal dependencies will change. Right now jquery+jquery-ui (trimmed versions) are still being used internally for a short while.
266+
267+
2. code change:
268+
269+
**OLD** initializing code + adding a widget + adding an event:
270+
```js
271+
// initialization returned Jquery element, requiring second call to get GridStack var
272+
$('.grid-stack').gridstack(opts?);
273+
var grid = $('.grid-stack').data('grid-stack');
274+
275+
// returned Jquery element
276+
grid.addWidget($('<div><div class="grid-stack-item-content"> test </div></div>'), {width: 2});
277+
278+
// jquery event handler
279+
$('.grid-stack').on('added', function(e, items) {/* items contains info */});
280+
281+
```
282+
**NEW**
283+
```js
284+
// element identifier defaults to '.grid-stack', returns the grid
285+
// for Typescript use window.GridStack.init()
286+
var grid = GridStack.init(opts?, element?);
287+
288+
// returns DOM element
289+
grid.addWidget('<div><div class="grid-stack-item-content"> test </div></div>', {width: 2});
290+
291+
// event handler
292+
grid.on('added', function(e, items) {/* items contains info */});
293+
294+
```
295+
296+
Other vars/global changes
297+
```
298+
`GridStackUI` --> `GridStack`
299+
`GridStackUI.GridStackEngine` --> `GridStack.Engine`
300+
`grid.container` (jquery grid wrapper) --> `grid.el` (grid DOM element)
301+
`grid.grid` (GridStackEngine) --> `grid.engine`
302+
`grid.setColumn(N)` --> `grid.column(N)` and new `grid.column()` to get value, old API still supported though
303+
```
304+
305+
Recommend looking at the [many samples](../demo) for more code examples.
306+
307+
We're working on implementing support for other drag'n'drop libraries through the plugin system. Right now it is still jquery-ui based (but minimal build content)
289308
290309
Changes
291310
=====

0 commit comments

Comments
 (0)