1/** 2 * @file 3 * CKEditor Accordion functionality. 4 */ 5 6(function ($, Drupal, drupalSettings) { 7 'use strict'; 8 Drupal.behaviors.ckeditorAccordion = { 9 attach: function (context, settings) { 10 11 // Create accordion functionality if the required elements exist is available. 12 var $ckeditorAccordion = $('.ckeditor-accordion'); 13 if ($ckeditorAccordion.length > 0) { 14 // Create simple accordion mechanism for each tab. 15 $ckeditorAccordion.each(function () { 16 var $accordion = $(this); 17 if ($accordion.hasClass('styled')) { 18 return; 19 } 20 21 // The first one is the correct one. 22 if (!drupalSettings.ckeditorAccordion.accordionStyle.collapseAll) { 23 $accordion.children('dt:first').addClass('active'); 24 $accordion.children('dd:first').addClass('active'); 25 $accordion.children('dd:first').css('display', 'block'); 26 } 27 28 // Turn the accordion tabs to links so that the content is accessible & can be traversed using keyboard. 29 $accordion.children('dt').each(function () { 30 var $tab = $(this); 31 var tabText = $tab.text().trim(); 32 var toggleClass = $tab.hasClass('active') ? ' active' : ''; 33 $tab.html('<a class="ckeditor-accordion-toggler" href="#"><span class="ckeditor-accordion-toggle' + toggleClass + '"></span>' + tabText + '</a>'); 34 }); 35 36 // Wrap the accordion in a div element so that quick edit function shows the source correctly. 37 $accordion.addClass('styled').removeClass('ckeditor-accordion').wrap('<div class="ckeditor-accordion-container"></div>'); 38 39 // Trigger an ckeditorAccordionAttached event to let other frameworks know that the accordion has been attached. 40 $accordion.trigger('ckeditorAccordionAttached'); 41 }); 42 43 // Add click event to body once because quick edits & ajax calls might reset the HTML. 44 $('body').once('ckeditorAccordionToggleEvent').on('click', '.ckeditor-accordion-toggler', function (e) { 45 var $t = $(this).parent(); 46 var $parent = $t.parent(); 47 48 // Clicking on open element, close it. 49 if ($t.hasClass('active')) { 50 $t.removeClass('active'); 51 $t.next().slideUp(); 52 } 53 else { 54 if(!drupalSettings.ckeditorAccordion.accordionStyle.keepRowsOpen) { 55 // Remove active classes. 56 $parent.children('dt.active').removeClass('active').children('a').removeClass('active'); 57 $parent.children('dd.active').slideUp(function () { 58 $(this).removeClass('active'); 59 }); 60 } 61 62 // Show the selected tab. 63 $t.addClass('active'); 64 $t.next().slideDown(300).addClass('active'); 65 } 66 67 // Don't add hash to url. 68 e.preventDefault(); 69 }); 70 } 71 } 72 }; 73})(jQuery, Drupal, drupalSettings);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.