Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit d8ac4e8

Browse files
committed
Merge pull request #165 from thgreasi/wrong-script-order
feat(sortable): log error if jquery was not available to angular on load
2 parents 4674a53 + 3f6fe42 commit d8ac4e8

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-ui-sortable",
3-
"version": "0.12.4",
3+
"version": "0.12.5",
44
"description": "This directive allows you to jQueryUI Sortable.",
55
"author": "https://github.com/angular-ui/ui-sortable/graphs/contributors",
66
"license": "MIT",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-ui-sortable",
3-
"version": "0.12.4",
3+
"version": "0.12.5",
44
"description": "This directive allows you to jQueryUI Sortable.",
55
"author": "https://github.com/angular-ui/ui-sortable/graphs/contributors",
66
"license": "MIT",

src/sortable.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ angular.module('ui.sortable', [])
3535

3636
angular.extend(opts, uiSortableConfig);
3737

38+
if (!angular.element.fn || !angular.element.fn.jquery) {
39+
$log.error('ui.sortable: jQuery should be included before AngularJS!');
40+
return;
41+
}
42+
3843
if (ngModel) {
3944

4045
// When we add or remove elements, we need the sortable to 'refresh'

test/sortable.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,29 @@ describe('uiSortable', function() {
3636
});
3737
});
3838

39+
it('should log an error about jQuery dependency', function() {
40+
inject(function($compile, $rootScope, $log) {
41+
var oldAngularElementFn = angular.element.fn;
42+
var mockJQliteFn = $({}, angular.element.fn, true);
43+
mockJQliteFn.jquery = null;
44+
angular.element.fn = mockJQliteFn;
45+
46+
this.after(function () {
47+
angular.element.fn = oldAngularElementFn;
48+
});
49+
50+
var element;
51+
element = $compile('<ul ui-sortable><li ng-repeat="item in items" id="s-{{$index}}">{{ item }}</li></ul>')($rootScope);
52+
$rootScope.$apply(function() {
53+
$rootScope.items = ['One', 'Two', 'Three'];
54+
});
55+
56+
expect($log.error.logs.length).toEqual(1);
57+
expect($log.error.logs[0].length).toEqual(1);
58+
expect($log.error.logs[0][0]).toEqual('ui.sortable: jQuery should be included before AngularJS!');
59+
});
60+
});
61+
3962
it('should refresh sortable properly after an apply', function() {
4063
inject(function($compile, $rootScope, $timeout) {
4164
var element;

0 commit comments

Comments
 (0)