allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [07/10] allura git commit: [#8253] Adding reaction scripts to base
Date Thu, 08 Nov 2018 21:53:48 GMT
[#8253] Adding reaction scripts to base


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/919f146a
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/919f146a
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/919f146a

Branch: refs/heads/master
Commit: 919f146ad42e50ce46292ad46ea3c7f525071b19
Parents: 73490b0
Author: Shalitha <shalithasuranga@gmail.com>
Authored: Tue Oct 30 22:05:34 2018 +0530
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Thu Nov 8 21:53:25 2018 +0000

----------------------------------------------------------------------
 Allura/allura/public/nf/js/allura-base.js | 69 ++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/919f146a/Allura/allura/public/nf/js/allura-base.js
----------------------------------------------------------------------
diff --git a/Allura/allura/public/nf/js/allura-base.js b/Allura/allura/public/nf/js/allura-base.js
index b59fbe2..87b414f 100644
--- a/Allura/allura/public/nf/js/allura-base.js
+++ b/Allura/allura/public/nf/js/allura-base.js
@@ -254,3 +254,72 @@ $(function(){
         });
     });
 });
+
+// Reaction support
+$(function(){
+
+    $('.reaction-button').tooltipster({
+        animation: 'fade',
+        delay: 200,
+        theme: 'tooltipster-default',
+        trigger: 'click',
+        position: 'top',
+        iconCloning: false,
+        maxWidth: 400,
+        contentAsHTML: true,
+        interactive: true
+    });
+
+    $('.reaction-button').each(function() {
+        var btnId = $(this).attr('id');
+        $(this).click(function(e) {
+            e.preventDefault();
+            var tooltiptext = `
+            <div class="post-reactions-list">
+                <span onclick="reactComment('` + btnId  + `', 'thumbs_up')"><img
draggable="false" class="emoji" alt="👍" src="https://twemoji.maxcdn.com/2/72x72/1f44d.png"></span>
+                <span onclick="reactComment('` + btnId  + `', 'thumbs_down')"><img
draggable="false" class="emoji" alt="👎" src="https://twemoji.maxcdn.com/2/72x72/1f44e.png"></span>
+                <span onclick="reactComment('` + btnId  + `', 'laugh')"><img draggable="false"
class="emoji" alt="😃" src="https://twemoji.maxcdn.com/2/72x72/1f603.png"></span>
+                <span onclick="reactComment('` + btnId  + `', 'hooray')"><img draggable="false"
class="emoji" alt="🎉" src="https://twemoji.maxcdn.com/2/72x72/1f389.png"></span>
+                <span onclick="reactComment('` + btnId  + `', 'confused')"><img
draggable="false" class="emoji" alt="😕" src="https://twemoji.maxcdn.com/2/72x72/1f615.png"></span>
+                <span onclick="reactComment('` + btnId  + `', 'heart')"><img draggable="false"
class="emoji" alt="❤" src="https://twemoji.maxcdn.com/2/72x72/2764.png"></span>
+            </div>
+            `;
+            $(this).tooltipster('content', tooltiptext);
+            $(this).tooltipster('show');
+        });
+    });
+
+
+});
+
+function reactComment(btnId ,r) {
+    var btn = $('#' + btnId);
+    var reacts_list = btn.closest('.post-content').find('.reactions');
+    $.ajax({
+        type: 'post',
+        url: btn.data('commentlink') + 'post_reaction',
+        data: {
+            'r' : r,
+            '_session_id' : $.cookie('_session_id')
+        },
+        success: function(res) {
+            var react_html = '';
+            if(res.react_thumbs_up > 0) 
+                react_html += '<span>👍</span> ' + res.react_thumbs_up;
+            if(res.react_thumbs_down > 0) 
+                react_html += '<span>👎</span> ' + res.react_thumbs_down;
+            if(res.react_laugh > 0) 
+                react_html += '<span>😄</span> ' + res.react_laugh;
+            if(res.react_hooray > 0) 
+                react_html += '<span>🎉</span> ' + res.react_hooray;
+            if(res.react_confused > 0) 
+                react_html += '<span>😕</span> ' + res.react_confused;
+            if(res.react_heart > 0) 
+                react_html += '<span>❤</span> ' + res.react_heart;
+            
+            reacts_list.html(react_html);
+            twemoji.parse(reacts_list[0]);
+            btn.tooltipster('hide');
+        }
+    });
+}
\ No newline at end of file


Mime
View raw message