From af48fc4e1a827c8a49ffd92d75b316da9c2ae624 Mon Sep 17 00:00:00 2001 From: Adolfo Fitoria Date: Mon, 13 Aug 2012 11:03:35 -0600 Subject: fixed widget js --- .../default/templates/widgets/askbot_widget.js | 61 ++++++++++++++++------ 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/askbot/skins/default/templates/widgets/askbot_widget.js b/askbot/skins/default/templates/widgets/askbot_widget.js index 808776a5..cac8495a 100755 --- a/askbot/skins/default/templates/widgets/askbot_widget.js +++ b/askbot/skins/default/templates/widgets/askbot_widget.js @@ -1,31 +1,60 @@ var AskbotAskWidget = { element_id: "AskbotAskWidget", widgetToggle: function() { - element = document.getElementById(this.element_id); + element = document.getElementById(AskbotAskWidget.element_id); element.style.visibility = (element.style.visibility == "visible") ? "hidden" : "visible"; }, toHtml: function() { - //document.write(''); - document.write(this.createButton()); - document.write(''); + var html = AskbotAskWidget.createButton(); + var link = document.createElement('link'); + link.setAttribute("rel", "stylesheet"); + link.setAttribute("href", 'http://{{host}}/static/default/media/style/askbot-modal.css'); + + //creating the div + var motherDiv = document.createElement('div'); + motherDiv.setAttribute("id", AskbotAskWidget.element_id); + {%if widget.outer_style %} - document.write(''); + outerStyle = document.createElement('style'); + outerStyle.innerText = "{{widget.outer_style}}"; + motherDiv.appendChild(outerStyle); {%endif%} - //creating the div - document.write("
"); - document.write("Close"); - document.write("
"); - document.write("' + + '
'; + theBody.appendChild(popmask); + theBody.appendChild(popcont); + + this.gPopupMask = document.getElementById("AskbotPopupMask"); + this.gPopupContainer = document.getElementById("AskbotPopupContainer"); + this.gPopFrame = document.getElementById("AskbotPopupFrame"); + + // check to see if this is IE version 6 or lower. hide select boxes if so + // maybe they'll fix this in version 7? + var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10); + if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1) { + this.gHideSelects = true; + } + + // Add onclick handlers to 'a' elements of class submodal or submodal-width-height + var elms = document.getElementsByTagName('a'); + for (i = 0; i < elms.length; i++) { + if (elms[i].className.indexOf("submodal") == 0) { + // var onclick = 'function (){showPopWin(\''+elms[i].href+'\','+width+', '+height+', null);return false;};'; + // elms[i].onclick = eval(onclick); + elms[i].onclick = function(){ + // default width and height + var width = 400; + var height = 200; + // Parse out optional width and height from className + params = this.className.split('-'); + if (params.length == 3) { + width = parseInt(params[1]); + height = parseInt(params[2]); + } + this.showPopWin(this.href,width,height,null); return false; + } + } + } + }, + + + showPopWin: function(url, width, height, returnFunc, showCloseBox) { + // show or hide the window close widget + if (showCloseBox == null || showCloseBox == true) { + document.getElementById("AskbotPopCloseBox").style.display = "block"; + } else { + document.getElementById("AskbotPopCloseBox").style.display = "none"; + } + this.gPopupIsShown = true; + this.disableTabIndexes(); + this.gPopupMask.style.display = "block"; + this.gPopupContainer.style.display = "block"; + // calculate where to place the window on screen + this.centerPopWin(width, height); + + var titleBarHeight = parseInt(document.getElementById("AskbotPopupTitleBar").offsetHeight, 10); + + + this.gPopupContainer.style.width = width + "px"; + this.gPopupContainer.style.height = (height+titleBarHeight) + "px"; + + this.setMaskSize(); + + // need to set the width of the iframe to the title bar width because of the dropshadow + // some oddness was occuring and causing the frame to poke outside the border in IE6 + this.gPopFrame.style.width = parseInt(document.getElementById("AskbotPopupTitleBar").offsetWidth, 10) + "px"; + this.gPopFrame.style.height = (height) + "px"; + + // set the url + this.gPopFrame.src = url; + + this.gReturnFunc = returnFunc; + // for IE + if (this.gHideSelects == true) { + this.hideSelectBoxes(); + } + + window.setTimeout("this.setPopTitle();", 600); + }, + + centerPopWin: function(width, height) { + if (gPopupIsShown == true) { + if (width == null || isNaN(width)) { + width = this.gPopupContainer.offsetWidth; + } + if (height == null) { + height = this.gPopupContainer.offsetHeight; + } + + //var theBody = document.documentElement; + var theBody = document.getElementsByTagName("BODY")[0]; + //theBody.style.overflow = "hidden"; + var scTop = parseInt(getScrollTop(),10); + var scLeft = parseInt(theBody.scrollLeft,10); + + this.setMaskSize(); + + //window.status = gPopupMask.style.top + " " + gPopupMask.style.left + " " + gi++; + + var titleBarHeight = parseInt(document.getElementById("AskbotPopupTitleBar").offsetHeight, 10); + + var fullHeight = getViewportHeight(); + var fullWidth = getViewportWidth(); + + this.gPopupContainer.style.top = (scTop + ((fullHeight - (height+titleBarHeight)) / 2)) + "px"; + this.gPopupContainer.style.left = (scLeft + ((fullWidth - width) / 2)) + "px"; + //alert(fullWidth + " " + width + " " + gPopupContainer.style.left); + } + }, + + setMaskSize: function () { + var theBody = document.getElementsByTagName("BODY")[0]; + + var fullHeight = getViewportHeight(); + var fullWidth = getViewportWidth(); + + // Determine what's bigger, scrollHeight or fullHeight / width + if (fullHeight > theBody.scrollHeight) { + popHeight = fullHeight; + } else { + popHeight = theBody.scrollHeight; + } + + if (fullWidth > theBody.scrollWidth) { + popWidth = fullWidth; + } else { + popWidth = theBody.scrollWidth; + } + + this.gPopupMask.style.height = popHeight + "px"; + this.gPopupMask.style.width = popWidth + "px"; + }, + + hidePopWin: function (callReturnFunc) { + this.gPopupIsShown = false; + var theBody = document.getElementsByTagName("BODY")[0]; + theBody.style.overflow = ""; + this.restoreTabIndexes(); + if (this.gPopupMask == null) { + return; + } + this.gPopupMask.style.display = "none"; + this.gPopupContainer.style.display = "none"; + if (callReturnFunc == true && gReturnFunc != null) { + // Set the return code to run in a timeout. + // Was having issues using with an Ajax.Request(); + this.gReturnVal = window.frames["AskbotPopupFrame"].returnVal; + window.setTimeout('this.gReturnFunc(gReturnVal);', 1); + } + this.gPopFrame.src = this.gDefaultPage; + // display all select boxes + if (this.gHideSelects == true) { + this.displaySelectBoxes(); + } + }, + + setPopTitle: function () { + return; + if (window.frames["AskbotPopupFrame"].document.title == null) { + window.setTimeout("this.setPopTitle();", 10); + } else { + document.getElementById("AskbotpopupTitle").innerHTML = window.frames["AskbotPopupFrame"].document.title; + } + }, + + disableTabIndexes: function() { + if (document.all) { + var i = 0; + for (var j = 0; j < gTabbableTags.length; j++) { + var tagElements = document.getElementsByTagName(gTabbableTags[j]); + for (var k = 0 ; k < tagElements.length; k++) { + this.gTabIndexes[i] = tagElements[k].tabIndex; + tagElements[k].tabIndex="-1"; + i++; + } + } + } + }, + + restoreTabIndexes: function () { + if (document.all) { + var i = 0; + for (var j = 0; j < gTabbableTags.length; j++) { + var tagElements = document.getElementsByTagName(gTabbableTags[j]); + for (var k = 0 ; k < tagElements.length; k++) { + tagElements[k].tabIndex = gTabIndexes[i]; + tagElements[k].tabEnabled = true; + i++; + } + } + } + }, + + hideSelectBoxes: function () { + var x = document.getElementsByTagName("SELECT"); + + for (i=0;x && i < x.length; i++) { + x[i].style.visibility = "hidden"; + } + }, + + displaySelectBoxes: function () { + var x = document.getElementsByTagName("SELECT"); + + for (i=0;x && i < x.length; i++){ + x[i].style.visibility = "visible"; + } + } +}; + +/** + * Initializes popup code on load. + */ +// +addEvent(window, "resize", centerPopWin); +addEvent(window, "scroll", centerPopWin); +window.onscroll = centerPopWin; + + + +/** + * Makes all drop down form select boxes on the screen visible so they do not + * reappear after the dialog is closed. + * + * IE has a problem with wanting select form tags to always be the + * topmost z-index or layer. + */ +function keyDownHandler(e) { + if (AskbotWidget.gPopupIsShown && e.keyCode == 9) return false; +} + +if (!document.all) { + document.onkeypress = keyDownHandler; +} + -- cgit v1.2.3-1-g7c22