PageSourceSearch

https://q1e.co.uk/resources/scripts/lib/tcglib.js

js q1e.co.uk collected 2026-10-04 07:03:34 UTC 3,754 bytes, 168 lines download raw bytes

1// PURE
2//
3// version 29.04.20 - added tcAjaxModule
4// version 19.11.19 - added getFirstElementByClassName
5// @version 28.10.19 - fix $ problem
6// @version 02.04.19 - tcElement : restore couple of items to stop error message
7// version 11.03.19 - remove default params and fix bad problems with tcElement
8// version 3.02.19 - can pass object to tcElement
9
10window.addEventListener("load", function() {
11	HTMLElement.prototype.$ = function(c) { return this.getElementById(c);}
12	HTMLElement.prototype.$$ = function(c) { return this.querySelectorAll(c);}
13});
14
15function	tcBalanceCols(c)	{
16	var	hc = $$("." + c);
17	var h = 0;
18	hc.forEach(function(v) {
19		if(v.clientHeight > h)	{
20			h = v.clientHeight;
21		}
22	});
23	hc.forEach(function(v) {
24		v.style.height = h + "px";
25	});
26}
27
28function loadScript(src, onf) {
29	var script = document.createElement('script');
30	script.src = src;
31	if( onf ) script.onload = onf
32	document.head.appendChild(script);
33}
34
35function loadCss(src, onf) {
36	
37	var script = document.createElement('link');
38	script.href = src;
39	script.type = "text/css";
40	script.rel = "stylesheet";
41	script.media = "screen,print";
42	if( onf ) script.onload = onf
43	document.head.appendChild(script);
44}
45
46function formSubmitModule(_fname, _action, _module, _form_state_change) {
47
48	if(!_form_state_change) 	_form_state_change=null;
49	myForm	=	document.getElementById(_fname);
50	myForm.onsubmit = function(e) {
51	    e.preventDefault();
52
53	    xhttp = new XMLHttpRequest();
54		xhttp.open('POST', myForm.action, true );
55		xhttp.onreadystatechange = _form_state_change;
56		
57	    var fd = new FormData(myForm);
58		fd.append("module", _module);
59		fd.append("action",_action);
60		fd.append("formid",_fname);
61		
62		xhttp.send(fd);
63	}
64	
65//	return xhttp;
66}
67
68//function 			var newAction = tcElement("input", ['name' => 'option', 'value' => 'on'] );
69
70/*
71 * //		newItem.className = "client";
72//		newItem.innerHTML = e.garden_client_name;
73 */
74function	tcElement(ele, arr) {
75	
76	var e = document.createElement(ele);
77
78//	if( typeof arr === "object") {
79	if( !Array.isArray(arr)) {
80		narr = []
81		for(key in arr) {
82			narr[key] = arr[key]
83		}
84		arr = narr
85	}
86	
87	if(arr) {
88		for(var idx in arr) {
89			var val = arr[idx];
90			switch(idx) {
91			case('class'):
92				e.className = val;
93				break;
94			case('html'):
95			case('text'):
96				e.innerHTML = val;
97				break;
98			case('attr'):
99				for(var didx in val) {
100					e.setAttribute(didx, val[didx])
101				}
102				break;
103			case('style'):
104				e.setAttribute("style",val);
105				break;
106			case('id'):
107			case('href'):
108				e[idx] = val;
109				break;
110			default:
111				e[idx] = val;		
112				console.log('Unknown index ' + idx + " creating element");
113			}
114		}
115	}
116	return e;
117}
118
119var tcClass = function(methods) {   
120    var klass = function() {    
121        this.initialize.apply(this, arguments);          
122    };  
123
124    for (var property in methods) { 
125       klass.prototype[property] = methods[property];
126    }
127
128    if (!klass.prototype.initialize) klass.prototype.initialize = function(){};      
129
130    return klass;    
131};
132
133
134function tcAjaxModule( _module, _action, _data, _success ) {
135	xhttp = new XMLHttpRequest();
136	xhttp.open('POST', "/code/ajaxcall.php", true );
137	xhttp.onload = _success;
138	var fd = new FormData();
139
140	fd.append("module", _module);
141	fd.append("action",_action);	
142	fd.append("data", JSON.stringify(_data));
143	
144	xhttp.send(fd);
145	return xhttp;
146	
147}
148
149//function tcAjax( url, data, success, failure) {
150function tcAjax( url, data, success ) {
151	xhttp = new XMLHttpRequest();
152	xhttp.open('POST', url, true );
153	xhttp.onload = success;
154	var fd = new FormData();
155	fd.append("data", data);
156	xhttp.send(fd);
157	return xhttp;
158}
159
160
161function getFirstElementByClassName(c) {
162	var it = document.getElementsByClassName(c);
163	if( it.length != 0) {
164		return it[0]
165	}
166	return null
167}
168	

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.