(function () { var url /*= 'http://spa.niche.local'*/; var iframeLoaded = false; var scriptSource = (function () { var scripts = document.getElementsByTagName('script'), script = scripts[scripts.length - 1]; if (script.getAttribute.length !== undefined) { return script.getAttribute('src') } return script.getAttribute('src', 2) }()); var pathArray = /*document.currentScript.src.split('/') ||*/ scriptSource.split('/'); var protocol = pathArray[0]; var host = pathArray[2]; url = protocol + '//' + host; //Detect mobile platform function detectMobile() { var deviceWidth = (window.innerWidth > 0) ? window.innerWidth : screen.width; var check = false; (function (a) { if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) check = true })(navigator.userAgent || navigator.vendor || window.opera); return check; } //Some defaults for mobile devices if (!detectMobile()) { var containerWidth = 290; } else { var containerWidth = 246; } if (!detectMobile()) { var buttonsRightMargin = "-21px"; } else { var buttonsRightMargin = "0px"; } if (!detectMobile()) { var buttonsRightMarginOnOpen = ('buttonsLarge' == "buttonsLarge") ? "217px" : "233px"; if ('block' == 'none') buttonsRightMarginOnOpen += 50; } else { var buttonsRightMarginOnOpen = "230px"; if ('block' == 'none') buttonsRightMarginOnOpen += 50; } /*Function for loading css for widget*/ var loadCss = function () { /*Font-awesome css*/ var font_awesome_css = document.createElement("link"); font_awesome_css.setAttribute("rel", "stylesheet"); font_awesome_css.setAttribute("type", "text/css"); font_awesome_css.setAttribute("href", "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.css"); document.getElementsByTagName("head")[0].appendChild(font_awesome_css); /*Widget css*/ var widget_css = document.createElement("link"); widget_css.setAttribute("rel", "stylesheet"); widget_css.setAttribute("type", "text/css"); widget_css.setAttribute("href", url + "/src/assets/js/widgets/css/widget.css"); document.getElementsByTagName("head")[0].appendChild(widget_css); } /*Alternate for jQuery.hasClass */ function hasClassCustom(target, className) { return new RegExp('(\\s|^)' + className + '(\\s|$)').test(target.className); } /*Trigger code for sidebar buttons*/ var linkAndOpenTriggers = function () { var toggleLink = document.getElementsByClassName("openNSide"); var nicheSideListing = document.getElementsByClassName("nicheSideListing"); var nicheResizeHandle = document.getElementById("nicheResizeHandle"); toggleLink[0].onclick = function () { if (hasClassCustom(this, "active")) { //Panel is open, close it nicheResizeHandle.style.visibility = "hidden"; this.className = "openNSide"; if (!detectMobile()) { var spanWithin = this.getElementsByTagName("span"); spanWithin[0].innerHTML = 'Tutorials' ; } var iWithin = this.getElementsByTagName("i"); iWithin[0].className = "fa fa-chevron-up"; if ("no" == "yes") { this.parentNode.style.right = "-58px"; adjustButtons(true); } else { this.parentNode.style.right = buttonsRightMargin; adjustButtons(false); } nicheSideListing[0].style.right = "-" + containerWidth + "px"; nicheSideListing[0].style.width = containerWidth + "px"; } else { //Panel is close, open it loadInitIframe(); var deviceWidth = (window.innerWidth > 0) ? window.innerWidth : screen.width; nicheResizeHandle.style.visibility = "visible"; nicheResizeHandle.style.background = "#cccee3"; nicheResizeHandle.style.color = "rgb(97, 97, 97) !important"; this.className = "openNSide active"; if (!detectMobile()) { var spanWithin = this.getElementsByTagName("span"); spanWithin[0].innerHTML = "Close"; } var iWithin = this.getElementsByTagName("i"); iWithin[0].className = "fa fa-chevron-down"; this.parentNode.style.right = "267px"; nicheSideListing[0].style.right = "0px"; var nichSideBtns = document.getElementsByClassName("nichSideBtns"); nichSideBtns[0].style.right = buttonsRightMarginOnOpen; } } } /*Load initial Iframe with academy course listing*/ var loadInitIframe = function () { if (!iframeLoaded) { iframeLoaded = true; loadAcademyIFrame(url + '/nbpltexas'); } } /*Loads an Iframe with provided URL*/ var loadAcademyIFrame = function (url) { var nicheSideListing = document.getElementsByClassName("nicheSideListing"); var nicheSideListingIframe = document.createElement('iframe'); nicheSideListingIframe.setAttribute('frameBorder', '0'); nicheSideListingIframe.src = url; nicheSideListingIframe.id = 'nicheDataIframe'; nicheSideListingIframe.setAttribute('allowfullscreen', ''); nicheSideListing[0].innerHTML = '
'; nicheSideListing[0].appendChild(nicheSideListingIframe); } /*For arbitrary links*/ var openOnLink = function (course, lesson) { if ("no" == "yes") { var nichSideBtns = document.getElementsByClassName("nichSideBtns"); var buttonsActualHeight = Math.round((nichSideBtns[0].getBoundingClientRect().height - nichSideBtns[0].getBoundingClientRect().width) / 2) + 58; nichSideBtns[0].style.right = "-" + buttonsActualHeight + "px"; } else { loadInitIframe(); } } function loadJs() { var head = document.getElementsByTagName('head').item(0); var interactjs = document.createElement('script'); interactjs.setAttribute('type', 'text/javascript'); interactjs.setAttribute('src', 'https://cdnjs.cloudflare.com/ajax/libs/interact.js/1.2.5/interact.js'); head.appendChild(interactjs); } /*Make the listing re-sizable*/ function makeResizable(interact) { interact('.nicheSideListing') .resizable({ edges: { left: true, right: false, bottom: false, top: false } }) .on('resizeend', function (event) { var resizeIndicator = document.getElementById('resizeIndicator'); resizeIndicator.style.display = 'none'; var nichSideBtns = document.getElementsByClassName("nichSideBtns"); nichSideBtns[0].style.WebkitTransition = 'all 0.5s ease'; nichSideBtns[0].style.MozTransition = 'all 0.5s ease'; nichSideBtns[0].style.transition = 'all 0.5s ease'; var nicheSideListing = document.getElementsByClassName("nicheSideListing"); nicheSideListing[0].style.WebkitTransition = 'all 0.5s ease'; nicheSideListing[0].style.MozTransition = 'all 0.5s ease'; nicheSideListing[0].style.transition = 'all 0.5s ease'; }) .on('resizemove', function (event) { var nicheSideListing = document.getElementsByClassName("nicheSideListing"); nicheSideListing[0].style.WebkitTransition = 'all 0s'; nicheSideListing[0].style.MozTransition = 'all 0s'; nicheSideListing[0].style.transition = 'all 0s'; var nichSideBtns = document.getElementsByClassName("nichSideBtns"); nichSideBtns[0].style.WebkitTransition = 'all 0s'; nichSideBtns[0].style.MozTransition = 'all 0s'; nichSideBtns[0].style.transition = 'all 0s'; var resizeIndicator = document.getElementById('resizeIndicator'); resizeIndicator.style.display = 'block'; var target = event.target, x = (parseFloat(target.getAttribute('data-x')) || 0), y = (parseFloat(target.getAttribute('data-y')) || 0); // update the element's style var nichSideBtns = document.getElementsByClassName("nichSideBtns"); var buttonsActualHeight = Math.round((nichSideBtns[0].getBoundingClientRect().height - nichSideBtns[0].getBoundingClientRect().width) / 2); if (event.rect.width >= containerWidth && event.rect.left >= 100 && event.rect.left > (nichSideBtns[0].getBoundingClientRect().height + 50)) { target.style.width = event.rect.width + 'px'; nichSideBtns[0].style.right = ((event.rect.right - event.rect.left) - buttonsActualHeight) + "px"; } // translate when resizing from top or left edges x += event.deltaRect.left; y += event.deltaRect.top; target.setAttribute('data-x', x); target.setAttribute('data-y', y); moveHandler(event, document.getElementById('nicheResizeHandle')); }); interact('#nicheResizeHandle').on('down', function (event) { var interaction = event.interaction, handle = event.currentTarget; interaction.start({ name: 'resize', edges: { top: false, left: true, bottom: false, right: false, } }, interact('.nicheSideListing'), // target Interactable document.getElementById('resizeDiv')); // target Element }); } function moveHandler(event, handlerElement) { var target = handlerElement, // keep the dragged position in the data-x/data-y attributes x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx, y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy; // update the posiion attributes target.setAttribute('data-x', x); target.setAttribute('data-y', y); } function createWidgetHtml() { if (detectMobile()) { var mainButtons = '
' + '
' + '
' + '
' + '' + '' + '' + '
' + ' ' + '
' + '
'; var widgetDiv = document.createElement('div'); widgetDiv.innerHTML = mainButtons; document.getElementsByTagName("body")[0].appendChild(widgetDiv); } else { var mainButtons = '
' + '
' + '
' + '
' + '' + '  Tutorials ' + '' + '
' + ' Resize' + '
' + '
'; var widgetDiv = document.createElement('div'); widgetDiv.innerHTML = mainButtons; document.getElementsByTagName("body")[0].appendChild(widgetDiv); } } loadJs(); loadCss(); /*Initialize widget code*/ function initWidget() { createWidgetHtml(); linkAndOpenTriggers(); // openOnLink(); //Function for opening widget using arbitrary links window.loadOnLink = function (course) { var nichSideBtns = document.getElementsByClassName("nichSideBtns"); var nicheResizeHandle = document.getElementById("nicheResizeHandle"); var toggleLink = document.getElementsByClassName("openNSide"); var nicheSideListing = document.getElementsByClassName("nicheSideListing"); toggleLink[0].className = "openNSide active"; if (!detectMobile()) { var spanWithin = toggleLink[0].getElementsByTagName("span"); spanWithin[0].innerHTML = "Close"; } var iWithin = toggleLink[0].getElementsByTagName("i"); iWithin[0].className = "fa fa-chevron-down"; var newRightForButtons = Math.round(document.getElementById("resizeDiv").offsetWidth - (nichSideBtns[0].getBoundingClientRect().height - nichSideBtns[0].getBoundingClientRect().width) / 2); if ('block' == 'none') newMarginForButtons += 50; nichSideBtns[0].style.right = newRightForButtons + 'px'; nicheSideListing[0].style.right = "0px"; var deviceWidth = (window.innerWidth > 0) ? window.innerWidth : screen.width; nicheResizeHandle.style.visibility = "visible"; //Is course id provided? if (typeof course != 'undefined' && course != '') { //Is lesson id empty? //If so, load course loadAcademyIFrame(url + '/nbpltexas/course/' + course); } else { // Just load academy course listing since course id is not provided loadAcademyIFrame(url + '/nbpltexas'); } } //Object init fix for NodeJs/RequireJs/DuelJs/CommonJs // available globally if (window.interact) { makeResizable(window.interact); } // check for AMD else if (typeof define === 'function' && define.amd) { require(['interact'], makeResizable); } // finally try CommonJS else { makeResizable(require(['interact'])); } window.setTimeout(function () { if ("no" != "yes") { adjustButtons(false); } }, 500); } /*Adjust button right margins after widget load*/ function adjustButtons(hideButtons) { if (typeof hideButtons == "undefined" || hideButtons == "") { hideButtons = false; } var openButton = document.getElementsByClassName("openNSide")[0]; var linkButton = document.getElementsByClassName("linkNSite")[0]; var nichSideBtns = document.getElementsByClassName("nichSideBtns")[0]; var newMarginForButtons = openButton.getBoundingClientRect().height - 33; var newRightForButtons = Math.round((nichSideBtns.getBoundingClientRect().height - nichSideBtns.getBoundingClientRect().width) / 2); //Hide the buttons if the arbitrary buttons option is set if (hideButtons === true) { newRightForButtons += ('buttonsLarge' == "buttonsLarge") ? "47" : "37"; } nichSideBtns.style.right = "-" + newRightForButtons + "px"; } /*Listener for scroll events*/ function scrollEventListener(e) { var iframe = document.getElementById('nicheDataIframe'); if (e.target === iframe) { e.preventDefault(); } } /*Loading widget initialization code on window load*/ if (window.addEventListener) {// W3C standard window.addEventListener('load', initWidget, false); window.addEventListener('mousewheel', scrollEventListener, false); } else if (window.attachEvent) {// Microsoft window.attachEvent('onload', initWidget); window.attachEvent('onmousewheel', scrollEventListener); } })();