Jonas Kress (WMDE) has uploaded a new change for review.

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

Change subject: Create button to reshow visual editor
......................................................................

Create button to reshow visual editor

Change-Id: I674c1d360c32aa4dc9ebd4c02d91ae31f8a49172
---
M index.html
M style.css
M wikibase/queryService/ui/App.js
3 files changed, 59 insertions(+), 38 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikidata/query/gui 
refs/changes/37/283137/1

diff --git a/index.html b/index.html
index 4f42e16..75040a9 100644
--- a/index.html
+++ b/index.html
@@ -81,18 +81,6 @@
                                        <div class="alert alert-success 
alert-dismissible" role="alert">
                                                Press <i>[CTRL-SPACE]</i> to 
activate auto completion. Data last updated: <span 
id="dbUpdated">[connecting]</span>
                                        </div>
-                                       <div class="visual-editor">
-                                               <div class="panel panel-info">
-                                                       <div 
class="panel-heading">
-                                                               Query 
explanation
-                                                               <a href="#" 
class="help"><span class="glyphicon glyphicon-question-sign" 
aria-hidden="true"></span></a>
-                                                               <button 
type="button" class="close" aria-label="Close">
-                                                                       <span 
aria-hidden="true">&times;</span>
-                                                               </button>
-                                                       </div>
-                                                       <div 
class="panel-body"></div>
-                                               </div>
-                                       </div>
                                        <nav class="navbar navbar-default">
                                                <div class="nav navbar-form 
navbar-left">
                                                        <div class="form-group">
@@ -132,6 +120,19 @@
                                                </ul>
                                        </nav>
                                </form>
+
+                               <a href="#" class="visual-editor-trigger" 
target="_blank" title="Show query explanation"> <span class="glyphicon 
glyphicon-question-sign" aria-hidden="true"></span></a>
+                               <div class="visual-editor">
+                                       <div class="panel panel-info">
+                                               <div class="panel-heading">
+                                                       Query explanation <a 
href="#" class="help"><span class="glyphicon glyphicon-question-sign" 
aria-hidden="true"></span></a>
+                                                       <button type="button" 
class="close" aria-label="Close">
+                                                               <span 
aria-hidden="true">&times;</span>
+                                                       </button>
+                                               </div>
+                                               <div class="panel-body"></div>
+                                       </div>
+                               </div>
                                <a href="#" class="shareQuery shortUrlTrigger 
query" target="_blank" title="Short URL to this page" data-toggle="popover"> 
<span class="glyphicon glyphicon-link" aria-hidden="true"></span></a>
                        </div>
                </div>
diff --git a/style.css b/style.css
index 5bbfd6d..9dca58a 100644
--- a/style.css
+++ b/style.css
@@ -354,6 +354,15 @@
 /*
 Visual Editor
 */
+.visual-editor-trigger {
+       display: none;
+    z-index: 100;
+    position: absolute;
+    top: 10px;
+    right: 45px;
+    font-size: 25px;
+}
+
 .visual-editor {
        display: none;
        min-width: 300px;
diff --git a/wikibase/queryService/ui/App.js b/wikibase/queryService/ui/App.js
index f8164c0..b4f95e9 100644
--- a/wikibase/queryService/ui/App.js
+++ b/wikibase/queryService/ui/App.js
@@ -139,45 +139,56 @@
         **/
        SELF.prototype._initVisualEditor = function() {
                var self = this;
-
-               if( !this._visualEditor ){
+               if (!this._visualEditor) {
                        this._visualEditor = new 
wikibase.queryService.ui.visualEditor.VisualEditor();
                }
-
-               this._visualEditor.setChangeListener(function( ve ){
-                       self._editor.setValue( ve.getQuery() );
+               this._visualEditor.setChangeListener(function(ve) {
+                       self._editor.setValue(ve.getQuery());
                });
 
-               if( this._editor ){
-                       this._editor.registerCallback( 'change', _.debounce( 
function(){
-                               if( $('.visual-editor' ).length === 0 ||
-                                               self._editor.getValue() === 
self._visualEditor.getQuery() ){
+               if (this._editor) {
+                       this._editor.registerCallback('change', 
_.debounce(function() {
+                               if ($('.visual-editor-trigger').is(':visible') 
||
+                                               self._editor.getValue() === 
self._visualEditor.getQuery()) {
                                        return;
                                }
-                               $('.visual-editor' ).hide();
-
-                               try {
-                                       self._visualEditor.setQuery( 
self._editor.getValue() );
-                                       self._visualEditor.draw( 
$('.visual-editor .panel-body' ) );
-
-                                       $('.visual-editor' ).delay( 500 
).fadeIn();
-                               } catch (e) {
-                                       if( e.stack ){
-                                               window.console.log( e.stack );
-                                       }
-                               }
-                       }, 500 ) );
+                               $('.visual-editor').hide();
+                               self._drawVisualEditor();
+                       }, 500));
                }
 
-                $('.visual-editor .panel-heading .close' ).click( function(){
-                        $('.visual-editor' ).remove();
-                } );
-       };
+               $('.visual-editor .panel-heading .close').click(function() {
+                       $('.visual-editor').hide();
+                       $('.visual-editor-trigger').show();
+                       return false;
+               });
 
+               $('.visual-editor-trigger').click(function() {
+                       $('.visual-editor-trigger').hide();
+                       self._drawVisualEditor();
+                       return false;
+               });
+       };
 
        /**
         * @private
         **/
+       SELF.prototype._drawVisualEditor = function() {
+               try {
+                       this._visualEditor.setQuery( this._editor.getValue() );
+                       this._visualEditor.draw( $('.visual-editor 
.panel-body') );
+
+                       $('.visual-editor').delay(500).fadeIn();
+               } catch (e) {
+                       if (e.stack) {
+                               window.console.log(e.stack);
+                       }
+               }
+       };
+
+       /**
+        * @private
+        */
        SELF.prototype._initExamples = function() {
                var self = this;
                new wikibase.queryService.ui.QueryExampleDialog( $( 
'#QueryExamples' ), this._querySamplesApi, function( query, title ){

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I674c1d360c32aa4dc9ebd4c02d91ae31f8a49172
Gerrit-PatchSet: 1
Gerrit-Project: wikidata/query/gui
Gerrit-Branch: master
Gerrit-Owner: Jonas Kress (WMDE) <jonas.kr...@wikimedia.de>

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

Reply via email to