🚧 [jquery] Preparando el módulo para un tutorial
This commit is contained in:
parent
7138b9c58b
commit
e033630d2a
3 changed files with 30 additions and 16 deletions
|
|
@ -2,10 +2,11 @@ use pagetop::prelude::*;
|
|||
|
||||
use_handle!(MODULE_JQUERY);
|
||||
|
||||
use_locale!(LOCALE_JQUERY);
|
||||
|
||||
use_static!(jquery);
|
||||
|
||||
const JQUERY_PARAM: &str = "jquery.add";
|
||||
const JQUERY_SOURCE: &str = "/jquery/3.6.0/jquery.min.js";
|
||||
|
||||
pub struct JQuery;
|
||||
|
||||
|
|
@ -14,6 +15,18 @@ impl ModuleTrait for JQuery {
|
|||
MODULE_JQUERY
|
||||
}
|
||||
|
||||
fn actions(&self) -> Vec<Action> {
|
||||
vec![action!(ActionBeforeRenderPage => before_render_page)]
|
||||
}
|
||||
|
||||
fn name(&self) -> L10n {
|
||||
L10n::t("module_name", &LOCALE_JQUERY)
|
||||
}
|
||||
|
||||
fn description(&self) -> L10n {
|
||||
L10n::t("module_description", &LOCALE_JQUERY)
|
||||
}
|
||||
|
||||
fn configure_service(&self, cfg: &mut service::web::ServiceConfig) {
|
||||
serve_static_files!(cfg, "/jquery", jquery);
|
||||
}
|
||||
|
|
@ -21,23 +34,20 @@ impl ModuleTrait for 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_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);
|
||||
}
|
||||
}
|
||||
|
||||
fn before_render_page(page: &mut Page) {
|
||||
if let Some(true) = page.context().get_param::<bool>(JQUERY_PARAM) {
|
||||
page.context().alter(ContextOp::AddJavaScript(
|
||||
JavaScript::located("/jquery/3.6.0/jquery.min.js")
|
||||
.with_weight(isize::MIN)
|
||||
.with_mode(ModeJS::Normal),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
pagetop-jquery/src/locale/en-US/module.flt
Normal file
2
pagetop-jquery/src/locale/en-US/module.flt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
module_name = jQuery support
|
||||
module_description = Integrate the jQuery library into web pages generated by other modules.
|
||||
2
pagetop-jquery/src/locale/es-ES/module.flt
Normal file
2
pagetop-jquery/src/locale/es-ES/module.flt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
module_name = Soporte a jQuery
|
||||
module_description = Incorpora la librería jQuery en páginas web generadas por otros módulos.
|
||||
Loading…
Add table
Add a link
Reference in a new issue