From 0fc71b326f5961e82a2cb9bca5bfce92ec84af4e Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Aug 28 2015 02:22:23 +0000 Subject: [PATCH 1/2] Fix showing the comment's preview on the pull-request page --- diff --git a/pagure/templates/pull_request.html b/pagure/templates/pull_request.html index fd0c6c7..80cb23e 100644 --- a/pagure/templates/pull_request.html +++ b/pagure/templates/pull_request.html @@ -384,17 +384,42 @@ ); $( ".tabs" ).tabs({ - activate: function( event, ui ) { - var _title = ui.newPanel.attr('id'); - if ($.inArray( _title, [ "request_diff", "commit_list" ] ) >= 0) { - window.location.hash = _title; - } + activate: function( event, ui ) { + var _title = ui.newPanel.attr('id'); + if ($.inArray( _title, [ "request_diff", "commit_list" ] ) >= 0) { + window.location.hash = _title; } + } }); {% if pull_request %} {# These lines are only for existing pull-requests, not new ones #} + $( ".tabs" ).on('tabsactivate', + function(event, ui) { + if (ui.newPanel.selector == '#preview') { + var _text = $( "#comment" ).val(); + var _url = "{{ url_for('markdown_preview') }}"; + $.ajax({ + url: _url , + type: 'POST', + data: { + content: _text, + csrf_token: "{{ mergeform.csrf_token.current_token }}", + }, + dataType: 'html', + success: function(res) { + $( "#preview" ).html(emojione.toImage(res)); + }, + error: function() { + alert('Unable to generate preview!'); + } + }); + return false; + } + } + ); + emoji_complete(json_url, folder); $('#cancel_pr').click(function(){ From 939f4f066e7409a1846db0031803fa1c8b803582 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Aug 28 2015 08:43:58 +0000 Subject: [PATCH 2/2] Remove duplication in the code --- diff --git a/pagure/templates/pull_request.html b/pagure/templates/pull_request.html index 80cb23e..e78b1e9 100644 --- a/pagure/templates/pull_request.html +++ b/pagure/templates/pull_request.html @@ -395,31 +395,6 @@ {% if pull_request %} {# These lines are only for existing pull-requests, not new ones #} - $( ".tabs" ).on('tabsactivate', - function(event, ui) { - if (ui.newPanel.selector == '#preview') { - var _text = $( "#comment" ).val(); - var _url = "{{ url_for('markdown_preview') }}"; - $.ajax({ - url: _url , - type: 'POST', - data: { - content: _text, - csrf_token: "{{ mergeform.csrf_token.current_token }}", - }, - dataType: 'html', - success: function(res) { - $( "#preview" ).html(emojione.toImage(res)); - }, - error: function() { - alert('Unable to generate preview!'); - } - }); - return false; - } - } - ); - emoji_complete(json_url, folder); $('#cancel_pr').click(function(){ @@ -468,7 +443,7 @@ } ); - $( "#comment" ).on('tabsactivate', + $( ".tabs" ).on('tabsactivate', function(event, ui) { if (ui.newPanel.selector == '#preview') { var _text = $( "#comment" ).val();