sync
This commit is contained in:
38
public/javascripts/src/app/application.js
Normal file
38
public/javascripts/src/app/application.js
Normal file
@@ -0,0 +1,38 @@
|
||||
$(document).ready(function() {
|
||||
Cookie.setup();
|
||||
|
||||
// $("#hide-upgrade-account-link").click(function() {
|
||||
// $("#upgrade-account").hide();
|
||||
// Cookie.put('hide-upgrade-account', '1', 7);
|
||||
// });
|
||||
|
||||
// Style button spans
|
||||
|
||||
// Comment listing
|
||||
$(".comment-section form").hide();
|
||||
$(".comment-section input.expand-comment-response").click(function() {
|
||||
var post_id = $(this).closest(".comment-section").attr("data-post-id");
|
||||
$(".comment-section[data-post-id=" + post_id + "] form").show();
|
||||
$(this).hide();
|
||||
});
|
||||
|
||||
// Image resize sidebar
|
||||
$("#resize-links").hide();
|
||||
|
||||
$("#resize-links a").click(function(e) {
|
||||
var image = $("#image");
|
||||
var target = $(e.target);
|
||||
image.attr("src", target.attr("data-src"));
|
||||
image.attr("width", target.attr("data-width"));
|
||||
image.attr("height", target.attr("data-height"));
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("#resize-link a").click(function(e) {
|
||||
$("#resize-links").toggle();
|
||||
e.preventDefault();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
var Danbooru = {};
|
||||
58
public/javascripts/src/app/cookie.js
Normal file
58
public/javascripts/src/app/cookie.js
Normal file
@@ -0,0 +1,58 @@
|
||||
Cookie = {
|
||||
put: function(name, value, days) {
|
||||
if (days == null) {
|
||||
days = 365;
|
||||
}
|
||||
|
||||
var date = new Date();
|
||||
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
||||
var expires = "; expires=" + date.toGMTString();
|
||||
document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/";
|
||||
},
|
||||
|
||||
raw_get: function(name) {
|
||||
var nameEq = name + "=";
|
||||
var ca = document.cookie.split(";");
|
||||
|
||||
for (var i = 0; i < ca.length; ++i) {
|
||||
var c = ca[i];
|
||||
|
||||
while (c.charAt(0) == " ") {
|
||||
c = c.substring(1, c.length);
|
||||
}
|
||||
|
||||
if (c.indexOf(nameEq) == 0) {
|
||||
return c.substring(nameEq.length, c.length);
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
},
|
||||
|
||||
get: function(name) {
|
||||
return this.unescape(this.raw_get(name));
|
||||
},
|
||||
|
||||
remove: function(name) {
|
||||
Cookie.put(name, "", -1);
|
||||
},
|
||||
|
||||
unescape: function(val) {
|
||||
return decodeURIComponent(val.replace(/\+/g, " "));
|
||||
},
|
||||
|
||||
setup: function() {
|
||||
if (location.href.match(/^\/(comment|pool|note|post)/) && this.get("tos") != "1") {
|
||||
// Setting location.pathname in Safari doesn't work, so manually extract the domain.
|
||||
var domain = location.href.match(/^(http:\/\/[^\/]+)/)[0];
|
||||
location.href = domain + "/static/terms_of_service?url=" + location.href;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.get("hide-upgrade-account") != "1") {
|
||||
if ($("upgrade-account")) {
|
||||
$("upgrade-account").show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
168
public/javascripts/src/app/posts.js
Normal file
168
public/javascripts/src/app/posts.js
Normal file
@@ -0,0 +1,168 @@
|
||||
PostModeMenu = {
|
||||
init: function() {
|
||||
this.original_background_color = $(document.body).css("background-color")
|
||||
|
||||
if (Cookie.get("mode") == "") {
|
||||
Cookie.put("mode", "view");
|
||||
$("#mode-box select").val("view");
|
||||
} else {
|
||||
$("#mode-box select").val(Cookie.get("mode"));
|
||||
}
|
||||
|
||||
// this.change();
|
||||
},
|
||||
|
||||
change: function() {
|
||||
var s = $("#mode-box select").val();
|
||||
Cookie.put("mode", s, 7);
|
||||
|
||||
if (s == "view") {
|
||||
$(document.body).css({"background-color": this.original_background_color});
|
||||
} else if (s == "edit") {
|
||||
$(document.body).css({"background-color": "#3A3"});
|
||||
} else if (s == "add-fav") {
|
||||
$(document.body).css({"background-color": "#FFA"});
|
||||
} else if (s == "remove-fav") {
|
||||
$(document.body).css({"background-color": "#FFA"});
|
||||
} else if (s == "rating-q") {
|
||||
$(document.body).css({"background-color": "#AAA"});
|
||||
} else if (s == "rating-s") {
|
||||
$(document.body).css({"background-color": "#6F6"});
|
||||
} else if (s == "rating-e") {
|
||||
$(document.body).css({"background-color": "#F66"});
|
||||
} else if (s == "vote-down") {
|
||||
$(document.body).css({"background-color": "#FAA"});
|
||||
} else if (s == "vote-up") {
|
||||
$(document.body).css({"background-color": "#AFA"});
|
||||
} else if (s == "lock-rating") {
|
||||
$(document.body).css({"background-color": "#AA3"});
|
||||
} else if (s == "lock-note") {
|
||||
$(document.body).css({"background-color": "#3AA"});
|
||||
} else if (s == "approve") {
|
||||
$(document.body).css({"background-color": "#26A"});
|
||||
} else if (s == "unapprove") {
|
||||
$(document.body).css({"background-color": "#F66"});
|
||||
} else if (s == "add-to-pool") {
|
||||
$(document.body).css({"background-color": "#26A"});
|
||||
} else if (s == "apply-tag-script") {
|
||||
$(document.body).css({"background-color": "#A3A"});
|
||||
} else if (s == "edit-tag-script") {
|
||||
$(document.body).css({"background-color": "#FFF"});
|
||||
|
||||
var script = Cookie.get("tag-script");
|
||||
script = prompt("Enter a tag script", script);
|
||||
|
||||
if (script) {
|
||||
Cookie.put("tag-script", script);
|
||||
$("#mode-box select").val("apply-tag-script");
|
||||
} else {
|
||||
$("#mode-box select").val("view");
|
||||
}
|
||||
|
||||
this.change();
|
||||
} else {
|
||||
$(document.body).css({"background-color": "#AFA"});
|
||||
}
|
||||
},
|
||||
|
||||
click: function(post_id) {
|
||||
var s = $("#mode-box select").val();
|
||||
|
||||
if (s.value == "view") {
|
||||
return true;
|
||||
} else if (s.value == "add-fav") {
|
||||
Favorite.create(post_id);
|
||||
} else if (s.value == "remove-fav") {
|
||||
Favorite.destroy(post_id);
|
||||
} else if (s.value == "edit") {
|
||||
// TODO
|
||||
} else if (s.value == 'vote-down') {
|
||||
PostVote.create("down", post_id);
|
||||
} else if (s.value == 'vote-up') {
|
||||
PostVote.create("up", post_id);
|
||||
} else if (s.value == 'rating-q') {
|
||||
Post.update(post_id, {"post[rating]": "questionable"});
|
||||
} else if (s.value == 'rating-s') {
|
||||
Post.update(post_id, {"post[rating]": "safe"});
|
||||
} else if (s.value == 'rating-e') {
|
||||
Post.update(post_id, {"post[rating]": "explicit"});
|
||||
} else if (s.value == 'lock-rating') {
|
||||
Post.update(post_id, {"post[is_rating_locked]": "1"});
|
||||
} else if (s.value == 'lock-note') {
|
||||
Post.update(post_id, {"post[is_note_locked]": "1"});
|
||||
} else if (s.value == 'unapprove') {
|
||||
Unapproval.create(post_id);
|
||||
} else if (s.value == "approve") {
|
||||
Post.update(post_id, {"post[is_pending]": "0"});
|
||||
} else if (s.value == 'add-to-pool') {
|
||||
Pool.add_post(post_id, 0);
|
||||
} else if (s.value == "apply-tag-script") {
|
||||
var tag_script = Cookie.get("tag-script");
|
||||
TagScript.run(post_id, tag_script);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
TagScript = {
|
||||
parse: function(script) {
|
||||
return script.match(/\[.+?\]|\S+/g);
|
||||
},
|
||||
|
||||
test: function(tags, predicate) {
|
||||
var split_pred = predicate.match(/\S+/g);
|
||||
var is_true = true;
|
||||
|
||||
split_pred.each(function(x) {
|
||||
if (x[0] == "-") {
|
||||
if (tags.include(x.substr(1, 100))) {
|
||||
is_true = false;
|
||||
throw $break;
|
||||
}
|
||||
} else {
|
||||
if (!tags.include(x)) {
|
||||
is_true = false;
|
||||
throw $break;
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return is_true
|
||||
},
|
||||
|
||||
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] == "-") {
|
||||
return tags.reject(function(x) {return x == command.substr(1, 100)})
|
||||
} else {
|
||||
tags.push(command)
|
||||
return tags;
|
||||
}
|
||||
},
|
||||
|
||||
run: function(post_id, tag_script) {
|
||||
var commands = TagScript.parse(tag_script);
|
||||
var post = Post.posts.get(post_id);
|
||||
var old_tags = post.tags.join(" ");
|
||||
|
||||
commands.each(function(x) {
|
||||
post.tags = TagScript.process(post.tags, x);
|
||||
})
|
||||
|
||||
Post.update(post_id, {"post[old_tags]": old_tags, "post[tags]": post.tags.join(" ")});
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
$("#mode-box select").click(PostModeMenu.change);
|
||||
PostModeMenu.init();
|
||||
});
|
||||
13
public/javascripts/src/app/uploads.js
Normal file
13
public/javascripts/src/app/uploads.js
Normal file
@@ -0,0 +1,13 @@
|
||||
$(document).ready(function() {
|
||||
var img = $("#image-preview img");
|
||||
if (img) {
|
||||
var height = img.attr("height");
|
||||
var width = img.attr("width");
|
||||
if (height > 400) {
|
||||
var ratio = 400.0 / height;
|
||||
img.attr("height", height * ratio);
|
||||
img.attr("width", width * ratio);
|
||||
$("#scale").val("Scaled " + parseInt(100 * ratio) + "%");
|
||||
}
|
||||
}
|
||||
});
|
||||
13
public/javascripts/src/app/users.js
Normal file
13
public/javascripts/src/app/users.js
Normal file
@@ -0,0 +1,13 @@
|
||||
$(document).ready(function() {
|
||||
$("footer.nav-links a").click(function(event) {
|
||||
$("div#users-new > div").hide();
|
||||
$(event.target.hash).show();
|
||||
});
|
||||
|
||||
if ($("meta[name=errors]").attr("content")) {
|
||||
$("#p1").hide();
|
||||
$("#notice").hide();
|
||||
} else {
|
||||
$("#p2").hide();
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user