jenkins-bot has submitted this change and it was merged.

Change subject: Provide a FileDropHandler for HTML files
......................................................................


Provide a FileDropHandler for HTML files

Change-Id: I0dac125ffddbb012769a41c7b5a8d31fb97b7def
---
M .docs/eg-iframe.html
M build/modules.json
M demos/ve/desktop.html
M demos/ve/mobile.html
A src/ui/filedrophandlers/ve.ui.HTMLFileDropHandler.js
M tests/index.html
6 files changed, 89 insertions(+), 0 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  Esanders: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/.docs/eg-iframe.html b/.docs/eg-iframe.html
index a475983..ad2fa95 100644
--- a/.docs/eg-iframe.html
+++ b/.docs/eg-iframe.html
@@ -307,6 +307,7 @@
                <script src="../src/ui/dialogs/ve.ui.NodeDialog.js"></script>
                <script 
src="../src/ui/dialogs/ve.ui.ProgressDialog.js"></script>
                <script 
src="../src/ui/filedrophandlers/ve.ui.PlainTextFileDropHandler.js"></script>
+               <script 
src="../src/ui/filedrophandlers/ve.ui.HTMLFileDropHandler.js"></script>
                <script 
src="../src/ui/widgets/ve.ui.LanguageSearchWidget.js"></script>
                <script 
src="../src/ui/widgets/ve.ui.LanguageResultWidget.js"></script>
                <script 
src="../src/ui/dialogs/ve.ui.LanguageSearchDialog.js"></script>
diff --git a/build/modules.json b/build/modules.json
index 0f8adb3..316f665 100644
--- a/build/modules.json
+++ b/build/modules.json
@@ -333,6 +333,7 @@
                        "src/ui/dialogs/ve.ui.NodeDialog.js",
                        "src/ui/dialogs/ve.ui.ProgressDialog.js",
                        
"src/ui/filedrophandlers/ve.ui.PlainTextFileDropHandler.js",
+                       "src/ui/filedrophandlers/ve.ui.HTMLFileDropHandler.js",
                        "src/ui/widgets/ve.ui.LanguageSearchWidget.js",
                        "src/ui/widgets/ve.ui.LanguageResultWidget.js",
                        "src/ui/dialogs/ve.ui.LanguageSearchDialog.js",
diff --git a/demos/ve/desktop.html b/demos/ve/desktop.html
index 49ddc20..d01afc9 100644
--- a/demos/ve/desktop.html
+++ b/demos/ve/desktop.html
@@ -320,6 +320,7 @@
                <script src="../../src/ui/dialogs/ve.ui.NodeDialog.js"></script>
                <script 
src="../../src/ui/dialogs/ve.ui.ProgressDialog.js"></script>
                <script 
src="../../src/ui/filedrophandlers/ve.ui.PlainTextFileDropHandler.js"></script>
+               <script 
src="../../src/ui/filedrophandlers/ve.ui.HTMLFileDropHandler.js"></script>
                <script 
src="../../src/ui/widgets/ve.ui.LanguageSearchWidget.js"></script>
                <script 
src="../../src/ui/widgets/ve.ui.LanguageResultWidget.js"></script>
                <script 
src="../../src/ui/dialogs/ve.ui.LanguageSearchDialog.js"></script>
diff --git a/demos/ve/mobile.html b/demos/ve/mobile.html
index 6997b4f..28a92af 100644
--- a/demos/ve/mobile.html
+++ b/demos/ve/mobile.html
@@ -321,6 +321,7 @@
                <script src="../../src/ui/dialogs/ve.ui.NodeDialog.js"></script>
                <script 
src="../../src/ui/dialogs/ve.ui.ProgressDialog.js"></script>
                <script 
src="../../src/ui/filedrophandlers/ve.ui.PlainTextFileDropHandler.js"></script>
+               <script 
src="../../src/ui/filedrophandlers/ve.ui.HTMLFileDropHandler.js"></script>
                <script 
src="../../src/ui/widgets/ve.ui.LanguageSearchWidget.js"></script>
                <script 
src="../../src/ui/widgets/ve.ui.LanguageResultWidget.js"></script>
                <script 
src="../../src/ui/dialogs/ve.ui.LanguageSearchDialog.js"></script>
diff --git a/src/ui/filedrophandlers/ve.ui.HTMLFileDropHandler.js 
b/src/ui/filedrophandlers/ve.ui.HTMLFileDropHandler.js
new file mode 100644
index 0000000..677910e
--- /dev/null
+++ b/src/ui/filedrophandlers/ve.ui.HTMLFileDropHandler.js
@@ -0,0 +1,84 @@
+/*!
+ * VisualEditor UserInterface HTML file drop handler class.
+ *
+ * @copyright 2011-2014 VisualEditor Team and others; see 
http://ve.mit-license.org
+ */
+
+/**
+ * HTML file drop handler.
+ *
+ * @class
+ * @extends ve.ui.FileDropHandler
+ *
+ * @constructor
+ * @param {ve.ui.Surface} surface
+ * @param {File} file
+ */
+ve.ui.HTMLFileDropHandler = function VeUiHTMLFileDropHandler() {
+       // Parent constructor
+       ve.ui.HTMLFileDropHandler.super.apply( this, arguments );
+};
+
+/* Inheritance */
+
+OO.inheritClass( ve.ui.HTMLFileDropHandler, ve.ui.FileDropHandler );
+
+/* Static properties */
+
+ve.ui.HTMLFileDropHandler.static.name = 'html';
+
+ve.ui.HTMLFileDropHandler.static.types = [ 'text/html', 
'application/xhtml+xml' ];
+
+/* Methods */
+
+/**
+ * @inheritdoc
+ */
+ve.ui.HTMLFileDropHandler.prototype.process = function () {
+       this.createProgress( this.insertableDataDeferred.promise() );
+       this.reader.readAsText( this.file );
+};
+
+/**
+ * @inheritdoc
+ */
+ve.ui.HTMLFileDropHandler.prototype.onFileProgress = function ( e ) {
+       if ( e.lengthComputable ) {
+               this.setProgress( 100 * e.loaded / e.total );
+       } else {
+               this.setProgress( false );
+       }
+};
+
+/**
+ * @inheritdoc
+ */
+ve.ui.HTMLFileDropHandler.prototype.onFileLoad = function () {
+       this.insertableDataDeferred.resolve(
+               this.surface.getModel().getDocument().newFromHtml( 
this.reader.result )
+       );
+       this.setProgress( 100 );
+};
+
+/**
+ * @inheritdoc
+ */
+ve.ui.HTMLFileDropHandler.prototype.onFileLoadEnd = function () {
+       // 'loadend' fires after 'load'/'abort'/'error'.
+       // Reject the deferred if it hasn't already resolved.
+       this.insertableDataDeferred.reject();
+};
+
+/**
+ * @inheritdoc
+ */
+ve.ui.HTMLFileDropHandler.prototype.abort = function () {
+       // Parent method
+       ve.ui.HTMLFileDropHandler.super.prototype.abort.call( this );
+
+       this.reader.abort();
+};
+
+/* Registration */
+
+ve.ui.fileDropHandlerFactory.register( ve.ui.HTMLFileDropHandler );
diff --git a/tests/index.html b/tests/index.html
index 393d97e..b40a6cd 100644
--- a/tests/index.html
+++ b/tests/index.html
@@ -270,6 +270,7 @@
                <script src="../src/ui/dialogs/ve.ui.NodeDialog.js"></script>
                <script 
src="../src/ui/dialogs/ve.ui.ProgressDialog.js"></script>
                <script 
src="../src/ui/filedrophandlers/ve.ui.PlainTextFileDropHandler.js"></script>
+               <script 
src="../src/ui/filedrophandlers/ve.ui.HTMLFileDropHandler.js"></script>
                <script 
src="../src/ui/widgets/ve.ui.LanguageSearchWidget.js"></script>
                <script 
src="../src/ui/widgets/ve.ui.LanguageResultWidget.js"></script>
                <script 
src="../src/ui/dialogs/ve.ui.LanguageSearchDialog.js"></script>

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I0dac125ffddbb012769a41c7b5a8d31fb97b7def
Gerrit-PatchSet: 9
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Jforrester <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to