Skip to content

Commit 4770821

Browse files
remcokranenburgcodef0rmerz
authored andcommitted
fix(ngJq): Closes #211 - maintain compatibility with angular 1.4+
1 parent 41c9d1e commit 4770821

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

bower.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@
1717
],
1818
"dependencies": {
1919
"jquery-ui": "latest",
20-
"angular": "~1.x"
20+
"angular": "latest"
2121
},
2222
"devDependencies": {
23-
"angular-mocks": "~1.x",
24-
"angular-ui-bootstrap-bower": "~0.12.0"
25-
},
26-
"resolutions": {
27-
"angular": "1.3.15"
23+
"angular-mocks": "latest",
24+
"angular-ui-bootstrap-bower": "latest"
2825
}
2926
}

src/angular-dragdrop.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti
3434
this.draggableScope = null;
3535
this.droppableScope = null;
3636

37-
angular.element(document).find('head').prepend('<style type="text/css">@charset "UTF-8";.angular-dragdrop-hide{display: none !important;}</style>');
37+
$('head').prepend('<style type="text/css">@charset "UTF-8";.angular-dragdrop-hide{display: none !important;}</style>');
3838

3939
this.callEventCallback = function (scope, callbackName, event, ui) {
4040
if (!callbackName) return;
@@ -121,7 +121,7 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti
121121
// be nice with absolutely positioned brethren :-)
122122
$helper = $draggable.clone();
123123
$helper.css({'position': 'absolute'}).css($draggable.offset());
124-
angular.element(document).find('body').append($helper);
124+
$('body').append($helper);
125125
$draggable.addClass('angular-dragdrop-hide');
126126

127127
this.move($helper, $droppableDraggable.length > 0 ? $droppableDraggable : $droppable, null, 'fast', dropSettings, function() { $helper.remove(); });
@@ -274,7 +274,8 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti
274274
return {
275275
require: '?jqyouiDroppable',
276276
restrict: 'A',
277-
link: function(scope, element, attrs) {
277+
link: function(scope, elem, attrs) {
278+
var element = $(elem);
278279
var dragSettings, jqyouiOptions, zIndex, killWatcher;
279280
var updateDraggable = function(newValue, oldValue) {
280281
if (newValue) {
@@ -286,13 +287,13 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti
286287
.draggable({
287288
start: function(event, ui) {
288289
ngDragDropService.draggableScope = scope;
289-
zIndex = angular.element(jqyouiOptions.helper ? ui.helper : this).css('z-index');
290-
angular.element(jqyouiOptions.helper ? ui.helper : this).css('z-index', 9999);
291-
jqyoui.startXY = angular.element(this)[dragSettings.containment || 'offset']();
290+
zIndex = $(jqyouiOptions.helper ? ui.helper : this).css('z-index');
291+
$(jqyouiOptions.helper ? ui.helper : this).css('z-index', 9999);
292+
jqyoui.startXY = $(this)[dragSettings.containment || 'offset']();
292293
ngDragDropService.callEventCallback(scope, dragSettings.onStart, event, ui);
293294
},
294295
stop: function(event, ui) {
295-
angular.element(jqyouiOptions.helper ? ui.helper : this).css('z-index', zIndex);
296+
$(jqyouiOptions.helper ? ui.helper : this).css('z-index', zIndex);
296297
ngDragDropService.callEventCallback(scope, dragSettings.onStop, event, ui);
297298
},
298299
drag: function(event, ui) {
@@ -321,11 +322,12 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti
321322
return {
322323
restrict: 'A',
323324
priority: 1,
324-
link: function(scope, element, attrs) {
325+
link: function(scope, elem, attrs) {
326+
var element = $(elem);
325327
var dropSettings, killWatcher;
326328
var updateDroppable = function(newValue, oldValue) {
327329
if (newValue) {
328-
dropSettings = scope.$eval(angular.element(element).attr('jqyoui-droppable') || angular.element(element).attr('data-jqyoui-droppable')) || {};
330+
dropSettings = scope.$eval($(element).attr('jqyoui-droppable') || $(element).attr('data-jqyoui-droppable')) || {};
329331
element
330332
.droppable({disabled: false})
331333
.droppable(scope.$eval(attrs.jqyouiOptions) || {})
@@ -350,9 +352,9 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti
350352
}
351353

352354
beforeDropPromise.then(angular.bind(this, function() {
353-
if (angular.element(ui.draggable).ngattr('ng-model') && attrs.ngModel) {
355+
if ($(ui.draggable).ngattr('ng-model') && attrs.ngModel) {
354356
ngDragDropService.droppableScope = scope;
355-
ngDragDropService.invokeDrop(angular.element(ui.draggable), angular.element(this), event, ui);
357+
ngDragDropService.invokeDrop($(ui.draggable), $(this), event, ui);
356358
} else {
357359
ngDragDropService.callEventCallback(scope, dropSettings.onDrop, event, ui);
358360
}
@@ -381,8 +383,8 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti
381383
};
382384
}]);
383385

384-
angular.element.prototype.ngattr = function(name, value) {
385-
var element = angular.element(this).get(0);
386+
$.fn.ngattr = function(name, value) {
387+
var element = this[0];
386388

387389
return element.getAttribute(name) || element.getAttribute('data-' + name);
388390
};

0 commit comments

Comments
 (0)