mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-28 00:24:21 +02:00
update dependencies and jshint
This commit is contained in:
+2
-2
@@ -1,6 +1,6 @@
|
||||
//Based on https://github.com/jonnyreeves/qunit-require
|
||||
/* global require */
|
||||
"use strict";
|
||||
/* global require, QUnit*/
|
||||
'use strict';
|
||||
require.config({
|
||||
//set the baseUrl to the src dir so that gridster
|
||||
//AMD modules can be found.
|
||||
|
||||
Vendored
+1
@@ -1,3 +1,4 @@
|
||||
define(['jquery'], function (jq) {
|
||||
'use strict';
|
||||
return jq.noConflict( true );
|
||||
});
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
/*global QUnit:false, module:false, test:false, asyncTest:false, expect:false*/
|
||||
/*global start:false, stop:false ok:false, equal:false, notEqual:false, deepEqual:false*/
|
||||
/*global notDeepEqual:false, strictEqual:false, notStrictEqual:false, raises:false*/
|
||||
//jshint quotmark:false
|
||||
/*global module:false, test:false */
|
||||
/*global ok:false, equal:false, notEqual:false, deepEqual:false*/
|
||||
/*global notDeepEqual:false */
|
||||
(function ($) {
|
||||
|
||||
'use strict';
|
||||
/*
|
||||
======== A Handy Little QUnit Reference ========
|
||||
http://docs.jquery.com/QUnit
|
||||
@@ -117,13 +118,11 @@
|
||||
});
|
||||
|
||||
test('get_highest_occupied_cell', 1, function () {
|
||||
var input = {col: 2, row: 3, size_x: 3, size_y: 1};
|
||||
var grid = this.el.gridster().data('gridster');
|
||||
deepEqual(grid.get_min_col(), 1);
|
||||
});
|
||||
|
||||
test('get_highest_occupied_cell', 1, function () {
|
||||
var input = {col: 2, row: 3, size_x: 3, size_y: 1};
|
||||
var grid = this.el.gridster().data('gridster');
|
||||
deepEqual(grid.get_highest_occupied_cell(), {col: 3, row: 2});
|
||||
});
|
||||
@@ -172,7 +171,7 @@
|
||||
grid.add_widget('<li />', this.size_x, this.size_y, this.col, this.row);
|
||||
});
|
||||
equal(grid.get_num_widgets(), numBefore + this.resizeGrid.length, 'Loading the widgets to prepare for tests');
|
||||
var row, col;
|
||||
|
||||
//check for widgets in the space it will occupy
|
||||
var widgets = grid.get_widgets_in_range(1,1,2,2);
|
||||
var numberInSpaceBefore = widgets.length;
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
/* global u, SPEED*/
|
||||
|
||||
'use strict';
|
||||
|
||||
window.serialization = {
|
||||
'default': function() {
|
||||
return [
|
||||
{name: 'A', col: 1, row: 1, size_x: 1, size_y: 2},
|
||||
{name: 'B', col: 2, row: 1, size_x: 3, size_y: 2},
|
||||
{name: 'C', col: 5, row: 1, size_x: 3, size_y: 2},
|
||||
{name: 'D', col: 8, row: 1, size_x: 2, size_y: 1},
|
||||
{name: 'E', col: 1, row: 3, size_x: 4, size_y: 1},
|
||||
{name: 'F', col: 10, row: 1, size_x: 1, size_y: 2},
|
||||
{name: 'G', col: 8, row: 2, size_x: 2, size_y: 1},
|
||||
{name: 'H', col: 5, row: 3, size_x: 3, size_y: 2},
|
||||
{name: 'I', col: 8, row: 3, size_x: 1, size_y: 1},
|
||||
{name: 'J', col: 9, row: 3, size_x: 2, size_y: 2},
|
||||
{name: 'K', col: 1, row: 4, size_x: 1, size_y: 3}
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
window.u = {
|
||||
pick: function(data, prop) {
|
||||
return data.map(function(elm) {
|
||||
return elm[prop];
|
||||
});
|
||||
},
|
||||
|
||||
getRandomColor: function() {
|
||||
var letters = '0123456789ABCDEF'.split('');
|
||||
var color = '#';
|
||||
for (var i = 0; i < 6; i++) {
|
||||
color += letters[Math.round(Math.random() * 10)];
|
||||
}
|
||||
return color;
|
||||
},
|
||||
|
||||
createGridster: function(config, serialize, fromDom) {
|
||||
var defaults = {
|
||||
widget_margins: [5, 5],
|
||||
widget_base_dimensions: [100, 55],
|
||||
min_cols: 10,
|
||||
max_cols: 10
|
||||
};
|
||||
|
||||
serialize || (serialize = window.serialization.default());
|
||||
|
||||
var widgets = [];
|
||||
$.each(serialize, function(i, w) {
|
||||
widgets.push(['<li>' + w.name + '</li>', w.size_x, w.size_y, w.col, w.row]);
|
||||
});
|
||||
|
||||
this.$fixture = $('#fixture');
|
||||
this.$fixture.html('<div class="gridster"><ul></ul></div>');
|
||||
this.$el = $('.gridster > ul');
|
||||
|
||||
if (fromDom) {
|
||||
var html = [];
|
||||
$.each(serialize, function(i, w) {
|
||||
html.push('<li data-col="' + w.col + '" data-row="' + w.row + '" data-sizex="' + w.size_x + '" data-sizey="' + w.size_y + '">' + w.name + '</li>');
|
||||
});
|
||||
this.$el.html(html.join('\n'));
|
||||
}
|
||||
|
||||
this.gridster = this.$el.gridster(
|
||||
$.extend({}, defaults, config)).data('gridster');
|
||||
|
||||
if (!fromDom) {
|
||||
$.each(widgets, function(i, widget) {
|
||||
this.gridster.add_widget.apply(this.gridster, widget);
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
this.drag_from_to = u._dragFromTo;
|
||||
|
||||
return this.gridster;
|
||||
},
|
||||
|
||||
createEvent: function(type, offset) {
|
||||
var event = document.createEvent('MouseEvents');
|
||||
event.initMouseEvent(type, true, true, window, 0, 0, 0,
|
||||
offset.left, offset.top, false, false, false, false, 0, null);
|
||||
|
||||
return event;
|
||||
},
|
||||
|
||||
dispatchEvent: function(elem, type, event) {
|
||||
if (elem.dispatchEvent) {
|
||||
elem.dispatchEvent(event);
|
||||
} else if (elem.fireEvent) {
|
||||
elem.fireEvent('on' + type, event);
|
||||
}
|
||||
},
|
||||
|
||||
_dragFromTo: function(fromCoords, toCoords) {
|
||||
var d = $.Deferred();
|
||||
var gridster = this.gridster;
|
||||
var $el;
|
||||
|
||||
function getMousePos(coords) {
|
||||
var size = gridster.options.widget_base_dimensions;
|
||||
var margin = gridster.options.widget_margins;
|
||||
|
||||
var left = ((coords[0] - 1) * size[0]) + (margin[0] * ((coords[0] * 2) - 1));
|
||||
var top = ((coords[1] - 1) * size[1]) + (margin[1] * ((coords[1] * 2) - 1));
|
||||
|
||||
var parentOffset = gridster.$wrapper.offset();
|
||||
|
||||
return {
|
||||
left: parentOffset.left + left + 20,
|
||||
top: parentOffset.top + top + 20
|
||||
};
|
||||
}
|
||||
|
||||
function addPoint(offset) {
|
||||
$('<span/>').css({
|
||||
left: offset.left + 'px',
|
||||
top: offset.top + 'px',
|
||||
width: '2px',
|
||||
height: '2px',
|
||||
background: 'red',
|
||||
display: 'inline-block',
|
||||
position: 'absolute',
|
||||
zIndex: '9999'
|
||||
}).appendTo('body');
|
||||
}
|
||||
|
||||
var from_offset;
|
||||
|
||||
if (fromCoords instanceof $) {
|
||||
$el = fromCoords;
|
||||
var offset = $el.offset();
|
||||
from_offset = {
|
||||
left: offset.left + ($el.width() / 2),
|
||||
top: offset.top + ($el.height() / 2)
|
||||
};
|
||||
} else {
|
||||
$el = this.gridster.gridmap[fromCoords[0]][fromCoords[1]];
|
||||
from_offset = getMousePos(fromCoords);
|
||||
}
|
||||
|
||||
if (! $el) {
|
||||
return;
|
||||
}
|
||||
|
||||
var to_offset = getMousePos(toCoords);
|
||||
var el = $el.get(0);
|
||||
|
||||
addPoint(from_offset);
|
||||
addPoint(to_offset);
|
||||
|
||||
// Simulating drag start
|
||||
var type = 'mousedown';
|
||||
var event = u.createEvent(type, from_offset);
|
||||
u.dispatchEvent(el, type, event);
|
||||
|
||||
// Simulating drop
|
||||
type = 'mousemove';
|
||||
u.dispatchEvent(el, type, u.createEvent(type, {
|
||||
top: from_offset.top + 2,
|
||||
left: from_offset.left + 2
|
||||
}));
|
||||
|
||||
this.gridster.$el.on('gridster:dragstop gridster:resizestop', function() {
|
||||
setTimeout(function() {
|
||||
d.resolveWith(this);
|
||||
}.bind(this), SPEED);
|
||||
}.bind(this));
|
||||
|
||||
var diff_x = to_offset.left - from_offset.left;
|
||||
var diff_y = to_offset.top - from_offset.top;
|
||||
var steps = 10;
|
||||
var step_x = diff_x / steps;
|
||||
var step_y = diff_y / steps;
|
||||
|
||||
var tmp_offset = {
|
||||
left: from_offset.left,
|
||||
top: from_offset.top
|
||||
};
|
||||
|
||||
for (var i = 0; i < steps; i++) {
|
||||
tmp_offset.left += step_x;
|
||||
tmp_offset.top += step_y;
|
||||
addPoint(tmp_offset);
|
||||
u.dispatchEvent(el, type, u.createEvent(type, tmp_offset));
|
||||
}
|
||||
|
||||
u.dispatchEvent(el, type, u.createEvent(type, to_offset));
|
||||
addPoint(to_offset);
|
||||
|
||||
// Simulating drag end
|
||||
type = 'mouseup';
|
||||
var dragEndEvent = u.createEvent(type, to_offset);
|
||||
u.dispatchEvent(el, type, dragEndEvent);
|
||||
|
||||
return d.promise();
|
||||
}
|
||||
};
|
||||
+4
-5
@@ -1,12 +1,11 @@
|
||||
/* global require */
|
||||
"use strict";
|
||||
'use strict';
|
||||
define([
|
||||
'QUnit',
|
||||
'jquery',
|
||||
'gridster'
|
||||
], function(QUnit, $, gridster) {
|
||||
|
||||
QUnit.module("Gridster AMD", {
|
||||
QUnit.module('Gridster AMD', {
|
||||
setup: function () {
|
||||
},
|
||||
teardown: function () {
|
||||
@@ -21,8 +20,8 @@ define([
|
||||
|
||||
QUnit.test('gridster should be initialized.', function() {
|
||||
$('.wrapper ul').gridster();
|
||||
equal($(".wrapper").hasClass('ready'), true, 'Gridster should initialized wrapper.');
|
||||
equal($(".wrapper ul li").length, $(".gs-w").length, 'grid elements get a .gs-w class');
|
||||
equal($('.wrapper').hasClass('ready'), true, 'Gridster should initialized wrapper.');
|
||||
equal($('.wrapper ul li').length, $('.gs-w').length, 'grid elements get a .gs-w class');
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user