mirror of
				https://github.com/kevinveenbirkenbach/computer-playbook.git
				synced 2025-10-31 02:10:05 +00:00 
			
		
		
		
	Huge role refactoring/cleanup. Other commits will propably follow. Because some bugs will exist. Still important for longrun and also for auto docs/help/slideshow generation
This commit is contained in:
		
							
								
								
									
										1
									
								
								roles/webserver-injector-iframe/templates/head_sub.j2
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								roles/webserver-injector-iframe/templates/head_sub.j2
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| <script>{{ iframe_code_one_liner | replace("'", "\\'") }}</script> | ||||
| @@ -0,0 +1,46 @@ | ||||
| (function() { | ||||
|   var primary = "{{ primary_domain }}"; | ||||
|   var allowedOrigin = "https://{{ domains | get_domain('portfolio') }}"; | ||||
|  | ||||
|   function notifyParent() { | ||||
|     try { | ||||
|       window.parent.postMessage({ | ||||
|         type: "iframeLocationChange", | ||||
|         href: window.location.href | ||||
|       }, allowedOrigin); | ||||
|     } catch (e) {} | ||||
|   } | ||||
|  | ||||
|   function forceExternalLinks() { | ||||
|     Array.prototype.forEach.call(document.querySelectorAll("a[href]"), function(a) { | ||||
|       try { | ||||
|         var url = new URL(a.href, location); | ||||
|         if (!url.hostname.endsWith(primary)) { | ||||
|           a.target = "_blank"; | ||||
|           a.rel = "noopener"; | ||||
|         } | ||||
|       } catch (e) {} | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   window.addEventListener("load", function() { | ||||
|     notifyParent(); | ||||
|     forceExternalLinks(); | ||||
|   }); | ||||
|   window.addEventListener("popstate", function() { | ||||
|     notifyParent(); | ||||
|     forceExternalLinks(); | ||||
|   }); | ||||
|  | ||||
|   // SPA support | ||||
|   var _pushState = history.pushState; | ||||
|   history.pushState = function() { | ||||
|     _pushState.apply(history, arguments); | ||||
|     notifyParent(); | ||||
|     forceExternalLinks(); | ||||
|   }; | ||||
| })(); | ||||
|  | ||||
| {% if enable_debug | bool %} | ||||
| console.log("[iframe-sync] Sender for iframe messages is active."); | ||||
| {% endif %} | ||||
		Reference in New Issue
	
	Block a user