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

Commit 6efeec2

Browse files
committed
Attribute callbacks capsulated
Attribute callbacks capsulated with a function. This function has try-catch scope and calls scope.received function by default. Syntax warnings are cleared.
1 parent f275977 commit 6efeec2

File tree

1 file changed

+42
-21
lines changed

1 file changed

+42
-21
lines changed

src/sortable.js

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ angular.module('ui.sortable', [])
1414
'uiSortableConfig', '$timeout', '$log',
1515
function(uiSortableConfig, $timeout, $log) {
1616
return {
17-
require: '?ngModel',
17+
require:'?ngModel',
1818
scope: {
19-
ngModel: '=',
20-
uiSortable: '=',
21-
receive :'&uiSortableReceive',//Expression bindings from html.
22-
remove :'&uiSortableRemove',
23-
start :'&uiSortableStart',
24-
stop :'&uiSortableStop',
25-
update :'&uiSortableUpdate'
19+
ngModel:'=',
20+
uiSortable:'=',
21+
receive:'&uiSortableReceive',//Expression bindings from html.
22+
remove:'&uiSortableRemove',
23+
start:'&uiSortableStart',
24+
stop:'&uiSortableStop',
25+
update:'&uiSortableUpdate',
26+
received :'&uiSortableReceived'
2627
},
2728
link: function(scope, element, attrs, ngModel) {
2829
var savedNodes;
@@ -132,21 +133,41 @@ angular.module('ui.sortable', [])
132133
}
133134

134135

135-
/*
136-
* If user defines ui-sortable-callback for @key and callback based option at the same time the html based ui-sortable-callback expression will be selected. (Overridden)
137-
* If user defined ui-sortable-callback for @key but callback expression is empty then option based @key callback will be selected.
138-
* If user not defines a option for @key callback then html based ui-sortable-callback will be just selected.
139-
* If user just defines option for @key callback then it will be attached.
140-
* */
141-
var attrKey = 'uiSortable'+key.substring(0,1).toUpperCase()+key.substring(1);
142-
if(scope[key]!=undefined && scope[key] instanceof Function && attrs[attrKey] != undefined && attrs[attrKey].length > 0)
136+
/*
137+
* If user defines ui-sortable-callback for @key and callback based option at the same time the html based ui-sortable-callback expression will be selected. (Overridden)
138+
* If user defined ui-sortable-callback for @key but callback expression is empty then option based @key callback will be selected.
139+
* If user not defines a option for @key callback then html based ui-sortable-callback will be just selected.
140+
* If user just defines option for @key callback then it will be attached.
141+
* */
142+
var attrKey = 'uiSortable'+key.substring(0,1).toUpperCase()+key.substring(1);
143+
if(scope[key]!==undefined && scope[key] instanceof Function && attrs[attrKey] !== undefined && attrs[attrKey].length > 0)
144+
{
145+
146+
var expression = scope[key]; //Scope variable can be changed on fly.
147+
var receivedFunct = scope.received;
148+
var expressionCapsule = function(e, ui)
143149
{
144-
value = patchSortableOption(key, scope[key]);
145-
}
146-
else
147-
{
148-
value = patchSortableOption(key, value);
150+
try
151+
{
152+
153+
expression.apply(0,arguments); //Sends all of arguments to callBack function.
154+
155+
if(receivedFunct instanceof Function)
156+
receivedFunct.apply(0,arguments);
157+
158+
}
159+
catch(err)
160+
{
161+
//Can be printed to console.
162+
}
149163
}
164+
165+
value = patchSortableOption(key, expressionCapsule);
166+
}
167+
else
168+
{
169+
value = patchSortableOption(key, value);
170+
}
150171

151172

152173
if (!optsDiff) {

0 commit comments

Comments
 (0)