[SOLVED] Dynamic JavaScript Injection/Execution

AoN

Internet Programmer
Joined
Aug 1, 2012
Posts
114
A small little rundown of what I'm trying to do:

1) Dynamically determine if a browser is capable of playing HTML5 video (Working)
2) If not capable of playing HTML5 video, load Flash version of video, CSS, and page (Working)
3) If capable of playing HTML5 video, load HTML5 version of video, CSS, and page (Stuck)

All the code needed loads into the browser (IE10, IE11, and Chrome 36 have been tested). The problem is with the execution of JavaScript that is added through the dynamic loading. I'm using the Adobe Captivate CS6 publishing system for Flash and HTML5 output, and all my customized code works perfectly if the scripts are loaded normally, but not through this dynamic method. To save a little bit of effort, I'm just going to post the code for the HTML5 version.

Code:
        function addExternalStyleSheet(href)
        {
            if(document.createStyleSheet)
            {
                document.createStyleSheet(href);
            }
            else
            {
                var newSheet = document.createElement('link');
                newSheet.setAttribute('rel', 'stylesheet');
                newSheet.setAttribute('type', 'text/css');
                newSheet.setAttribute('href', href);
                document.getElementsByTagName('head')[0].appendChild(newSheet);
            }
        }
        function addInternalStyleSheet(selector, attributes)
        {
            if(document.createStyleSheet)
            {
                var styleSheet = document.createStyleSheet('');
                styleSheet.cssText = selector + '{' + attibutes + '}';
            }
            else
            {
                var styleTag = document.createElement('style');
                var head = document.getElementsByTagName('head')[0];
                head.appendChild(styleTag);
                var sheet = styleTag.sheet ? styleTag.sheet : styleTag.styleSheet;
                if(sheet.insertRule)
                    sheet.insertRule(selector + '{' + attributes + '}', 0);
                else
                    sheet.addRule(selector, attributes, 0);
            }
        }
        function addJavaScript(src)
        {
            var newScript = document.createElement('script');
            newScript.setAttribute('type', 'text/javascript');
            newScript.setAttribute('src', src);
            document.getElementsByTagName('head')[0].appendChild(newScript);
        }
        function generateEmbed()
        {
            if(fileType == 'html5')
            {
                addExternalStyleSheet('assets/playbar/playbarStyle.css');
                addExternalStyleSheet('assets/css/CPLibrary.css');
                addExternalStyleSheet('assets/css/CPQuiz.css');
                addExternalStyleSheet('assets/css/smoothness/jquery-ui-1.8.14.custom.css');
                addExternalStyleSheet('assets/css/dd.css');
                addInternalStyleSheet('.shadow', 'overflow: hidden;');
                addInternalStyleSheet('.cpMainContainer', 'background-color: transparent; height: 100%; width: 100%; padding: 0px; position: absolute;');
                addInternalStyleSheet('.blocker', 'position: absolute; left: 0px; top: 0px; display: none;');
                addInternalStyleSheet('.loadingBackground', 'background-color: #777777; opacity: 0.5;');
                addInternalStyleSheet('.loadingString', 'color: #ffffff;');
                addJavaScript('assets/js/jquery-1.6.1.min.js');
                addJavaScript('assets/js/uncompressed.jquery.dd.js');
                addJavaScript('assets/js/uncompressed-jquery-ui-1.8.14.custom.js');
                addJavaScript('assets/js/CPRuntimeDailog.js');
                addJavaScript('assets/js/CPLibrary.js');
                addJavaScript('assets/js/CPQuizLibrary.js');
                addJavaScript('assets/js/CPPlaybar.js');
                addJavaScript('assets/js/CPTOC.js');
                addJavaScript('assets/js/CPWidgetManager.js');
                addJavaScript('assets/playbar/playbarScript.js');
                addJavaScript('Project.js');
                document.getElementById('player').innerHTML = '\n       <div class="cpMainContainer" id="cpDocument" style="left: 0px; top: 0px;">\n            <div class="shadow" id="project_container" style="left: 0px; top: 0px; position: absolute;">\n              <div id="project" class="cp-movie" style="width: 1280px; height: 720px">\n                  <div id="project_main" class="cp-timeline cp-main">\n                       <div id="div_Slide" onclick="handleClick(event)" style="top: 0px; width: 1280px; height: 720px; position: absolute; -webkit-tap-highlight-color: rgba(0,0,0,0);"><\/div>\n                  <\/div>\n                   <div id="autoplayDiv" style="display: block; text-align: center; position: absolute; left: 0px; top: 0px;">\n                       <img id="autoplayImage" src="" style="position: absolute; display: block; vertical-align: middle;" \/>\n                        <div id="playImage" tabindex="0" role="buton" aria-label="play" class="autoPlayButton" onkeydown="CPPlayButtonHandle(event)" onClick="cp.movie.play()" style="position: absolute; display: block; vertical-align: middle;"><\/div>\n                    <\/div>\n               <\/div>\n               <div id="playbar" style="left: 0px; float: left; position: absolute;"><\/div>\n             <div id="toc" style="left: 0px; float: left; position: absolute;"><\/div>\n             <div id="cc" style="left: 0px; float: left; position: absolute; visibility: hidden;">\n                 <div id="ccText" style="left: 0px; float: left; position: absolute; width: 100%; height: 100%;">\n                      <p style="margin-left: 8px; margin-right: 8px; margin-top: 2px;"><\/p>\n                    <\/div>\n                   <div id="ccClose" style="background-image: url(.\/assets\/Playbar_icons\/ccClose.png); right: 0px; float: right; position: absolute; cursor: pointer; width: 13px; height: 11px;" onclick="showHideCC()"><\/div>\n              <\/div>\n               <div id="passwordDiv" style="display: block; text-align: center; position: absolute; width: 100%; height: 100%; left: 0px; top: 0px;"><\/div>\n             <div id="expDiv" style="display: block; text-align: center; position: absolute; width: 100%; height: 100%; left: 0px; top: 0px;"><\/div>\n          <\/div>\n       <\/div>\n       <div id="blockUserInteraction" class="blocker" style="width: 100%; height: 100%;">\n            <table style="width: 100%; height: 100%; text-align: center; vertical-align: middle;" id="loading" class="loadingBackground">\n             <tr style="width: 100%; height: 100%; text-align: center; vertical-align: middle;">\n                   <td style="width: 100%; height: 100%; text-align: center; vertical-align: middle;">\n                       <image id="preloaderImage"><\/image>\n                      <div id="loadingString" class="loadingString">Loading...<\/div>\n                   <\/td>\n                <\/tr>\n            <\/table>\n     <\/div>\n';
                function DoCPInit()
                {
                    CPPreInit();
                    cp.QuizLibraryInit();
                    CPPostInit();
                }
                document.oncomplete = DoCPInit();
            }
        }

I included all the functions for inserting files (internal and external CSS and JavaScript), in case the problem is there, though it took me several hours just to get the internal CSS function to work without disabling the JavaScript function. :S

When using the browser debugger in IE, it errors with the execution (as a part of the DoCPInit function) of the CPPreInit function, which is located in CPLibrary.js, the fifth script dynamically loaded. The debugger states that the function is undefined.

Honestly, I'd prefer to use PHP to get this all done, but my hands are tied, so JavaScript has to get the job done, and I know it can, I'm just screwing it up. :(
 
Well, yall know I only post after hours upon hours to toiling with a bug. It looks like I only needed another 2 hours to figure it out. ^^'

I determined that the issue was multi-fold (at least two). Firstly, Captivate publishes with scripts that required a blank SCRIPT tag in the header, so I rewrote the addJavaScript function to permit blank entries and added functionality for noscript tags:

Code:
			function addJavaScript(src, noScript)
			{
					var newScript = document.createElement('script');
				newScript.setAttribute('type', 'text/javascript');
				if(src != '')
					newScript.setAttribute('src', src);
				document.getElementsByTagName('head')[0].appendChild(newScript);
				if(noScript != '')
				{
					var newNoScript = document.createElement('noscript');
					newNoScript.innerHTML = noScript;
					document.getElementsByTagName('head')[0].appendChild(newNoScript);
				}
			}

Next, to be safe that the original files called were not interfering, I added a removeFiles function to remove them after the player type had been determined, though I don't think this was actually needed.

Code:
		function removeFiles(filename, filetype)
		{
			var targetelement = (filetype == 'js') ? 'script' : (filetype == 'css') ? 'link' : 'none';
			var targetattr = (filetype == 'js') ? 'src' : (filetype == 'css') ? 'href' : 'none';
			var allsuspects = document.getElementsByTagName(targetelement);
			for(var i = allsuspects.length; i >= 0; i--)
			{
				if(allsuspects[i] && allsuspects[i].getAttribute(targetattr) != null && allsuspects[i].getAttribute(targetattr).indexOf(filename) != -1)
				allsuspects[i].parentNode.removeChild(allsuspects[i])
			}
		}

The last bit was, and I believe this was the kicker, the DoCPInit function. In the original published files, it is placed after the content of my 'player' DIV. So, as a solution to the issue, I appended the script after the DIV.

Code:
				var _in = document.getElementById('player');
				var scriptNode = document.createElement('script');
				scriptNode.innerHTML = 'function DoCPInit() { CPPreInit(); cp.QuizLibraryInit(); CPPostInit(); } document.oncomplete = DoCPInit();';
				_in.appendChild(scriptNode);

Stupid thing about me posting this is that I normally type these things up but never get to posting them because I figure out the solution by thinking about how to best explain the problem. ^^'



Edit:
And then it was shattered. Doesn't work outside IE...RAWR!!!
 
Bloody timeout on post editing...*sigh*

Alright, so, due to the ability to emulate older browser version in IE, I was using it to test my code between IE >8 (HTML5 player) and IE <=8 (Flash Player). For the IE >8, I was using "Edge", which is the default document mode for IE11. At so point, I had changed it to 10 and forgot I had changed it. As a result, I completely missed that while my code now works perfectly for all of the older IEs, it doesn't work for IE11 or Chome 36 (I don't have a lot of browser options on my work computer for testing). I'm certain it doesn't work in Firefox, SeaMonkey, etc.

To further add to the confusion, the HTML5, which works when I open the HTML file from My Documents, won't work on my web server. :S

Bare in mind, this is, disappointingly, a modification to the default publishing done by Adobe Captivate CS6. With that said, here's the full code I currently have, which works in all forms of older IE (from My Documents):
Code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" style="background-color: #000000; height: 100%;">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="viewport" content="initial-scale = 1, minimum-scale = 1, maximum-scale = 1" />
		<title>ENG120_U1_Lecture1</title>
		<meta http-equiv="CACHE-CONTROL" content="NO-CACHE" />
		<script src="standard.js" type="text/javascript"></script>
		<script src="assets/js/CPHTML5Warnings.js" type="text/javascript"></script> 
		<script>
			function addExternalStyleSheet(href)
			{
				if(document.createStyleSheet)
				{
					document.createStyleSheet(href);
				}
				else
				{
					var newSheet = document.createElement('link');
					newSheet.setAttribute('rel', 'stylesheet');
					newSheet.setAttribute('type', 'text/css');
					newSheet.setAttribute('href', href);
					document.getElementsByTagName('head')[0].appendChild(newSheet);
				}
			}
			function addInternalStyleSheet(selector, attributes)
			{
				if(document.createStyleSheet)
				{
					var styleSheet = document.createStyleSheet('');
					styleSheet.cssText = selector + '{' + attributes + '}';
				}
				else
				{
					var styleTag = document.createElement('style');
					var head = document.getElementsByTagName('head')[0];
					head.appendChild(styleTag);
					var sheet = styleTag.sheet ? styleTag.sheet : styleTag.styleSheet;
					if(sheet.insertRule)
						sheet.insertRule(selector + '{' + attributes + '}', 0);
					else
						sheet.addRule(selector, attributes, 0);
				}
			}
			function addJavaScript(src, noScript)
			{
				var newScript = document.createElement('script');
				newScript.setAttribute('type', 'text/javascript');
				if(src != '')
					newScript.setAttribute('src', src);
				document.getElementsByTagName('head')[0].appendChild(newScript);
				if(noScript != '')
				{
					var newNoScript = document.createElement('noscript');
					newNoScript.innerHTML = noScript;
					document.getElementsByTagName('head')[0].appendChild(newNoScript);
				}
			}
			function removeFiles(filename, filetype)
			{
				var targetelement = (filetype == 'js') ? 'script' : (filetype == 'css') ? 'link' : 'none';
				var targetattr = (filetype == 'js') ? 'src' : (filetype == 'css') ? 'href' : 'none';
				var allsuspects = document.getElementsByTagName(targetelement);
				for(var i = allsuspects.length; i >= 0; i--)
				{
					if(allsuspects[i] && allsuspects[i].getAttribute(targetattr) != null && allsuspects[i].getAttribute(targetattr).indexOf(filename) != -1)
					allsuspects[i].parentNode.removeChild(allsuspects[i])
				}
			}
			function generateEmbed()
			{
				var fileType;
					if(!!document.createElement('video').canPlayType)
					{
						var vidTest = document.createElement('video');
						oggTest = vidTest.canPlayType('video/ogg; codecs="theora, vorbis"');
						if(!oggTest)
						{
							h264Test = vidTest.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"');
							if(!h264Test)
								fileType = 'flash';
							else
							{
								if(h264Test == 'probably')
									fileType = 'html5';
								else
									fileType = 'flash';
							}
						}
						else
							if(oggTest == 'probably')
								fileType = 'html5';
							else
								fileType = 'flash';
					}
					else
						fileType = 'flash';
				if(fileType == 'html5')
				{
					removeFiles('standard.js', 'js');
					removeFiles('assets/js/CPHTML5Warnings.js', 'js');
					addExternalStyleSheet('assets/css/CPLibrary.css');
					addExternalStyleSheet('assets/css/CPQuiz.css');
					addExternalStyleSheet('assets/css/smoothness/jquery-ui-1.8.14.custom.css');
					addExternalStyleSheet('assets/css/dd.css');
					addJavaScript('assets/js/jquery-1.6.1.min.js', '');
					addJavaScript('assets/js/uncompressed.jquery.dd.js', '');
					addJavaScript('assets/js/uncompressed-jquery-ui-1.8.14.custom.js', '');
					addJavaScript('', 'Enable Javascript support in the browser.');
					addInternalStyleSheet('.shadow', 'overflow: hidden;');
					addInternalStyleSheet('.cpMainContainer', 'background-color: transparent; height: 100%; width: 100%; padding: 0px; position: absolute;');
					addInternalStyleSheet('.blocker', 'position: absolute; left: 0px; top: 0px; display: none;');
					addInternalStyleSheet('.loadingBackground', 'background-color: #777777; opacity: 0.5;');
					addInternalStyleSheet('.loadingString', 'color: #ffffff;');
					addJavaScript('assets/js/CPRuntimeDailog.js', '');
					addJavaScript('assets/js/CPLibrary.js', '');
					addJavaScript('assets/js/CPQuizLibrary.js', '');
					addJavaScript('assets/js/CPPlaybar.js', '');
					addJavaScript('assets/js/CPTOC.js', '');
					addJavaScript('assets/js/CPWidgetManager.js', '');
					addExternalStyleSheet('assets/playbar/playbarStyle.css');
					addJavaScript('assets/playbar/playbarScript.js', '');
					addJavaScript('Project.js', '');
					document.getElementById('player').innerHTML = '\n		<div class="cpMainContainer" id="cpDocument" style="left: 0px; top: 0px;">\n			<div class="shadow" id="project_container" style="left: 0px; top: 0px; position: absolute;">\n				<div id="project" class="cp-movie" style="width: 1280px; height: 720px">\n					<div id="project_main" class="cp-timeline cp-main">\n						<div id="div_Slide" onclick="handleClick(event)" style="top: 0px; width: 1280px; height: 720px; position: absolute; -webkit-tap-highlight-color: rgba(0,0,0,0);"><\/div>\n					<\/div>\n					<div id="autoplayDiv" style="display: block; text-align: center; position: absolute; left: 0px; top: 0px;">\n						<img id="autoplayImage" src="" style="position: absolute; display: block; vertical-align: middle;" \/>\n						<div id="playImage" tabindex="0" role="buton" aria-label="play" class="autoPlayButton" onkeydown="CPPlayButtonHandle(event)" onClick="cp.movie.play()" style="position: absolute; display: block; vertical-align: middle;"><\/div>\n					<\/div>\n				<\/div>\n				<div id="playbar" style="left: 0px; float: left; position: absolute;"><\/div>\n				<div id="toc" style="left: 0px; float: left; position: absolute;"><\/div>\n				<div id="cc" style="left: 0px; float: left; position: absolute; visibility: hidden;">\n					<div id="ccText" style="left: 0px; float: left; position: absolute; width: 100%; height: 100%;">\n						<p style="margin-left: 8px; margin-right: 8px; margin-top: 2px;"><\/p>\n					<\/div>\n					<div id="ccClose" style="background-image: url(.\/assets\/Playbar_icons\/ccClose.png); right: 0px; float: right; position: absolute; cursor: pointer; width: 13px; height: 11px;" onclick="showHideCC()"><\/div>\n				<\/div>\n				<div id="passwordDiv" style="display: block; text-align: center; position: absolute; width: 100%; height: 100%; left: 0px; top: 0px;"><\/div>\n				<div id="expDiv" style="display: block; text-align: center; position: absolute; width: 100%; height: 100%; left: 0px; top: 0px;"><\/div>\n			<\/div>\n		<\/div>\n		<div id="blockUserInteraction" class="blocker" style="width: 100%; height: 100%;">\n			<table style="width: 100%; height: 100%; text-align: center; vertical-align: middle;" id="loading" class="loadingBackground">\n				<tr style="width: 100%; height: 100%; text-align: center; vertical-align: middle;">\n					<td style="width: 100%; height: 100%; text-align: center; vertical-align: middle;">\n						<image id="preloaderImage"><\/image>\n						<div id="loadingString" class="loadingString">Loading...<\/div>\n					<\/td>\n				<\/tr>\n			<\/table>\n		<\/div>\n';
					var _in = document.getElementById('player');
					var scriptNode = document.createElement('script');
					scriptNode.innerHTML = 'function DoCPInit() { CPPreInit(); cp.QuizLibraryInit(); CPPostInit(); } document.oncomplete = DoCPInit();';
					_in.appendChild(scriptNode);
				}
				else
				{
					removeFiles('assets/js/CPHTML5Warnings.js', 'js');
					addExternalStyleSheet('captivate.css');
					document.getElementById('player').innerHTML = ' \n			<div id="CaptivateContent"><\/div>\n';
					var so = new SWFObject('ENG120_U1_Lecture1_skin.swf', 'Captivate', '100%', '100%', '10');
					so.addParam('wmode', 'transparent');
					so.addParam('quality', 'high');
					so.addParam('name', 'Captivate');
					so.addParam('id', 'Captivate');
					so.addParam('menu', 'false');
					so.addParam('AllowScriptAccess','always');
					so.addVariable('variable1', 'value1');
					so.setAttribute('redirectUrl', 'http://ww.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash');
					so.write('CaptivateContent');
					document.getElementById('Captivate').focus();
					document.Captivate.focus();
				}
			}
		</script>
	</head>
	<body onload="generateEmbed();" style="margin: 0px; padding: 0px; width: 100%; height: 100%; overflow: hidden;">
		<div style="background-color: transparent; border: 0px; padding: 0px; width: 100%; height: 100%;" id="player" name="content" src="" seamless allowtransparency="true">
		</div>
	</body>
</html>

On my web server, it can be accessed at: ENG120_U1_Lecture1

Basically, the point of ALL of this is to turn ENG120_U1_Lecture1, which is three pages, into a single page.

Any ideas on what I've screwed up?
 
Few things to keep in mind Chris.

Check how IE is interpreting the page. (Internet Explorer: IE8, IE9, IE10, and IE11 Compatibility mode: Can't log into Claro with IE8, IE9, IE10 or IE11 ? Feedback & Support)

Intranet often has a different version than internet.

Because of this you may or may not be able to append child elements and so forth.

Another thing to keep in mind. Most browsers load all the files for a page asynchronously unless you force it to otherwise.

What I mean by this is that all the files need for that page will be loaded when the page first loads.

Long story short, the javascript includes you are writing to the body likely aren't even running at all.

Drop in a couple alert('sdasdasd')s and you should be able to quickly tell if this is true or not.

As you are already including a Jquery library I suggest you use that for most of the heavy lifting.

It has a whole bunch of prebuilt functions that will simplify your life.

Sorry I don't have time to actually dive into this :sad:
 
@Laxer
I took your suggestion and converted the majority of my code to jQuery (I hadn't even realized one of the scripts being called was jQuery. ^^'). Now, the problem has changed.

Initially, using getScript(), I had no change in the symptoms from before I did the conversion, but your suggestion to add the alerts pointed out that the issue was, as I had originally thought, an issue of the script files loading. The alerts revealed the page completed it's loading before the scripts provided the alerts (which I placed as the first line in the scripts). So, I swapped getScript() for ajax() with the async set as false. This works...mostly.

Now, the HTML5 presentation plays just fine in IE and Chrome, however, they don't load the playbar. Actually, that's not entirely accurate. The symptoms are...odd. I've gotten the playbar to load a few times through refreshes. Other times, the code indicates that the bar should be there, but nothing. Mostly, it just doesn't display, though the code still indicates that it should. No errors in the console, at all (I was shocked, it had been erring the jQuery. xD).

On the plus side, it works perfectly on the default Android browser on both my phone and tablet.

There was a error being called out when drawing the playbar, until I included the DoCPInit() in the jQuery append of #player. After I did that, all the errors vanished and the player started working, just missing the playbar most of the time. :S

Here's the new code:
Code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" style="background-color: #000000; height: 100%;">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="viewport" content="initial-scale = 1, minimum-scale = 1, maximum-scale = 1" />
		<title>ENG120_U1_Lecture1</title>
		<meta http-equiv="CACHE-CONTROL" content="NO-CACHE" />
		<script src="standard.js" type="text/javascript"></script>
		<script src="assets/js/CPHTML5Warnings.js" type="text/javascript"></script> 
        <script src="assets/js/jquery-1.6.1.min.js" type="text/javascript"></script>
		<script>
			function addInternalStyleSheet(selector, attributes)
			{
				if(document.createStyleSheet)
				{
					var styleSheet = document.createStyleSheet('');
					styleSheet.cssText = selector + '{' + attributes + '}';
				}
				else
				{
					var styleTag = document.createElement('style');
					var head = document.getElementsByTagName('head')[0];
					head.appendChild(styleTag);
					var sheet = styleTag.sheet ? styleTag.sheet : styleTag.styleSheet;
					if(sheet.insertRule)
						sheet.insertRule(selector + '{' + attributes + '}', 0);
					else
						sheet.addRule(selector, attributes, 0);
				}
			}
			function removeFiles(filename, filetype)
			{
				var targetelement = (filetype == 'js') ? 'script' : (filetype == 'css') ? 'link' : 'none';
				var targetattr = (filetype == 'js') ? 'src' : (filetype == 'css') ? 'href' : 'none';
				var allsuspects = document.getElementsByTagName(targetelement);
				for(var i = allsuspects.length; i >= 0; i--)
				{
					if(allsuspects[i] && allsuspects[i].getAttribute(targetattr) != null && allsuspects[i].getAttribute(targetattr).indexOf(filename) != -1)
					allsuspects[i].parentNode.removeChild(allsuspects[i])
				}
			}
			function generateEmbed()
			{
				var fileType;
					if(!!document.createElement('video').canPlayType)
					{
						var vidTest = document.createElement('video');
						oggTest = vidTest.canPlayType('video/ogg; codecs="theora, vorbis"');
						if(!oggTest)
						{
							h264Test = vidTest.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"');
							if(!h264Test)
								fileType = 'flash';
							else
							{
								if(h264Test == 'probably')
									fileType = 'html5';
								else
									fileType = 'flash';
							}
						}
						else
							if(oggTest == 'probably')
								fileType = 'html5';
							else
								fileType = 'flash';
					}
					else
						fileType = 'flash';
				if(fileType == 'html5')
				{
					removeFiles('standard.js', 'js');
					removeFiles('assets/js/CPHTML5Warnings.js', 'js');
					var externalStyleSheet = ['assets/css/CPLibrary.css', 'assets/css/CPQuiz.css', 'assets/css/smoothness/jquery-ui-1.8.14.custom.css', 'assets/css/dd.css', 'assets/playbar/playbarStyle.css'];
					jQuery.each(externalStyleSheet, function(i, val) { if(document.createStyleSheet) { document.createStyleSheet(val); } else { $('head').append($('<link rel="stylesheet" href="' + val + '" type="text/css" />')); } });
					addInternalStyleSheet('.shadow', 'overflow: hidden;');
					addInternalStyleSheet('.cpMainContainer', 'background-color: transparent; height: 100%; width: 100%; padding: 0px; position: absolute;');
					addInternalStyleSheet('.blocker', 'position: absolute; left: 0px; top: 0px; display: none;');
					addInternalStyleSheet('.loadingBackground', 'background-color: #777777; opacity: 0.5;');
					addInternalStyleSheet('.loadingString', 'color: #ffffff;');
					var addJavaScript = ['assets/js/uncompressed.jquery.dd.js', 'assets/js/uncompressed-jquery-ui-1.8.14.custom.js', 'assets/js/CPRuntimeDailog.js', 'assets/js/CPLibrary.js', 'assets/js/CPQuizLibrary.js', 'assets/js/CPPlaybar.js', 'assets/js/CPTOC.js', 'assets/js/CPWidgetManager.js', 'assets/playbar/playbarScript.js', 'Project.js'];
					jQuery.each(addJavaScript, function(i, val) { jQuery.ajax({ async: false, dataType: 'script', url: val }); });
					$('#player').append($('\n		<div class="cpMainContainer" id="cpDocument" style="left: 0px; top: 0px;">\n			<div class="shadow" id="project_container" style="left: 0px; top: 0px; position: absolute;">\n				<div id="project" class="cp-movie" style="width: 1280px; height: 720px">\n					<div id="project_main" class="cp-timeline cp-main">\n						<div id="div_Slide" onclick="handleClick(event)" style="top: 0px; width: 1280px; height: 720px; position: absolute; -webkit-tap-highlight-color: rgba(0,0,0,0);"><\/div>\n					<\/div>\n					<div id="autoplayDiv" style="display: block; text-align: center; position: absolute; left: 0px; top: 0px;">\n						<img id="autoplayImage" src="" style="position: absolute; display: block; vertical-align: middle;" \/>\n						<div id="playImage" tabindex="0" role="buton" aria-label="play" class="autoPlayButton" onkeydown="CPPlayButtonHandle(event)" onClick="cp.movie.play()" style="position: absolute; display: block; vertical-align: middle;"><\/div>\n					<\/div>\n				<\/div>\n				<div id="playbar" style="left: 0px; float: left; position: absolute;"><\/div>\n				<div id="toc" style="left: 0px; float: left; position: absolute;"><\/div>\n				<div id="cc" style="left: 0px; float: left; position: absolute; visibility: hidden;">\n					<div id="ccText" style="left: 0px; float: left; position: absolute; width: 100%; height: 100%;">\n						<p style="margin-left: 8px; margin-right: 8px; margin-top: 2px;"><\/p>\n					<\/div>\n					<div id="ccClose" style="background-image: url(.\/assets\/Playbar_icons\/ccClose.png); right: 0px; float: right; position: absolute; cursor: pointer; width: 13px; height: 11px;" onclick="showHideCC()"><\/div>\n				<\/div>\n				<div id="passwordDiv" style="display: block; text-align: center; position: absolute; width: 100%; height: 100%; left: 0px; top: 0px;"><\/div>\n				<div id="expDiv" style="display: block; text-align: center; position: absolute; width: 100%; height: 100%; left: 0px; top: 0px;"><\/div>\n			<\/div>\n		<\/div>\n		<div id="blockUserInteraction" class="blocker" style="width: 100%; height: 100%;">\n			<table style="width: 100%; height: 100%; text-align: center; vertical-align: middle;" id="loading" class="loadingBackground">\n				<tr style="width: 100%; height: 100%; text-align: center; vertical-align: middle;">\n					<td style="width: 100%; height: 100%; text-align: center; vertical-align: middle;">\n						<image id="preloaderImage"><\/image>\n						<div id="loadingString" class="loadingString">Loading...<\/div>\n					<\/td>\n				<\/tr>\n			<\/table>\n		<\/div>\n		<script>\n			function DoCPInit()\n			{\n			CPPreInit();\n				cp.QuizLibraryInit();\n				CPPostInit();\n			}\n			document.oncomplete = DoCPInit();\n		<\/script>'));
				}
				else
				{
					removeFiles('assets/js/CPHTML5Warnings.js', 'js');
					if(document.createStyleSheet) { document.createStyleSheet('captivate.css'); } else { $('head').append($('<link rel="stylesheet" href="captivate.css" type="text/css" />')); }
					document.getElementById('player').innerHTML = ' \n			<div id="CaptivateContent"><\/div>\n';
					var so = new SWFObject('ENG120_U1_Lecture1_skin.swf', 'Captivate', '100%', '100%', '10');
					so.addParam('wmode', 'transparent');
					so.addParam('quality', 'high');
					so.addParam('name', 'Captivate');
					so.addParam('id', 'Captivate');
					so.addParam('menu', 'false');
					so.addParam('AllowScriptAccess','always');
					so.addVariable('variable1', 'value1');
					so.setAttribute('redirectUrl', 'http://ww.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash');
					so.write('CaptivateContent');
					document.getElementById('Captivate').focus();
					document.Captivate.focus();
				}
			}
		</script>
	</head>
	<body onload="generateEmbed();" style="margin: 0px; padding: 0px; width: 100%; height: 100%; overflow: hidden;">
		<div style="background-color: transparent; border: 0px; padding: 0px; width: 100%; height: 100%;" id="player" name="content" src="" seamless allowtransparency="true">
		</div>
	</body>
</html>

It's still accessible via ENG120_U1_Lecture1, which is really needed since a lot of jQuery errors if you don't have the web server backend.

Anyways, let me know what yall think.
 
I apologize now, I wrote the majority of this yesterday and had to leave for a meeting that I can't remember the topic of now. By the time I got back, it was well past time for me to have left, so I did. ^^'

Alright, had a theory that I could still be, somehow, related to the dynamic loading of the scripts, so I created another page with the script files pre-coded into the header: ENG120_U1_Lecture1. Suffice to say, there was no change to the issue. The player loads up a tadbit faster, but still have an intermittent playbar.

Playing around, I found that the bar displays, fully functional, at the top of the page when I disable both the standard and webkit transforms on it. That's sorta good, sorta not. Since the transform is generated by Captivate, it's something I can't be messing with.

If I expand the height of the #project_container div by the height of the playbar, it displays, but this is also configured by Captivate export.

Any ideas?
 
Alright, I think I've identified the exact problem, just not a solution to it. Since it seems to be an issue with the output of the Captivate scripts to my version of the player, I've created a thread on the Adobe community with the details of my findings and asking for assistance. You can check it out at https://forums.adobe.com/message/6601340#6601340.
 
I looked at it and honestly have no clue... :sad:

I got it to pop up and disappear a few times but never consistently...

I also think it may be something to do with the height as you hinted in your post over at the adobe forum.

This may be one you have to attack with Fiddlery or the web dev toolkit
 
Last edited:
Well, I found a "solution" on my own. It basically the same was JWPlayer, loading both players and just hiding what isn't needed from view. I don't like that, but it works, so, bleh.
 
Well, I found a "solution" on my own. It basically the same was JWPlayer, loading both players and just hiding what isn't needed from view. I don't like that, but it works, so, bleh.

As long as they both use the same video source the performance drop shouldn't really be noticeable.
 
That's just it, they don't use the same source. One uses a Flash file while the other is text/image-based HTML5 (no actual video). Basically, the browser will load two forms to presentation and hide the one not being used. Of course, with Flash, that isn't a big deal, since it would be ignoring the HTML5 as invalid anyways, but from the HTML5 side you get the Flash in addition to the HTML5. Not exactly ideal, but it works.
 

Has Sysnative Forums helped you? Please consider donating to help us support the site!

Back
Top