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(){
if(document.getElementById("wrap700")) {
document.getElementById("wrap700").style.width = (document.documentElement.clientWidth < 750)
? "750px"
: "100%";
}
if(document.getElementById("wrap400")) {
document.getElementById("wrap400").style.width = (document.documentElement.clientWidth < 450)
? "450px"
: "100%";
}
};
function mkwidth(){ window.attachEvent('onload', mkwidth);
if(document.getElementById("wrap700")) { window.attachEvent('onresize', mkwidth);
document.getElementById("wrap700").style.width = document.documentElement.clientWidth < 750 ? "750px" : "100%"; })(window, document);
}
if(document.getElementById("wrap400")) {
document.getElementById("wrap400").style.width = document.documentElement.clientWidth < 450 ? "450px" : "100%";
}
};

View File

@ -16,64 +16,67 @@
* 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){
$("#background-popup").fadeOut("slow");
$("#dashboard-locales-popup").fadeOut("slow");
popupStatus = 0;
}
}
function normpos(a) { var disablePopup = function(){
if(a < 10) { if(isPopupOpened){
return 10; $("#background-popup").fadeOut("slow");
} $("#dashboard-locales-popup").fadeOut("slow");
return a; isPopupOpened = false;
} }
}
function centerPopup(){ var normalizePosition = function(a) {
var windowWidth = document.documentElement.clientWidth; if(a < 10) {
var windowHeight = document.documentElement.clientHeight; return 10;
var popupHeight = $("#dashboard-locales-popup").height(); }
var popupWidth = $("#dashboard-locales-popup").width(); return a;
$("#dashboard-locales-popup").css({ }
"position": "absolute",
"top": normpos((windowHeight-popupHeight) * 0.2),
"left": normpos(windowWidth/2-popupWidth/2)
});
$("#background-popup").css({
"height": windowHeight
});
}
$(function(){ var centerPopup = function(){
$("#change-language").click(function(){ var windowWidth = document.documentElement.clientWidth;
centerPopup(); var windowHeight = document.documentElement.clientHeight;
loadPopup(); var popupHeight = $("#dashboard-locales-popup").height();
return false; var popupWidth = $("#dashboard-locales-popup").width();
}); $("#dashboard-locales-popup").css({
$("#dashboard-locales-popup-close").click(function(){ "position": "absolute",
disablePopup(); "top": normalizePosition((windowHeight-popupHeight) * 0.2),
return false; "left": normalizePosition(windowWidth/2-popupWidth/2)
}); });
$("#background-popup").click(function(){ $("#background-popup").css({
disablePopup(); "height": windowHeight
}); });
$(document).keypress(function(e){ }
if(e.keyCode==27 && popupStatus==1){
disablePopup(); $(function(){
} $("#change-language").click(function(){
}); centerPopup();
}); loadPopup();
return false;
});
$("#dashboard-locales-popup-close").click(function(){
disablePopup();
return false;
});
$("#background-popup").click(function(){
disablePopup();
});
$(document).keypress(function(e){
if(e.keyCode == 27 && isPopupOpened){
disablePopup();
}
});
});
})(jQuery, document);