1/** 2 * Flexy Breadcrumb Front-end Script 3 * 4 * Automatically detects dynamic client-side RTL translation (such as GTranslate, 5 * Google Translate, Weglot, or TranslatePress) and toggles RTL classes and attributes. 6 * 7 * @package Flexy_Breadcrumb 8 * @since 1.0.0 9 * @since 1.3.1 Added automatic client-side RTL detection for translation plugins. 10 */ 11(function() { 12 'use strict'; 13 14 var rtlLanguages = ['ar', 'he', 'iw', 'fa', 'ur', 'ps', 'sd', 'ug', 'yi']; 15 16 function isRtlLanguage(lang) { 17 if (!lang) { 18 return false; 19 } 20 lang = String(lang).toLowerCase().split('-')[0].trim(); 21 return rtlLanguages.indexOf(lang) !== -1; 22 } 23 24 function checkRTL() { 25 var isRtl = false; 26 var html = document.documentElement; 27 28 // 1. Google Translate class on <html> 29 if (html && (html.classList.contains('translated-rtl') || html.getAttribute('dir') === 'rtl')) { 30 isRtl = true; 31 } 32 33 // 2. Standard WordPress body class or dir attribute 34 if (!isRtl && document.body && (document.body.classList.contains('rtl') || document.body.getAttribute('dir') === 'rtl')) { 35 isRtl = true; 36 } 37 38 // 3. GTranslate / Google Translate cookie (e.g. googtrans=/en/ar or googtrans=/auto/ar) 39 if (!isRtl) { 40 var match = document.cookie.match(/(?:^|;\s*)googtrans=([^;]+)/); 41 if (match && match[1]) { 42 var lang = match[1].split('/').pop(); 43 if (isRtlLanguage(lang)) { 44 isRtl = true; 45 } 46 } 47 } 48 49 // 4. GTranslate active language in the DOM 50 if (!isRtl) { 51 var gtActive = document.querySelector('.gt-current-lang[data-gt-lang], .gt-current-wrapper[data-gt-lang]'); 52 if (gtActive) { 53 var gtLang = gtActive.getAttribute('data-gt-lang'); 54 if (isRtlLanguage(gtLang)) { 55 isRtl = true; 56 } 57 } 58 } 59 60 // Apply or remove fbc-rtl and dir="rtl" on all breadcrumb navigation elements 61 var breadcrumbs = document.querySelectorAll('nav.fbc-page, .fbc-page'); 62 for (var i = 0; i < breadcrumbs.length; i++) { 63 var el = breadcrumbs[i]; 64 if (isRtl) { 65 if (!el.classList.contains('fbc-rtl')) { 66 el.classList.add('fbc-rtl'); 67 } 68 if (el.getAttribute('dir') !== 'rtl') { 69 el.setAttribute('dir', 'rtl'); 70 } 71 } else { 72 // If it was dynamically added by this script, remove it 73 if (!el.hasAttribute('data-server-rtl')) { 74 el.classList.remove('fbc-rtl'); 75 if (el.getAttribute('dir') === 'rtl') { 76 el.removeAttribute('dir'); 77 } 78 } 79 } 80 } 81 } 82 83 // Run on initial load 84 if (document.readyState === 'loading') { 85 document.addEventListener('DOMContentLoaded', checkRTL); 86 } else { 87 checkRTL(); 88 } 89 90 // Observe changes to <html> (when Google Translate adds or removes 'translated-rtl') 91 if (window.MutationObserver) { 92 var observer = new MutationObserver(function() { 93 checkRTL(); 94 }); 95 observer.observe(document.documentElement, { 96 attributes: true, 97 attributeFilter: ['class', 'dir', 'lang'] 98 }); 99 if (document.body) { 100 observer.observe(document.body, { 101 attributes: true, 102 attributeFilter: ['class', 'dir'] 103 }); 104 } 105 } 106 107 // Listen for GTranslate language clicks or select changes 108 document.addEventListener('click', function(e) { 109 var target = e.target && e.target.closest && e.target.closest('[data-gt-lang], .glink, .goog-te-combo'); 110 if (target) { 111 setTimeout(checkRTL, 200); 112 setTimeout(checkRTL, 600); 113 setTimeout(checkRTL, 1200); 114 } 115 });
116 117 document.addEventListener('change', function(e) { 118 if (e.target && e.target.classList && e.target.classList.contains('goog-te-combo')) { 119 setTimeout(checkRTL, 200); 120 setTimeout(checkRTL, 600); 121 } 122 }); 123})();
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.