2019-03-20 17:56:17 +01:00
|
|
|
#![recursion_limit = "128"]
|
2019-03-15 16:06:10 +01:00
|
|
|
#![feature(decl_macro, proc_macro_hygiene, try_trait)]
|
|
|
|
|
|
|
|
extern crate gettext;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate gettext_macros;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
2018-12-25 11:51:40 +01:00
|
|
|
#[macro_use]
|
|
|
|
extern crate stdweb;
|
|
|
|
|
2019-03-20 17:56:17 +01:00
|
|
|
use stdweb::web::{event::*, *};
|
2019-03-15 16:06:10 +01:00
|
|
|
|
|
|
|
init_i18n!("plume-front", en, fr);
|
|
|
|
|
|
|
|
mod editor;
|
|
|
|
|
|
|
|
compile_i18n!();
|
|
|
|
|
|
|
|
lazy_static! {
|
|
|
|
static ref CATALOG: gettext::Catalog = {
|
|
|
|
let catalogs = include_i18n!();
|
2019-03-20 17:56:17 +01:00
|
|
|
let lang = js! { return navigator.language }.into_string().unwrap();
|
2019-03-15 16:06:10 +01:00
|
|
|
let lang = lang.splitn(2, '-').next().unwrap_or("en");
|
2019-03-20 17:56:17 +01:00
|
|
|
catalogs
|
|
|
|
.iter()
|
|
|
|
.find(|(l, _)| l == &lang)
|
|
|
|
.unwrap_or(&catalogs[0])
|
|
|
|
.clone()
|
|
|
|
.1
|
2019-03-15 16:06:10 +01:00
|
|
|
};
|
|
|
|
}
|
2018-12-25 11:51:40 +01:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
menu();
|
|
|
|
search();
|
2019-03-15 16:06:10 +01:00
|
|
|
editor::init()
|
2019-03-20 17:56:17 +01:00
|
|
|
.map_err(|e| console!(error, format!("Editor error: {:?}", e)))
|
|
|
|
.ok();
|
2018-12-25 11:51:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Toggle menu on mobile device
|
|
|
|
///
|
|
|
|
/// It should normally be working fine even without this code
|
|
|
|
/// But :focus-within is not yet supported by Webkit/Blink
|
|
|
|
fn menu() {
|
2019-03-19 14:37:56 +01:00
|
|
|
if let Some(button) = document().get_element_by_id("menu") {
|
|
|
|
if let Some(menu) = document().get_element_by_id("content") {
|
|
|
|
button.add_event_listener(|_: ClickEvent| {
|
2019-03-20 17:56:17 +01:00
|
|
|
document()
|
|
|
|
.get_element_by_id("menu")
|
|
|
|
.map(|menu| menu.class_list().add("show"));
|
2019-03-19 14:37:56 +01:00
|
|
|
});
|
|
|
|
menu.add_event_listener(|_: ClickEvent| {
|
2019-03-20 17:56:17 +01:00
|
|
|
document()
|
|
|
|
.get_element_by_id("menu")
|
|
|
|
.map(|menu| menu.class_list().remove("show"));
|
2019-03-19 14:37:56 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2018-12-25 11:51:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Clear the URL of the search page before submitting request
|
|
|
|
fn search() {
|
2019-03-19 14:37:56 +01:00
|
|
|
if let Some(form) = document().get_element_by_id("form") {
|
|
|
|
form.add_event_listener(|_: SubmitEvent| {
|
2019-03-20 17:56:17 +01:00
|
|
|
document()
|
|
|
|
.query_selector_all("#form input")
|
|
|
|
.map(|inputs| {
|
|
|
|
for input in inputs {
|
|
|
|
js! {
|
|
|
|
if (@{&input}.name === "") {
|
|
|
|
@{&input}.name = @{&input}.id
|
|
|
|
}
|
|
|
|
if (@{&input}.name && !@{&input}.value) {
|
|
|
|
@{&input}.name = "";
|
|
|
|
}
|
2018-12-25 11:51:40 +01:00
|
|
|
}
|
|
|
|
}
|
2019-03-20 17:56:17 +01:00
|
|
|
})
|
|
|
|
.ok();
|
2018-12-25 11:51:40 +01:00
|
|
|
});
|
2019-03-19 14:37:56 +01:00
|
|
|
}
|
2018-12-25 11:51:40 +01:00
|
|
|
}
|