From 06936bda05a48e5b6e20d7c0b0979cf7fc1a29ae Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 22 Jun 2015 04:00:55 +0200 Subject: [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 --- phpBB/assets/javascript/editor.js | 58 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) (limited to 'phpBB/assets/javascript/editor.js') 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(); -- cgit v1.2.1 From 4f1b25706f6a1ae6eb1c6c60ef27b42bb7ac4b40 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Wed, 24 Jun 2015 22:20:39 +0200 Subject: [ticket/10620] Removed extraneous quotes from attribute values PHPBB3-10620 --- phpBB/assets/javascript/editor.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'phpBB/assets/javascript/editor.js') diff --git a/phpBB/assets/javascript/editor.js b/phpBB/assets/javascript/editor.js index d0d849330a..878a5cab86 100644 --- a/phpBB/assets/javascript/editor.js +++ b/phpBB/assets/javascript/editor.js @@ -250,13 +250,13 @@ function generate_quote(text, attributes) if ('author' in attributes) { // Add the author as the BBCode's default attribute - quote += '=' + enquote(attributes.author); + quote += '=' + format_attribute_value(attributes.author); delete attributes.author; } for (var name in attributes) { var value = attributes[name]; - quote += ' ' + name + '=' + enquote(String(value)); + quote += ' ' + name + '=' + format_attribute_value(String(value)); } quote += ']' + text + '[/quote]'; @@ -264,16 +264,22 @@ function generate_quote(text, attributes) } /** -* Return given string between quotes +* Format given string to be used as an attribute value * -* Will use either single- or double- quotes depending on whichever requires less escaping. +* Will return the string as-is if it can be used in a BBCode without quotes. Otherwise, +* it 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 +* @return {!string} Same string if possible, escaped string within quotes otherwise */ -function enquote(str) +function format_attribute_value(str) { + if (!/[ "'\\\]]/.test(str)) + { + // Return as-is if it contains none of: space, ' " \ or ] + return str; + } var singleQuoted = "'" + str.replace(/[\\']/g, '\\$&') + "'", doubleQuoted = '"' + str.replace(/[\\"]/g, '\\$&') + '"'; -- cgit v1.2.1 From 4c9507e20ad4e3de291143c8a40d5c977388f5a5 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Wed, 24 Jun 2015 22:36:44 +0200 Subject: [ticket/10620] Fixed some stylistic issues in JS PHPBB3-10620 --- phpBB/assets/javascript/editor.js | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) (limited to 'phpBB/assets/javascript/editor.js') diff --git a/phpBB/assets/javascript/editor.js b/phpBB/assets/javascript/editor.js index 878a5cab86..f0fa064ec5 100644 --- a/phpBB/assets/javascript/editor.js +++ b/phpBB/assets/javascript/editor.js @@ -111,7 +111,6 @@ function bbfontstyle(bbopen, bbclose) { } textarea.focus(); - return; } /** @@ -177,6 +176,9 @@ function addquote(post_id, username, l_wrote, attributes) { // Backwards compatibility l_wrote = 'wrote'; } + if (typeof attributes !== 'object') { + attributes = {}; + } if (document.all) { divarea = document.all[message_name]; @@ -213,12 +215,8 @@ function addquote(post_id, username, l_wrote, attributes) { if (theSelection) { if (bbcodeEnabled) { - if (typeof attributes === 'undefined') - { - attributes = {}; - } attributes.author = username; - insert_text(generate_quote(theSelection, attributes)); + insert_text(generateQuote(theSelection, attributes)); } else { insert_text(username + ' ' + l_wrote + ':' + '\n'); var lines = split_lines(theSelection); @@ -227,8 +225,6 @@ function addquote(post_id, username, l_wrote, attributes) { } } } - - return; } /** @@ -244,19 +240,18 @@ function addquote(post_id, username, l_wrote, attributes) { * @param {!Object} attributes Quote's attributes * @return {!string} Quote block to be used in a new post/text */ -function generate_quote(text, attributes) -{ +function generateQuote(text, attributes) { var quote = '[quote'; - if ('author' in attributes) - { + if (attributes.author) { // Add the author as the BBCode's default attribute - quote += '=' + format_attribute_value(attributes.author); + quote += '=' + formatAttributeValue(attributes.author); delete attributes.author; } - for (var name in attributes) - { - var value = attributes[name]; - quote += ' ' + name + '=' + format_attribute_value(String(value)); + for (var name in attributes) { + if (attributes.hasOwnProperty(name)) { + var value = attributes[name]; + quote += ' ' + name + '=' + formatAttributeValue(value.toString()); + } } quote += ']' + text + '[/quote]'; @@ -273,10 +268,8 @@ function generate_quote(text, attributes) * @param {!string} str Original string * @return {!string} Same string if possible, escaped string within quotes otherwise */ -function format_attribute_value(str) -{ - if (!/[ "'\\\]]/.test(str)) - { +function formatAttributeValue(str) { + if (!/[ "'\\\]]/.test(str)) { // Return as-is if it contains none of: space, ' " \ or ] return str; } -- cgit v1.2.1 From 5a55ce3f6832677e2c0a244d3a5c0b4c2587b8c5 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Wed, 24 Jun 2015 22:41:58 +0200 Subject: [ticket/10620] Add more whitespace to long quotes in JS PHPBB3-10620 --- phpBB/assets/javascript/editor.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'phpBB/assets/javascript/editor.js') diff --git a/phpBB/assets/javascript/editor.js b/phpBB/assets/javascript/editor.js index f0fa064ec5..df353bc29d 100644 --- a/phpBB/assets/javascript/editor.js +++ b/phpBB/assets/javascript/editor.js @@ -241,6 +241,7 @@ function addquote(post_id, username, l_wrote, attributes) { * @return {!string} Quote block to be used in a new post/text */ function generateQuote(text, attributes) { + text = text.replace(/^\s+/, '').replace(/\s+$/, ''); var quote = '[quote'; if (attributes.author) { // Add the author as the BBCode's default attribute @@ -253,7 +254,9 @@ function generateQuote(text, attributes) { quote += ' ' + name + '=' + formatAttributeValue(value.toString()); } } - quote += ']' + text + '[/quote]'; + quote += ']'; + var newline = ((quote + text + '[/quote]').length > 80 || text.indexOf('\n') > -1) ? '\n' : ''; + quote += newline + text + newline + '[/quote]'; return quote; } -- cgit v1.2.1