Clean up JS in the default page style

This commit is contained in:
Dmitriy Simushev 2014-12-18 13:20:35 +00:00
parent a72a602120
commit 506425a9e1
2 changed files with 76 additions and 67 deletions

View File

@ -16,14 +16,20 @@
* limitations under the License. * limitations under the License.
*/ */
window.attachEvent('onload', mkwidth); (function(window, document) {
window.attachEvent('onresize', mkwidth); var mkwidth = function(){
function mkwidth(){
if(document.getElementById("wrap700")) { if(document.getElementById("wrap700")) {
document.getElementById("wrap700").style.width = document.documentElement.clientWidth < 750 ? "750px" : "100%"; document.getElementById("wrap700").style.width = (document.documentElement.clientWidth < 750)
? "750px"
: "100%";
} }
if(document.getElementById("wrap400")) { if(document.getElementById("wrap400")) {
document.getElementById("wrap400").style.width = document.documentElement.clientWidth < 450 ? "450px" : "100%"; document.getElementById("wrap400").style.width = (document.documentElement.clientWidth < 450)
? "450px"
: "100%";
} }
}; };
window.attachEvent('onload', mkwidth);
window.attachEvent('onresize', mkwidth);
})(window, document);

View File

@ -16,49 +16,51 @@
* limitations under the License. * limitations under the License.
*/ */
var popupStatus = 0; (function($, document) {
var isPopupOpened = false;
function loadPopup(){ var loadPopup = function(){
if(popupStatus==0){ if(!isPopupOpened){
$("#background-popup").css({ $("#background-popup").css({
"opacity": "0.7" "opacity": "0.7"
}); });
$("#background-popup").fadeIn("slow"); $("#background-popup").fadeIn("slow");
$("#dashboard-locales-popup").fadeIn("slow"); $("#dashboard-locales-popup").fadeIn("slow");
popupStatus = 1; isPopupOpened = true;
} }
} }
function disablePopup(){
if(popupStatus==1){ var disablePopup = function(){
if(isPopupOpened){
$("#background-popup").fadeOut("slow"); $("#background-popup").fadeOut("slow");
$("#dashboard-locales-popup").fadeOut("slow"); $("#dashboard-locales-popup").fadeOut("slow");
popupStatus = 0; isPopupOpened = false;
}
} }
}
function normpos(a) { var normalizePosition = function(a) {
if(a < 10) { if(a < 10) {
return 10; return 10;
} }
return a; return a;
} }
function centerPopup(){ var centerPopup = function(){
var windowWidth = document.documentElement.clientWidth; var windowWidth = document.documentElement.clientWidth;
var windowHeight = document.documentElement.clientHeight; var windowHeight = document.documentElement.clientHeight;
var popupHeight = $("#dashboard-locales-popup").height(); var popupHeight = $("#dashboard-locales-popup").height();
var popupWidth = $("#dashboard-locales-popup").width(); var popupWidth = $("#dashboard-locales-popup").width();
$("#dashboard-locales-popup").css({ $("#dashboard-locales-popup").css({
"position": "absolute", "position": "absolute",
"top": normpos((windowHeight-popupHeight) * 0.2), "top": normalizePosition((windowHeight-popupHeight) * 0.2),
"left": normpos(windowWidth/2-popupWidth/2) "left": normalizePosition(windowWidth/2-popupWidth/2)
}); });
$("#background-popup").css({ $("#background-popup").css({
"height": windowHeight "height": windowHeight
}); });
} }
$(function(){ $(function(){
$("#change-language").click(function(){ $("#change-language").click(function(){
centerPopup(); centerPopup();
loadPopup(); loadPopup();
@ -72,8 +74,9 @@ $(function(){
disablePopup(); disablePopup();
}); });
$(document).keypress(function(e){ $(document).keypress(function(e){
if(e.keyCode==27 && popupStatus==1){ if(e.keyCode == 27 && isPopupOpened){
disablePopup(); disablePopup();
} }
}); });
}); });
})(jQuery, document);