Skip to content

Commit 94a16d7

Browse files
authored
Better iframe support (php-debugbar#636)
1 parent b32d998 commit 94a16d7

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

demo/iframes/iframe2.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,14 @@
66

77
$debugbar['messages']->addMessage('I\'m a Deeper Hidden Iframe');
88

9-
render_demo_page(function() {});
9+
render_demo_page(function() {
10+
?>
11+
<script type="text/javascript">
12+
$(function() {
13+
$.get('../ajax.php', function(data) {
14+
//ajax from IFRAME
15+
});
16+
});
17+
</script>
18+
<?php
19+
});

src/DebugBar/Resources/debugbar.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,7 @@ if (typeof(PhpDebugBar) == 'undefined') {
425425
this.activeDatasetId = null;
426426
this.datesetTitleFormater = new DatasetTitleFormater(this);
427427
this.options.bodyMarginBottomHeight = parseInt($('body').css('margin-bottom'));
428-
this.hasParent = window.parent && window.parent !== window.top
429-
&& window.parent.phpdebugbar && window.parent.phpdebugbar != this;
428+
this.isIframe = window.self !== window.top;
430429
this.registerResizeHandler();
431430
},
432431

@@ -436,7 +435,7 @@ if (typeof(PhpDebugBar) == 'undefined') {
436435
* @this {DebugBar}
437436
*/
438437
registerResizeHandler: function() {
439-
if (typeof this.resize.bind == 'undefined' || this.hasParent) return;
438+
if (typeof this.resize.bind == 'undefined' || this.isIframe) return;
440439

441440
var f = this.resize.bind(this);
442441
this.respCSSSize = 0;
@@ -477,7 +476,7 @@ if (typeof(PhpDebugBar) == 'undefined') {
477476
* @this {DebugBar}
478477
*/
479478
render: function() {
480-
if (this.hasParent) {
479+
if (this.isIframe) {
481480
this.$el.hide();
482481
}
483482

@@ -580,7 +579,7 @@ if (typeof(PhpDebugBar) == 'undefined') {
580579
* @this {DebugBar}
581580
*/
582581
restoreState: function() {
583-
if (this.hasParent) return;
582+
if (this.isIframe) return;
584583
// bar height
585584
var height = localStorage.getItem('phpdebugbar-height');
586585
this.setHeight(height || this.$body.height());
@@ -934,12 +933,8 @@ if (typeof(PhpDebugBar) == 'undefined') {
934933
* @return {String} Dataset's id
935934
*/
936935
addDataSet: function(data, id, suffix, show) {
937-
if (this.hasParent) {
938-
if (!suffix || ('(iframe)').indexOf(suffix) < 0) {
939-
suffix = '(iframe)' + (suffix || '');
940-
}
941-
942-
window.parent.phpdebugbar.addDataSet(data, id, suffix, show);
936+
if (this.isIframe) {
937+
window.top.phpdebugbar.addDataSet(data, id, '(iframe)' + (suffix || ''), show);
943938
return;
944939
}
945940

0 commit comments

Comments
 (0)