🎉 [jquery] Módulo para incluir jQuery en páginas
This commit is contained in:
parent
20f6c85e68
commit
b95a154a34
6 changed files with 97 additions and 0 deletions
44
pagetop-jquery/src/lib.rs
Normal file
44
pagetop-jquery/src/lib.rs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
use pagetop::prelude::*;
|
||||
|
||||
pub_handle!(MODULE_JQUERY);
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/jquery.rs"));
|
||||
|
||||
const JQUERY_PARAM: &str = "jquery.add";
|
||||
const JQUERY_SOURCE: &str = "/jquery/js/jquery.min.js";
|
||||
|
||||
pub struct JQuery;
|
||||
|
||||
impl ModuleTrait for JQuery {
|
||||
fn handle(&self) -> Handle {
|
||||
MODULE_JQUERY
|
||||
}
|
||||
|
||||
fn configure_service(&self, cfg: &mut server::web::ServiceConfig) {
|
||||
serve_static_files!(cfg, "/jquery", bundle_jquery);
|
||||
}
|
||||
}
|
||||
|
||||
impl JQuery {
|
||||
pub fn add_jquery(rcx: &mut RenderContext) {
|
||||
match rcx.get_param::<bool>(JQUERY_PARAM) {
|
||||
Some(true) => {}
|
||||
_ => {
|
||||
rcx.alter(ContextOp::AddJavaScript(
|
||||
JavaScript::located(JQUERY_SOURCE)
|
||||
.with_version("3.6.0")
|
||||
.with_weight(isize::MIN)
|
||||
.with_mode(ModeJS::Normal),
|
||||
));
|
||||
rcx.set_param::<bool>(JQUERY_PARAM, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remove_jquery(rcx: &mut RenderContext) {
|
||||
if let Some(true) = rcx.get_param::<bool>(JQUERY_PARAM) {
|
||||
rcx.alter(ContextOp::RemoveJavaScript(JQUERY_SOURCE));
|
||||
rcx.set_param::<bool>(JQUERY_PARAM, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue