Skip to content

Commit 3bbed50

Browse files
committed
cleanup js
1 parent 9c10907 commit 3bbed50

File tree

6 files changed

+16
-110
lines changed

6 files changed

+16
-110
lines changed

app/concepts/matestack/ui/core/collection/content/content.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def setup
99

1010
def response
1111
components {
12-
div attributes: {"v-if": "showing"} do
12+
div do
1313
yield_components
1414
end
1515
}

app/concepts/matestack/ui/core/collection/filter/input/input.haml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@
55
id: component_id,
66
"@keyup.enter": "submitFilter()",
77
ref: "filter.#{attr_key}",
8-
placeholder: options[:placeholder],
9-
"init-value": init_value}
8+
placeholder: options[:placeholder]}

app/concepts/matestack/ui/core/collection/filter/input/input.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,5 @@ def attr_key
99
return options[:key].to_s
1010
end
1111

12-
def init_value
13-
14-
end
15-
1612
end
1713
end

app/concepts/matestack/ui/core/collection/order/order.js

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Vue from 'vue/dist/vue.esm'
22

33
import matestackEventHub from 'js/event-hub'
4+
import queryParamsHelper from 'js/helpers/query-params-helper'
45

56
import componentMixin from 'component/component'
67

@@ -21,8 +22,8 @@ const componentDef = {
2122
this.ordering[key] = undefined
2223
}
2324
var url;
24-
url = this.updateQueryParams(this.componentConfig["id"] + "-order-" + key, this.ordering[key])
25-
url = this.updateQueryParams(this.componentConfig["id"] + "-offset", 0, url)
25+
url = queryParamsHelper.updateQueryParams(this.componentConfig["id"] + "-order-" + key, this.ordering[key])
26+
url = queryParamsHelper.updateQueryParams(this.componentConfig["id"] + "-offset", 0, url)
2627
window.history.pushState({matestackApp: true, url: url}, null, url);
2728
matestackEventHub.$emit(this.componentConfig["id"] + "-update")
2829
this.$forceUpdate()
@@ -33,67 +34,17 @@ const componentDef = {
3334
resetFilter: function(){
3435
var url;
3536
for (var key in this.filter) {
36-
url = this.updateQueryParams(this.componentConfig["id"] + "-filter-" + key, null)
37+
url = queryParamsHelper.updateQueryParams(this.componentConfig["id"] + "-filter-" + key, null)
3738
this.filter[key] = null;
3839
this.$forceUpdate();
3940
}
4041
window.history.pushState({matestackApp: true, url: url}, null, url);
4142
matestackEventHub.$emit(this.componentConfig["id"] + "-update")
42-
},
43-
updateQueryParams: function (key, value, url) {
44-
if (!url) url = window.location.href;
45-
var re = new RegExp("([?&])" + key + "=.*?(&|#|$)(.*)", "gi"),
46-
hash;
47-
48-
if (re.test(url)) {
49-
if (typeof value !== 'undefined' && value !== null)
50-
return url.replace(re, '$1' + key + "=" + value + '$2$3');
51-
else {
52-
hash = url.split('#');
53-
url = hash[0].replace(re, '$1$3').replace(/(&|\?)$/, '');
54-
if (typeof hash[1] !== 'undefined' && hash[1] !== null)
55-
url += '#' + hash[1];
56-
return url;
57-
}
58-
}
59-
else {
60-
if (typeof value !== 'undefined' && value !== null) {
61-
var separator = url.indexOf('?') !== -1 ? '&' : '?';
62-
hash = url.split('#');
63-
url = hash[0] + separator + key + '=' + value;
64-
if (typeof hash[1] !== 'undefined' && hash[1] !== null)
65-
url += '#' + hash[1];
66-
return url;
67-
}
68-
else
69-
return url;
70-
}
71-
},
72-
getQueryParam: function (name, url) {
73-
if (!url) url = window.location.href;
74-
name = name.replace(/[\[\]]/g, '\\$&');
75-
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
76-
results = regex.exec(url);
77-
if (!results) return null;
78-
if (!results[2]) return '';
79-
return decodeURIComponent(results[2].replace(/\+/g, ' '));
80-
},
81-
queryParamsToObject: function(){
82-
var search = window.location.search.substring(1);
83-
if(search.length === 0){
84-
return {}
85-
} else {
86-
var result = JSON.parse(
87-
'{"' + search.replace(/&/g, '","').replace(/=/g,'":"') + '"}',
88-
function(key, value) { return key===""?value:decodeURIComponent(value) }
89-
)
90-
return result;
91-
}
9243
}
9344
},
9445
created: function(){
9546
var self = this;
96-
var queryParamsObject = this.queryParamsToObject()
47+
var queryParamsObject = queryParamsHelper.queryParamsToObject()
9748
Object.keys(queryParamsObject).forEach(function(key){
9849
if (key.startsWith(self.componentConfig["id"] + "-order-")){
9950
self.ordering[key.replace(self.componentConfig["id"] + "-order-", "")] = queryParamsObject[key]

vendor/assets/javascripts/matestack-ui-core.js

Lines changed: 8 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/assets/javascripts/matestack-ui-core.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)