Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
282837c7
Commit
282837c7
authored
Aug 28, 2017
by
Jonathan Rehm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use ES5 syntax
parent
a8b53ab3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
33 deletions
+34
-33
edit_books.js
cps/static/js/edit_books.js
+34
-33
No files found.
cps/static/js/edit_books.js
View file @
282837c7
...
@@ -4,31 +4,31 @@
...
@@ -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) {
...
@@ -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({
...
@@ -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({
...
@@ -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({
...
@@ -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({
...
@@ -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) {
...
@@ -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() {
...
@@ -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"
)))
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment