Fix for bug #493 including unit tests to prove.

Run npm install and visit test/jquery.gridster-amd.html in browser.
This commit is contained in:
Glen Pike
2015-03-03 00:46:11 +00:00
parent 314037471f
commit c0a2bde09c
13 changed files with 166 additions and 27 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
/*! gridster.js - v0.5.6 - 2014-09-25
/*! gridster.js - v0.5.6 - 2015-03-03
* http://gridster.net/
* Copyright (c) 2014 ducksboard; Licensed MIT */
* Copyright (c) 2015 ducksboard; Licensed MIT */
.gridster {
position:relative;
+3 -3
View File
@@ -1,6 +1,6 @@
/*! gridster.js - v0.5.6 - 2014-09-25
/*! gridster.js - v0.5.6 - 2015-03-03
* http://gridster.net/
* Copyright (c) 2014 ducksboard; Licensed MIT */
* Copyright (c) 2015 ducksboard; Licensed MIT */
;(function(root, factory) {
@@ -1686,7 +1686,7 @@
* than the original.
*/
fn.register_widget = function($el) {
var isDOM = $el instanceof jQuery;
var isDOM = $el instanceof $;
var wgd = isDOM ? this.dom_to_coords($el) : $el;
var posChanged = false;
isDOM || ($el = wgd.el);
+1 -1
View File
@@ -1,2 +1,2 @@
/*! gridster.js - v0.5.6 - 2014-09-25 - * http://gridster.net/ - Copyright (c) 2014 ducksboard; Licensed MIT */
/*! gridster.js - v0.5.6 - 2015-03-03 - * http://gridster.net/ - Copyright (c) 2015 ducksboard; Licensed MIT */
.gridster{position:relative}.gridster>*{margin:0 auto;-webkit-transition:height .4s,width .4s;-moz-transition:height .4s,width .4s;-o-transition:height .4s,width .4s;-ms-transition:height .4s,width .4s;transition:height .4s,width .4s}.gridster .gs-w{z-index:2;position:absolute}.ready .gs-w:not(.preview-holder){-webkit-transition:opacity .3s,left .3s,top .3s;-moz-transition:opacity .3s,left .3s,top .3s;-o-transition:opacity .3s,left .3s,top .3s;transition:opacity .3s,left .3s,top .3s}.ready .gs-w:not(.preview-holder),.ready .resize-preview-holder{-webkit-transition:opacity .3s,left .3s,top .3s,width .3s,height .3s;-moz-transition:opacity .3s,left .3s,top .3s,width .3s,height .3s;-o-transition:opacity .3s,left .3s,top .3s,width .3s,height .3s;transition:opacity .3s,left .3s,top .3s,width .3s,height .3s}.gridster .preview-holder{z-index:1;position:absolute;background-color:#fff;border-color:#fff;opacity:.3}.gridster .player-revert{z-index:10!important;-webkit-transition:left .3s,top .3s!important;-moz-transition:left .3s,top .3s!important;-o-transition:left .3s,top .3s!important;transition:left .3s,top .3s!important}.gridster .dragging,.gridster .resizing{z-index:10!important;-webkit-transition:all 0s!important;-moz-transition:all 0s!important;-o-transition:all 0s!important;transition:all 0s!important}.gs-resize-handle{position:absolute;z-index:1}.gs-resize-handle-both{width:20px;height:20px;bottom:-8px;right:-8px;background-image:url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/Pg08IS0tIEdlbmVyYXRvcjogQWRvYmUgRmlyZXdvcmtzIENTNiwgRXhwb3J0IFNWRyBFeHRlbnNpb24gYnkgQWFyb24gQmVhbGwgKGh0dHA6Ly9maXJld29ya3MuYWJlYWxsLmNvbSkgLiBWZXJzaW9uOiAwLjYuMSAgLS0+DTwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DTxzdmcgaWQ9IlVudGl0bGVkLVBhZ2UlMjAxIiB2aWV3Qm94PSIwIDAgNiA2IiBzdHlsZT0iYmFja2dyb3VuZC1jb2xvcjojZmZmZmZmMDAiIHZlcnNpb249IjEuMSINCXhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHhtbDpzcGFjZT0icHJlc2VydmUiDQl4PSIwcHgiIHk9IjBweCIgd2lkdGg9IjZweCIgaGVpZ2h0PSI2cHgiDT4NCTxnIG9wYWNpdHk9IjAuMzAyIj4NCQk8cGF0aCBkPSJNIDYgNiBMIDAgNiBMIDAgNC4yIEwgNCA0LjIgTCA0LjIgNC4yIEwgNC4yIDAgTCA2IDAgTCA2IDYgTCA2IDYgWiIgZmlsbD0iIzAwMDAwMCIvPg0JPC9nPg08L3N2Zz4=);background-position:top left;background-repeat:no-repeat;cursor:se-resize;z-index:20}.gs-resize-handle-x{top:0;bottom:13px;right:-5px;width:10px;cursor:e-resize}.gs-resize-handle-y{left:0;right:13px;bottom:-5px;height:10px;cursor:s-resize}.gs-w:hover .gs-resize-handle,.resizing .gs-resize-handle{opacity:1}.gs-resize-handle,.gs-w.dragging .gs-resize-handle{opacity:0}.gs-resize-disabled .gs-resize-handle{display:none!important}[data-max-sizex="1"] .gs-resize-handle-x,[data-max-sizey="1"] .gs-resize-handle-y,[data-max-sizey="1"][data-max-sizex="1"] .gs-resize-handle{display:none!important}
+2 -2
View File
File diff suppressed because one or more lines are too long
+3 -3
View File
@@ -1,6 +1,6 @@
/*! gridster.js - v0.5.6 - 2014-09-25
/*! gridster.js - v0.5.6 - 2015-03-03
* http://gridster.net/
* Copyright (c) 2014 ducksboard; Licensed MIT */
* Copyright (c) 2015 ducksboard; Licensed MIT */
;(function(root, factory) {
@@ -1686,7 +1686,7 @@
* than the original.
*/
fn.register_widget = function($el) {
var isDOM = $el instanceof jQuery;
var isDOM = $el instanceof $;
var wgd = isDOM ? this.dom_to_coords($el) : $el;
var posChanged = false;
isDOM || ($el = wgd.el);
File diff suppressed because one or more lines are too long
+10 -9
View File
@@ -26,16 +26,17 @@
"jquery": "git+https://github.com/jquery/jquery.git#2.0.3"
},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-uglify": "~0.2.0",
"grunt-contrib-jshint": "~0.3.0",
"grunt-contrib-concat": "~0.1.3",
"grunt-contrib-watch": "~0.3.1",
"grunt-contrib-cssmin": "~0.5.0",
"grunt-contrib-yuidoc": "~0.4.0",
"bower": "~0.9.2",
"qunitjs": "~1.11.0",
"grunt": "~0.4.1",
"grunt-bump": "0.0.11",
"grunt-conventional-changelog": "~1.0.0"
"grunt-contrib-concat": "~0.1.3",
"grunt-contrib-cssmin": "~0.5.0",
"grunt-contrib-jshint": "~0.3.0",
"grunt-contrib-uglify": "~0.2.0",
"grunt-contrib-watch": "~0.3.1",
"grunt-contrib-yuidoc": "~0.4.0",
"grunt-conventional-changelog": "~1.0.0",
"qunitjs": "~1.11.0",
"requirejs": "^2.1.16"
}
}
+1 -1
View File
@@ -839,7 +839,7 @@
* than the original.
*/
fn.register_widget = function($el) {
var isDOM = $el instanceof jQuery;
var isDOM = $el instanceof $;
var wgd = isDOM ? this.dom_to_coords($el) : $el;
var posChanged = false;
isDOM || ($el = wgd.el);
+53
View File
@@ -0,0 +1,53 @@
//Based on https://github.com/jonnyreeves/qunit-require
/* global require */
"use strict";
require.config({
//set the baseUrl to the src dir so that gridster
//AMD modules can be found.
baseUrl: '../src/',
paths: {
'QUnit': '../node_modules/qunitjs/qunit/qunit',
'jquery': '../node_modules/jquery/jquery',
'gridster': 'jquery.gridster',
},
map: {
// '*' means all modules will get 'jquery-private'
// for their 'jquery' dependency.
'*': { 'jquery': '../test/jquery-private' },
// 'jquery-private' wants the real jQuery module
// though. If this line was not here, there would
// be an unresolvable cyclic dependency.
'../test/jquery-private': { 'jquery': 'jquery' }
},
shim: {
'QUnit': {
exports: 'QUnit',
init: function() {
QUnit.config.autoload = false;
QUnit.config.autostart = false;
}
}
}
});
/*
Load all of our require'd files
We have to load all of the gridster jquery.* modules so
that they are defined for when gridster needs them.
Lastly, load the testsuite which defines some tests.
*/
require([
'QUnit',
'utils',
'jquery.coords',
'jquery.collision',
'jquery.draggable',
'../test/testsuite'
//Require'd files are passed as args, but we don't use them.
], function(QUnit/*, utils, coords, collision, draggable, testsuite*/) {
QUnit.load();
QUnit.start();
}
);
+3
View File
@@ -0,0 +1,3 @@
define(['jquery'], function (jq) {
return jq.noConflict( true );
});
+4 -4
View File
@@ -4,11 +4,11 @@
<meta charset="utf-8">
<title>gridster.js Test Suite</title>
<!-- Load local jQuery, removing access to $ (use jQuery, not $). -->
<script src="../libs/jquery/jquery.js"></script>
<script src="../node_modules/jquery/jquery.js"></script>
<script>jQuery.noConflict()</script>
<script type="text/javascript" src="../libs/jquery/jquery.js"></script>
<script type="text/javascript" src="../node_modules/jquery/jquery.js"></script>
<script src="../dist/jquery.gridster.min.js" type="text/javascript" charset="utf-8"></script>
@@ -16,9 +16,9 @@
<!-- Load local QUnit (grunt requires v1.0.0 or newer). -->
<link rel="stylesheet" href="../libs/qunit/qunit.css" media="screen">
<link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css" media="screen">
<script src="../libs/qunit/qunit.js"></script>
<script src="../node_modules/qunitjs/qunit/qunit.js"></script>
<!-- Load local lib and tests. -->
<script src="../src/jquery.gridster.js"></script>
<script src="jquery.gridster_test.js"></script>
+54
View File
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>gridster.js AMD Test Suite</title>
<link rel="stylesheet" type="text/css" href="../dist/jquery.gridster.css">
<link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css" media="screen">
<!-- Load requirejs which will load amd-main.js and start from there-->
<script data-main="amd-main.js" src="../node_modules/requirejs/require.js"></script>
</head>
<body>
<h1 id="qunit-header">gridster.js AMD Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">
<div class="wrapper">
<ul>
<li data-row="1" data-col="1" data-sizex="2" data-sizey="2"></li>
<li data-row="1" data-col="3" data-sizex="1" data-sizey="2"></li>
<li data-row="1" data-col="4" data-sizex="1" data-sizey="1"></li>
<li data-row="3" data-col="2" data-sizex="3" data-sizey="1"></li>
<li data-row="4" data-col="1" data-sizex="1" data-sizey="1"></li>
<li data-row="3" data-col="1" data-sizex="1" data-sizey="1"></li>
<li data-row="4" data-col="2" data-sizex="1" data-sizey="1"></li>
<li data-row="5" data-col="2" data-sizex="1" data-sizey="1"></li>
<li data-row="4" data-col="4" data-sizex="1" data-sizey="1"></li>
<li data-row="1" data-col="5" data-sizex="1" data-sizey="3"></li>
<li data-row="5" data-col="1" data-sizex="1" data-sizey="2"></li>
<li data-row="4" data-col="3" data-sizex="1" data-sizey="2"></li>
<li data-row="5" data-col="4" data-sizex="1" data-sizey="1"></li>
<li data-row="6" data-col="2" data-sizex="3" data-sizey="1"></li>
<li data-row="4" data-col="5" data-sizex="1" data-sizey="2"></li>
<li data-row="6" data-col="5" data-sizex="1" data-sizey="1"></li>
<li data-row="7" data-col="3" data-sizex="1" data-sizey="1"></li>
</ul>
</div>
</div>
</body>
</html>
+28
View File
@@ -0,0 +1,28 @@
/* global require */
"use strict";
define([
'QUnit',
'jquery',
'gridster'
], function(QUnit, $, gridster) {
QUnit.module("Gridster AMD", {
setup: function () {
},
teardown: function () {
}
});
QUnit.test('window.$ should be undefined.', function() {
equal(typeof window.$, 'undefined', 'window.$ should be undefined');
equal(typeof window.jQuery, 'undefined', 'window.jQuery should be undefined');
});
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');
});
}
);