Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //* TITLE Comments **//
- //* VERSION 0.0.1 **//
- //* DESCRIPTION Leave a comment on a Tumblr post. **//
- //* DETAILS This extension allows you to comment on original posts on your dashboard. **//
- //* DEVELOPER wolfspirals **//
- //* FRAME false **//
- //* BETA false **//
- //* SLOW true **//
- XKit.extensions.comments = new Object({
- running: false,
- slow: true,
- run: function() {
- this.running = true;
- XKit.tools.init_css("timestamps");
- try {
- if (this.is_compatible()) {
- XKit.tools.add_css('#posts .post .post_content { padding-top: 0px; }', "timestamps");
- XKit.post_listener.add("comments", this.add_commenters);
- this.add_commenters();
- $(document).on("submit",".reply form", XKit.extensions.comments.submit_comment);
- }
- } catch(e) {
- show_error_script("Comments: " + e.message);
- }
- },
- is_compatible: function() {
- return !(XKit.interface.where().queue || XKit.interface.where().drafts || XKit.interface.where().search || XKit.interface.where().inbox);
- },
- add_commenters: function() {
- var posts = $(".posts .post.is_original").not(".xkit_comments");
- if (posts.length === 0) {
- return;
- }
- posts.each(function() {
- var post = $(this);
- post.addClass("xkit_comments");
- var post_id = post.attr('data-post-id');
- var key = post.attr('data-tumblelog-key');
- var commentbox_html = '<div class="post_control reply" title="Reply"><div class="popover popover_gradient popover_post_tools" style="display: none;"><div class="popover_inner"><form action="https://tumblr.com/reply"><textarea name="reply_text" maxlength="250" title="250 max" style="background-image: none; background-position: 0% 0%; background-repeat: repeat;"></textarea><button type="submit" class="chrome blue" data-label-loading="Replying..." data-label="Reply" style="width:100%" disabled="disabled">Reply</button></form></div></div></div>';
- post.find(".post_controls_inner").append(commentbox_html);
- });
- },
- submit_comment: function(e) {
- e.preventDefault();
- var comment_form = $(this);
- $.ajax({
- type: "POST",
- url: "/reply",
- data: {
- reply_text: " " + comment_form.find("textarea").get(0).value,
- post_id: comment_form.parents(".post").attr("data-post-id"),
- key: comment_form.parents(".post").attr("data-tumblelog-key")
- },
- cache: true,
- dataType: "jsonp",
- crossDomain: true,
- jsonp: false,
- jsonpCallback: function() {
- setTimeout(XKit.extensions.comments.click_dialog, 10);
- }
- });
- },
- click_dialog: function(){
- if($(".ui_dialog_pos").length > 0) {
- $(".ui_dialog_pos button").click();
- $(".ui_dialog_lock").hide();
- var reply = $(".reply.active");
- reply.removeClass("active");
- reply.find(".popover").css("display", "none");
- reply.find("form textarea").val("");
- reply.find("form button").text("Reply");
- } else {
- setTimeout(XKit.extensions.comments.click_dialog, 10);
- }
- },
- destroy: function() {
- this.running = false;
- $(".reply").remove();
- $(".xkit_comments").removeClass("xkit_comments");
- XKit.tools.remove_css("comments");
- XKit.post_listener.remove("comments");
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement