Skip to content

Instantly share code, notes, and snippets.

@fwextensions
Created March 9, 2009 16:05
Show Gist options
  • Save fwextensions/76356 to your computer and use it in GitHub Desktop.
Save fwextensions/76356 to your computer and use it in GitHub Desktop.
try {
(function()
{
if (fw.selection.length == 0) {
alert("To use this command, first select a group from which the Smart Resize auto shape should be detached.");
return;
}
var dom = fw.getDocumentDOM();
// remove Smart Resize auto shapes from the current selection, digging
// into groups as needed
var selection = removeSmartResize([].concat(fw.selection));
// there aren't any auto shapes left in selection, but there might be
// groups that now contain a single group (and which used to also contain
// an auto shape), so go through them and remove extra groups
for (var i = selection.length - 1; i >= 0; i--) {
fw.selection = [selection[i]];
dom.selectParents();
var parent = fw.selection[0];
// trying to check parent != selection[i] doesn't work. even when
// it's the same element, the check is false. so just check that
// the parent is a group and is not a smart shape, otherwise ungrouping
// the smart shape would cause an error.
if (!parent.isSmartShape && parent.elements && parent.elements.length == 1) {
// element has a parent group that contains just 1 element, so
// get rid of the parent group
dom.ungroup();
}
}
fw.selection = selection;
function removeSmartResize(
inElements)
{
var remainingElements = [];
var dom = fw.getDocumentDOM();
for (var i = inElements.length - 1; i >= 0; i--) {
var element = inElements[i];
if (element.customData.shapeName == "Smart Resize") {
fw.selection = [element];
dom.deleteSelection(false);
} else if (element.elements && !element.isSmartShape) {
var elementCount = element.elements.length;
arguments.callee([].concat(element.elements));
if (element.elements.length == 1 && element.elements.length != elementCount) {
fw.selection = [element];
dom.ungroup();
remainingElements = remainingElements.concat(fw.selection);
} else {
remainingElements.push(element);
}
} else {
remainingElements.push(element);
}
}
return remainingElements;
}
})();
} catch (exception) {
alert([exception, exception.lineNumber, exception.fileName].join("\n"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment