diff --git a/core/modules/responsive_preview/js/responsive-preview.js b/core/modules/responsive_preview/js/responsive-preview.js index 3511680..e4b2717 100644 --- a/core/modules/responsive_preview/js/responsive-preview.js +++ b/core/modules/responsive_preview/js/responsive-preview.js @@ -153,7 +153,7 @@ Drupal.behaviors.responsivePreview = { } } }, - detach: function (context) { + detach: function (context, settings, trigger) { /** * Loops through object properties; applies a callback function. */ @@ -164,20 +164,24 @@ Drupal.behaviors.responsivePreview = { } } } - // Remove listeners on the window and document. - $(window).add(document).off('.responsivepreview'); - // Set the preview to an inactive state. - Drupal.responsivePreview.models.previewModel.set('isActive', false); - // Remove and delete the views. - looper(Drupal.responsivePreview.views, function (label, view) { - Drupal.responsivePreview.views[label].remove(); - Drupal.responsivePreview.views[label] = undefined; - }); - // Remove listeners and delete the models. - looper(Drupal.responsivePreview.models, function (label, model) { - Drupal.responsivePreview.models[label].off(); - Drupal.responsivePreview.models[label] = undefined; - }); + + var app = Drupal.responsivePreview.views.appView || null; + // Detach only if the app view is unloading. + if (app && context === app && trigger === 'unload') { + // Remove listeners on the window and document. + $(window).add(document).off('.responsivepreview'); + // Remove and delete the view references. + looper(Drupal.responsivePreview.views, function (label, view) { + view.remove(); + Drupal.responsivePreview.views[label] = undefined; + }); + // Reset models, remove listeners and delete the model references. + looper(Drupal.responsivePreview.models, function (label, model) { + model.set(model.defaults); + model.off(); + Drupal.responsivePreview.models[label] = undefined; + }); + } } };