Merge remote-tracking branch 'adv/es5-syntax'

pull/308/head
OzzieIsaacs 7 years ago
commit 429f4a11a9

@ -4,31 +4,31 @@
/* global Bloodhound, language, Modernizr, tinymce */ /* global Bloodhound, language, Modernizr, tinymce */
if ($("#description").length) { if ($("#description").length) {
tinymce.init({ tinymce.init({
selector: "#description", selector: "#description",
branding: false, branding: false,
menubar: "edit view format", menubar: "edit view format",
language language: language
}); });
if (!Modernizr.inputtypes.date) { if (!Modernizr.inputtypes.date) {
$("#pubdate").datepicker({ $("#pubdate").datepicker({
format: "yyyy-mm-dd", format: "yyyy-mm-dd",
language language: language
}).on("change", function () { }).on("change", function () {
// Show localized date over top of the standard YYYY-MM-DD date // Show localized date over top of the standard YYYY-MM-DD date
let pubDate; var pubDate;
const results = /(\d{4})[-\/\\](\d{1,2})[-\/\\](\d{1,2})/.exec(this.value); // YYYY-MM-DD var results = /(\d{4})[-\/\\](\d{1,2})[-\/\\](\d{1,2})/.exec(this.value); // YYYY-MM-DD
if (results) { if (results) {
pubDate = new Date(results[1], parseInt(results[2], 10)-1, results[3]) || new Date(this.value); pubDate = new Date(results[1], parseInt(results[2], 10) - 1, results[3]) || new Date(this.value);
} }
$("#fake_pubdate") $("#fake_pubdate")
.val(pubDate.toLocaleDateString(language)) .val(pubDate.toLocaleDateString(language))
.removeClass("hidden"); .removeClass("hidden");
}).trigger("change"); }).trigger("change");
} }
} }
/* /*
Takes a prefix, query typeahead callback, Bloodhound typeahead adapter Takes a prefix, query typeahead callback, Bloodhound typeahead adapter
and returns the completions it gets from the bloodhound engine prefixed. and returns the completions it gets from the bloodhound engine prefixed.
@ -43,6 +43,7 @@ function prefixedSource(prefix, query, cb, bhAdapter) {
cb(matches); cb(matches);
}); });
} }
function getPath() { function getPath() {
var jsFileLocation = $("script[src*=edit_books]").attr("src"); // the js file path var jsFileLocation = $("script[src*=edit_books]").attr("src"); // the js file path
jsFileLocation = jsFileLocation.replace("/static/js/edit_books.js", ""); // the js folder path jsFileLocation = jsFileLocation.replace("/static/js/edit_books.js", ""); // the js folder path
@ -56,7 +57,7 @@ var authors = new Bloodhound({
}, },
queryTokenizer: Bloodhound.tokenizers.whitespace, queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: { remote: {
url: getPath()+"/get_authors_json?q=%QUERY" url: getPath() + "/get_authors_json?q=%QUERY"
} }
}); });
@ -69,9 +70,9 @@ var series = new Bloodhound({
return [query]; return [query];
}, },
remote: { remote: {
url: getPath()+"/get_series_json?q=", url: getPath() + "/get_series_json?q=",
replace: function replace(url, query) { replace: function replace(url, query) {
return url+encodeURIComponent(query); return url + encodeURIComponent(query);
} }
} }
}); });
@ -84,11 +85,11 @@ var tags = new Bloodhound({
}, },
queryTokenizer: function queryTokenizer(query) { queryTokenizer: function queryTokenizer(query) {
var tokens = query.split(","); var tokens = query.split(",");
tokens = [tokens[tokens.length-1].trim()]; tokens = [tokens[tokens.length - 1].trim()];
return tokens; return tokens;
}, },
remote: { remote: {
url: getPath()+"/get_tags_json?q=%QUERY" url: getPath() + "/get_tags_json?q=%QUERY"
} }
}); });
@ -101,9 +102,9 @@ var languages = new Bloodhound({
return [query]; return [query];
}, },
remote: { remote: {
url: getPath()+"/get_languages_json?q=", url: getPath() + "/get_languages_json?q=",
replace: function replace(url, query) { replace: function replace(url, query) {
return url+encodeURIComponent(query); return url + encodeURIComponent(query);
} }
} }
}); });
@ -112,9 +113,9 @@ function sourceSplit(query, cb, split, source) {
var bhAdapter = source.ttAdapter(); var bhAdapter = source.ttAdapter();
var tokens = query.split(split); var tokens = query.split(split);
var currentSource = tokens[tokens.length-1].trim(); var currentSource = tokens[tokens.length - 1].trim();
tokens.splice(tokens.length-1, 1); // remove last element tokens.splice(tokens.length - 1, 1); // remove last element
var prefix = ""; var prefix = "";
var newSplit; var newSplit;
if (split === "&") { if (split === "&") {
@ -192,7 +193,7 @@ promiseLanguages.done(function() {
$("#search").on("change input.typeahead:selected", function() { $("#search").on("change input.typeahead:selected", function() {
var form = $("form").serialize(); var form = $("form").serialize();
$.getJSON( getPath()+"/get_matching_tags", form, function( data ) { $.getJSON( getPath() + "/get_matching_tags", form, function( data ) {
$(".tags_click").each(function() { $(".tags_click").each(function() {
if ($.inArray(parseInt($(this).children("input").first().val(), 10), data.tags) === -1 ) { if ($.inArray(parseInt($(this).children("input").first().val(), 10), data.tags) === -1 ) {
if (!($(this).hasClass("active"))) { if (!($(this).hasClass("active"))) {

Loading…
Cancel
Save