Apríl 2021: random otočení webu + context processor
V testu to je, tenhle commit není pro merge zajímavý. P.
This commit is contained in:
		
							parent
							
								
									fc7255c6f3
								
							
						
					
					
						commit
						2ed70b3673
					
				
					 3 changed files with 59 additions and 0 deletions
				
			
		|  | @ -10,3 +10,18 @@ def vzhled(request): | |||
|         noc = False | ||||
|     return {'noc' : noc} | ||||
| 
 | ||||
| def april(req): | ||||
|     if 'X-April' in req.headers: | ||||
|         try: | ||||
|             year = int(req.headers['X-April']) | ||||
|             return {'april': year} | ||||
|         except: | ||||
|             pass # Fall-back to regular behaviour | ||||
| 
 | ||||
|     import datetime | ||||
|     today = datetime.date.today() | ||||
|     if today.day == 1 and today.month == 4: | ||||
|         return {'april': today.year} | ||||
|     return {} | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -76,6 +76,7 @@ TEMPLATES = [ | |||
|                 'django.contrib.messages.context_processors.messages', | ||||
|                 'sekizai.context_processors.sekizai', | ||||
|                 'mamweb.context_processors.vzhled', | ||||
|                 'mamweb.context_processors.april', | ||||
|             ) | ||||
|         }, | ||||
|     }, | ||||
|  |  | |||
|  | @ -125,6 +125,49 @@ | |||
| 	   $("a[rel^='gallery-image']").prettyPhoto(prettyparams); | ||||
| 	}); | ||||
|     </script> | ||||
|     {% if april == 2021 %} | ||||
|     <script type="text/javascript" charset="utf-8"> | ||||
|     function rotace(vektor, uhel_deg) { | ||||
|             var uhel = uhel_deg *(Math.PI / 180); | ||||
|             var x = vektor[0]; | ||||
|             var y = vektor[1]; | ||||
|             return [x*Math.cos(uhel) - y*Math.sin(uhel), x*Math.sin(uhel) + y*Math.cos(uhel)]; | ||||
|     } | ||||
| 
 | ||||
|     function rotace_a_posun(obj, uhel) { | ||||
|             var ow = obj.width(); | ||||
|             var oh = obj.height(); | ||||
| 
 | ||||
|             var rohy = [[0,0], [0,oh], [ow, 0], [ow, oh]]; | ||||
|             var minx = 0; | ||||
|             var miny = 0; | ||||
|             for (var roh of rohy) { | ||||
|                     var otoceny = rotace(roh, uhel); | ||||
|                     if (otoceny[0] < minx) { | ||||
|                             minx = otoceny[0]; | ||||
|                     } | ||||
|                     if (otoceny[1] < miny) { | ||||
|                             miny = otoceny[1]; | ||||
|                     } | ||||
|             } | ||||
| 
 | ||||
|             miny *= -1; | ||||
|             minx *= -1; | ||||
| 
 | ||||
|             var transf_str = "translateX("+minx+"px) translateY("+miny+"px) rotate("+uhel+"deg)"; | ||||
|             obj.css('transform-origin', 'top left'); | ||||
|             obj.css('transform', transf_str); | ||||
|     } | ||||
| 
 | ||||
|     function randomUhel() { | ||||
|             return Math.floor(360*Math.random()); | ||||
|     } | ||||
| 
 | ||||
|     $('.container').css('margin', 0); | ||||
|     rotace_a_posun($('.container'), randomUhel()); | ||||
|     </script> | ||||
|     {% endif %} | ||||
| 
 | ||||
|     {% render_block "js" %} | ||||
|   </body> | ||||
| </html> | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 MaM Web user
						MaM Web user