PageSourceSearch

https://forum.blu-ray.com/clientscript/ncode_imageresizer.js?v=1.0.1

js blu-ray.com collected 2026-10-09 16:46:30 UTC 6,542 bytes, 208 lines download raw bytes

1// nCode Image Resizer for vBulletin 3.6.0
2// http://www.ncode.nl/vbulletinplugins/
3// Version: 1.0.1
4//
5// (c) 2007 nCode
6
7
8NcodeImageResizer.IMAGE_ID_BASE = 'ncode_imageresizer_container_';
9NcodeImageResizer.WARNING_ID_BASE = 'ncode_imageresizer_warning_';
10NcodeImageResizer.scheduledResizes = [];
11
12function NcodeImageResizer(id, img) {
13	this.id = id;
14	this.img = img;
15	this.originalWidth = 0;
16	this.originalHeight = 0;
17	this.warning = null;
18	this.warningTextNode = null;
19	this.originalWidth = img.originalWidth;
20	this.originalHeight = img.originalHeight;
21	
22	img.id = NcodeImageResizer.IMAGE_ID_BASE+id;
23}
24
25NcodeImageResizer.executeOnload = function() {
26	var rss = NcodeImageResizer.scheduledResizes;
27	for(var i = 0; i  < rss.length; i++) {
28		NcodeImageResizer.createOn(rss[i], true);
29	}
30}
31
32NcodeImageResizer.schedule = function(img) {
33	if(NcodeImageResizer.scheduledResizes.length == 0) {
34		if(window.addEventListener) {
35			window.addEventListener('load', NcodeImageResizer.executeOnload, false);
36		} else if(window.attachEvent) {
37			window.attachEvent('onload', NcodeImageResizer.executeOnload);
38		}
39	}
40	NcodeImageResizer.scheduledResizes.push(img);
41}
42
43NcodeImageResizer.getNextId = function() {
44	var id = 1;
45	while(document.getElementById(NcodeImageResizer.IMAGE_ID_BASE+id) != null) {
46		id++;
47	}
48	return id;
49}
50
51NcodeImageResizer.createOnId = function(id) {
52	return NcodeImageResizer.createOn(document.getElementById(id));
53}
54
55NcodeImageResizer.createOn = function(img, isSchedule) {
56	if(typeof isSchedule == 'undefined') isSchedule = false;
57	
58	if(!img || !img.tagName || img.tagName.toLowerCase() != 'img') {
59		alert(img+' is not an image ('+img.tagName.toLowerCase()+')');
60	}
61	
62	if(img.width == 0 || img.height == 0) {
63		if(!isSchedule)
64			NcodeImageResizer.schedule(img);
65		return;
66	}
67	
68	if(!img.originalWidth) img.originalWidth = img.width;
69	if(!img.originalHeight) img.originalHeight = img.height;
70	
71	if((NcodeImageResizer.MAXWIDTH > 0 && img.originalWidth > NcodeImageResizer.MAXWIDTH) || (NcodeImageResizer.MAXHEIGHT > 0 && img.originalHeight > NcodeImageResizer.MAXHEIGHT)) {
72		var isRecovery = false; // if this is a recovery from QuickEdit, which only restores the HTML, not the OO structure
73		var newid, resizer;
74		if(img.id && img.id.indexOf(NcodeImageResizer.IMAGE_ID_BASE) == 0) {
75			newid = img.id.substr(NcodeImageResizer.IMAGE_ID_BASE.length);
76			if(document.getElementById(NcodeImageResizer.WARNING_ID_BASE+newid) != null) {
77				resizer = new NcodeImageResizer(newid, img);
78				isRecovery = true;
79				resizer.restoreImage();
80			}
81		} else {
82			newid = NcodeImageResizer.getNextId();
83			resizer = new NcodeImageResizer(newid, img);
84		}
85		
86		if(isRecovery) {
87			resizer.reclaimWarning(newid);
88		} else {
89			resizer.createWarning();
90		}
91		resizer.scale();
92	}
93}
94
95NcodeImageResizer.prototype.restoreImage = function() {
96	newimg = document.createElement('IMG');
97	newimg.src = this.img.src;
98	this.img.width = newimg.width;
99	this.img.height = newimg.height;
100}
101
102NcodeImageResizer.prototype.reclaimWarning = function(id) {
103	this.warning = document.getElementById(NcodeImageResizer.WARNING_ID_BASE+id);
104	this.warningTextNode = this.warning.firstChild.firstChild.childNodes[1].firstChild;
105	this.warning.resize = this;
106	
107	this.scale();
108}
109
110NcodeImageResizer.prototype.createWarning = function() {
111	var mtable = document.createElement('TABLE');
112	var mtbody = document.createElement('TBODY');
113	var mtr = document.createElement('TR');
114	var mtd1 = document.createElement('TD');
115	var mtd2 = document.createElement('TD');
116	var mimg = document.createElement('IMG');
117	var mtext = document.createTextNode('');
118	
119	mimg.src = NcodeImageResizer.BBURL+'/images/statusicon/wol_error.gif';
120	mimg.width = 16;
121	mimg.height = 16;
122	mimg.alt = '';
123	mimg.border = 0;
124	
125	mtd1.width = 20;
126	mtd1.className = 'td1';
127	
128	mtd2.unselectable = 'on';
129	mtd2.className = 'td2';
130	
131	mtable.className = 'ncode_imageresizer_warning';
132	mtable.textNode = mtext;
133	mtable.resize = this;
134	mtable.id = NcodeImageResizer.WARNING_ID_BASE+this.id;
135	
136	mtd1.appendChild(mimg);
137	mtd2.appendChild(mtext);
138	
139	mtr.appendChild(mtd1);
140	mtr.appendChild(mtd2);
141	
142	mtbody.appendChild(mtr);
143	
144	mtable.appendChild(mtbody);
145	
146	this.img.parentNode.insertBefore(mtable, this.img);
147	
148	this.warning = mtable;
149	this.warningTextNode = mtext;
150}
151
152NcodeImageResizer.prototype.setText = function(text) {
153	var newnode = document.createTextNode(text);
154	this.warningTextNode.parentNode.replaceChild(newnode, this.warningTextNode);
155	this.warningTextNode = newnode;
156}
157
158NcodeImageResizer.prototype.scale = function() {
159	this.img.height = this.originalHeight;
160	this.img.width = this.originalWidth;
161	
162	if(NcodeImageResizer.MAXWIDTH > 0 && this.img.width > NcodeImageResizer.MAXWIDTH) {
163		this.img.height = (NcodeImageResizer.MAXWIDTH / this.img.width) * this.img.height;
164		this.img.width = NcodeImageResizer.MAXWIDTH;
165	}
166	
167	if(NcodeImageResizer.MAXHEIGHT > 0 && this.img.height > NcodeImageResizer.MAXHEIGHT) {
168		this.img.width = (NcodeImageResizer.MAXHEIGHT / this.img.height) * this.img.width;
169		this.img.height = NcodeImageResizer.MAXHEIGHT;
170	}
171	
172	this.warning.width = this.img.width;
173	this.warning.onclick = function() { return this.resize.unScale(); }
174	
175	if(this.img.width < 450) {
176		this.setText(vbphrase['ncode_imageresizer_warning_small']);
177	} else if(this.img.fileSize && this.img.fileSize > 0) {
178		this.setText(vbphrase['ncode_imageresizer_warning_filesize'].replace('%1$s', this.originalWidth).replace('%2$s', this.originalHeight).replace('%3$s', Math.round(this.img.fileSize/1024)));
179	} else {
180		this.setText(vbphrase['ncode_imageresizer_warning_no_filesize'].replace('%1$s', this.originalWidth).replace('%2$s', this.originalHeight));
181	}
182	
183	return false;
184}
185
186NcodeImageResizer.prototype.unScale = function() {
187	switch(NcodeImageResizer.MODE) {
188		case 'samewindow':
189			window.open(this.img.src, '_self');
190			break;
191		case 'newwindow':
192			window.open(this.img.src, '_blank');
193			break;
194		case 'enlarge':
195		default:
196			this.img.width = this.originalWidth;
197			this.img.height = this.originalHeight;
198			this.img.className = 'ncode_imageresizer_original';
199			if(this.warning != null) {
200				this.setText(vbphrase['ncode_imageresizer_warning_fullsize']);
201				this.warning.width = this.img.width;
202				this.warning.onclick = function() { return this.resize.scale() };
203			}
204			break;
205	}
206	
207	return false;
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.