| @@ -1,0 +1,39 @@ | ||
| 1 | +"use strict"; | |
| 2 | +(function ($) { | |
| 3 | + $(window).on('elementor/frontend/init', function () { | |
| 4 | + let KngCustomCSSHandler = elementorModules.frontend.handlers.Base.extend({ | |
| 5 | + onInit: function onInit() { | |
| 6 | + if (this.$element.hasClass('kng-custom-css-yes')) { | |
| 7 | + this.applyKngCustomCSS(); | |
| 8 | + } | |
| 9 | + }, | |
| 10 | + getReadySettings: function getReadySettings() { | |
| 11 | + let settings = { | |
| 12 | + kng_custom_css: this.getElementSettings('kng_custom_css') | |
| 13 | + }; | |
| 14 | + return $.extend({}, settings); | |
| 15 | + }, | |
| 16 | + onElementChange: function onElementChange() { | |
| 17 | + if (this.$element.hasClass('kng-custom-css-yes')) { | |
| 18 | + this.applyKngCustomCSS(); | |
| 19 | + } else { | |
| 20 | + let element_ID = this.$element.data('id'); | |
| 21 | + $('.kng-custom-css-' + element_ID).remove(); | |
| 22 | + } | |
| 23 | + }, | |
| 24 | + applyKngCustomCSS: function applyKngCustomCSS() { | |
| 25 | + let options = this.getReadySettings(); | |
| 26 | + let element_ID = this.$element.data('id'); | |
| 27 | + $('.kng-custom-css-' + element_ID).remove(); | |
| 28 | + this.$element.before('<style class="kng-custom-css-' + element_ID + '">' + options.kng_custom_css.replace("[current-element]", '.elementor-element-' + element_ID) + '</style>'); | |
| 29 | + } | |
| 30 | + }); | |
| 31 | + | |
| 32 | + elementorFrontend.hooks.addAction('frontend/element_ready/global', function ($scope) { | |
| 33 | + elementorFrontend.elementsHandler.addHandler(KngCustomCSSHandler, { | |
| 34 | + $element: $scope | |
| 35 | + }); | |
| 36 | + }); | |
| 37 | + | |
| 38 | + }); | |
| 39 | +})(jQuery); | |