Skip to content

Commit 48c7bf0

Browse files
author
Miika Arponen
authored
Merge pull request #17 from ivuorinen/fix/ajax-of-undefined
Uncaught TypeError: Cannot set property 'Ajax' of undefined
2 parents c7e88e7 + 0157547 commit 48c7bf0

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
composer.phar
2+
composer.lock
3+
/vendor/

js/dustpress-debugger-min.js

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

js/dustpress-debugger.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/**
22
* DUSTPRESS DEBUGGER
33
*/
44
window.DustPressDebugger = ( function( window, document, $ ) {
@@ -51,32 +51,36 @@ window.DustPressDebugger = ( function( window, document, $ ) {
5151
"action": "dustpress_debugger",
5252
"hash" : dustpress_debugger.hash
5353
},
54-
success:function(data) {
54+
success: function(data) {
5555
if (typeof data !== "object") {
5656
data = JSON.parse(data);
5757
}
5858
app.jsonData = data.data;
5959

60+
if ( "undefined" === typeof app.jsonData.Debugs ) {
61+
app.jsonData.Debugs = {};
62+
}
63+
6064
app.jsonData.Debugs.Ajax = app.waiting;
6165
delete app.waiting;
6266

6367
// Log also into the console
6468
console.log("Debugger", app.jsonData);
6569

6670
app.jsonView = app.$jsonDiv.JSONView(
67-
app.jsonData,
68-
app.jsonSettings
71+
app.jsonData,
72+
app.jsonSettings
6973
);
7074
},
7175
error: function(e){
72-
console.log("DustPress Debugger Error", e);
76+
console.error("DustPress Debugger Error", e);
7377
}
7478
});
7579
};
7680

7781
app.closeByEsc = function(e) {
7882
// Escape key maps to keycode 27
79-
if (e.keyCode == 27) {
83+
if (e.keyCode === 27) {
8084
if ( ! $(".jsonview_data_debug").hasClass("jsonview_data_debug_closed") ) {
8185
app.toggleDebugger();
8286
}
@@ -95,26 +99,31 @@ window.DustPressDebugger = ( function( window, document, $ ) {
9599
}
96100

97101
// Catch the data before the JSONView is rendered
98-
if ( undefined == app.jsonData ) {
102+
if ( "undefined" === typeof app.jsonData ) {
99103
if ( "undefined" === typeof app.waiting[key] ) {
100104
app.waiting[key] = [];
101105
}
102106
app.waiting[key].push(data);
103107
}
104108
// Add the extended data and rerender the JSONView
105109
else {
106-
if ( undefined === app.jsonData.Debugs.Ajax ) {
110+
if ( "undefined" === typeof app.jsonData.Debugs ) {
111+
app.jsonData.Debugs = {};
112+
}
113+
114+
if ( "undefined" === typeof app.jsonData.Debugs.Ajax ) {
107115
app.jsonData.Debugs.Ajax = {};
108116
}
109117

110118
if ( undefined === app.jsonData.Debugs.Ajax[key] ) {
111119
app.jsonData.Debugs.Ajax[key] = [];
112120
}
121+
113122
app.jsonData.Debugs.Ajax[key].push(data);
114123

115124
app.$jsonDiv.JSONView(
116-
app.jsonData,
117-
app.jsonSettings
125+
app.jsonData,
126+
app.jsonSettings
118127
);
119128
}
120129
};
@@ -124,4 +133,4 @@ window.DustPressDebugger = ( function( window, document, $ ) {
124133

125134
return app;
126135

127-
})( window, document, jQuery );
136+
})( window, document, jQuery );

0 commit comments

Comments
 (0)