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

Commit

Permalink
Merge pull request #165 from thgreasi/wrong-script-order
Browse files Browse the repository at this point in the history
feat(sortable): log error if jquery was not available to angular on load
  • Loading branch information
thgreasi committed Apr 27, 2014
2 parents 4674a53 + 3f6fe42 commit d8ac4e8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 5 additions & 0 deletions src/sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
23 changes: 23 additions & 0 deletions test/sortable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<ul ui-sortable><li ng-repeat="item in items" id="s-{{$index}}">{{ item }}</li></ul>')($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;
Expand Down

0 comments on commit d8ac4e8

Please sign in to comment.