Jforrester has uploaded a new change for review.

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

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, 91 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/49/172749/1

diff --git a/.docs/eg-iframe.html b/.docs/eg-iframe.html
index 819e94f..9212d46 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 c485bed..6d74622 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 8641a09..e201380 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 a43f8d3..70bfcfe 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..baf442c
--- /dev/null
+++ b/src/ui/filedrophandlers/ve.ui.HTMLFileDropHandler.js
@@ -0,0 +1,86 @@
+/*!
+ * 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 () {
+       var document = this.surface.getModel().getDocument();
+
+       this.insertableDataDeferred.resolve(
+               document.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 f35fb53..c3f3cbb 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: newchange
Gerrit-Change-Id: I0dac125ffddbb012769a41c7b5a8d31fb97b7def
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Jforrester <[email protected]>

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

Reply via email to