PageSourceSearch

https://savethevalley.org/js/common.js?v=1529163457

js savethevalley.org collected 2026-09-26 15:57:14 UTC 5,417 bytes, 191 lines download raw bytes

1/**
2 * global js functionality holder
3 * @type {Function}
4 *
5 */
6var LeiGlob = {};
7
8/**
9 * manage dynamic js data
10 */
11LeiGlob.jsdata = {
12
13    //available data
14    data: {},
15
16    //set data
17    init: function(){
18//        var _hold = $('#-lei-jsdata'),
19//            _raw = $.parseJSON(_hold.html());
20//        var _raw = leiJsData;
21        if(typeof leiJsData == 'undefined'){
22            return;
23        }
24        this.data = leiJsData;
25        //_hold.empty().data('data', _raw);
26//        _hold.empty();
27    },
28
29    //add data
30    add: function(type, id, key, val){
31        if(!this.data[type]){
32            this.data[type] = {};
33        }
34        if(!this.data[type][id]){
35            this.data[type][id] = {};
36        }
37        this.data[type][id][key] = val;
38    },
39
40    addArray: function(type, id, data){
41        if(!this.data[type]){
42            this.data[type] = {};
43        }
44        if(!this.data[type][id]){
45            this.data[type][id] = {};
46        }
47        this.data[type][id] = $.extend(this.data[type][id], data);
48    },
49
50    //get data
51    fetch: function(type, id){
52        if(!this.data[type]){
53            return null;
54        }
55        if(!id){
56            return this.data[type];
57        }
58        if(!this.data[type][id]){
59            return null;
60        }
61        return this.data[type][id];
62    }
63}
64
65LeiGlob.previewMode = function(){
66
67    var t = this;
68    this.nav = $('#-lei-preview-nav');
69    this.mode = this.nav.data('mode');
70
71    this.isMode = function(mode){
72        if(['preview','live', 'close'].indexOf(mode) == -1){
73            window.location.reload(true);
74            return false;
75        }
76        return true;
77    }
78
79    this.nav.on('click', '.-lei-preview-btn', function(event){
80        event.preventDefault();
81        var btn = $(this),
82            mode = btn.data('mode');
83        if(!t.isMode(mode)){
84            return;
85        }
86
87        var path = window.location.pathname;
88        if(mode == 'close'){
89            window.location.replace(path);
90            return;
91        }
92
93        window.location.replace(path +'?'+ mode +'=true');
94    });
95
96    $('body').find('a:not(.-lei-preview-btn)').each(function(){
97        var link = $(this),
98            url = link.prop('href'),
99            mode = t.nav.data('mode');
100        if(link.attr('target') == '_blank' || link.attr('target') == 'new'){
101            return;
102        }
103        link.prop('href', url +'?'+ mode +'=true');
104    });
105
106    /*
107     $('body').on('click', 'a:not(.-lei-preview-btn)', function(event){
108     if(!t.isMode(t.mode)){
109     return;
110     }
111     var btn = $(this);
112     if(btn.attr('target') == '_blank' || btn.attr('target') == 'new'){
113     return;
114     }
115     event.preventDefault();
116     window.location.replace(btn.prop('href') +'?'+ t.mode +'=true');
117     });
118    * */
119}
120
121/**
122 * https://jsfiddle.net/sturtevant/AZFvQ/
123 */
124function CSVToArray(strData, strDelimiter) {
125    // Check to see if the delimiter is defined. If not,
126    // then default to comma.
127    strDelimiter = (strDelimiter || ",");
128    // Create a regular expression to parse the CSV values.
129    var objPattern = new RegExp((
130        // Delimiters.
131    "(\\" + strDelimiter + "|\\r?\\n|\\r|^)" +
132        // Quoted fields.
133    "(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" +
134        // Standard fields.
135    "([^\"\\" + strDelimiter + "\\r\\n]*))"), "gi");
136    // Create an array to hold our data. Give the array
137    // a default empty first row.
138    var arrData = [[]];
139    // Create an array to hold our individual pattern
140    // matching groups.
141    var arrMatches = null;
142    // Keep looping over the regular expression matches
143    // until we can no longer find a match.
144    while (arrMatches = objPattern.exec(strData)) {
145        // Get the delimiter that was found.
146        var strMatchedDelimiter = arrMatches[1];
147        // Check to see if the given delimiter has a length
148        // (is not the start of string) and if it matches
149        // field delimiter. If id does not, then we know
150        // that this delimiter is a row delimiter.
151        if (strMatchedDelimiter.length && (strMatchedDelimiter != strDelimiter)) {
152            // Since we have reached a new row of data,
153            // add an empty row to our data array.
154            arrData.push([]);
155        }
156        // Now that we have our delimiter out of the way,
157        // let's check to see which kind of value we
158        // captured (quoted or unquoted).
159        if (arrMatches[2]) {
160            // We found a quoted value. When we capture
161            // this value, unescape any double quotes.
162            var strMatchedValue = arrMatches[2].replace(
163                new RegExp("\"\"", "g"), "\"");
164        } else {
165            // We found a non-quoted value.
166            var strMatchedValue = arrMatches[3];
167        }
168        // Now that we have our value string, let's add
169        // it to the data array.
170        arrData[arrData.length - 1].push(strMatchedValue);
171    }
172    // Return the parsed data.
173    return (arrData);
174}
175
176function CSV2JSON(csv) {
177    var array = CSVToArray(csv);
178    var objArray = [];
179    for (var i = 1; i < array.length; i++) {
180        objArray[i - 1] = {};
181        for (var k = 0; k < array[0].length && k < array[i].length; k++) {
182            var key = array[0][k];
183            objArray[i - 1][key] = array[i][k]
184        }
185    }
186
187    var json = JSON.stringify(objArray);
188    var str = json.replace(/},/g, "},\r\n");
189
190    return str;
191}

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.