Javascript
How do we make our apps interactive with modern JS implementation
Jquery
We want to remove all the legacy jquery.
VueJs (new way)
This waits for the DOM-tree to load and then starts to initialize a vue-app. It works just as jQuery
, ready()
, but without jQuery
.
Components
Example
Linting
The vue plugin of eslint is set at the 'recommended' level to lint our code in .eslintrc.js
.
Known issue
vue-cli-service: command not found
Solution
rm -rf node_modules yarn.lock && yarn install
i18n
Usage
Tip: When going from i18n stored in Rails to i18n handled directly in the front, ruby -rjson -ryaml -e "puts YAML.load_file('path/file_to_convert.yml').to_json"
will take a .yml
file and output its corresponding JSON for ease of conversion.
VueJs (old way)
Forms
Even if some forms still use some jquery, most of the SeraphinWeb forms are enhanced with a Vuejs app
(#vueApp
) to manipulate the DOM.
Profiling forms
The majority of our products purchase process begin with a profiling form to gather product oriented data and data from the user.
Two Vue apps are used :
#vueApp
- for all the product specific questions#vueProfiling
- for the generic shared questions on the user
The profiling Vue app :
is in shared partial, so it needs to be included in the view
needs to get data from the back end
form
:data: #{ raw form.serialized_data.to_json }
Note that the back end profiling form needs to have the serialized_data
method accordingly.
Mixins
It exists a special Vue instance with sole purpose to be used as a mixin by other Vue app. This Vue app is stateless and only contains helper methods.
Script
To enhance SeraphinWeb front end, some scripts are injected.
examples :
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src='https://maps.googleapis.com/maps/api/js?...'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/intro.js/2.7.0/intro.min.js'></script>
Polyfills
Because SeraphinWeb needs to be compliant with old browsers (IE, safari...), polyfills are used.
examples :
<script src='https://cdn.polyfill.io/v2/polyfill.min.js?features=default,Array.prototype.includes'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/es6-promise/4.1.1/es6-promise.auto.min.js'></script>
Last updated