aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
authorCallum Macrae <callum@macr.ae>2015-05-29 13:01:33 +0200
committerCallum Macrae <callum@macr.ae>2015-05-29 13:01:33 +0200
commit0fc6816be6e1615fd6f3d7f3a52bb48049212e96 (patch)
treecb061fe2d75430f456f0b2d74f666cd70b65c0c8 /phpBB
parent143578ad09e45e1d8a8abea0c718bf04043bed70 (diff)
downloadforums-0fc6816be6e1615fd6f3d7f3a52bb48049212e96.tar
forums-0fc6816be6e1615fd6f3d7f3a52bb48049212e96.tar.gz
forums-0fc6816be6e1615fd6f3d7f3a52bb48049212e96.tar.bz2
forums-0fc6816be6e1615fd6f3d7f3a52bb48049212e96.tar.xz
forums-0fc6816be6e1615fd6f3d7f3a52bb48049212e96.zip
[ticket/13887] Made unreadable code readable
PHPBB3-13887
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/assets/javascript/plupload.js26
1 files changed, 12 insertions, 14 deletions
diff --git a/phpBB/assets/javascript/plupload.js b/phpBB/assets/javascript/plupload.js
index ba40976544..625907a2f6 100644
--- a/phpBB/assets/javascript/plupload.js
+++ b/phpBB/assets/javascript/plupload.js
@@ -329,22 +329,20 @@ phpbb.plupload.updateBbcode = function(action, index) {
var searchRegexp = function(index) {
return new RegExp('\\[attachment=' + index + '\\](.*?)\\[\\/attachment\\]', 'g');
};
- // The update order of the indices is based on the action taken to ensure that we don't corrupt
- // the bbcode index by updating it several times as we move through the loop.
- // Removal loop starts at the removed index and moves to the end of the array.
- // Addition loop starts at the end of the array and moves to the added index at 0.
- var searchLoop = function() {
- if (typeof i === 'undefined') {
- i = (removal) ? index : phpbb.plupload.ids.length - 1;
- }
- return (removal) ? (i < phpbb.plupload.ids.length): (i >= index);
- };
- var i;
- while (searchLoop()) {
- text = text.replace(searchRegexp(i), updateBbcode);
- i += (removal) ? 1 : -1;
+ // Loop forwards when removing and backwards when adding ensures we don't
+ // corrupt the bbcode index.
+ var i;
+ if (removal) {
+ for (i = index; i < phpbb.plupload.ids.length; i++) {
+ text = text.replace(searchRegexp(i), updateBbcode);
+ }
+ } else {
+ for (i = phpbb.plupload.ids.length - 1; i >= index; i--) {
+ text = text.replace(searchRegexp(i), updateBbcode);
+ }
}
+
textarea.val(text);
};