Permalink
Browse files

convert into a jquery plugin

  • Loading branch information...
1 parent 4cd19a9 commit 09cad4413475237130c19c4988dab1aea3996c0a Greg Borenstein committed Mar 15, 2009
Showing with 50 additions and 50 deletions.
  1. +0 −50 gaggle.js
  2. +50 −0 jquery.gaggle.js
View
@@ -1,50 +0,0 @@
-GResult = function(resultData){
- this.title = resultData.title;
- this.url = resultData.unescapedUrl;
- this.domain = resultData.visibleUrl;
-};
-
-Gaggle = {
- results : [],
- expectedPages : 0,
-
- processSearchResultsPage : function(data){
- Gaggle.moreResultsUrl = data.responseData.cursor.moreResultsUrl;
- for (i = 0; i < data.responseData.results.length; i++){
- Gaggle.results.push(new GResult(data.responseData.results[i]));
- };
- },
-
- submitQuery : function(q, callback, type, p){
- var currentPage = p || 0;
- var queryType = type || "web";
- var rootUrl = "http://ajax.googleapis.com/ajax/services/search/"+queryType+"?v=1.0&start="+currentPage+"&q=";
- $.getJSON(rootUrl + q + "&callback=?",function(data){
- if(data.responseData){
- Gaggle.expectedPages = Math.ceil(data.responseData.cursor.estimatedResultCount / 4);
- Gaggle.processSearchResultsPage(data);
- } else {
- Gaggle.reachedMax = true;
- callback(Gaggle.results);
- Gaggle.reachedMax = false;
-
- // reset
- Gaggle.results = [];
- Gaggle.expectedPages = 0;
- return false;
- }
-
- if(currentPage + 1 < Gaggle.expectedPages){
- Gaggle.submitQuery(q, callback, queryType, (currentPage + 1));
- }
- else{
- callback(Gaggle.results);
- // reset
- Gaggle.results = [];
- Gaggle.expectedPages = 0;
- }
- return false;
- });
- return false;
- }
-};
View
@@ -0,0 +1,50 @@
+jQuery.gaggle = {
+ results : [],
+ expectedPages : 0,
+
+ gResult : function(resultData){
+ this.title = resultData.title;
+ this.url = resultData.unescapedUrl;
+ this.domain = resultData.visibleUrl;
+ },
+
+ processSearchResultsPage : function(data){
+ jQuery.gaggle.moreResultsUrl = data.responseData.cursor.moreResultsUrl;
+ for (i = 0; i < data.responseData.results.length; i++){
+ jQuery.gaggle.results.push(new jQuery.gaggle.gResult(data.responseData.results[i]));
+ };
+ },
+
+ q : function(query, callback, type, p){
+ var currentPage = p || 0;
+ var queryType = type || "web";
+ var rootUrl = "http://ajax.googleapis.com/ajax/services/search/"+queryType+"?v=1.0&start="+currentPage+"&q=";
+ $.getJSON(rootUrl + query + "&callback=?",function(data){
+ if(data.responseData){
+ jQuery.gaggle.expectedPages = Math.ceil(data.responseData.cursor.estimatedResultCount / 4);
+ jQuery.gaggle.processSearchResultsPage(data);
+ } else {
+ jQuery.gaggle.reachedMax = true;
+ callback(jQuery.gaggle.results);
+ jQuery.gaggle.reachedMax = false;
+
+ // reset
+ jQuery.gaggle.results = [];
+ jQuery.gaggle.expectedPages = 0;
+ return false;
+ }
+
+ if(currentPage + 1 < jQuery.gaggle.expectedPages){
+ jQuery.gaggle.q(query, callback, queryType, (currentPage + 1));
+ }
+ else{
+ callback(jQuery.gaggle.results);
+ // reset
+ jQuery.gaggle.results = [];
+ jQuery.gaggle.expectedPages = 0;
+ }
+ return false;
+ });
+ return false;
+ }
+};

0 comments on commit 09cad44

Please sign in to comment.