Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Post = {
- posts: new Hash(),
- blacklist_options: {replace: true},
- register: function(post) {
- post.tags = post.tags.match(/\S+/g)
- if (!post.tags)
- post.tags = []
- post.match_tags = post.tags.clone()
- post.match_tags.push("rating:" + post.rating.charAt(0))
- post.match_tags.push("status:" + post.status)
- post.match_tags.push("user:" + post.author.toLowerCase())
- post.match_tags.push("id:"+post.id)
- post.match_tags.push("type:"+post.file_ext)
- // These won't actually work for blacklisting until it's rewritten to take into account comparison/ranges (score:<0)
- post.match_tags.push("score:"+post.score)
- post.match_tags.push("width:"+post.width)
- post.match_tags.push("height:"+post.height)
- this.posts.set(post.id, post)
- },
- blacklists: [],
- is_blacklisted: function(post_id) { // you can't have side effects like ++b.hits in a method called "is_blacklisted", ffs
- var post = this.posts.get(post_id)
- var has_tag = post.match_tags.member.bind(post.match_tags)
- return Post.blacklists.any(function(b) {
- return (b.require.all(has_tag) && !b.exclude.any(has_tag))
- })
- },
- apply_blacklists: function() {
- Post.blacklists.each(function(b) { b.hits = 0 })
- var count = 0
- Post.posts.each(function(pair) {
- var thumbs = $$("#p" + pair.key)
- if (thumbs.length == 0)
- return;
- var post = pair.value
- var has_tag = post.match_tags.member.bind(post.match_tags)
- post.blacklisted = []
- Post.blacklists.each(function(b) {
- if (b.require.all(has_tag) && !b.exclude.any(has_tag)) {
- b.hits++
- if (!b.disabled)
- post.blacklisted.push(b)
- }
- })
- bld = post.blacklisted.length > 0
- count += bld
- thumbs.each(function(thumb) {
- if (Post.blacklist_options.replace) {
- var img = thumb.down('img')
- var isavatar = (img.parentNode.parentNode.className.indexOf("thumb_avatar") != -1)
- if (bld && ((isavatar && (Cookie.get("blacklist_avatars") == "true")) || !isavatar)) {
- img.src = "/images/blacklisted-preview.png"
- img.setAttribute('data-original', "/images/blacklisted-preview.png");
- img.width = img.height = 150
- }
- else {
- img.setAttribute('data-original', post.preview_url);
- img.src = post.preview_url
- img.width = post.preview_width
- img.height = post.preview_height
- }
- thumb.removeClassName('blacklisted');
- }
- else {
- if (bld)
- thumb.addClassName('blacklisted');
- else
- thumb.removeClassName('blacklisted');
- }
- });
- })
- if (Post.countText)
- $j('#blacklist-count').html(count);
- return count
- },
- init_blacklisted: function (options) {
- Post.blacklisted=[];
- Post.blacklists=[];
- Post.blacklist_options = Object.extend(Post.blacklist_options, options);
- var bl_entries = Cookie.get("blacklisted_tags").split(/[&,]/);
- bl_entries.each(function (val) {
- var s = Cookie.unescape(val).replace(/(rating:[qes])\w+/, "$1");
- var tags = s.match(/\S+/g);
- if (!tags)
- return;
- var b = {tags: tags, require: [], exclude: [], disabled: false, hits: 0};
- tags.each(function (tag) {
- Post.blacklisted_user(tag);
- if (tag.charAt(0) == "-")
- b.exclude.push(tag.slice(1));
- else
- b.require.push(tag);
- });
- Post.blacklists.push(b);});
- var sidebar = $("blacklisted-sidebar");
- if (!sidebar) {
- Post.apply_blacklists();
- return;
- };
- var blacklist_count = $("blacklist-count");
- if (blacklist_count && !Post.countText)
- Post.countText = blacklist_count.appendChild(document.createTextNode(""));
- if (!Post.apply_blacklists()) {
- sidebar.hide();
- return;
- }
- sidebar.show();
- sidebar.observe("mousedown", function (event) {event.stop();});
- var list = $("blacklisted-list");
- while (list.childNodes.length>1) {
- list.removeChild(list.childNodes[1]);
- }
- Post.blacklists.each(function (b) {
- if (!b.hits)
- return;
- var li = list.appendChild(document.createElement("li"));
- li.className = "blacklisted-tags";
- var a = li.appendChild(document.createElement("a"));
- a.href = "#";
- var expand = a.appendChild(document.createTextNode("\xBB"));
- a.observe("click", function (event) {
- b.disabled = !b.disabled;
- a.className = b.disabled ? "blacklisted-tags-disabled" : "blacklisted-tags";
- Post.apply_blacklists();
- event.stop();
- });
- a.appendChild(document.createTextNode(" "));
- var tags = a.appendChild(document.createTextNode(b.tags.join(" ")));
- li.appendChild(document.createTextNode(" "));
- var span = li.appendChild(document.createElement("span"));
- span.className = "post-count";
- span.appendChild(document.createTextNode(b.hits));
- });
- },
- blacklisted_user: function(tag) {
- if (Cookie.get("blacklist_users") == "true") {
- var pattern=/user:/i;
- if (pattern.test(tag)) {
- var username = tag.replace(pattern, "").toLowerCase();
- jQuery("div[data-author='" + username +"'], tr[data-author='" + username +"']").each(function(){
- jQuery(this).hide();
- });
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement