brett
2 Feb 2007, 4:56 PM
We're using lots of YUI and yui-ext at work, and we're finally implementing BorderLayout for some projects. But, I've run into a scope issue that only surfaces with a prototype-based approach to OO-Javascript.
Firebug has been a big help, but even this seems to be beyond the reach of a good code-stepping.
I've put together a few test files to illustrate the issue. First is the HTML. Then, there are two flavors of Javascript I use for the custom piece. The first is a prototype approach, and the second uses the approach from the yui-ext examples, but slightly modified to be a bit more OO-friendly.
I've tested this by first using the yui-ext example flavor, and found that BorderLayout works as expected. Then, I swtiched to the prototype flavor, and Firebug kindly tells me that "this.el has no properties."
I suspect that in the prototype flavor, the document object is out of scope because document.body is null. Working it over with Firebug hasn't given me any clues otherwise.
Any help, insight or feedback is greatly appreciated.
index.html
<html>
<head>
<title>yui-test</title>
<link rel="stylesheet" type="text/css"
href="yui-ext/resources/css/yui-ext.css" />
<script type="text/javascript" src="yui/build/yahoo/yahoo-min.js"></script>
<script type="text/javascript" src="yui/build/event/event-min.js"></script>
<script type="text/javascript" src="yui/build/dom/dom-min.js"></script>
<script type="text/javascript" src="yui/build/dragdrop/dragdrop-min.js"></script>
<script type="text/javascript" src="yui-ext/yui-ext.js"></script>
<script type="text/javascript" src="layout.js"></script>
</head>
<body>
<div id="north">North</div>
<div id="west">West</div>
<div id="center">Center</div>
<div id="east">East</div>
<div id="south">South</div>
</body>
</html>
layout1.js - prototype flavor
function DefaultLayout() {
this.init();
}
DefaultLayout.prototype = {
_layout: null,
init: function() {
if (this._layout) { return; }
this._layout = new YAHOO.ext.BorderLayout(document.body, {
north: {},
east: {
split: true,
initialSize: 200,
collapsible: true,
minSize: 100,
maxSize: 400
},
south: {},
west: {
split: true,
initialSize: 200,
collapsible: true,
minSize: 100,
maxSize: 400
},
center: {
autoScroll: true
}
});
},
initLayout: function() {
this._layout.beginUpdate();
this._layout.add('north', new YAHOO.ext.ContentPanel('north'));
this._layout.add('east', new YAHOO.ext.ContentPanel('east'));
this._layout.add('south', new YAHOO.ext.ContentPanel('south'));
this._layout.add('west', new YAHOO.ext.ContentPanel('west'));
this._layout.add('center', new YAHOO.ext.ContentPanel('center', { fitToFrame: true }));
this._layout.endUpdate();
}
};
var layout = new DefaultLayout();
YAHOO.ext.EventManager.onDocumentReady(layout.initLayout,
layout, true);
layout2.js - yui-ext flavor
DefaultLayout = function() {
return {
_layout: null,
init: function() {
this._layout = new YAHOO.ext.BorderLayout(document.body, {
north: {},
east: {
split: true,
initialSize: 200,
collapsible: true,
minSize: 100,
maxSize: 400
},
south: {},
west: {
split: true,
initialSize: 200,
collapsible: true,
minSize: 100,
maxSize: 400
},
center: {
autoScroll: true
}
});
},
initLayout: function() {
if(!this._layout) {
this.init();
}
this._layout.beginUpdate();
this._layout.add('north', new YAHOO.ext.ContentPanel('north'));
this._layout.add('east', new YAHOO.ext.ContentPanel('east'));
this._layout.add('south', new YAHOO.ext.ContentPanel('south'));
this._layout.add('west', new YAHOO.ext.ContentPanel('west'));
this._layout.add('center', new YAHOO.ext.ContentPanel('center', { fitToFrame: true }));
this._layout.endUpdate();
}
}
}();
var layout = DefaultLayout;
YAHOO.ext.EventManager.onDocumentReady(layout.initLayout,
layout, true);
Firebug has been a big help, but even this seems to be beyond the reach of a good code-stepping.
I've put together a few test files to illustrate the issue. First is the HTML. Then, there are two flavors of Javascript I use for the custom piece. The first is a prototype approach, and the second uses the approach from the yui-ext examples, but slightly modified to be a bit more OO-friendly.
I've tested this by first using the yui-ext example flavor, and found that BorderLayout works as expected. Then, I swtiched to the prototype flavor, and Firebug kindly tells me that "this.el has no properties."
I suspect that in the prototype flavor, the document object is out of scope because document.body is null. Working it over with Firebug hasn't given me any clues otherwise.
Any help, insight or feedback is greatly appreciated.
index.html
<html>
<head>
<title>yui-test</title>
<link rel="stylesheet" type="text/css"
href="yui-ext/resources/css/yui-ext.css" />
<script type="text/javascript" src="yui/build/yahoo/yahoo-min.js"></script>
<script type="text/javascript" src="yui/build/event/event-min.js"></script>
<script type="text/javascript" src="yui/build/dom/dom-min.js"></script>
<script type="text/javascript" src="yui/build/dragdrop/dragdrop-min.js"></script>
<script type="text/javascript" src="yui-ext/yui-ext.js"></script>
<script type="text/javascript" src="layout.js"></script>
</head>
<body>
<div id="north">North</div>
<div id="west">West</div>
<div id="center">Center</div>
<div id="east">East</div>
<div id="south">South</div>
</body>
</html>
layout1.js - prototype flavor
function DefaultLayout() {
this.init();
}
DefaultLayout.prototype = {
_layout: null,
init: function() {
if (this._layout) { return; }
this._layout = new YAHOO.ext.BorderLayout(document.body, {
north: {},
east: {
split: true,
initialSize: 200,
collapsible: true,
minSize: 100,
maxSize: 400
},
south: {},
west: {
split: true,
initialSize: 200,
collapsible: true,
minSize: 100,
maxSize: 400
},
center: {
autoScroll: true
}
});
},
initLayout: function() {
this._layout.beginUpdate();
this._layout.add('north', new YAHOO.ext.ContentPanel('north'));
this._layout.add('east', new YAHOO.ext.ContentPanel('east'));
this._layout.add('south', new YAHOO.ext.ContentPanel('south'));
this._layout.add('west', new YAHOO.ext.ContentPanel('west'));
this._layout.add('center', new YAHOO.ext.ContentPanel('center', { fitToFrame: true }));
this._layout.endUpdate();
}
};
var layout = new DefaultLayout();
YAHOO.ext.EventManager.onDocumentReady(layout.initLayout,
layout, true);
layout2.js - yui-ext flavor
DefaultLayout = function() {
return {
_layout: null,
init: function() {
this._layout = new YAHOO.ext.BorderLayout(document.body, {
north: {},
east: {
split: true,
initialSize: 200,
collapsible: true,
minSize: 100,
maxSize: 400
},
south: {},
west: {
split: true,
initialSize: 200,
collapsible: true,
minSize: 100,
maxSize: 400
},
center: {
autoScroll: true
}
});
},
initLayout: function() {
if(!this._layout) {
this.init();
}
this._layout.beginUpdate();
this._layout.add('north', new YAHOO.ext.ContentPanel('north'));
this._layout.add('east', new YAHOO.ext.ContentPanel('east'));
this._layout.add('south', new YAHOO.ext.ContentPanel('south'));
this._layout.add('west', new YAHOO.ext.ContentPanel('west'));
this._layout.add('center', new YAHOO.ext.ContentPanel('center', { fitToFrame: true }));
this._layout.endUpdate();
}
}
}();
var layout = DefaultLayout;
YAHOO.ext.EventManager.onDocumentReady(layout.initLayout,
layout, true);