uber_select_rails 0.6.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,70 +1,5 @@
1
- function Search(queryInput, resultsContainer, options){
2
- var context = this
3
- var model = new SearchModel(options.model)
4
- var list = new List(options.view)
5
- var resultsRendered = false
6
-
7
- // HELPER FUNCTIONS
8
-
9
- this.setData = function(data){
10
- model.setData(data)
11
- }
12
-
13
- this.renderResults = function(){
14
- list.renderResults(model.getResults())
15
- $(this).trigger('renderedResults')
16
- resultsRendered = true
17
- }
18
-
19
- this.getQuery = function(){
20
- return model.getQuery()
21
- }
22
-
23
- this.getResults = function(){
24
- return list.getResults()
25
- }
26
-
27
- this.clear = function(){
28
- if (!resultsRendered){
29
- this.renderResults()
30
- }
31
-
32
- if (queryInput.val() === '') {
33
- list.unhighlightResults()
34
- } else {
35
- queryInput.val('').change()
36
- }
37
- }
38
-
39
- this.highlightResult = function(element) {
40
- list.unhighlightResults()
41
- list.highlightResult(element)
42
- }
43
-
44
- // BEHAVIOUR
45
-
46
- $(queryInput).on('searchInput', function(){
47
- model.setQuery(this.value)
48
- })
49
-
50
- $(model).on('resultsUpdated', function(){
51
- context.renderResults()
52
- })
53
-
54
- // Forward query change
55
- $(model).on('queryChanged', function(){
56
- $(context).trigger('queryChanged')
57
- })
58
-
59
-
60
- // INITIALIZATION
61
-
62
- resultsContainer.html(list.view)
63
-
64
-
65
- // PROTOTYPES
66
-
67
- function SearchModel(options){
1
+ (function($) {
2
+ UberSearch.SearchModel = function(options){
68
3
  var data, results
69
4
  var processedQuery = ''
70
5
  var context = this
@@ -122,7 +57,7 @@ function Search(queryInput, resultsContainer, options){
122
57
  // Provides a regexp for matching the processedDatum from the processedQuery
123
58
  // Can be overridden to provide more sophisticated matching behaviour
124
59
  this.patternForMatching = function(processedQuery){
125
- return new RegExp(processedQuery.escapeForRegExp(), 'i')
60
+ return new RegExp(escapeForRegExp(processedQuery), 'i')
126
61
  }
127
62
 
128
63
  // Can be overridden to provide more sophisticated matching behaviour
@@ -148,4 +83,11 @@ function Search(queryInput, resultsContainer, options){
148
83
  delete this.data // Data isn't an attribute we want to expose
149
84
  this.setData(options.data)
150
85
  }
151
- }
86
+
87
+ // HELPER FUNCTIONS
88
+
89
+ // Escape a string before it is used in a RegExp
90
+ function escapeForRegExp(string){
91
+ return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
92
+ }
93
+ })(jQuery)