Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
js.phtml
Go to the documentation of this file.
1 <?php
7 // @codingStandardsIgnoreFile
8 
10 ?>
11 <script>
12 require([
13  "jquery",
14  "prototype",
15  "mage/backend/tabs"
16 ], function(jQuery){
17 
18 //<![CDATA[
19 Event.observe(window, 'load', recalculateTax);
20 Event.observe(window, 'load', registerTaxRecalcs);
21 
22 function registerTaxRecalcs() {
23  if (typeof dynamicTaxes == 'undefined') {
24  return;
25  }
26 
27  for (var i = 0; i < dynamicTaxes.length; i++) {
28  Event.observe($(dynamicTaxes[i]), 'change', recalculateTax);
29  }
30  Event.observe($('tax_class_id'), 'change', recalculateTax);
31 }
32 
33 var priceFormat = <?= /* @escapeNotVerified */ $this->helper('Magento\Tax\Helper\Data')->getPriceFormat($block->getStore()) ?>;
34 var taxRates = <?= /* @escapeNotVerified */ $block->getAllRatesByProductClassJson() ?>;
35 
36 function recalculateTax() {
37  if (typeof dynamicTaxes == 'undefined') {
38  return;
39  }
40 
41  for (var i = 0; i < dynamicTaxes.length; i++) {
42  var code = dynamicTaxes[i];
43  var span = $('dynamic-tax-' + code);
44  var input = $(code);
45 
46  if (!input.value) {
47  span.innerHTML = '';
48  continue;
49  }
50 
51  var rate = 0,
52  taxClass = $('tax_class_id').options[$('tax_class_id').selectedIndex].value,
53  value = taxRates['value_' + taxClass];
54 
55  if (value != undefined) {
56  rate = value;
57  }
58 
59  var spanValue = '';
60  if (rate != 0) {
61  spanValue = ' ' + formatCurrency(input.value / (100 + rate) * rate, priceFormat);
62  }
63  span.innerHTML = spanValue;
64  }
65 }
66 
67 // Bind tab changes
68 function bindActiveProductTab(event, ui) {
69  var anchor = jQuery(ui.newTab).find('a');
70  if (anchor && anchor.name && $('store_switcher')) {
71  $('store_switcher').switchParams = 'active_tab/' + anchor.name + '/';
72  }
73 }
74 //varienGlobalEvents.attachEventHandler('showTab', bindActiveProductTab);
75 jQuery(document).on('tabsactivate', bindActiveProductTab);
76 
77 // bind active tab
78 <?php if ($tabsBlock = $block->getLayout()->getBlock('product_tabs')): ?>
79 jQuery(function () {
80  if (jQuery('#<?= /* @escapeNotVerified */ $tabsBlock->getId() ?>').length && jQuery('#<?= /* @escapeNotVerified */ $tabsBlock->getId() ?>').is(':mage-tabs')) {
81  var activeAnchor = jQuery('#<?= /* @escapeNotVerified */ $tabsBlock->getId() ?>').tabs('activeAnchor');
82  if (activeAnchor && $('store_switcher')) {
83  $('store_switcher').switchParams = 'active_tab/' + activeAnchor.prop('name') + '/';
84  }
85  }
86 });
87 <?php endif; ?>
88 
89 window.recalculateTax = recalculateTax;
90 window.bindActiveProductTab = bindActiveProductTab;
91 window.registerTaxRecalcs = registerTaxRecalcs;
92 //]]>
93 
94 });
95 </script>
$block setTitle( 'CMS Block Title') -> setIdentifier('fixture_block') ->setContent('< h1 >Fixture Block Title</h1 >< a href=" store url</a><p> Config value
Definition: block.php:9
$block
Definition: block.php:8
endif
Definition: js.phtml:216
jquery ui
Definition: tree.phtml:41
jQuery('.store-switcher .dropdown-menu li a').each(function()
Definition: switcher.phtml:203