Issue #1988328 by nod_, jessebeach: Contextual link JavaScript error when viewing a page such as /admin/* that doesn't contain any contextual links.

8.0.x
Dries 2013-06-05 13:10:45 -04:00
parent b9de1f2d0d
commit 9600c1e521
2 changed files with 19 additions and 18 deletions

View File

@ -142,7 +142,6 @@ function contextual_library_info() {
array('system', 'jquery.once'),
array('system', 'drupal.tabbingmanager'),
array('system', 'drupal.announce'),
array('contextual', 'drupal.contextual-links')
),
);

View File

@ -43,25 +43,27 @@ function initContextualToolbar (context) {
});
// Show the edit tab while there's >=1 contextual link.
var contextualCollection = Drupal.contextual.collection;
function trackContextualCount () {
model.set('contextualCount', contextualCollection.length);
}
contextualCollection.on('reset remove add', trackContextualCount);
trackContextualCount();
if (Drupal.contextual && Drupal.contextual.collection) {
var contextualCollection = Drupal.contextual.collection;
var trackContextualCount = function () {
model.set('contextualCount', contextualCollection.length);
};
contextualCollection.on('reset remove add', trackContextualCount);
trackContextualCount();
// Whenever edit mode is toggled, lock all contextual links.
model.on('change:isViewing', function() {
contextualCollection.each(function (contextualModel) {
contextualModel.set('isLocked', !model.get('isViewing'));
// Whenever edit mode is toggled, lock all contextual links.
model.on('change:isViewing', function() {
contextualCollection.each(function (contextualModel) {
contextualModel.set('isLocked', !model.get('isViewing'));
});
});
});
// When a new contextual link is added and edit mode is enabled, lock it.
contextualCollection.on('add', function (contextualModel) {
if (!model.get('isViewing')) {
contextualModel.set('isLocked', true);
}
});
// When a new contextual link is added and edit mode is enabled, lock it.
contextualCollection.on('add', function (contextualModel) {
if (!model.get('isViewing')) {
contextualModel.set('isLocked', true);
}
});
}
// Checks whether localStorage indicates we should start in edit mode
// rather than view mode.