Elementor Pro (the WordPress page builder) integrates beautifully with Swiper, tying their GUI to the JS parameters and database content.
However, for my project, I need to make some changes to the Swiper "CoverFlow" skin Init parameters (show more slides, change the 3D effect facing direction...).
My hope is to to use the Destroy method of the Swiper API which looks like:
mySwiper.destroy(deleteInstance, cleanStyles);
Then I can initialize the Swiper again, with my own custom parameters. The challenge is that the way Elementor calls Swiper in frontend.js is a complex anonymous function that doesn't really allow me to know what "mySwiper" would be... On line 567:
this.swipers.main = new Swiper(this.elements.$mainSwiper, this.getSwiperOptions());
I would be so grateful if someone could please help me understand what "this.swipers.main" would translate to after Init so that I can destroy the swiper and initialize it again with my own parameters.
Obviously I cannot edit frontend.js itself as it is a plugin file that needs to be updated.
Extra points for whomever teaches me how to fish and what the methodology is to solve these types of puzzles for other similar situations.
You can give an ID to the Elementor widget ex: slider1 and then with JS you can use:
var sliderInstance = document.querySelector('#slider1 .swiper-container').swiper;
After this you can call sliderInstance.destroy() wherever you want.
And if you want to initialize it again you can call:
var sliderInstance = new Swiper('#slider1 .swiper-container', {
//options
});
Related
I have to deal with a node.js server project that uses global variables for common APIs. For instance in the entry point server.js there is a Firebase variable for the real-time database that is stored like this:
fireDB = admin.database();
I wasn't aware that this is possible and I would consider this a bad approach, but now I have to deal with it.
I'm not really interested to re-write any of the many calls to this variable in all those files, rather I would find a way to make fireDB show me suggestions only by changing this variable or installing an extension.
I tried to define it on top of the file as var fireDB, but then suggestions only work in the same file, not in others.
When I set a dot behind admin.database() the suggestions work, when I write fireDB. I get no suggestions, yet the call seems to be possible. Suggestions need to work in other files, too. How can I get this to work?
WARNING: MAKE SURE YOU UNDERSTAND THE PROBLEMS WITH GLOBALS BEFORE USING THEM IN A PROJECT
The above warning/disclaimer is mostly for anyone starting a new project that might happen across this answer.
With that out of the way, create a new .d.ts file and put it somewhere with a descriptive name. For example, globals.d.ts at the top level of the directory. Then just populate it with the following (I don't have any experience with firebase, so I had to make some assumptions about which module you're using, etc.):
globals.d.ts
import { database } from "firebase-admin";
declare global {
var fireDB: database.Database;
}
IntelliSense should then recognize fireDB as a global of the appropriate type in the rest of your JavaScript project.
Why does this work? IntelliSense uses TypeScript even if you're working with a JS project. Many popular JS packages includes a .d.ts file where typings are declared, which allows IntelliSense to suggest something useful when you type require('firebase-admin').database(), for example.
IntelliSense will also automatically create typings internally when you do something "obvious", e.g. with literals:
const MY_OBJ = { a: 1, b: "hello"};
MY_OBJ. // IntelliSense can already autocomplete properties "a" and "b" here
Global autocompletion isn't one of those "obvious" things, however, probably because of all the problems with global variables. I'd also guess it'd be difficult to efficiently know what order your files will run in (and hence when a global might be declared). Thus, you need to explicitly declare your global typings.
If you're interested in further augmenting the capabilities of IntelliSense within your JS project, you can also use comments to explicitly create typings:
/**
* #param {String[]} arrayOfStrings
*/
function asAnExample(arrayOfStrings) {
arrayOfStrings. // IntelliSense recognizes this as an array and will provide suggestions for it
}
See this TypeScript JSDoc reference for more on that.
I have already created a test blueprint that works, so I kinda got the idea, but I would like to make sure that I am approaching this correctly.
I want to extend the field type prompt to offer custom types alongside String, int, boolean etc.
This means I need to modify the templates, like templates/src/main/java/package/domain/Entity.java.ejs
My blueprint only had generators/client and generators/entity-client, so I guess I have to:
create generators/entity-server
create index.js
create files.js (can I copy that from here https://github.com/jhipster/generator-jhipster/blob/master/generators/entity-server/files.js ?)
create the templates in entity-server/templates
create generators/entity
copy and modify generators/entity/prompts.js: do I have to just write a new prompts.js, or do I have to copy over everything in generators/entity and only change what I would like to change ?
For the templates, can I copy them from the JHipster repo ?
Should I ? If not, why not and what is the alternative ?
If copying them is the right move, do I have to copy everything ? Or just the ones I want to modify ? (I haven't checked yet if I will need to modify everything)
When JHipster is updated, I suppose either I manually merge the new files, or I risk that slowly my code will differ more and more from the JHipster code ?
Is there a simpler method to achieve what I am trying to do ?
It would be nice if I could just say I want to add TypeX and TypeY to that prompt and provide limited templates that only cover those types, like a template for the import, one for the field, and one for the setter and getter, and if only the import is provided, a generic template is used.
I'll try to answer to all your questions.
First to create Blueprint I suggest to use https://github.com/jhipster/generator-jhipster-blueprint even in another folder and copy all you need for your current project. I think it's easier and you could choose which generator you want to add e.g. entity-server and entity.
Prompts phase
If you want to modify prompt phase you can merge your phase with the JHipster one like that
get prompting() {
const phaseFromJHipster = super._prompting();
const phaseFromMe = {
askForTheme: prompts.askForTheme,
setMySharedConfigOptions() {
this.configOptions.theme = this.theme;
}
};
return { ...phaseFromJHipster, ...phaseFromMe };
}
(source: https://github.com/avdev4j/samSuffit/tree/master/generators/client)
But by doing this you can't modify existing questions, for this case you should copy all existing questions into your blueprint.
Templates management
Your blueprint is linked with a JHipster version. As I used to say (in my talks) is that you should copy and modify templates from JHipster except for configuration files because it's a bit tricky to handle. For them, I prefer to use JHipster API like 'replaceContent()' or the needle API which allowed you to insert some code into some files (like a dependency in the pom.xml file).
Of course you can use the way you want, but with experiences I prefer to control my templates and merge them when I upgrade the JHipster version.
You should only copy the templates you want to modify, merge JHipster and your writing phase. JHipster use yeoman, which use memfs to handle file generation. Every files are created in memory and dumped at the final step. You can easily override a file without performance compromise.
get writing() {
const phaseFromJHipster = super._writing();
/* eslint-disable */
const phaseFromSam = {
writeSamFiles() {
if (this.clientFramework === 'angularX') {
return writeAngularFiles.call(this);
}
}
};
/* eslint-enable */
return { ...phaseFromJHipster, ...phaseFromSam };
}
JHipster upgrade
I suggest you to check templates when upgrading JHipster and apply modifications if needed. Otherwise, you could have bugs. Also, I suggest to set a definitive (like 6.1.0) version of JHipster in your blueprint package.json.
As far I know there is no way to do what you want to do. I'm thinking of a way to modify prompts easily without copying all other questions, if you want to contribute ;).
You can check my blueprint sample I use to show in my talks:
https://github.com/avdev4j/samSuffit/
I hope It can help you can, feel free to ask more.
regards,
I am creating a new module in Prestashop 1.6 which displays some data on the products page in the info box. I have created a new hook in the install method of the module like this: $this->registerHook('combinationDescription') and created the hookDisplayCombinationDescription function for assigning some smarty variables and displaying them with a tpl file.
After installing my module the hook is registered into the database so its usable.
Manually I can insert code into the product.tpl file just like: {hook h="hookDisplayCombinationDescription"} and I think it's working, but I would like to make this step automatically when the module gets installed. How can I do that?
My guess would be that to edit the product.tpl file from the install method of the module but it's a bit dirty method for me. Is there some other nice way to do that?
If you made a custom hook you need to insert its execution somewhere manually: into .tpl or into overrided ProductController.php (if it is an action hook). Prestashop can't execute it automatically for it doesn't know where do you want to execute it.
But you can use the default Prestashop 1.6 hooks to make your part of the code hooked and ready after the module installation. For the product page are these:
displayLeftColumnProduct
displayRightColumnProduct
displayProductTab
displayProductTabContent
displayFooterProduct
displayProductButtons
displayProductPriceBlock
actionProductOutOfStock
You can use one of these hooks and position your content with css (or javascript - to any part of the page).
If you make any custom hook then you have to make it executable first.Prestashop can't execute custom hooks automatically.But for displaying some data on product page you can use predefined prestashop hooks.Some are following
displayProductButtons
displayProductTab
To use these hooks, first you have to register hooks in install function like
public function install()
{
if (!parent::install() || !$this->registerHook('displayProductButtons')){
}
}
and in the same file you have to make a function like
public function hookDisplayProductButtons($params)
{
}
Now in that function you can assign some smarty variables which you want to access or show in your tpl file like
public function hookDisplayProductButtons($params)
{
$this->smarty->assign(array(
'product_name' => 'abc'
));
}
Now in your tpl file you can access that
If you want to add new custom hook and execute them when your particular module is active or installed.
Please follow the following steps:
Add you new custom hook code any where you want to perform your action.
Then, you can insert entry for that new custom hook into database at the time of installing module.
Now, your hook will execute as per your need.
Delete the same entry of hook from database at the time of uninstalling module so that hook could not be executed after uninstalling module.
I am not sure for, Is any other solution available to fulfill your need in prestashop?
So, there's a problem - I need to transplant "Categories Block" module to "displayTopColumn" hook (yep, designer put categories list near (on?) slider). But, by default, there is no possibilities to do this. I don't like that awful Prestashop restrictions, so maybe there is solution for this problem - remove those restrictions?
Thanks.
Removing those restrictions would not resolve anything for a simple reason: if you could hook the module blockcategories to displayTopColumn, this module would not know what to display in this hook because there is no hookDisplayTopColumn() function in it.
However, you can modify the module, and add a function to manage this hook.
To do so, open the file blockcategories.php and add the following:
public function hookDisplayTopColumn($params)
{
// Your code
}
If you want to display here the same content as in the hookLeftColumn hook, you can simply do this:
public function hookDisplayTopColumn($params)
{
return $this->hookLeftColumn($params);
}
You can also create your own function and template by copying, pasting and modifying the code you can find in the function hookLeftColumn() or in the function hookFooter().
I am facing an issue in declaring a fucation in block which I have added . I am calling a function by including an file which ia placed in the theme. I have also tried it by placing out of the theme folder. The function is alredy being user in front page. But when I am using the same function in that block. The screen gets blank and nothing displays. some part of my block coding is written below. Please help me.
<?php
global $base_url;
include($_SERVER['DOCUMENT_ROOT']."/travellar/geoiploc.php"); // indluded file
$ip = "203.189.25.0"; // Australia IP test
$country_code = getCountryFromIP($ip, "code");
I've had no problems loading functions from modules into custom blocks, but I've never tried loading one from a theme before. It's not clear to me whether or not theme functions are loaded before the page content is loaded.
You might have to create a custom module or include file to hold the function. Check out the module_load_include() function for how to load a specific include file.
A custom module would be a good approach as it is loaded before the theme layer and can be accessed from almost anywhere in Drupal except other modules with a lower weight than the custom module. It is also likely to come in handy for hooks and other overrides.
However, if you must have it in the theme layer, another option is adding it to template.php of your theme which should make it available within page.tpl.php and such, but not blocks I don't believe.
/sites/all/modules/mymodule/mymodule.info
name = My Module
package = !
description = It is MY module, not yours!
core = 6.x
The package "!" will make this module appear at the top of the modules page
/sites/all/modules/mymodule/mymodule.module
<?php
// Load mymodule.morePHP.inc
module_load_include('inc', 'mymodule', 'mymodule.morePHP');
// A custom function
function mymodule_my_custom_function($args) {
/* do custom stuff here */
return 'output';
}
/sites/all/modules/mymodule/mymodule.morePHP.inc
<?php
// An included custom function
function mymodule_other_custom_stuff() {
}