Update to ES5 standards
Also fix ESLint issues
This commit is contained in:
@ -32,7 +32,7 @@ Takes a prefix, query typeahead callback, Bloodhound typeahead adapter
|
||||
and returns the completions it gets from the bloodhound engine prefixed.
|
||||
*/
|
||||
function prefixedSource(prefix, query, cb, bhAdapter) {
|
||||
bhAdapter(query, function(retArray){
|
||||
bhAdapter(query, function(retArray) {
|
||||
var matches = [];
|
||||
for (var i = 0; i < retArray.length; i++) {
|
||||
var obj = {name : prefix + retArray[i].name};
|
||||
@ -41,7 +41,7 @@ function prefixedSource(prefix, query, cb, bhAdapter) {
|
||||
cb(matches);
|
||||
});
|
||||
}
|
||||
function getPath(){
|
||||
function getPath() {
|
||||
var jsFileLocation = $("script[src*=edit_books]").attr("src"); // the js file path
|
||||
jsFileLocation = jsFileLocation.replace("/static/js/edit_books.js", ""); // the js folder path
|
||||
return jsFileLocation;
|
||||
@ -49,7 +49,7 @@ function getPath(){
|
||||
|
||||
var authors = new Bloodhound({
|
||||
name: "authors",
|
||||
datumTokenizer(datum) {
|
||||
datumTokenizer: function datumTokenizer(datum) {
|
||||
return [datum.name];
|
||||
},
|
||||
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
||||
@ -60,15 +60,15 @@ var authors = new Bloodhound({
|
||||
|
||||
var series = new Bloodhound({
|
||||
name: "series",
|
||||
datumTokenizer(datum) {
|
||||
datumTokenizer: function datumTokenizer(datum) {
|
||||
return [datum.name];
|
||||
},
|
||||
queryTokenizer(query) {
|
||||
queryTokenizer: function queryTokenizer(query) {
|
||||
return [query];
|
||||
},
|
||||
remote: {
|
||||
url: getPath()+"/get_series_json?q=",
|
||||
replace(url, query) {
|
||||
replace: function replace(url, query) {
|
||||
return url+encodeURIComponent(query);
|
||||
}
|
||||
}
|
||||
@ -77,10 +77,10 @@ var series = new Bloodhound({
|
||||
|
||||
var tags = new Bloodhound({
|
||||
name: "tags",
|
||||
datumTokenizer(datum) {
|
||||
datumTokenizer: function datumTokenizer(datum) {
|
||||
return [datum.name];
|
||||
},
|
||||
queryTokenizer(query) {
|
||||
queryTokenizer: function queryTokenizer(query) {
|
||||
var tokens = query.split(",");
|
||||
tokens = [tokens[tokens.length-1].trim()];
|
||||
return tokens;
|
||||
@ -92,15 +92,15 @@ var tags = new Bloodhound({
|
||||
|
||||
var languages = new Bloodhound({
|
||||
name: "languages",
|
||||
datumTokenizer(datum) {
|
||||
datumTokenizer: function datumTokenizer(datum) {
|
||||
return [datum.name];
|
||||
},
|
||||
queryTokenizer(query) {
|
||||
queryTokenizer: function queryTokenizer(query) {
|
||||
return [query];
|
||||
},
|
||||
remote: {
|
||||
url: getPath()+"/get_languages_json?q=",
|
||||
replace(url, query) {
|
||||
replace: function replace(url, query) {
|
||||
return url+encodeURIComponent(query);
|
||||
}
|
||||
}
|
||||
@ -115,9 +115,9 @@ function sourceSplit(query, cb, split, source) {
|
||||
tokens.splice(tokens.length-1, 1); // remove last element
|
||||
var prefix = "";
|
||||
var newSplit;
|
||||
if (split === "&"){
|
||||
if (split === "&") {
|
||||
newSplit = " " + split + " ";
|
||||
}else{
|
||||
} else {
|
||||
newSplit = split + " ";
|
||||
}
|
||||
for (var i = 0; i < tokens.length; i++) {
|
||||
@ -127,76 +127,78 @@ function sourceSplit(query, cb, split, source) {
|
||||
}
|
||||
|
||||
var promiseAuthors = authors.initialize();
|
||||
promiseAuthors.done(function(){
|
||||
promiseAuthors.done(function() {
|
||||
$("#bookAuthor").typeahead(
|
||||
{
|
||||
highlight: true, minLength: 1,
|
||||
hint: true
|
||||
}, {
|
||||
name: "authors",
|
||||
displayKey: "name",
|
||||
source(query, cb){
|
||||
return sourceSplit(query, cb, "&", authors); //sourceSplit //("&")
|
||||
{
|
||||
highlight: true, minLength: 1,
|
||||
hint: true
|
||||
}, {
|
||||
name: "authors",
|
||||
displayKey: "name",
|
||||
source: function source(query, cb) {
|
||||
return sourceSplit(query, cb, "&", authors); //sourceSplit //("&")
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
var promiseSeries = series.initialize();
|
||||
promiseSeries.done(function(){
|
||||
promiseSeries.done(function() {
|
||||
$("#series").typeahead(
|
||||
{
|
||||
highlight: true, minLength: 0,
|
||||
hint: true
|
||||
}, {
|
||||
name: "series",
|
||||
displayKey: "name",
|
||||
source: series.ttAdapter()
|
||||
}
|
||||
{
|
||||
highlight: true, minLength: 0,
|
||||
hint: true
|
||||
}, {
|
||||
name: "series",
|
||||
displayKey: "name",
|
||||
source: series.ttAdapter()
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
var promiseTags = tags.initialize();
|
||||
promiseTags.done(function(){
|
||||
promiseTags.done(function() {
|
||||
$("#tags").typeahead(
|
||||
{
|
||||
highlight: true, minLength: 0,
|
||||
hint: true
|
||||
}, {
|
||||
name: "tags",
|
||||
displayKey: "name",
|
||||
source(query, cb){
|
||||
return sourceSplit(query, cb, ",", tags);
|
||||
}
|
||||
});
|
||||
});
|
||||
{
|
||||
highlight: true, minLength: 0,
|
||||
hint: true
|
||||
}, {
|
||||
name: "tags",
|
||||
displayKey: "name",
|
||||
source: function source(query, cb) {
|
||||
return sourceSplit(query, cb, ",", tags);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
var promiseLanguages = languages.initialize();
|
||||
promiseLanguages.done(function(){
|
||||
promiseLanguages.done(function() {
|
||||
$("#languages").typeahead(
|
||||
{
|
||||
highlight: true, minLength: 0,
|
||||
hint: true
|
||||
}, {
|
||||
name: "languages",
|
||||
displayKey: "name",
|
||||
source(query, cb){
|
||||
return sourceSplit(query, cb, ",", languages); //(",")
|
||||
}
|
||||
});
|
||||
});
|
||||
{
|
||||
highlight: true, minLength: 0,
|
||||
hint: true
|
||||
}, {
|
||||
name: "languages",
|
||||
displayKey: "name",
|
||||
source: function source(query, cb) {
|
||||
return sourceSplit(query, cb, ",", languages); //(",")
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$("#search").on("change input.typeahead:selected", function(){
|
||||
$("#search").on("change input.typeahead:selected", function() {
|
||||
var form = $("form").serialize();
|
||||
$.getJSON( getPath()+"/get_matching_tags", form, function( data ) {
|
||||
$(".tags_click").each(function() {
|
||||
if ($.inArray(parseInt($(this).children("input").first().val(), 10), data.tags) === -1 ) {
|
||||
if (!($(this).hasClass("active"))) {
|
||||
$(this).addClass("disabled");
|
||||
}
|
||||
}
|
||||
else {
|
||||
$(this).removeClass("disabled");
|
||||
}
|
||||
});
|
||||
$(".tags_click").each(function() {
|
||||
if ($.inArray(parseInt($(this).children("input").first().val(), 10), data.tags) === -1 ) {
|
||||
if (!($(this).hasClass("active"))) {
|
||||
$(this).addClass("disabled");
|
||||
}
|
||||
} else {
|
||||
$(this).removeClass("disabled");
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user