c5ed4aa9f69d3e1b73bfb31fbb1b985301a418b2
1 $
(document
).ready(function(){
4 siteURL
: 'www.bulletin.auf.org', // Change this to your site
8 perPage
: 8, // A maximum of 8 is allowed by Google
9 page
: 0 // The start page
12 // The small arrow that marks the active search icon:
13 var arrow
= $
('<span>',{className
:'arrow'}).appendTo('ul.icons');
15 $
('ul.icons li').click(function(){
18 if(el
.hasClass('active')){
19 // The icon is already active, exit
23 el
.siblings().removeClass('active');
24 el
.addClass('active');
26 // Move the arrow below this icon
27 arrow
.stop().animate({
28 left
: el
.position().left
,
29 marginLeft
: (el
.width()/1)-4
32 // Set the search type
33 config
.type
= el
.attr('data-searchType');
37 // Adding the site domain as a label for the first radio button:
38 $
('#siteNameLabel').append(' '+config
.siteURL
);
40 // Marking the Search tutorialzine.com radio as active:
41 $
('#searchSite').click();
43 // Marking the web search icon as active:
46 // Focusing the input text box:
49 $
('#searchForm').submit(function(){
54 $
('#searchSite,#searchWeb').change(function(){
55 // Listening for a click on one of the radio buttons.
56 // config.searchSite is either true or false.
58 config
.searchSite
= this.id
== 'searchSite';
62 function googleSearch(settings
){
64 // If no parameters are supplied to the function,
65 // it takes its defaults from the config object above:
67 settings
= $
.extend({},config
,settings
);
68 settings
.term
= settings
.term || $
('#s').val();
70 if(settings
.searchSite
){
71 // Using the Google site:example.com to limit the search to a
73 settings
.term
= 'site:'+settings
.siteURL
+' '+settings
.term
;
76 // URL of Google's AJAX search API
77 var apiURL
= 'http://ajax.googleapis.com/ajax/services/search/'+settings
.type
+'?v=1.0&callback=?';
78 var resultsDiv
= $
('#resultsDiv');
80 $
.getJSON(apiURL
,{q
:settings
.term
,rsz
:settings
.perPage
,start
:settings
.page
*settings
.perPage
},function(r
){
82 var results
= r
.responseData
.results
;
87 // If results were returned, add them to a pageContainer div,
88 // after which append them to the #resultsDiv:
90 var pageContainer
= $
('<div>',{className
:'pageContainer'});
92 for(var i
=0;i
<results
.length
;i
++){
93 // Creating a new result object and firing its toString method:
94 pageContainer
.append(new result(results
[i]) + '');
98 // This is executed when running a new search,
99 // instead of clicking on the More button:
103 pageContainer
.append('<div class="clear"></div>')
104 .hide().appendTo(resultsDiv
)
107 var cursor
= r
.responseData
.cursor
;
109 // Checking if there are more pages with results,
110 // and deciding whether to show the More button:
112 if( +cursor
.estimatedResultCount
> (settings
.page
+1)*settings
.perPage
){
113 $
('<div>',{id
:'more'}).appendTo(resultsDiv
).click(function(){
114 googleSearch({append
:true,page
:settings
.page
+1});
121 // No results were found for this search.
124 $
('<p>',{className
:'notFound',html
:'Aucun résultat'}).hide().appendTo(resultsDiv
).fadeIn();
131 // This is class definition. Object of this class are created for
132 // each result. The markup is generated by the .toString() method.
136 // GsearchResultClass is passed by the google API
137 switch(r
.GsearchResultClass
){
141 '<div class="webResult">',
142 '<h2><a href="',r
.unescapedUrl
,'" target="_blank">',r
.title
,'</a></h2>',
143 '<p>',r
.content
,'</p>',
144 '<a href="',r
.unescapedUrl
,'" target="_blank">',r
.visibleUrl
,'</a>',
150 '<div class="imageResult">',
151 '<a target="_blank" href="',r
.unescapedUrl
,'" title="',r
.titleNoFormatting
,'" class="pic" style="width:',r
.tbWidth
,'px;height:',r
.tbHeight
,'px;">',
152 '<img src="',r
.tbUrl
,'" width="',r
.tbWidth
,'" height="',r
.tbHeight
,'" /></a>',
153 '<div class="clear"></div>','<a href="',r
.originalContextUrl
,'" target="_blank">',r
.visibleUrl
,'</a>',
159 '<div class="imageResult">',
160 '<a target="_blank" href="',r
.url
,'" title="',r
.titleNoFormatting
,'" class="pic" style="width:150px;height:auto;">',
161 '<img src="',r
.tbUrl
,'" width="100%" /></a>',
162 '<div class="clear"></div>','<a href="',r
.originalContextUrl
,'" target="_blank">',r
.publisher
,'</a>',
168 '<div class="webResult">',
169 '<h2><a href="',r
.unescapedUrl
,'" target="_blank">',r
.title
,'</a></h2>',
170 '<p>',r
.content
,'</p>',
171 '<a href="',r
.unescapedUrl
,'" target="_blank">',r
.publisher
,'</a>',
177 // The toString method.
178 this.toString
= function(){