| 10411 | */ |
| 10412 | orderByFilter.$inject = ['$parse']; |
| 10413 | function orderByFilter($parse){ |
| 10414 | return function(array, sortPredicate, reverseOrder) { |
| 10415 | if (!isArray(array)) return array; |
| 10416 | if (!sortPredicate) return array; |
| 10417 | sortPredicate = isArray(sortPredicate) ? sortPredicate: [sortPredicate]; |
| 10418 | sortPredicate = map(sortPredicate, function(predicate){ |
| 10419 | var descending = false, get = predicate || identity; |
| 10420 | if (isString(predicate)) { |
| 10421 | if ((predicate.charAt(0) == '+' || predicate.charAt(0) == '-')) { |
| 10422 | descending = predicate.charAt(0) == '-'; |
| 10423 | predicate = predicate.substring(1); |
| 10424 | } |
| 10425 | get = $parse(predicate); |
| 10426 | } |
| 10427 | return reverseComparator(function(a,b){ |
| 10428 | return compare(get(a),get(b)); |
| 10429 | }, descending); |
| 10430 | }); |
| 10431 | var arrayCopy = []; |
| 10432 | for ( var i = 0; i < array.length; i++) { arrayCopy.push(array[i]); } |
| 10433 | return arrayCopy.sort(reverseComparator(comparator, reverseOrder)); |
| 10434 | |
| 10435 | function comparator(o1, o2){ |
| 10436 | for ( var i = 0; i < sortPredicate.length; i++) { |
| 10437 | var comp = sortPredicate[i](o1, o2); |
| 10438 | if (comp !== 0) return comp; |
| 10439 | } |
| 10440 | return 0; |
| 10441 | } |
| 10442 | function reverseComparator(comp, descending) { |
| 10443 | return toBoolean(descending) |
| 10444 | ? function(a,b){return comp(b,a);} |
| 10445 | : comp; |
| 10446 | } |
| 10447 | function compare(v1, v2){ |
| 10448 | var t1 = typeof v1; |
| 10449 | var t2 = typeof v2; |
| 10450 | if (t1 == t2) { |
| 10451 | if (t1 == "string") v1 = v1.toLowerCase(); |
| 10452 | if (t1 == "string") v2 = v2.toLowerCase(); |
| 10453 | if (v1 === v2) return 0; |
| 10454 | return v1 < v2 ? -1 : 1; |
| 10455 | } else { |
| 10456 | return t1 < t2 ? -1 : 1; |
| 10457 | } |
| 10458 | } |
| 10459 | } |
| 10460 | } |
| 10461 | |
| 10462 | function ngDirective(directive) { |
| 10463 | if (isFunction(directive)) { |