Browse Source

Merge pull request #52 from mutantmonkey/textarea_tab

add tab functionality to pastebin (resolves #48)
pull/53/head
Andrei Marcu 9 years ago
parent
commit
95d3a62c0c
  1. 5
      static/js/bin.js
  2. 3
      static/js/paste.js
  3. 18
      static/js/util.js
  4. 1
      templates/display/bin.html
  5. 3
      templates/paste.html

5
static/js/bin.js

@ -5,7 +5,6 @@ var navlist = document.getElementById("info").getElementsByClassName("right")[0]
init(); init();
function init() { function init() {
var editA = document.createElement('a'); var editA = document.createElement('a');
editA.setAttribute("href", "#"); editA.setAttribute("href", "#");
@ -23,8 +22,8 @@ function init() {
document.getElementById('wordwrap').addEventListener('click', wrap); document.getElementById('wordwrap').addEventListener('click', wrap);
} }
function edit(ev) { function edit(ev) {
ev.preventDefault();
navlist.remove(); navlist.remove();
document.getElementById("filename").remove(); document.getElementById("filename").remove();
@ -35,9 +34,9 @@ function edit(ev) {
var editordiv = document.getElementById("editor"); var editordiv = document.getElementById("editor");
editordiv.style.display = "block"; editordiv.style.display = "block";
editordiv.addEventListener('keydown', handleTab);
} }
function paste(ev) { function paste(ev) {
var editordiv = document.getElementById("editor"); var editordiv = document.getElementById("editor");
document.getElementById("newcontent").value = editordiv.value; document.getElementById("newcontent").value = editordiv.value;

3
static/js/paste.js

@ -0,0 +1,3 @@
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
document.getElementById('content').addEventListener('keydown', handleTab);
// @license-end

18
static/js/util.js

@ -0,0 +1,18 @@
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
function handleTab(ev) {
// change tab key behavior to insert tab instead of change focus
if(ev.keyCode == 9) {
ev.preventDefault();
var val = this.value;
var start = this.selectionStart;
var end = this.selectionEnd;
this.value = val.substring(0, start) + '\t' + val.substring(end);
this.selectionStart = start + 1;
this.selectionEnd = end + 1;
}
}
// @license-end

1
templates/display/bin.html

@ -52,5 +52,6 @@
<script src="/static/js/bin_hljs.js"></script> <script src="/static/js/bin_hljs.js"></script>
{% endif %} {% endif %}
<script src="/static/js/util.js"></script>
<script src="/static/js/bin.js"></script> <script src="/static/js/bin.js"></script>
{% endblock %} {% endblock %}

3
templates/paste.html

@ -33,4 +33,7 @@
</div> </div>
</div> </div>
</form> </form>
<script src="/static/js/util.js"></script>
<script src="/static/js/paste.js"></script>
{% endblock %} {% endblock %}
Loading…
Cancel
Save