diff options
author | JoshyPHP <s9e.dev@gmail.com> | 2015-06-22 04:00:55 +0200 |
---|---|---|
committer | JoshyPHP <s9e.dev@gmail.com> | 2015-06-25 03:11:58 +0200 |
commit | 06936bda05a48e5b6e20d7c0b0979cf7fc1a29ae (patch) | |
tree | 95f16e6d9e06ee08c51965c55152a14f50ae234d /phpBB/assets | |
parent | c934b8f150c81115062687e59988ca0f78b35c37 (diff) | |
download | forums-06936bda05a48e5b6e20d7c0b0979cf7fc1a29ae.tar forums-06936bda05a48e5b6e20d7c0b0979cf7fc1a29ae.tar.gz forums-06936bda05a48e5b6e20d7c0b0979cf7fc1a29ae.tar.bz2 forums-06936bda05a48e5b6e20d7c0b0979cf7fc1a29ae.tar.xz forums-06936bda05a48e5b6e20d7c0b0979cf7fc1a29ae.zip |
[ticket/10620] Added enhanced quotes in topic review
Added support for enhanced quotes in topic_review's quote button.
NOTE: the UI doesn't appear to be testable via PhantomJS.
PHPBB3-10620
Diffstat (limited to 'phpBB/assets')
-rw-r--r-- | phpBB/assets/javascript/editor.js | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/phpBB/assets/javascript/editor.js b/phpBB/assets/javascript/editor.js index 298526ab1f..d0d849330a 100644 --- a/phpBB/assets/javascript/editor.js +++ b/phpBB/assets/javascript/editor.js @@ -167,7 +167,7 @@ function attachInline(index, filename) { /** * Add quote text to message */ -function addquote(post_id, username, l_wrote) { +function addquote(post_id, username, l_wrote, attributes) { var message_name = 'message_' + post_id; var theSelection = ''; var divarea = false; @@ -213,7 +213,12 @@ function addquote(post_id, username, l_wrote) { if (theSelection) { if (bbcodeEnabled) { - insert_text('[quote="' + username + '"]' + theSelection + '[/quote]'); + if (typeof attributes === 'undefined') + { + attributes = {}; + } + attributes.author = username; + insert_text(generate_quote(theSelection, attributes)); } else { insert_text(username + ' ' + l_wrote + ':' + '\n'); var lines = split_lines(theSelection); @@ -226,6 +231,55 @@ function addquote(post_id, username, l_wrote) { return; } +/** +* Create a quote block for given text +* +* Possible attributes: +* - author: author's name (usually a username) +* - post_id: post_id of the post being quoted +* - user_id: user_id of the user being quoted +* - time: timestamp of the original message +* +* @param {!string} text Quote's text +* @param {!Object} attributes Quote's attributes +* @return {!string} Quote block to be used in a new post/text +*/ +function generate_quote(text, attributes) +{ + var quote = '[quote'; + if ('author' in attributes) + { + // Add the author as the BBCode's default attribute + quote += '=' + enquote(attributes.author); + delete attributes.author; + } + for (var name in attributes) + { + var value = attributes[name]; + quote += ' ' + name + '=' + enquote(String(value)); + } + quote += ']' + text + '[/quote]'; + + return quote; +} + +/** +* Return given string between quotes +* +* Will use either single- or double- quotes depending on whichever requires less escaping. +* Quotes and backslashes are escaped with backslashes where necessary +* +* @param {!string} str Original string +* @return {!string} Escaped string within quotes +*/ +function enquote(str) +{ + var singleQuoted = "'" + str.replace(/[\\']/g, '\\$&') + "'", + doubleQuoted = '"' + str.replace(/[\\"]/g, '\\$&') + '"'; + + return (singleQuoted.length < doubleQuoted.length) ? singleQuoted : doubleQuoted; +} + function split_lines(text) { var lines = text.split('\n'); var splitLines = new Array(); |