accessibility-8.x-1.x-dev/modules/accessibility_content/js/accessibility_content.js
modules/accessibility_content/js/accessibility_content.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | ( function ($) { Drupal.behaviors.accessibilityContent = { messages : {}, formErrors : {}, attach: function (context) { if (Drupal.settings.accessibility_content.options.form) { this .checkForm(); } else { if (Drupal.settings.accessibility_content.show_toggle) { this .addToggle(); } else { if (Drupal.settings.accessibility_content.show_default) { this .checkContent(); } } } }, checkForm : function () { var that = this ; $( '.accessible-content-check-form' ).each( function () { that.checkFormElement($( this )); $( this ).change( function () { that.checkFormElement($( this )); }); }); }, checkFormElement : function ($element) { var that = this ; var current = 0; $element.data( 'accessible-content-errors' , 0); var severity = $element.data( 'accessible-content-severity' ).split( ',' ); Drupal.accessibility.checkElement($($element.val()), function (event) { if (severity.indexOf(event.severity) > -1) { current++; $element.data( 'accessible-content-errors' , current); } that.checkFormStatus($element.parents( 'form' )); }, function () { }, 'content' ); }, checkFormStatus : function ($form) { var total = 0; $form.find( '.accessible-content-check-form' ).each( function () { total += $( this ).data( 'accessible-content-errors' ); if ($( this ).data( 'accessible-content-errors' )) { $( this ).addClass( 'error' ); } else { $( this ).removeClass( 'error' ); } }); if (total) { $form.find( '[type=submit]' ) .attr( 'disabled' , 'disabled' ) .addClass( 'disabled' ); } else { $form.find( '[type=submit]' ) .removeAttr( 'disabled' ) .removeClass( 'disabled' ); } }, addToggle : function () { var that = this ; if ($( '#accessibility-content-toggle' ).length) { return ; } var $toggle = $( '<div>' ).attr( 'id' , 'accessibility-content-toggle' ) .addClass( 'accessibility-content-toggle' ); var $link = $( '<a>' ).html(Drupal.settings.accessibility_content.toggle.off_message) .attr( 'role' , 'button' ) .attr( 'href' , '#' ); $toggle.append($link); $( 'body' ).append($toggle); $( '#accessibility-content-toggle a' ).on( 'click' , function () { if ($( 'body' ).hasClass( 'accessibility-checked' )) { $( this ).html(Drupal.settings.accessibility_content.toggle.off_message); $( 'body' ).removeClass( 'accessibility-checked' ); Drupal.accessibility.cleanUpHighlight(); Drupal.accessibility.errorConsole.hide(); } else { $( this ).html(Drupal.settings.accessibility_content.toggle.on_message); that.checkContent(); } return false ; }); if (Drupal.settings.accessibility_content.show_default) { $( '#accessibility-content-toggle a' ).trigger( 'click' ); } $( 'body' ).bind( 'accessibility-console-show' , function () { var height = $( '#accessibility-console' ).outerHeight(); $( '#accessibility-content-toggle' ).css( 'bottom' , height + 'px' ); }); $( 'body' ).bind( 'accessibility-console-hide' , function () { $( '#accessibility-content-toggle' ).css( 'bottom' , '0px' ); }); }, checkContent : function () { var that = this ; if ($( 'body' ).hasClass( 'accessibility-checked' )) { return ; } $( 'body' ).addClass( 'accessibility-checked' ); Drupal.accessibility.checkElement($( '.ac-check-field' ), false , function () { }, 'content' ); } }; })(jQuery); |