aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCallum Macrae <callum@macr.ae>2015-05-29 13:08:31 +0200
committerCallum Macrae <callum@macr.ae>2015-05-29 13:08:31 +0200
commitda6f751cefedd0573611cf3e9123b4345759d779 (patch)
tree06c11bb3a6df4318ea04dc9bf3401701e91fd5fd
parent0fc6816be6e1615fd6f3d7f3a52bb48049212e96 (diff)
downloadforums-da6f751cefedd0573611cf3e9123b4345759d779.tar
forums-da6f751cefedd0573611cf3e9123b4345759d779.tar.gz
forums-da6f751cefedd0573611cf3e9123b4345759d779.tar.bz2
forums-da6f751cefedd0573611cf3e9123b4345759d779.tar.xz
forums-da6f751cefedd0573611cf3e9123b4345759d779.zip
[ticket/13887] Made readable code DRY
PHPBB3-13887
-rw-r--r--phpBB/assets/javascript/plupload.js29
1 files changed, 13 insertions, 16 deletions
diff --git a/phpBB/assets/javascript/plupload.js b/phpBB/assets/javascript/plupload.js
index 625907a2f6..3845de6c56 100644
--- a/phpBB/assets/javascript/plupload.js
+++ b/phpBB/assets/javascript/plupload.js
@@ -315,31 +315,28 @@ phpbb.plupload.updateBbcode = function(action, index) {
return;
}
- // Private function used to replace the bbcode.
- var updateBbcode = function(match, fileName) {
- // Remove the bbcode if the file was removed.
- if (removal && index === i) {
- return '';
- }
- var newIndex = i + ((removal) ? -1 : 1);
- return '[attachment=' + newIndex +']' + fileName + '[/attachment]';
- };
-
- // Private function used to generate search regexp
- var searchRegexp = function(index) {
- return new RegExp('\\[attachment=' + index + '\\](.*?)\\[\\/attachment\\]', 'g');
- };
+ function runUpdate(i) {
+ var regex = new RegExp('\\[attachment=' + i + '\\](.*?)\\[\\/attachment\\]', 'g');
+ text = text.replace(regex, function updateBbcode(_, fileName) {
+ // Remove the bbcode if the file was removed.
+ if (removal && index === i) {
+ return '';
+ }
+ var newIndex = i + ((removal) ? -1 : 1);
+ return '[attachment=' + newIndex +']' + fileName + '[/attachment]';
+ });
+ }
// 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);
+ runUpdate(i);
}
} else {
for (i = phpbb.plupload.ids.length - 1; i >= index; i--) {
- text = text.replace(searchRegexp(i), updateBbcode);
+ runUpdate(i);
}
}