Skip to content
This repository was archived by the owner on Feb 16, 2021. It is now read-only.

Commit 218cfb3

Browse files
committed
Remove coffee script and convert it to ES6
1 parent edd9c35 commit 218cfb3

File tree

3 files changed

+140
-99
lines changed

3 files changed

+140
-99
lines changed

Resources/assets/coffee/autocomplete.coffee

Lines changed: 0 additions & 29 deletions
This file was deleted.

Resources/assets/js/AutoComplete.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
export class AutoComplete {
2+
3+
constructor() {
4+
this.initAutoComplete();
5+
}
6+
7+
getData() {
8+
return [
9+
"ActionScript",
10+
"AppleScript",
11+
"Asp",
12+
"BASIC",
13+
"C",
14+
"C++",
15+
"Clojure",
16+
"COBOL",
17+
"ColdFusion",
18+
"Erlang",
19+
"Fortran",
20+
"Groovy",
21+
"Haskell",
22+
"Java",
23+
"JavaScript",
24+
"Lisp",
25+
"Perl",
26+
"PHP",
27+
"Python",
28+
"Ruby",
29+
"Scala",
30+
"Scheme"
31+
];
32+
}
33+
34+
initAutoComplete() {
35+
$('#autocomplete-example').autocomplete({
36+
source: this.getData()
37+
}
38+
)}
39+
}
40+
41+
new AutoComplete();

Resources/assets/coffee/charts.coffee renamed to Resources/assets/js/Charts.js

Lines changed: 99 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1-
class Charts
2-
constructor: ->
3-
$ =>
4-
@initLineChart()
5-
@initBarChart()
6-
@initRadarChart()
7-
@initPolarAreaChart()
8-
@initPieChart()
9-
@initDoughnutChart()
10-
11-
initLineChart: ->
12-
data = {
1+
export class Charts {
2+
3+
constructor(element) {
4+
if ($(element).data('type') == "line-chart"){
5+
this.initLineChart(element);
6+
}
7+
else if ($(element).data('type') == "bar-chart"){
8+
this.initBarChart(element);
9+
}
10+
else if ($(element).data('type') == "radar-chart") {
11+
this.initRadarChart(element);
12+
}
13+
else if ($(element).data('type') == 'polar-area-chart') {
14+
this.initPolarAreaChart(element);
15+
}
16+
else if ($(element).data('type') == 'pie-chart') {
17+
this.initPieChart(element);
18+
}
19+
else if ($(element).data('type') == 'doughnut-chart') {
20+
this.initDoughnutChart(element);
21+
}
22+
}
23+
24+
initLineChart(element) {
25+
let $lineChart = $(element);
26+
let data = {
1327
labels: ["January", "February", "March", "April", "May", "June", "July"],
1428
datasets: [
1529
{
@@ -33,20 +47,20 @@ class Charts
3347
data: [28, 48, 40, 19, 86, 27, 90]
3448
}
3549
]
36-
}
37-
38-
options = {
50+
};
51+
let options = {
3952
responsive: true,
40-
}
53+
};
4154

42-
$lineChart = $('#line-chart')
43-
44-
if $lineChart.length > 0
45-
ctx = $lineChart[0].getContext('2d')
46-
myLineChart = new Chart(ctx).Line(data, options)
55+
if ($lineChart.length > 0) {
56+
let myLineChart;
57+
let ctx = $lineChart[0].getContext('2d');
58+
return myLineChart = new Chart(ctx).Line(data, options);
59+
}
60+
}
4761

48-
initBarChart: ->
49-
data = {
62+
initBarChart(element) {
63+
let data = {
5064
labels: ["January", "February", "March", "April", "May", "June", "July"],
5165
datasets: [
5266
{
@@ -66,20 +80,23 @@ class Charts
6680
data: [28, 48, 40, 19, 86, 27, 90]
6781
}
6882
]
69-
}
83+
};
7084

71-
options = {
85+
let options = {
7286
responsive: true,
73-
}
87+
};
7488

75-
$barChart = $('#bar-chart')
89+
let $barChart = $(element);
7690

77-
if $barChart.length > 0
78-
ctx = $barChart[0].getContext('2d')
79-
myBarChart = new Chart(ctx).Bar(data, options)
91+
if ($barChart.length > 0) {
92+
let myBarChart;
93+
let ctx = $barChart[0].getContext('2d');
94+
return myBarChart = new Chart(ctx).Bar(data, options);
95+
}
96+
}
8097

81-
initRadarChart: ->
82-
data = {
98+
initRadarChart(element) {
99+
let data = {
83100
labels: ["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"],
84101
datasets: [
85102
{
@@ -103,20 +120,23 @@ class Charts
103120
data: [28, 48, 40, 19, 96, 27, 100]
104121
}
105122
]
106-
}
123+
};
107124

108-
options = {
125+
let options = {
109126
responsive: true,
110-
}
127+
};
111128

112-
$radarChart = $('#radar-chart')
129+
let $radarChart = $(element);
113130

114-
if $radarChart.length > 0
115-
ctx = $radarChart[0].getContext('2d')
116-
myRadarChart = new Chart(ctx).Radar(data, options)
131+
if ($radarChart.length > 0) {
132+
let myRadarChart;
133+
let ctx = $radarChart[0].getContext('2d');
134+
return myRadarChart = new Chart(ctx).Radar(data, options);
135+
}
136+
}
117137

118-
initPolarAreaChart: ->
119-
data = [
138+
initPolarAreaChart(element) {
139+
let data = [
120140
{
121141
value: 300,
122142
color:"#F7464A",
@@ -147,20 +167,23 @@ class Charts
147167
highlight: "#616774",
148168
label: "Dark Grey"
149169
}
150-
]
170+
];
151171

152-
options = {
172+
let options = {
153173
responsive: true,
154-
}
174+
};
155175

156-
$polarChart = $('#polar-area-chart')
176+
let $polarChart = $(element);
157177

158-
if $polarChart.length > 0
159-
ctx = $polarChart[0].getContext('2d')
160-
myPolarAreaChart = new Chart(ctx).PolarArea(data, options)
178+
if ($polarChart.length > 0) {
179+
let myPolarAreaChart;
180+
let ctx = $polarChart[0].getContext('2d');
181+
return myPolarAreaChart = new Chart(ctx).PolarArea(data, options);
182+
}
183+
}
161184

162-
initPieChart: ->
163-
data = [
185+
initPieChart(element) {
186+
let data = [
164187
{
165188
value: 300,
166189
color:"#F7464A",
@@ -179,21 +202,24 @@ class Charts
179202
highlight: "#FFC870",
180203
label: "Yellow"
181204
}
182-
]
205+
];
183206

184-
options = {
207+
let options = {
185208
responsive: true,
186209
showTooltips: false,
187-
}
210+
};
188211

189-
$pieChart = $('#pie-chart')
212+
let $pieChart = $(element);
190213

191-
if $pieChart.length > 0
192-
ctx = $pieChart[0].getContext('2d')
193-
myPieChart = new Chart(ctx).Pie(data, options)
214+
if ($pieChart.length > 0) {
215+
let myPieChart;
216+
let ctx = $pieChart[0].getContext('2d');
217+
return myPieChart = new Chart(ctx).Pie(data, options);
218+
}
219+
}
194220

195-
initDoughnutChart: ->
196-
data = [
221+
initDoughnutChart(element) {
222+
let data = [
197223
{
198224
value: 300,
199225
color:"#F7464A",
@@ -212,19 +238,22 @@ class Charts
212238
highlight: "#FFC870",
213239
label: "Yellow"
214240
}
215-
]
241+
];
216242

217-
options = {
243+
let options = {
218244
responsive: true,
219-
}
245+
};
220246

221-
$doughnutChart = $('#doughnut-chart')
247+
let $doughnutChart = $(element);
222248

223-
if $doughnutChart.length > 0
224-
ctx = $doughnutChart[0].getContext('2d')
225-
myDoughnutChart = new Chart(ctx).Doughnut(data, options)
226-
227-
228-
Charts.current = new Charts()
249+
if ($doughnutChart.length > 0) {
250+
let myDoughnutChart;
251+
let ctx = $doughnutChart[0].getContext('2d');
252+
return myDoughnutChart = new Chart(ctx).Doughnut(data, options);
253+
}
254+
}
255+
}
229256

230-
window.Charts = Charts
257+
$('.chart').each((index, element) => {
258+
element.chart = new Charts($(element));
259+
});

0 commit comments

Comments
 (0)