简体   繁体   English

如何在Mootools上使用FX.Accordion

[英]How to FX.Accordion on mootools

I am creating a checkout page design that has an accordion. 我正在创建一个具有手风琴的结帐页面设计。 My employer only allows mootools as their js framework and doesn't want jquery on their application. 我的雇主只允许将mootools作为其js框架,并且不希望在其应用程序上使用jquery。 I am using BehaviorUI for front-end framework as it is a replica of bootstrap but are built based on mootools. 我将BehaviorUI用于前端框架,因为它是bootstrap的副本,但基于mootools构建。 The only problem is I am having trouble on creating the next/continue button for the next accordion. 唯一的问题是我在为下一个手风琴创建下一个/继续按钮时遇到麻烦。

here is what I have tried so far but turns out no luck: 到目前为止,这是我尝试过的,但是没有运气:

<div class="panel-group checkout-accordion" id="accordion" data-behavior="Accordion" data-accordion-options="'headers': 'a.accordion-toggle', 'sections': '.panel-collapse'">        
        <div class="panel panel-default">
            <div class="panel-heading">
                <a class="accordion-toggle"><span class="badge pull-left custom-badge">1</span>
                   <h3 class="panel-title"> Checkout Method </h3>
                </a>
            </div>
            <div id="step1" class="panel-collapse">
                <div class="panel-body">
                    <h3>You're Logged in as Erica!</h3>
                    <a href="#" class="btn btn-primary btn-sm pull-right" data-trigger="reveal" data-reveal-target="!.panel-group .panel #step2">Continue <i class="glyphicon glyphicon-arrow-right"></i></a>
                </div>
            </div>
        </div>

        <div class="panel panel-default" id="test">
            <div class="panel-heading">                    
                <a class="accordion-toggle"><span class="badge pull-left custom-badge">2</span>
                    <h3 class="panel-title">Shipping Method</h3>
                </a>                    
            </div>
            <div id="step2" class="panel-collapse">
                <div class="panel-body">
                    <h3>Destination State And Zip Code</h3>
                    <div class="form-group">
                        <label for="state" class="control-label">State</label>
                        <select id="state" class="no-flat-select form-control">
                            <option value="0" selected="selected">Select State</option>
                            <option value="1">Florida</option>
                            <option value="2">Arkansas</option>
                            <option value="3">Alaska</option>
                        </select>
                    </div>

                    <div class="form-group">
                        <label for="zip" class="control-label">Zip Code</label>
                        <input type="text" class="form-control" id="zip" placeholder="Zip Code">
                    </div>
                    <a href="#" class="btn btn-primary btn-sm pull-right">Continue <i class="glyphicon glyphicon-arrow-right"></i></a>
                </div>
            </div>
        </div>
</div>

As further explanation of what my goal is. 作为我的目标的进一步解释。 Here is an image that might help - link to image 这是一张可能有帮助的图片- 链接到该图片

It might be helpful to just go look at what Behavior.Accordion.js is doing ( source here on github ) 仅查看Behavior.Accordion.js在做什么(可能来自github上的内容 )可能会有所帮助。

All it does is create an instance of Fx.Accordion for you. 它所做的Fx.Accordion为您创建一个Fx.Accordion实例。 Your use of the reveal delegator is sort of out of scope of the accordion in that it, independently, knows how to show things, but it doesn't invoke any of Fx.Accordion 's methods (which wouldn't hide the first section). 您对reveal委托人的使用超出了手风琴的范围,因为它独立地知道如何显示事物,但是它不会调用Fx.Accordion的任何方法(不会隐藏第一部分) )。

No problem though. 没问题。 Just write a new delegator! 只需编写一个新的委托人!

http://jsfiddle.net/4y5sLt5d/ http://jsfiddle.net/4y5sLt5d/

Delegator.register('click', {
  'showAccordionSection': {
    requireAs: {
      // gotta tell it which section you want to show
      target: String
    },
    defaults: {
      // how to find the accordion instance
      // by convention, all selectors are relative to the element with
      // the trigger. this default assumes the clicked element is inside
      // the accordion.
      accordionSelector: '![data-behavior*=Accordion]'
    },
    handler: function(event, element, api){
      // find the target section to show
      var target = api.getElement('target');
      // we gotta find the accordion instance, so we look for
      var accordionElement = api.getElement('accordionSelector');
      // get the accordion instance from the element, created by Behavior
      var accordionInstance = accordionElement.getBehaviorResult('Accordion');
      // no accordion found? fail quietly
      if (!accordionInstance) api.fail('Could not retrieve Fx.Accordion instance from element', accordionElement);
      // not a section of the accordion? fail quietly
      if (accordionInstance.elements.indexOf(target) < 0) api.fail('Target element is not an accordion section', target);
      // show it!
      accordionInstance.display(target);
    }
  }
});

Just drop that anywhere into your site's javascript (after Delegator of course) and you're good to go. 只要将其放到您网站的javascript中(当然是在Delegator之后),就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM