PageSourceSearch

https://www.ubo.cl/wp-content/plugins/add-campo-rut-cf7/scripts.js?1790916096

js ubo.cl collected 2026-10-02 04:42:53 UTC 3,502 bytes, 110 lines download raw bytes

1/*!
2 * 
3 * JavaScript for Campo RUT para Contact Form 7
4 * 
5 */
6
7
8/**
9 * ------------------------------------------------------------------------
10 * Ready function
11 * ------------------------------------------------------------------------
12 */
13
14function cf7rf_ready(callback){
15  // in case the document is already rendered
16  if (document.readyState!='loading') callback();
17  // modern browsers
18  else if (document.addEventListener) document.addEventListener('DOMContentLoaded', callback);
19  // IE <= 8
20  else document.attachEvent('onreadystatechange', function(){
21      if (document.readyState=='complete') callback();
22  });
23}
24
25/**
26 * ------------------------------------------------------------------------
27 * Field filter
28 * ------------------------------------------------------------------------
29 */
30
31function cf7rf_setInputFilter(textbox, inputFilter) {
32  ["input", "keydown", "keyup", "mousedown", "mouseup", "select", "contextmenu", "drop"].forEach(function(event) {
33    textbox.addEventListener(event, function() {
34    if (inputFilter(this.value)) {
35      this.oldValue = this.value;
36      this.oldSelectionStart = this.selectionStart;
37      this.oldSelectionEnd = this.selectionEnd;
38    } else if (this.hasOwnProperty("oldValue")) {
39      this.value = this.oldValue;
40      this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
41    } else {
42      this.value = "";
43    }
44    });
45  });
46}
47
48
49/**
50 * ------------------------------------------------------------------------
51 * Format RUT
52 * ------------------------------------------------------------------------
53 */
54
55function cf7rf_formatRut(rut) {
56 var rut = rut.replace(/^0+/, "");
57  if (rut != '' && rut.length > 1) {
58      var rut = rut.replace(/\./g, "");
59      var rut = rut.replace(/-/g, "");
60      var dv = rut.substring(rut.length - 1);
61      var rut = rut.substring(0, rut.length - 1);
62      var rutPoints = "";
63      var i = 0;
64      var j = 1;
65      for (i = rut.length - 1; i >= 0; i--) {
66          var c = rut.charAt(i);
67          rutPoints = c + rutPoints;
68          if (j % 3 == 0 && j <= rut.length - 1) {
69            rutPoints = "." + rutPoints;
70          }
71          j++;
72      }
73      rutPoints = rutPoints + "-" + dv;
74      return rutPoints;
75  }else{
76    return null;
77  }
78}
79
80
81/**
82 * ------------------------------------------------------------------------
83 * Callback ready
84 * ------------------------------------------------------------------------
85 */
86
87cf7rf_ready(function(){
88  if(typeof document.getElementsByClassName('wpcf7-form')[0] !== 'undefined' && document.getElementsByClassName('wpcf7-form')[0] !== null){
89    if(typeof document.getElementsByClassName('wpcf7-validates-as-rut')[0] !== 'undefined' && document.getElementsByClassName('wpcf7-validates-as-rut')[0] !== null){
90      var fields = document.getElementsByClassName('wpcf7-validates-as-rut');
91      for (var i = 0; i < fields.length; ++i) {
92        var field = fields[i];
93        if(field.classList.contains("wpcf7-rut-onlynumbers")){
94          cf7rf_setInputFilter(field , function(value) {return /^[0-9kK]*$/.test(value); });
95        }
96        field.addEventListener("blur", blurCallback, false);
97      }
98      function blurCallback(e) {
99        var field = e.currentTarget
100        var value = field.value;
101        if(typeof value  !== 'undefined' && value != '' && value != null){
102          if(field.classList.contains("wpcf7-rut-onformat")){
103            field.value = cf7rf_formatRut(value);
104          }
105        }
106      }
107    } 
108  }
109
110});

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.