作者:杨艳奎_718 | 来源:互联网 | 2023-05-19 11:40
Githubhasareallynicesourcebrowser.Navigatingbetweendifferentpathsintherepogeneratesaj
Github has a really nice source browser. Navigating between different paths in the repo generates ajax calls to load the content (as you can clearly see in the firebug log). The ajax call returns the html of the new list of files to be displayed. In addition to changing the view list of files, the url changes as well. However it does not use fragments like most ajax deep-linked sites (use of #). At github the whole url changes.
Github有一个很棒的源浏览器。在repo中的不同路径之间导航会生成ajax调用来加载内容(您可以在firebug日志中清楚地看到)。ajax调用返回要显示的新文件列表的html。除了更改文件的视图列表之外,url也会更改。但是它不像大多数ajax深层链接站点那样使用片段(使用#)。在github上,整个url都变了。
For example at django repo at https://github.com/django/django going to django
folder will generate ajax request to https://github.com/django/django/tree/master/django?slide=1&_=1327709883334
which will return the html content of the folder. The link will also change to https://github.com/django/django/tree/master/django. As you can see this new link does not use a fragment.
例如,在django repo上(https://github.com/django/django去django文件夹),将生成对https://github.com/django/django/tree/master/django?幻灯片=1&_=1327709883334将返回文件夹的html内容。该链接还将更改为https://github.com/django/django/tree/master/django。正如您所看到的,这个新链接不使用片段。
How is that done? I always thought that ajax based sites have to use url fragments (#) to achieve deep linking but apparently it is not so.
是怎么做到的呢?我一直认为基于ajax的站点必须使用url片段(#)来实现深度链接,但显然不是这样。
2 个解决方案
4
Well, as was described in the comments by Dav, it appears that GitHub does not use the pAjax library. Due to the fact that I ended up answering with an "incorrect" information (actually I think I had seen something related to GitHub using pAjax when I was answering this question, but at the moment I can not find the source), I went after the correct answer.
正如Dav注释中描述的那样,GitHub似乎并不使用pAjax库。由于我最终回答了一个“不正确”的信息(实际上我认为我在回答这个问题的时候看到了一些与GitHub有关的东西,但是当时我找不到来源),我就去寻找正确的答案。
I did not find anything official on the part of developers regarding whether any library was used, only found a post saying that the History API was used: https://github.com/blog/760-the-tree-slider
关于是否使用了任何库,我没有找到任何开发人员的官方信息,只是找到了一个帖子,说使用了History API: https://github.com/blog/760thetree -slider
Then came to my head, why not ask the code itself?
然后来到我的脑海,为什么不问问代码本身呢?
Using Chrome (in reality any browser with a decent developer tools), open a repository (in this case, pAjax), right-clicking on any directory, simply choose inspect element.
使用Chrome(实际上是任何拥有优秀开发工具的浏览器),打开一个存储库(在本例中是pAjax),右键单击任何目录,只需选择inspect元素。
This will display the a
element responsible for the directory link.
这将显示负责目录链接的a元素。
A "suspect" class showed up, let's search for it on the Javascript source of the page.
出现了一个“可疑”类,让我们在页面的Javascript源上搜索它。
And here it's, the click event handler for the directory link, in addition to the entire code related to the animation and the History Api. And as can be noted, it's not used any library behind the History Api. Don't forget to mark the Pretty Print option.
这里是目录链接的单击事件处理程序,以及与动画和历史Api相关的整个代码。可以指出,它没有使用历史Api背后的任何库。不要忘记标记漂亮的打印选项。
Old and incorrect answer
GitHub uses the jQuery plugin
pJax (pushState + Ajax), which uses the HTML5 history API.
GitHub使用jQuery插件pJax (pushState + Ajax),该插件使用HTML5 history API。