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

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

Change subject: Cleanup folder structure of codemirror and enable placeholder
......................................................................

Cleanup folder structure of codemirror and enable placeholder

Change-Id: I281ecef1f57d5542e0351b7de593c9b5e602f684
---
M gui/index.html
A gui/vendor/codemirror/addon/display/placeholder.js
R gui/vendor/codemirror/addon/hint/show-hint.css
R gui/vendor/codemirror/addon/hint/show-hint.js
R gui/vendor/codemirror/addon/hint/wikibase-rdf-hint.js
R gui/vendor/codemirror/addon/hint/wikibase-sparql-hint.js
R gui/vendor/codemirror/addon/tooltip/WikibaseRDFTooltip.js
R gui/vendor/codemirror/lib/codemirror.css
R gui/vendor/codemirror/lib/codemirror.js
R gui/vendor/codemirror/mode/sparql.js
10 files changed, 70 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikidata/query/rdf 
refs/changes/02/251002/1

diff --git a/gui/index.html b/gui/index.html
index 40df811..ab59cc8 100644
--- a/gui/index.html
+++ b/gui/index.html
@@ -3,20 +3,21 @@
 <head>
 <script src="jquery-1.11.3.js"></script>
 <script src="bootstrap.min.js"></script>
-<script src="codemirror.js"></script>
-<script src="sparql.js"></script>
-<script src="addon/hint/show-hint.js"></script>
-<script src="addon/hint/wikibase-sparql-hint.js"></script>
-<script src="addon/hint/wikibase-rdf-hint.js"></script>
-<script src="addon/tooltip/WikibaseRDFTooltip.js"></script>
+<script src="vendor/codemirror/lib/codemirror.js"></script>
+<script src="vendor/codemirror/mode/sparql.js"></script>
+<script src="vendor/codemirror/addon/hint/show-hint.js"></script>
+<script src="vendor/codemirror/addon/hint/wikibase-sparql-hint.js"></script>
+<script src="vendor/codemirror/addon/hint/wikibase-rdf-hint.js"></script>
+<script src="vendor/codemirror/addon/tooltip/WikibaseRDFTooltip.js"></script>
+<script src="vendor/codemirror/addon/display/placeholder.js"></script>
 <script src="gui.js"></script>
 <script src="vis.js"></script>
 <script src="wdqs.js"></script>
 <script src="wdqs-explorer.js"></script>
 <link rel="stylesheet" href="bootstrap.min.css">
 <link rel="stylesheet" href="style.css">
-<link rel="stylesheet" href="codemirror.css">
-<link rel="stylesheet" href="addon/hint/show-hint.css">
+<link rel="stylesheet" href="vendor/codemirror/lib/codemirror.css">
+<link rel="stylesheet" href="vendor/codemirror/addon/hint/show-hint.css">
 
 <link rel="shortcut icon"
        href="//www.wikidata.org/static/favicon/testwikidata.ico">
@@ -63,7 +64,7 @@
                        <div class="col-md-12" id="query-box">
                                <form class="form-horizontal" id="query-form">
                                        <div class="form-group">
-                                               <textarea id="query" 
name="query" placeholder="(Input a SPARQL query)"></textarea>
+                                               <textarea id="query" 
name="query" placeholder="(Input a SPARQL query or choose a query 
example)"></textarea>
                                                <div class="alert alert-success 
alert-dismissible" role="alert">
                                                        <button type="button" 
class="close" data-dismiss="alert" aria-label="Close"><span 
aria-hidden="true">&times;</span></button>
                                                        Press 
<i>[CTRL-SPACE]</i> to activate auto completion. Data last updated: <span 
id="dbUpdated">[connecting]</span>
diff --git a/gui/vendor/codemirror/addon/display/placeholder.js 
b/gui/vendor/codemirror/addon/display/placeholder.js
new file mode 100644
index 0000000..babddfb
--- /dev/null
+++ b/gui/vendor/codemirror/addon/display/placeholder.js
@@ -0,0 +1,60 @@
+// CodeMirror, copyright (c) by Marijn Haverbeke and others
+// Distributed under an MIT license: http://codemirror.net/LICENSE
+
+(function(mod) {
+  if (typeof exports == "object" && typeof module == "object") // CommonJS
+    mod(require("../../lib/codemirror"));
+  else if (typeof define == "function" && define.amd) // AMD
+    define(["../../lib/codemirror"], mod);
+  else // Plain browser env
+    mod(CodeMirror);
+})(function(CodeMirror) {
+  CodeMirror.defineOption("placeholder", "", function(cm, val, old) {
+    var prev = old && old != CodeMirror.Init;
+    if (val && !prev) {
+      cm.on("blur", onBlur);
+      cm.on("change", onChange);
+      onChange(cm);
+    } else if (!val && prev) {
+      cm.off("blur", onBlur);
+      cm.off("change", onChange);
+      clearPlaceholder(cm);
+      var wrapper = cm.getWrapperElement();
+      wrapper.className = wrapper.className.replace(" CodeMirror-empty", "");
+    }
+
+    if (val && !cm.hasFocus()) onBlur(cm);
+  });
+
+  function clearPlaceholder(cm) {
+    if (cm.state.placeholder) {
+      cm.state.placeholder.parentNode.removeChild(cm.state.placeholder);
+      cm.state.placeholder = null;
+    }
+  }
+  function setPlaceholder(cm) {
+    clearPlaceholder(cm);
+    var elt = cm.state.placeholder = document.createElement("pre");
+    elt.style.cssText = "height: 0; overflow: visible";
+    elt.className = "CodeMirror-placeholder";
+    var placeHolder = cm.getOption("placeholder")
+    if (typeof placeHolder == "string") placeHolder = 
document.createTextNode(placeHolder)
+    elt.appendChild(placeHolder)
+    cm.display.lineSpace.insertBefore(elt, cm.display.lineSpace.firstChild);
+  }
+
+  function onBlur(cm) {
+    if (isEmpty(cm)) setPlaceholder(cm);
+  }
+  function onChange(cm) {
+    var wrapper = cm.getWrapperElement(), empty = isEmpty(cm);
+    wrapper.className = wrapper.className.replace(" CodeMirror-empty", "") + 
(empty ? " CodeMirror-empty" : "");
+
+    if (empty) setPlaceholder(cm);
+    else clearPlaceholder(cm);
+  }
+
+  function isEmpty(cm) {
+    return (cm.lineCount() === 1) && (cm.getLine(0) === "");
+  }
+});
diff --git a/gui/addon/hint/show-hint.css 
b/gui/vendor/codemirror/addon/hint/show-hint.css
similarity index 100%
rename from gui/addon/hint/show-hint.css
rename to gui/vendor/codemirror/addon/hint/show-hint.css
diff --git a/gui/addon/hint/show-hint.js 
b/gui/vendor/codemirror/addon/hint/show-hint.js
similarity index 100%
rename from gui/addon/hint/show-hint.js
rename to gui/vendor/codemirror/addon/hint/show-hint.js
diff --git a/gui/addon/hint/wikibase-rdf-hint.js 
b/gui/vendor/codemirror/addon/hint/wikibase-rdf-hint.js
similarity index 100%
rename from gui/addon/hint/wikibase-rdf-hint.js
rename to gui/vendor/codemirror/addon/hint/wikibase-rdf-hint.js
diff --git a/gui/addon/hint/wikibase-sparql-hint.js 
b/gui/vendor/codemirror/addon/hint/wikibase-sparql-hint.js
similarity index 100%
rename from gui/addon/hint/wikibase-sparql-hint.js
rename to gui/vendor/codemirror/addon/hint/wikibase-sparql-hint.js
diff --git a/gui/addon/tooltip/WikibaseRDFTooltip.js 
b/gui/vendor/codemirror/addon/tooltip/WikibaseRDFTooltip.js
similarity index 100%
rename from gui/addon/tooltip/WikibaseRDFTooltip.js
rename to gui/vendor/codemirror/addon/tooltip/WikibaseRDFTooltip.js
diff --git a/gui/codemirror.css b/gui/vendor/codemirror/lib/codemirror.css
similarity index 100%
rename from gui/codemirror.css
rename to gui/vendor/codemirror/lib/codemirror.css
diff --git a/gui/codemirror.js b/gui/vendor/codemirror/lib/codemirror.js
similarity index 100%
rename from gui/codemirror.js
rename to gui/vendor/codemirror/lib/codemirror.js
diff --git a/gui/sparql.js b/gui/vendor/codemirror/mode/sparql.js
similarity index 100%
rename from gui/sparql.js
rename to gui/vendor/codemirror/mode/sparql.js

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I281ecef1f57d5542e0351b7de593c9b5e602f684
Gerrit-PatchSet: 1
Gerrit-Project: wikidata/query/rdf
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