| 
									
										
										
										
											2011-09-06 11:35:14 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @provides javelin-behavior-repository-crossreference | 
					
						
							|  |  |  |  * @requires javelin-behavior | 
					
						
							|  |  |  |  *           javelin-dom | 
					
						
							| 
									
										
										
										
											2012-09-17 14:50:49 -07:00
										 |  |  |  *           javelin-stratcom | 
					
						
							| 
									
										
										
										
											2011-09-06 11:35:14 -07:00
										 |  |  |  *           javelin-uri | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-28 15:32:58 -07:00
										 |  |  | JX.behavior('repository-crossreference', function(config, statics) { | 
					
						
							| 
									
										
										
										
											2011-09-06 11:35:14 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-28 15:32:58 -07:00
										 |  |  |   var highlighted; | 
					
						
							|  |  |  |   var linked = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   var isMac = navigator.platform.indexOf('Mac') > -1; | 
					
						
							|  |  |  |   var signalKey = isMac ? 91 /*COMMAND*/ : 17 /*CTRL*/; | 
					
						
							|  |  |  |   function isSignalkey(event) { | 
					
						
							|  |  |  |     return isMac ? | 
					
						
							|  |  |  |       event.getRawEvent().metaKey : | 
					
						
							|  |  |  |       event.getRawEvent().ctrlKey; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   var classHighlight = 'crossreference-item'; | 
					
						
							|  |  |  |   var classMouseCursor = 'crossreference-cursor'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // TODO maybe move the dictionary part of this list to the server?
 | 
					
						
							|  |  |  |   var class_map = { | 
					
						
							|  |  |  |     nc : 'class', | 
					
						
							|  |  |  |     nf : 'function', | 
					
						
							|  |  |  |     na : null, | 
					
						
							|  |  |  |     nb : 'builtin', | 
					
						
							|  |  |  |     n : null, | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2011-09-06 11:35:14 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
											
												Support symbol linking in Remarkup code blocks
Summary:
Trigger the crossreference behavior on code blocks. Limited to
Differential, where we know what the project is, but includes regular
comments, inline comments, and previews of both.
(Hopefully event handlers on deleted elements also get deleted, so we
don't leak memory? Also, caching is a problem, and I didn't find a way
to mark existing cache entries as stale, like
`DifferentialChangesetParser::CACHE_VERSION`...)
Test Plan:
Load Differential revision, make lots of comments, click on
things.
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin
Maniphest Tasks: T1602
Differential Revision: https://secure.phabricator.com/D3283
											
										 
											2012-08-14 14:03:26 -07:00
										 |  |  |   function link(element, lang) { | 
					
						
							|  |  |  |     JX.DOM.alterClass(element, 'repository-crossreference', true); | 
					
						
							| 
									
										
										
										
											2015-05-28 15:32:58 -07:00
										 |  |  |     linked.push(element); | 
					
						
							| 
									
										
										
											
												Support symbol linking in Remarkup code blocks
Summary:
Trigger the crossreference behavior on code blocks. Limited to
Differential, where we know what the project is, but includes regular
comments, inline comments, and previews of both.
(Hopefully event handlers on deleted elements also get deleted, so we
don't leak memory? Also, caching is a problem, and I didn't find a way
to mark existing cache entries as stale, like
`DifferentialChangesetParser::CACHE_VERSION`...)
Test Plan:
Load Differential revision, make lots of comments, click on
things.
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin
Maniphest Tasks: T1602
Differential Revision: https://secure.phabricator.com/D3283
											
										 
											2012-08-14 14:03:26 -07:00
										 |  |  |     JX.DOM.listen( | 
					
						
							|  |  |  |       element, | 
					
						
							| 
									
										
										
										
											2015-05-28 15:32:58 -07:00
										 |  |  |       ['mouseover', 'mouseout', 'click'], | 
					
						
							| 
									
										
										
											
												Support symbol linking in Remarkup code blocks
Summary:
Trigger the crossreference behavior on code blocks. Limited to
Differential, where we know what the project is, but includes regular
comments, inline comments, and previews of both.
(Hopefully event handlers on deleted elements also get deleted, so we
don't leak memory? Also, caching is a problem, and I didn't find a way
to mark existing cache entries as stale, like
`DifferentialChangesetParser::CACHE_VERSION`...)
Test Plan:
Load Differential revision, make lots of comments, click on
things.
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin
Maniphest Tasks: T1602
Differential Revision: https://secure.phabricator.com/D3283
											
										 
											2012-08-14 14:03:26 -07:00
										 |  |  |       'tag:span', | 
					
						
							|  |  |  |       function(e) { | 
					
						
							| 
									
										
										
										
											2015-05-28 15:32:58 -07:00
										 |  |  |         if (e.getType() === 'mouseout') { | 
					
						
							| 
									
										
										
										
											2015-08-27 04:15:40 -07:00
										 |  |  |           unhighlight(); | 
					
						
							| 
									
										
										
										
											2015-05-28 15:32:58 -07:00
										 |  |  |           return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (!isSignalkey(e)) { | 
					
						
							|  |  |  |           return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (e.getType() === 'mouseover') { | 
					
						
							|  |  |  |           var target = e.getTarget(); | 
					
						
							|  |  |  |           while (target !== document.body) { | 
					
						
							|  |  |  |             if (JX.DOM.isNode(target, 'span') && | 
					
						
							|  |  |  |                (target.className in class_map)) { | 
					
						
							|  |  |  |               highlighted = target; | 
					
						
							|  |  |  |               JX.DOM.alterClass(highlighted, classHighlight, true); | 
					
						
							|  |  |  |               break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             target = target.parentNode; | 
					
						
							| 
									
										
										
										
											2012-08-09 15:19:02 -07:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2015-05-28 15:32:58 -07:00
										 |  |  |         } else if (e.getType() === 'click') { | 
					
						
							| 
									
										
										
										
											2015-08-27 04:17:33 -07:00
										 |  |  |           openSearch(e.getTarget(), lang); | 
					
						
							| 
									
										
										
										
											2012-07-31 17:01:57 -07:00
										 |  |  |         } | 
					
						
							| 
									
										
										
											
												Support symbol linking in Remarkup code blocks
Summary:
Trigger the crossreference behavior on code blocks. Limited to
Differential, where we know what the project is, but includes regular
comments, inline comments, and previews of both.
(Hopefully event handlers on deleted elements also get deleted, so we
don't leak memory? Also, caching is a problem, and I didn't find a way
to mark existing cache entries as stale, like
`DifferentialChangesetParser::CACHE_VERSION`...)
Test Plan:
Load Differential revision, make lots of comments, click on
things.
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin
Maniphest Tasks: T1602
Differential Revision: https://secure.phabricator.com/D3283
											
										 
											2012-08-14 14:03:26 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-08-27 04:15:40 -07:00
										 |  |  |   function unhighlight() { | 
					
						
							|  |  |  |     highlighted && JX.DOM.alterClass(highlighted, classHighlight, false); | 
					
						
							|  |  |  |     highlighted = null; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
											
												Support symbol linking in Remarkup code blocks
Summary:
Trigger the crossreference behavior on code blocks. Limited to
Differential, where we know what the project is, but includes regular
comments, inline comments, and previews of both.
(Hopefully event handlers on deleted elements also get deleted, so we
don't leak memory? Also, caching is a problem, and I didn't find a way
to mark existing cache entries as stale, like
`DifferentialChangesetParser::CACHE_VERSION`...)
Test Plan:
Load Differential revision, make lots of comments, click on
things.
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin
Maniphest Tasks: T1602
Differential Revision: https://secure.phabricator.com/D3283
											
										 
											2012-08-14 14:03:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-28 15:32:58 -07:00
										 |  |  |   function openSearch(target, lang) { | 
					
						
							|  |  |  |     var symbol = target.textContent || target.innerText; | 
					
						
							|  |  |  |     var query = { | 
					
						
							|  |  |  |       lang : lang, | 
					
						
							|  |  |  |       repositories : config.repositories.join(','), | 
					
						
							|  |  |  |       jump : true | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     var c = target.className; | 
					
						
							|  |  |  |     c = c.replace(classHighlight, '').trim(); | 
					
						
							|  |  |  |     if (class_map[c]) { | 
					
						
							|  |  |  |       query.type = class_map[c]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (target.hasAttribute('data-symbol-context')) { | 
					
						
							|  |  |  |       query.context = target.getAttribute('data-symbol-context'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (target.hasAttribute('data-symbol-name')) { | 
					
						
							|  |  |  |       symbol = target.getAttribute('data-symbol-name'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     var uri = JX.$U('/diffusion/symbol/' + symbol + '/'); | 
					
						
							|  |  |  |     uri.addQueryParams(query); | 
					
						
							|  |  |  |     window.open(uri); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 03:27:47 +10:00
										 |  |  |   function linkAll() { | 
					
						
							| 
									
										
										
										
											2013-05-12 06:52:53 -07:00
										 |  |  |     var blocks = JX.DOM.scry(document.body, 'div', 'remarkup-code-block'); | 
					
						
							| 
									
										
										
											
												Support symbol linking in Remarkup code blocks
Summary:
Trigger the crossreference behavior on code blocks. Limited to
Differential, where we know what the project is, but includes regular
comments, inline comments, and previews of both.
(Hopefully event handlers on deleted elements also get deleted, so we
don't leak memory? Also, caching is a problem, and I didn't find a way
to mark existing cache entries as stale, like
`DifferentialChangesetParser::CACHE_VERSION`...)
Test Plan:
Load Differential revision, make lots of comments, click on
things.
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin
Maniphest Tasks: T1602
Differential Revision: https://secure.phabricator.com/D3283
											
										 
											2012-08-14 14:03:26 -07:00
										 |  |  |     for (var i = 0; i < blocks.length; ++i) { | 
					
						
							|  |  |  |       if (blocks[i].hasAttribute('data-code-lang')) { | 
					
						
							|  |  |  |         var lang = blocks[i].getAttribute('data-code-lang'); | 
					
						
							|  |  |  |         link(blocks[i], lang); | 
					
						
							| 
									
										
										
										
											2011-09-06 11:35:14 -07:00
										 |  |  |       } | 
					
						
							| 
									
										
										
											
												Support symbol linking in Remarkup code blocks
Summary:
Trigger the crossreference behavior on code blocks. Limited to
Differential, where we know what the project is, but includes regular
comments, inline comments, and previews of both.
(Hopefully event handlers on deleted elements also get deleted, so we
don't leak memory? Also, caching is a problem, and I didn't find a way
to mark existing cache entries as stale, like
`DifferentialChangesetParser::CACHE_VERSION`...)
Test Plan:
Load Differential revision, make lots of comments, click on
things.
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin
Maniphest Tasks: T1602
Differential Revision: https://secure.phabricator.com/D3283
											
										 
											2012-08-14 14:03:26 -07:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (config.container) { | 
					
						
							|  |  |  |     link(JX.$(config.container), config.lang); | 
					
						
							|  |  |  |   } else if (config.section) { | 
					
						
							|  |  |  |     linkAll(JX.$(config.section)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   JX.Stratcom.listen( | 
					
						
							|  |  |  |     'differential-preview-update', | 
					
						
							|  |  |  |     null, | 
					
						
							|  |  |  |     function(e) { | 
					
						
							|  |  |  |       linkAll(e.getData().container); | 
					
						
							| 
									
										
										
										
											2011-09-06 11:35:14 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-27 04:15:40 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-28 15:32:58 -07:00
										 |  |  |   JX.Stratcom.listen( | 
					
						
							|  |  |  |     ['keydown', 'keyup'], | 
					
						
							|  |  |  |     null, | 
					
						
							|  |  |  |     function(e) { | 
					
						
							|  |  |  |       if (e.getRawEvent().keyCode !== signalKey) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2015-08-27 04:15:40 -07:00
										 |  |  |       setCursorMode(e.getType() === 'keydown'); | 
					
						
							| 
									
										
										
										
											2015-05-28 15:32:58 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       if (!statics.active) { | 
					
						
							| 
									
										
										
										
											2015-08-27 04:15:40 -07:00
										 |  |  |         unhighlight(); | 
					
						
							| 
									
										
										
										
											2015-05-28 15:32:58 -07:00
										 |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-08-27 04:15:40 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   JX.Stratcom.listen( | 
					
						
							|  |  |  |     'blur', | 
					
						
							|  |  |  |     null, | 
					
						
							|  |  |  |     function(e) { | 
					
						
							|  |  |  |       if (e.getTarget()) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       unhighlight(); | 
					
						
							|  |  |  |       setCursorMode(false); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   function setCursorMode(active) { | 
					
						
							|  |  |  |     statics.active = active; | 
					
						
							|  |  |  |     linked.forEach(function(element) { | 
					
						
							|  |  |  |       JX.DOM.alterClass(element, classMouseCursor, statics.active); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-09-06 11:35:14 -07:00
										 |  |  | }); |