diff --git a/bower.json b/bower.json index 30d8db7..f6ebb2c 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-ui-sortable", - "version": "0.12.4", + "version": "0.12.5", "description": "This directive allows you to jQueryUI Sortable.", "author": "https://github.com/angular-ui/ui-sortable/graphs/contributors", "license": "MIT", diff --git a/package.json b/package.json index d320613..95b3993 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-ui-sortable", - "version": "0.12.4", + "version": "0.12.5", "description": "This directive allows you to jQueryUI Sortable.", "author": "https://github.com/angular-ui/ui-sortable/graphs/contributors", "license": "MIT", diff --git a/src/sortable.js b/src/sortable.js index 43e0c88..15c27d8 100644 --- a/src/sortable.js +++ b/src/sortable.js @@ -35,6 +35,11 @@ angular.module('ui.sortable', []) angular.extend(opts, uiSortableConfig); + if (!angular.element.fn || !angular.element.fn.jquery) { + $log.error('ui.sortable: jQuery should be included before AngularJS!'); + return; + } + if (ngModel) { // When we add or remove elements, we need the sortable to 'refresh' diff --git a/test/sortable.spec.js b/test/sortable.spec.js index 36b67f4..fd1a988 100644 --- a/test/sortable.spec.js +++ b/test/sortable.spec.js @@ -36,6 +36,29 @@ describe('uiSortable', function() { }); }); + it('should log an error about jQuery dependency', function() { + inject(function($compile, $rootScope, $log) { + var oldAngularElementFn = angular.element.fn; + var mockJQliteFn = $({}, angular.element.fn, true); + mockJQliteFn.jquery = null; + angular.element.fn = mockJQliteFn; + + this.after(function () { + angular.element.fn = oldAngularElementFn; + }); + + var element; + element = $compile('')($rootScope); + $rootScope.$apply(function() { + $rootScope.items = ['One', 'Two', 'Three']; + }); + + expect($log.error.logs.length).toEqual(1); + expect($log.error.logs[0].length).toEqual(1); + expect($log.error.logs[0][0]).toEqual('ui.sortable: jQuery should be included before AngularJS!'); + }); + }); + it('should refresh sortable properly after an apply', function() { inject(function($compile, $rootScope, $timeout) { var element;