PageSourceSearch

https://www.bdentalspa.com/wp-content/themes/doctorgenius-framework/js/awda-accessibility.js

js bdentalspa.com collected 2026-09-29 18:52:15 UTC 8,572 bytes, 222 lines download raw bytes

1var awdaDebug = false;
2var textColorCookieName = "DGAccessibilityTextColor";
3var textSizeCookieName = "DGAccessibilityTextSize";
4
5jQuery(document).ready(function( $ ) {
6    //setCookie(textSizeCookieName, 100);
7
8    /* Text Color Controls */
9    $('.black-text-activator').click( { color: 'black'}, AccessibilityTextColorHandler );
10    $('.white-text-activator').click( { color: 'white'}, AccessibilityTextColorHandler );
11
12    /* Text Size Controls */
13    $('.font-increase-activator').click( { multiplierDelta: 10 }, ChangeAccessibilityTextSize );
14    $('.font-decrease-activator').click( { multiplierDelta: -10 }, ChangeAccessibilityTextSize );
15    $('.font-size-reset').click( {}, resetFontAccessibility );
16   
17    //Read and Apply Cookies
18    var accessibilityTextColorCookie = getCookie( textColorCookieName );
19    if ( accessibilityTextColorCookie ) {
20        if ( awdaDebug ) { console.log( "Accessibility Text Mode Loaded: " + accessibilityTextColorCookie + " text on contrast background." ); }
21        ApplyAccessibilityTextColor( accessibilityTextColorCookie ); 
22    }
23
24    var accessibilityTextSizeCookie = parseInt( getCookie( textSizeCookieName ) );
25    if ( accessibilityTextSizeCookie ) {
26        if ( awdaDebug ) { console.log( "Accessibility Text Mode Loaded: " + accessibilityTextSizeCookie + "% font size." ); }
27        ApplyAccessibilityTextSize();
28    }
29});
30
31
32function ChangeAccessibilityTextSize( e ) {
33    // Get text nodes
34    var textNodes = findTextNodes( 'body *' );
35    
36    //Cache previous text percent, used to calculate 'original' text size when changing
37    var previousTextPercent = parseInt( getCookie(textSizeCookieName) ? getCookie(textSizeCookieName) : '100' );
38    var previousTextSizeMultiplier = previousTextPercent * .01;
39
40    //Calculate new target text size multiplier based on button click
41    var textPercentDelta = parseInt( e.data.multiplierDelta );
42    var newTextPercent = previousTextPercent + textPercentDelta;
43    var newTextSizeMultiplier = newTextPercent * .01 ;
44
45    
46    /* console.log( "Button pressed. Before button, text percent was " + previousTextPercent + " so to find original text size we divide current text size by " + previousTextSizeMultiplier 
47        + ".  New text percent is " + newTextPercent + " so to find new text size we multiply original text size by " + newTextSizeMultiplier ); */ 
48    
49    
50    jQuery.each( textNodes, function() {
51        // Find the node's encapsulating element
52        var textElement = jQuery(this).parent();
53
54        //Calculate original node text size
55        var currentTextSize = parseFloat( textElement.css('font-size') );
56        var originalTextSize = currentTextSize / previousTextSizeMultiplier;
57        
58        //Calculate and apply new node text size
59        var newTextSize = originalTextSize * newTextSizeMultiplier;
60        textElement.css( 'font-size', newTextSize + "px" );
61
62        // If larger than 100%, also apply bold font weight
63        if ( newTextSizeMultiplier > 1 ) {
64            textElement.css('font-weight', 'bold');
65        } else {
66            textElement.css('font-weight', '');
67        }
68        
69    });
70
71    //Finally, preserve new text % as a cookie for future use
72    setCookie( textSizeCookieName, newTextPercent );
73    
74}
75
76function ApplyAccessibilityTextSize() {
77    var textSizePercent = parseInt( getCookie(textSizeCookieName) ? getCookie(textSizeCookieName) : '100' );
78    var textSizeMultiplier = textSizePercent * .01 ;
79    var textNodes = findTextNodes( 'body *' );
80    
81    if ( awdaDebug ) { console.log( 'Applying Text Size from cookie: ' + parseInt( textSizePercent ) + '%.' ); }
82
83    jQuery.each( textNodes, function( index ) {
84
85        // Find the node's encapsulating element
86        var textElement = jQuery(this).parent();
87        var currentTextSize = parseFloat( textElement.css('font-size') );
88        var newTextSize = parseFloat( currentTextSize * textSizeMultiplier );
89
90        if ( textSizeMultiplier > 1 ) {
91            textElement.css('font-weight', 'bold'); 
92        } else {
93            textElement.css('font-weight', '');
94        }
95        
96        textElement.css( 'font-size', newTextSize + 'px' );
97
98    });
99
100}
101
102
103function AccessibilityTextColorHandler( e ) {
104    var eventColor = e.data.color;
105
106    if ( getCookie(textColorCookieName) !== eventColor ) {
107        ApplyAccessibilityTextColor( eventColor );
108        var accessibilityBackgroundColor = ( eventColor === 'white' ) ? 'black' : 'white';
109        if ( awdaDebug ) { console.log( 'Accessibility Text Color Mode Activated: ' + eventColor + ' text on ' + accessibilityBackgroundColor + ' background.' ); }
110    }
111    else {
112        if (awdaDebug) { console.log( "Accessibility Text Mode: " + eventColor + " already activated. Button click ignored." ); }
113    }
114    
115}
116
117
118function ApplyAccessibilityTextColor( AccessibilityTextColor ) {
119   
120    if ( ! setCookie( textColorCookieName, AccessibilityTextColor ) ) { 
121        console.log( "Error creating local cookie. AwDA Accessibility will not persist.  Please enable cookies for full accessibility." );
122    }
123
124    var accessibilityBackgroundColor = (AccessibilityTextColor === 'white') ? 'black' : 'white';
125
126    var textNodes = findTextNodes('body *');
127    textNodes.each(function () {
128
129        // Color the text of each node's parent (ie, each actual element) correctly, and save it for background coloring
130        var textColorElements = jQuery(this).parent();
131
132        textColorElements = textColorElements.add(jQuery('select')).add(jQuery('input')).add(jQuery('.sticky-footer .col .btn-floating i'));
133        textColorElements.css('color', AccessibilityTextColor);
134
135        //Add one level of parents to the backgrounds list
136        var backgroundElements = textColorElements.add(textColorElements.parent())
137            .add(textColorElements.parent().parent())
138            // Also add all our fw color classes
139            .add(jQuery(".bg-primary, .bg-secondary, .bg-tertiary, .btn-tertiary, .bg-mute"));
140        
141        //Color the backgrounds
142        backgroundElements.css('background-color', accessibilityBackgroundColor);
143    });
144
145    
146}
147
148
149function setCookie(cname, cvalue, exdays) {
150    //Handle cookie expiration
151    var d = new Date();
152    d.setTime(d.getTime() + (exdays*24*60*60*1000));
153    var expires = "expires="+ d.toUTCString();
154    
155    //Create the actual cookie with root path on the site
156    try {
157        document.cookie = encodeURIComponent(cname) + "=" + cvalue + ";" + expires + ";path=/";
158    } catch(e) {
159        if (awdaDebug) { console.log("Error setting local cookie."); }
160        return false; 
161    }
162    return true;
163}
164
165function getCookie(cname) {
166    //Read in the document cookies
167    var decodedCookie = decodeURIComponent(document.cookie);
168    var ca = decodedCookie.split(';');
169    
170    //Cookie formatting
171    var name = cname + "=";
172    
173    //Search the entire cookie string for the supplied cookie name
174    for ( var i = 0; i < ca.length; i++ ) {
175        var c = ca[i];
176        while ( c.charAt(0) === ' ' ) {
177            c = c.substring(1);
178        }
179        if ( c.indexOf(name) === 0 ) {
180            return c.substring(name.length, c.length);
181        }
182    }
183    return false;
184}
185
186function findTextNodes( startingSelector ) {
187    return jQuery( startingSelector ).not('iframe').contents().filter(function () {
188        return (this.nodeType == 3) && this.nodeValue.match(/\S/);
189    });
190}
191
192function resetFontAccessibility(){
193    if ( awdaDebug ) { console.log( 'Resetting Text Size and color to Original'); }
194    
195    //Finally, reset cookies
196    setCookie(textSizeCookieName, '');
197    setCookie(textColorCookieName, '');
198    
199    var textNodes = findTextNodes( 'body *' );
200    jQuery.each( textNodes, function() {
201        
202        // Find the node's encapsulating element
203        var textElement = jQuery(this).parent();
204        textElement.css( 'font-size', '' );
205        textElement.css( 'font-weight', '' );
206
207        var textColorElements = textElement.add(jQuery('select')).add(jQuery('input')).add(jQuery('.sticky-footer .col .btn-floating i'));
208        textColorElements.css('color', '');
209
210        //Add one level of parents to the backgrounds list
211        var backgroundElements = textColorElements.add(textColorElements.parent())
212            .add(textColorElements.parent().parent())
213            // Also add all our fw color classes
214            .add(jQuery(".bg-primary, .bg-secondary, .bg-tertiary, .btn-tertiary, .bg-mute"));
215
216
217        //Color the backgrounds
218        backgroundElements.css('background-color', '');        
219        
220    });
221
222}

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.