|
39 | 39 | // for more info see: https://www.firebase.com/docs/ordered-data.html |
40 | 40 | angular.module("firebase").filter("orderByPriority", function() { |
41 | 41 | return function(input) { |
42 | | - if (!input) { |
43 | | - return []; |
44 | | - } |
45 | | - if (!input.$getIndex || typeof input.$getIndex != "function") { |
46 | | - // If input is an object, map it to an array for the time being. |
47 | | - var type = Object.prototype.toString.call(input); |
48 | | - if (typeof input == "object" && type == "[object Object]") { |
49 | | - var ret = []; |
50 | | - for (var prop in input) { |
51 | | - if (input.hasOwnProperty(prop)) { |
52 | | - ret.push(input[prop]); |
53 | | - } |
| 42 | + var sorted = []; |
| 43 | + if (input) { |
| 44 | + if (!input.$getIndex || typeof input.$getIndex != "function") { |
| 45 | + // input is not an angularFire instance |
| 46 | + if( angular.isArray(input) ) { |
| 47 | + // if input is an array, copy it |
| 48 | + sorted = input.slice(0); |
| 49 | + } |
| 50 | + else if( angular.isObject(input) ) { |
| 51 | + // If input is an object, map it to an array |
| 52 | + angular.forEach(input, function(prop) { |
| 53 | + sorted.push(prop); |
| 54 | + }); |
54 | 55 | } |
55 | | - return ret; |
56 | 56 | } |
57 | | - return input; |
58 | | - } |
59 | | - |
60 | | - var sorted = []; |
61 | | - var index = input.$getIndex(); |
62 | | - if (index.length <= 0) { |
63 | | - return input; |
64 | | - } |
65 | | - |
66 | | - for (var i = 0; i < index.length; i++) { |
67 | | - var val = input[index[i]]; |
68 | | - if (val) { |
69 | | - val.$id = index[i]; |
70 | | - sorted.push(val); |
| 57 | + else { |
| 58 | + // input is an angularFire instance |
| 59 | + var index = input.$getIndex(); |
| 60 | + if (index.length > 0) { |
| 61 | + for (var i = 0; i < index.length; i++) { |
| 62 | + var val = input[index[i]]; |
| 63 | + if (val) { |
| 64 | + val.$id = index[i]; |
| 65 | + sorted.push(val); |
| 66 | + } |
| 67 | + } |
| 68 | + } |
71 | 69 | } |
72 | 70 | } |
73 | | - |
74 | 71 | return sorted; |
75 | 72 | }; |
76 | 73 | }); |
|
0 commit comments