2011-03-24 21:28:43 -07:00
|
|
|
|
jQuery(document).ready(function ($) {
|
2011-02-14 17:19:44 -08:00
|
|
|
|
$(function () {
|
2011-03-25 12:36:39 -07:00
|
|
|
|
// default shape window height when first opened
|
|
|
|
|
var defaultHeight = 200;
|
|
|
|
|
|
2011-03-09 16:06:37 -08:00
|
|
|
|
// append the shape tracing window container at the end of the document
|
2011-03-10 22:37:50 -08:00
|
|
|
|
$('<div id="shape-tracing-container"> ' +
|
|
|
|
|
'<div id="shape-tracing-resize-handle" ></div>' +
|
2011-03-10 13:50:46 -08:00
|
|
|
|
'<div id="shape-tracing-toolbar">' +
|
2011-03-10 22:37:50 -08:00
|
|
|
|
'<div id="shape-tracing-toolbar-switch"></div>' +
|
2011-03-10 13:50:46 -08:00
|
|
|
|
'</div>' +
|
2011-03-12 16:18:33 -08:00
|
|
|
|
'<div id="shape-tracing-window">' +
|
|
|
|
|
'<div id="shape-tracing-window-tree"></div>' +
|
2011-03-21 09:44:40 -07:00
|
|
|
|
'<div id="shape-tracing-window-content"></div>' +
|
2011-03-12 16:18:33 -08:00
|
|
|
|
'</div>' +
|
2011-03-10 13:50:46 -08:00
|
|
|
|
'</div>' +
|
2011-03-14 16:15:00 -07:00
|
|
|
|
'<div id="shape-tracing-container-ghost"></div>' +
|
|
|
|
|
'<div id="shape-tracing-overlay"></div>'
|
2011-03-10 13:50:46 -08:00
|
|
|
|
).appendTo('body');
|
2011-03-09 16:06:37 -08:00
|
|
|
|
|
|
|
|
|
// preload main objects
|
|
|
|
|
var shapeTracingContainer = $('#shape-tracing-container');
|
2011-03-14 16:15:00 -07:00
|
|
|
|
var shapeTracingResizeHandle = $('#shape-tracing-resize-handle');
|
2011-03-09 16:06:37 -08:00
|
|
|
|
var shapeTracingToolbar = $('#shape-tracing-toolbar');
|
2011-03-10 13:50:46 -08:00
|
|
|
|
var shapeTracingToolbarSwitch = $('#shape-tracing-toolbar-switch');
|
2011-03-09 16:06:37 -08:00
|
|
|
|
var shapeTracingWindow = $('#shape-tracing-window');
|
2011-03-12 16:18:33 -08:00
|
|
|
|
var shapeTracingWindowTree = $('#shape-tracing-window-tree');
|
|
|
|
|
var shapeTracingWindowContent = $('#shape-tracing-window-content');
|
2011-03-09 16:06:37 -08:00
|
|
|
|
var shapeTracingGhost = $('#shape-tracing-container-ghost');
|
2011-03-14 16:15:00 -07:00
|
|
|
|
var shapeTracingOverlay = $('#shape-tracing-overlay');
|
2011-03-09 16:06:37 -08:00
|
|
|
|
|
2011-03-23 21:51:27 -07:00
|
|
|
|
var shapeTracingEnabled = false;
|
|
|
|
|
|
2011-03-10 13:50:46 -08:00
|
|
|
|
// store the size of the container when it is closed (default in css)
|
|
|
|
|
var initialContainerSize = shapeTracingContainer.height();
|
|
|
|
|
var previousSize = 0;
|
|
|
|
|
|
2011-03-09 16:06:37 -08:00
|
|
|
|
// ensure the ghost has always the same size as the container
|
2011-03-10 13:50:46 -08:00
|
|
|
|
// and the container is always positionned correctly
|
|
|
|
|
var syncResize = function () {
|
|
|
|
|
var _window = $(window);
|
2011-03-14 16:15:00 -07:00
|
|
|
|
var containerHeight = shapeTracingContainer.outerHeight();
|
2011-03-25 16:10:52 -07:00
|
|
|
|
var containerWidth = shapeTracingContainer.outerWidth();
|
2011-03-14 16:15:00 -07:00
|
|
|
|
var toolbarHeight = shapeTracingToolbar.outerHeight();
|
|
|
|
|
var resizeHandleHeight = shapeTracingResizeHandle.outerHeight();
|
|
|
|
|
|
2011-03-11 11:36:38 -08:00
|
|
|
|
shapeTracingGhost.height(containerHeight);
|
|
|
|
|
|
2011-03-10 13:50:46 -08:00
|
|
|
|
var windowHeight = _window.height();
|
|
|
|
|
var scrollTop = _window.scrollTop();
|
2011-03-25 16:10:52 -07:00
|
|
|
|
var containerWindowHeight = containerHeight - toolbarHeight - resizeHandleHeight;
|
2011-03-10 13:50:46 -08:00
|
|
|
|
|
|
|
|
|
shapeTracingContainer.offset({ top: windowHeight - containerHeight + scrollTop, left: 0 });
|
2011-03-25 16:10:52 -07:00
|
|
|
|
shapeTracingWindow.height(containerWindowHeight);
|
|
|
|
|
shapeTracingWindowTree.height(containerWindowHeight);
|
|
|
|
|
shapeTracingWindowContent.height(containerWindowHeight);
|
2011-03-10 13:50:46 -08:00
|
|
|
|
shapeTracingContainer.width('100%');
|
2011-03-25 16:10:52 -07:00
|
|
|
|
|
|
|
|
|
syncResizeMeta();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// forces the content meta zone's height to enable scrollbar
|
|
|
|
|
var syncResizeMeta = function () {
|
|
|
|
|
var containerHeight = shapeTracingContainer.outerHeight();
|
|
|
|
|
var containerWidth = shapeTracingContainer.outerWidth();
|
|
|
|
|
var toolbarHeight = shapeTracingToolbar.outerHeight();
|
|
|
|
|
var resizeHandleHeight = shapeTracingResizeHandle.outerHeight();
|
|
|
|
|
|
|
|
|
|
var tabsHeight = $('.shape-tracing-tabs:visible').outerHeight();
|
2011-03-25 18:17:44 -07:00
|
|
|
|
var breadcrumbHeight = $('.shape-tracing-breadcrumb:visible').outerHeight();
|
2011-03-25 16:10:52 -07:00
|
|
|
|
if (tabsHeight) {
|
|
|
|
|
var metaContent = $('.shape-tracing-meta-content:visible');
|
|
|
|
|
padding = parseInt(metaContent.css('padding-bottom') + metaContent.css('padding-top'));
|
2011-03-25 18:17:44 -07:00
|
|
|
|
metaContent.height(containerHeight - toolbarHeight - resizeHandleHeight - tabsHeight - breadcrumbHeight - padding);
|
2011-03-25 16:10:52 -07:00
|
|
|
|
}
|
2011-03-10 13:50:46 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ensure the size/position is correct whenver the container or the browser is resized
|
|
|
|
|
shapeTracingContainer.resize(syncResize);
|
|
|
|
|
$(window).resize(syncResize);
|
|
|
|
|
$(window).resize();
|
|
|
|
|
|
|
|
|
|
// removes the position flickering by hiding it first, then showing when ready
|
|
|
|
|
shapeTracingContainer.show();
|
|
|
|
|
|
|
|
|
|
// expand/collapse behavior
|
|
|
|
|
// ensure the container has always a valid size when expanded
|
|
|
|
|
shapeTracingToolbarSwitch.click(function () {
|
|
|
|
|
var _this = $(this);
|
|
|
|
|
_this.toggleClass('expanded');
|
|
|
|
|
if (_this.hasClass('expanded')) {
|
2011-03-25 12:36:39 -07:00
|
|
|
|
shapeTracingContainer.height(Math.max(previousSize, defaultHeight, shapeTracingContainer.height()));
|
2011-03-23 21:51:27 -07:00
|
|
|
|
enableShapeTracing();
|
2011-03-10 13:50:46 -08:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// save previous height
|
|
|
|
|
previousSize = shapeTracingContainer.height();
|
|
|
|
|
shapeTracingContainer.height(initialContainerSize);
|
2011-03-23 21:51:27 -07:00
|
|
|
|
disableShapeTracing();
|
2011-03-10 13:50:46 -08:00
|
|
|
|
}
|
2011-03-10 22:37:50 -08:00
|
|
|
|
|
2011-03-10 13:50:46 -08:00
|
|
|
|
syncResize();
|
|
|
|
|
});
|
|
|
|
|
|
2011-03-23 21:51:27 -07:00
|
|
|
|
var disableShapeTracing = function () {
|
|
|
|
|
shapeTracingEnabled = false;
|
|
|
|
|
selectShape();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var enableShapeTracing = function () {
|
|
|
|
|
shapeTracingEnabled = true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-10 13:50:46 -08:00
|
|
|
|
// add a resizable handle to the container
|
|
|
|
|
$('#shape-tracing-resize-handle').addClass('ui-resizable-handle ui-resizable-n');
|
2011-03-23 21:51:27 -07:00
|
|
|
|
shapeTracingContainer.resizable({
|
|
|
|
|
handles: { n: '#shape-tracing-resize-handle' },
|
2011-03-25 16:34:07 -07:00
|
|
|
|
grid: 20, // mitigates the number of calls to syncResize(), and aligns to the line height
|
2011-03-25 18:26:39 -07:00
|
|
|
|
resize: function () { shapeTracingEnabled = false },
|
|
|
|
|
stop: function () { shapeTracingEnabled = true }
|
2011-03-23 21:51:27 -07:00
|
|
|
|
});
|
2011-02-25 23:52:45 -08:00
|
|
|
|
|
2011-03-11 15:12:53 -08:00
|
|
|
|
var shapeNodes = {}; // represents the main index of shape nodes, indexed by id
|
|
|
|
|
|
2011-03-10 22:37:50 -08:00
|
|
|
|
// projects the shape ids to each DOM element
|
2011-03-11 15:12:53 -08:00
|
|
|
|
var startShapeTracingBeacons = $('.shape-tracing-wrapper[shape-id]');
|
|
|
|
|
startShapeTracingBeacons.each(function () {
|
2011-03-10 22:37:50 -08:00
|
|
|
|
var _this = $(this);
|
2011-03-11 15:12:53 -08:00
|
|
|
|
|
|
|
|
|
var shapeNode = {
|
|
|
|
|
id: _this.attr('shape-id'),
|
|
|
|
|
type: _this.attr('shape-type'),
|
2011-03-12 16:18:33 -08:00
|
|
|
|
hint: _this.attr('shape-hint'),
|
2011-03-11 15:12:53 -08:00
|
|
|
|
parent: null,
|
|
|
|
|
children: {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// register the new shape node into the main shape nodes index
|
|
|
|
|
shapeNodes[shapeNode.id] = shapeNode;
|
|
|
|
|
|
2011-03-14 16:15:00 -07:00
|
|
|
|
// assign the shape-id attribute to all direct children, except wrappers themselves (it would erase their own shape-id)
|
2011-03-12 16:18:33 -08:00
|
|
|
|
var found = false;
|
2011-03-11 15:12:53 -08:00
|
|
|
|
_this
|
|
|
|
|
.nextUntil('[end-of="' + shapeNode.id + '"]') // all elements between the script beacons
|
2011-03-25 13:38:48 -07:00
|
|
|
|
.find(':not(.shape-tracing-wrapper)') // all children but not inner beacons
|
2011-03-11 15:12:53 -08:00
|
|
|
|
.andSelf() // add the first level items
|
|
|
|
|
.attr('shape-id', shapeNode.id) // add the shape-id attribute
|
|
|
|
|
.each(function () {
|
|
|
|
|
// assign a shapeNode instance to the DOM element
|
|
|
|
|
this.shapeNode = shapeNode;
|
2011-03-12 16:18:33 -08:00
|
|
|
|
found = true;
|
2011-03-11 15:12:53 -08:00
|
|
|
|
});
|
|
|
|
|
|
2011-03-12 16:18:33 -08:00
|
|
|
|
// if the shape is empty, add a hint
|
|
|
|
|
if (!found) {
|
|
|
|
|
shapeNode.hint = 'empty';
|
|
|
|
|
}
|
2011-03-11 15:12:53 -08:00
|
|
|
|
this.shapeNode = shapeNode;
|
2011-03-10 22:37:50 -08:00
|
|
|
|
});
|
|
|
|
|
|
2011-03-11 15:12:53 -08:00
|
|
|
|
// construct the shape tree based on all current nodes
|
|
|
|
|
// for each start beacon, search for the first parent beacon, and create nodes if they don't exist
|
|
|
|
|
startShapeTracingBeacons.each(function () {
|
|
|
|
|
var _this = $(this);
|
|
|
|
|
var shapeNode = this.shapeNode;
|
2011-03-25 13:38:48 -07:00
|
|
|
|
var parent = _this.parents('[shape-id!=' + shapeNode.id + ']').get(0);
|
2011-03-11 15:12:53 -08:00
|
|
|
|
|
|
|
|
|
shapeNodes[shapeNode.id] = shapeNode;
|
|
|
|
|
|
|
|
|
|
if (parent.shapeNode) {
|
|
|
|
|
var parentShapeNode = parent.shapeNode;
|
|
|
|
|
shapeNodes[parentShapeNode.id] = parentShapeNode;
|
|
|
|
|
shapeNode.parent = parentShapeNode;
|
|
|
|
|
parentShapeNode.children[shapeNode.id] = shapeNode;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// removes all beacons as we don't need them anymore
|
|
|
|
|
$('.shape-tracing-wrapper').remove();
|
|
|
|
|
|
2011-03-12 16:18:33 -08:00
|
|
|
|
// add first level shapes tree nodes
|
2011-03-11 15:12:53 -08:00
|
|
|
|
var shapes = $('<ul></ul>');
|
|
|
|
|
for (var shapeId in shapeNodes) {
|
|
|
|
|
if (!shapeNodes[shapeId].parent) {
|
|
|
|
|
shapes.append(createTreeNode(shapeNodes[shapeId]));
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-10 22:37:50 -08:00
|
|
|
|
|
2011-03-12 16:18:33 -08:00
|
|
|
|
shapeTracingWindowTree.append(shapes);
|
|
|
|
|
|
2011-03-21 09:44:40 -07:00
|
|
|
|
// add the expand/collapse logic to the shapes tree
|
2011-03-12 16:18:33 -08:00
|
|
|
|
var glyph = $('<span class="expando-glyph-container closed"><span class="expando-glyph"></span>​</span>');
|
|
|
|
|
shapeTracingWindowTree.find('div').parent(':has(li)').prepend(glyph);
|
|
|
|
|
|
|
|
|
|
// collapse all sub uls
|
|
|
|
|
shapeTracingWindowTree.find('ul ul').toggle(false);
|
|
|
|
|
|
|
|
|
|
// expands a list of shapes in the tree
|
|
|
|
|
var openExpando = function (expando) {
|
|
|
|
|
if (expando.hasClass("closed") || expando.hasClass("closing")) {
|
|
|
|
|
expando.siblings('ul').slideDown(100, function () { expando.removeClass("opening").removeClass("closed").addClass("open"); });
|
|
|
|
|
expando.addClass("opening");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// collapses a list of shapes in the tree
|
|
|
|
|
var closeExpando = function (expando) {
|
|
|
|
|
if (!expando.hasClass("closed") && !expando.hasClass("closing")) {
|
|
|
|
|
expando.siblings('ul').slideUp(100, function () { expando.removeClass("closing").removeClass("open").addClass("closed"); });
|
|
|
|
|
expando.addClass("closing");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-14 16:15:00 -07:00
|
|
|
|
//create an overlay on shapes' descendants
|
|
|
|
|
var overlayTarget = null;
|
|
|
|
|
$('[shape-id]').add(shapeTracingOverlay).mousemove(
|
|
|
|
|
function (event) {
|
2011-03-23 21:51:27 -07:00
|
|
|
|
if (!shapeTracingEnabled) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-14 16:15:00 -07:00
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
|
|
if ($(this).get(0) == shapeTracingOverlay.get(0)) {
|
|
|
|
|
shapeTracingOverlay.hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var element = document.elementFromPoint(event.pageX - $(window).scrollLeft(), event.pageY - $(window).scrollTop());
|
|
|
|
|
shapeTracingOverlay.show();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (element && !element.shapeNode)
|
|
|
|
|
element = element.parentNode;
|
|
|
|
|
|
|
|
|
|
if (!element || (overlayTarget != null && overlayTarget.get(0) == element)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
element = $(element);
|
|
|
|
|
shapeTracingOverlay.offset(element.offset());
|
|
|
|
|
shapeTracingOverlay.width(element.outerWidth()); // include border and padding
|
|
|
|
|
shapeTracingOverlay.height(element.outerHeight()); // include border and padding
|
|
|
|
|
|
|
|
|
|
overlayTarget = element;
|
2011-03-10 22:37:50 -08:00
|
|
|
|
}
|
|
|
|
|
);
|
2011-03-12 16:18:33 -08:00
|
|
|
|
|
2011-03-14 16:15:00 -07:00
|
|
|
|
// selects a specific shape in the tree, highlight its elements, and display the information
|
|
|
|
|
var selectShape = function (shapeId) {
|
2011-03-23 21:51:27 -07:00
|
|
|
|
if (!shapeId) {
|
|
|
|
|
// remove selection ?
|
|
|
|
|
shapeTracingOverlay.hide();
|
2011-03-24 14:19:28 -07:00
|
|
|
|
$('.shape-tracing-selected').removeClass('shape-tracing-selected');
|
2011-03-23 21:51:27 -07:00
|
|
|
|
shapeTracingWindowTree.find('.shape-tracing-selected').removeClass('shape-tracing-selected');
|
|
|
|
|
$('[shape-id-meta]:visible').toggle(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-24 14:19:28 -07:00
|
|
|
|
$('.shape-tracing-selected').removeClass('shape-tracing-selected');
|
2011-03-14 16:15:00 -07:00
|
|
|
|
$('li[tree-shape-id="' + shapeId + '"] > div').add('[shape-id="' + shapeId + '"]').addClass('shape-tracing-selected');
|
|
|
|
|
shapeTracingOverlay.hide();
|
2011-03-21 09:44:40 -07:00
|
|
|
|
|
|
|
|
|
// show the properties for the selected shape
|
|
|
|
|
$('[shape-id-meta]:visible').toggle(false);
|
|
|
|
|
var target = $('[shape-id-meta="' + shapeId + '"]"');
|
|
|
|
|
target.toggle(true);
|
|
|
|
|
|
|
|
|
|
// enable codemirror for the current tab
|
|
|
|
|
enableCodeMirror(target);
|
2011-03-25 16:10:52 -07:00
|
|
|
|
|
|
|
|
|
syncResizeMeta();
|
2011-03-14 16:15:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-12 16:18:33 -08:00
|
|
|
|
// select shapes when clicked
|
2011-03-14 16:15:00 -07:00
|
|
|
|
shapeTracingOverlay.click(function () {
|
|
|
|
|
var shapeNode = overlayTarget.get(0).shapeNode;
|
|
|
|
|
selectShape(shapeNode.id);
|
2011-03-12 16:18:33 -08:00
|
|
|
|
|
|
|
|
|
var lastExpanded = null;
|
|
|
|
|
// open the tree until the selected element
|
2011-03-14 16:15:00 -07:00
|
|
|
|
$('li[tree-shape-id="' + shapeNode.id + '"]').parents('li').andSelf().find('> .expando-glyph-container').each(function () {
|
|
|
|
|
openExpando($(this));
|
|
|
|
|
})
|
|
|
|
|
.last()
|
|
|
|
|
.each(function () {
|
|
|
|
|
this.scrollIntoView()
|
2011-03-12 16:18:33 -08:00
|
|
|
|
});
|
|
|
|
|
|
2011-03-14 16:15:00 -07:00
|
|
|
|
return false;
|
2011-03-12 16:18:33 -08:00
|
|
|
|
});
|
|
|
|
|
|
2011-03-14 16:15:00 -07:00
|
|
|
|
//create an overlay on shape tree nodes
|
2011-03-23 21:51:27 -07:00
|
|
|
|
shapeTracingWindowTree.find('[tree-shape-id] > div')
|
|
|
|
|
.hover(
|
2011-03-14 16:15:00 -07:00
|
|
|
|
function () {
|
|
|
|
|
var _this = $(this);
|
|
|
|
|
$('.shape-tracing-overlay').removeClass('shape-tracing-overlay');
|
|
|
|
|
_this.addClass('shape-tracing-overlay');
|
|
|
|
|
},
|
|
|
|
|
function () {
|
|
|
|
|
$('.shape-tracing-overlay').removeClass('shape-tracing-overlay');
|
2011-03-23 21:51:27 -07:00
|
|
|
|
})
|
|
|
|
|
.click(function (event) {
|
2011-03-12 16:18:33 -08:00
|
|
|
|
var shapeId = $(this).parent().get(0).shapeNode.id;
|
|
|
|
|
selectShape(shapeId);
|
|
|
|
|
|
|
|
|
|
var element = $('[shape-id="' + shapeId + '"]').get(0);
|
|
|
|
|
// there might be no DOM element if the shape was empty, or is not displayed
|
|
|
|
|
if (element) {
|
|
|
|
|
element.scrollIntoView();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
});
|
2011-03-21 09:44:40 -07:00
|
|
|
|
|
|
|
|
|
// move all shape tracing meta blocks to the content window
|
|
|
|
|
$("[shape-id-meta]").detach().prependTo(shapeTracingWindowContent);
|
|
|
|
|
|
|
|
|
|
// add the expand/collapse logic to the shape model
|
|
|
|
|
// var glyph = $('<span class="expando-glyph-container closed"><span class="expando-glyph"></span>​</span>');
|
2011-03-24 15:53:33 -07:00
|
|
|
|
shapeTracingWindowContent.find('li:has(ul)').prepend(glyph);
|
2011-03-21 09:44:40 -07:00
|
|
|
|
|
|
|
|
|
// collapse all sub uls
|
2011-03-24 15:53:33 -07:00
|
|
|
|
shapeTracingWindowContent.find('ul ul').toggle(false);
|
2011-03-21 09:44:40 -07:00
|
|
|
|
|
|
|
|
|
// tabs events
|
|
|
|
|
shapeTracingWindowContent.find('.shape-tracing-tabs > li').click(function () {
|
|
|
|
|
var _this = $(this);
|
|
|
|
|
var tabName = this.className.split(/\s/)[0];
|
|
|
|
|
|
|
|
|
|
// toggle the selected class on the tab li
|
|
|
|
|
$('.shape-tracing-tabs > li.selected').removeClass('selected');
|
|
|
|
|
$('.shape-tracing-tabs > li.' + tabName).addClass('selected');
|
|
|
|
|
|
|
|
|
|
// hide all tabs and display the selected one
|
|
|
|
|
$('.shape-tracing-meta-content > div').toggle(false);
|
|
|
|
|
$('.shape-tracing-meta-content > div.' + tabName).toggle(true);
|
|
|
|
|
|
|
|
|
|
// look for the targetted panel
|
|
|
|
|
var wrapper = _this.parent().parent().first();
|
|
|
|
|
var panel = wrapper.find('div.' + tabName);
|
|
|
|
|
|
2011-03-25 18:17:44 -07:00
|
|
|
|
var breadcrumb = _this.parent().next();
|
|
|
|
|
var container = _this.parents('.shape-tracing-meta');
|
|
|
|
|
if (_this.hasClass('shape')) {
|
|
|
|
|
breadcrumb.text('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_this.hasClass('model')) {
|
|
|
|
|
breadcrumb.text('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_this.hasClass('placement')) {
|
|
|
|
|
breadcrumb.text(container.find('.sgd-pl').text());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_this.hasClass('template')) {
|
|
|
|
|
breadcrumb.text(container.find('.sgd-t').text());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_this.hasClass('html')) {
|
|
|
|
|
breadcrumb.text('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
syncResizeMeta();
|
|
|
|
|
|
2011-03-21 09:44:40 -07:00
|
|
|
|
// enable codemirror for the current tab
|
|
|
|
|
enableCodeMirror(panel);
|
|
|
|
|
});
|
|
|
|
|
|
2011-03-24 15:53:33 -07:00
|
|
|
|
// template link opens template tab
|
|
|
|
|
shapeTracingWindowContent.find('.sgd-t a').click(function () {
|
|
|
|
|
$(this).parents('.shape-tracing-meta').find('.shape-tracing-tabs > .template').click()
|
|
|
|
|
});
|
|
|
|
|
|
2011-03-21 09:44:40 -07:00
|
|
|
|
// activates codemirror on specific textareas
|
|
|
|
|
var enableCodeMirror = function (target) {
|
|
|
|
|
// if there is a script, and colorization is not enabled yet, turn it on
|
|
|
|
|
// code mirror seems to work only if the textarea is visible
|
|
|
|
|
target.find('textarea:visible').each(function () {
|
|
|
|
|
if ($(this).next('.CodeMirror').length == 0) {
|
|
|
|
|
CodeMirror.fromTextArea(this, { mode: "razor", tabMode: "indent", height: "100%", readOnly: true });
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// automatically expand or collapse shapes in the tree
|
|
|
|
|
shapeTracingWindow.find('.expando-glyph-container').click(function () {
|
|
|
|
|
var _this = $(this);
|
|
|
|
|
if (_this.hasClass("closed") || _this.hasClass("closing")) {
|
|
|
|
|
openExpando(_this);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
closeExpando(_this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2011-03-23 21:51:27 -07:00
|
|
|
|
|
|
|
|
|
//create an overlay on model nodes
|
|
|
|
|
shapeTracingWindowContent.find('.model div.name')
|
|
|
|
|
.hover(
|
|
|
|
|
function () {
|
|
|
|
|
var _this = $(this);
|
|
|
|
|
$('.shape-tracing-overlay').removeClass('shape-tracing-overlay');
|
|
|
|
|
_this.addClass('shape-tracing-overlay');
|
|
|
|
|
},
|
|
|
|
|
function () {
|
|
|
|
|
$('.shape-tracing-overlay').removeClass('shape-tracing-overlay');
|
|
|
|
|
})
|
|
|
|
|
.click(function (event) {
|
|
|
|
|
// model node is selected
|
|
|
|
|
var _this = $(this);
|
|
|
|
|
shapeTracingWindowContent.find('.shape-tracing-selected').removeClass('shape-tracing-selected');
|
|
|
|
|
_this.addClass('shape-tracing-selected');
|
|
|
|
|
|
|
|
|
|
// display breadcrumb
|
2011-03-24 14:19:28 -07:00
|
|
|
|
var breadcrumb = null;
|
2011-03-23 21:51:27 -07:00
|
|
|
|
_this.parentsUntil('.model').children('.name').each(function () {
|
|
|
|
|
if (breadcrumb != null) {
|
|
|
|
|
breadcrumb = $(this).text() + '.' + breadcrumb;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
breadcrumb = $(this).text();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-03-25 18:17:44 -07:00
|
|
|
|
// fix enumerable properties display
|
|
|
|
|
breadcrumb = breadcrumb.replace('.[', '[');
|
|
|
|
|
|
|
|
|
|
_this.parents('.shape-tracing-meta').find('.shape-tracing-breadcrumb').text('@' + breadcrumb);
|
2011-03-23 21:51:27 -07:00
|
|
|
|
event.stopPropagation();
|
|
|
|
|
});
|
|
|
|
|
|
2011-02-08 17:52:53 -08:00
|
|
|
|
});
|
2011-03-11 15:12:53 -08:00
|
|
|
|
|
2011-03-12 16:18:33 -08:00
|
|
|
|
// recursively create a node for the shapes tree
|
2011-03-11 15:12:53 -08:00
|
|
|
|
function createTreeNode(shapeNode) {
|
|
|
|
|
var node = $('<li></li>');
|
2011-03-12 16:18:33 -08:00
|
|
|
|
node.attr('tree-shape-id', shapeNode.id);
|
|
|
|
|
node.get(0).shapeNode = shapeNode;
|
2011-03-14 16:15:00 -07:00
|
|
|
|
|
2011-03-12 16:18:33 -08:00
|
|
|
|
var text = shapeNode.type;
|
|
|
|
|
// add the hint to the tree node if available
|
|
|
|
|
if (shapeNode.hint != '') {
|
|
|
|
|
text += ' [' + shapeNode.hint + ']';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
node.append('<div>' + text + '</div>');
|
2011-03-11 15:12:53 -08:00
|
|
|
|
var list = $('<ul></ul>');
|
|
|
|
|
node.append(list);
|
|
|
|
|
if (shapeNode.children) {
|
|
|
|
|
for (var shapeId in shapeNode.children) {
|
|
|
|
|
var child = createTreeNode(shapeNode.children[shapeId]);
|
|
|
|
|
list.append(child);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-24 21:28:43 -07:00
|
|
|
|
});
|