bubble的备忘录

本blog主要用于常用资料的备忘、备份、备搜索

源码注释:Custom Search Engines (部分)

google.load('search', '1');

// the cse class encapsulates a left and right search control
// both controls are driven by a shared search form
function cse() {
//创建变量,分别对应搜索框和左右结果框
var sFormDiv = document.getElementById("searchForm");
var leftScDiv = document.getElementById("leftSearchControl");
var rightScDiv = document.getElementById("rightSearchControl");

// create a left, right search control
// create a custom search form
//创建搜索控件,分别对应左右搜索结果框,和搜索输入框
this.leftControl = new google.search.SearchControl();
this.rightControl = new google.search.SearchControl();
this.searchForm = new google.search.SearchForm(true, sFormDiv);

// bind clear and submit functions
//继续创建searchForm对象的后续两个步骤,提交按钮和清除按钮
this.searchForm.setOnSubmitCallback(this, cse.prototype.onSubmit);
this.searchForm.setOnClearCallback(this, cse.prototype.onClear);

// set up for small result sets
//设置结果集大小
this.leftControl.setResultSetSize(google.search.Search.SMALL_RESULTSET);
this.rightControl.setResultSetSize(google.search.Search.SMALL_RESULTSET);

var searcher;
var options;

// configure left control
// Site Restrict to CSE ID for reviews
//配置左边的搜索引擎,使用定制的个性化搜索引擎作为限定站点
searcher = new google.search.WebSearch();
options = new google.search.SearcherOptions();
searcher.setSiteRestriction("000455696194071821846:reviews");
//该搜索引擎就是000455696194071821846:reviews,其中reviews不是搜索引擎内的标签
searcher.setUserDefinedLabel("Product Reviews");
options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);//设置结果展示模式
this.leftControl.addSearcher(searcher, options);

// configure right control for
// -- cse for comparisons
// -- cse for community
// -- cse for shopping
// -- blog search
// -- news search
//配置右边的搜索引擎,设置了六个搜索引擎
searcher = new google.search.WebSearch();
options = new google.search.SearcherOptions();
searcher.setSiteRestriction("000455696194071821846:comparisons");
searcher.setUserDefinedLabel("Prices");
this.rightControl.addSearcher(searcher, options);

searcher = new google.search.WebSearch();
options = new google.search.SearcherOptions();
searcher.setSiteRestriction("000455696194071821846:community");
searcher.setUserDefinedLabel("Forums");
this.rightControl.addSearcher(searcher, options);

searcher = new google.search.WebSearch();
options = new google.search.SearcherOptions();
searcher.setSiteRestriction("000455696194071821846:shopping");
searcher.setUserDefinedLabel("Shopping");
this.rightControl.addSearcher(searcher, options);

searcher = new google.search.BlogSearch();
this.rightControl.addSearcher(searcher);

searcher = new google.search.WebSearch();
this.rightControl.addSearcher(searcher);

searcher = new google.search.NewsSearch();
this.rightControl.addSearcher(searcher);

// draw the left and right controls
// the right control is drawn in tabbed mode
//绘制结果,使用标签模式排列
var drawOptions = new google.search.DrawOptions();
drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);

this.leftControl.draw(leftScDiv);
this.rightControl.draw(rightScDiv, drawOptions);

// bind in a videobar
//绑定视频搜索结果显示框,和视频播放框
var videoBarDiv = document.getElementById("videoBar");
var videoPlayerDiv = document.getElementById("videoPlayer")
var vboptions = {
largeResultSet : false,
horizontal : true
}

this.videoBar = new GSvideoBar(videoBarDiv, videoPlayerDiv, vboptions);
//同时设置视频搜索和播放框

// execute a starter search
this.searchForm.execute("Apple iPod");

}

// when the form fires a submit, grab its
// value and call the left and right control
//设置搜索按钮
//当从搜索输入框接收到搜索请求之后,同时调用搜索左右搜索框以及视频搜索框
cse.prototype.onSubmit = function(form) {
var q = form.input.value;
if (q && q!= "") {
this.leftControl.execute(q);
this.rightControl.execute(q);
this.videoBar.execute(q);
}
return false;
}

// when the form fires a clear, call the left and right control
//设置清除按钮
cse.prototype.onClear = function(form) {
this.leftControl.clearAllResults();
this.rightControl.clearAllResults();
this.videoBar.clearAllResults();
form.input.value = "";
return false;
}

function OnLoad() {
new cse();
}
google.setOnLoadCallback(OnLoad, true);

0 评论: