Bmansurov has uploaded a new change for review.

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

Change subject: WIP: Alpha experiment
......................................................................

WIP: Alpha experiment

Change-Id: I73f18ac906cd1c79c75e5ef0f4ac46d765d89424
---
M includes/Resources.php
A javascripts/modules/textSelection/TextSelectionDrawer.js
A javascripts/modules/textSelection/init.js
A less/modules/textSelection.less
A templates/modules/textSelection/Drawer.hogan
5 files changed, 153 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/50/198450/1

diff --git a/includes/Resources.php b/includes/Resources.php
index 792e2ba..24aa82b 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -1077,6 +1077,24 @@
                ),
        ),
 
+       'mobile.textSelection' => $wgMFResourceParsedMessageModuleBoilerplate + 
array(
+                       'dependencies' => array(
+                               'mobile.startup',
+                               'mobile.drawers',
+                               'mobile.toast',
+                       ),
+                       'scripts' => array(
+                               
'javascripts/modules/textSelection/TextSelectionDrawer.js',
+                               'javascripts/modules/textSelection/init.js',
+                       ),
+                       'templates' => array(
+                               'Drawer.hogan' => 
'templates/modules/textSelection/Drawer.hogan',
+                       ),
+                       'styles' => array(
+                               'less/modules/textSelection.less',
+                       ),
+               ),
+
        'mobile.languages' => $wgMFResourceParsedMessageModuleBoilerplate + 
array(
                'dependencies' => array(
                        'mobile.overlays',
@@ -1666,6 +1684,7 @@
                        'mobile.errorReport',
                        'mobile.otherProjects',
                        'mobile.quickLookup',
+                       'mobile.textSelection',
                ),
                'scripts' => array(
                        'javascripts/modules/commonsCategory/init.js',
diff --git a/javascripts/modules/textSelection/TextSelectionDrawer.js 
b/javascripts/modules/textSelection/TextSelectionDrawer.js
new file mode 100644
index 0000000..f0f19db
--- /dev/null
+++ b/javascripts/modules/textSelection/TextSelectionDrawer.js
@@ -0,0 +1,77 @@
+( function ( M, $ ) {
+       var Icon = M.require( 'Icon' ),
+               Drawer = M.require( 'Drawer' ),
+               user = M.require( 'user' ),
+               Page = M.require( 'Page' ),
+               TextSelectionDrawer;
+
+       /**
+        * Drawer for showing a brief information about a page.
+        * @inheritdoc
+        * @class TextSelectionDrawer
+        * @extends Drawer
+        */
+       TextSelectionDrawer = Drawer.extend( {
+               /**
+                * @inheritdoc
+                * @cfg {Object} defaults Default options hash.
+                * @cfg {String} defaults.cancelButton HTML of the button that 
closes the drawer.
+                * @cfg {String} defaults.text text being looked up
+                * @cfg {String} defaults.description description of 
defaults.text
+                */
+               defaults: {
+                       cancelButton: new Icon( {
+                               tagName: 'a',
+                               name: 'cancel-light',
+                               additionalClassNames: 'cancel',
+                               label: mw.msg( 'mobile-frontend-overlay-close' )
+                       } ).toHtmlString(),
+                       text: '',
+                       description: ''
+               },
+               /**
+                * @inheritdoc
+                */
+               className: Drawer.prototype.className + ' text-selection',
+               /**
+                * @inheritdoc
+                */
+               template: mw.template.get( 'mobile.textSelection', 
'Drawer.hogan' ),
+               /**
+                * @inheritdoc
+                */
+               closeOnScroll: false,
+               /**
+                * @inheritdoc
+                */
+               postRender: function ( options ) {
+                       var self = this,
+                               windowHeight = $( window ).height();
+
+                       Drawer.prototype.postRender.apply( this, arguments );
+
+                       // make sure the drawer doesn't take up more than 50% 
of the viewport height
+                       if ( windowHeight / 2 < 400 ) {
+                               this.$el.css( 'max-height', windowHeight / 2 );
+                       }
+
+                       this.on( 'show', $.proxy( this, 'onShow' ) );
+                       this.on( 'hide', $.proxy( this, 'onHide' ) );
+               },
+               /**
+                * Make body not scrollable
+                */
+               onShow: function () {
+                       $( 'body' ).addClass( 'drawer-enabled' );
+               },
+               /**
+                * Restore body scroll
+                */
+               onHide: function () {
+                       $( 'body' ).removeClass( 'drawer-enabled' );
+                       this.$el.detach();
+               }
+       } );
+
+       M.define( 'modules/textSelection/TextSelectionDrawer', 
TextSelectionDrawer );
+}( mw.mobileFrontend, jQuery ) );
diff --git a/javascripts/modules/textSelection/init.js 
b/javascripts/modules/textSelection/init.js
new file mode 100644
index 0000000..e3de62f
--- /dev/null
+++ b/javascripts/modules/textSelection/init.js
@@ -0,0 +1,54 @@
+/**
+ * This module helps the user interact with the selected text.
+ * Possible use cases are:
+ * 1. Searching wikidata
+ * 2. Micro editing
+ * 3. Creating a new page whose title is selected text
+ * 4. add more ideas here ...
+ */
+( function ( M, $ ) {
+       M.require( 'context' ).assertMode( [ 'alpha' ] );
+
+       var TextSelectionDrawer = M.require( 
'modules/textSelection/TextSelectionDrawer' ),
+               drawer;
+
+       /**
+        * Return selected text
+        * @returns {String} selected text
+        */
+       function getSelectionText() {
+               var selectedText = '';
+
+               if ( window.getSelection ) {
+                       selectedText = window.getSelection().toString();
+               } else if ( document.selection && 
document.selection.createRange ) {
+                       selectedText = document.selection.createRange().text;
+               }
+
+               return selectedText;
+       }
+
+       $( function () {
+               var timeoutID,
+                       selectionText;
+
+               $( '#content' )
+                       .on( 'click, tap', function () {
+                               selectionText = getSelectionText();
+
+                               clearTimeout( timeoutID );
+                               // Set timeout so that we don't run this 
function twice on double click
+                               timeoutID = setTimeout( function () {
+
+                                       if ( selectionText ) {
+                                               drawer = new 
TextSelectionDrawer( {
+                                                       text: selectionText,
+                                                       description: 
'Description'
+                                               } );
+                                               drawer.show();
+                                       }
+                               }, 100 );
+                       } );
+       } );
+
+}( mw.mobileFrontend, jQuery ) );
diff --git a/less/modules/textSelection.less b/less/modules/textSelection.less
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/less/modules/textSelection.less
diff --git a/templates/modules/textSelection/Drawer.hogan 
b/templates/modules/textSelection/Drawer.hogan
new file mode 100644
index 0000000..745c3e1
--- /dev/null
+++ b/templates/modules/textSelection/Drawer.hogan
@@ -0,0 +1,3 @@
+<h3>{{{text}}}</h3>
+{{{cancelButton}}}
+<p>{{{description}}}</p>

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I73f18ac906cd1c79c75e5ef0f4ac46d765d89424
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Bmansurov <bmansu...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to