From de6b6526cec02c07a8fa2601f4eb3fbff3255cc0 Mon Sep 17 00:00:00 2001 From: John Chen Date: Fri, 3 Aug 2012 14:58:30 +0800 Subject: [PATCH] [Widgets] Extend zones more gracefully Looking for parent zone with the same name. If found, extend it with descendant zone, otherwize add a new zone. --- index.html | 2 +- src/js/widgets.js | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 63575124..be1f29a0 100644 --- a/index.html +++ b/index.html @@ -25,6 +25,7 @@ + @@ -35,7 +36,6 @@ - diff --git a/src/js/widgets.js b/src/js/widgets.js index 4f4e845c..ead7546d 100644 --- a/src/js/widgets.js +++ b/src/js/widgets.js @@ -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; @@ -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; }