Fixes #3807. Drops the TagScript module entirely and replaces it with a simple call to Post.tag. Simultaneously fixes #3773 as a consequence of removing TagScript.run. Post.update already updates data-tags by itself, so there was no need for TagScript.run to update data-tags as well.
This commit is contained in:
@@ -38,4 +38,3 @@ export { default as Note } from '../src/javascripts/notes.js';
|
||||
export { default as PostModeMenu } from '../src/javascripts/post_mode_menu.js';
|
||||
export { default as Utility } from '../src/javascripts/utility.js';
|
||||
export { default as Ugoira } from '../src/javascripts/ugoira.js';
|
||||
export { default as TagScript } from '../src/javascripts/tag_script.js';
|
||||
|
||||
@@ -2,7 +2,6 @@ import Utility from './utility'
|
||||
import Cookie from './cookie'
|
||||
import Post from './posts.js.erb'
|
||||
import Favorite from './favorites'
|
||||
import TagScript from './tag_script'
|
||||
|
||||
let PostModeMenu = {};
|
||||
|
||||
@@ -175,7 +174,7 @@ PostModeMenu.click = function(e) {
|
||||
} else if (s === "tag-script") {
|
||||
var current_script_id = Cookie.get("current_tag_script_id");
|
||||
var tag_script = Cookie.get("tag-script-" + current_script_id);
|
||||
TagScript.run(post_id, tag_script);
|
||||
Post.tag(post_id, tag_script);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -535,6 +535,11 @@ Post.vote = function(score, id) {
|
||||
});
|
||||
}
|
||||
|
||||
Post.tag = function(post_id, tags) {
|
||||
const tag_string = (Array.isArray(tags) ? tags.join(" ") : String(tags));
|
||||
Post.update(post_id, { "post[old_tag_string]": "", "post[tag_string]": tag_string });
|
||||
}
|
||||
|
||||
Post.update = function(post_id, params) {
|
||||
Post.notice_update("inc");
|
||||
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
import Utility from './utility'
|
||||
import Post from './posts.js.erb'
|
||||
|
||||
let TagScript = {};
|
||||
|
||||
TagScript.parse = function(script) {
|
||||
return script.match(/\[.+?\]|\S+/g);
|
||||
}
|
||||
|
||||
TagScript.test = function(tags, predicate) {
|
||||
var split_pred = predicate.match(/\S+/g);
|
||||
var is_true = true;
|
||||
|
||||
$.each(split_pred, function(i, x) {
|
||||
if (x[0] === "-") {
|
||||
if ($.inArray(x.substr(1, 100), tags)) {
|
||||
is_true = false;
|
||||
}
|
||||
} else if (!$.inArray(x, tags)) {
|
||||
is_true = false;
|
||||
}
|
||||
});
|
||||
|
||||
return is_true;
|
||||
}
|
||||
|
||||
TagScript.process = function(tags, command) {
|
||||
if (command.match(/^\[if/)) {
|
||||
var match = command.match(/\[if\s+(.+?)\s*,\s*(.+?)\]/);
|
||||
if (TagScript.test(tags, match[1])) {
|
||||
return TagScript.process(tags, match[2]);
|
||||
} else {
|
||||
return tags;
|
||||
}
|
||||
} else if (command === "[reset]") {
|
||||
return [];
|
||||
} else if (command[0] === "-" && !command.match(/^(?:-pool|-parent|-fav|-favgroup):/i)) {
|
||||
return Utility.reject(tags, function(x) {return x === command.substr(1, 100)});
|
||||
} else {
|
||||
tags.push(command);
|
||||
return tags;
|
||||
}
|
||||
}
|
||||
|
||||
TagScript.run = function(post_id, tag_script) {
|
||||
var commands = TagScript.parse(tag_script);
|
||||
var $post = $("#post_" + post_id);
|
||||
var old_tags = $post.data("tags");
|
||||
|
||||
$.each(commands, function(i, x) {
|
||||
var array = String($post.data("tags")).match(/\S+/g);
|
||||
$post.data("tags", TagScript.process(array, x).join(" "));
|
||||
});
|
||||
|
||||
Post.update(post_id, {"post[old_tag_string]": old_tags, "post[tag_string]": $post.data("tags")});
|
||||
}
|
||||
|
||||
export default TagScript
|
||||
@@ -99,16 +99,6 @@ Utility.without = function(array, element) {
|
||||
return temp;
|
||||
}
|
||||
|
||||
Utility.reject = function(array, f) {
|
||||
var filtered = [];
|
||||
$.each(array, function(i, x) {
|
||||
if (!f(x)) {
|
||||
filtered.push(x);
|
||||
}
|
||||
});
|
||||
return filtered;
|
||||
}
|
||||
|
||||
Utility.regexp_escape = function(string) {
|
||||
return string.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user