Skip to content

accordion ui widget name conflict #4334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shabith opened this issue Apr 28, 2016 · 5 comments
Closed

accordion ui widget name conflict #4334

shabith opened this issue Apr 28, 2016 · 5 comments

Comments

@shabith
Copy link

shabith commented Apr 28, 2016

Steps to reproduce

  1. implement a jQueryUI Accordion inside a jQueryUI widget
define([
   "jquery",
   "jquery/ui"
], function ($) {
   "use strict"

   $.widget("Ns.help", {
        _create: function () {

        $('#help').accordion({
           active: 2
        });

        }
    });

   return $.Ns.help;
});

Expected result

  1. show jQueryUI accordion

Actual result

  1. show mage accordion

In detail

both plugins has the same name but different name space ($.mage.accordion and $.ui.accordion)
So when we try to implement an accordion it will create a naming conflict.

Solution

At the moment only possible way to avoid this conflict is by using $.ui.bridge

$.widget.bridge( "mage_accordion", $.mage.accordion );
$.widget.bridge( "ui_accordion", $.ui.accordion );

// then call it with...
$('#help').ui_accordion({
           active: 2
        });
@piotrekkaminski
Copy link
Contributor

@guz-anton @vkorotun can you look into it?

@veloraven
Copy link
Contributor

@shabith is this issue still actual?
If it is please specify Magento version you are running.

@shabith
Copy link
Author

shabith commented Nov 2, 2016

@veloraven yes! the issue still exists.
Magento ver. 2.1.2

@ennostuurman
Copy link

@shabith I came across your post looking for a way to use and extend jQuery UI accordion in a custom Magento 2 theme.

I fixed it avoiding the collision between mage.accordion and jQuery UI accordion (accordion is mapped to mage.accordion in vendor/magento/module-theme/view/frontend/requirejs-config.js)

This solution is based upon Magento devdocs (http://devdocs.magento.com/guides/v2.1/javascript-dev-guide/javascript/js_practice.html) and the jQuery UI widget documentation ( http://learn.jquery.com/jquery-ui/widget-factory/extending-widgets/ ).

  1. Adjust your custom js file to extend the jquery/ui accordion:
define([
    "jquery",
    "jquery/ui"
], function ($) {
    "use strict"
        $.widget("customnamespace.accordion", $.ui.accordion, {
        });
    return $.customnamespace.accordion;
});
  1. Namespace your local js accordion file:

path-to-your-file/customnamespace-accordion.js

  1. Create a requirejs-config.js in your theme or module with the following content:
var config = {
    map: {
        "*": {
            "customnamespace.accordion" : "path-to-your-file/customnamespace-accordion"
        }
    }
};

  1. Now you can call your custom accordion with data-mage-init in your template. An example with default jQuery UI accordion attributes:
<nav data-mage-init='{"customnamespace.accordion": {"active": false, "collapsible": true, "heightStyle": "content", "icons": false}}'

@KrystynaKabannyk
Copy link

KrystynaKabannyk commented Dec 5, 2016

Hello @shabith, thank you for reporting this issue, however this is not the one widget name that conflicts with jQuery UI. To fix the described issue we need to change the entire architecture of Javascript widgets, and unfortunately we don't have plans to change it in nearest future. So, please follow the suggestions, given to you above to fix your issue, and I have to close this bug report.

magento-engcom-team pushed a commit that referenced this issue Jun 13, 2019
Implemented Stories:
- MAGETWO-55809: Eliminate @escapeNotVerified in Module Backend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants