From da7fef94f7df6bafbea49779dd247b45b7b855ad Mon Sep 17 00:00:00 2001
From: Denys Rul <drul@ebay.com>
Date: Fri, 23 Jan 2015 18:29:28 +0200
Subject: [PATCH] MAGETWO-32484: Stabilization of changes and bug fixing

- Change components initialization
---
 .../view/frontend/templates/onepage.phtml     | 40 ++++++++++-------
 .../view/frontend/web/js/accordion.js         | 43 -------------------
 .../frontend/web/js/opc-checkout-method.js    |  1 -
 3 files changed, 25 insertions(+), 59 deletions(-)
 delete mode 100644 app/code/Magento/Checkout/view/frontend/web/js/accordion.js

diff --git a/app/code/Magento/Checkout/view/frontend/templates/onepage.phtml b/app/code/Magento/Checkout/view/frontend/templates/onepage.phtml
index b908011858b..a75fb924b01 100644
--- a/app/code/Magento/Checkout/view/frontend/templates/onepage.phtml
+++ b/app/code/Magento/Checkout/view/frontend/templates/onepage.phtml
@@ -25,24 +25,34 @@ $_paymentBlock = $this->getLayout()->getBlock('checkout.onepage.payment');
     </ol>
     <script>
 require([
-    "jquery",
-    "mage/mage"
-], function($){
+    "underscore",
+    "accordion",
+    "opcOrderReview",
+], function(_, accordion, opcOrderReview){
     'use strict';
 
-    $(document).ready(function() {
-        $('#checkoutSteps').mage('accordion',{
-            'collapsibleElement' : ' > li',
-            'openedState' : 'active'
-        }).mage('opcOrderReview', $.extend({
-            'checkoutAgreements': '#checkout-agreements',
-            'checkoutProgressContainer': '#checkout-progress-wrapper',
-            'methodDescription': '.items'
-            },
-            <?php echo $this->helper('Magento\Core\Helper\Data')->jsonEncode($_paymentBlock->getOptions()); ?>
-        ));
-    });
+    /**
+     * @todo refactor opcCheckoutMethod
+     *
+     * Initializiation of this components can't be moved to a data-mage-init attribute
+     * due to dependencies between instances of opcCheckoutMethod and mage.accordion.
+     * Thus initializiation has to be synchronyous.
+     */
+    var elem = document.getElementById('checkoutSteps'),
+        opcConfig;
 
+    opcConfig = _.extend({
+        'checkoutAgreements': '#checkout-agreements',
+        'checkoutProgressContainer': '#checkout-progress-wrapper',
+        'methodDescription': '.items'
+    },<?php echo $this->helper('Magento\Core\Helper\Data')->jsonEncode($_paymentBlock->getOptions()); ?>);
+
+    accordion({
+        'collapsibleElement': ' > li',
+        'openedState': 'active'
+    }, elem);
+
+    opcOrderReview(opcConfig, elem);
 });
 </script>
 </div>
diff --git a/app/code/Magento/Checkout/view/frontend/web/js/accordion.js b/app/code/Magento/Checkout/view/frontend/web/js/accordion.js
deleted file mode 100644
index 9793d45d07a..00000000000
--- a/app/code/Magento/Checkout/view/frontend/web/js/accordion.js
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * Copyright © 2015 Magento. All rights reserved.
- * See COPYING.txt for license details.
- */
-/*jshint jquery:true browser:true*/
-define([
-    "jquery",
-    "jquery/ui"
-], function($){
-    'use strict';
-
-    // mage.accordion base functionality
-    $.widget('mage.accordion', $.ui.accordion, {
-        options: {
-            heightStyle: 'content',
-            animate: false,
-            beforeActivate: function(e, ui) {
-                // Make sure sections below current are not clickable and sections above are clickable
-                var newPanelParent = $(ui.newPanel).parent();
-                if (!newPanelParent.hasClass('allow')) {
-                    return false;
-                }
-                newPanelParent.addClass('active allow').prevAll().addClass('allow');
-                newPanelParent.nextAll().removeClass('allow');
-                $(ui.oldPanel).parent().removeClass('active');
-            }
-        },
-
-        /**
-         * Accordion creation
-         * @protected
-         */
-        _create: function() {
-            // Custom to enable section
-            this.element.on('enableSection', function(event, data) {
-                $(data.selector).addClass('allow').find('h2').trigger('click');
-            });
-            this._super();
-            $(this.options.activeSelector).addClass('allow active').find('h2').trigger('click');
-        }
-    });
-
-});
\ No newline at end of file
diff --git a/app/code/Magento/Checkout/view/frontend/web/js/opc-checkout-method.js b/app/code/Magento/Checkout/view/frontend/web/js/opc-checkout-method.js
index 3eacc8103b7..09c2b3d679f 100644
--- a/app/code/Magento/Checkout/view/frontend/web/js/opc-checkout-method.js
+++ b/app/code/Magento/Checkout/view/frontend/web/js/opc-checkout-method.js
@@ -10,7 +10,6 @@ define([
     "jquery",
     "jquery/ui",
     "mage/validation/validation",
-    "Magento_Checkout/js/accordion",
     "mage/translate"
 ], function($){
     'use strict';
-- 
GitLab