-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrabpyWidget.js
88 lines (76 loc) · 1.92 KB
/
CrabpyWidget.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
define([
'dojo/_base/declare',
'dijit/_WidgetBase',
'./CrabZoomer',
'./CapakeyZoomer'
], function (
declare,
_WidgetBase,
CrabZoomer,
CapakeyZoomer
) {
return declare([_WidgetBase], {
baseClass: "crabpyselect",
baseUrl: null,
alleGewesten: false,
postCreate: function () {
this.inherited(arguments);
this.sortMethod = this._sortNatural;
},
startup: function () {
this.inherited(arguments);
},
createCrabZoomer: function (node) {
return new CrabZoomer({
name: "crabzoomer",
baseUrl: this.baseUrl,
baseClass: this.baseClass,
alleGewesten: this.alleGewesten,
sortMethod: this._sortNatural
}, node);
},
createCapakeyZoomer: function (node) {
return new CapakeyZoomer({
name: "capakeyzoomer",
baseUrl: this.baseUrl,
baseClass: this.baseClass,
sortMethod: this._sortNatural
}, node);
},
_sortNatural: function (a, b) {
function chunkify(t) {
var tz = [], x = 0, y = -1, n = 0, i, j;
while (i = (j = t.charAt(x++)).charCodeAt(0)) {
var m = (i == 46 || (i >=48 && i <= 57));
if (m !== n) {
tz[++y] = "";
n = m;
}
tz[y] += j;
}
return tz;
}
var aProperty = a;
var bProperty = b;
if (a.label) {
aProperty = a.label;
bProperty = b.label;
}
else if (a.naam) {
aProperty = a.naam;
bProperty = b.naam;
}
var aa = chunkify(aProperty.toLowerCase());
var bb = chunkify(bProperty.toLowerCase());
for (x = 0; aa[x] && bb[x]; x++) {
if (aa[x] !== bb[x]) {
var c = Number(aa[x]), d = Number(bb[x]);
if (c == aa[x] && d == bb[x]) {
return c - d;
} else return (aa[x] > bb[x]) ? 1 : -1;
}
}
return aa.length - bb.length;
}
});
});