ui/twig/create/modals/full.html.twig line 1

Open in your IDE?
  1. {% set htmlId = _args.htmlId %}
  2. {% set ajax = _args.ajax %}
  3. {% set version = _args.version|default(null) %}
  4. <div class="v3_2">
  5.     <div id="{{ htmlId }}" class="modal modal--full" data-cs-modal-start="{{ ajax }}" tabindex="-1">
  6.         {% if version is not empty %}
  7.             <div class="modal__version"><span class="badge badge--beta">{{ version }}</span></div>
  8.         {% endif %}
  9.         <button class="modal__close" data-dismiss="modal">
  10.             <span></span>
  11.         </button>
  12.         <div class="modal__content"></div>
  13.     </div>
  14. </div>
  15. <script>
  16.     $(function () {
  17.         $('#{{ htmlId }}')
  18.             // load up the start page when showing
  19.             .on('show.bs.modal', function (e) {
  20.                 var $modal = $(e.target),
  21.                     url = $modal.attr('data-cs-modal-start');
  22.                 $modal.trigger('navigate.cs.modal', {
  23.                     url: url
  24.                 });
  25.             })
  26.             // once hidden, wipe the html content
  27.             .on('hidden.bs.modal', function (e) {
  28.                 var $modal = $(e.target);
  29.                 $modal.find('.modal__content').html('');
  30.             })
  31.             // special event handling for "navigating" within the modal
  32.             .on('navigate.cs.modal', function (e, opts) {
  33.                 var $elem = $(e.target),// element the even is being triggered on, can be anything
  34.                     $modal = $elem.closest('.modal'),// get the modal wrapper/main element
  35.                     $ajax = $.ajax(opts.url, {
  36.                         method: 'GET',
  37.                         xhrFields: {
  38.                             withCredentials: true
  39.                         }
  40.                     });// ajax call to get the url
  41.                 // fade out the existing content
  42.                 $modal.find('.modal__content').fadeOut(100);
  43.                 // handle success
  44.                 $ajax.done(function (resp, status, xhr) {
  45.                     // wait for animation then set the html on the element
  46.                     $modal.find('.modal__content').promise().done(function () {
  47.                         $(this).html(resp);
  48.                     });
  49.                 });
  50.                 // TODO: handle errors
  51.                 $ajax.fail(function () {
  52.                     //alert('ERROR!');
  53.                 });
  54.                 // fade the content back in when done
  55.                 $ajax.always(function () {
  56.                     $modal.find('.modal__content').promise().done(function () {
  57.                         $(this).fadeIn(100);
  58.                     });
  59.                 });
  60.             })
  61.             // handle special event of form ajax submission
  62.             .on('submission.cs.modal', function (e, opts) {
  63.                 var $elem = $(e.target),// the element that triggered the form load
  64.                     $modal = $elem.closest('.modal'),// the modal wrapper
  65.                     $ajax = $.ajax(opts.url, {
  66.                         method: opts.method,
  67.                         data: opts.data,
  68.                         xhrFields: {
  69.                             withCredentials: true
  70.                         }
  71.                     });// ajax call for the form submission
  72.                 // fade out the content
  73.                 $modal.find('.modal__content').fadeOut(100);
  74.                 // handle success
  75.                 $ajax.done(function (resp, status, xhr) {
  76.                     // wait for animation then set the html on the element
  77.                     $modal.find('.modal__content').promise().done(function () {
  78.                         $(this).html(resp);
  79.                     });
  80.                 });
  81.                 // TODO: handle errors
  82.                 $ajax.fail(function () {
  83.                     //alert('ERROR!');
  84.                 });
  85.                 // fade the content back in when done
  86.                 $ajax.always(function () {
  87.                     $modal.find('.modal__content').promise().done(function () {
  88.                         $(this).fadeIn(100);
  89.                     });
  90.                 });
  91.             })
  92.         ;
  93.         // register click handlers in the modal to capture and process navigating to different "screens" in the modal
  94.         $('#{{ htmlId }} .modal__content')
  95.             // hide the content, it will fade in when loaded
  96.             .hide()
  97.             // handle links
  98.             .on('click', 'a', function (e) {
  99.                 var $link = $(e.currentTarget),// the link that was clicked
  100.                     href = $link.attr('href'),// the href attribute of the link, if any
  101.                     target = $link.attr('target');// the target value
  102.                 // if we have an href attribute and the target is self; we are treating self as if the modal is an iframe
  103.                 if (href && ( ! target || target === '_self')) {
  104.                     // need to prevent the default behavior
  105.                     e.preventDefault();
  106.                     // if the href is legit follow it via modal navigation (ajax load and inject response into modal content)
  107.                     if (href && href !== '#') {
  108.                         // due to using this in the page editor stuff, we also need to stop the click propagation
  109.                         e.stopPropagation();
  110.                         // trigger the navigation
  111.                         $link.trigger('navigate.cs.modal', {
  112.                             url: href
  113.                         });
  114.                         // to be safe, also return false
  115.                         return false;
  116.                     }
  117.                 }
  118.             })
  119.             // handle for submissions
  120.             .on('submit', 'form', function (e) {
  121.                 var $form = $(e.currentTarget),// the form being submitted
  122.                     $button = (e.originalEvent) ? $(e.originalEvent.submitter) : $(''),// input button, if any, that was used to submit the form
  123.                     target = $form.attr('target'),// target value of the form
  124.                     data = $form.serializeArray();
  125.                 // add button if there is a name
  126.                 if ($button.attr('name')) {
  127.                     data.push({
  128.                         name: $button.attr('name'),
  129.                         value: ($button.attr('value')) ? $button.attr('value') : ''
  130.                     });
  131.                 }
  132.                 // make sure that the target is one we are concerned with
  133.                 if ( ! target || target === '_self') {
  134.                     // we want to handle the submission, prevent the default
  135.                     e.preventDefault();
  136.                     // due to using this in the page editor stuff, we also need to stop the click propagation
  137.                     e.stopPropagation();
  138.                     // use the ajax submit
  139.                     $form.trigger('submission.cs.modal', {
  140.                         url: $form.attr('action'),
  141.                         method: $form.attr('method'),
  142.                         data: data
  143.                     });
  144.                     // to be safe, also return false
  145.                     return false;
  146.                 }
  147.             })
  148.         ;
  149.     });
  150. </script>