PageSourceSearch

https://www.infogreen.lu/squelettes/js/jQWCloudv3.4.1.js?1682514799

js infogreen.lu collected 2026-10-02 16:23:59 UTC 15,036 bytes, 520 lines download raw bytes

1var LB=1,  //Left Bottom
2	LT=2,  //Left Top
3	RT=3,  //Right Top
4	RB=4,  //Right Bottom
5	HR=1, 	//Horizontal		
6	VR=2,    //Vertical
7	WordObjType='span',
8	DIV='div',
9	Word_Default_font_Family='Impact',
10	distance_Counter=1,
11	word_counter=1;
12
13function Util(){}
14//To Generate Random Colors For Words
15Util.getRandomColor = function(){
16	var letters = '0123456789ABCDEF'.split('');
17    var color = '#';
18    for (var i = 0; i < 6; i++ ) {
19        color += letters[Math.round(Math.random() * 15)];
20    }
21    return color;
22};
23
24function space(spaceType,width,height,x,y){
25	this.spaceType=spaceType;
26	this.width=width;
27	this.height=height;
28	this.x=x;
29	this.y=y;
30}
31
32function Word(wordConfig){
33	this.word=wordConfig.word;
34	this.weight=wordConfig.weight;
35	
36	this.fontFactor=wordConfig.fontFactor;
37	this.fontOffset=wordConfig.fontOffset;
38	this.minWeight=wordConfig.minWeight;
39	this.padding_left=wordConfig.padding_left;
40	
41	this.font_family=wordConfig.font_family;
42	this.font=null;
43	this.color=wordConfig.color;
44	this.span=null;
45	this.width=null;
46    this.height=null;
47    this.word_class=wordConfig.word_class;
48    
49    this._init();
50}
51Word.prototype = {
52	_init: function(){
53		this._setFont();
54		this._setSpan_Size();
55	},
56	_setFont: function(){
57		this.font=Math.floor(((this.weight-this.minWeight) *this.fontFactor ) + this.fontOffset);
58	},
59	_setSpan_Size: function(){
60		var span = document.createElement(WordObjType);
61		span.setAttribute('id', "Word_"+(word_counter++)+"_"+this.weight);
62		document.body.appendChild(span);
63		$(span).css({
64			   position: 'absolute',
65			   display: 'block',
66			   left: -999990,
67			   top: 0
68		});
69		$(span).css("font-size",this.font+"px");
70		
71		if(this.font_family!=null && this.font_family!='')
72			$(span).css("font-family",this.font_family);
73		else
74			$(span).css("font-family",Word_Default_font_Family);
75		
76		
77		if(this.word_class!=null && this.word_class!='')
78			$(span).addClass(this.word_class);
79		
80		if(this.color!=null && this.color!='')
81			$(span).css("color",this.color);
82		else
83			$(span).css("color",Util.getRandomColor());
84		
85		$(span).css("-webkit-user-select","none").css("-moz-user-select","none").css("-ms-user-select","none");
86		$(span).css("user-select","none").css("-o-user-select","none");
87		$(span).css("line-height",this.font+"px");
88		if(this.padding_left==null)
89			this.padding_left=0;
90			
91		$(span).css("padding-left",this.padding_left+"px");
92		$(span).html(this.word);
93		
94		this.width=$(span).outerWidth()+(this.padding_left*2);
95	    this.height=$(span).outerHeight();
96	    
97	    $(span).remove();
98	    this.span=span;	
99}	
100};
101
102
103function WordCloud() {
104	this.defaultOptions={
105			title: 'JQ WOrd Cloud',
106			words: [],
107			minFont: 10,
108			maxFont: 50,
109			fontOffset: 0,
110			showSpaceDIV: false,
111			verticalEnabled: true,
112			cloud_color: null,
113			cloud_font_family: null,
114			spaceDIVColor: 'white',
115			padding_left: null,
116			word_common_classes: null,
117			word_click : function(){},
118			word_mouseOver : function(){},
119			word_mouseEnter : function(){},
120			word_mouseOut : function(){},
121			beforeCloudRender: function(){},
122			afterCloudRender: function(){}
123	};
124	this.minWeight=null;
125	this.maxWeight=null;			
126	
127	this.spaceDataObject=null;
128	this.spaceIdArray=null;			
129	this.words=null;
130	this.fontFactor=1,
131	
132	this.methods = {
133		    destroy : this._destroy
134	};
135	
136};
137
138WordCloud.prototype = {
139		_init: function(options){
140	
141			//Calling Methods from this.Methods{}
142			if(options !=null && typeof options === 'string')
143				if(this.methods[options]!=null) 
144					return this.methods[options].apply();
145				else
146					return null;
147	
148			if(options==null)
149				this.options=this.defaultOptions;
150			else if(options !=null && typeof options === 'object') 
151				this.options=$.extend(this.defaultOptions,options);
152			
153			this.spaceDataObject={};
154			this.spaceIdArray=[];
155			
156			this.words=this.options.words;
157			//Sorting Words according weight descending order
158			this.words.sort(function(a, b) { if (a.weight < b.weight) {return 1;} else if (a.weight > b.weight) {return -1;} else {return 0;} });
159			
160			this.options.beforeCloudRender();
161			this._start();
162			this.options.afterCloudRender();
163			this._final();
164		},
165		_setFontFactor: function(){
166			this.maxWeight=this.words[0].weight;
167			this.minWeight=this.words[this.words.length-1].weight;						
168			this.fontFactor=(this.options.maxFont-this.options.minFont)/(this.maxWeight-this.minWeight);
169		},
170		_start: function(){
171				this._destroy();
172				this._setFontFactor();
173				this._draw();			
174		},
175		_final: function() {
176		},
177		_destroy: function(){
178			this.$target.html('');
179		},
180		_setTarget: function($target){
181			this.$target=$target;
182			$target.css("position","relative");
183			this.tWidth=$target.innerWidth();
184			this.xOffset=this.tWidth/2;
185			
186			this.tHeight=$target.innerHeight();				
187			this.yOffset=this.tHeight/2;			
188		},
189		_draw: function() {
190			
191			for(var index=0; index<this.words.length; index++){
192				var currWord=this.words[index];				
193				var wordConfigObj={};
194				wordConfigObj['word']=currWord.word;
195				wordConfigObj['weight']=currWord.weight;
196				
197				if(this.options.cloud_color!=null)
198					wordConfigObj['color']=this.options.cloud_color;
199				else
200					wordConfigObj['color']=currWord.color;
201				
202				if(this.options.padding_left!=null)
203					wordConfigObj['padding_left']=this.options.padding_left;
204				
205				wordConfigObj['word_class']=currWord.word_class;
206				
207				if(this.options.cloud_font_family!=null)
208					wordConfigObj['font_family']=this.options.cloud_font_family;
209				else	
210					wordConfigObj['font_family']=currWord.font_family;
211				
212				wordConfigObj['fontFactor']=this.fontFactor;
213				wordConfigObj['fontOffset']=(this.options.fontOffset + this.options.minFont);
214				wordConfigObj['minWeight']=this.minWeight;
215				
216				
217				var wordObj=new Word(wordConfigObj);
218				
219				if(this.options.word_common_classes!=null)
220					$(wordObj.span).addClass(this.options.word_common_classes);
221				
222				$(wordObj.span).on("click",this.options.word_click);
223				$(wordObj.span).on("mouseover",this.options.word_mouseOver);
224				$(wordObj.span).on("mouseout",this.options.word_mouseOut);
225				$(wordObj.span).on("mouseenter",this.options.word_mouseEnter);
226				
227				if(index==0)
228					this._placeFirstWord(wordObj);
229				else	
230					this._placeOtherWord(wordObj);		
231			}
232		},
233		
234		_updateSpaceIdArray: function(distanceS, distance) {
235			if(this.spaceIdArray.length!=0){
236				for(var index=0;index<this.spaceIdArray.length;index++){
237					if(distance<parseFloat(this.spaceIdArray[index].split("_")[0])){
238						this.spaceIdArray.splice(index,0,distanceS);
239						return;
240					}
241				}
242				this.spaceIdArray.push(distanceS);
243			}
244			else
245				this.spaceIdArray.push(distanceS);
246		
247		},
248		_showSpaceDiv: function(type, w, h, x, y) {
249			var xMul=1; 
250			var yMul=1;
251			
252			switch(type)
253				{
254				case LB:
255					xMul=0;
256					yMul=-1;
257					break;
258				case LT:
259					xMul=0;
260					yMul=0;
261					break;
262				case RT:
263					xMul=-1;
264					yMul=0;
265					break;
266				case RB:
267					xMul=-1;
268					yMul=-1;
269					break;
270				}
271			
272			var div=document.createElement(DIV);
273			$(div).css("left",x+xMul*w).css("top",y+yMul*h).css("width",w).css("height",h).css("border","1px "+this.options.spaceDIVColor+" solid").css("position","absolute").css("display","block");
274			this.$target.append(div);
275		},	
276		_pushSpaceData: function(type, w, h, x, y) {
277				//Calculating Distance between (x,y): Key point of Space and and Center of Container (this.xOffset,this.yOffset) 
278				var distance=Math.sqrt((this.xOffset-x)*(this.xOffset-x) + (this.yOffset-y)*(this.yOffset-y));
279				var distanceS=distance+'_'+ (distance_Counter++);
280				
281				//Update Space Id Array
282				this._updateSpaceIdArray(distanceS, distance);
283				//Add Space into Space Data Object
284				this.spaceDataObject[distanceS]=new space(type, w, h, x, y);
285				
286				// To Show The Space
287				if(this.options.showSpaceDIV){
288					this._showSpaceDiv(type, w, h, x, y);
289					
290				}
291				
292			},
293		_placeFirstWord: function(word) {	
294				
295				var w=word.width;
296				var h=word.height;
297				var xoff=this.xOffset-w/2;
298				var yoff=this.yOffset-h/2;
299				var tw=this.tWidth;
300				var th=this.tHeight;
301				
302				var span=word.span;
303				$(span).css("left",xoff).css("top",yoff).css("display","inline");
304				this.$target.append(span);
305				
306				this._pushSpaceData(LB, tw-xoff-w, h, xoff+w, yoff+h/2);   //M1
307				this._pushSpaceData(LT, w, th-yoff-h, xoff+w/2, yoff+h); //M2				
308				this._pushSpaceData(RT, xoff, h, xoff, yoff+h/2); //M3				
309				this._pushSpaceData(RB, w, yoff, xoff+w/2, yoff);  //M4
310				
311				this._pushSpaceData(LT, w/2, h/2, xoff+w, yoff+h/2);   //C1
312				this._pushSpaceData(RT, w/2, h/2, xoff+w/2, yoff+h); //C2				
313				this._pushSpaceData(RB, w/2, h/2, xoff, yoff+h/2); //C3				
314				this._pushSpaceData(LB, w/2, h/2, xoff+w/2, yoff);  //C4
315				
316				this._pushSpaceData(LT, tw-xoff-w-w/2, th-yoff-h/2, xoff+w+w/2, yoff+h/2);   //S1
317				this._pushSpaceData(RT, xoff+w/2, th-yoff-h-h/2, xoff+w/2, yoff+h+h/2); //S2				
318				this._pushSpaceData(RB, xoff-w/2, yoff+h/2, xoff-w/2, yoff+h/2); //S3				
319				this._pushSpaceData(LB, xoff+w/2, yoff-h/2, xoff+w/2, yoff-h/2);  //S4
320				
321				
322				
323				
324			},
325		
326		 _placeOtherWord: function(word) {	
327					
328				for(var index=0;
328index<this.spaceIdArray.length;index++){
329					var spaceId=this.spaceIdArray[index];
330					var obj=this.spaceDataObject[spaceId];
331					
332					var alignmentInd=0;
333					var alignmentIndCount=0;
334					
335					
336					if(word.width<=obj.width && word.height<=obj.height){
337						alignmentInd=HR;
338						alignmentIndCount++;
339					}	
340					
341					if(this.options.verticalEnabled){
342						if(word.height<=obj.width && word.width<=obj.height){
343							alignmentInd=VR;
344							alignmentIndCount++;
345						}
346					}
347					if(alignmentIndCount>0){
348						
349						this.spaceDataObject[spaceId]=null;
350						this.spaceIdArray.splice(index,1);
351						
352						
353						//For Word's Span Position
354						var xMul=1;
355						var yMul=1;
356						
357						//For new Child Spaces
358						var xMulS=1;
359						var yMulS=1;
360						
361						switch(obj.spaceType)
362							{
363							case LB:
364								xMul=0;
365								yMul=-1;
366								xMulS=1;
367								yMulS=-1;
368								break;
369							case LT:
370								xMul=0;
371								yMul=0;
372								xMulS=1;
373								yMulS=1;
374								break;
375							case RT:
376								xMul=-1;
377								yMul=0;
378								xMulS=-1;
379								yMulS=1;
380								break;
381							case RB:
382								xMul=-1;
383								yMul=-1;
384								xMulS=-1;
385								yMulS=-1;
386								break;
387							}
388						
389						if(alignmentIndCount>1){
390							
391							//Making Horizontal Word in Larger Number
392							// Random number[0,5] is >0 and <3 --> HR
393							// Random number[0,5] is >3 --> VR
394							
395							 if(Math.random()*5>3)
396								 alignmentInd=VR;
397							 else	 
398								 alignmentInd=HR;
399						}
400						
401						var w=word.width;
402						var h=word.height;
403						
404						switch(alignmentInd)
405						{
406						case HR:
407									var span=word.span;
408									$(span).css("left",obj.x + xMul*w).css("top", obj.y + yMul*h).css("display","inline");
409									this.$target.append(span);
410									
411								    if(Math.random()*2>1){
412								    	
413								    	/*
414								    	 * 			_________________________________
415								    	 *			|								|
416								    	 *			|				T				|
417								    	 *			|								|
418								    	 *			|_______________________________|
419								    	 *			|				|				|								
420								    	 *			|	  WORD		|		R		|
421								    	 *			|	********	|				|
422								    	 *			|_______________|_______________|
423								    	 * 
424								    	 */
425								    	
426								    	this._pushSpaceData(obj.spaceType, obj.width-w, h, obj.x+xMulS*w, obj.y);  //R
427								    	this._pushSpaceData(obj.spaceType, obj.width, obj.height-h, obj.x, obj.y+yMulS*h);  //T
428								    	
429								    }else{
430								    	
431								    	/*
432								    	 * 			_________________________________
433								    	 *			|				|				|
434								    	 *			|		T		|				|
435								    	 *			|				|				|
436								    	 *			|_______________|		R		|
437								    	 *			|				|				|								
438								    	 *			|	  WORD		|				|
439								    	 *			|	********	|				|
440								    	 *			|_______________|_______________|
441								    	 * 
442								    	 */
443								    	
444								    	this._pushSpaceData(obj.spaceType, obj.width-w, obj.height, obj.x+xMulS*w, obj.y);  //R
445								    	this._pushSpaceData(obj.spaceType, w, obj.height-h, obj.x, obj.y+yMulS*h); 		//T
446								    }	
447							break;
448							
449						case VR:
450									var span=word.span;
451									//IE Handling for Differenet way of Rotation Transforms 
452									if(jQuery.browser && jQuery.browser.msie){
453										$(span).css("left",obj.x + xMul*h).css("top", obj.y + yMul*w);
454									}else{
455										$(span).css("left",obj.x + xMul*h - (w-h)/2).css("top", obj.y + yMul*w + (w-h)/2);							
456									}	
457									
458									$(span).css("display","block").css("-webkit-transform","rotate(270deg)").css("-moz-transform","rotate(270deg)");
459									$(span).css("-o-transform","rotate(270deg)").css("filter","progid:DXImageTransform.Microsoft.BasicImage(rotation=3)");
460									this.$target.append(span);
461									
462								    if(Math.random()*2>1){
463								    	
464								    	/*
465								    	 * 			_________________________________
466								    	 *			|								|
467								    	 *			|				T				|
468								    	 *			|								|
469								    	 *			|_______________________________|
470								    	 *			|		D		|				|								
471								    	 *			|		R		|		R		|
472								    	 *			|		O		|				|
473								    	 *			|_______W_______|_______________|
474								    	 * 
475								    	 */
476								    	
477								    	this._pushSpaceData(obj.spaceType, obj.width-h, w, obj.x+xMulS*h, obj.y);  //R
478								    	this._pushSpaceData(obj.spaceType, obj.width, obj.height-w, obj.x, obj.y+yMulS*w);  //T
479								    }else{
480								    	
481								    	/*
482								    	 * 			_________________________________
483								    	 *			|				|				|
484								    	 *			|		T		|				|
485								    	 *			|				|				|
486								    	 *			|_______________|		R		|
487								    	 *			|		D		|				|								
488								    	 *			|	  	R		|				|
489								    	 *			|		O		|				|
490								    	 *			|_______W_______|_______________|
491								    	 * 
492								    	 */
493								    	
494								    	this._pushSpaceData(obj.spaceType, obj.width-h, obj.height, obj.x+xMulS*h, obj.y);  //R
495								    	this._pushSpaceData(obj.spaceType, h, obj.height-w, obj.x, obj.y+yMulS*w); 		//T
496								    }
497							break;
498						
499						}
500						
501						return;
502					}
503				}
504				
505			}
506			
507	};
508
509(function( $ ){
510	  $.fn.jQWCloud = function(options) {
511			  var wc=new WordCloud();
512			  wc._setTarget($(this));
513			  wc._init(options);
514	  };
515})( jQuery );
516
517
518
519
520

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.