This commit is contained in:
Tom Morris 2013-06-11 15:31:23 -04:00
commit 1445984113
15 changed files with 388 additions and 291 deletions

6
.travis.yml Normal file
View File

@ -0,0 +1,6 @@
language: java
jdk:
- oraclejdk7
- openjdk6
script: ./refine test

View File

@ -101,7 +101,7 @@ SchemaAlignment._batchSearch = function(queries, onDone) {
// TODO: New API doesn't accept multiple queries
// args.push("https://www.googleapis.com/freebase/v1/search?key=" + Freebase.API_KEY + "&" +
args.push("http://api.freebase.com/api/service/search?" +
args.push("http://api.freebase.com/api/service/search?" + // FIXME:
$.param({ "queries" : JSON.stringify(batch) }) + "&callback=?");
args.push(null); // no data

View File

@ -40,6 +40,8 @@ import java.io.StringWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
@ -250,6 +252,10 @@ public class StandardReconConfig extends ReconConfig {
jsonWriter.key("id"); jsonWriter.value(cell2.recon.match.id);
jsonWriter.key("name"); jsonWriter.value(cell2.recon.match.name);
jsonWriter.endObject();
} else if (cell2.value instanceof Calendar) {
jsonWriter.value(ParsingUtilities.dateToString(((Calendar) cell2.value).getTime()));
} else if (cell2.value instanceof Date) {
jsonWriter.value(ParsingUtilities.dateToString((Date) cell2.value));
} else {
jsonWriter.value(cell2.value.toString());
}

View File

@ -160,7 +160,8 @@ public class KeyValueColumnizeOperation extends AbstractOperation {
String keyString = key.toString();
// Start a new row on our beginning of record key
if (keyString.equals(recordKey)) {
// TODO: Add support for processing in record mode instead of just by rows
if (keyString.equals(recordKey) || recordKey == null) {
reusableRow = new Row(newColumns.size());
newRows.add(reusableRow);
currentRows.clear();

View File

@ -222,6 +222,7 @@ public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperat
List<CellAtRow> responseBodies = new ArrayList<CellAtRow>(urls.size());
for (int i = 0; i < urls.size(); i++) {
CellAtRow urlData = urls.get(i);
long start = System.currentTimeMillis();
CellAtRow cellAtRow = fetch(urlData);
if (cellAtRow != null) {
responseBodies.add(cellAtRow);
@ -229,7 +230,10 @@ public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperat
_progress = i * 100 / urls.size();
try {
Thread.sleep(_delay);
long delay = _delay - (System.currentTimeMillis() - start);
if (delay > 0) {
Thread.sleep(delay);
}
} catch (InterruptedException e) {
if (_canceled) {
break;

View File

@ -54,7 +54,7 @@ import org.json.JSONTokener;
public class ParsingUtilities {
static final public SimpleDateFormat s_sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
static final public SimpleDateFormat ISO8601_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
static public Properties parseUrlParameters(HttpServletRequest request) {
Properties options = new Properties();
@ -136,6 +136,9 @@ public class ParsingUtilities {
}
private static final URLCodec codec = new URLCodec();
/**
* Encode a string as UTF-8.
*/
static public String encode(String s) {
try {
return codec.encode(s, "UTF-8");
@ -143,6 +146,10 @@ public class ParsingUtilities {
return s; // should not happen
}
}
/**
* Decode a string from UTF-8 encoding.
*/
static public String decode(String s) {
try {
return codec.decode(s, "UTF-8");
@ -153,13 +160,25 @@ public class ParsingUtilities {
}
}
/**
* Convert a date/time to an ISO 8601 string
*
* @param d the date to be written
* @return string with ISO 8601 formatted date & time
*/
static public String dateToString(Date d) {
return s_sdf.format(d);
return ISO8601_FORMAT.format(d);
}
/**
* Parse an ISO 8601 formatted string into a Java Date.
*
* @param s the string to be parsed
* @return Date or null if the parse failed
*/
static public Date stringToDate(String s) {
try {
return s_sdf.parse(s);
return ISO8601_FORMAT.parse(s);
} catch (ParseException e) {
return null;
}

View File

@ -380,7 +380,7 @@ function init() {
"externals/jquery-1.7.2.min.js",
"externals/jquery.cookie.js",
"externals/jquery.eventstack-0.3.js",
"externals/suggest/suggest-4_1.min.js",
"externals/suggest/suggest-4_2.min.js",
"externals/jquery-ui/jquery-ui-1.8.20.custom.min.js",
"externals/imgareaselect/jquery.imgareaselect.js",
"externals/date.js",
@ -445,7 +445,7 @@ function init() {
"project/styles",
module,
[
"externals/suggest/css/suggest-4_1.min.css",
"externals/suggest/css/suggest-4_2.min.css",
"externals/jquery-ui/css/ui-lightness/jquery-ui-1.8.20.custom.css",
"externals/imgareaselect/css/imgareaselect-default.css",
@ -485,7 +485,7 @@ function init() {
[
"externals/jquery-1.7.2.min.js",
"externals/jquery.cookie.js",
"externals/suggest/suggest-4_1.min.js",
"externals/suggest/suggest-4_2.min.js",
"externals/jquery-ui/jquery-ui-1.8.20.custom.min.js",
"externals/imgareaselect/jquery.imgareaselect.js",
"externals/date.js",
@ -496,7 +496,7 @@ function init() {
"preferences/styles",
module,
[
"externals/suggest/css/suggest-4_1.min.css",
"externals/suggest/css/suggest-4_2.min.css",
"externals/jquery-ui/css/ui-lightness/jquery-ui-1.8.20.custom.css",
"styles/jquery-ui-overrides.less",
"styles/common.less",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -158,6 +158,12 @@ li.fbs-selected .fbs-item-name {
color: #aaa;
}
.fbs-citation {
white-space: nowrap;
color: #999;
font-size: 11px;
}
/* topic image */
#fbs-topic-image,
.fbs-flyout-images {
@ -499,6 +505,8 @@ h3.fbs-topic-properties {
.fbs-flyout-pane p {
font-size: 1.2em;
line-height: 1.4;
max-height: 10em;
overflow: auto;
}
/* this class is applied with fbs-topic-flyout when a thumbnail is present

File diff suppressed because one or more lines are too long

View File

@ -1,81 +0,0 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Additional Licenses for Third Party components can be found here:
* http://wiki.freebase.com/wiki/Freebase_Site_License
*
*/
(function(c,q){if(!("console"in window)){var o=window.console={};o.log=o.warn=o.error=o.debug=function(){}}c(function(){var a=c("<div>");c(document.body).append(a);var b=setTimeout(function(){if(c.cleanData){var a=c.cleanData;c.cleanData=function(b){for(var e=0,g;null!=(g=b[e]);e++)c(g).triggerHandler("remove");a(b)}}else{var b=c.fn.remove;c.fn.remove=function(a,f){return this.each(function(){f||(!a||c.filter(a,[this]).length)&&c("*",this).add([this]).each(function(){c(this).triggerHandler("remove")});
return b.call(c(this),a,f)})}}},1);a.bind("remove",function(){clearTimeout(b)});a.remove()});var p={key:1,filter:1,spell:1,exact:1,lang:1,scoring:1,prefixed:1,stemmed:1,format:1,mql_output:1,output:1,type:1};c.suggest=function(a,b){c.fn[a]=function(b){this.length||console.warn("Suggest: invoked on empty element set");return this.each(function(){this.nodeName&&("INPUT"===this.nodeName.toUpperCase()?this.type&&"TEXT"!==this.type.toUpperCase()&&console.warn("Suggest: unsupported INPUT type: "+this.type):console.warn("Suggest: unsupported DOM element: "+
this.nodeName));var g=c.data(this,a);g&&g._destroy();c.data(this,a,new c.suggest[a](this,b))._init()})};c.suggest[a]=function(b,g){var d=this,e=this.options=c.extend(!0,{},c.suggest.defaults,c.suggest[a].defaults,g),j=e.css_prefix=e.css_prefix||"",h=e.css;this.name=a;c.each(h,function(a){h[a]=j+h[a]});e.ac_param={};c.each(p,function(a){var b=e[a];null===b||""===b||(e.ac_param[a]=b)});e.flyout_lang=null;if(e.ac_param.lang){var i=e.ac_param.lang;"string"===c.type(i)&&(i=i.split(","));if(c.isArray(i)&&
i.length&&(i=c.trim(i[0])))e.flyout_lang=i}this._status={START:"",LOADING:"",SELECT:"",ERROR:""};e.status&&(e.status instanceof Array&&3<=e.status.length)&&(this._status.START=e.status[0]||"",this._status.LOADING=e.status[1]||"",this._status.SELECT=e.status[2]||"",4===e.status.length&&(this._status.ERROR=e.status[3]||""));var i=this.status=c('<div style="display:none;">').addClass(h.status),k=this.list=c("<ul>").addClass(h.list),l=this.pane=c('<div style="display:none;" class="fbs-reset">').addClass(h.pane);
l.append(i).append(k);e.parent?c(e.parent).append(l):(l.css("position","absolute"),e.zIndex&&l.css("z-index",e.zIndex),c(document.body).append(l));l.bind("mousedown",function(a){d.input.data("dont_hide",true);a.stopPropagation()}).bind("mouseup",function(a){d.input.data("dont_hide")&&d.input.focus();d.input.removeData("dont_hide");a.stopPropagation()}).bind("click",function(a){a.stopPropagation();if(a=d.get_selected()){d.onselect(a,true);d.hide_all()}});k.hover(function(a){d.hoverover_list(a)},function(a){d.hoverout_list(a)});
this.input=c(b).attr("autocomplete","off").unbind(".suggest").bind("remove.suggest",function(){d._destroy()}).bind("keydown.suggest",function(a){d.keydown(a)}).bind("keypress.suggest",function(a){d.keypress(a)}).bind("keyup.suggest",function(a){d.keyup(a)}).bind("blur.suggest",function(a){d.blur(a)}).bind("textchange.suggest",function(){d.textchange()}).bind("focus.suggest",function(a){d.focus(a)}).bind(c.browser.msie?"paste.suggest":"input.suggest",function(){clearTimeout(d.paste_timeout);d.paste_timeout=
setTimeout(function(){d.textchange()},0)});this.onresize=function(){d.invalidate_position();if(l.is(":visible")){d.position();if(e.flyout&&d.flyoutpane&&d.flyoutpane.is(":visible")){var a=d.get_selected();a&&d.flyout_position(a)}}};c(window).bind("resize.suggest",this.onresize).bind("scroll.suggest",this.onresize)};c.suggest[a].prototype=c.extend({},c.suggest.prototype,b)};c.suggest.prototype={_init:function(){},_destroy:function(){this.pane.remove();this.list.remove();this.input.unbind(".suggest");
c(window).unbind("resize.suggest",this.onresize).unbind("scroll.suggest",this.onresize);this.input.removeData("data.suggest")},invalidate_position:function(){self._position=null},status_start:function(){this.hide_all();this.status.siblings().hide();this._status.START&&(this.status.text(this._status.START).show(),this.pane.is(":visible")||(this.position(),this.pane_show()));this._status.LOADING&&this.status.removeClass("loading")},status_loading:function(){this.status.siblings().show();this._status.LOADING?
(this.status.addClass("loading").text(this._status.LOADING).show(),this.pane.is(":visible")||(this.position(),this.pane_show())):this.status.hide()},status_select:function(){this.status.siblings().show();this._status.SELECT?this.status.text(this._status.SELECT).show():this.status.hide();this._status.LOADING&&this.status.removeClass("loading")},status_error:function(){this.status.siblings().show();this._status.ERROR?this.status.text(this._status.ERROR).show():this.status.hide();this._status.LOADING&&
this.status.removeClass("loading")},focus:function(a){""===this.input.val()?this.status_start():this.focus_hook(a)},focus_hook:function(){!this.input.data("data.suggest")&&(!this.pane.is(":visible")&&c("."+this.options.css.item,this.list).length)&&(this.position(),this.pane_show())},keydown:function(a){var b=a.keyCode;if(9===b)this.tab(a);else if(38===b||40===b)a.shiftKey||a.preventDefault()},keypress:function(a){var b=a.keyCode;38===b||40===b?a.shiftKey||a.preventDefault():13===b&&this.enter(a)},
keyup:function(a){var b=a.keyCode;if(38===b)a.preventDefault(),this.up(a);else if(40===b)a.preventDefault(),this.down(a);else if(a.ctrlKey&&77===b)c(".fbs-more-link",this.pane).click();else if(c.suggest.is_char(a)){clearTimeout(this.keypress.timeout);var f=this;this.keypress.timeout=setTimeout(function(){f.textchange()},0)}else 27===b&&this.escape(a);return!0},blur:function(){this.input.data("dont_hide")||(this.input.data("data.suggest"),this.hide_all())},tab:function(a){if(!a.shiftKey&&!a.metaKey&&
!a.ctrlKey){var a=this.options,a=this.pane.is(":visible")&&c("."+a.css.item,this.list).length,b=this.get_selected();a&&b&&(this.onselect(b),this.hide_all())}},enter:function(a){var b=this.options;this.pane.is(":visible")&&(a.shiftKey?(this.shift_enter(a),a.preventDefault()):c("."+b.css.item,this.list).length&&((b=this.get_selected())?(this.onselect(b),this.hide_all(),a.preventDefault()):(this.input.data("data.suggest"),c("."+this.options.css.item+":visible",this.list).length&&(this.updown(!1),a.preventDefault()))))},
shift_enter:function(){},escape:function(){this.hide_all()},up:function(a){this.updown(!0,a.ctrlKey||a.shiftKey)},down:function(a){this.updown(!1,null,a.ctrlKey||a.shiftKey)},updown:function(a,b,f){var g=this.options.css,d=this.list;if(this.pane.is(":visible")){var e=c("."+g.item+":visible",d);if(e.length){var d=c(e[0]),e=c(e[e.length-1]),j=this.get_selected()||[];clearTimeout(this.ignore_mouseover.timeout);this._ignore_mouseover=!1;a?b?this._goto(d):j.length?j[0]==d[0]?(d.removeClass(g.selected),
this.input.val(this.input.data("original.suggest")),this.hoverout_list()):(a=j.prevAll("."+g.item+":visible:first"),this._goto(a)):this._goto(e):f?this._goto(e):j.length?j[0]==e[0]?(e.removeClass(g.selected),this.input.val(this.input.data("original.suggest")),this.hoverout_list()):(a=j.nextAll("."+g.item+":visible:first"),this._goto(a)):this._goto(d)}}else a||this.textchange()},_goto:function(a){a.trigger("mouseover.suggest");var b=a.data("data.suggest");this.input.val(b?b.name:this.input.data("original.suggest"));
this.scroll_to(a)},scroll_to:function(a){var b=this.list,c=b.scrollTop(),g=c+b.innerHeight(),d=a.outerHeight(),a=a.prevAll().length*d,d=a+d;a<c?(this.ignore_mouseover(),b.scrollTop(a)):d>g&&(this.ignore_mouseover(),b.scrollTop(c+d-g))},textchange:function(){this.input.removeData("data.suggest");this.input.trigger("fb-textchange",this);var a=this.input.val();""===a?this.status_start():(this.status_loading(),this.request(a))},request:function(){},response:function(a){if(a&&("cost"in a&&this.trackEvent(this.name,
"response","cost",a.cost),this.check_response(a))){var b=[];c.isArray(a)?b=a:"result"in a&&(b=a.result);var f=c.map(arguments,function(a){return a});this.response_hook.apply(this,f);var g=null,d=this,e=this.options;c.each(b,function(b,c){if(!c.id&&c.mid)c.id=c.mid;var f=d.create_item(c,a).bind("mouseover.suggest",function(a){d.mouseover_item(a)});f.data("data.suggest",c);d.list.append(f);b===0&&(g=f)});this.input.data("original.suggest",this.input.val());if(0===c("."+e.css.item,this.list).length&&
e.nomatch){b=c('<li class="fbs-nomatch">');if("string"===typeof e.nomatch)b.text(e.nomatch);else if(e.nomatch.title&&b.append(c('<em class="fbs-nomatch-text">').text(e.nomatch.title)),e.nomatch.heading&&b.append(c("<h3>").text(e.nomatch.heading)),(e=e.nomatch.tips)&&e.length){var j=c('<ul class="fbs-search-tips">');c.each(e,function(a,b){j.append(c("<li>").text(b))});b.append(j)}b.bind("click.suggest",function(a){a.stopPropagation()});this.list.append(b)}f.push(g);this.show_hook.apply(this,f);this.position();
this.pane_show()}},pane_show:function(){var a=!1;c("> li",this.list).length&&(a=!0);a||this.pane.children(":not(."+this.options.css.list+")").each(function(){if("none"!=c(this).css("display"))return a=!0,!1});if(a)if(this.options.animate){var b=this;this.pane.slideDown("fast",function(){b.input.trigger("fb-pane-show",b)})}else this.pane.show(),this.input.trigger("fb-pane-show",this);else this.pane.hide(),this.input.trigger("fb-pane-hide",this)},create_item:function(a){var b=this.options.css,f=c("<li>").addClass(b.item),
a=c("<label>").text(a.name);f.append(c("<div>").addClass(b.item_name).append(a));return f},mouseover_item:function(a){if(!this._ignore_mouseover){a=a.target;"li"!==a.nodeName.toLowerCase()&&(a=c(a).parents("li:first"));var b=c(a),f=this.options.css;c("."+f.item,this.list).each(function(){this!==b[0]&&c(this).removeClass(f.selected)});b.hasClass(f.selected)||(b.addClass(f.selected),this.mouseover_item_hook(b))}},mouseover_item_hook:function(){},hoverover_list:function(){},hoverout_list:function(){},
check_response:function(){return!0},response_hook:function(){this.list.empty()},show_hook:function(){this.status_select()},position:function(){var a=this.pane,b=this.options;if(!b.parent){if(!self._position){var f=this.input,g=f.offset(),d=f.outerWidth(!0),e=f.outerHeight(!0);g.top+=e;var j=a.outerWidth(),h=a.outerHeight(),i=g.top+h/2,k=c(window).scrollLeft(),f=c(window).scrollTop(),l=c(window).width(),n=c(window).height()+f,m=!0;"left"==b.align?m=!0:"right"==b.align?m=!1:g.left>k+l/2&&(m=!1);m||
(m=g.left-(j-d),m>k&&(g.left=m));i>n&&(b=g.top-e-h,b>f&&(g.top=b));this._position=g}a.css({top:this._position.top,left:this._position.left})}},ignore_mouseover:function(){this._ignore_mouseover=!0;var a=this;this.ignore_mouseover.timeout=setTimeout(function(){a.ignore_mouseover_reset()},1E3)},ignore_mouseover_reset:function(){this._ignore_mouseover=!1},get_selected:function(){var a=null,b=this.options.css.selected;c("li",this.list).each(function(){var f=c(this);if(f.hasClass(b)&&f.is(":visible"))return a=
f,!1});return a},onselect:function(a){var b=a.data("data.suggest");b&&(this.input.val(b.name).data("data.suggest",b).trigger("fb-select",b),this.trackEvent(this.name,"fb-select","index",a.prevAll().length))},trackEvent:function(a,b,c,g){this.input.trigger("fb-track-event",{category:a,action:b,label:c,value:g})},hide_all:function(){this.pane.hide();this.input.trigger("fb-pane-hide",this)}};c.extend(c.suggest,{defaults:{status:["Start typing to get suggestions...","Searching...","Select an item from the list:",
"Sorry, something went wrong. Please try again later"],soft:!1,nomatch:"no matches",css:{pane:"fbs-pane",list:"fbs-list",item:"fbs-item",item_name:"fbs-item-name",selected:"fbs-selected",status:"fbs-status"},css_prefix:null,parent:null,animate:!1,zIndex:null},strongify:function(a,b){var f,g=a.toLowerCase().indexOf(b.toLowerCase());if(0<=g){var d=b.length;f=document.createTextNode(a.substring(0,g));var e=c("<strong>").text(a.substring(g,g+d)),g=document.createTextNode(a.substring(g+d));f=c("<div>").append(f).append(e).append(g)}else f=
c("<div>").text(a);return f},keyCode:{CAPS_LOCK:20,CONTROL:17,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,INSERT:45,LEFT:37,NUMPAD_ENTER:108,PAGE_DOWN:34,PAGE_UP:33,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38,OPTION:18,APPLE:224},is_char:function(a){if("keypress"===a.type){if((a.metaKey||a.ctrlKey)&&118===a.charCode)return!0;if("isChar"in a)return a.isChar}else{var b=c.suggest.keyCode.not_char;b||(b={},c.each(c.suggest.keyCode,function(a,c){b[""+c]=1}),c.suggest.keyCode.not_char=b);return!(""+a.keyCode in
b)}},parse_input:function(a){for(var b=/(\S+)\:(?:\"([^\"]+)\"|(\S+))/g,f=a,g=[],d={},e=b.exec(a);e;)e[1]in p?d[e[1]]=c.isEmptyObject(e[2])?e[3]:e[2]:g.push(e[0]),f=f.replace(e[0],""),e=b.exec(a);f=c.trim(f.replace(/\s+/g," "));return[f,g,d]},mqlkey_fast:/^[_A-Za-z0-9][A-Za-z0-9_-]*$/,mqlkey_slow:/^(?:[A-Za-z0-9]|\$[A-F0-9]{4})(?:[A-Za-z0-9_-]|\$[A-F0-9]{4})*$/,check_mql_key:function(a){return c.suggest.mqlkey_fast.test(a)||c.suggest.mqlkey_slow.test(a)?!0:!1},check_mql_id:function(a){if(0===a.indexOf("/")){a=
a.split("/");a.shift();if(!(1==a.length&&""===a[0]))for(var b=0,f=a.length;b<f;b++)if(!c.suggest.check_mql_key(a[b]))return!1;return!0}return!1}});var r=c.suggest.prototype._destroy,s=c.suggest.prototype.show_hook;c.suggest("suggest",{_init:function(){var a=this,b=this.options;null==b.flyout_service_url&&(b.flyout_service_url=b.service_url);this.flyout_url=b.flyout_service_url;b.flyout_service_path&&(this.flyout_url+=b.flyout_service_path);this.flyout_url=this.flyout_url.replace(/\$\{key\}/g,b.key);
null==b.flyout_image_service_url&&(b.flyout_image_service_url=b.service_url);this.flyout_image_url=b.flyout_image_service_url;b.flyout_image_service_path&&(this.flyout_image_url+=b.flyout_image_service_path);this.flyout_image_url=this.flyout_image_url.replace(/\$\{key\}/g,b.key);c.suggest.cache||(c.suggest.cache={});if(b.flyout&&(this.flyoutpane=c('<div style="display:none;" class="fbs-reset">').addClass(b.css.flyoutpane),b.flyout_parent?c(b.flyout_parent).append(this.flyoutpane):(this.flyoutpane.css("position",
"absolute"),b.zIndex&&this.flyoutpane.css("z-index",b.zIndex),c(document.body).append(this.flyoutpane)),this.flyoutpane.hover(function(b){a.hoverover_list(b)},function(b){a.hoverout_list(b)}).bind("mousedown.suggest",function(b){b.stopPropagation();a.pane.click()}),c.suggest.flyout||(c.suggest.flyout={}),!c.suggest.flyout.cache))c.suggest.flyout.cache={}},_destroy:function(){r.call(this);this.flyoutpane&&this.flyoutpane.remove();this.input.removeData("request.count.suggest");this.input.removeData("flyout.request.count.suggest")},
shift_enter:function(){this.options.suggest_new&&(this.suggest_new(),this.hide_all())},hide_all:function(){this.pane.hide();this.flyoutpane&&this.flyoutpane.hide();this.input.trigger("fb-pane-hide",this);this.input.trigger("fb-flyoutpane-hide",this)},request:function(a,b){var f=this,g=this.options,d=a,e=g.ac_param.filter||[],j=null;"string"===c.type(e)&&(e=[e]);e=e.slice();if(g.advanced){var h=c.suggest.parse_input(d),d=h[0];h[1].length&&e.push("(all "+h[1].join(" ")+")");j=h[2];c.suggest.check_mql_id(d)&&
(e.push('(all mid:"'+d+'")'),d="")}h={};h[g.query_param_name]=d;b&&(h.cursor=b);c.extend(h,g.ac_param,j);e.length&&(h.filter=e);var i=g.service_url+g.service_path+"?"+c.param(h,!0);if(d=c.suggest.cache[i])this.response(d,b?b:-1,!0);else{clearTimeout(this.request.timeout);var k={url:g.service_url+g.service_path,data:h,traditional:!0,beforeSend:function(){var a=f.input.data("request.count.suggest")||0;a||f.trackEvent(f.name,"start_session");a=a+1;f.trackEvent(f.name,"request","count",a);f.input.data("request.count.suggest",
a)},success:function(d){c.suggest.cache[i]=d;d.prefix=a;f.response(d,b?b:-1)},error:function(a){f.status_error();f.trackEvent(f.name,"request","error",{url:this.url,response:a?a.responseText:""});f.input.trigger("fb-error",Array.prototype.slice.call(arguments))},complete:function(a){a&&f.trackEvent(f.name,"request","tid",a.getResponseHeader("X-Metaweb-TID"))},dataType:"jsonp",cache:!0};this.request.timeout=setTimeout(function(){c.ajax(k)},g.xhr_delay)}},create_item:function(a,b){var f=this.options.css,
g=c("<li>").addClass(f.item),d=c("<label>").append(c.suggest.strongify(a.name||a.id,b.prefix)),e=c("<div>").addClass(f.item_name).append(d);a.under&&c(":first",d).append(c("<small>").text(" ("+a.under+")"));null!=this.options.scoring&&"SCHEMA"===this.options.scoring.toUpperCase()&&c(":first",d).append(c("<small>").text(" ("+a.id+")"));g.append(e);d=a.notable;f=c("<div>").addClass(f.item_type);d&&d.name?f.text(d.name):this.options.show_id&&a.id&&f.text(a.id);e.prepend(f);return g},mouseover_item_hook:function(a){a=
a.data("data.suggest");this.options.flyout&&a&&this.flyout_request(a)},check_response:function(a){return a.prefix===this.input.val()},response_hook:function(a,b){this.flyoutpane&&this.flyoutpane.hide();0<b?c(".fbs-more",this.pane).remove():this.list.empty()},show_hook:function(a,b,f){s.apply(this,[a]);var g=this.options,d=this,e=this.pane,j=this.list,h=a.result,i=c(".fbs-more",e),k=c(".fbs-suggestnew",e);c(".fbs-status",e);var l=a.correction;if(l&&l.length){var n=c('<a class="fbs-spell-link" href="#">').append(l[0]).bind("click.suggest",
function(a){a.preventDefault();a.stopPropagation();d.input.val(l[0]).trigger("textchange")});d.status.empty().append("Search instead for ").append(n).show()}h&&h.length&&"cursor"in a?(i.length||(h=c('<a class="fbs-more-link" href="#" title="(Ctrl+m)">view more</a>'),i=c('<div class="fbs-more">').append(h),h.bind("click.suggest",function(a){a.preventDefault();a.stopPropagation();a=c(this).parent(".fbs-more");d.more(a.data("cursor.suggest"))}),j.after(i)),i.data("cursor.suggest",a.cursor),i.show()):
i.remove();g.suggest_new?(k.length||(a=c('<button class="fbs-suggestnew-button">'),a.text(g.suggest_new),k=c('<div class="fbs-suggestnew">').append('<div class="fbs-suggestnew-description">Your item not in the list?</div>').append(a).append('<span class="fbs-suggestnew-shortcut">(Shift+Enter)</span>').bind("click.suggest",function(a){a.stopPropagation();d.suggest_new(a)}),e.append(k)),k.show()):k.remove();f&&(f.length&&0<b)&&(b=f.prevAll().length*f.outerHeight(),j.scrollTop(),j.animate({scrollTop:b},
"slow",function(){f.trigger("mouseover.suggest")}))},suggest_new:function(){var a=this.input.val();""!==a&&(this.input.data("data.suggest",a).trigger("fb-select-new",a),this.trackEvent(this.name,"fb-select-new","index","new"),this.hide_all())},more:function(a){if(a){var b=this.input.data("original.suggest");null!==b&&this.input.val(b);this.request(this.input.val(),a);this.trackEvent(this.name,"more","cursor",a)}return!1},flyout_request:function(a){var b=this,f=this.options,g=this.flyoutpane.data("data.suggest");
if(g&&a.id===g.id)this.flyoutpane.is(":visible")||(a=this.get_selected(),this.flyout_position(a),this.flyoutpane.show(),this.input.trigger("fb-flyoutpane-show",this));else if((g=c.suggest.flyout.cache[a.id])&&g.id&&g.html)this.flyout_response(g);else{var d=a.id,e={url:this.flyout_url.replace(/\$\{id\}/g,a.id),traditional:!0,beforeSend:function(){var a=b.input.data("flyout.request.count.suggest")||0,a=a+1;b.trackEvent(b.name,"flyout.request","count",a);b.input.data("flyout.request.count.suggest",a)},
success:function(a){a["req:id"]=d;a.html=c.suggest.suggest.create_flyout(a,b.flyout_image_url);c.suggest.flyout.cache[d]=a;b.flyout_response(a)},error:function(a){b.trackEvent(b.name,"flyout","error",{url:this.url,response:a?a.responseText:""})},complete:function(a){a&&b.trackEvent(b.name,"flyout","tid",a.getResponseHeader("X-Metaweb-TID"))},dataType:"jsonp",cache:!0};f.flyout_lang&&(e.data={lang:f.flyout_lang});clearTimeout(this.flyout_request.timeout);this.flyout_request.timeout=setTimeout(function(){c.ajax(e)},
f.xhr_delay);this.input.trigger("fb-request-flyout",e)}},flyout_response:function(a){var b=this.pane,c=this.get_selected()||[];if(b.is(":visible")&&c.length&&(b=c.data("data.suggest"))&&a["req:id"]===b.id&&a.html)this.flyoutpane.html(a.html),this.flyout_position(c),this.flyoutpane.show().data("data.suggest",b),this.input.trigger("fb-flyoutpane-show",this)},flyout_position:function(a){if(!this.options.flyout_parent){var b=this.pane,f=this.flyoutpane,g=this.options.css,d=q,e=parseInt(f.css("top"),10),
j=parseInt(f.css("left"),10),h=b.offset(),i=b.outerWidth(),k=f.outerHeight(),l=f.outerWidth();if("bottom"===this.options.flyout)d=h,i=this.input.offset(),d.top=h.top<i.top?d.top-k:d.top+b.outerHeight(),f.addClass(g.flyoutpane+"-bottom");else{d=a.offset();a=a.outerHeight();d.left+=i;var n=d.left+l,b=c(document.body).scrollLeft(),m=c(window).width()+b;d.top=d.top+a-k;d.top<h.top&&(d.top=h.top);n>m&&(h=d.left-(i+l),h>b&&(d.left=h));f.removeClass(g.flyoutpane+"-bottom")}d.top===e&&d.left===j||f.css({top:d.top,
left:d.left})}},hoverout_list:function(){this.flyoutpane&&!this.get_selected()&&this.flyoutpane.hide()}});c.extend(c.suggest.suggest,{defaults:{filter:null,spell:"always",exact:!1,scoring:null,lang:null,key:null,prefixed:!0,stemmed:null,format:null,advanced:!0,show_id:!0,query_param_name:"query",service_url:"https://www.googleapis.com/freebase/v1",service_path:"/search",align:null,flyout:!0,flyout_service_url:null,flyout_service_path:"/topic${id}?filter=suggest&filter=/common/topic/article&key=${key}",
flyout_image_service_url:null,flyout_image_service_path:"/image${id}?maxwidth=75&key=${key}",flyout_parent:null,suggest_new:null,nomatch:{title:"No suggested matches",heading:"Tips on getting better suggestions:",tips:["Enter more or fewer characters","Add words related to your original search","Try alternate spellings","Check your spelling"]},css:{item_type:"fbs-item-type",flyoutpane:"fbs-flyout-pane"},xhr_delay:200},get_property:function(a,b){var c=a.property;return c?c[b]:null},get_values:function(a,
b){var f=c.suggest.suggest.get_property(a,b);return f&&f.values?f.values:null},get_first_value:function(a,b){var f=c.suggest.suggest.get_values(a,b);return f&&0<f.length?f[0]:null},create_flyout:function(a,b){var f=c.suggest.suggest.get_property,g=c.suggest.suggest.get_values,d=c.suggest.suggest.get_first_value,e=d(a,"/type/object/name");e&&(e=e.text);var j=d(a,"/common/topic/description")||d(a,"/common/topic/article")||!1;j&&(j=j.text);(d=d(a,"/common/topic/image")||!1)&&(d=b.replace(/\$\{id\}/g,
a.id));var h=[],i=[a.id],k=g(a,"/common/topic/notable_properties");k&&c.each(k,function(b,d){var e=f(a,d.id);if(e&&e.valuetype!=="compound")if((e=g(a,d.id))&&e.length){e=c.map(e,function(a){return a.text}).join(", ");h.push([d.text||d.id,e])}});var k=g(a,"/common/topic/notable_for"),l=g(a,"/common/topic/notable_types");if(k||l){var n={},i=[];c.each([k,l],function(a,b){b&&b.forEach(function(a){if(a.id&&!n[a.id]){i.push(a.text);n[a.id]=true}})})}var i=i.join(", "),m=c('<div class="fbs-flyout-content">');
e&&m.append(c('<h1 id="fbs-flyout-title">').text(e));m.append(c('<h3 class="fbs-topic-properties fbs-flyout-id">').text(a.id));c.each(h,function(a,b){m.append(c('<h3 class="fbs-topic-properties">').append(c("<strong>").text(b[0]+": ")).append(document.createTextNode(b[1])))});j&&m.append(c('<p class="fbs-topic-article">').text(j));d&&(m.children().addClass("fbs-flyout-image-true"),m.prepend(c('<img id="fbs-topic-image" class="fbs-flyout-image-true" src="'+d+'">')));e=c('<span class="fbs-flyout-types">').text(i);
e=c('<div class="fbs-attribution">').append(e);return c("<div>").append(m).append(e).html()}});document.createElement("input")})(jQuery);

View File

@ -143,14 +143,11 @@
o.flyout_lang = null;
if (o.ac_param.lang) {
var lang = o.ac_param.lang;
if ($.type(lang) === "string") {
lang = lang.split(",");
}
if ($.isArray(lang) && lang.length) {
lang = $.trim(lang[0]);
if (lang) {
o.flyout_lang = lang;
}
lang = lang.join(',');
}
if (lang) {
o.flyout_lang = lang;
}
}
@ -462,6 +459,7 @@
if (e.shiftKey) {
this.shift_enter(e);
e.preventDefault();
return;
}
else if ($("." + o.css.item, this.list).length) {
var s = this.get_selected();
@ -469,19 +467,29 @@
this.onselect(s);
this.hide_all();
e.preventDefault();
return;
}
else {
else if (!o.soft) {
var data = this.input.data("data.suggest");
if ($("."+this.options.css.item + ":visible", this.list).length) {
this.updown(false);
e.preventDefault();
return;
}
}
}
//console.log("enter preventDefault");
}
if (o.soft) {
// submit form
this.soft_enter();
}
else {
e.preventDefault();
}
},
soft_enter: function(e) {},
shift_enter: function(e) {},
escape: function(e) {
@ -869,7 +877,7 @@
label: label,
value: value
});
console.log("trackEvent", category, action, label, value);
//console.log("trackEvent", category, action, label, value);
},
hide_all: function(e) {
@ -1053,6 +1061,13 @@
else {
return false;
}
},
is_system_type: function(type_id) {
if (type_id == null) {
return false;
}
return (type_id.indexOf("/type/") === 0);
}
});
@ -1076,7 +1091,7 @@
if (o.flyout_service_path) {
this.flyout_url += o.flyout_service_path;
}
// set api key for flyout/topic api
// set api key for flyout service (search)
this.flyout_url = this.flyout_url.replace(/\$\{key\}/g, o.key);
if (o.flyout_image_service_url == null) {
o.flyout_image_service_url = o.service_url;
@ -1179,8 +1194,11 @@
}
extend_ac_param = structured[2];
if ($.suggest.check_mql_id(query)) {
// handle anything that looks like a valid mql id
filter.push("(all mid:\"" + query + "\")");
// handle anything that looks like a valid mql id:
// filter=(all%20alias{start}:/people/pers)&prefixed=true
filter.push("(any alias{start}:\"" + query + "\" mid:\"" +
query + "\")");
extend_ac_param['prefixed'] = true;
query = "";
}
}
@ -1219,7 +1237,6 @@
self.input.data("request.count.suggest", calls);
},
success: function(data) {
// FIXME: bad mql_output param can end up here with data: {'error':{'code':400,'errors':[...],'message':'Type /type/object does not have property lang'}}
$.suggest.cache[url] = data;
data.prefix = val; // keep track of prefix to match up response with input value
self.response(data, cursor ? cursor : -1);
@ -1254,16 +1271,17 @@
.append($.suggest.strongify(data.name || data.id, response_data.prefix));
var name = $("<div>").addClass(css.item_name)
.append(label);
var nt = data.notable;
if (data.under) {
$(":first", label).append($("<small>").text(" ("+data.under+")"));
}
if (this.options.scoring != null &&
this.options.scoring.toUpperCase() === 'SCHEMA') {
if ((nt != null && $.suggest.is_system_type(nt.id)) ||
(this.options.scoring != null &&
this.options.scoring.toUpperCase() === 'SCHEMA')) {
$(":first", label).append($("<small>").text(" ("+data.id+")"));
}
var types = data.type;
li.append(name);
var nt = data.notable;
var type = $("<div>").addClass(css.item_type);
if (nt && nt.name) {
type.text(nt.name);
@ -1450,7 +1468,11 @@
},
success: function(data) {
data["req:id"] = flyout_id;
data.html = $.suggest.suggest.create_flyout(data, self.flyout_image_url);
if (data['result'] && data['result'].length) {
data.html =
$.suggest.suggest.create_flyout(data['result'][0],
self.flyout_image_url);
}
$.suggest.flyout.cache[flyout_id] = data;
self.flyout_response(data);
},
@ -1635,13 +1657,15 @@
flyout_service_url: null,
// flyout_service_url + flyout_service_path =
// url to topic api with filter=suggest
flyout_service_path: "/topic${id}?filter=suggest&filter=/common/topic/article&key=${key}",
// url to search with output=(notable:/client/summary description type).
flyout_service_path: "/search?filter=(all mid:${id})&" +
"output=(notable:/client/summary description type)&key=${key}",
// default is service_url if NULL
flyout_image_service_url: null,
flyout_image_service_path: "/image${id}?maxwidth=75&key=${key}",
flyout_image_service_path:
"/image${id}?maxwidth=75&key=${key}&errorid=/freebase/no_image_png",
// jQuery selector to specify where the flyout
// will be appended to (defaults to document.body).
@ -1675,131 +1699,194 @@
xhr_delay: 200
},
// utility methods to get property, values from the topic api result
get_property: function(topic_result, prop_id) {
var props = topic_result.property;
if (props) {
return props[prop_id];
}
else {
/**
* Utility method to get values of an object specified by one or more
* (nested) keys. For example:
* <code>
* get_value(my_dict, ['foo', 'bar'])
* // Would resolve to my_dict['foo']['bar'];
* </code>
* The method will return null, if any of the path specified refers to
* a null or undefined value in the object.
*
* If resolved_search_values is TRUE, this will flatten search api
* values that are arrays of entities ({mid, name})
* to an array of their names and ALWAYS return an array of strings
* of length >= 0.
*/
get_value: function(obj, path, resolve_search_values) {
if (obj == null || path == null || path.length == 0) {
return null;
}
if (!$.isArray(path)) {
path = [path];
}
var v = null;
$.each(path, function(i, p){
v = obj[p];
if (v == null) {
return false;
}
obj = v;
return true;
});
if (resolve_search_values) {
if (v == null) {
return [];
}
if (!$.isArray(v)) {
v = [v];
}
var values = [];
$.each(v, function(i, value) {
if ($.type(value) === 'object') {
if (value['name'] != null) {
value = value['name'];
}
else if (value['id'] || value['mid']) {
value = value['id'] || value['mid'];
}
else if (value['value'] != null) {
// For cvts, value may contain other useful info (like date, etc.)
var cvts = [];
$.each(value, function(k, v) {
if (k !== 'value') {
cvts.push(v);
}
});
value = value['value'];
if (cvts.length) {
value += ' (' + cvts.join(', ') + ')';
}
}
}
if ($.isArray(value) && value.length) {
value = value[0].value;
}
if (value != null) {
values.push(value);
}
});
return values;
}
// Cast undefined to null.
return v == null ? null : v;
},
get_values: function(topic_result, prop_id) {
var prop = $.suggest.suggest.get_property(topic_result, prop_id);
if (prop && prop.values) {
return prop.values;
is_commons_id: function(id) {
if (/^\/base\//.test(id) || /^\/user\//.test(id)) {
return false;
}
else {
return null;
}
},
get_first_value: function(topic_result, prop_id) {
var values = $.suggest.suggest.get_values(topic_result, prop_id);
if (values && values.length > 0) {
return values[0];
}
return null;
return true;
},
/**
* Create the flyout html content given the topic api result
* (i.e., .../topic/some/id?filter=suggest). The resulting html
* will be cached for optimization.
* Create the flyout html content given the search result
* containing output=(notable:/client/summary description type).
* The resulting html will be cached for optimization.
*
* @param data:Object - The topic api result with ?filter=suggest
* @param flyout_image_url:Object - The url template for the image url.
* @param data:Object - The search result with
* output=(notable:/client/summary description type).
* @param flyout_image_url:String - The url template for the image url.
* The substring, "${id}", will be replaced by data.id. It is assumed all
* parameters to the flyout image service (api key, dimensions, etc.) is
* already encoded into the url template.
*/
create_flyout: function(data, flyout_image_url) {
var get_property = $.suggest.suggest.get_property;
var get_values = $.suggest.suggest.get_values;
var get_first_value = $.suggest.suggest.get_first_value;
var name = get_first_value(data, "/type/object/name");
if (name) {
name = name.text;
}
// prefer /common/topic/description over /common/topic/article
var article =
get_first_value(data, "/common/topic/description") ||
get_first_value(data, "/common/topic/article") || false;
if (article) {
article = article.text;
}
var image = get_first_value(data, "/common/topic/image") || false;
if (image) {
image = flyout_image_url.replace(/\$\{id\}/g, data.id);
}
var notable_props = [];
var notability = [data.id];
var get_value = $.suggest.suggest.get_value;
var is_system_type = $.suggest.is_system_type;
var is_commons_id = $.suggest.suggest.is_commons_id;
// notable (disambiguating) properties
var values = get_values(data, "/common/topic/notable_properties");
if (values) {
$.each(values, function(i, prop) {
var p = get_property(data, prop.id);
if (p && p.valuetype !== 'compound') {
var prop_values = get_values(data, prop.id);
if (prop_values && prop_values.length) {
prop_values = $.map(prop_values, function(v) {
return v.text;
}).join(", ");
notable_props.push([prop.text || prop.id, prop_values]);
}
}
});
var name = data['name'];
var id = null;
var image = null;
var notable_props = [];
var notable_types = [];
var notable_seen = {}; // Notable types already added
var notable = get_value(data, 'notable');
if (notable && notable['name']) {
notable_types.push(notable['name']);
notable_seen[notable['name']] = true;
}
if (notable && is_system_type(notable['id'])) {
id = data['id'];
}
else {
id = data['mid'];
image = flyout_image_url.replace(/\$\{id\}/g, id);
}
var description_src = 'freebase';
var description = get_value(
data, ['output', 'description', 'wikipedia'], true);
if (description && description.length) {
description_src = 'wikipedia';
}
else {
description = get_value(
data, ['output', 'description', 'freebase'], true);
}
if (description && description.length) {
description = description[0];
}
else {
description = null;
}
var summary = get_value(data, ['output', 'notable:/client/summary']);
if (summary) {
var notable_paths = get_value(summary, '/common/topic/notable_paths');
if (notable_paths && notable_paths.length) {
$.each(notable_paths, function(i, path) {
var values = get_value(summary, path, true);
if (values && values.length) {
var prop_text = path.split('/').pop();
notable_props.push([prop_text, values.join(', ')]);
}
});
}
// notability (notable_for and notable_types)
var notable_for = get_values(data, "/common/topic/notable_for");
var notable_types = get_values(data, "/common/topic/notable_types");
if (notable_for || notable_types) {
var seen = {};
notability = [];
$.each([notable_for, notable_types], function(i, notable) {
if (notable) {
notable.forEach(function(n) {
if (n.id && !seen[n.id]) {
notability.push(n.text);
seen[n.id] = true;
}
});
}
});
}
notability = notability.join(", ");
var content = $('<div class="fbs-flyout-content">');
if (name) {
content.append($('<h1 id="fbs-flyout-title">').text(name));
}
content.append($('<h3 class="fbs-topic-properties fbs-flyout-id">').text(data.id));
$.each(notable_props, function(i, prop) {
content.append($('<h3 class="fbs-topic-properties">')
.append($('<strong>').text(prop[0] + ': '))
.append(document.createTextNode(prop[1])));
}
var types = get_value(
data, ['output', 'type', '/type/object/type'], true);
if (types && types.length) {
$.each(types, function(i, t) {
if (!notable_seen[t]) {
notable_types.push(t);
notable_seen[t] = true;
}
});
if (article) {
content.append($('<p class="fbs-topic-article">').text(article));
}
if (image) {
content.children().addClass('fbs-flyout-image-true');
content.prepend($('<img id="fbs-topic-image" class="fbs-flyout-image-true" src="' + image + '">'));
}
}
var content = $('<div class="fbs-flyout-content">');
if (name) {
content.append($('<h1 id="fbs-flyout-title">').text(name));
}
content
.append($('<h3 class="fbs-topic-properties fbs-flyout-id">')
.text(id));
$.each(notable_props, function(i, prop) {
content.append($('<h3 class="fbs-topic-properties">')
.append($('<strong>').text(prop[0] + ': '))
.append(document.createTextNode(prop[1])));
});
if (description) {
content.append(
$('<p class="fbs-topic-article">')
.append($('<em class="fbs-citation">')
.text('[' + description_src + '] '))
.append(document.createTextNode(description)));
}
if (image) {
content.children().addClass('fbs-flyout-image-true');
content.prepend(
$('<img id="fbs-topic-image" class="fbs-flyout-image-true" src="' +
image + '">'));
}
var flyout_types = $('<span class="fbs-flyout-types">')
.text(notable_types.slice(0, 10).join(', '));
var footer = $('<div class="fbs-attribution">').append(flyout_types);
var types = $('<span class="fbs-flyout-types">').text(notability);
var footer = $('<div class="fbs-attribution">').append(types);
return $('<div>')
.append(content)
.append(footer)
.html();
return $('<div>')
.append(content)
.append(footer)
.html();
}
});

View File

@ -0,0 +1,82 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Additional Licenses for Third Party components can be found here:
* http://wiki.freebase.com/wiki/Freebase_Site_License
*
*/
(function(c,r){if(!("console"in window)){var p=window.console={};p.log=p.warn=p.error=p.debug=function(){}}c(function(){var a=c("<div>");c(document.body).append(a);var b=setTimeout(function(){if(c.cleanData){var a=c.cleanData;c.cleanData=function(b){for(var f=0,g;null!=(g=b[f]);f++)c(g).triggerHandler("remove");a(b)}}else{var b=c.fn.remove;c.fn.remove=function(a,e){return this.each(function(){e||(!a||c.filter(a,[this]).length)&&c("*",this).add([this]).each(function(){c(this).triggerHandler("remove")});
return b.call(c(this),a,e)})}}},1);a.bind("remove",function(){clearTimeout(b)});a.remove()});var q={key:1,filter:1,spell:1,exact:1,lang:1,scoring:1,prefixed:1,stemmed:1,format:1,mql_output:1,output:1,type:1};c.suggest=function(a,b){c.fn[a]=function(b){this.length||console.warn("Suggest: invoked on empty element set");return this.each(function(){this.nodeName&&("INPUT"===this.nodeName.toUpperCase()?this.type&&"TEXT"!==this.type.toUpperCase()&&console.warn("Suggest: unsupported INPUT type: "+this.type):console.warn("Suggest: unsupported DOM element: "+
this.nodeName));var g=c.data(this,a);g&&g._destroy();c.data(this,a,new c.suggest[a](this,b))._init()})};c.suggest[a]=function(b,g){var d=this,f=this.options=c.extend(!0,{},c.suggest.defaults,c.suggest[a].defaults,g),i=f.css_prefix=f.css_prefix||"",h=f.css;this.name=a;c.each(h,function(a){h[a]=i+h[a]});f.ac_param={};c.each(q,function(a){var b=f[a];null===b||""===b||(f.ac_param[a]=b)});f.flyout_lang=null;if(f.ac_param.lang){var j=f.ac_param.lang;c.isArray(j)&&j.length&&(j=j.join(","));j&&(f.flyout_lang=
j)}this._status={START:"",LOADING:"",SELECT:"",ERROR:""};f.status&&(f.status instanceof Array&&3<=f.status.length)&&(this._status.START=f.status[0]||"",this._status.LOADING=f.status[1]||"",this._status.SELECT=f.status[2]||"",4===f.status.length&&(this._status.ERROR=f.status[3]||""));var j=this.status=c('<div style="display:none;">').addClass(h.status),l=this.list=c("<ul>").addClass(h.list),k=this.pane=c('<div style="display:none;" class="fbs-reset">').addClass(h.pane);k.append(j).append(l);f.parent?
c(f.parent).append(k):(k.css("position","absolute"),f.zIndex&&k.css("z-index",f.zIndex),c(document.body).append(k));k.bind("mousedown",function(a){d.input.data("dont_hide",true);a.stopPropagation()}).bind("mouseup",function(a){d.input.data("dont_hide")&&d.input.focus();d.input.removeData("dont_hide");a.stopPropagation()}).bind("click",function(a){a.stopPropagation();if(a=d.get_selected()){d.onselect(a,true);d.hide_all()}});l.hover(function(a){d.hoverover_list(a)},function(a){d.hoverout_list(a)});
this.input=c(b).attr("autocomplete","off").unbind(".suggest").bind("remove.suggest",function(){d._destroy()}).bind("keydown.suggest",function(a){d.keydown(a)}).bind("keypress.suggest",function(a){d.keypress(a)}).bind("keyup.suggest",function(a){d.keyup(a)}).bind("blur.suggest",function(a){d.blur(a)}).bind("textchange.suggest",function(){d.textchange()}).bind("focus.suggest",function(a){d.focus(a)}).bind(c.browser.msie?"paste.suggest":"input.suggest",function(){clearTimeout(d.paste_timeout);d.paste_timeout=
setTimeout(function(){d.textchange()},0)});this.onresize=function(){d.invalidate_position();if(k.is(":visible")){d.position();if(f.flyout&&d.flyoutpane&&d.flyoutpane.is(":visible")){var a=d.get_selected();a&&d.flyout_position(a)}}};c(window).bind("resize.suggest",this.onresize).bind("scroll.suggest",this.onresize)};c.suggest[a].prototype=c.extend({},c.suggest.prototype,b)};c.suggest.prototype={_init:function(){},_destroy:function(){this.pane.remove();this.list.remove();this.input.unbind(".suggest");
c(window).unbind("resize.suggest",this.onresize).unbind("scroll.suggest",this.onresize);this.input.removeData("data.suggest")},invalidate_position:function(){self._position=null},status_start:function(){this.hide_all();this.status.siblings().hide();this._status.START&&(this.status.text(this._status.START).show(),this.pane.is(":visible")||(this.position(),this.pane_show()));this._status.LOADING&&this.status.removeClass("loading")},status_loading:function(){this.status.siblings().show();this._status.LOADING?
(this.status.addClass("loading").text(this._status.LOADING).show(),this.pane.is(":visible")||(this.position(),this.pane_show())):this.status.hide()},status_select:function(){this.status.siblings().show();this._status.SELECT?this.status.text(this._status.SELECT).show():this.status.hide();this._status.LOADING&&this.status.removeClass("loading")},status_error:function(){this.status.siblings().show();this._status.ERROR?this.status.text(this._status.ERROR).show():this.status.hide();this._status.LOADING&&
this.status.removeClass("loading")},focus:function(a){""===this.input.val()?this.status_start():this.focus_hook(a)},focus_hook:function(){!this.input.data("data.suggest")&&(!this.pane.is(":visible")&&c("."+this.options.css.item,this.list).length)&&(this.position(),this.pane_show())},keydown:function(a){var b=a.keyCode;if(9===b)this.tab(a);else if(38===b||40===b)a.shiftKey||a.preventDefault()},keypress:function(a){var b=a.keyCode;38===b||40===b?a.shiftKey||a.preventDefault():13===b&&this.enter(a)},
keyup:function(a){var b=a.keyCode;if(38===b)a.preventDefault(),this.up(a);else if(40===b)a.preventDefault(),this.down(a);else if(a.ctrlKey&&77===b)c(".fbs-more-link",this.pane).click();else if(c.suggest.is_char(a)){clearTimeout(this.keypress.timeout);var e=this;this.keypress.timeout=setTimeout(function(){e.textchange()},0)}else 27===b&&this.escape(a);return!0},blur:function(){this.input.data("dont_hide")||(this.input.data("data.suggest"),this.hide_all())},tab:function(a){if(!a.shiftKey&&!a.metaKey&&
!a.ctrlKey){var a=this.options,a=this.pane.is(":visible")&&c("."+a.css.item,this.list).length,b=this.get_selected();a&&b&&(this.onselect(b),this.hide_all())}},enter:function(a){var b=this.options;if(this.pane.is(":visible")){if(a.shiftKey){this.shift_enter(a);a.preventDefault();return}if(c("."+b.css.item,this.list).length){var e=this.get_selected();if(e){this.onselect(e);this.hide_all();a.preventDefault();return}if(!b.soft&&(this.input.data("data.suggest"),c("."+this.options.css.item+":visible",this.list).length)){this.updown(!1);
a.preventDefault();return}}}b.soft?this.soft_enter():a.preventDefault()},soft_enter:function(){},shift_enter:function(){},escape:function(){this.hide_all()},up:function(a){this.updown(!0,a.ctrlKey||a.shiftKey)},down:function(a){this.updown(!1,null,a.ctrlKey||a.shiftKey)},updown:function(a,b,e){var g=this.options.css,d=this.list;if(this.pane.is(":visible")){var f=c("."+g.item+":visible",d);if(f.length){var d=c(f[0]),f=c(f[f.length-1]),i=this.get_selected()||[];clearTimeout(this.ignore_mouseover.timeout);
this._ignore_mouseover=!1;a?b?this._goto(d):i.length?i[0]==d[0]?(d.removeClass(g.selected),this.input.val(this.input.data("original.suggest")),this.hoverout_list()):(a=i.prevAll("."+g.item+":visible:first"),this._goto(a)):this._goto(f):e?this._goto(f):i.length?i[0]==f[0]?(f.removeClass(g.selected),this.input.val(this.input.data("original.suggest")),this.hoverout_list()):(a=i.nextAll("."+g.item+":visible:first"),this._goto(a)):this._goto(d)}}else a||this.textchange()},_goto:function(a){a.trigger("mouseover.suggest");
var b=a.data("data.suggest");this.input.val(b?b.name:this.input.data("original.suggest"));this.scroll_to(a)},scroll_to:function(a){var b=this.list,c=b.scrollTop(),g=c+b.innerHeight(),d=a.outerHeight(),a=a.prevAll().length*d,d=a+d;a<c?(this.ignore_mouseover(),b.scrollTop(a)):d>g&&(this.ignore_mouseover(),b.scrollTop(c+d-g))},textchange:function(){this.input.removeData("data.suggest");this.input.trigger("fb-textchange",this);var a=this.input.val();""===a?this.status_start():(this.status_loading(),this.request(a))},
request:function(){},response:function(a){if(a&&("cost"in a&&this.trackEvent(this.name,"response","cost",a.cost),this.check_response(a))){var b=[];c.isArray(a)?b=a:"result"in a&&(b=a.result);var e=c.map(arguments,function(a){return a});this.response_hook.apply(this,e);var g=null,d=this,f=this.options;c.each(b,function(b,c){if(!c.id&&c.mid)c.id=c.mid;var e=d.create_item(c,a).bind("mouseover.suggest",function(a){d.mouseover_item(a)});e.data("data.suggest",c);d.list.append(e);b===0&&(g=e)});this.input.data("original.suggest",
this.input.val());if(0===c("."+f.css.item,this.list).length&&f.nomatch){b=c('<li class="fbs-nomatch">');if("string"===typeof f.nomatch)b.text(f.nomatch);else if(f.nomatch.title&&b.append(c('<em class="fbs-nomatch-text">').text(f.nomatch.title)),f.nomatch.heading&&b.append(c("<h3>").text(f.nomatch.heading)),(f=f.nomatch.tips)&&f.length){var i=c('<ul class="fbs-search-tips">');c.each(f,function(a,b){i.append(c("<li>").text(b))});b.append(i)}b.bind("click.suggest",function(a){a.stopPropagation()});this.list.append(b)}e.push(g);
this.show_hook.apply(this,e);this.position();this.pane_show()}},pane_show:function(){var a=!1;c("> li",this.list).length&&(a=!0);a||this.pane.children(":not(."+this.options.css.list+")").each(function(){if("none"!=c(this).css("display"))return a=!0,!1});if(a)if(this.options.animate){var b=this;this.pane.slideDown("fast",function(){b.input.trigger("fb-pane-show",b)})}else this.pane.show(),this.input.trigger("fb-pane-show",this);else this.pane.hide(),this.input.trigger("fb-pane-hide",this)},create_item:function(a){var b=
this.options.css,e=c("<li>").addClass(b.item),a=c("<label>").text(a.name);e.append(c("<div>").addClass(b.item_name).append(a));return e},mouseover_item:function(a){if(!this._ignore_mouseover){a=a.target;"li"!==a.nodeName.toLowerCase()&&(a=c(a).parents("li:first"));var b=c(a),e=this.options.css;c("."+e.item,this.list).each(function(){this!==b[0]&&c(this).removeClass(e.selected)});b.hasClass(e.selected)||(b.addClass(e.selected),this.mouseover_item_hook(b))}},mouseover_item_hook:function(){},hoverover_list:function(){},
hoverout_list:function(){},check_response:function(){return!0},response_hook:function(){this.list.empty()},show_hook:function(){this.status_select()},position:function(){var a=this.pane,b=this.options;if(!b.parent){if(!self._position){var e=this.input,g=e.offset(),d=e.outerWidth(!0),f=e.outerHeight(!0);g.top+=f;var i=a.outerWidth(),h=a.outerHeight(),j=g.top+h/2,l=c(window).scrollLeft(),e=c(window).scrollTop(),k=c(window).width(),n=c(window).height()+e,m=!0;"left"==b.align?m=!0:"right"==b.align?m=
!1:g.left>l+k/2&&(m=!1);m||(m=g.left-(i-d),m>l&&(g.left=m));j>n&&(b=g.top-f-h,b>e&&(g.top=b));this._position=g}a.css({top:this._position.top,left:this._position.left})}},ignore_mouseover:function(){this._ignore_mouseover=!0;var a=this;this.ignore_mouseover.timeout=setTimeout(function(){a.ignore_mouseover_reset()},1E3)},ignore_mouseover_reset:function(){this._ignore_mouseover=!1},get_selected:function(){var a=null,b=this.options.css.selected;c("li",this.list).each(function(){var e=c(this);if(e.hasClass(b)&&
e.is(":visible"))return a=e,!1});return a},onselect:function(a){var b=a.data("data.suggest");b&&(this.input.val(b.name).data("data.suggest",b).trigger("fb-select",b),this.trackEvent(this.name,"fb-select","index",a.prevAll().length))},trackEvent:function(a,b,c,g){this.input.trigger("fb-track-event",{category:a,action:b,label:c,value:g})},hide_all:function(){this.pane.hide();this.input.trigger("fb-pane-hide",this)}};c.extend(c.suggest,{defaults:{status:["Start typing to get suggestions...","Searching...",
"Select an item from the list:","Sorry, something went wrong. Please try again later"],soft:!1,nomatch:"no matches",css:{pane:"fbs-pane",list:"fbs-list",item:"fbs-item",item_name:"fbs-item-name",selected:"fbs-selected",status:"fbs-status"},css_prefix:null,parent:null,animate:!1,zIndex:null},strongify:function(a,b){var e,g=a.toLowerCase().indexOf(b.toLowerCase());if(0<=g){var d=b.length;e=document.createTextNode(a.substring(0,g));var f=c("<strong>").text(a.substring(g,g+d)),g=document.createTextNode(a.substring(g+
d));e=c("<div>").append(e).append(f).append(g)}else e=c("<div>").text(a);return e},keyCode:{CAPS_LOCK:20,CONTROL:17,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,INSERT:45,LEFT:37,NUMPAD_ENTER:108,PAGE_DOWN:34,PAGE_UP:33,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38,OPTION:18,APPLE:224},is_char:function(a){if("keypress"===a.type){if((a.metaKey||a.ctrlKey)&&118===a.charCode)return!0;if("isChar"in a)return a.isChar}else{var b=c.suggest.keyCode.not_char;b||(b={},c.each(c.suggest.keyCode,function(a,c){b[""+c]=1}),
c.suggest.keyCode.not_char=b);return!(""+a.keyCode in b)}},parse_input:function(a){for(var b=/(\S+)\:(?:\"([^\"]+)\"|(\S+))/g,e=a,g=[],d={},f=b.exec(a);f;)f[1]in q?d[f[1]]=c.isEmptyObject(f[2])?f[3]:f[2]:g.push(f[0]),e=e.replace(f[0],""),f=b.exec(a);e=c.trim(e.replace(/\s+/g," "));return[e,g,d]},mqlkey_fast:/^[_A-Za-z0-9][A-Za-z0-9_-]*$/,mqlkey_slow:/^(?:[A-Za-z0-9]|\$[A-F0-9]{4})(?:[A-Za-z0-9_-]|\$[A-F0-9]{4})*$/,check_mql_key:function(a){return c.suggest.mqlkey_fast.test(a)||c.suggest.mqlkey_slow.test(a)?
!0:!1},check_mql_id:function(a){if(0===a.indexOf("/")){a=a.split("/");a.shift();if(!(1==a.length&&""===a[0]))for(var b=0,e=a.length;b<e;b++)if(!c.suggest.check_mql_key(a[b]))return!1;return!0}return!1},is_system_type:function(a){return null==a?!1:0===a.indexOf("/type/")}});var s=c.suggest.prototype._destroy,t=c.suggest.prototype.show_hook;c.suggest("suggest",{_init:function(){var a=this,b=this.options;null==b.flyout_service_url&&(b.flyout_service_url=b.service_url);this.flyout_url=b.flyout_service_url;
b.flyout_service_path&&(this.flyout_url+=b.flyout_service_path);this.flyout_url=this.flyout_url.replace(/\$\{key\}/g,b.key);null==b.flyout_image_service_url&&(b.flyout_image_service_url=b.service_url);this.flyout_image_url=b.flyout_image_service_url;b.flyout_image_service_path&&(this.flyout_image_url+=b.flyout_image_service_path);this.flyout_image_url=this.flyout_image_url.replace(/\$\{key\}/g,b.key);c.suggest.cache||(c.suggest.cache={});if(b.flyout&&(this.flyoutpane=c('<div style="display:none;" class="fbs-reset">').addClass(b.css.flyoutpane),
b.flyout_parent?c(b.flyout_parent).append(this.flyoutpane):(this.flyoutpane.css("position","absolute"),b.zIndex&&this.flyoutpane.css("z-index",b.zIndex),c(document.body).append(this.flyoutpane)),this.flyoutpane.hover(function(b){a.hoverover_list(b)},function(b){a.hoverout_list(b)}).bind("mousedown.suggest",function(b){b.stopPropagation();a.pane.click()}),c.suggest.flyout||(c.suggest.flyout={}),!c.suggest.flyout.cache))c.suggest.flyout.cache={}},_destroy:function(){s.call(this);this.flyoutpane&&this.flyoutpane.remove();
this.input.removeData("request.count.suggest");this.input.removeData("flyout.request.count.suggest")},shift_enter:function(){this.options.suggest_new&&(this.suggest_new(),this.hide_all())},hide_all:function(){this.pane.hide();this.flyoutpane&&this.flyoutpane.hide();this.input.trigger("fb-pane-hide",this);this.input.trigger("fb-flyoutpane-hide",this)},request:function(a,b){var e=this,g=this.options,d=a,f=g.ac_param.filter||[],i=null;"string"===c.type(f)&&(f=[f]);f=f.slice();if(g.advanced){var h=c.suggest.parse_input(d),
d=h[0];h[1].length&&f.push("(all "+h[1].join(" ")+")");i=h[2];c.suggest.check_mql_id(d)&&(f.push('(any alias{start}:"'+d+'" mid:"'+d+'")'),i.prefixed=!0,d="")}h={};h[g.query_param_name]=d;b&&(h.cursor=b);c.extend(h,g.ac_param,i);f.length&&(h.filter=f);var j=g.service_url+g.service_path+"?"+c.param(h,!0);if(d=c.suggest.cache[j])this.response(d,b?b:-1,!0);else{clearTimeout(this.request.timeout);var l={url:g.service_url+g.service_path,data:h,traditional:!0,beforeSend:function(){var a=e.input.data("request.count.suggest")||
0;a||e.trackEvent(e.name,"start_session");a=a+1;e.trackEvent(e.name,"request","count",a);e.input.data("request.count.suggest",a)},success:function(d){c.suggest.cache[j]=d;d.prefix=a;e.response(d,b?b:-1)},error:function(a){e.status_error();e.trackEvent(e.name,"request","error",{url:this.url,response:a?a.responseText:""});e.input.trigger("fb-error",Array.prototype.slice.call(arguments))},complete:function(a){a&&e.trackEvent(e.name,"request","tid",a.getResponseHeader("X-Metaweb-TID"))},dataType:"jsonp",
cache:!0};this.request.timeout=setTimeout(function(){c.ajax(l)},g.xhr_delay)}},create_item:function(a,b){var e=this.options.css,g=c("<li>").addClass(e.item),d=c("<label>").append(c.suggest.strongify(a.name||a.id,b.prefix)),f=c("<div>").addClass(e.item_name).append(d),i=a.notable;a.under&&c(":first",d).append(c("<small>").text(" ("+a.under+")"));(null!=i&&c.suggest.is_system_type(i.id)||null!=this.options.scoring&&"SCHEMA"===this.options.scoring.toUpperCase())&&c(":first",d).append(c("<small>").text(" ("+
a.id+")"));g.append(f);e=c("<div>").addClass(e.item_type);i&&i.name?e.text(i.name):this.options.show_id&&a.id&&e.text(a.id);f.prepend(e);return g},mouseover_item_hook:function(a){a=a.data("data.suggest");this.options.flyout&&a&&this.flyout_request(a)},check_response:function(a){return a.prefix===this.input.val()},response_hook:function(a,b){this.flyoutpane&&this.flyoutpane.hide();0<b?c(".fbs-more",this.pane).remove():this.list.empty()},show_hook:function(a,b,e){t.apply(this,[a]);var g=this.options,
d=this,f=this.pane,i=this.list,h=a.result,j=c(".fbs-more",f),l=c(".fbs-suggestnew",f);c(".fbs-status",f);var k=a.correction;if(k&&k.length){var n=c('<a class="fbs-spell-link" href="#">').append(k[0]).bind("click.suggest",function(a){a.preventDefault();a.stopPropagation();d.input.val(k[0]).trigger("textchange")});d.status.empty().append("Search instead for ").append(n).show()}h&&h.length&&"cursor"in a?(j.length||(h=c('<a class="fbs-more-link" href="#" title="(Ctrl+m)">view more</a>'),j=c('<div class="fbs-more">').append(h),
h.bind("click.suggest",function(a){a.preventDefault();a.stopPropagation();a=c(this).parent(".fbs-more");d.more(a.data("cursor.suggest"))}),i.after(j)),j.data("cursor.suggest",a.cursor),j.show()):j.remove();g.suggest_new?(l.length||(a=c('<button class="fbs-suggestnew-button">'),a.text(g.suggest_new),l=c('<div class="fbs-suggestnew">').append('<div class="fbs-suggestnew-description">Your item not in the list?</div>').append(a).append('<span class="fbs-suggestnew-shortcut">(Shift+Enter)</span>').bind("click.suggest",
function(a){a.stopPropagation();d.suggest_new(a)}),f.append(l)),l.show()):l.remove();e&&(e.length&&0<b)&&(b=e.prevAll().length*e.outerHeight(),i.scrollTop(),i.animate({scrollTop:b},"slow",function(){e.trigger("mouseover.suggest")}))},suggest_new:function(){var a=this.input.val();""!==a&&(this.input.data("data.suggest",a).trigger("fb-select-new",a),this.trackEvent(this.name,"fb-select-new","index","new"),this.hide_all())},more:function(a){if(a){var b=this.input.data("original.suggest");null!==b&&this.input.val(b);
this.request(this.input.val(),a);this.trackEvent(this.name,"more","cursor",a)}return!1},flyout_request:function(a){var b=this,e=this.options,g=this.flyoutpane.data("data.suggest");if(g&&a.id===g.id)this.flyoutpane.is(":visible")||(a=this.get_selected(),this.flyout_position(a),this.flyoutpane.show(),this.input.trigger("fb-flyoutpane-show",this));else if((g=c.suggest.flyout.cache[a.id])&&g.id&&g.html)this.flyout_response(g);else{var d=a.id,f={url:this.flyout_url.replace(/\$\{id\}/g,a.id),traditional:!0,
beforeSend:function(){var a=b.input.data("flyout.request.count.suggest")||0,a=a+1;b.trackEvent(b.name,"flyout.request","count",a);b.input.data("flyout.request.count.suggest",a)},success:function(a){a["req:id"]=d;a.result&&a.result.length&&(a.html=c.suggest.suggest.create_flyout(a.result[0],b.flyout_image_url));c.suggest.flyout.cache[d]=a;b.flyout_response(a)},error:function(a){b.trackEvent(b.name,"flyout","error",{url:this.url,response:a?a.responseText:""})},complete:function(a){a&&b.trackEvent(b.name,
"flyout","tid",a.getResponseHeader("X-Metaweb-TID"))},dataType:"jsonp",cache:!0};e.flyout_lang&&(f.data={lang:e.flyout_lang});clearTimeout(this.flyout_request.timeout);this.flyout_request.timeout=setTimeout(function(){c.ajax(f)},e.xhr_delay);this.input.trigger("fb-request-flyout",f)}},flyout_response:function(a){var b=this.pane,c=this.get_selected()||[];if(b.is(":visible")&&c.length&&(b=c.data("data.suggest"))&&a["req:id"]===b.id&&a.html)this.flyoutpane.html(a.html),this.flyout_position(c),this.flyoutpane.show().data("data.suggest",
b),this.input.trigger("fb-flyoutpane-show",this)},flyout_position:function(a){if(!this.options.flyout_parent){var b=this.pane,e=this.flyoutpane,g=this.options.css,d=r,f=parseInt(e.css("top"),10),i=parseInt(e.css("left"),10),h=b.offset(),j=b.outerWidth(),l=e.outerHeight(),k=e.outerWidth();if("bottom"===this.options.flyout)d=h,j=this.input.offset(),d.top=h.top<j.top?d.top-l:d.top+b.outerHeight(),e.addClass(g.flyoutpane+"-bottom");else{d=a.offset();a=a.outerHeight();d.left+=j;var n=d.left+k,b=c(document.body).scrollLeft(),
m=c(window).width()+b;d.top=d.top+a-l;d.top<h.top&&(d.top=h.top);n>m&&(h=d.left-(j+k),h>b&&(d.left=h));e.removeClass(g.flyoutpane+"-bottom")}d.top===f&&d.left===i||e.css({top:d.top,left:d.left})}},hoverout_list:function(){this.flyoutpane&&!this.get_selected()&&this.flyoutpane.hide()}});c.extend(c.suggest.suggest,{defaults:{filter:null,spell:"always",exact:!1,scoring:null,lang:null,key:null,prefixed:!0,stemmed:null,format:null,advanced:!0,show_id:!0,query_param_name:"query",service_url:"https://www.googleapis.com/freebase/v1",
service_path:"/search",align:null,flyout:!0,flyout_service_url:null,flyout_service_path:"/search?filter=(all mid:${id})&output=(notable:/client/summary description type)&key=${key}",flyout_image_service_url:null,flyout_image_service_path:"/image${id}?maxwidth=75&key=${key}&errorid=/freebase/no_image_png",flyout_parent:null,suggest_new:null,nomatch:{title:"No suggested matches",heading:"Tips on getting better suggestions:",tips:["Enter more or fewer characters","Add words related to your original search",
"Try alternate spellings","Check your spelling"]},css:{item_type:"fbs-item-type",flyoutpane:"fbs-flyout-pane"},xhr_delay:200},get_value:function(a,b,e){if(null==a||null==b||0==b.length)return null;c.isArray(b)||(b=[b]);var g=null;c.each(b,function(b,c){g=a[c];if(null==g)return!1;a=g;return!0});if(e){if(null==g)return[];c.isArray(g)||(g=[g]);var d=[];c.each(g,function(a,b){if("object"===c.type(b))if(null!=b.name)b=b.name;else if(b.id||b.mid)b=b.id||b.mid;else if(null!=b.value){var e=[];c.each(b,function(a,
b){"value"!==a&&e.push(b)});b=b.value;e.length&&(b+=" ("+e.join(", ")+")")}c.isArray(b)&&b.length&&(b=b[0].value);null!=b&&d.push(b)});return d}return null==g?null:g},is_commons_id:function(a){return/^\/base\//.test(a)||/^\/user\//.test(a)?!1:!0},create_flyout:function(a,b){var e=c.suggest.suggest.get_value,g=c.suggest.is_system_type,d=a.name,f=null,i=null,h=[],j=[],l={};if((f=e(a,"notable"))&&f.name)j.push(f.name),l[f.name]=!0;f&&g(f.id)?f=a.id:(f=a.mid,i=b.replace(/\$\{id\}/g,f));var g="freebase",
k=e(a,["output","description","wikipedia"],!0);k&&k.length?g="wikipedia":k=e(a,["output","description","freebase"],!0);var k=k&&k.length?k[0]:null,n=e(a,["output","notable:/client/summary"]);if(n){var m=e(n,"/common/topic/notable_paths");m&&m.length&&c.each(m,function(a,b){var c=e(n,b,true);if(c&&c.length){var d=b.split("/").pop();h.push([d,c.join(", ")])}})}(m=e(a,["output","type","/type/object/type"],!0))&&m.length&&c.each(m,function(a,b){if(!l[b]){j.push(b);l[b]=true}});var o=c('<div class="fbs-flyout-content">');
d&&o.append(c('<h1 id="fbs-flyout-title">').text(d));o.append(c('<h3 class="fbs-topic-properties fbs-flyout-id">').text(f));c.each(h,function(a,b){o.append(c('<h3 class="fbs-topic-properties">').append(c("<strong>").text(b[0]+": ")).append(document.createTextNode(b[1])))});k&&o.append(c('<p class="fbs-topic-article">').append(c('<em class="fbs-citation">').text("["+g+"] ")).append(document.createTextNode(k)));i&&(o.children().addClass("fbs-flyout-image-true"),o.prepend(c('<img id="fbs-topic-image" class="fbs-flyout-image-true" src="'+
i+'">')));d=c('<span class="fbs-flyout-types">').text(j.slice(0,10).join(", "));d=c('<div class="fbs-attribution">').append(d);return c("<div>").append(o).append(d).html()}});document.createElement("input")})(jQuery);

View File

@ -427,6 +427,7 @@ DataTableCellUI.prototype._postProcessSeveralCells = function(command, params, b
);
};
// FIXME: Topic Blocks are gone
DataTableCellUI.topicBlockPreview = {
url: 'http://www.freebase.com/widget/topic{{id}}?mode=content&blocks=[{"block":"full_info"},{"block":"article_props"}]',
width: 430,