PageSourceSearch

https://www.brindesbrasil.com.br/wp-content/plugins/BrindesBrasil_…tras-quantidades-abertura.js?ver=1788887229

js brindesbrasil.com.br collected 2026-10-05 23:16:42 UTC 12,629 bytes, 194 lines download raw bytes

1(function(){
2    'use strict';
3
4    var cfg=window.BrindesBrasilOutrasQuantidadesConfig||{};
5    var valid=['inline','expand_up','modal','bottom_sheet','drawer','popover'];
6    var active=null;
7    var raf=0;
8
9    function controlFor(element){
10        if(!element){return null;}
11        var direct=element.closest&&element.closest('.bb-quantidade-personalizada');
12        if(direct){return direct;}
13        var panel=element.closest&&element.closest('.bb-quantidade-personalizada-painel');
14        var owner=panel&&panel.getAttribute('data-bb-opening-owner');
15        return owner?document.querySelector('.bb-quantidade-personalizada[data-bb-opening-id="'+cssEscape(owner)+'"]'):null;
16    }
17
18    function cssEscape(value){
19        return window.CSS&&window.CSS.escape?window.CSS.escape(value):String(value).replace(/[^a-zA-Z0-9_-]/g,'\\$&');
20    }
21
22    function panelFor(control){
23        if(!control){return null;}
24        var id=control.getAttribute('data-bb-opening-id');
25        if(active&&active.control===control){return active.panel;}
26        return control.querySelector('.bb-quantidade-personalizada-painel')||
27            (id?document.querySelector('.bb-quantidade-personalizada-painel[data-bb-opening-owner="'+cssEscape(id)+'"]'):null);
28    }
29
30    function modeForViewport(){
31        var mobile=window.matchMedia('(max-width:'+(parseInt(cfg.breakpoint,10)||849)+'px)').matches;
32        var mode=mobile?String(cfg.mobile||'inherit'):String(cfg.desktop||'inline');
33        if(mode==='inherit'){mode=String(cfg.desktop||'inline');}
34        return valid.indexOf(mode)!==-1?mode:'inline';
35    }
36
37    function updateState(control,open){
38        var button=control&&control.querySelector('.bb-quantidade-personalizada-toggle');
39        if(!control||!button){return;}
40        control.classList.toggle('bb-quantidade-personalizada-aberta',!!open);
41        button.setAttribute('aria-expanded',open?'true':'false');
42        var icon=button.querySelector('.bb-quantidade-personalizada-icone');
43        if(icon){icon.textContent=open?(button.getAttribute('data-bb-icon-open')||'−'):(button.getAttribute('data-bb-icon-closed')||'+');}
44    }
45
46    function copyVisualTokens(root,panel){
47        var input=panel.querySelector('.bb-quantidade-personalizada-input');
48        var confirm=panel.querySelector('.bb-quantidade-personalizada-confirmar');
49        var ps=getComputedStyle(panel);
50        root.style.setProperty('--bb-oq-panel-bg',ps.backgroundColor==='rgba(0, 0, 0, 0)'?'#fff':ps.backgroundColor);
51        root.style.setProperty('--bb-oq-panel-border',ps.borderTopColor||'#d9e0e8');
52        root.style.setProperty('--bb-oq-panel-text',ps.color||'#596579');
53        if(input){var ins=getComputedStyle(input);root.style.setProperty('--bb-oq-input-bg',ins.backgroundColor);root.style.setProperty('--bb-oq-input-border',ins.borderTopColor);root.style.setProperty('--bb-oq-input-text',ins.color);root.style.setProperty('--bb-oq-input-size',ins.fontSize);}
54        if(confirm){var cs=getComputedStyle(confirm);root.style.setProperty('--bb-oq-confirm-bg',cs.backgroundColor);root.style.setProperty('--bb-oq-confirm-border',cs.borderTopColor);root.style.setProperty('--bb-oq-confirm-text',cs.color);root.style.setProperty('--bb-oq-confirm-size',cs.fontSize);root.style.setProperty('--bb-oq-confirm-height',cs.minHeight);root.style.setProperty('--bb-oq-confirm-radius',cs.borderRadius);}
55        ['--bb-card-other-input-height','--bb-card-other-input-line-height','--bb-card-other-label-size','--bb-card-other-technique-size','--bb-card-other-feedback-size'].forEach(function(token){var current=ps.getPropertyValue(token).trim();if(current){root.style.setProperty(token,current);}});
56    }
57
58    function focusables(shell){
59        return Array.prototype.filter.call(shell.querySelectorAll('button,input,select,textarea,a[href],[tabindex]:not([tabindex="-1"])'),function(el){return !el.disabled&&!el.hidden&&el.offsetParent!==null;});
60    }
61
62    function fitInputValue(input){
63        if(!input||!input.matches('.bb-quantidade-personalizada-input')){return;}
64        input.style.removeProperty('font-size');
65        var desired=parseFloat(getComputedStyle(input).fontSize)||16;
66        var length=Math.max(1,String(input.value||'').replace(/[^0-9]/g,'').length);
67        var available=Math.max(40,input.clientWidth-30);
68        input.style.setProperty('font-size',Math.max(16,Math.min(desired,available/(length*.62)))+'px','important');
69    }
70
71    function onKeydown(event){
72        if(!active){return;}
73        if(event.key==='Escape'){event.preventDefault();closeActive(true);return;}
74        if(event.key!=='Tab'||['modal','bottom_sheet','drawer'].indexOf(active.mode)===-1){return;}
75        var items=focusables(active.shell);if(!items.length){event.preventDefault();return;}
76        var first=items[0],last=items[items.length-1];
77        if(event.shiftKey&&document.activeElement===first){event.preventDefault();last.focus();}
78        else if(!event.shiftKey&&document.activeElement===last){event.preventDefault();first.focus();}
79    }
80
81    function restorePanel(record){
82        if(!record){return;}
83        record.panel.hidden=true;
84        record.panel.removeAttribute('data-bb-opening-owner');
85        if(record.placeholder&&record.placeholder.parentNode){record.placeholder.parentNode.insertBefore(record.panel,record.placeholder);
85record.placeholder.remove();}
86        else if(record.control&&record.control.isConnected){record.control.appendChild(record.panel);}
87    }
88
89    function closeActive(restoreFocus){
90        if(!active){return;}
91        var record=active;active=null;
92        restorePanel(record);
93        updateState(record.control,false);
94        record.root.remove();
95        document.body.classList.remove('bb-oq-scroll-locked');
96        document.removeEventListener('keydown',onKeydown,true);
97        if(restoreFocus&&record.button&&record.button.isConnected){record.button.focus();}
98    }
99
100    function positionAnchored(record){
101        if(!record||!record.button.isConnected){closeActive(false);return false;}
102        var rect=record.button.getBoundingClientRect();
103        var gap=10,viewportW=document.documentElement.clientWidth,viewportH=window.innerHeight;
104        var width=Math.min(parseInt(cfg.width,10)||420,viewportW-24);
105        record.shell.style.width=width+'px';
106        record.shell.style.maxHeight=Math.min(viewportH-24,viewportH*((parseInt(cfg.maxHeight,10)||80)/100))+'px';
107        var height=Math.min(record.shell.scrollHeight,parseFloat(record.shell.style.maxHeight));
108        var above=rect.top-gap-height;
109        var below=rect.bottom+gap;
110        var useAbove=above>=12;
111        if(!useAbove&&below+height>viewportH-12&&record.mode==='expand_up'){return false;}
112        var top=useAbove?above:Math.min(below,viewportH-height-12);
113        var left=Math.max(12,Math.min(rect.left+(rect.width-width)/2,viewportW-width-12));
114        record.shell.style.top=Math.max(12,top)+'px';record.shell.style.left=left+'px';
115        record.root.classList.toggle('bb-oq-anchor-above',useAbove);record.root.classList.toggle('bb-oq-anchor-below',!useAbove);
116        record.root.style.setProperty('--bb-oq-arrow-left',Math.max(16,Math.min(width-28,rect.left+rect.width/2-left-6))+'px');
117        return true;
118    }
119
120    function schedulePosition(){
121        if(!active||['expand_up','popover'].indexOf(active.mode)===-1){return;}
122        cancelAnimationFrame(raf);raf=requestAnimationFrame(function(){positionAnchored(active);});
123    }
124
125    function openPortal(control,mode){
126        closeActive(false);
127        var panel=panelFor(control),button=control.querySelector('.bb-quantidade-personalizada-toggle');
128        if(!panel||!button||!control.isConnected){return false;}
129        var owner=control.getAttribute('data-bb-opening-id');
130        if(!owner){owner='bb-outras-runtime-'+Date.now()+'-'+Math.floor(Math.random()*10000);control.setAttribute('data-bb-opening-id',owner);}
131        var placeholder=document.createComment('bb-outras-quantidades-origem');
132        panel.parentNode.insertBefore(placeholder,panel);
133        var root=document.createElement('div');root.className='bb-oq-portal bb-oq-mode-'+mode+' bb-oq-side-'+(cfg.drawerSide==='left'?'left':'right');
134        root.style.setProperty('--bb-oq-width',(parseInt(cfg.width,10)||420)+'px');
135        root.style.setProperty('--bb-oq-max-height',(parseInt(cfg.maxHeight,10)||80)+'vh');
136        root.style.setProperty('--bb-oq-overlay',String(cfg.overlayColor||'#263548'));
137        root.style.setProperty('--bb-oq-overlay-opacity',String(typeof cfg.overlayOpacity==='number'?cfg.overlayOpacity:.55));
138        root.style.setProperty('--bb-oq-duration',(parseInt(cfg.animationMs,10)||0)+'ms');
139        copyVisualTokens(root,panel);
140        var overlay=document.createElement('div');overlay.className='bb-oq-overlay';overlay.setAttribute('aria-hidden','true');
141        var shell=document.createElement('div');shell.className='bb-oq-shell';shell.tabIndex=-1;
142        var modal=['modal','bottom_sheet','drawer'].indexOf(mode)!==-1;
143        shell.setAttribute('role',modal?'dialog':'region');
144        if(modal){shell.setAttribute('aria-modal','true');shell.setAttribute('aria-label','Outras quantidades');}
145        var close=document.createElement('button');close.type='button';close.className='bb-oq-close';close.setAttribute('aria-label','Fechar outras quantidades');close.textContent='×';
146        close.addEventListener('click',function(){closeActive(true);});
147        if(cfg.closeOnOverlay!==false){overlay.addEventListener('click',function(){closeActive(true);});}
148        if(['modal','bottom_sheet','drawer'].indexOf(mode)!==-1){root.appendChild(overlay);}
149        shell.appendChild(close);panel.setAttribute('data-bb-opening-owner',owner);panel.hidden=false;shell.appendChild(panel);root.appendChild(shell);document.body.appendChild(root);
150        active={control:control,panel:panel,button:button,placeholder:placeholder,root:root,shell:shell,mode:mode};
151        if(['modal','bottom_sheet','drawer'].indexOf(mode)!==-1){document.body.classList.add('bb-oq-scroll-locked');}
152        document.addEventListener('keydown',onKeydown,true);updateState(control,true);
153        if(['expand_up','popover'].indexOf(mode)!==-1&&!positionAnchored(active)){
154            closeActive(false);return openPortal(control,'modal');
155        }
156        fitInputValue(panel.querySelector('.bb-quantidade-personalizada-input'));
157        window.setTimeout(function(){
158            if(!active||active.control!==control){return;}
159            var input=panel.querySelector('.bb-quantidade-personalizada-input');
160            if(input&&!window.matchMedia('(pointer:coarse)').matches){input.focus();}else{shell.focus();}
161        },20);
162        return true;
163    }
164
165    function setOpen(control,open,options){
166        control=controlFor(control)||control;
167        if(!control){return false;}
168        var panel=panelFor(control),button=control.querySelector('.bb-quantidade-personalizada-toggle');
169        if(!panel||!button){return false;}
170        if(!open){if(active&&active.control===control){closeActive(options&&options.restoreFocus);}else{panel.hidden=true;updateState(control,false);}return true;}
171        var mode=modeForViewport();
172        if(mode==='inline'){
173            if(active&&active.control!==control){closeActive(false);}
174            panel.hidden=false;updateState(control,true);
175            fitInputValue(panel.querySelector('.bb-quantidade-personalizada-input'));
176            if(!(options&&options.skipFocus)&&!window.matchMedia('(pointer:coarse)').matches){var inlineInput=panel.querySelector('.bb-quantidade-personalizada-input');if(inlineInput){inlineInput.focus();}}
177            return true;
178        }
179        return openPortal(control,mode);
180    }
181
182    function toggle(button){
183        var control=controlFor(button),panel=panelFor(control);
184        if(!control||!panel){return false;}
185        return setOpen(control,panel.hidden||!(control.classList.contains('bb-quantidade-personalizada-aberta')),{restoreFocus:true});
186    }
187
188    window.addEventListener('resize',schedulePosition,{passive:true});
189    window.addEventListener('orientationchange',schedulePosition,{passive:true});
190    window.addEventListener('scroll',schedulePosition,{passive:true,capture:true});
191    document.addEventListener('input',function(event){fitInputValue(event.target);},true);
192    window.addEventListener('resize',function(){document.querySelectorAll('.bb-quantidade-personalizada-input').forEach(fitInputValue);},{passive:true});
193    window.BrindesBrasilOutrasQuantidades={toggle:toggle,setOpen:setOpen,closeActive:closeActive,getControl:controlFor,getPanel:panelFor};
194}());

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.