allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [allura] 01/02: [#8280] move post JS from a .py file to .js file
Date Tue, 30 Apr 2019 17:59:12 GMT
This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch db/8280
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 7f26735fd0dec8014ca9283649d66369217f3bf0
Author: Dave Brondsema <dave@brondsema.net>
AuthorDate: Fri Apr 26 17:03:43 2019 -0400

    [#8280] move post JS from a .py file to .js file
---
 Allura/allura/lib/widgets/discuss.py           | 114 +---------------------
 Allura/allura/lib/widgets/resources/js/post.js | 130 +++++++++++++++++++++++++
 2 files changed, 131 insertions(+), 113 deletions(-)

diff --git a/Allura/allura/lib/widgets/discuss.py b/Allura/allura/lib/widgets/discuss.py
index 6918196..f988418 100644
--- a/Allura/allura/lib/widgets/discuss.py
+++ b/Allura/allura/lib/widgets/discuss.py
@@ -321,119 +321,7 @@ class Post(HierWidget):
         }
         ''')
         yield ew.JSLink('js/jquery.lightbox_me.js')
-        yield ew.JSScript('''
-        (function () {
-            $('div.discussion-post').each(function () {
-                var post = this;
-                $('.moderate_post', post).click(function(e){
-                    e.preventDefault();
-                    var mod = $(this).text();
-
-                    if ($(this).hasClass('delete')) mod = 'Delete';
-                    else if ($(this).hasClass('approve')) mod = 'Approve';
-                    else if ($(this).hasClass('spam')) mod = 'Spam';
-                    else if ($(this).hasClass('undo')) mod = 'Undo';
-
-
-                    if (mod === 'Delete' && !confirm('Really delete this post?'))
{
-                        return;
-                    }
-                    $.ajax({
-                        type: 'POST',
-                        url: this.parentNode.action,
-                        data: jQuery(this.parentNode).serialize(),
-                        success: function() {
-                            if (mod === 'Delete'){
-                                $(post).remove();
-                            }
-                            else if (mod === 'Approve'){
-                                $('a.shortlink, form.moderate_spam, form.moderate_approve',
post).toggle();
-                                $('div.moderate', post).removeClass('moderate');
-                            }
-                            else if (mod == 'Spam'){
-                                spam_block_display($(post), 'show_spam');
-                            }
-                            else if (mod == 'Undo'){
-                                spam_block_display($(post), 'hide_spam');
-                            }
-                        }
-                    });
-                });
-
-                function spam_block_display($post, display_type) {
-                    var spam_block = $post.find('.info.grid-15.spam-present');
-                    var row = $post.find('.comment-row').eq(0);
-
-                    if (display_type == 'show_spam') {
-                        spam_block.show();
-                        row.hide();
-                    } else if (display_type == 'hide_spam') {
-                        spam_block.hide();
-                        row.show();
-                    }
-                }
-
-                if($('a.edit_post', post)){
-                    $('a.edit_post', post).click(function (evt) {
-                        evt.preventDefault();
-                        $('.display_post', post).hide();
-
-                        // remove the options column, but have to adjust the width of the
middle section which is
-                        // already hard-coded
-                        var $opts = $('.options:first', post);
-                        var opts_width = $opts.outerWidth(true);
-                        $opts.hide();
-                        var $post_middle = $('div.grid-14:first', post);
-                        $post_middle.data('original-width', $post_middle.width());
-                        $post_middle.width($post_middle.width() + opts_width);
-
-                        var $edit_post_form = $('.edit_post_form', post);
-                        var cm = get_cm($edit_post_form);
-                        $edit_post_form.show();
-                        cm.refresh();
-                        cm.focus();
-                    });
-                    $("a.cancel_edit_post", post).click(function(evt){
-                        $('.display_post', post).show();
-                        $('.options', post).show();
-                        $('.edit_post_form', post).hide();
-                        var $post_middle = $('div.grid-14:first', post);
-                        $post_middle.width($post_middle.data('original-width'));
-                    });
-                }
-                if($('.reply_post', post)){
-                    $('.reply_post', post).click(function (evt) {
-                        evt.preventDefault();
-                        var $reply_post_form = $('.reply_post_form', post);
-                        var cm = get_cm($reply_post_form);
-                        $reply_post_form.show();
-                        cm.focus();
-                        $('form', $reply_post_form).trigger('replyRevealed');
-                    });
-                }
-                if($('.add_attachment', post)){
-                    $('.add_attachment', post).click(function (evt) {
-                        evt.preventDefault();
-                        $('.add_attachment_form', post).show();
-                    });
-                }
-                if($('.shortlink', post)){
-                    var popup = $('.shortlink_popup', post);
-                    $('.shortlink', post).click(function(evt){
-                        evt.preventDefault();
-                        popup.lightbox_me({
-                            onLoad: function() {
-                                $('input', popup).select();
-                            }
-                        });
-                    });
-                    $('.close', popup).bind('click', function() {
-                        popup.hide();
-                    });
-                }
-            });
-        }());
-        ''')
+        yield ew.JSLink('js/post.js')
 
 
 class PostThread(ew_core.Widget):
diff --git a/Allura/allura/lib/widgets/resources/js/post.js b/Allura/allura/lib/widgets/resources/js/post.js
new file mode 100644
index 0000000..0a47a48
--- /dev/null
+++ b/Allura/allura/lib/widgets/resources/js/post.js
@@ -0,0 +1,130 @@
+/*
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+ */
+
+(function () {
+    $('div.discussion-post').each(function () {
+        var post = this;
+        $('.moderate_post', post).click(function(e){
+            e.preventDefault();
+            var mod = $(this).text();
+
+            if ($(this).hasClass('delete')) mod = 'Delete';
+            else if ($(this).hasClass('approve')) mod = 'Approve';
+            else if ($(this).hasClass('spam')) mod = 'Spam';
+            else if ($(this).hasClass('undo')) mod = 'Undo';
+
+
+            if (mod === 'Delete' && !confirm('Really delete this post?')) {
+                return;
+            }
+            $.ajax({
+                type: 'POST',
+                url: this.parentNode.action,
+                data: jQuery(this.parentNode).serialize(),
+                success: function() {
+                    if (mod === 'Delete'){
+                        $(post).remove();
+                    }
+                    else if (mod === 'Approve'){
+                        $('a.shortlink, form.moderate_spam, form.moderate_approve', post).toggle();
+                        $('div.moderate', post).removeClass('moderate');
+                    }
+                    else if (mod == 'Spam'){
+                        spam_block_display($(post), 'show_spam');
+                    }
+                    else if (mod == 'Undo'){
+                        spam_block_display($(post), 'hide_spam');
+                    }
+                }
+            });
+        });
+
+        function spam_block_display($post, display_type) {
+            var spam_block = $post.find('.info.grid-15.spam-present');
+            var row = $post.find('.comment-row').eq(0);
+
+            if (display_type == 'show_spam') {
+                spam_block.show();
+                row.hide();
+            } else if (display_type == 'hide_spam') {
+                spam_block.hide();
+                row.show();
+            }
+        }
+
+        if($('a.edit_post', post)){
+            $('a.edit_post', post).click(function (evt) {
+                evt.preventDefault();
+                $('.display_post', post).hide();
+
+                // remove the options column, but have to adjust the width of the middle
section which is
+                // already hard-coded
+                var $opts = $('.options:first', post);
+                var opts_width = $opts.outerWidth(true);
+                $opts.hide();
+                var $post_middle = $('div.grid-14:first', post);
+                $post_middle.data('original-width', $post_middle.width());
+                $post_middle.width($post_middle.width() + opts_width);
+
+                var $edit_post_form = $('.edit_post_form', post);
+                var cm = get_cm($edit_post_form);
+                $edit_post_form.show();
+                cm.refresh();
+                cm.focus();
+            });
+            $("a.cancel_edit_post", post).click(function(evt){
+                $('.display_post', post).show();
+                $('.options', post).show();
+                $('.edit_post_form', post).hide();
+                var $post_middle = $('div.grid-14:first', post);
+                $post_middle.width($post_middle.data('original-width'));
+            });
+        }
+        if($('.reply_post', post)){
+            $('.reply_post', post).click(function (evt) {
+                evt.preventDefault();
+                var $reply_post_form = $('.reply_post_form', post);
+                var cm = get_cm($reply_post_form);
+                $reply_post_form.show();
+                cm.focus();
+                $('form', $reply_post_form).trigger('replyRevealed');
+            });
+        }
+        if($('.add_attachment', post)){
+            $('.add_attachment', post).click(function (evt) {
+                evt.preventDefault();
+                $('.add_attachment_form', post).show();
+            });
+        }
+        if($('.shortlink', post)){
+            var popup = $('.shortlink_popup', post);
+            $('.shortlink', post).click(function(evt){
+                evt.preventDefault();
+                popup.lightbox_me({
+                    onLoad: function() {
+                        $('input', popup).select();
+                    }
+                });
+            });
+            $('.close', popup).bind('click', function() {
+                popup.hide();
+            });
+        }
+    });
+}());
\ No newline at end of file


Mime
View raw message