diff --git a/.jshintrc b/.jshintrc
index 5e076bb..698262e 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -10,9 +10,11 @@
"describe",
"before",
"after",
- "should"
+ "should",
+ "$"
],
+ "browser": true,
"node" : true,
"es5": true,
"bitwise": true,
diff --git a/config.default.js b/config.default.js
index 6b168c5..c743184 100644
--- a/config.default.js
+++ b/config.default.js
@@ -18,6 +18,7 @@ exports.config = {
[ '/about', '关于' ],
],
site_static_host: '', // 静态文件存储域名
+ site_enable_search_preview: false, // 开启google search preview
db: 'mongodb://127.0.0.1/node_club_dev',
session_secret: 'node_club',
diff --git a/public/javascripts/google_search_preview.js b/public/javascripts/google_search_preview.js
new file mode 100644
index 0000000..3b46a4e
--- /dev/null
+++ b/public/javascripts/google_search_preview.js
@@ -0,0 +1,44 @@
+$(function () {
+ var id = -1;
+ var start = function () {
+ id = setInterval(check, 1000);
+ };
+ var old = '';
+ var check = function () {
+ var q = $in.val().trim();
+ if (q === '' || old === q) {
+ return;
+ }
+ old = q;
+ var url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=site:cnodejs.org+' + q + '&callback=?';
+ $.getJSON(url, function (d) {
+ if (!(d.responseData && Array.isArray(d.responseData.results))) {
+ return;
+ }
+ var list = d.responseData.results;
+ showList(list);
+ });
+ };
+ var stop = function () {
+ clearInterval(id);
+ $list.slideUp(500);
+ };
+ var $in = $('input#q');
+ $in.focusin(start).focusout(stop);
+ $in.after('
')
+ .after('');
+ var $list = $('#__quick_search_list');
+ var showList = function (list) {
+ var html = '';
+ list.forEach(function (line) {
+ html += '