1 | "use babel"; |
||
2 | |||
3 | import DevmindBeautifierView from "./devmind-beautifier-view"; |
||
4 | import { CompositeDisposable } from "atom"; |
||
5 | var qs = require("qs"); |
||
6 | |||
7 | function request(ext, text, url) { |
||
8 | data = { extension: ext, content: text }; |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
9 | var http = new XMLHttpRequest(); |
||
0 ignored issues
–
show
The variable
XMLHttpRequest seems to be never declared. If this is a global, consider adding a /** global: XMLHttpRequest */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN.
Loading history...
|
|||
10 | http.open("POST", url, true); |
||
11 | http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); |
||
12 | http.send(qs.stringify(data)); |
||
13 | changeState(http); |
||
14 | } |
||
15 | |||
16 | function changeState(http) { |
||
17 | http.onreadystatechange = function() { |
||
18 | if (http.readyState == 4 && http.status == 200) { |
||
19 | success(http); |
||
20 | } |
||
21 | if (http.status !== 200) { |
||
22 | fail(); |
||
23 | } |
||
24 | }; |
||
25 | } |
||
26 | |||
27 | function success(http) { |
||
28 | if (typeof http.responseText.status === "undefined") { |
||
29 | editor.setText(http.responseText); |
||
0 ignored issues
–
show
The variable
editor seems to be never declared. If this is a global, consider adding a /** global: editor */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN.
Loading history...
|
|||
30 | atom.notifications.addSuccess("Now your code looks fancy"); |
||
0 ignored issues
–
show
The variable
atom seems to be never declared. If this is a global, consider adding a /** global: atom */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN.
Loading history...
|
|||
31 | panel.modalPanel.hide(); |
||
0 ignored issues
–
show
The variable
panel seems to be never declared. If this is a global, consider adding a /** global: panel */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN.
Loading history...
|
|||
32 | } else { |
||
33 | atom.notifications.addInfo("File extension not supported. Yet."); |
||
34 | } |
||
35 | } |
||
36 | |||
37 | function fail() { |
||
38 | panel.modalPanel.hide(); |
||
0 ignored issues
–
show
The variable
panel seems to be never declared. If this is a global, consider adding a /** global: panel */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN.
Loading history...
|
|||
39 | atom.notifications.addError( |
||
0 ignored issues
–
show
The variable
atom seems to be never declared. If this is a global, consider adding a /** global: atom */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN.
Loading history...
|
|||
40 | "Something went wrong, please check your internet connection" |
||
41 | ); |
||
42 | } |
||
43 | |||
44 | export default { |
||
45 | devmindBeautifierView: null, |
||
46 | modalPanel: null, |
||
47 | subscriptions: null, |
||
48 | |||
49 | activate(state) { |
||
50 | this.devmindBeautifierView = new DevmindBeautifierView( |
||
51 | state.devmindBeautifierViewState |
||
52 | ); |
||
53 | this.modalPanel = atom.workspace.addModalPanel({ |
||
0 ignored issues
–
show
The variable
atom seems to be never declared. If this is a global, consider adding a /** global: atom */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN.
Loading history...
|
|||
54 | item: this.devmindBeautifierView.getElement(), |
||
55 | visible: false |
||
56 | }); |
||
57 | |||
58 | // Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable |
||
59 | this.subscriptions = new CompositeDisposable(); |
||
60 | |||
61 | // Register command that toggles this view |
||
62 | this.subscriptions.add( |
||
63 | atom.commands.add("atom-workspace", { |
||
64 | "devmind-beautifier:toggle": () => this.toggle() |
||
65 | }) |
||
66 | ); |
||
67 | }, |
||
68 | |||
69 | deactivate() { |
||
70 | this.modalPanel.destroy(); |
||
71 | this.subscriptions.dispose(); |
||
72 | this.devmindBeautifierView.destroy(); |
||
73 | }, |
||
74 | |||
75 | serialize() { |
||
76 | return { |
||
77 | devmindBeautifierViewState: this.devmindBeautifierView.serialize() |
||
78 | }; |
||
79 | }, |
||
80 | |||
81 | toggle() { |
||
82 | panel = this; |
||
0 ignored issues
–
show
|
|||
83 | |||
84 | editor = atom.workspace.getActiveTextEditor(); |
||
0 ignored issues
–
show
The variable
atom seems to be never declared. If this is a global, consider adding a /** global: atom */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN.
Loading history...
|
|||
85 | text = editor.getText().trim(); |
||
0 ignored issues
–
show
|
|||
86 | fileName = editor.getTitle(); |
||
0 ignored issues
–
show
|
|||
87 | ext = fileName |
||
0 ignored issues
–
show
|
|||
88 | .split(".") |
||
89 | .pop() |
||
90 | .trim(); |
||
91 | request(ext, text, "https://beautifier.devmind.io/format"); |
||
92 | } |
||
93 | }; |
||
94 |