PageSourceSearch

https://jenniferbecker-photography.de/files/SBCommonFiles/updateHeadLinks.js

js jenniferbecker-photography.de collected 2026-10-07 06:16:46 UTC 3,581 bytes, 113 lines download raw bytes

1/*****************************************************************************************
2*		SeaBreeze.SBHeadUpdaterScripts
3******************************************************************************************
4SBHeadUpdaterScripts contains the Javascript part of the Head-Updater functionality. It keeps the head-element in sync with what the server expects, during ajax calls. If an element is added that has new required-libraries, these are then automatically loaded and also removed.
5*****************************************************************************************/
6
7jQuery(function($){
8//  --------------------------------------------------------------------------------------
9function main()
10	{
11	window.sbUpdateHeadURLs = sbUpdateHeadURLs;
12	}
13
14
15//  --------------------------------------------------------------------------------------
16function appendHeadElementsWithURLs(urlArray)
17	{
18	urlArray.each(function(index, url)
19		{
20		appendHeadElementWithURL(url);
21		});
22	}
23
24
25//  --------------------------------------------------------------------------------------
26function differenceBetween(sourceA, sourceB)
27	{
28	// Computes the difference of two quantities, which means all elements of sourceA without the elements of sourceB
29	//
30	return jQuery(sourceA).filter(function(index, elementA)
31		{
32		return jQuery.inArray(elementA, sourceB) < 0;
33		});
34	}
35
36
37//  --------------------------------------------------------------------------------------
38function appendCSSElementWithURL(url)
39	{
40	/* Now using plain javascript. Several forum entries on the web said that
41 	    using jQuery to create elements does not update DOM properly */
42
43	var head = document.head || (document.getElementsByTagName("HEAD")[0]) ;
44	var link = document.createElement('link');
45
46	link.type = 'text/css';
47	link.rel = 'stylesheet';
48	link.href = url;
49
50	document.head.appendChild(link);
51
52	}
53
54
55//  --------------------------------------------------------------------------------------
56function appendHeadElementWithURL(url)
57	{
58	if (url.match("js$"))
59		appendJavascriptElementWithURL(url);
60
61	if (url.match("css$"))
62		appendCSSElementWithURL(url);
63	}
64
65
66//  --------------------------------------------------------------------------------------
67function sbUpdateHeadURLs(removedURLs, addedURLs)
68	{
69	var	head			= jQuery("head");
70	var	links			= head.children("link");
71	var	linkURLs		= attrForAll(links, "href");
72	var	scripts			= head.children("script");
73	var	scriptURLs		= attrForAll(scripts, "src");
74	var	headURLs		= linkURLs.add(scriptURLs);
75	var	missingURLs	= differenceBetween(addedURLs, headURLs);
76
77	appendHeadElementsWithURLs(missingURLs);
78	}
79
80
81//  --------------------------------------------------------------------------------------
82function attrForAll(jqArray, attributeName)
83	{
84	// computes the given <attibuteName> for all elements of the jQuery array
85	//
86	return jqArray.map(function(index, element)
87		{
88		return jQuery(element).attr(attributeName);
89		});
90	}
91
92
93//  --------------------------------------------------------------------------------------
94function appendJavascriptElementWithURL(url)
95{
96	var	script = jQuery("<script type='text/javascript'></script>");
97
98	// if there's a syntax-error in the javascript file, this method will crash and be catched in sbKeepFocus, 
99	// which is super hard to debug and has nothing to do with our code to add the javascript file.
100	// thus here's another try/catch and a useful error message is added
101	try {
102		script.attr("src", url);
103		script.appendTo("head");
104	}
105	catch (error) {
106		console.log("error in javascript file: ", url);
107	}
108}
109
110
111
112	main()
113});

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.