var ensemblePluginStyleSheetName = 'ensembleVideo.css|ensemblePlugin.css'; var ensemblePluginStyleSheetElementID = '_ensembleVideoCss|ensembleStyleSheet'; var ensemblePluginStyleSheetUrl = 'css/ensemblePlugin.css'; var ensembleEmbeddedContentStyleSheetUrl = 'css/ensembleEmbeddedContent.css'; var scriptInstances = document.getElementsByTagName('script'); var styleElements = document.getElementsByTagName('style'); var linkElements = document.getElementsByTagName('link'); var config = {}; var pluginInstances = new Array(); var iframe = '', sourceUrl = '', elementIDPrefix = 'ensembleContentContainer_'; var styleSheetUrl = ''; // Check all the link elements for a style matching the Ensemble style sheet for (i = 0; i < linkElements.length; i++) { if (linkElements[i].href.match(ensemblePluginStyleSheetName) || linkElements[i].id.match(ensemblePluginStyleSheetElementID)) { styleSheetUrl = linkElements[i].href; } } // Check all the style elements for a style matching the Ensemble style sheet for (i = 0; i < styleElements.length; i++) { if (styleElements[i].innerHTML.match(ensemblePluginStyleSheetName) ||styleElements[i].id.match(ensemblePluginStyleSheetElementID)) { styleSheetUrl = styleElements[i].innerHTML.replace(/.*url\(("|')(.*)("|')\).*/, '$2').replace(/^\s+/,"").replace(/\s+$/,""); } } for (i = 0; i < scriptInstances.length; i++) { if (scriptInstances[i].src.match(/plugin(\.aspx|\.js)/i)) { sourceUrl = scriptInstances[i].src; config.baseUrl = sourceUrl.replace(/plugin.aspx.*/i, ''); config.styleSheetUrl = (styleSheetUrl == '') ? encodeURIComponent(config.baseUrl + ensemblePluginStyleSheetUrl) : encodeURIComponent(styleSheetUrl); config.isEmbedCall = ((sourceUrl.match(/\?embed=true/i)) || (sourceUrl.match(/&embed=true/i))) ? true : false; config.isPlaylistEmbedCall = (sourceUrl.match(/&playlistEmbed=true/i)) ? true : false; config.isResponsive = (sourceUrl.match(/&isResponsive=true/i)) ? true : false; config.isAudio = (sourceUrl.match(/&isAudio=true/i)) ? true : false; config.isNewPluginEmbed = (sourceUrl.match(/&isNewPluginEmbed=true/i)) ? true : false; config.displayShowcase = (sourceUrl.match(/&displayShowcase=true/i)) ? true : false; config.queryString = CleanQuery(sourceUrl.replace(/.*\?(.*)/, '$1')); if (!config.queryString.match(/q=.*/i)) { config.queryString += '&q=' + escape(location.host); } // If this is an embed call, configure the stylesheet URL if (config.isEmbedCall && !config.isNewPluginEmbed) { config.styleSheetUrl = (styleSheetUrl == '') ? encodeURIComponent(config.baseUrl + ensembleEmbeddedContentStyleSheetUrl) : styleSheetUrl; } if (sourceUrl.match(/videoID=.*/i)) config.contentID = (sourceUrl.match(/videoID=.*/i)) ? sourceUrl.replace(/.*videoID=([a-z0-9\-_]+)(.*)?/i, '$1') : scriptInstances[i].id; else if (sourceUrl.match(/contentID=.*/i)) config.contentID = (sourceUrl.match(/contentID=.*/i)) ? sourceUrl.replace(/.*contentID=([a-z0-9\-_]+)(.*)?/i, '$1') : scriptInstances[i].id; else { if (config.isEmbedCall) config.contentID = scriptInstances[i].id; } config.destinationID = (sourceUrl.match(/destinationID=.*/i)) ? sourceUrl.replace(/.*destinationID=([a-z0-9\-_]+)(.*)?/i, '$1') : scriptInstances[i].id; // Make sure the parent has it's ID set if (scriptInstances[i].parentNode.id == '') { var elementID = ''; if (config.isEmbedCall) elementID = elementIDPrefix + config.contentID; else elementID = elementIDPrefix + config.destinationID; scriptInstances[i].parentNode.id = elementID; config.parentID = elementID; } else { config.parentID = scriptInstances[i].parentNode.id; } pluginInstances.push(config); } } for (i = 0; i < pluginInstances.length; i++) { var width = '', height = ''; var config = pluginInstances[i]; var parent = document.getElementById(config.parentID); var iframe = document.createElement('iframe'); // Create the parent if it doesn't exist if (parent == undefined) { var div = document.createElement('div'); div.id = config.parentID; document.getElementsByTagName('body')[0].appendChild(div); parent = div; } if (parent.width) { width = parent.width; } else if (parent.style.width) { width = parent.style.width } else { var w_parm = sourceUrl.match(/width=[^&]*/); if (w_parm) { width = w_parm[0].split('=')[1] + 'px'; } } if (parent.height) { height = parent.height; } else if (parent.style.height) { height = parent.style.height } else { var h_parm = sourceUrl.match(/height=[^&]*/); if (h_parm) { height = parseInt(h_parm[0].split('=')[1], 10) + 56 + 'px'; } } iframe.id = 'iframe_' + config.parentID; if (config.isEmbedCall) { var widthInt = parseInt(width.replace(/(\d+).*/, '$1')) + 20; var widthMeasure = width.replace(/\d+(.*)/, '$1'); var heightInt = parseInt(height.replace(/(\d+).*/, '$1')) + 20; var heightMeasure = height.replace(/\d+(.*)/, '$1'); if (config.isResponsive){ if (config.isAudio) { iframe.style.width = '100%'; var h_parm = sourceUrl.match(/audioHeight=[^&]*/); if (h_parm) { iframe.style.height = h_parm[0].split('=')[1]; } } else{ iframe.style.position = 'absolute'; iframe.style.top = 0; iframe.style.left = 0; iframe.style.width = '100%'; iframe.style.height = '100%'; } } else { iframe.style.width = widthInt.toString() + widthMeasure; iframe.style.height = heightInt.toString() + heightMeasure; } iframe.src = config.baseUrl + 'plugin.aspx?insideIFrame=true&useIFrame=True&styleSheetUrl=' + config.styleSheetUrl + '&contentID=' + config.contentID + ((config.destinationID != '') ? '&destinationID=' + config.destinationID : '') + ((!config.queryString.match(/^&/) && config.queryString != '') ? '&' : '') + config.queryString; //iframe.scrolling = 'no'; } else { if (config.isPlaylistEmbedCall && config.isResponsive) { iframe.style.position = 'absolute'; iframe.style.top = 0; iframe.style.left = 0; iframe.style.width = '100%'; iframe.style.height = '100%'; } else { iframe.style.width = ((width == '') ? '100%' : width); iframe.style.height = ((height == '') ? '800px' : height); } iframe.src = config.baseUrl + 'plugin.aspx?insideIFrame=true&useIFrame=True&styleSheetUrl=' + config.styleSheetUrl + '&destinationID=' + config.destinationID + ((!config.queryString.match(/^&/) && config.queryString != '') ? '&' : '') + config.queryString; } iframe.frameBorder = '0'; iframe.marginheight = '0'; iframe.marginwidth = '0'; iframe.setAttribute('allowFullScreen', '') document.getElementById(config.parentID).innerHTML = ''; document.getElementById(config.parentID).appendChild(iframe); } function Log(message) { try { console.log(message); } catch (e) { } } function CleanQuery(queryString) { var cleanQueryString = ''; var vars = queryString.split('&'); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split('='); if (!pair[0].toLowerCase().match(/^(contentID|destinationID|useIFrame)/ig)) { cleanQueryString += (cleanQueryString != '') ? '&' : cleanQueryString; cleanQueryString += pair[0] + '=' + pair[1]; } } return cleanQueryString; } function ParseQuery(queryString) { var queryHash = {}; var query = queryString; var vars = query.split("&"); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split("="); queryHash[pair[0].toLowerCase()] = pair[1]; } return queryHash; } function QueryValue(queryHash, name) { var value = queryHash[name.toLowerCase()]; if (value == undefined) value = ''; return value; }