Esanders has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/106258


Change subject: Add method to fully destroy a target
......................................................................

Add method to fully destroy a target

Destroys the surface, toolbar and removes the container from the DOM.
Surface#destroy takes care of removing overlays.

Use this method in the standalone demo.

Change-Id: I2e98f8d0ba90ff725c5f0218be941c00a6fa2c8e
---
M demos/ve/demo.js
M modules/ve/init/ve.init.Target.js
2 files changed, 17 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/58/106258/1

diff --git a/demos/ve/demo.js b/demos/ve/demo.js
index e20668f..efd4fd0 100644
--- a/demos/ve/demo.js
+++ b/demos/ve/demo.js
@@ -59,11 +59,9 @@
                        );
 
                        target.on( 'surfaceReady', function () {
-                               // TODO: Target should have a way to tear 
itself down (should include removing
-                               // elements outside target.$element, such as 
global overlays).
                                $targetContainer.promise().done( function () {
                                        if ( currentTarget ) {
-                                               currentTarget.$element.remove();
+                                               currentTarget.destroy();
                                        }
                                        $targetContainer
                                                .append( target.$element )
diff --git a/modules/ve/init/ve.init.Target.js 
b/modules/ve/init/ve.init.Target.js
index 94c5e9d..8c25aa3 100644
--- a/modules/ve/init/ve.init.Target.js
+++ b/modules/ve/init/ve.init.Target.js
@@ -38,6 +38,22 @@
        this.toolbar = null;
 };
 
+/**
+ * Destroy the target
+ */
+ve.init.Target.prototype.destroy = function () {
+       this.$document = null;
+       if ( this.surface ) {
+               this.surface.destroy();
+       }
+       if ( this.toolbar ) {
+               this.toolbar.destroy();
+       }
+       if ( this.$element ) {
+               this.$element.remove();
+       }
+};
+
 /* Events */
 
 /**

-- 
To view, visit https://gerrit.wikimedia.org/r/106258
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2e98f8d0ba90ff725c5f0218be941c00a6fa2c8e
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to