Exemplo n.º 1
0
		public void MoveScript(ScriptLoadGroup to, ScriptLoadItem script)
		{
			Scripts.Remove(script);
			to.AddScript(script);
		}
Exemplo n.º 2
0
		public HashSet<ScriptLoadGroup> MapScripts(HashSet<ScriptResource> pageScripts)
		{
			// TODO: A setup like this:
			// jquery -> site -> loggedin -> shipmenttotals -> dash
			// jquery -> site -> rsswidget
			// Causes this to lose scripts - shipmenttotals and dash are thrown out

			// TODO: A setup like this:
			// jquery -> site -> loggedin -> shipmenttotals -> dash
			// jquery, excanvas -> flot -> dash
			// Causes an infinite loop - presumably from jquery being too deep to properly merge


			// Just stupidly map it all out every time - in the future we should
			// use caching and better data structures to make this smart

			// The global list of ScriptResource objects declared in Global.asax
			Dictionary<string, ScriptResource> appScripts = AppScripts.Current.List;

			foreach (ScriptResource resource in pageScripts)
			{
				if (ProcessedScripts.ContainsKey(resource))
				{
					// This script has already been put into a group, so we
					// can just skip it.
					continue;
				}

				ScriptLoadItem script = processScript(resource);

				if (script.Script.ParentScripts.Length == 0)
				{
					simpleScriptGroup.AddScript(script);
				}
				else
				{
					// Look for its dependency already added
					// If it's not there, add the dependency to a new root ScriptGroup,
					// then add this as its only child
					// If it is there, add this to the list of children for that ScriptGroup
					// If there are more than one dependency, find all dependencies,
					// make new ones for ones that don't exist yet, and merge them all together

					ScriptLoadGroup group = new ScriptLoadGroup();
					group.AddScript(script);

					ScriptLoadGroup parentGroup = new ScriptLoadGroup();
					group.Parent = parentGroup;

					parentGroup = buildParentScriptGroup(script.Script.ParentScripts, parentGroup);

					// Find the highest level parent, and add it to root
					while (parentGroup.Parent != null)
						parentGroup = parentGroup.Parent;

					root.Add(parentGroup);
				}
			}

			if (simpleScriptGroup.Scripts.Count > 0)
				root.Add(simpleScriptGroup);

			return root;
		}