docs: Add examples for mw.Upload
authorPrateek Saxena <prtksxna@gmail.com>
Wed, 5 Aug 2015 10:28:43 +0000 (15:58 +0530)
committerPrateek Saxena <prtksxna@gmail.com>
Wed, 5 Aug 2015 10:28:43 +0000 (15:58 +0530)
Change-Id: Icd759657fb1756d1559173d3a335f87e7a2baa2e

resources/src/mediawiki/mediawiki.Upload.js

index b842545..2d4bef0 100644 (file)
@@ -9,6 +9,40 @@
         * but this model class will tie it together as well as let you perform
         * actions in a logical way.
         *
+        * A simple example:
+        *
+        *      var file = new OO.ui.SelectFileWidget(),
+        *              button = new OO.ui.ButtonWidget( { label: 'Save' } ),
+        *              upload = new mw.Upload;
+        *
+        *      button.on( 'click', function () {
+        *              upload.setFile( file.getValue() );
+        *              upload.setFilename( file.getValue().name );
+        *              upload.upload();
+        *      } );
+        *
+        *      $( 'body' ).append( file.$element, button.$element );
+        *
+        * You can also choose to {@link #uploadToStash stash the upload} and
+        * {@link #finishStashUpload finalize} it later:
+        *
+        *      var file, // Some file object
+        *              upload = new mw.Upload,
+        *              stashPromise = $.Deferred();
+        *
+        *      upload.setFile( file );
+        *      upload.uploadToStash().then( function () {
+        *              stashPromise.resolve();
+        *      } );
+        *
+        *      stashPromise.then( function () {
+        *              upload.setFilename( 'foo' );
+        *              upload.setText( 'bar' );
+        *              upload.finishStashUpload().then( function () {
+        *                      console.log( 'Done!' );
+        *              } );
+        *      } );
+        *
         * @constructor
         * @param {Object} apiconfig Passed to the constructor of mw.Api.
         */