Skip to content
This repository has been archived by the owner on Mar 14, 2020. It is now read-only.

Commit

Permalink
[Widgets] Extend zones more gracefully
Browse files Browse the repository at this point in the history
Looking for parent zone with the same name. If found, extend it
with descendant zone, otherwize add a new zone.
  • Loading branch information
zhizhangchen authored and grgustaf committed Sep 1, 2012
1 parent 3f9bb5e commit de6b652
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.html
Expand Up @@ -25,6 +25,7 @@
<body class="vbox fullsize">
<script src="lib/jquery-1.6.4.min.js"></script>
<script src="lib/jquery-ui-1.8.16.custom.min.js"></script>
<script src="src/js/jquery-workarounds.js"></script>
<script src="src/js/msg-box.js"></script>
<script src="src/js/events.js"></script>
<script src="src/js/widgets.js"></script>
Expand All @@ -35,7 +36,6 @@
<script src="src/js/projects.js"></script>
<script src="src/js/serialize.js"></script>
<!-- New stuff from here ... -->
<script src="src/js/jquery-workarounds.js"></script>
<script src="src/js/jquery-plugins.js"></script>
<script src="src/js/views/base.js"></script>
<script src="src/js/views/tree.js"></script>
Expand Down
22 changes: 21 additions & 1 deletion src/js/widgets.js
Expand Up @@ -2619,7 +2619,7 @@ var BWidget = {
init: function () {
// effects: add the type and displayLabel properties to widget
// registry objects
var type, parentName;
var type, parentName, newZones, descendantZone, descendantZoneIndex;
for (type in BWidgetRegistry) {
if (BWidgetRegistry.hasOwnProperty(type)) {
BWidgetRegistry[type].type = type;
Expand Down Expand Up @@ -2657,6 +2657,26 @@ var BWidget = {
}
parentName = BWidgetRegistry[type].parent;
while (parentName) {
if (BWidgetRegistry[parentName].zones) {
newZones = [];
$.each(BWidgetRegistry[parentName].zones, function (i, pZone) {
descendantZone = null;
if (BWidgetRegistry[type].zones)
$.each(BWidgetRegistry[type].zones, function (i, zone) {
if (pZone.name === zone.name) {
descendantZone = zone;
descendantZoneIndex = i;
return false;
}
});
if (descendantZone)
BWidgetRegistry[type].zones[descendantZoneIndex] = $.extend(true, true, {}, pZone, descendantZone);
else
newZones.push(pZone);
});
if(BWidgetRegistry[type].zones)
$.merge(BWidgetRegistry[type].zones, newZones);
}
BWidgetRegistry[type] = $.extend(true, true, {}, BWidgetRegistry[parentName], BWidgetRegistry[type]);
parentName = BWidgetRegistry[parentName].parent;
}
Expand Down

0 comments on commit de6b652

Please sign in to comment.