aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/styles
diff options
context:
space:
mode:
authorNathaniel Guse <nathaniel.guse@gmail.com>2013-06-06 14:07:27 -0500
committerNathaniel Guse <nathaniel.guse@gmail.com>2013-06-06 14:07:27 -0500
commit8c3bb26a62ade208d5035015299c2126b15854cb (patch)
tree6e8b789cfad8bd87e86b1df5df4c6aacfc4e6eb7 /phpBB/styles
parent4a4a822df888231d2fbea7bf9555604b93f3dc95 (diff)
parent9db0fa88569da1922ac21d9a003b7e577a96c810 (diff)
downloadforums-8c3bb26a62ade208d5035015299c2126b15854cb.tar
forums-8c3bb26a62ade208d5035015299c2126b15854cb.tar.gz
forums-8c3bb26a62ade208d5035015299c2126b15854cb.tar.bz2
forums-8c3bb26a62ade208d5035015299c2126b15854cb.tar.xz
forums-8c3bb26a62ade208d5035015299c2126b15854cb.zip
Merge remote-tracking branch 'remotes/cyberalien/feature/editor-code-tabs' into develop
# By Vjacheslav Trushkin # Via Vjacheslav Trushkin * remotes/cyberalien/feature/editor-code-tabs: [feature/editor-code-tabs] Make inTag function reusable [feature/editor-code-tabs] Check for browser support in function [feature/editor-code-tabs] Apply code editor to everything [feature/editor-code-tabs] Correctly count indentation on first line
Diffstat (limited to 'phpBB/styles')
-rw-r--r--phpBB/styles/prosilver/template/editor.js77
-rw-r--r--phpBB/styles/subsilver2/template/editor.js1
2 files changed, 3 insertions, 75 deletions
diff --git a/phpBB/styles/prosilver/template/editor.js b/phpBB/styles/prosilver/template/editor.js
index fd4c68adfe..235cc0025b 100644
--- a/phpBB/styles/prosilver/template/editor.js
+++ b/phpBB/styles/prosilver/template/editor.js
@@ -401,7 +401,7 @@ function getCaretPosition(txtarea) {
*/
(function($) {
$(document).ready(function() {
- var doc, textarea, startTags, endTags;
+ var doc, textarea;
// find textarea, make sure browser supports necessary functions
if (document.forms[form_name]) {
@@ -415,81 +415,8 @@ function getCaretPosition(txtarea) {
}
textarea = doc.forms[form_name].elements[text_name];
- if (!textarea || typeof textarea.selectionStart !== 'number') {
- return;
- }
-
- // list of allowed start and end bbcode code tags, in lower case
- startTags = ['[code]', '[code='];
- endTags = ['[/code]'];
-
- function inTag() {
- var start = textarea.selectionStart,
- lastEnd = -1,
- lastStart = -1,
- i, index, value;
-
- value = textarea.value.toLowerCase();
-
- for (i = 0; i < startTags.length; i++) {
- var tagLength = startTags[i].length;
- if (start >= tagLength) {
- index = value.lastIndexOf(startTags[i], start - tagLength);
- lastStart = Math.max(lastStart, index);
- }
- }
- if (lastStart == -1) return false;
-
- if (start > 0) {
- for (i = 0; i < endTags.length; i++) {
- index = value.lastIndexOf(endTags[i], start - 1);
- lastEnd = Math.max(lastEnd, index);
- }
- }
-
- return (lastEnd < lastStart);
- }
-
- function getLastLine() {
- var start = textarea.selectionStart,
- value = textarea.value,
- index = value.lastIndexOf("\n", start - 1);
- return value.substring(index + 1, start);
- }
-
- function appendCode(code) {
- var start = textarea.selectionStart,
- end = textarea.selectionEnd,
- value = textarea.value;
- textarea.value = value.substr(0, start) + code + value.substr(end);
- textarea.selectionStart = textarea.selectionEnd = start + code.length;
- }
-
- $(textarea).on('keydown', function(event) {
- var key = event.keyCode || event.which;
- // intercept tabs
- if (key == 9) {
- if (inTag()) {
- appendCode("\t");
- event.preventDefault();
- return;
- }
- }
-
- // intercept new line characters
- if (key == 13) {
- if (inTag()) {
- var lastLine = getLastLine(),
- code = '' + /^\s*/g.exec(lastLine);
- if (code.length > 0) {
- appendCode("\n" + code);
- event.preventDefault();
- return;
- }
- }
- }
- });
+ phpbb.applyCodeEditor(textarea);
});
})(jQuery);
diff --git a/phpBB/styles/subsilver2/template/editor.js b/phpBB/styles/subsilver2/template/editor.js
index 93506b8d4a..6cf616e180 100644
--- a/phpBB/styles/subsilver2/template/editor.js
+++ b/phpBB/styles/subsilver2/template/editor.js
@@ -38,6 +38,7 @@ function initInsertions() {
}
var textarea = doc.forms[form_name].elements[text_name];
+ phpbb.applyCodeEditor(textarea);
if (is_ie && typeof(baseHeight) !== 'number') {
textarea.focus();