PageSourceSearch

https://nationalchip.com/static/js/tools.js?v=v2

js nationalchip.com collected 2026-10-05 18:09:11 UTC 9,494 bytes, 365 lines download raw bytes

1"use strict";
2var tools = {
3	check_cookie:function(){
4		if(window.navigator.cookieEnabled)  
5			return true;  
6		else{  
7			alert("浏览器配置错误,Cookie不可用!");  
8			return false;
9		}  
10	}
11	,set_cookie:function(name,value){  
12	   var Days = 30; //此 cookie 将被保存 30 天  
13	   var exp = new Date(); //new Date("December 31, 9998");  
14	   exp.setTime(exp.getTime() + Days*24*60*60*1000);  
15	   document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();  
16	}  
17	,get_cookie:function(name)
18	{  
19		var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));  
20		if(arr != null) return unescape(arr[2]); return null;  
21
22		// var regexp = new RegExp("(?:^" + name + "|;\s*"+ name + ")=(.*?)(?:;|$)", "g");
23		// var result = regexp.exec(document.cookie);
24		// return (result === null) ? null : result[1];
25	}  
26	,del_cookie:function(name)
27	{  
28		var exp = new Date();  
29		exp.setTime(exp.getTime() - 1);  
30		var cval=getCookie(name);  
31		if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();  
32	}  
33	// 检测空对象
34	// 空则返回true
35	,isEmptyValue:function(value) {
36		var type;
37	    if(value === null) { // 等同于 value === undefined || value === null
38	    	return true;
39	    }
40	    type = Object.prototype.toString.call(value).slice(8, -1);
41	    switch(type) {
42	    	case 'String':
43	    	return !!$.trim(value);
44	    	case 'Array':
45	    	return !value.length;
46	    	case 'Object':
47	    	// return $.isEmptyObject(value);
48	    	return !value.length;
49	    	default:
50	    	return false;
51	    }
52	}
53	,isEmpty : function(v){
54		if (v instanceof String) {
55			var r = /^\s*$/;
56			return r.test(v);
57		}else if(v instanceof Array){
58			return !v.length;
59		}else if(v instanceof Object){
60			return v === {};
61		}else{
62			return false;
63		}
64	}
65	,is_set:function(value){
66		if (typeof(value) == "undefined") {
67			return false;
68		}else{
69			return true;
70		}
71
72	}
73	// 解析URL路径
74	,parseURL:function(url) {
75		var a =  document.createElement('a');
76		a.href = url;
77		return {
78			source: url,
79			protocol: a.protocol.replace(':',''),
80			host: a.hostname,
81			port: a.port,
82			query: a.search,
83			params: (function(){
84				var ret = [],
85				seg = a.search.replace(/^\?/,'').split('&'),
86				len = seg.length, i = 0, s;
87				for (;i<len;i++) {
88					if (!seg[i]) { continue; }
89					s = seg[i].split('=');
90					ret[i] = {"key":s[0],"val":s[1]};
91				}
92				return ret;
93			})(),
94			file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1],
95			hash: a.hash.replace('#',''),
96			path: a.pathname.replace(/^([^\/])/,'/$1'),
97			relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [,''])[1],
98			segments: a.pathname.replace(/^\//,'').split('/')
99		};
100	}	
101};
102
103/**
104 * 图片头数据加载就绪事件
105 * @version	2011.05.27
106 * @author	TangBin
107 * @param	{String}	图片路径
108 * @param	{Function}	尺寸就绪
109 * @param	{Function}	加载完毕 (可选)
110 * @param	{Function}	加载错误 (可选)
111 * @example imgReady('http://www.google.com.hk/intl/zh-CN/images/logo_cn.png', function () {
112		alert('size ready: width=' + this.width + '; height=' + this.height);
113	});
114 */
115var imgReady = (function () {
116	var list = [];
117	var intervalId = null;
118
119	// 用来执行队列
120	var tick = function () {
121		var i = 0;
122		for (; i < list.length; i++) {
123			list[i].end ? list.splice(i--, 1) : list[i]();
124		};
125		!list.length && stop();
126	};
127
128	// 停止所有定时器队列
129	var stop = function () {
130		clearInterval(intervalId);
131		intervalId = null;
132	};
133
134	return function (url, ready, load, error) {
135		var onready, width, height, newWidth, newHeight,
136			img = new Image();
137		
138		img.src = url;
139
140		// 如果图片被缓存,则直接返回缓存数据
141		if (img.complete) {
142			ready.call(img);
143			load && load.call(img);
144			return;
145		};
146		
147		width = img.width;
148		height = img.height;
149		
150		// 加载错误后的事件
151		img.onerror = function () {
152			error && error.call(img);
153			onready.end = true;
154			img = img.onload = img.onerror = null;
155		};
156		
157		// 图片尺寸就绪
158		onready = function () {
159			newWidth = img.width;
160			newHeight = img.height;
161			if (newWidth !== width || newHeight !== height ||
162				// 如果图片已经在其他地方加载可使用面积检测
163				newWidth * newHeight > 1024
164			) {
165				ready.call(img);
166				onready.end = true;
167			};
168		};
169		onready();
170		
171		// 完全加载完毕的事件
172		img.onload = function () {
173			// onload在定时器时间差范围内可能比onready快
174			// 这里进行检查并保证onready优先执行
175			!onready.end && onready();
176		
177			load && load.call(img);
178			
179			// IE gif动画会循环执行onload,置空onload即可
180			img = img.onload = img.onerror = null;
181		};
182
183		// 加入队列中定期执行
184		if (!onready.end) {
185			list.push(onready);
186			// 无论何时只允许出现一个定时器,减少浏览器性能损耗
187			if (intervalId === null) intervalId = setInterval(tick, 40);
188		};
189	};
190})();
191
192
193// if (!window.console || !console.firebug)
194// if (!window.console)
195// {
196//     var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
197//     "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
198
199//     window.console = {};
200//     for (var i = 0; i < names.length; ++i)
201//         window.console[names[i]] = function() {};
202// }
203
204// IE9 console 未定义
205window.console = window.console || (function(){
206	var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile = c.clear = c.exception = c.trace = c.assert = function(){};
207	return c;
208})(); 
209
210// 表单 to object for ajax
211// 扩展 组织表单内容
212$.fn.serializeObject = function(){
213    var o = {};
214    var a = this.serializeArray();
215    $.each(a, function() {
216        if (o[this.name]) {
217            if (!o[this.name].push) {
218                o[this.name] = [o[this.name]];
219            }
220            o[this.name].push(this.value || '');
221        } else {
222            o[this.name] = this.value || '';
223        }
224    });
225    return o;
226};
227
228// array 删除对应值
229Array.prototype.remove = function(b) { 
230    var a = this.indexOf(b); 
231    if (a >= 0) { 
232        this.splice(a, 1); 
233        return true; 
234    } 
235    return false; 
236}; 
237
238
239// 一部加载页面对分页按钮处理 ,id 带有 #
240function load_page(_url,nodeId) {
241	$.ajax({
242		url: _url,
243		type: 'GET',
244		dataType: 'html'
245	})
246	.done(function(data) {
247		console.log("success");
248		$(nodeId).html(data);
249		$(nodeId+" .pagination a").each(function(index, el) {
250			var elhref = $(el).attr('href');
251			if ( elhref == '#' ) {
252				elhref = _url;
253				$(el).attr('data-href',_url);
254			}else{
255				$(el).attr('data-href',elhref);
256			};
257			$(el).attr('href',"javascript:load_page('"+elhref+"','"+nodeId+"')");
258		});
259	})
260	.fail(function() {
261		console.log("error");
262	})
263	.always(function() {
264		console.log("complete");
265	});
266} 
267
268
269/**
270 * @brief 创建表单验证
271 * 注意引用  jquery.validate.js 和 jquery.validate.lang.cn.js
272 * @param frm  表单 Id
273 * @param rules 验证规则
274 */
275function make_validate(frm,rules,messages,inline){
276	if (inline == 0) {
277		inline = "block";
278	}else{
279		inline = "inline";
280	}
281	$('#'+frm).validate({
282		ignore: ".ignore", // 忽略
283		rules:rules,
284		onchange: true, 
285		onblur: true,
286		messages:messages,
287		errorClass: "help-"+inline+" validate",
288		errorElement: "span",
289		highlight:function(element, errorClass, validClass) {
290			$(element).parents('.control-group').removeClass('success').addClass('error');
291			$(element).removeClass('success').addClass('error');
292			$(element).nextAll('span.validate').remove();
293		},
294		unhighlight: function(element, errorClass, validClass) {
295			$(element).parents('.control-group').removeClass('error').addClass('success');
296			$(element).removeClass('error').addClass('success');
297			$(element).nextAll('span.validate').remove();
298		},
299		errorPlacement: function(error, element) {
300			if (inline == "block") {
301				error.appendTo(element.parents(".control-group"));
302			}else{
303				element.after(error);
304			}
305		}
306	});
307}
308
309/**
310 * @brief 创建表单验证
311 	      带有返回函数, 可以验证后直接用ajax处理
312 * 注意引用  jquery.validate.js 和 jquery.validate.lang.cn.js
313 * @param frm  表单 Id
314 * @param rules 验证规则
315 */
316function make_validate_submit(frm,rules,messages,submit_fun,inline){
317	if (inline == 0) {
318		inline = "block";
319	}else{
320		inline = "inline";
321	}
322	$('#'+frm).validate({
323		ignore: ".ignore", // 忽略
324		rules:rules,
325		onchange: true, 
326		onblur: true,
327		messages:messages,
328		errorClass: "help-inline validate",
329		errorElement: "span",
330		highlight:function(element, errorClass, validClass) {
331			$(element).parents('.control-group').removeClass('success').addClass('error');
332			$(element).removeClass('success').addClass('error');
333			$(element).nextAll('span.validate').remove();
334		},
335		unhighlight: function(element, errorClass, validClass) {
336			$(element).parents('.control-group').removeClass('error').addClass('success');
337			$(element).removeClass('error').addClass('success');
338			$(element).nextAll('span.validate').remove();
339		},
340		errorPlacement: function(error, element) {
341			if (inline == "block") {
342				error.appendTo(element.parents(".control-group"));
343			}else{
344				element.after(error);
345			}
346		},
347		submitHandler:function(form){
348			submit_fun(form);
349		}
350	});
351}
352
353// 判定空
354// String.prototype.isEmpty = function(){
355//     var r = /^\s*$/;
356//     return r.test(this);
357// };
358
359// Array.prototype.isEmpty = function(){
360// 	return !this.length;
361// };
362
363// Object.prototype.isEmpty = function(){
364// 	return this === {};
365// };

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.