PageSourceSearch

https://filtergraph.com/filtergraph/static/_1.0.0/js/web2py.js

js filtergraph.com collected 2026-10-01 14:40:53 UTC 8,538 bytes, 208 lines download raw bytes

1function popup(url) {
2  newwindow=window.open(url,'name','height=400,width=600');
3  if (window.focus) newwindow.focus();
4  return false;
5}
6function collapse(id) { jQuery('#'+id).slideToggle(); }
7function fade(id,value) { if(value>0) jQuery('#'+id).hide().fadeIn('slow'); else jQuery('#'+id).show().fadeOut('slow'); }
8function ajax(u,s,t) {
9    query = '';
10    if (typeof s == "string") {
11        d = jQuery(s).serialize();
12        if(d){ query = d; }
13    } else {
14        pcs = [];
15        if (s != null && s != undefined) for(i=0; i<s.length; i++) {
16            q = jQuery("[name="+s[i]+"]").serialize();
17            if(q){pcs.push(q);}
18        }
19        if (pcs.length>0){query = pcs.join("&");}
20    }
21    jQuery.ajax({type: "POST", url: u, data: query, success: function(msg) { if(t) { if(t==':eval') eval(msg); else if(typeof t=='string') jQuery("#"+t).html(msg); else t(msg); } } });
22}
23
24String.prototype.reverse = function () { return this.split('').reverse().join('');};
25function web2py_ajax_fields(target) {
26  var date_format = (typeof w2p_ajax_date_format != 'undefined') ? w2p_ajax_date_format : "%Y-%m-%d";
27  var datetime_format = (typeof w2p_ajax_datetime_format != 'undefined') ? w2p_ajax_datetime_format : "%Y-%m-%d %H:%M:%S";
28  jQuery("input.date",target).each(function() {Calendar.setup({inputField:this, ifFormat:date_format, showsTime:false });});
29  jQuery("input.datetime",target).each(function() {Calendar.setup({inputField:this, ifFormat:datetime_format, showsTime: true, timeFormat: "24" });});
30  jQuery("input.time",target).each(function(){jQuery(this).timeEntry();});
31
32};
33
34function web2py_ajax_init(target) {
35  jQuery('.hidden', target).hide();
36  jQuery('.error', target).hide().slideDown('slow');
37  web2py_ajax_fields(target);
38};
39
40function web2py_event_handlers() {
41  var doc = jQuery(document)
42      doc.on('click', '.flash', function(e){var t=jQuery(this); if(t.css('top')=='0px') t.slideUp('slow'); else t.fadeOut(); e.preventDefault();});
43  doc.on('keyup', 'input.integer', function(){this.value=this.value.reverse().replace(/[^0-9\-]|\-(?=.)/g,'').reverse();});
44  doc.on('keyup', 'input.double, input.decimal', function(){this.value=this.value.reverse().replace(/[^0-9\-\.,]|[\-](?=.)|[\.,](?=[0-9]*[\.,])/g,'').reverse();});
45  var confirm_message = (typeof w2p_ajax_confirm_message != 'undefined') ? w2p_ajax_confirm_message : "Are you sure you want to delete this object?";
46  doc.on('click', "input[type='checkbox'].delete", function(){if(this.checked) if(!confirm(confirm_message)) this.checked=false;});
47  doc.ajaxSuccess(function(e, xhr) {
48    var redirect=xhr.getResponseHeader('web2py-redirect-location');
49    if (redirect != null) {
50      window.location = redirect;
51    };
52  });
53};
54
55jQuery(function() {
56   var flash = jQuery('.flash');
57   flash.hide();
58   if(flash.html()) flash.append('<span id="closeflash">&times;</span>').slideDown();
59   web2py_ajax_init(document);
60   web2py_event_handlers();
61});
62
63function web2py_trap_form(action,target) {
64   jQuery('#'+target+' form').each(function(i){
65      var form=jQuery(this);
66      if(!form.hasClass('no_trap'))
67        form.submit(function(e){
68         jQuery('.flash').hide().html('');
69         web2py_ajax_page('post',action,form.serialize(),target);
70         e.preventDefault();
71      });
72   });
73}
74
75function web2py_trap_link(target) {
76    jQuery('#'+target+' a.w2p_trap').each(function(i){
77            var link=jQuery(this);
78            link.click(function(e) {
79                    jQuery('.flash').hide().html('');
80                    web2py_ajax_page('get',link.attr('href'),[],target);
81                    e.preventDefault();
82                });
83        });
84}
85
86function web2py_ajax_page(method, action, data, target) {
87  jQuery.ajax({'type':method, 'url':action, 'data':data,
88    'beforeSend':function(xhr) {
89      xhr.setRequestHeader('web2py-component-location', document.location);
90      xhr.setRequestHeader('web2py-component-element', target);},
91    'complete':function(xhr,text){
92      var html=xhr.responseText;
93      var content=xhr.getResponseHeader('web2py-component-content');
94      var command=xhr.getResponseHeader('web2py-component-command');
95      var flash=xhr.getResponseHeader('web2py-component-flash');
96      var t = jQuery('#'+target);
97      if(content=='prepend') t.prepend(html);
98      else if(content=='append') t.append(html);
99      else if(content!='hide') t.html(html);
100      web2py_trap_form(action,target);
101      web2py_trap_link(target);
102      web2py_ajax_init('#'+target);
103      if(command)
104          eval(decodeURIComponent(command));
105      if(flash) {
106          jQuery('.flash')
107                .html(decodeURIComponent(flash))
108                .append('<span id="closeflash">&times;</span>')
109                .slideDown();
110        }
111    }
112  });
113}
114
115function web2py_component(action, target, timeout, times){
116  jQuery(function(){
117    var jelement = jQuery("#" + target);
118    var element = jelement.get(0);
119    var statement = "jQuery('#" + target + "').get(0).reload();";
120    element.reload = function (){
121        // Continue if times is Infinity or
122        // the times limit is not reached
123        if (this.reload_check()){
124            web2py_ajax_page('get', action, null, target);} }; // reload
125    // Method to check timing limit
126    element.reload_check = function (){
127        if (jelement.hasClass('w2p_component_stop')) {return false;}
128        if (this.reload_counter == Infinity){return true;}
129        else {
130            if (!isNaN(this.reload_counter)){
131                this.reload_counter -= 1;
132                if (this.reload_counter < 0){
133                    if (!this.run_once){
134                        clearInterval(this.timing);
135                        return false;
136                    }
137                }
138                else{return true;}
139            } }
140            return false;}; // reload check
141    if (!isNaN(timeout)){
142        element.timeout = timeout;
143        element.reload_counter = times;
144        if (times > 1){
145        // Multiple or infinite reload
146        // Run first iteration
147        web2py_ajax_page('get', action, null, target);
148        element.run_once = false;
149        element.timing = setInterval(statement, timeout);
150        element.reload_counter -= 1;
151        }
152        else if (times == 1) {
153        // Run once with timeout
154        element.run_once = true;
155        element.setTimeout = setTimeout;
156        element.timing = setTimeout(statement, timeout);
157        }
158    } else {
159        // run once (no timeout specified)
160        element.reload_counter = Infinity;
161        web2py_ajax_page('get', action, null, target);
162    } }); }
163
164function web2py_websocket(url,onmessage,onopen,onclose) {
165  if ("WebSocket" in window) {
166    var ws = new WebSocket(url);
167    ws.onopen = onopen?onopen:(function(){});
168    ws.onmessage = onmessage;
169    ws.onclose = onclose?onclose:(function(){});
170    return true; // supported
171  } else return false; // not supported
172}
173
174
175function web2py_calc_entropy(mystring) {
176    //calculate a simple entropy for a given string
177    var csets = new Array(
178      'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
179      '0123456789', '!@#$\%^&*()', '~`-_=+[]{}\|;:\'",.<>?/',
180      '0123456789abcdefghijklmnopqrstuvwxyz');
181    var score = 0, other = {}, seen = {}, lastset = null, mystringlist = mystring.split('');
182    for (var i=0;i<mystringlist.length;i++) { // classify this character
183        var c = mystringlist[i], inset=5;
184        for(var j = 0; j<csets.length; j++)
185          if (csets[j].indexOf(c) != -1) {inset = j; break;}
186        //calculate effect of character on alphabet size       
187        if(!(inset in seen)) {seen[inset] = 1;score += csets[inset].length;}
188        else if (!(c in other)) {score += 1;other[c] = 1;}
189        if (inset != lastset) {score += 1;lastset = inset;}
190    }
191    var entropy = mystring.length*Math.log(score)/0.6931471805599453;
192    return Math.round(entropy*100)/100
193}
194
195function web2py_validate_entropy(myfield, req_entropy) {
196    var validator = function () {
197        var v = (web2py_calc_entropy(myfield.val())||0)/req_entropy;
198        var r=0,g=0,b=0,rs=function(x){return Math.round(x*15).toString(16)};
199	if(v<=0.5) {r=1.0; g=2.0*v;}
200	else {r=(1.0-2.0*(Math.max(v,0)-0.5)); g=1.0;}
201	var color = '#'+rs(r)+rs(g)+rs(b);
202        myfield.css('background-color',color);
203	entropy_callback = myfield.data('entropy_callback');
204	if(entropy_callback) entropy_callback(v);
205    }
206    if(!myfield.hasClass('entropy_check')) myfield.on('keyup', validator).on('keydown', validator).addClass('entropy_check');
207}
208

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.