Skip to content

Commit d5c3269

Browse files
committed
[spalenque] - allow multiple instances
1 parent d9b6dd1 commit d5c3269

3 files changed

Lines changed: 80 additions & 74 deletions

File tree

app/app.js

Lines changed: 77 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -17,83 +17,88 @@ define(['jquery', 'ractive', 'rv!templates/template', 'text!css/widget-styles.cs
1717
.append($style)
1818
.append('<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" >');
1919

20-
// render our main view
21-
this.ractive = new Ractive({
22-
el: 'openstack-search-bar',
23-
baseUrl: baseUrl,
24-
context: context,
25-
template: mainTemplate,
26-
data: {
27-
term: '',
28-
page: 1,
29-
perPage: 10,
30-
pagesToShow: [1,2,3,4,5],
31-
fromResult: 1,
32-
toResult: 10,
33-
total: 88,
34-
results: [],
35-
suggestions: []
36-
}
37-
});
38-
39-
this.ractive.on({
40-
clear: function(ev) {
41-
ev.original.preventDefault();
42-
$('.ossw-search-suggestions').hide();
43-
this.set('term', '');
44-
},
45-
search: function(ev) {
46-
var term = this.get('term');
47-
var that = this;
48-
ev.original.preventDefault();
49-
50-
if(ev.original.keyCode == 13) {
51-
if ( xhr_suggestions ) xhr_suggestions.abort();
52-
if ( timeout_suggestions ) clearTimeout(timeout_suggestions);
53-
54-
doSearch(that, true);
55-
$('.ossw-search-results').show();
56-
$('.ossw-search-suggestions').hide();
57-
$('.ossw-suggestions-wrapper').hide();
58-
} else {
59-
$('.ossw-search-suggestions').show();
60-
if ( timeout_suggestions ) clearTimeout(timeout_suggestions);
61-
timeout_suggestions = window.setTimeout(doSuggestions, 500, that);
20+
$('.openstack-search-bar').each(function() {
21+
22+
var el = $(this);
23+
// render our main view
24+
this.ractive = new Ractive({
25+
el: el,
26+
baseUrl: baseUrl,
27+
context: context,
28+
template: mainTemplate,
29+
data: {
30+
term: '',
31+
page: 1,
32+
perPage: 10,
33+
pagesToShow: [1,2,3,4,5],
34+
fromResult: 1,
35+
toResult: 10,
36+
total: 88,
37+
results: [],
38+
suggestions: []
6239
}
63-
},
64-
searchPopup: function(ev) {
65-
var term = this.get('term');
66-
var that = this;
67-
68-
ev.original.preventDefault();
69-
70-
if(ev.original.keyCode == 13) {
71-
doSearch(that, true);
72-
$('.ossw-suggestions-wrapper').hide();
73-
} else {
74-
$('.ossw-suggestions-wrapper').show();
75-
if ( timeout_suggestions ) clearTimeout(timeout_suggestions);
76-
timeout_suggestions = window.setTimeout(doSuggestions, 500, that);
40+
});
41+
42+
this.ractive.on({
43+
clear: function(ev) {
44+
ev.original.preventDefault();
45+
$('.ossw-search-suggestions', el).hide();
46+
this.set('term', '');
47+
},
48+
search: function(ev) {
49+
var term = this.get('term');
50+
var that = this;
51+
ev.original.preventDefault();
52+
53+
if(ev.original.keyCode == 13) {
54+
if ( xhr_suggestions ) xhr_suggestions.abort();
55+
if ( timeout_suggestions ) clearTimeout(timeout_suggestions);
56+
57+
doSearch(that, true);
58+
$('.ossw-search-results', el).show();
59+
$('.ossw-search-suggestions', el).hide();
60+
$('.ossw-suggestions-wrapper', el).hide();
61+
} else {
62+
$('.ossw-search-suggestions', el).show();
63+
if ( timeout_suggestions ) clearTimeout(timeout_suggestions);
64+
timeout_suggestions = window.setTimeout(doSuggestions, 500, that);
65+
}
66+
},
67+
searchPopup: function(ev) {
68+
var term = this.get('term');
69+
var that = this;
70+
71+
ev.original.preventDefault();
72+
73+
if(ev.original.keyCode == 13) {
74+
doSearch(that, true);
75+
$('.ossw-suggestions-wrapper', el).hide();
76+
} else {
77+
$('.ossw-suggestions-wrapper', el).show();
78+
if ( timeout_suggestions ) clearTimeout(timeout_suggestions);
79+
timeout_suggestions = window.setTimeout(doSuggestions, 500, that);
80+
}
81+
},
82+
closePopup: function(ev) {
83+
$('.ossw-search-results', el).hide();
84+
},
85+
changePage: function(ev, newPage) {
86+
var total = this.get('total');
87+
var perPage = this.get('perPage');
88+
var totalPages = Math.ceil(total / perPage);
89+
var that = this;
90+
91+
ev.original.preventDefault();
92+
if (newPage > totalPages || newPage < 1) return false;
93+
94+
changePagination(that, newPage);
95+
doSearch(that, false);
7796
}
78-
},
79-
closePopup: function(ev) {
80-
$('.ossw-search-results').hide();
81-
},
82-
changePage: function(ev, newPage) {
83-
var total = this.get('total');
84-
var perPage = this.get('perPage');
85-
var totalPages = Math.ceil(total / perPage);
86-
var that = this;
87-
88-
ev.original.preventDefault();
89-
if (newPage > totalPages || newPage < 1) return false;
90-
91-
changePagination(that, newPage);
92-
doSearch(that, false);
93-
}
97+
});
9498
});
9599

96100

101+
97102
}
98103
};
99104

0 commit comments

Comments
 (0)