hexo-theme-volantis 4.3.1 → 5.0.0-alpha.112

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. package/README.md +6 -4
  2. package/_config.yml +599 -246
  3. package/languages/en.yml +7 -0
  4. package/languages/zh-CN.yml +13 -2
  5. package/languages/zh-TW.yml +7 -0
  6. package/layout/404.ejs +1 -1
  7. package/layout/_meta/author.ejs +4 -4
  8. package/layout/_meta/category.ejs +11 -8
  9. package/layout/_meta/counter.ejs +29 -7
  10. package/layout/_meta/date.ejs +1 -1
  11. package/layout/_meta/music.ejs +1 -1
  12. package/layout/_meta/share.ejs +1 -1
  13. package/layout/_meta/tags.ejs +3 -0
  14. package/layout/_meta/thumbnail.ejs +3 -1
  15. package/layout/_meta/updated.ejs +1 -1
  16. package/layout/_meta/walinecount.ejs +2 -1
  17. package/layout/{_cover → _partial/_cover}/blank.ejs +0 -0
  18. package/layout/{_cover → _partial/_cover}/dock.ejs +1 -1
  19. package/layout/{_cover → _partial/_cover}/featured.ejs +1 -1
  20. package/layout/{_cover → _partial/_cover}/focus.ejs +1 -1
  21. package/layout/_partial/_cover/layout.ejs +8 -0
  22. package/layout/{_cover → _partial/_cover}/search.ejs +2 -2
  23. package/layout/_partial/archive.ejs +2 -2
  24. package/layout/_partial/article.ejs +21 -16
  25. package/layout/_partial/categories.ejs +1 -1
  26. package/layout/_partial/cover.ejs +8 -28
  27. package/layout/_partial/footer.ejs +19 -11
  28. package/layout/_partial/head.ejs +70 -116
  29. package/layout/_partial/header.ejs +17 -11
  30. package/layout/_partial/meta.ejs +18 -4
  31. package/layout/_partial/post.ejs +35 -9
  32. package/layout/_partial/scripts/_ctrl/cdnCtrl.ejs +126 -0
  33. package/layout/_partial/scripts/{coverCtrl.ejs → _ctrl/coverCtrl.ejs} +17 -25
  34. package/layout/_partial/scripts/_ctrl.ejs +2 -0
  35. package/layout/_partial/scripts/content-visibility-scroll-fix.ejs +88 -0
  36. package/layout/_partial/scripts/global.ejs +422 -109
  37. package/layout/_partial/scripts/index.ejs +91 -46
  38. package/layout/_partial/scripts/toc.ejs +98 -68
  39. package/layout/_partial/side.ejs +4 -1
  40. package/layout/_plugins/_page_plugins/artitalk/index.ejs +15 -0
  41. package/layout/_plugins/_page_plugins/bbtalk/index.ejs +10 -0
  42. package/layout/_plugins/_page_plugins/fcircle/index.ejs +12 -0
  43. package/layout/_plugins/_page_plugins/gitter/index.ejs +14 -0
  44. package/layout/_plugins/_page_plugins/indent/index.ejs +16 -0
  45. package/layout/_plugins/_page_plugins/index.ejs +27 -0
  46. package/layout/_plugins/_page_plugins/katex/index.ejs +13 -0
  47. package/layout/{_third-party/math/mathjax/script.ejs → _plugins/_page_plugins/mathjax/index.ejs} +2 -2
  48. package/layout/_plugins/_page_plugins/snackbar/index.ejs +55 -0
  49. package/layout/{_partial/scripts/counter.ejs → _plugins/analytics/LCCounter.ejs} +0 -0
  50. package/layout/{_third-party → _plugins}/analytics/script.ejs +43 -5
  51. package/layout/{_third-party → _plugins}/aplayer/layout.ejs +0 -0
  52. package/layout/_plugins/aplayer/script.ejs +74 -0
  53. package/layout/_plugins/chat/gitter/script.ejs +17 -0
  54. package/layout/_plugins/chat/index.ejs +1 -0
  55. package/layout/_plugins/chat/tidio/script.ejs +1 -0
  56. package/layout/_plugins/comments/artalk/script.ejs +59 -0
  57. package/layout/_plugins/comments/beaudar/script.ejs +61 -0
  58. package/layout/_plugins/comments/discuss/script.ejs +30 -0
  59. package/layout/_plugins/comments/disqus/script.ejs +98 -0
  60. package/layout/_plugins/comments/disqusjs/script.ejs +35 -0
  61. package/layout/_plugins/comments/giscus/script.ejs +47 -0
  62. package/layout/_plugins/comments/gitalk/script.ejs +24 -0
  63. package/layout/_plugins/comments/hashover/script.ejs +5 -0
  64. package/layout/{_third-party → _plugins}/comments/index.ejs +10 -3
  65. package/layout/_plugins/comments/isso/script.ejs +27 -0
  66. package/layout/_plugins/comments/livere/script.ejs +15 -0
  67. package/layout/_plugins/comments/twikoo/script.ejs +40 -0
  68. package/layout/_plugins/comments/utterances/script.ejs +43 -0
  69. package/layout/_plugins/comments/vssue/script.ejs +37 -0
  70. package/layout/_plugins/comments/waline/script.ejs +62 -0
  71. package/layout/_plugins/comments/z-custom/script.ejs +1 -0
  72. package/layout/_plugins/darkmode/script.ejs +114 -0
  73. package/layout/{_third-party → _plugins}/end-of-support/script.ejs +25 -8
  74. package/layout/_plugins/github-api/script.ejs +27 -0
  75. package/layout/_plugins/highlight/highlightjs/script.ejs +26 -0
  76. package/layout/_plugins/highlight/prismjs/script.ejs +25 -0
  77. package/layout/_plugins/highlight/script.ejs +1 -0
  78. package/layout/{_third-party → _plugins}/lazyload/script.ejs +1 -1
  79. package/layout/{_third-party → _plugins}/nodewaves/script.ejs +1 -1
  80. package/layout/_plugins/parallax/script.ejs +74 -0
  81. package/layout/{_third-party → _plugins}/pjax/animate.ejs +31 -31
  82. package/layout/_plugins/pjax/index.ejs +73 -0
  83. package/layout/_plugins/pjax/pdata.ejs +56 -0
  84. package/layout/{_third-party → _plugins}/preload/script.ejs +3 -3
  85. package/layout/_plugins/rightmenu/layout.ejs +119 -0
  86. package/layout/_plugins/rightmenus/layout.ejs +137 -0
  87. package/layout/_plugins/scrollreveal/script.ejs +25 -0
  88. package/layout/_plugins/search/script.ejs +50 -0
  89. package/layout/{_third-party → _plugins}/share/layout.ejs +0 -0
  90. package/layout/_plugins/swiper/script.ejs +37 -0
  91. package/layout/_pre.ejs +2 -2
  92. package/layout/_widget/_pre.ejs +5 -0
  93. package/layout/_widget/blogger.ejs +1 -1
  94. package/layout/_widget/category.ejs +2 -2
  95. package/layout/_widget/copyright.ejs +1 -1
  96. package/layout/_widget/grid.ejs +3 -3
  97. package/layout/_widget/lastupdate.ejs +27 -0
  98. package/layout/_widget/list.ejs +2 -2
  99. package/layout/_widget/load.ejs +18 -0
  100. package/layout/_widget/music.ejs +3 -2
  101. package/layout/_widget/page.ejs +1 -1
  102. package/layout/_widget/qrcode.ejs +1 -1
  103. package/layout/_widget/related_posts.ejs +1 -1
  104. package/layout/_widget/tagcloud.ejs +1 -1
  105. package/layout/_widget/text.ejs +1 -1
  106. package/layout/_widget/toc.ejs +6 -2
  107. package/layout/_widget/webinfo.ejs +13 -76
  108. package/layout/archive.ejs +4 -4
  109. package/layout/category.ejs +9 -4
  110. package/layout/docs.ejs +1 -1
  111. package/layout/friends.ejs +6 -25
  112. package/layout/index.ejs +1 -1
  113. package/layout/layout.ejs +30 -12
  114. package/layout/list.ejs +1 -1
  115. package/layout/page.ejs +1 -1
  116. package/layout/post.ejs +1 -1
  117. package/layout/tag.ejs +8 -3
  118. package/package.json +5 -3
  119. package/scripts/events/index.js +13 -0
  120. package/scripts/events/lib/check-configuration.js +43 -0
  121. package/scripts/events/lib/check-environment.js +74 -0
  122. package/scripts/events/lib/config.js +34 -9
  123. package/scripts/events/lib/render-stylus.js +78 -0
  124. package/scripts/events/lib/stellar-tag-utils.js +76 -0
  125. package/scripts/filters/content-visibility.js +25 -0
  126. package/scripts/{render → filters}/img.js +0 -0
  127. package/scripts/filters/replace.js +15 -0
  128. package/scripts/{z-lazyload/lib/process.js → filters/z-lazyload.js} +6 -3
  129. package/scripts/helpers/custom-files.js +165 -0
  130. package/scripts/helpers/first-style.js +19 -0
  131. package/scripts/helpers/head/autoCanonical.js +15 -0
  132. package/scripts/helpers/head/generate_preload_fontfamily.js +22 -0
  133. package/scripts/helpers/head/generate_seo.js +24 -0
  134. package/scripts/helpers/head/generate_title__keywords__description.js +101 -0
  135. package/scripts/{related_posts/index.js → helpers/related-posts.js} +1 -1
  136. package/scripts/helpers/revisioned.js +158 -0
  137. package/scripts/helpers/structured-data/index.js +2 -0
  138. package/scripts/helpers/structured-data/lib/blogposting.js +77 -0
  139. package/scripts/helpers/structured-data/lib/breadcrumblist.js +152 -0
  140. package/scripts/helpers/structured-data/lib/config.js +31 -0
  141. package/scripts/helpers/structured-data/lib/index.js +30 -0
  142. package/scripts/helpers/structured-data/lib/organization.js +15 -0
  143. package/scripts/helpers/structured-data/lib/person.js +16 -0
  144. package/scripts/helpers/structured-data/lib/website.js +42 -0
  145. package/scripts/tags/btn.js +6 -1
  146. package/scripts/tags/btns.js +7 -2
  147. package/scripts/tags/checkbox.js +12 -2
  148. package/scripts/tags/contributors.js +100 -0
  149. package/scripts/tags/dropmenu.js +18 -3
  150. package/scripts/tags/fancybox.js +44 -10
  151. package/scripts/tags/folding.js +6 -1
  152. package/scripts/tags/frame.js +6 -1
  153. package/scripts/tags/friends.js +99 -0
  154. package/scripts/tags/ghcard.js +6 -1
  155. package/scripts/tags/image.js +14 -2
  156. package/scripts/tags/link.js +6 -1
  157. package/scripts/tags/md.js +59 -0
  158. package/scripts/tags/media.js +25 -1
  159. package/scripts/tags/note.js +36 -3
  160. package/scripts/tags/site.js +87 -51
  161. package/scripts/tags/span.js +12 -2
  162. package/scripts/tags/swiper.js +38 -0
  163. package/scripts/tags/tabs.js +33 -3
  164. package/scripts/tags/timeline.js +6 -1
  165. package/source/css/Readme.md +28 -0
  166. package/source/css/_defines/AutoPrefixCSS.styl +347 -0
  167. package/source/css/_defines/Readme.md +3 -0
  168. package/source/css/_defines/color.styl +41 -1
  169. package/source/css/_defines/effect.styl +0 -13
  170. package/source/css/_defines/fonts.styl +17 -18
  171. package/source/css/_defines/func.styl +12 -30
  172. package/source/css/_first/base_first.styl +118 -0
  173. package/source/css/_first/{cover.styl → cover_first.styl} +113 -87
  174. package/source/css/_first/dark_first.styl +76 -0
  175. package/source/css/_first/fontfamily_first.styl +17 -0
  176. package/source/css/_first/{navbar.styl → navbar_first.styl} +4 -10
  177. package/source/css/_first/search_first.styl +12 -0
  178. package/source/css/{_base/index.styl → _style/_base/base.styl} +9 -93
  179. package/source/css/_style/_base/fontfamily_async.styl +8 -0
  180. package/source/css/{_layout → _style/_layout}/archive.styl +0 -0
  181. package/source/css/{_layout → _style/_layout}/article.styl +3 -30
  182. package/source/css/{_layout → _style/_layout}/footer.styl +0 -0
  183. package/source/css/_style/_layout/friends-simpleuser.styl +23 -0
  184. package/source/css/_style/_layout/friends-traditional.styl +81 -0
  185. package/source/css/{_layout → _style/_layout}/img.styl +0 -0
  186. package/source/css/_style/_layout/loading.styl +14 -0
  187. package/source/css/{_layout → _style/_layout}/main.styl +19 -7
  188. package/source/css/{_layout → _style/_layout}/md.styl +0 -0
  189. package/source/css/{_layout → _style/_layout}/pagination.styl +1 -1
  190. package/source/css/{_layout → _style/_layout}/posts.styl +2 -0
  191. package/source/css/{_first → _style/_layout}/search.styl +0 -103
  192. package/source/css/{_layout → _style/_layout}/sidebar.styl +23 -3
  193. package/source/css/{_layout → _style/_layout}/snackbar.styl +0 -0
  194. package/source/css/{_layout → _style/_layout}/toc.styl +3 -3
  195. package/source/css/{_layout → _style/_layout}/video.styl +0 -0
  196. package/source/css/_style/_plugins/_dark/dark_async.styl +41 -0
  197. package/source/css/_style/_plugins/_dark/dark_plugins.styl +136 -0
  198. package/source/css/_style/_plugins/_highlight/highlightjs/clipboard.styl +36 -0
  199. package/source/css/_style/_plugins/_highlight/highlightjs/color.styl +96 -0
  200. package/source/css/_style/_plugins/_highlight/highlightjs/index.styl +102 -0
  201. package/source/css/_style/_plugins/_highlight/highlightjs/language.styl +63 -0
  202. package/source/css/_style/_plugins/_highlight/index.styl +1 -0
  203. package/source/css/_style/_plugins/_highlight/prismjs/clipboard.styl +33 -0
  204. package/source/css/_style/_plugins/_highlight/prismjs/index.styl +8 -0
  205. package/source/css/_style/_plugins/_highlight/prismjs/language.styl +63 -0
  206. package/source/css/_style/_plugins/_rightmenu/reading.styl +56 -0
  207. package/source/css/{_plugins → _style/_plugins/_rightmenu}/rightmenu.styl +22 -2
  208. package/source/css/{_plugins → _style/_plugins}/aplayer.styl +8 -1
  209. package/source/css/{_plugins → _style/_plugins}/cursor.styl +49 -19
  210. package/source/css/_style/_plugins/fontcolor.styl +84 -0
  211. package/source/css/{_plugins → _style/_plugins}/gitalk.styl +0 -0
  212. package/source/css/_style/_plugins/index.styl +24 -0
  213. package/source/css/{_plugins → _style/_plugins}/mathjax.styl +0 -0
  214. package/source/css/_style/_plugins/message.styl +14 -0
  215. package/source/css/{_plugins → _style/_plugins}/pjaxanimate.styl +0 -0
  216. package/source/css/_style/_tag-plugins/Readme.md +6 -0
  217. package/source/css/{_tag-plugins → _style/_tag-plugins}/btns.styl +0 -0
  218. package/source/css/{_tag-plugins → _style/_tag-plugins}/checkbox.styl +0 -0
  219. package/source/css/{_tag-plugins → _style/_tag-plugins}/dropmenu.styl +0 -0
  220. package/source/css/{_plugins → _style/_tag-plugins}/fancybox.styl +8 -9
  221. package/source/css/{_tag-plugins → _style/_tag-plugins}/folding.styl +0 -0
  222. package/source/css/{_tag-plugins → _style/_tag-plugins}/frame.styl +0 -0
  223. package/source/css/_style/_tag-plugins/friends.styl +72 -0
  224. package/source/css/{_tag-plugins → _style/_tag-plugins}/ghcard.styl +0 -0
  225. package/source/css/{_tag-plugins → _style/_tag-plugins}/image.styl +0 -0
  226. package/source/css/{_tag-plugins → _style/_tag-plugins}/link.styl +0 -0
  227. package/source/css/{_tag-plugins → _style/_tag-plugins}/media.styl +0 -0
  228. package/source/css/{_tag-plugins → _style/_tag-plugins}/note.styl +0 -0
  229. package/source/css/_style/_tag-plugins/sites.styl +87 -0
  230. package/source/css/{_tag-plugins → _style/_tag-plugins}/span.styl +0 -0
  231. package/source/css/_style/_tag-plugins/swiper.styl +44 -0
  232. package/source/css/{_tag-plugins → _style/_tag-plugins}/table.styl +0 -0
  233. package/source/css/{_tag-plugins → _style/_tag-plugins}/tabs.styl +0 -0
  234. package/source/css/_style/_tag-plugins/tag.json +35 -0
  235. package/source/css/_style/_tag-plugins/text.styl +31 -0
  236. package/source/css/{_tag-plugins → _style/_tag-plugins}/timeline.styl +0 -0
  237. package/source/css/_style/index.styl +8 -0
  238. package/source/css/first.styl +17 -6
  239. package/source/css/style.styl +9 -7
  240. package/source/js/app.js +1051 -278
  241. package/source/js/plugins/aplayer.js +186 -0
  242. package/source/js/plugins/parallax.js +191 -0
  243. package/source/js/plugins/rightMenu.js +577 -0
  244. package/source/js/plugins/rightMenus.js +616 -0
  245. package/source/js/plugins/tags/contributors.js +92 -0
  246. package/source/js/plugins/tags/friends.js +93 -0
  247. package/source/js/plugins/tags/sites.js +96 -0
  248. package/source/js/search/hexo.js +180 -373
  249. package/.eslintrc.json +0 -111
  250. package/layout/_meta/valinecount.ejs +0 -15
  251. package/layout/_partial/rightmenu.ejs +0 -199
  252. package/layout/_partial/scripts/cover.ejs +0 -45
  253. package/layout/_partial/scripts/darkmode.ejs +0 -85
  254. package/layout/_partial/scripts/import.ejs +0 -3
  255. package/layout/_partial/scripts/issues.ejs +0 -18
  256. package/layout/_partial/scripts/search.ejs +0 -62
  257. package/layout/_partial/snackbar.ejs +0 -22
  258. package/layout/_third-party/aplayer/script.ejs +0 -26
  259. package/layout/_third-party/clipboard/script.ejs +0 -54
  260. package/layout/_third-party/comments/disqus/layout.ejs +0 -5
  261. package/layout/_third-party/comments/disqus/script.ejs +0 -90
  262. package/layout/_third-party/comments/disqusjs/layout.ejs +0 -1
  263. package/layout/_third-party/comments/disqusjs/script.ejs +0 -34
  264. package/layout/_third-party/comments/gitalk/layout.ejs +0 -1
  265. package/layout/_third-party/comments/gitalk/script.ejs +0 -22
  266. package/layout/_third-party/comments/hashover/layout.ejs +0 -2
  267. package/layout/_third-party/comments/hashover/script.ejs +0 -1
  268. package/layout/_third-party/comments/isso/layout.ejs +0 -1
  269. package/layout/_third-party/comments/isso/script.ejs +0 -1
  270. package/layout/_third-party/comments/livere/layout.ejs +0 -3
  271. package/layout/_third-party/comments/livere/script.ejs +0 -10
  272. package/layout/_third-party/comments/minivaline/layout.ejs +0 -3
  273. package/layout/_third-party/comments/minivaline/script.ejs +0 -34
  274. package/layout/_third-party/comments/twikoo/layout.ejs +0 -3
  275. package/layout/_third-party/comments/twikoo/script.ejs +0 -32
  276. package/layout/_third-party/comments/valine/layout.ejs +0 -3
  277. package/layout/_third-party/comments/valine/script.ejs +0 -49
  278. package/layout/_third-party/comments/vssue/layout.ejs +0 -1
  279. package/layout/_third-party/comments/vssue/script.ejs +0 -21
  280. package/layout/_third-party/comments/waline/layout.ejs +0 -3
  281. package/layout/_third-party/comments/waline/script.ejs +0 -33
  282. package/layout/_third-party/fancybox/script.ejs +0 -61
  283. package/layout/_third-party/highlightjs/script.ejs +0 -11
  284. package/layout/_third-party/pjax/index.ejs +0 -78
  285. package/layout/_third-party/pjax/pdata.ejs +0 -53
  286. package/layout/_third-party/scrollreveal/script.ejs +0 -21
  287. package/layout/_third-party/tidio/script.ejs +0 -3
  288. package/layout/artitalk.ejs +0 -13
  289. package/layout/bb.ejs +0 -10
  290. package/package-lock.json +0 -916
  291. package/scripts/tags/issues.js +0 -41
  292. package/scripts/z-lazyload/index.js +0 -4
  293. package/source/css/_highlight/index.styl +0 -316
  294. package/source/css/_layout/friends.styl +0 -79
  295. package/source/css/_plugins/clipboard.styl +0 -37
  296. package/source/css/_plugins/dark.styl +0 -149
  297. package/source/css/_plugins/darkmode.styl +0 -9
  298. package/source/css/_plugins/index.styl +0 -18
  299. package/source/css/_plugins/twikoo.styl +0 -21
  300. package/source/css/_plugins/valine.styl +0 -183
  301. package/source/css/_tag-plugins/simpleuser.styl +0 -21
  302. package/source/css/_tag-plugins/site-card.styl +0 -70
  303. package/source/js/aplayer.js +0 -167
  304. package/source/js/issues.js +0 -186
  305. package/source/js/search/algolia.js +0 -344
  306. package/source/js/search/azure.js +0 -355
  307. package/source/js/search/baidu.js +0 -340
  308. package/source/js/search/google.js +0 -339
  309. package/source/js/valine.js +0 -5137
@@ -1,340 +0,0 @@
1
- var SearchService = '';
2
-
3
- (function($) {
4
-
5
- /**
6
- * A super class of common logics for all search services
7
- * @param options : (object)
8
- */
9
- SearchService = function(options) {
10
- var self = this;
11
-
12
- self.config = $.extend({
13
- per_page : 10,
14
- selectors: {
15
- body : 'body',
16
- form : '.u-search-form',
17
- input : '.u-search-input',
18
- container : '#u-search',
19
- modal : '#u-search .modal',
20
- modal_body : '#u-search .modal-body',
21
- modal_footer : '#u-search .modal-footer',
22
- modal_overlay : '#u-search .modal-overlay',
23
- modal_results : '#u-search .modal-results',
24
- modal_metadata : '#u-search .modal-metadata',
25
- modal_error : '#u-search .modal-error',
26
- modal_loading_bar : '#u-search .modal-loading-bar',
27
- modal_ajax_content: '#u-search .modal-ajax-content',
28
- modal_logo : '#u-search .modal-footer .logo',
29
- btn_close : '#u-search .btn-close',
30
- btn_next : '#u-search .btn-next',
31
- btn_prev : '#u-search .btn-prev'
32
- },
33
- brands: {
34
- 'hexo' : {logo: '', url: ''},
35
- 'google' : {logo: 'google.svg', url: 'https://cse.google.com'},
36
- 'algolia': {logo: 'algolia.svg', url: 'https://www.algolia.com'},
37
- 'baidu' : {logo: 'baidu.svg', url: 'http://zn.baidu.com/cse/home/index'},
38
- 'azure' : {logo: 'azure.svg', url: 'https://azure.microsoft.com/en-us/services/search/'}
39
- },
40
- imagePath: 'https://cdn.jsdelivr.net/gh/volantis-x/cdn-volantis@master/img/logo/'
41
- }, options);
42
-
43
- self.dom = {};
44
- self.percentLoaded = 0;
45
- self.open = false;
46
- self.queryText = '';
47
- self.nav = {
48
- next : -1,
49
- prev : -1,
50
- total : 0,
51
- current: 1
52
- };
53
-
54
- self.parseSelectors = function() {
55
- for (var key in self.config.selectors) {
56
- self.dom[key] = $(self.config.selectors[key]);
57
- }
58
- };
59
-
60
- self.beforeQuery = function() {
61
- if (!self.open) {
62
- self.dom.container.fadeIn();
63
- // self.dom.body.addClass('modal-active');
64
- // 上面的是去除了文章的滚动条,我觉得没必要
65
- }
66
- self.dom.input.each(function(index, elem) {
67
- $(elem).val(self.queryText);
68
- });
69
- document.activeElement.blur();
70
- self.dom.modal_error.hide();
71
- self.dom.modal_ajax_content.removeClass('loaded');
72
- self.startLoading();
73
- };
74
-
75
- self.afterQuery = function() {
76
- self.dom.modal_body.scrollTop(0);
77
- self.dom.modal_ajax_content.addClass('loaded');
78
- self.stopLoading();
79
- };
80
-
81
- /**
82
- * Perform a complete serach operation including UI updates and query
83
- * @param startIndex {int} start index or page number
84
- */
85
- self.search = function(startIndex, callback) {
86
- self.beforeQuery();
87
- if (self.search instanceof Function) {
88
- self.query(self.queryText, startIndex, function() {
89
- self.afterQuery();
90
- });
91
- } else {
92
- console.log('query() does not exist.');
93
- self.onQueryError(self.queryText, '');
94
- self.afterQuery();
95
- }
96
- };
97
-
98
- /**
99
- * Query error handler
100
- * @param queryText: (string)
101
- * @param status: (string)
102
- */
103
- self.onQueryError = function(queryText, status) {
104
- var errMsg = '';
105
- if (status === 'success') errMsg = 'No result found for "' + queryText + '".';
106
- else if (status === 'timeout') errMsg = 'Unfortunate timeout.';
107
- else errMsg = 'Mysterious failure.';
108
- self.dom.modal_results.html('');
109
- self.dom.modal_error.html(errMsg);
110
- self.dom.modal_error.show();
111
- };
112
-
113
- self.nextPage = function() {
114
- if (self.nav.next !== -1) {
115
- self.search(self.nav.next);
116
- }
117
- };
118
-
119
- self.prevPage = function() {
120
- if (self.nav.prev !== -1) {
121
- self.search(self.nav.prev);
122
- }
123
- };
124
-
125
- self.getUrlRelativePath = function(url) {
126
- var arrUrl = url.split('//');
127
- var start = arrUrl[1].indexOf('/');
128
- var relUrl = arrUrl[1].substring(start);
129
- if (relUrl.indexOf('?') != -1) {
130
- relUrl = relUrl.split('?')[0];
131
- }
132
- return relUrl;
133
- };
134
-
135
- /**
136
- * Generate html for one result
137
- * @param url : (string) url
138
- * @param title : (string) title
139
- * @param digest : (string) digest
140
- */
141
- self.buildResult = function(url, title, digest) {
142
- var result = self.getUrlRelativePath(url);
143
- var html = '';
144
- html = '<li>';
145
- html += '<a class=\'result\' href=\'' + result + '\'>';
146
- html += '<span class=\'title\'>' + title + '</span>';
147
- if (digest !== '') html += '<span class=\'digest\'>' + digest + '</span>';
148
- html += '</a>';
149
- html += '</li>';
150
- return html;
151
- };
152
-
153
- /**
154
- * Close the modal, resume body scrolling
155
- * no param
156
- */
157
- self.close = function() {
158
- self.open = false;
159
- self.dom.container.fadeOut();
160
- self.dom.body.removeClass('modal-active');
161
- };
162
-
163
- /**
164
- * Searchform submit event handler
165
- * @param queryText : (string) the query text
166
- */
167
- self.onSubmit = function(event) {
168
- event.preventDefault();
169
- self.queryText = $(this).find('.u-search-input').val();
170
- if (self.queryText) {
171
- self.search(1);
172
- }
173
- };
174
-
175
- /**
176
- * Start loading bar animation
177
- * no param
178
- */
179
- self.startLoading = function() {
180
- self.dom.modal_loading_bar.show();
181
- self.loadingTimer = setInterval(function() {
182
- self.percentLoaded = Math.min(self.percentLoaded + 5, 95);
183
- self.dom.modal_loading_bar.css('width', self.percentLoaded + '%');
184
- }, 100);
185
- };
186
-
187
- /**
188
- * Stop loading bar animation
189
- * no param
190
- */
191
- self.stopLoading = function() {
192
- clearInterval(self.loadingTimer);
193
- self.dom.modal_loading_bar.css('width', '100%');
194
- self.dom.modal_loading_bar.fadeOut();
195
- setTimeout(function() {
196
- self.percentLoaded = 0;
197
- self.dom.modal_loading_bar.css('width', '0%');
198
- }, 300);
199
- };
200
-
201
- /**
202
- * Add service branding
203
- * @param service {String} service name
204
- */
205
- self.addLogo = function(service) {
206
- var html = '';
207
- if (self.config.brands[service] && self.config.brands[service].logo) {
208
- html += '<a href=\'' + self.config.brands[service].url + '\' class=\'' + service + '\'>';
209
- html += '<img src="' + self.config.imagePath + self.config.brands[service].logo + '" />';
210
- html += '</a>';
211
- self.dom.modal_logo.html(html);
212
- }
213
- };
214
-
215
- self.destroy = function() {
216
- self.dom.form.each(function(index, elem) {
217
- $(elem).off('submit');
218
- });
219
- self.dom.modal_overlay.off('click');
220
- self.dom.btn_close.off('click');
221
- self.dom.btn_next.off('click');
222
- self.dom.btn_prev.off('click');
223
- self.dom.container.remove();
224
- };
225
-
226
- /**
227
- * Load template and register event handlers
228
- * no param
229
- */
230
- self.init = function() {
231
- $('body').append(template);
232
- self.parseSelectors();
233
- self.dom.modal_footer.show();
234
- self.dom.form.each(function(index, elem) {
235
- $(elem).on('submit', self.onSubmit);
236
- });
237
- self.dom.modal_overlay.on('click', self.close);
238
- self.dom.btn_close.on('click', self.close);
239
- self.dom.btn_next.on('click', self.nextPage);
240
- self.dom.btn_prev.on('click', self.prevPage);
241
- };
242
-
243
- self.init();
244
- };
245
-
246
- var template = '<div id="u-search"><div class="modal"> <header class="modal-header" class="clearfix"><form id="u-search-modal-form" class="u-search-form" name="uSearchModalForm"> <input type="text" id="u-search-modal-input" class="u-search-input" /> <button type="submit" id="u-search-modal-btn-submit" class="u-search-btn-submit"> <span class="fas fa-search"></span> </button></form> <a class="btn-close"> <span class="fas fa-times"></span> </a><div class="modal-loading"><div class="modal-loading-bar"></div></div> </header> <main class="modal-body"><ul class="modal-results modal-ajax-content"></ul> </main> <footer class="modal-footer clearfix"><div class="modal-metadata modal-ajax-content"> <strong class="range"></strong> of <strong class="total"></strong></div><div class="modal-error"></div> <div class="logo"></div> <a class="nav btn-next modal-ajax-content"> <span class="text">NEXT</span> <span class="fal fa-chevron-right"></span> </a> <a class="nav btn-prev modal-ajax-content"> <span class="fal fa-chevron-left"></span> <span class="text">PREV</span> </a> </footer></div><div class="modal-overlay"></div></div>';
247
- })(jQuery);
248
-
249
- var BaiduSearch;
250
- (function($) {
251
- 'use strict';
252
-
253
- /**
254
- * TODO
255
- * Search by Baidu Search API
256
- * @param options : (object)
257
- */
258
- BaiduSearch = function(options) {
259
- SearchService.apply(this, arguments);
260
- var self = this;
261
- var endpoint = '';
262
- self.addLogo('baidu');
263
-
264
- /**
265
- * Generate result list html
266
- * @param data : (array) result items
267
- */
268
- self.buildResultList = function(data, queryText) {
269
- var results = [];
270
- var html = '';
271
- $.each(data, function(index, post) {
272
- if (self.contentSearch(post, queryText)) { html += self.buildResult(post.linkUrl, post.title, post.abstract); }
273
- });
274
- html += '<script>try{pjax.refresh(document.querySelector(\'#u-search\'));document.addEventListener(\'pjax:send\',function(){$(\'#u-search\').fadeOut(500);$(\'body\').removeClass(\'modal-active\')});}catch(e){$(\'#u-search\').fadeOut(500);}</script>';
275
- return html;
276
- };
277
-
278
- /**
279
- * Generate metadata after a successful query
280
- * @param data : (object) the raw google custom search response data
281
- */
282
- self.buildMetadata = function(data) {
283
-
284
- };
285
-
286
- self.loadScript = function() {
287
- self.dom.input.each(function(index, elem) {
288
- $(elem).attr('disabled', true);
289
- });
290
- var script = '<script src=\'http://zhannei.baidu.com/api/customsearch/apiaccept?sid=' + self.config.apiId + '&v=2.0&callback=customSearch.initBaidu\' type=\'text/javascript\' charset=\'utf-8\'></script>';
291
- self.dom.body.append(script);
292
- };
293
-
294
- self.initBaidu = function() {
295
- self.cse = new BCse.Search(self.config.apiId);
296
- //self.cse.setPageNum(self.config.per_page);
297
- self.dom.input.each(function(index, elem) {
298
- $(elem).attr('disabled', false);
299
- });
300
- };
301
-
302
- /**
303
- * Get search results
304
- * @param queryText {String}
305
- * @param page {Integer}
306
- * @param callback {Function}
307
- */
308
- self.query = function(queryText, page, callback) {
309
- self.cse.getResult(queryText, function(data) {
310
- console.log('Searching: ' + queryText);
311
- self.cse.getError(function(data) {
312
- console.log(data);
313
- });
314
- if (data.length > 0) {
315
- self.buildResultList(data, queryText);
316
- self.cse.getSearchInfo(queryText, function(data) {
317
- console.log(data);
318
- self.buildMetadata(data);
319
- });
320
- } else {
321
- self.nav.total = 0;
322
- self.nav.next = -1;
323
- self.nav.prev = -1;
324
- self.dom.modal_metadata.hide();
325
- self.dom.btn_next.hide();
326
- self.dom.btn_prev.hide();
327
- self.onQueryError(queryText, 'success');
328
- }
329
- if (callback instanceof Function) {
330
- callback();
331
- }
332
- });
333
- };
334
-
335
- self.loadScript();
336
-
337
- return self;
338
- };
339
-
340
- })(jQuery);
@@ -1,339 +0,0 @@
1
- var SearchService = '';
2
-
3
- (function($) {
4
-
5
- /**
6
- * A super class of common logics for all search services
7
- * @param options : (object)
8
- */
9
- SearchService = function(options) {
10
- var self = this;
11
-
12
- self.config = $.extend({
13
- per_page : 10,
14
- selectors: {
15
- body : 'body',
16
- form : '.u-search-form',
17
- input : '.u-search-input',
18
- container : '#u-search',
19
- modal : '#u-search .modal',
20
- modal_body : '#u-search .modal-body',
21
- modal_footer : '#u-search .modal-footer',
22
- modal_overlay : '#u-search .modal-overlay',
23
- modal_results : '#u-search .modal-results',
24
- modal_metadata : '#u-search .modal-metadata',
25
- modal_error : '#u-search .modal-error',
26
- modal_loading_bar : '#u-search .modal-loading-bar',
27
- modal_ajax_content: '#u-search .modal-ajax-content',
28
- modal_logo : '#u-search .modal-footer .logo',
29
- btn_close : '#u-search .btn-close',
30
- btn_next : '#u-search .btn-next',
31
- btn_prev : '#u-search .btn-prev'
32
- },
33
- brands: {
34
- 'hexo' : {logo: '', url: ''},
35
- 'google' : {logo: 'google.svg', url: 'https://cse.google.com'},
36
- 'algolia': {logo: 'algolia.svg', url: 'https://www.algolia.com'},
37
- 'baidu' : {logo: 'baidu.svg', url: 'http://zn.baidu.com/cse/home/index'},
38
- 'azure' : {logo: 'azure.svg', url: 'https://azure.microsoft.com/en-us/services/search/'}
39
- },
40
- imagePath: 'https://cdn.jsdelivr.net/gh/volantis-x/cdn-volantis@master/img/logo/'
41
- }, options);
42
-
43
- self.dom = {};
44
- self.percentLoaded = 0;
45
- self.open = false;
46
- self.queryText = '';
47
- self.nav = {
48
- next : -1,
49
- prev : -1,
50
- total : 0,
51
- current: 1
52
- };
53
-
54
- self.parseSelectors = function() {
55
- for (var key in self.config.selectors) {
56
- self.dom[key] = $(self.config.selectors[key]);
57
- }
58
- };
59
-
60
- self.beforeQuery = function() {
61
- if (!self.open) {
62
- self.dom.container.fadeIn();
63
- // self.dom.body.addClass('modal-active');
64
- // 上面的是去除了文章的滚动条,我觉得没必要
65
- }
66
- self.dom.input.each(function(index, elem) {
67
- $(elem).val(self.queryText);
68
- });
69
- document.activeElement.blur();
70
- self.dom.modal_error.hide();
71
- self.dom.modal_ajax_content.removeClass('loaded');
72
- self.startLoading();
73
- };
74
-
75
- self.afterQuery = function() {
76
- self.dom.modal_body.scrollTop(0);
77
- self.dom.modal_ajax_content.addClass('loaded');
78
- self.stopLoading();
79
- };
80
-
81
- /**
82
- * Perform a complete serach operation including UI updates and query
83
- * @param startIndex {int} start index or page number
84
- */
85
- self.search = function(startIndex, callback) {
86
- self.beforeQuery();
87
- if (self.search instanceof Function) {
88
- self.query(self.queryText, startIndex, function() {
89
- self.afterQuery();
90
- });
91
- } else {
92
- console.log('query() does not exist.');
93
- self.onQueryError(self.queryText, '');
94
- self.afterQuery();
95
- }
96
- };
97
-
98
- /**
99
- * Query error handler
100
- * @param queryText: (string)
101
- * @param status: (string)
102
- */
103
- self.onQueryError = function(queryText, status) {
104
- var errMsg = '';
105
- if (status === 'success') errMsg = 'No result found for "' + queryText + '".';
106
- else if (status === 'timeout') errMsg = 'Unfortunate timeout.';
107
- else errMsg = 'Mysterious failure.';
108
- self.dom.modal_results.html('');
109
- self.dom.modal_error.html(errMsg);
110
- self.dom.modal_error.show();
111
- };
112
-
113
- self.nextPage = function() {
114
- if (self.nav.next !== -1) {
115
- self.search(self.nav.next);
116
- }
117
- };
118
-
119
- self.prevPage = function() {
120
- if (self.nav.prev !== -1) {
121
- self.search(self.nav.prev);
122
- }
123
- };
124
-
125
- self.getUrlRelativePath = function(url) {
126
- var arrUrl = url.split('//');
127
- var start = arrUrl[1].indexOf('/');
128
- var relUrl = arrUrl[1].substring(start);
129
- if (relUrl.indexOf('?') != -1) {
130
- relUrl = relUrl.split('?')[0];
131
- }
132
- return relUrl;
133
- };
134
-
135
- /**
136
- * Generate html for one result
137
- * @param url : (string) url
138
- * @param title : (string) title
139
- * @param digest : (string) digest
140
- */
141
- self.buildResult = function(url, title, digest) {
142
- var result = self.getUrlRelativePath(url);
143
- var html = '';
144
- html = '<li>';
145
- html += '<a class=\'result\' href=\'' + result + '\'>';
146
- html += '<span class=\'title\'>' + title + '</span>';
147
- if (digest !== '') html += '<span class=\'digest\'>' + digest + '</span>';
148
- html += '</a>';
149
- html += '</li>';
150
- return html;
151
- };
152
-
153
- /**
154
- * Close the modal, resume body scrolling
155
- * no param
156
- */
157
- self.close = function() {
158
- self.open = false;
159
- self.dom.container.fadeOut();
160
- self.dom.body.removeClass('modal-active');
161
- };
162
-
163
- /**
164
- * Searchform submit event handler
165
- * @param queryText : (string) the query text
166
- */
167
- self.onSubmit = function(event) {
168
- event.preventDefault();
169
- self.queryText = $(this).find('.u-search-input').val();
170
- if (self.queryText) {
171
- self.search(1);
172
- }
173
- };
174
-
175
- /**
176
- * Start loading bar animation
177
- * no param
178
- */
179
- self.startLoading = function() {
180
- self.dom.modal_loading_bar.show();
181
- self.loadingTimer = setInterval(function() {
182
- self.percentLoaded = Math.min(self.percentLoaded + 5, 95);
183
- self.dom.modal_loading_bar.css('width', self.percentLoaded + '%');
184
- }, 100);
185
- };
186
-
187
- /**
188
- * Stop loading bar animation
189
- * no param
190
- */
191
- self.stopLoading = function() {
192
- clearInterval(self.loadingTimer);
193
- self.dom.modal_loading_bar.css('width', '100%');
194
- self.dom.modal_loading_bar.fadeOut();
195
- setTimeout(function() {
196
- self.percentLoaded = 0;
197
- self.dom.modal_loading_bar.css('width', '0%');
198
- }, 300);
199
- };
200
-
201
- /**
202
- * Add service branding
203
- * @param service {String} service name
204
- */
205
- self.addLogo = function(service) {
206
- var html = '';
207
- if (self.config.brands[service] && self.config.brands[service].logo) {
208
- html += '<a href=\'' + self.config.brands[service].url + '\' class=\'' + service + '\'>';
209
- html += '<img src="' + self.config.imagePath + self.config.brands[service].logo + '" />';
210
- html += '</a>';
211
- self.dom.modal_logo.html(html);
212
- }
213
- };
214
-
215
- self.destroy = function() {
216
- self.dom.form.each(function(index, elem) {
217
- $(elem).off('submit');
218
- });
219
- self.dom.modal_overlay.off('click');
220
- self.dom.btn_close.off('click');
221
- self.dom.btn_next.off('click');
222
- self.dom.btn_prev.off('click');
223
- self.dom.container.remove();
224
- };
225
-
226
- /**
227
- * Load template and register event handlers
228
- * no param
229
- */
230
- self.init = function() {
231
- $('body').append(template);
232
- self.parseSelectors();
233
- self.dom.modal_footer.show();
234
- self.dom.form.each(function(index, elem) {
235
- $(elem).on('submit', self.onSubmit);
236
- });
237
- self.dom.modal_overlay.on('click', self.close);
238
- self.dom.btn_close.on('click', self.close);
239
- self.dom.btn_next.on('click', self.nextPage);
240
- self.dom.btn_prev.on('click', self.prevPage);
241
- };
242
-
243
- self.init();
244
- };
245
-
246
- var template = '<div id="u-search"><div class="modal"> <header class="modal-header" class="clearfix"><form id="u-search-modal-form" class="u-search-form" name="uSearchModalForm"> <input type="text" id="u-search-modal-input" class="u-search-input" /> <button type="submit" id="u-search-modal-btn-submit" class="u-search-btn-submit"> <span class="fas fa-search"></span> </button></form> <a class="btn-close"> <span class="fas fa-times"></span> </a><div class="modal-loading"><div class="modal-loading-bar"></div></div> </header> <main class="modal-body"><ul class="modal-results modal-ajax-content"></ul> </main> <footer class="modal-footer clearfix"><div class="modal-metadata modal-ajax-content"> <strong class="range"></strong> of <strong class="total"></strong></div><div class="modal-error"></div> <div class="logo"></div> <a class="nav btn-next modal-ajax-content"> <span class="text">NEXT</span> <span class="fal fa-chevron-right"></span> </a> <a class="nav btn-prev modal-ajax-content"> <span class="fal fa-chevron-left"></span> <span class="text">PREV</span> </a> </footer></div><div class="modal-overlay"></div></div>';
247
- })(jQuery);
248
-
249
- var GoogleCustomSearch = '';
250
- (function($) {
251
- 'use strict';
252
-
253
- /**
254
- * Search by Google Custom Search Engine JSON API
255
- * @param options : (object)
256
- */
257
- GoogleCustomSearch = function(options) {
258
- SearchService.apply(this, arguments);
259
- var self = this;
260
- var endpoint = 'https://www.googleapis.com/customsearch/v1';
261
- self.addLogo('google');
262
-
263
- /**
264
- * Generate result list html
265
- * @param data : (array) result items
266
- */
267
- self.buildResultList = function(data) {
268
- var html = '';
269
- $.each(data, function(index, row) {
270
- var url = row.link;
271
- var title = row.title;
272
- var digest = (row.htmlSnippet || '').replace('<br>', '');
273
- html += self.buildResult(url, title, digest);
274
- });
275
- html += '<script>try{pjax.refresh(document.querySelector(\'#u-search\'));document.addEventListener(\'pjax:send\',function(){$(\'#u-search\').fadeOut(500);$(\'body\').removeClass(\'modal-active\')});}catch(e){$(\'#u-search\').fadeOut(500);}</script>';
276
- return html;
277
- };
278
-
279
- /**
280
- * Generate metadata after a successful query
281
- * @param data : (object) the raw google custom search response data
282
- */
283
- self.buildMetadata = function(data) {
284
- if (data.queries && data.queries.request && data.queries.request[0].totalResults !== '0') {
285
- self.nav.current = data.queries.request[0].startIndex;
286
- self.nav.currentCount = data.queries.request[0].count;
287
- self.nav.total = parseInt(data.queries.request[0].totalResults);
288
- self.dom.modal_metadata.children('.total').html(self.nav.total);
289
- self.dom.modal_metadata.children('.range').html(self.nav.current + '-' + (self.nav.current + self.nav.currentCount - 1));
290
- self.dom.modal_metadata.show();
291
- } else {
292
- self.dom.modal_metadata.hide();
293
- }
294
- if (data.queries && data.queries.nextPage) {
295
- self.nav.next = data.queries.nextPage[0].startIndex;
296
- self.dom.btn_next.show();
297
- } else {
298
- self.nav.next = -1;
299
- self.dom.btn_next.hide();
300
- }
301
- if (data.queries && data.queries.previousPage) {
302
- self.nav.prev = data.queries.previousPage[0].startIndex;
303
- self.dom.btn_prev.show();
304
- } else {
305
- self.nav.prev = -1;
306
- self.dom.btn_prev.hide();
307
- }
308
- };
309
-
310
- /**
311
- * Send a GET request
312
- * @param queryText : (string) the query text
313
- * @param startIndex : (int) the index of first item (start from 1)
314
- * @param callback : (function)
315
- */
316
- self.query = function(queryText, startIndex, callback) {
317
- $.get(endpoint, {
318
- key : self.config.apiKey,
319
- cx : self.config.engineId,
320
- q : queryText,
321
- start: startIndex,
322
- num : self.config.per_page
323
- }, function(data, status) {
324
- if (status === 'success' && data.items && data.items.length > 0) {
325
- var results = self.buildResultList(data.items);
326
- self.dom.modal_results.html(results);
327
- } else {
328
- self.onQueryError(queryText, status);
329
- }
330
- self.buildMetadata(data);
331
- if (callback) {
332
- callback();
333
- }
334
- });
335
- };
336
-
337
- return self;
338
- };
339
- })(jQuery);