/** * jQuery gComplete v0.1.2 - autocomplete using "Google Web API" * * Terms of Use - jQuery gComplete * under the MIT (http://www.opensource.org/licenses/mit-license.php) License. * * Copyright 2010 xlune.com All rights reserved. * (http://blog.xlune.com/2010/02/jquerygcomplete.html) */ (function ($) { $.fn.extend({ gcomplete: function(option) { var _self = $(this); if(_self.length == 0 ){ return; }; var _tag = _self.get(0).tagName.toLowerCase(); if(_tag == "input" && _self.attr("type") == "text") { /* vars */ var _opt,_win,_intval; var gurl='http://clients1.'+ wp_keyword_tool_google +'/complete/search'; if (location.protocol === 'https:') { // page is secure gurl='https://clients1.'+ wp_keyword_tool_google +'/complete/search'; } var _prefix = "gcomplete-"; var def_option = { style: "default", url: gurl, query_key: "q", param: { output: "json", client:"firefox" }, limit: 50, cycle: 500, effect: false, oneword: false, callbackUseOnlyString: false, parseFunc: function(result) { return result[1]; } }; /* funcs */ function cycleStart() { _intval = setInterval(cycleEngine, getOption('cycle')); $.browser.mozilla ? _self.keypress(keyPress) : _self.keydown(keyPress); if(typeof(_self.mousewheel)=="function") { _self.mousedown(mouseDown); $(window).mousewheel(mouseWheel); } }; function cycleStop() { clearInterval(_intval); _opt.param[_opt.query_key] = ""; hideWindow(); $.browser.mozilla ? _self.unbind("keypress", keyPress) : _self.unbind("keydown", keyPress); if(typeof(_self.mousewheel)=="function") { _self.unbind("mousedown", mouseDown); $(window).unbind("mousewheel", mouseWheel); } }; function cycleEngine() { var str = _self.val(); if(str.length > 0 && str.replace(/ +$/, "") != _opt.param[_opt.query_key].replace(/ +$/, "")) { request(str); } else if(str.length <= 0) { hideWindow(); } }; function request(query) { var param = {}; _opt.param[_opt.query_key] = query; for(var i in _opt.param) { param[i] = _opt.param[i]; } if(getOption('oneword')) { param[_opt.query_key] = query.split(" ").pop(); if(!param[_opt.query_key]) { hideWindow(); return false; } } if(getOption("callbackUseOnlyString")) { var script = $("#__gcompleteaccess"); var key = "gcompletef"+getUniqueString(); param['callback'] = key; window[key] = callBack; if(script.size() > 0) { script.attr("src", _opt.url + "?" + $.param(param)); } else { $("