modulejs.define('ext/crumb', ['_', '$', 'core/event', 'core/location', 'core/resource', 'core/settings'], function (_, $, event, location, resource, allsettings) { var settings = _.extend({ enabled: false }, allsettings.crumb); var template = '' + '>' + '' + ''; var pageHintTemplate = 'has index page'; function update(item, force) { if (!force && item.$crumb) { return item.$crumb; } var $html = $(template); $html .addClass(item.isFolder() ? 'folder' : 'file') .data('item', item); location.setLink($html, item); $html.find('.label').text(item.label); if (item.isDomain() || item.isRoot()) { $html.find('.sep').width(0); } if (item.isCurrentFolder()) { $html.addClass('active'); } if (!item.isManaged) { $html.append($(pageHintTemplate)); } if (item.$crumb) { item.$crumb.replaceWith($html); } item.$crumb = $html; return $html; } function onLocationChanged(item) { var crumb = item.getCrumb(); var $crumbbar = $('#crumbbar'); var found = false; $crumbbar.find('.crumb').each(function () { var $html = $(this); if ($html.data('item') === item) { found = true; $html.addClass('active'); } else { $html.removeClass('active'); } }); if (!found) { $crumbbar.find('.crumb').remove(); _.each(crumb, function (e) { $crumbbar.append(update(e, true)); }); } } function init() { if (!settings.enabled) { return; } event.sub('location.changed', onLocationChanged); } init(); });