2010-10-20 20:11:15 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 2010, 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:
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
* Redistributions of source code must retain the above copyright
|
2010-10-20 20:11:15 +02:00
|
|
|
notice, this list of conditions and the following disclaimer.
|
2011-08-04 22:37:14 +02:00
|
|
|
* Redistributions in binary form must reproduce the above
|
2010-10-20 20:11:15 +02:00
|
|
|
copyright notice, this list of conditions and the following disclaimer
|
|
|
|
in the documentation and/or other materials provided with the
|
|
|
|
distribution.
|
2011-08-04 22:37:14 +02:00
|
|
|
* Neither the name of Google Inc. nor the names of its
|
2010-10-20 20:11:15 +02:00
|
|
|
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.
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
*/
|
2010-10-20 20:11:15 +02:00
|
|
|
|
2012-10-12 20:39:05 +02:00
|
|
|
var CustomSuggest = {};
|
|
|
|
|
|
|
|
CustomSuggest.setFreebaseAPIKey = function(freebaseAPIKey) {
|
|
|
|
$.suggest.suggest.defaults.key = freebaseAPIKey;
|
|
|
|
$.suggest.suggestT.defaults.key = freebaseAPIKey;
|
|
|
|
$.suggest.suggestP.defaults.key = freebaseAPIKey;
|
|
|
|
};
|
|
|
|
|
2010-03-03 00:48:21 +01:00
|
|
|
(function() {
|
2012-10-12 20:39:05 +02:00
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
/*
|
|
|
|
* Make suggest widgets clean up when removed.
|
|
|
|
*/
|
|
|
|
var oldInit = $.suggest.suggest.prototype._init;
|
|
|
|
$.suggest.suggest.prototype._init = function() {
|
|
|
|
oldInit.call(this);
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
this.input.bind("remove", function() {
|
|
|
|
self._destroy();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2010-03-05 20:28:35 +01:00
|
|
|
/*
|
|
|
|
* Property suggest
|
|
|
|
*/
|
2010-03-03 00:48:21 +01:00
|
|
|
$.suggest(
|
|
|
|
"suggestP",
|
|
|
|
$.extend(
|
|
|
|
true,
|
|
|
|
{},
|
|
|
|
$.suggest.suggest.prototype,
|
|
|
|
{
|
|
|
|
create_item: function(data, response_data) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var css = this.options.css;
|
|
|
|
|
|
|
|
var li = $("<li>").addClass(css.item);
|
|
|
|
|
|
|
|
var name = $("<div>")
|
|
|
|
.addClass(css.item_name)
|
|
|
|
.append(
|
|
|
|
$("<label>").append(
|
|
|
|
$.suggest.strongify(
|
|
|
|
data.name || data.guid, response_data.prefix
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
data.name = name.text(); // this converts html escaped strings like "&" back to "&"
|
|
|
|
li.append(name);
|
|
|
|
|
|
|
|
name.prepend($("<div>").addClass(css.item_type).text(data.id));
|
|
|
|
|
|
|
|
return li;
|
2010-03-03 00:48:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2011-08-04 22:37:14 +02:00
|
|
|
|
2010-06-29 00:42:53 +02:00
|
|
|
var originalSuggestP = $.suggest.suggestP;
|
|
|
|
$.suggest.suggestP = function(input, options) {
|
2011-08-04 22:37:14 +02:00
|
|
|
originalSuggestP.call(this, input, options);
|
|
|
|
|
|
|
|
if ("ac_param" in options) {
|
|
|
|
var ac_param = options.ac_param;
|
|
|
|
if ("schema" in ac_param) {
|
|
|
|
this.options.ac_param.schema = ac_param.schema;
|
2010-06-29 00:42:53 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
2010-06-29 00:42:53 +02:00
|
|
|
};
|
|
|
|
$.suggest.suggestP.prototype = originalSuggestP.prototype;
|
2011-08-04 22:37:14 +02:00
|
|
|
|
2010-03-03 00:48:21 +01:00
|
|
|
$.extend(
|
|
|
|
$.suggest.suggestP,
|
|
|
|
{
|
|
|
|
defaults: $.extend(
|
|
|
|
true,
|
|
|
|
{},
|
|
|
|
$.suggest.suggest.defaults, {
|
2012-10-12 20:39:05 +02:00
|
|
|
scoring: "schema",
|
2011-08-04 22:37:14 +02:00
|
|
|
css: { pane: "fbs-pane fbs-pane-property" }
|
2010-03-05 20:28:35 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
);
|
2011-08-04 22:37:14 +02:00
|
|
|
|
2010-03-05 20:28:35 +01:00
|
|
|
/*
|
|
|
|
* Type suggest
|
|
|
|
*/
|
|
|
|
$.suggest(
|
|
|
|
"suggestT",
|
|
|
|
$.extend(
|
|
|
|
true,
|
|
|
|
{},
|
|
|
|
$.suggest.suggest.prototype,
|
|
|
|
{
|
|
|
|
create_item: function(data, response_data) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var css = this.options.css;
|
2010-03-05 20:28:35 +01:00
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
var li = $("<li>").addClass(css.item);
|
2010-03-05 20:28:35 +01:00
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
var name = $("<div>")
|
|
|
|
.addClass(css.item_name)
|
|
|
|
.append(
|
|
|
|
$("<label>")
|
|
|
|
.append($.suggest.strongify(data.name || data.guid, response_data.prefix)));
|
2010-03-05 20:28:35 +01:00
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
data.name = name.text(); // this converts html escaped strings like "&" back to "&"
|
|
|
|
li.append(name);
|
2010-03-05 20:28:35 +01:00
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
name.prepend($("<div>").addClass(css.item_type).text(data.id));
|
|
|
|
|
|
|
|
return li;
|
2010-03-05 20:28:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2011-08-04 22:37:14 +02:00
|
|
|
|
2010-03-05 20:28:35 +01:00
|
|
|
$.extend(
|
|
|
|
$.suggest.suggestT,
|
|
|
|
{
|
|
|
|
defaults: $.extend(
|
|
|
|
true,
|
|
|
|
{},
|
|
|
|
$.suggest.suggest.defaults, {
|
2012-10-12 20:39:05 +02:00
|
|
|
scoring: "schema",
|
2011-08-04 22:37:14 +02:00
|
|
|
css: { pane: "fbs-pane fbs-pane-type" }
|
2010-03-03 00:48:21 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
);
|
2012-10-12 20:39:05 +02:00
|
|
|
|
|
|
|
// Use Freebase API Key
|
2012-10-13 19:47:08 +02:00
|
|
|
$.ajax("command/core/get-preference",
|
2012-10-12 20:39:05 +02:00
|
|
|
{
|
|
|
|
async: false,
|
|
|
|
data: {name: "freebase.api.key"},
|
|
|
|
success: function(data) {
|
|
|
|
if (data.value && data.value != "null") {
|
|
|
|
CustomSuggest.setFreebaseAPIKey(data.value);
|
|
|
|
} else {
|
|
|
|
// Default API key for Refine to use for freebase suggest widget
|
|
|
|
CustomSuggest.setFreebaseAPIKey("AIzaSyBBTAtJ31v_jlg_ImbQuBNnAaAyrHzRyW8");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2010-03-03 00:48:21 +01:00
|
|
|
})();
|