|
50 | 50 | constructor = callbackName.match(/^[^.]+.\s*/)[0].slice(0, -1); // matching a string upto a dot to check ctrl as syntax
|
51 | 51 | constructor = scope[constructor] && typeof scope[constructor].constructor === 'function' ? constructor : null;
|
52 | 52 | self.joinedArguments = [];
|
53 |
| - var argsArray = (args && args.split(',') || []).map(function(arg, index, array) { |
54 |
| - // We need to determine if we have a json object in the argument list |
55 |
| - var firstArg = arg[0], |
56 |
| - nextIndex = index + 1, |
57 |
| - isNthItem = nextIndex == array.length; |
58 |
| - |
59 |
| - if (firstArg == "{" && !isNthItem) { |
60 |
| - var nextItem = array[nextIndex], |
61 |
| - lastChar = nextItem[nextItem.length - 1]; |
62 |
| - |
63 |
| - if (lastChar == "}") { |
64 |
| - self.joinedArguments.push(nextItem); |
65 |
| - var joinedArg = [arg, nextItem].join(); |
66 |
| - return joinedArg; |
| 53 | + self.getLastIndexJSONElement = function (array){ |
| 54 | + for (var i = 0; i < array.length; i++) { |
| 55 | + var ithEl = array[i]; |
| 56 | + //If this is the closing json element |
| 57 | + if(ithEl[ithEl.length -1] == "}"){ |
| 58 | + // If this is not the last element |
| 59 | + if(i < (array.length -1)){ |
| 60 | + // then check the next element for the closing bracket |
| 61 | + var nextItem = array[i + 1]; |
| 62 | + // If the next element does not have a closing bracket |
| 63 | + if(nextItem.indexOf("}") == -1){ |
| 64 | + // then the current index is the last |
| 65 | + return i; |
| 66 | + } |
| 67 | + else{ |
| 68 | + // Then we are not the last closing tail |
| 69 | + continue; |
| 70 | + } |
| 71 | + } |
| 72 | + else { |
| 73 | + // else return this index |
| 74 | + return i; |
| 75 | + } |
| 76 | + } |
| 77 | + }; |
| 78 | + // if we get this far then we haven't found a closing jsonelement |
| 79 | + return -1; |
| 80 | + }; |
| 81 | + |
| 82 | + self.getArgs = function(args) { |
| 83 | + return (args && args.split(',') || []).map(function(arg, index, array) { |
| 84 | + // We need to determine if we have a json object in the argument list |
| 85 | + var firstArg = arg[0], |
| 86 | + nextIndex = index + 1, |
| 87 | + isNthItem = nextIndex == array.length; |
| 88 | + |
| 89 | + if (firstArg == "{" && !isNthItem) { |
| 90 | + var nextItem = array[nextIndex], |
| 91 | + lastChar = nextItem[nextItem.length - 1]; |
| 92 | + |
| 93 | + if (lastChar == "}") { |
| 94 | + self.joinedArguments.push(nextItem); |
| 95 | + var joinedArg = [arg, nextItem].join(); |
| 96 | + return joinedArg; |
| 97 | + } else { |
| 98 | + return arg; |
| 99 | + } |
67 | 100 | } else {
|
68 |
| - return arg; |
69 |
| - } |
70 |
| - } else { |
71 |
| - if (self.joinedArguments.indexOf(arg) == -1) { |
72 |
| - return arg; |
| 101 | + if (self.joinedArguments.indexOf(arg) == -1) { |
| 102 | + return arg; |
| 103 | + } |
73 | 104 | }
|
74 |
| - } |
75 |
| - }, self); |
76 |
| - |
| 105 | + }, self); |
| 106 | + }; |
| 107 | + var argsArray = self.getArgs(args); |
| 108 | + console.log("args: ", argsArray); |
| 109 | + //(args && args.split(',') || []).map(function(arg, index, array) { |
| 110 | + // // We need to determine if we have a json object in the argument list |
| 111 | + // var firstArg = arg[0], |
| 112 | + // nextIndex = index + 1, |
| 113 | + // isNthItem = nextIndex == array.length; |
| 114 | + |
| 115 | + // if (firstArg == "{" && !isNthItem) { |
| 116 | + // var nextItem = array[nextIndex], |
| 117 | + // lastChar = nextItem[nextItem.length - 1]; |
| 118 | + |
| 119 | + // if (lastChar == "}") { |
| 120 | + // self.joinedArguments.push(nextItem); |
| 121 | + // var joinedArg = [arg, nextItem].join(); |
| 122 | + // return joinedArg; |
| 123 | + // } else { |
| 124 | + // return arg; |
| 125 | + // } |
| 126 | + // } else { |
| 127 | + // if (self.joinedArguments.indexOf(arg) == -1) { |
| 128 | + // return arg; |
| 129 | + // } |
| 130 | + // } |
| 131 | + // }, self); |
| 132 | + |
77 | 133 | return {
|
78 | 134 | callback: callbackName.substring(constructor && constructor.length + 1 || 0, atStartBracket),
|
79 | 135 | args: argsArray.map(function(item) {
|
|
0 commit comments