PageSourceSearch

https://sysadvance.com/media/js/utils.js

js sysadvance.com collected 2026-10-02 21:42:54 UTC 17,078 bytes, 391 lines download raw bytes

1/* alterValue(this, 'nome'); */
2
3/* funcao spin para o loading */
4(function(t,e){if(typeof exports=="object")module.exports=e();else if(typeof define=="function"&&define.amd)define(e);else t.Spinner=e()})(this,function(){"use strict";var t=["webkit","Moz","ms","O"],e={},i;function o(t,e){var i=document.createElement(t||"div"),o;for(o in e)i[o]=e[o];return i}function n(t){for(var e=1,i=arguments.length;e<i;e++)t.appendChild(arguments[e]);return t}var r=function(){var t=o("style",{type:"text/css"});n(document.getElementsByTagName("head")[0],t);return t.sheet||t.styleSheet}();function s(t,o,n,s){var a=["opacity",o,~~(t*100),n,s].join("-"),f=.01+n/s*100,l=Math.max(1-(1-t)/o*(100-f),t),d=i.substring(0,i.indexOf("Animation")).toLowerCase(),u=d&&"-"+d+"-"||"";if(!e[a]){r.insertRule("@"+u+"keyframes "+a+"{"+"0%{opacity:"+l+"}"+f+"%{opacity:"+t+"}"+(f+.01)+"%{opacity:1}"+(f+o)%100+"%{opacity:"+t+"}"+"100%{opacity:"+l+"}"+"}",r.cssRules.length);e[a]=1}return a}function a(e,i){var o=e.style,n,r;if(o[i]!==undefined)return i;i=i.charAt(0).toUpperCase()+i.slice(1);for(r=0;r<t.length;r++){n=t[r]+i;if(o[n]!==undefined)return n}}function f(t,e){for(var i in e)t.style[a(t,i)||i]=e[i];return t}function l(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var o in i)if(t[o]===undefined)t[o]=i[o]}return t}function d(t){var e={x:t.offsetLeft,y:t.offsetTop};while(t=t.offsetParent)e.x+=t.offsetLeft,e.y+=t.offsetTop;return e}var u={lines:12,length:7,width:5,radius:10,rotate:0,corners:1,color:"#000",direction:1,speed:1,trail:100,opacity:1/4,fps:20,zIndex:2e9,className:"spinner",top:"auto",left:"auto",position:"relative"};function p(t){if(typeof this=="undefined")return new p(t);this.opts=l(t||{},p.defaults,u)}p.defaults={};l(p.prototype,{spin:function(t){this.stop();var e=this,n=e.opts,r=e.el=f(o(0,{className:n.className}),{position:n.position,width:0,zIndex:n.zIndex}),s=n.radius+n.length+n.width,a,l;if(t){t.insertBefore(r,t.firstChild||null);l=d(t);a=d(r);f(r,{left:(n.left=="auto"?l.x-a.x+(t.offsetWidth>>1):parseInt(n.left,10)+s)+"px",top:(n.top=="auto"?l.y-a.y+(t.offsetHeight>>1):parseInt(n.top,10)+s)+"px"})}r.setAttribute("role","progressbar");e.lines(r,e.opts);if(!i){var u=0,p=(n.lines-1)*(1-n.direction)/2,c,h=n.fps,m=h/n.speed,y=(1-n.opacity)/(m*n.trail/100),g=m/n.lines;(function v(){u++;for(var t=0;t<n.lines;t++){c=Math.max(1-(u+(n.lines-t)*g)%m*y,n.opacity);e.opacity(r,t*n.direction+p,c,n)}e.timeout=e.el&&setTimeout(v,~~(1e3/h))})()}return e},stop:function(){var t=this.el;if(t){clearTimeout(this.timeout);if(t.parentNode)t.parentNode.removeChild(t);this.el=undefined}return this},lines:function(t,e){var r=0,a=(e.lines-1)*(1-e.direction)/2,l;function d(t,i){return f(o(),{position:"absolute",width:e.length+e.width+"px",height:e.width+"px",background:t,boxShadow:i,transformOrigin:"left",transform:"rotate("+~~(360/e.lines*r+e.rotate)+"deg) translate("+e.radius+"px"+",0)",borderRadius:(e.corners*e.width>>1)+"px"})}for(;r<e.lines;r++){l=f(o(),{position:"absolute",top:1+~(e.width/2)+"px",transform:e.hwaccel?"translate3d(0,0,0)":"",opacity:e.opacity,animation:i&&s(e.opacity,e.trail,a+r*e.direction,e.lines)+" "+1/e.speed+"s linear infinite"});if(e.shadow)n(l,f(d("#000","0 0 4px "+"#000"),{top:2+"px"}));n(t,n(l,d(e.color,"0 0 1px rgba(0,0,0,.1)")))}return t},opacity:function(t,e,i){if(e<t.childNodes.length)t.childNodes[e].style.opacity=i}});function c(){function t(t,e){return o("<"+t+' xmlns="urn:schemas-microsoft.com:vml" class="spin-vml">',e)}r.addRule(".spin-vml","behavior:url(#default#VML)");p.prototype.lines=function(e,i){var o=i.length+i.width,r=2*o;function s(){return f(t("group",{coordsize:r+" "+r,coordorigin:-o+" "+-o}),{width:r,height:r})}var a=-(i.width+i.length)*2+"px",l=f(s(),{position:"absolute",top:a,left:a}),d;function u(e,r,a){n(l,n(f(s(),{rotation:360/i.lines*e+"deg",left:~~r}),n(f(t("roundrect",{arcsize:i.corners}),{width:o,height:i.width,left:i.radius,top:-i.width>>1,filter:a}),t("fill",{color:i.color,opacity:i.opacity}),t("stroke",{opacity:0}))))}if(i.shadow)for(d=1;d<=i.lines;d++)u(d,-2,"progid:DXImageTransform.Microsoft.Blur(pixelradius=2,makeshadow=1,shadowopacity=.3)");for(d=1;d<=i.lines;d++)u(d);return n(e,l)};
4p.prototype.opacity=function(t,e,i,o){var n=t.firstChild;o=o.shadow&&o.lines||0;if(n&&e+o<n.childNodes.length){n=n.childNodes[e+o];n=n&&n.firstChild;n=n&&n.firstChild;if(n)n.opacity=i}}}var h=f(o("group"),{behavior:"url(#default#VML)"});if(!a(h,"transform")&&h.adj)c();else i=a(h,"animation");return p});
5
6function alterValue(component, val) {
7    if (component.value == '') {
8        component.value = val;
9    } else if (component.value == val) {
10        component.value = '';
11    }
12}
13
14/**
15 * Preenche uma combo box a partir de um array
16*/
17function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
18    var i, j;
19    var prompt;
20    
21    if ((itemArray == '0') || (itemArray == -1) || (itemArray == null)) {
22        selectCtrl.disabled = true;
23    } else {
24        selectCtrl.disabled = false;
25    }
26    
27    // empty existing items
28    for (i = selectCtrl.options.length; i >= 0; i--) {
29        selectCtrl.options[i] = null; 
30    }
31    prompt = (itemArray != null) ? goodPrompt : badPrompt;
32    if (prompt == null) {
33        j = 0;
34    } else {
35        selectCtrl.options[0] = new Option(prompt);
36        j = 1;
37    }
38    if (itemArray != null) {
39        // add new items
40        for (i = 0; i < itemArray.length; i++) {
41            selectCtrl.options[j] = new Option(itemArray[i][0]);
42            if (itemArray[i][1] != null) {
43                selectCtrl.options[j].value = itemArray[i][1]; 
44            }
45            j++;
46        }
47        // select first item (prompt) for sub list
48        selectCtrl.options[0].selected = true;
49    }
50}
51 
52function loadjscssfile(filename, filetype, async){
53    if (filetype=="js"){ //if filename is a external JavaScript file
54        var fileref=document.createElement('script');
55        fileref.setAttribute("type","text/javascript");
56        fileref.setAttribute("src", filename);
57        if(async == 'true')
58           fileref.setAttribute("async", "true");
59    }
60    else if (filetype=="css"){ //if filename is an external CSS file
61        var fileref=document.createElement("link");
62        fileref.setAttribute("rel", "stylesheet");
63        fileref.setAttribute("type", "text/css");
64        fileref.setAttribute("href", filename);
65    }
66    if (typeof fileref!="undefined")
67        document.getElementsByTagName("head")[0].appendChild(fileref);
68}
69
70/* code from qodo.co.uk */
71//create as many regular expressions here as you need:
72var digitsOnly = /[1234567890]/g;
73var integerOnly = /[0-9\.]/g;
74var alphaOnly = /[A-Z]/g;
75
76function restrictCharacters(myfield, e, restrictionType) {
77    if (!e) var e = window.event
78    if (e.keyCode) code = e.keyCode;
79    else if (e.which) code = e.which;
80    var character = String.fromCharCode(code);
81
82    // if they pressed esc... remove focus from field...
83    if (code==27) { this.blur(); return false; }
84
85    // ignore if they are press other keys
86    // strange because code: 39 is the down key AND ' key...
87    // and DEL also equals .
88    if (!e.ctrlKey && code!=9 && code!=8 && code!=36 && code!=37 && code!=38 && (code!=39 || (code==39 && character=="'")) && code!=40) {
89        if (character.match(restrictionType)) {
90            return true;
91        } else {
92            return false;
93        }
94    }
95}
96
97
98function run_animation($element, delay, duration) {
99    $element.delay(delay).fadeToggle(duration, function() {
100        run_animation($element, delay, duration);
101    });
102}
103
104function save_cookie(lang,opt)
105{    
106    jQuery.ajax({
107        url: '/'+lang+'/cms/savecookie',
108        type: 'POST',
109        cache: false,
110        error: function(){},
111        success: function(result)
112        {
113            //se foi o <a>
114            if(jQuery.trim(opt) == '1')
115            {
116                var pageurl = jQuery("#cookies_div a").attr("href");
117                
118                window.location = pageurl;
119            }
120            else
121            {
122                jQuery("#cookies_div").slideUp(500);
123            }
124        }
125    });
126}
127
128//paginacao ajax
129function paginarElementos(url, divId){	
130    jQuery("#ajax_loader").modal({
131        keyboard: false,
132        backdrop: 'static'
133    });
134    
135    jQuery.ajax({
136        url: url,
137        type: 'post',
138        error: function(){
139            jQuery("#modal_box_generic").removeClass('modal-success');
140            jQuery("#modal_box_generic").removeClass('modal-danger');
141            
142            jQuery("#modal_box_generic").addClass('modal-danger');
143            jQuery("#modal_box_generic .modal-title").html('Error');
144            jQuery("#modal_box_generic .modal-body").html('Ajax Error!');
145            
146            jQuery("#ajax_loader").modal('hide');
147            
148            jQuery("#modal_box_generic").modal('show');
149        },
150        success: function(result){
151            jQuery("#"+jQuery.trim(divId)).html(result);
152            
153            jQuery("#ajax_loader").modal('hide');
154        }
155    });
156}
157
158//atribuir um cookie javascript
159function setCookie(cname, cvalue, exdays) {
160    var d = new Date();
161    d.setTime(d.getTime() + (exdays*24*60*60*1000));
162    var expires = "expires="+d.toGMTString();
163    document.cookie = cname + "=" + cvalue + "; " + expires;
164}
165
166//receber o valor do cookie javascript
167function getCookie(cname) {
168    var name = cname + "=";
169    var ca = document.cookie.split(';');
170    for(var i=0; i<ca.length; i++) {
171        var c = ca[i];
172        while (c.charAt(0)==' ') c = c.substring(1);
173        if (c.indexOf(name) != -1) return c.substring(name.length,c.length);
174    }
175    return "";
176}
177
178function check_enter(e,id_button)
179{
180    var tecla = (window.event) ? e.keyCode : e.which;
181
182    if(tecla == 13)
183    {
184        jQuery("#"+jQuery.trim(id_button)).click();
185    }
186
187    return true;
188}
189
190
191function gowebShowCustomBox(link,title, filter)
192{
193    event.preventDefault();
194
195    var data = {
196        'link' : link,
197        'title' : title,
198        'filter' : filter
199    };
200
201    jQuery.ajax({
202        url: link,
203        cache: true,
204        data: data,
205        success: function(result){            
206            jQuery("#modal_box_generic .modal-title").html(title);
207            jQuery("#modal_box_generic .modal-body").html(result);
208
209            jQuery("#modal_box_generic").modal({
210                keyboard: false,
211                backdrop: 'static'
212            });
213        }
214    });
215}
216
217function remove_box()
218{
219    jQuery("#modal_box_generic .modal-title").html('');
220    jQuery("#modal_box_generic .modal-body").html('');
221    jQuery("#modal_box_generic").modal('hide');
222}
223
224//funcao para deslocar a pagina ate um determinado elemento com id id_div
225function goToByScroll(id_div, orientation, margin)
226{   
227    //se a div existir na pagina a ser visualizada
228    if(jQuery("#"+id_div).length > 0)
229    {
230        //se for orientacao vertical
231        if(jQuery.trim(orientation) == 'v')
232        {
233            //Scroll
234            jQuery('body, html').animate({
235                scrollTop: jQuery("#"+id_div).offset().top-parseInt(margin)
236            },'slow');
237        }
238        //se for orientacao horizontal
239        else if(jQuery.trim(orientation) == 'h')
240        {
241            //margin left da primeira div
242            var m_left = 0;
243            //variavel de controlo para saber se ja chegou a div seleccionad
243a
244            var aux_index = 0;
245            //index da div seleccionada
246            var index_select_div = jQuery("#subcontent .div_parallax").index(jQuery("#"+id_div));
247            
248            jQuery("#subcontent").find('.div_parallax').each(function(){
249                
250                //se o index da div do ciclo for menor que o index da div seleccionada
251                if(aux_index < index_select_div)
252                {
253                    var left_aux = parseInt(jQuery(this).width())+parseInt(jQuery(this).css("border-left"))+parseInt(jQuery(this).css("border-right"));
254
255                    m_left += parseInt(left_aux);
256                }
257                
258                aux_index++;
259            });      
260            
261            var margin_left_parallax = parseInt(jQuery("#contents_parallax").css("margin-left"));
262            
263            //se ja esta negativo, entao ja foi deslocado para a esquerda
264            if(parseInt(margin_left_parallax) < 0)
265            {
266                //se o left calculado for maior, entao continua a deslocar para a esquerda
267                if(Math.abs(parseInt(margin_left_parallax)) < parseInt(m_left))
268                {
269                    var new_left = parseInt(m_left)-Math.abs(parseInt(margin_left_parallax));
270                    
271                    console.log("continua para a esquerda mais: "+new_left);
272                
273                    //Scroll
274                    jQuery("#contents_parallax").animate({
275                        'margin-left':'-='+new_left+'px'
276                    },'slow');
277                }
278                //desloca para a direita
279                else
280                {
281                    var new_left = Math.abs(parseInt(margin_left_parallax))-parseInt(m_left);
282                    
283                    console.log("vai para a direita mais: "+new_left);
284                
285                    //Scroll
286                    jQuery("#contents_parallax").animate({
287                        'margin-left':'+='+new_left+'px'
288                    },'slow');
289                }
290            }
291            //se for o deslocamento inicial
292            else
293            {
294                //Scroll
295                jQuery("#contents_parallax").animate({
296                    'margin-left':'-='+parseInt(m_left)+'px'
297                },'slow');
298            }
299            /*if(parseInt(margin_left_parallax) < parseInt(m_left))
300            {
301                var new_left = parseInt(m_left)-parseInt(margin_left_parallax);
302                
303                //Scroll
304                jQuery("#contents_parallax").animate({
305                    'margin-left':'-='+new_left+'px'
306                },'slow');
307            }
308            else
309            {
310                var new_left = parseInt(margin_left_parallax)-parseInt(m_left);
311                
312                //Scroll
313                jQuery("#contents_parallax").animate({
314                    'margin-left':'+='+new_left+'px'
315                },'slow');
316            }*/
317            
318            
319            
320            
321        }
322    }
323}
324
325//funcionalidades gerais
326jQuery(window).load(function(){
327    //verifica se existe a funcionalidade fancybox
328    if(jQuery().fancybox){
329        jQuery(".fancybox_ele").fancybox();
330    }
331});
332
333// CSRF token — automatically included in all jQuery AJAX POST requests
334// Uses the global csrfToken variable set in include_head_generic.tpl
335(function() {
336    if (typeof csrfToken !== 'undefined') {
337        jQuery.ajaxSetup({
338            beforeSend: function(xhr, settings) {
339                // So' para o proprio site (30 Set 2026): o token nao vai para
340                // outros dominios.
341                if (settings.crossDomain) return;
342                if (settings.type && settings.type.toUpperCase() === 'POST') {
343                    xhr.setRequestHeader('X-CSRF-Token', csrfToken);
344                }
345            }
346        });
347    }
348})();
349
350// Native fetch() wrapper — automatically includes XMLHttpRequest header and CSRF token
351// jQuery handles this via $.ajaxSetup above; this covers native fetch() calls
352//
353// 30 Set 2026: SO' para pedidos ao proprio site. Antes punha o
354// X-Requested-With (e o token CSRF nos POST) em TODOS os fetch, tambem para
355// outros dominios -- o CDN da CookieYes recusava o pedido (CORS: "x-requested-with
356// is not allowed"), a CookieYes ficava sem as regras do banner e dava o
357// consentimento como aceite sem mostrar banner nenhum. E o token CSRF ia
358// parar a servidores de terceiros. Pedidos para fora passam intactos.
359(function() {
360    var originalFetch = window.fetch;
361    var mesmoSite = function(input) {
362        try {
363            var url = (typeof input === 'string') ? input : (input && input.url) ? input.url : String(input);
364            return new URL(url, window.location.href).origin === window.location.origin;
365        } catch (e) {
366            return true;
367        }
368    };
369    window.fetch = function(input, init) {
370        if (!mesmoSite(input)) {
371            return originalFetch.apply(this, arguments);
372        }
373        init = init || {};
374        init.headers = new Headers(init.headers || {});
375
376        // Always mark as AJAX request
377        if (!init.headers.has('X-Requested-With')) {
378            init.headers.set('X-Requested-With', 'XMLHttpRequest');
379        }
380
381        // Add CSRF token to POST requests (same behavior as jQuery ajaxSetup)
382        if (typeof csrfToken !== 'undefined') {
383            var method = (init.method || 'GET').toUpperCase();
384            if (method === 'POST' && !init.headers.has('X-CSRF-Token')) {
385                init.headers.set('X-CSRF-Token', csrfToken);
386            }
387        }
388
389        return originalFetch.call(this, input, init);
390    };
391})();

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.