@@ 6246-6266 (lines=21) @@ | ||
6243 | * A helper service that can parse typeahead's syntax (string provided by users) |
|
6244 | * Extracted to a separate service for ease of unit testing |
|
6245 | */ |
|
6246 | .factory('uibTypeaheadParser', ['$parse', function($parse) { |
|
6247 | // 00000111000000000000022200000000000000003333333333333330000000000044000 |
|
6248 | var TYPEAHEAD_REGEXP = /^\s*([\s\S]+?)(?:\s+as\s+([\s\S]+?))?\s+for\s+(?:([\$\w][\$\w\d]*))\s+in\s+([\s\S]+?)$/; |
|
6249 | return { |
|
6250 | parse: function(input) { |
|
6251 | var match = input.match(TYPEAHEAD_REGEXP); |
|
6252 | if (!match) { |
|
6253 | throw new Error( |
|
6254 | 'Expected typeahead specification in form of "_modelValue_ (as _label_)? for _item_ in _collection_"' + |
|
6255 | ' but got "' + input + '".'); |
|
6256 | } |
|
6257 | ||
6258 | return { |
|
6259 | itemName: match[3], |
|
6260 | source: $parse(match[4]), |
|
6261 | viewMapper: $parse(match[2] || match[1]), |
|
6262 | modelMapper: $parse(match[1]) |
|
6263 | }; |
|
6264 | } |
|
6265 | }; |
|
6266 | }]) |
|
6267 | ||
6268 | .controller('UibTypeaheadController', ['$scope', '$element', '$attrs', '$compile', '$parse', '$q', '$timeout', '$document', '$window', '$rootScope', '$$debounce', '$uibPosition', 'uibTypeaheadParser', |
|
6269 | function(originalScope, element, attrs, $compile, $parse, $q, $timeout, $document, $window, $rootScope, $$debounce, $position, typeaheadParser) { |
@@ 6245-6265 (lines=21) @@ | ||
6242 | * A helper service that can parse typeahead's syntax (string provided by users) |
|
6243 | * Extracted to a separate service for ease of unit testing |
|
6244 | */ |
|
6245 | .factory('uibTypeaheadParser', ['$parse', function($parse) { |
|
6246 | // 00000111000000000000022200000000000000003333333333333330000000000044000 |
|
6247 | var TYPEAHEAD_REGEXP = /^\s*([\s\S]+?)(?:\s+as\s+([\s\S]+?))?\s+for\s+(?:([\$\w][\$\w\d]*))\s+in\s+([\s\S]+?)$/; |
|
6248 | return { |
|
6249 | parse: function(input) { |
|
6250 | var match = input.match(TYPEAHEAD_REGEXP); |
|
6251 | if (!match) { |
|
6252 | throw new Error( |
|
6253 | 'Expected typeahead specification in form of "_modelValue_ (as _label_)? for _item_ in _collection_"' + |
|
6254 | ' but got "' + input + '".'); |
|
6255 | } |
|
6256 | ||
6257 | return { |
|
6258 | itemName: match[3], |
|
6259 | source: $parse(match[4]), |
|
6260 | viewMapper: $parse(match[2] || match[1]), |
|
6261 | modelMapper: $parse(match[1]) |
|
6262 | }; |
|
6263 | } |
|
6264 | }; |
|
6265 | }]) |
|
6266 | ||
6267 | .controller('UibTypeaheadController', ['$scope', '$element', '$attrs', '$compile', '$parse', '$q', '$timeout', '$document', '$window', '$rootScope', '$$debounce', '$uibPosition', 'uibTypeaheadParser', |
|
6268 | function(originalScope, element, attrs, $compile, $parse, $q, $timeout, $document, $window, $rootScope, $$debounce, $position, typeaheadParser) { |