|
| 1 | +# Teamplate iFrame Widget |
| 2 | + |
| 3 | +This teamplate is mean to be used to create new experiences that can be included using iFrames into other application and websites. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +Create a new repository from this template. |
| 8 | + |
| 9 | +Clone your new repository to your local machine. |
| 10 | + |
| 11 | +Install the dependencies: |
| 12 | + |
| 13 | +```bash |
| 14 | +npm i |
| 15 | +``` |
| 16 | + |
| 17 | +Run the development server: |
| 18 | + |
| 19 | +```bash |
| 20 | +npm start |
| 21 | +``` |
| 22 | + |
| 23 | +You can view the development server at [http://localhost:4001](http://localhost:4001). |
| 24 | + |
| 25 | +### Production build |
| 26 | + |
| 27 | +```bash |
| 28 | +npm run build |
| 29 | +``` |
| 30 | + |
| 31 | +### Where to add your code |
| 32 | + |
| 33 | +Here are the main files and folders you will be working with: |
| 34 | + |
| 35 | +#### Assets and Images |
| 36 | + |
| 37 | +Add your assets and images into `src/assets/` folder. These will be copied into `dist/` folder as is |
| 38 | + |
| 39 | +#### HTML |
| 40 | + |
| 41 | +Add your custom HTML code into template `src/html/content.html`, this file will be added as innerHTML of the `body` element in templae `src/html/_index.html` file. This will be compiled into `dist/index.html`. |
| 42 | + |
| 43 | +#### CSS |
| 44 | + |
| 45 | +CSS is being compiled using SASS. Add your custom SASS code into template `src/sass/content.scss`, this will be compiled into `dist/widget.css`. |
| 46 | + |
| 47 | +#### JS |
| 48 | + |
| 49 | +Add your custom JS code into js files in `src/js/`. Each file will be concatanated into `dist/widget.js`. Files are concatanated in the order they are listed in the folder. |
| 50 | + |
| 51 | +#### JS Vendor Libs |
| 52 | + |
| 53 | +To add vendor JS libraries that will be compiled into `dist/vendor.js` and `dist/vendor.css` update the following section in `webpack.common.js`: |
| 54 | + |
| 55 | +```javascript |
| 56 | +new MergeIntoSingleFilePlugin({ |
| 57 | + files: { |
| 58 | + "vendor.js": [ |
| 59 | + 'node_modules/jquery/dist/jquery.min.js', |
| 60 | + 'node_modules/@popperjs/core/dist/umd/popper.js', |
| 61 | + 'node_modules/bootstrap/dist/js/bootstrap.js', |
| 62 | + 'node_modules/d3/dist/d3.js', |
| 63 | + ], |
| 64 | + "vendor.css": [ |
| 65 | + //nothing here yet |
| 66 | + ], |
| 67 | + "widget.js": [ |
| 68 | + paths.src + '/js/**/*.js', |
| 69 | + ] |
| 70 | + } |
| 71 | + }), |
| 72 | + |
| 73 | +``` |
| 74 | + |
| 75 | +##### JS Conventions |
| 76 | + |
| 77 | +Please keep JS simple, clean and namespaced. |
| 78 | + |
| 79 | +When adding new files "modules" use this as the template for your new module. |
| 80 | + |
| 81 | +```javascript |
| 82 | +//define namespace for your JS file |
| 83 | +//window.Widgets = {}; // already defined in _namespace.js |
| 84 | +window.Widgets.Widget = {}; |
| 85 | + |
| 86 | +//define your function to use in your component |
| 87 | +(function($, ns, componentsNs, document, window) { |
| 88 | + ns.version = '1.0.0'; |
| 89 | + |
| 90 | + ns.selectorComponent = '.js-component'; |
| 91 | + |
| 92 | + ns.init = function() { |
| 93 | + //initialize your class |
| 94 | + }; |
| 95 | + |
| 96 | +})(jQuery, Widgets.Widget, window.Widgets, document, window); |
| 97 | + |
| 98 | +//define your behaviour how will this component will be added to DOM. |
| 99 | +(function($, ns, componentsNs, document, window) { |
| 100 | + |
| 101 | + //watch for the component to be added to DOM |
| 102 | + componentsNs.watchDOMForComponent(`${ns.selectorComponent}`, ns.init); |
| 103 | + |
| 104 | +})(window.jQuery, window.Widgets.Widget, window.Widgets, document, window); |
| 105 | + |
| 106 | +``` |
| 107 | + |
0 commit comments