Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions demo/column.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="../dist/jquery-ui.min.js"></script>
<script src="../src/gridstack-poly.js"></script>
<script src="../src/gridstack.js"></script>
<script src="../src/gridstack.jQueryUI.js"></script>
</head>
Expand All @@ -36,9 +37,9 @@ <h1>setColumn() grid demo</h1>
$grid.gridstack({float: true});
grid = $grid.data('gridstack');

$grid.on('added', (e, items) => log(' added ', items));
$grid.on('removed', (e, items) => log(' removed ', items));
$grid.on('change', (e, items) => log(' change ', items));
$grid.on('added', function(e, items) {log(' added ', items)});
$grid.on('removed', function(e, items) {log(' removed ', items)});
$grid.on('change', function(e, items) {log(' change ', items)});
function log(type, items) {
if (!items) { return; }
var str = '';
Expand All @@ -63,7 +64,7 @@ <h1>setColumn() grid demo</h1>
};
grid.commit();

$('#add-widget').click(() => {
$('#add-widget').click(function() {
var node = items.pop() || {
x: Math.round(12 * Math.random()),
y: Math.round(5 * Math.random()),
Expand All @@ -73,15 +74,15 @@ <h1>setColumn() grid demo</h1>
grid.addWidget($('<div><div class="grid-stack-item-content">' + count++ + '</div></div>'), node);
});

$('#1column').click(() => { grid.setColumn(1); });
$('#2column').click(() => { grid.setColumn(2); });
$('#3column').click(() => { grid.setColumn(3); });
$('#4column').click(() => { grid.setColumn(4); });
$('#6column').click(() => { grid.setColumn(6); });
$('#6column').click(() => { grid.setColumn(6); });
$('#8column').click(() => { grid.setColumn(8); });
$('#10column').click(() => { grid.setColumn(10); });
$('#12column').click(() => { grid.setColumn(12); });
$('#1column').click(function() { grid.setColumn(1); });
$('#2column').click(function() { grid.setColumn(2); });
$('#3column').click(function() { grid.setColumn(3); });
$('#4column').click(function() { grid.setColumn(4); });
$('#6column').click(function() { grid.setColumn(6); });
$('#6column').click(function() { grid.setColumn(6); });
$('#8column').click(function() { grid.setColumn(8); });
$('#10column').click(function() { grid.setColumn(10); });
$('#12column').click(function() { grid.setColumn(12); });
});
</script>
</body>
Expand Down
49 changes: 48 additions & 1 deletion src/gridstack-poly.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Number.isNaN = Number.isNaN || function isNaN(input) {
return typeof input === 'number' && input !== input;
}

// https://tc39.github.io/ecma262/#sec-array.prototype.find
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
if (!Array.prototype.find) {
Object.defineProperty(Array.prototype, 'find', {
value: function (predicate) {
Expand Down Expand Up @@ -55,4 +55,51 @@ if (!Array.prototype.find) {
configurable: true,
writable: true
});
}

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex
if (!Array.prototype.findIndex) {
Object.defineProperty(Array.prototype, 'findIndex', {
value: function(predicate) {
// 1. Let O be ? ToObject(this value).
if (this == null) {
throw new TypeError('"this" is null or not defined');
}

var o = Object(this);

// 2. Let len be ? ToLength(? Get(O, "length")).
var len = o.length >>> 0;

// 3. If IsCallable(predicate) is false, throw a TypeError exception.
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function');
}

// 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
var thisArg = arguments[1];

// 5. Let k be 0.
var k = 0;

// 6. Repeat, while k < len
while (k < len) {
// a. Let Pk be ! ToString(k).
// b. Let kValue be ? Get(O, Pk).
// c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
// d. If testResult is true, return k.
var kValue = o[k];
if (predicate.call(thisArg, kValue, k, o)) {
return k;
}
// e. Increase k by 1.
k++;
}

// 7. Return -1.
return -1;
},
configurable: true,
writable: true
});
}
2 changes: 1 addition & 1 deletion src/jquery-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ $.Widget.prototype = {

if ( typeof key === "string" ) {

// Handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
// Handle nested keys, e.g., "foo.bar" = { foo: { bar: ___ } }
options = {};
parts = key.split( "." );
key = parts.shift();
Expand Down