diff --git a/resources/celerity/map.php b/resources/celerity/map.php --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -396,6 +396,7 @@ 'rsrc/js/application/dashboard/behavior-dashboard-move-panels.js' => '019f36c4', 'rsrc/js/application/dashboard/behavior-dashboard-query-panel-select.js' => '453c5375', 'rsrc/js/application/dashboard/behavior-dashboard-tab-panel.js' => 'd4eecc63', + 'rsrc/js/application/diff/behavior-preview-link.js' => '051c7832', 'rsrc/js/application/differential/ChangesetViewManager.js' => 'a2828756', 'rsrc/js/application/differential/DifferentialInlineCommentEditor.js' => '2e3f9738', 'rsrc/js/application/differential/behavior-add-reviewers-and-ccs.js' => 'e10f8e18', @@ -453,7 +454,7 @@ 'rsrc/js/application/search/behavior-reorder-profile-menu-items.js' => 'e2e0a072', 'rsrc/js/application/search/behavior-reorder-queries.js' => 'e9581f08', 'rsrc/js/application/slowvote/behavior-slowvote-embed.js' => '887ad43f', - 'rsrc/js/application/transactions/behavior-comment-actions.js' => 'c23ecb0b', + 'rsrc/js/application/transactions/behavior-comment-actions.js' => '47a3ff3a', 'rsrc/js/application/transactions/behavior-reorder-configs.js' => 'd7a74243', 'rsrc/js/application/transactions/behavior-reorder-fields.js' => 'b59e1e96', 'rsrc/js/application/transactions/behavior-show-older-transactions.js' => '94c65b72', @@ -609,7 +610,7 @@ 'javelin-behavior-bulk-job-reload' => 'edf8a145', 'javelin-behavior-calendar-month-view' => 'fe33e256', 'javelin-behavior-choose-control' => '327a00d1', - 'javelin-behavior-comment-actions' => 'c23ecb0b', + 'javelin-behavior-comment-actions' => '47a3ff3a', 'javelin-behavior-config-reorder-fields' => 'b6993408', 'javelin-behavior-conpherence-menu' => '7524fcfa', 'javelin-behavior-conpherence-participant-pane' => '8604caa8', @@ -625,6 +626,7 @@ 'javelin-behavior-desktop-notifications-control' => 'edd1ba66', 'javelin-behavior-detect-timezone' => '4c193c96', 'javelin-behavior-device' => 'bb1dd507', + 'javelin-behavior-diff-preview-link' => '051c7832', 'javelin-behavior-differential-add-reviewers-and-ccs' => 'e10f8e18', 'javelin-behavior-differential-comment-jump' => '4fdb476d', 'javelin-behavior-differential-diff-radios' => 'e1ff79b1', @@ -944,6 +946,11 @@ 'javelin-dom', 'phabricator-keyboard-shortcut', ), + '051c7832' => array( + 'javelin-behavior', + 'javelin-stratcom', + 'javelin-dom', + ), '05270951' => array( 'javelin-util', 'javelin-magical-init', @@ -1233,6 +1240,15 @@ 'javelin-view-renderer', 'javelin-install', ), + '47a3ff3a' => array( + 'javelin-behavior', + 'javelin-stratcom', + 'javelin-workflow', + 'javelin-dom', + 'phuix-form-control-view', + 'phuix-icon-view', + 'javelin-behavior-phabricator-gesture', + ), '47c794d8' => array( 'javelin-install', 'javelin-dom', @@ -1947,15 +1963,6 @@ 'javelin-install', 'javelin-dom', ), - 'c23ecb0b' => array( - 'javelin-behavior', - 'javelin-stratcom', - 'javelin-workflow', - 'javelin-dom', - 'phuix-form-control-view', - 'phuix-icon-view', - 'javelin-behavior-phabricator-gesture', - ), 'c587b80f' => array( 'javelin-install', ), diff --git a/src/infrastructure/diff/view/PHUIDiffInlineCommentPreviewListView.php b/src/infrastructure/diff/view/PHUIDiffInlineCommentPreviewListView.php --- a/src/infrastructure/diff/view/PHUIDiffInlineCommentPreviewListView.php +++ b/src/infrastructure/diff/view/PHUIDiffInlineCommentPreviewListView.php @@ -28,6 +28,14 @@ public function render() { $viewer = $this->getViewer(); + $config = array( + 'pht' => array( + 'view' => pht('View'), + ), + ); + + Javelin::initBehavior('diff-preview-link', $config); + $inlines = $this->getInlineComments(); foreach ($inlines as $key => $inline) { $inlines[$key] = DifferentialInlineComment::newFromModernComment( diff --git a/webroot/rsrc/js/application/diff/behavior-preview-link.js b/webroot/rsrc/js/application/diff/behavior-preview-link.js new file mode 100644 --- /dev/null +++ b/webroot/rsrc/js/application/diff/behavior-preview-link.js @@ -0,0 +1,36 @@ +/** + * @provides javelin-behavior-diff-preview-link + * @requires javelin-behavior + * javelin-stratcom + * javelin-dom + */ + +JX.behavior('diff-preview-link', function(config, statics) { + if (statics.initialized) { + return; + } + statics.initialized = true; + + var pht = JX.phtize(config.pht); + + // After inline comment previews are rendered, hook up the links to the + // comments that are visible on the current page. + function link_inline_preview(e) { + var root = e.getData().rootNode; + var links = JX.DOM.scry(root, 'a', 'differential-inline-preview-jump'); + + for (var ii = 0; ii < links.length; ii++) { + var data = JX.Stratcom.getData(links[ii]); + try { + JX.$(data.anchor); + links[ii].href = '#' + data.anchor; + JX.DOM.setContent(links[ii], pht('view')); + } catch (ignored) { + // This inline comment isn't visible, e.g. on some other diff. + } + } + + } + + JX.Stratcom.listen('EditEngine.didCommentPreview', null, link_inline_preview); +}); diff --git a/webroot/rsrc/js/application/transactions/behavior-comment-actions.js b/webroot/rsrc/js/application/transactions/behavior-comment-actions.js --- a/webroot/rsrc/js/application/transactions/behavior-comment-actions.js +++ b/webroot/rsrc/js/application/transactions/behavior-comment-actions.js @@ -147,13 +147,27 @@ if (!response.xactions.length) { JX.DOM.hide(panel); } else { + var preview_root = JX.$(config.timelineID); JX.DOM.setContent( - JX.$(config.timelineID), + preview_root, [ JX.$H(response.xactions.join('')), JX.$H(response.previewContent) ]); JX.DOM.show(panel); + + // NOTE: Resonses are currently processed before associated behaviors are + // registered. We need to defer invoking this event so that any behaviors + // accompanying the response are registered. + var invoke_preview = function() { + JX.Stratcom.invoke( + 'EditEngine.didCommentPreview', + null, + { + rootNode: preview_root + }); + }; + setTimeout(invoke_preview, 0); } }