blocks
4 years ago
admin.js
2 months ago
asset_manager_core_js.js
3 months ago
iframeResizer.contentWindow.min.js
2 years ago
iframeResizer.min.js
2 years ago
marketplace_setup_wizard.js
3 months ago
optout.js
1 year ago
settings.js
1 year ago
settings.js
85 lines
| 1 | /** |
| 2 | * Matomo - free/libre analytics platform |
| 3 | * |
| 4 | * @link https://matomo.org |
| 5 | * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 6 | * @package matomo |
| 7 | */ |
| 8 | |
| 9 | window.jQuery(document).ready(function ($) { |
| 10 | // generated tracking code update |
| 11 | if (typeof mtmTrackingSettingsAjax !== 'undefined' && mtmTrackingSettingsAjax.ajax_url) { |
| 12 | var DEFAULT_DEBOUNCE_DELAY = 300; |
| 13 | |
| 14 | function debounce(fn, delayInMs) { |
| 15 | var timeout; |
| 16 | |
| 17 | delayInMs = delayInMs || DEFAULT_DEBOUNCE_DELAY; |
| 18 | |
| 19 | return function wrapper() { |
| 20 | var args = Array.from(arguments); |
| 21 | if (timeout) { |
| 22 | clearTimeout(timeout); |
| 23 | } |
| 24 | |
| 25 | timeout = setTimeout(() => { |
| 26 | fn.apply(this, args); |
| 27 | }, delayInMs); |
| 28 | }; |
| 29 | } |
| 30 | |
| 31 | function updateGeneratedTrackingCode() { |
| 32 | var settings = $('form#tracking-settings').serializeArray().reduce(function (accumulator, current) { |
| 33 | if (/^_/.test(current.name)) { |
| 34 | return accumulator; |
| 35 | } |
| 36 | accumulator[current.name.replace(/^matomo\[(.*?)\]$/, '$1')] = current.value; |
| 37 | return accumulator; |
| 38 | }, {}); |
| 39 | |
| 40 | $.post( |
| 41 | mtmTrackingSettingsAjax.ajax_url, |
| 42 | Object.assign(settings, { |
| 43 | _ajax_nonce: mtmTrackingSettingsAjax.nonce, |
| 44 | action: 'matomo_generate_tracking_code', |
| 45 | }), |
| 46 | function (data) { |
| 47 | if (data) { |
| 48 | $('#generated_tracking_code').text(data.script); |
| 49 | $('#generated_noscript_code').text(data.noscript); |
| 50 | } |
| 51 | }, |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | updateGeneratedTrackingCode = debounce(updateGeneratedTrackingCode, 300); |
| 56 | |
| 57 | $('#auto-tracking-settings').on('change', ':not(#generatedTrackingCode)', updateGeneratedTrackingCode); |
| 58 | updateGeneratedTrackingCode(); |
| 59 | } |
| 60 | |
| 61 | // warn if user has unsaved changes |
| 62 | var initialFormContents = $('#tracking-settings').serialize(); |
| 63 | function beforePageUnload(e) { |
| 64 | var currentFormContents = $('#tracking-settings').serialize(); |
| 65 | if (initialFormContents !== currentFormContents) { |
| 66 | e.preventDefault(); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | window.addEventListener('beforeunload', beforePageUnload); |
| 71 | $('form#tracking-settings').on('submit', function () { |
| 72 | window.removeEventListener('beforeunload', beforePageUnload); |
| 73 | }); |
| 74 | |
| 75 | // auto-expand section if hash points to section |
| 76 | function onHashChange() { |
| 77 | var target = $(window.location.hash); |
| 78 | if (target.length) { |
| 79 | target.closest('.collapsible-settings').addClass('expanded'); |
| 80 | } |
| 81 | } |
| 82 | window.addEventListener('hashchange', onHashChange); |
| 83 | onHashChange(); |
| 84 | }); |
| 85 |