mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 13:28:55 +00:00
[ticket/13887] Made readable code DRY
PHPBB3-13887
This commit is contained in:
parent
0fc6816be6
commit
da6f751cef
1 changed files with 13 additions and 16 deletions
|
@ -315,31 +315,28 @@ phpbb.plupload.updateBbcode = function(action, index) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private function used to replace the bbcode.
|
function runUpdate(i) {
|
||||||
var updateBbcode = function(match, fileName) {
|
var regex = new RegExp('\\[attachment=' + i + '\\](.*?)\\[\\/attachment\\]', 'g');
|
||||||
// Remove the bbcode if the file was removed.
|
text = text.replace(regex, function updateBbcode(_, fileName) {
|
||||||
if (removal && index === i) {
|
// Remove the bbcode if the file was removed.
|
||||||
return '';
|
if (removal && index === i) {
|
||||||
}
|
return '';
|
||||||
var newIndex = i + ((removal) ? -1 : 1);
|
}
|
||||||
return '[attachment=' + newIndex +']' + fileName + '[/attachment]';
|
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');
|
|
||||||
};
|
|
||||||
|
|
||||||
// Loop forwards when removing and backwards when adding ensures we don't
|
// Loop forwards when removing and backwards when adding ensures we don't
|
||||||
// corrupt the bbcode index.
|
// corrupt the bbcode index.
|
||||||
var i;
|
var i;
|
||||||
if (removal) {
|
if (removal) {
|
||||||
for (i = index; i < phpbb.plupload.ids.length; i++) {
|
for (i = index; i < phpbb.plupload.ids.length; i++) {
|
||||||
text = text.replace(searchRegexp(i), updateBbcode);
|
runUpdate(i);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i = phpbb.plupload.ids.length - 1; i >= index; i--) {
|
for (i = phpbb.plupload.ids.length - 1; i >= index; i--) {
|
||||||
text = text.replace(searchRegexp(i), updateBbcode);
|
runUpdate(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue