Gå til innhold

Javascript fungerer ikke på nettsted


Anbefalte innlegg

Hei.

 

 

På nettsiden min har jeg noe javascript som skal brukes til linker og slikt. Når man har musen over linken skal egentlig en boks dukke opp med informasjon, men javascript blir ikke lastes av nettleseren av en eller annen grunn.

 

Her har du javascriptet:

 

/*

Copyright 2012(c) . All rights reserved.
*/
window.addEvent("domready", function() {
   window.js_domready = (new Date).getTime();
   document.Idle = true;
   new IdleChecker(document, 30000);
 $(document).getElements(".default_menu ul li a").each(function(i) {
    if ($(i).retrieve("Menuitem")) {
	    return
    }
    var h = new Element("span", {
	    "class": "hover"
    }).set("tween", {
	    duration: 300
    }).fade("hide").inject(i);
    i.addEvents({
	    mouseenter: function(j) {
		    j.stop();
		    h.fade(0.5)
	    },
	    mouseleave: function(j) {
		    j.stop();
		    h.fade(0)
	    }
    });
    i.store("Menuitem", true)
   });
   window.MenuAddsHandler = new MenuAddsHandler(document);
   if (hasLocalStorage()) {
    new AutoUpdates()
   } else {
    $("au_status").set("html", "Browser does not support localStorage")
   }
   var d = $("profileimage");
   var a = d.getElement(".links").set("tween", {
    duration: 300
   }).fade("hide");
   var c = d.getElement(".playername").set("tween", {
    duration: 300
   }).fade("hide");
   d.addEvents({
    mouseenter: function(h) {
	    h.stop();
	    a.fade(0.8);
	    c.fade(0.8)
    },
    mouseleave: function(h) {
	    h.stop();
	    a.fade(0);
	    c.fade(0)
    }
   });
   var g = $("default_top");
   var b = g.getElement("#default_top_menu").addClass("is_ready");
   var f = g.getElement("#default_top_content").addEvent("is_ready", function() {
    b.addClass("is_ready")
   });
   b.getElements("ul li a").addEvent("click", function() {
    if (!b.hasClass("is_ready")) {
	    return false
    }
    b.removeClass("is_ready");
    loadTopContent($(this).get("rel"));
    window.last_top = $(this).get("rel");
    return false
   });
   (elm = document.body.getElement('#default_top_menu ul li a[rel="' + window.last_top + '"]')).addClass("active");
   loadTopContent(elm.get("rel"));
   $("headerSize_toggle").addEvent("change", function() {
    var i = this;
    if (i.hasClass("sending")) {
	    return
    }
    i.addClass("sending");
    $("default_header").toggleClass("header_small");
    var h = new Request({
	    url: "/game/js/ajax/headerSize_toggle.php"
    });
    h.addEvents({
	    success: function() {
		    i.removeClass("sending")
	    },
	    failure: function() {
		    alert("Kunne ikke endre headerstørrelsen.")
	    }
    });
    h.send()
   });
   document.getElements(".numbersOnly").each(function(h) {
    h.addEvent("keyup", function() {
	    var i = this.get("value").toInt();
	    if (!$chk(i)) {
		    i = 0
	    }
	    this.set("value", i)
    })
   });
   var e = $("bottombar_wrap");
   new ChatBox(e, window.bottombar_chatIsOpen);
   document.getElements(".default_menu ul").each(function(i) {
    var h = new Sortables(i);
    i.timer = false;
    h.addEvent("complete", function() {
	    $clear(i.timer);
	    i.timer = setTimeout(function() {
		    try {
			    i.xhr.cancel()
		    } catch (j) {}
		    i.xhr = new Request({
			    url: "/game/js/ajax/menuSort_change.php",
			    method: "get",
			    data: "sort=" + h.serialize()
		    }).addEvents({
			    failure: function(k) {}
		    }).send()
	    }, 1000)
    })
   });
   e.getElement("a.toggleJailLog").addEvent("click", function() {
    this.request = $empty;
    var h = this;
    this.request = new Request({
	    url: "/game/js/ajax/jailLog_toggle.php"
    });
    this.request.addEvents({
	    success: function() {
		    h.toggleClass("active")
	    },
	    failure: function() {
		    alert("Kunne ikke utføre handlingen.")
	    }
    });
    this.request.send();
    return false
   });
   check_html(document);
   window.js_inited = (new Date).getTime();
   $("js_debug").set("html", " - HTML/JS: ca. " + ((window.js_inited - window.js_start) / 1000) + " sek").setStyle("cursor", "pointer").addEvent("click", time_used)
});
window.addEvent("load", function() {
   if (window.location.hash != "") {
    window.location.hash = window.location.hash
   }
   window.isLoaded = true
});
function time_used() {
   alert("mootools: " + (js_mootools - js_start) + " ms\ndefault_loaded: " + (js_default_loaded - js_mootools) + " ms\ndomready: " + (js_domready - js_default_loaded) + " ms\ninited: " + (js_inited - js_domready) + " ms\n\nTotalt ca. " + (js_inited - js_start) + " ms")
}
function loadTopContent(a) {
   if (!["logghandlinger", "siste_melding", "spillerinfo"].contains(a)) {
    return
   }
   var c = $("default_top_content");
   c.set("html", '<p class="center" style="margin-top: 65px;"><img src="/game/images/ajax_load.gif" alt="" /></p>');
   $$("#default_top_menu ul li a").removeClass("active");
   $$('#default_top_menu ul li a[rel="' + a + '"]').addClass("active");
   var b = new Request({
    url: "/game/js/ajax/miniapps/" + a + ".php"
   });
   b.addEvents({
    success: function(d) {
	    c.set("html", d);
	    detect_counters(c);
	    c.fireEvent("is_ready")
    },
    failure: function(d) {
	    c.set("html", "<h2>En feil oppstod.</h2>")
    }
   });
   b.send()
}
function check_html(a) {
   detect_counters(a);
   detect_images(a);
   detect_boxhandle(a);
   detect_toggleHTML(a);
   detect_buttons(a);
   target_blank_links(a);
   detect_playerlinks(a)
}
function NavigateTo(a, b) {
   a = $chk(a) ? a : document.location.href;
   var c = function() {
	    document.location = a
    };
   if (document.Idle) {
    document.addEvent("active", c)
   } else {
    c.delay($chk(b) ? b : 0)
   }
   NavigateTo = $empty
}
var AutoUpdates = new Class({
   options: {
    get_interval: 10000
   },
   initialize: function() {
    this.timer = false;
    this.paused = false;
    this.statusTxt = $("au_status");
    document.addEvents({
	    active: function() {
		    a.start()
	    },
	    idle: function() {
		    a.pause()
	    }
    });
    var a = this;
    this.timer = setTimeout(function() {
	    a.getData()
    }, this.options.get_interval)
   },
   getData: function() {
    var c = $time();
    var a = localStorage.getItem("AutoUpdates_last") || 0;
    if ((a.toInt() + this.options.get_interval) > c && $chk(localStorage.getItem("AutoUpdates_last"))) {
	    this.data = localStorage.getItem("AutoUpdates_data");
	    this.handleData();
	    $clear(this.timer);
	    this.timer = false;
	    var b = this;
	    this.timer = setTimeout(function() {
		    b.getData()
	    }, this.options.get_interval)
    } else {
	    var b = this;
	    this.request = new Request({
		    url: "/game/js/ajax/autoUpdates_get.php"
	    }).addEvents({
		    success: function(d) {
			    localStorage.setItem("AutoUpdates_last", c);
			    localStorage.setItem("AutoUpdates_data", d);
			    b.data = d;
			    b.handleData();
			    $clear(b.timer);
			    b.timer = false;
			    b.timer = setTimeout(function() {
				    b.getData()
			    }, b.options.get_interval)
		    },
		    failure: function(d) {
			    b.stop()
		    }
	    }).send()
    }
   },
   handleData: function() {
    var b = JSON.decode(this.data, true);
    for (key in b) {
	    if (key == "top" && window.last_top == "spillerinfo") {
		    var a = $("default_top_content");
		    a.set("html", b[key]);
		    detect_counters(a)
	    } else {
		    if (key == "progressbars") {
			    $("progressbars").set("html", b[key])
		    } else {
			    if (key == "menuAdds") {
				    window.MenuAddsHandler.setData(b[key])
			    }
		    }
	    }
    }
   },
   start: function() {
    if (this.paused == false) {
	    return
    }
    this.paused = false;
    this.getData();
    this.statusTxt.set("html", "")
   },
   pause: function() {
    if (this.paused == true) {
	    return
    }
    this.paused = true;
    this.request.cancel();
    $clear(this.timer);
    this.timer = false;
    this.statusTxt.set("html", "- Automatiske oppdateringer pauset")
   },
   stop: function() {
    this.statusTxt.set("html", "- Automatiske oppdateringer stoppet");
    this.getData = $empty;
    $clear(this.timer);
    this.timer = false;
    this.request.cancel()
   }
});
var IdleChecker = new Class({
   opts: {
    time_check: 5000,
    time_idle: 20000
   },
   initialize: function(c, b) {
    if ($type(b) == "number") {
	    this.opts.time_idle = b
    }
    this.dom = c;
    this.timer = false;
    this.checking = false;
    var a = this;
    this.bind = function() {
	    a.activity()
    };
    this.timer = setTimeout(function() {
	    a.idle()
    }, this.opts.time_idle + this.opts.time_check);
    this.start()
   },
   start: function() {
    if (this.dom.Idle || this.checking) {
	    this.dom.addEvents({
		    mousemove: this.bind,
		    keydown: this.bind,
		    focus: this.bind
	    });
	    if (!this.dom.Idle) {
		    var a = this;
		    this.timer = setTimeout(function() {
			    a.idle()
		    }, this.opts.time_idle)
	    }
	    return
    }
    this.checking = true;
    var a = this;
    setTimeout(function() {
	    a.idle()
    }, this.opts.time_check)
   },
   activity: function() {
    this.dom.removeEvents({
	    mousemove: this.bind,
	    keydown: this.bind,
	    focus: this.bind
    });
    if (this.dom.Idle) {
	    this.dom.Idle = false;
	    this.dom.fireEvent("active")
    }
    if (this.timer) {
	    $clear(this.timer);
	    this.timer = false
    }
    this.checking = false;
    this.start()
   },
   idle: function() {
    if (this.timer) {
	    this.timer = false;
	    this.dom.Idle = true;
	    this.dom.fireEvent("idle");
	    return
    }
    this.start()
   }
});
var MenuAddsHandler = new Class({
   initialize: function(c) {
    this.dom = c;
    this.timer = false;
    var b = this;
    var a = [];
    this.elmData = a;
    this.request = new Request.JSON({
	    url: "/game/js/ajax/autoUpdates_get.php",
	    method: "get",
	    data: "get=" + window.last_top
    }).addEvents({
	    success: function(e) {
		    if ($chk(e.error)) {
			    elm.set("html", "FEIL:" + e.error)
		    } else {
			    b.setData(e.menuAdds);
			    b.update();
			    var d = $("default_top_content");
			    d.set("html", e.top);
			    detect_counters(d)
		    }
	    },
	    failure: function(d) {
		    elm.set("html", "FEIL:" + d)
	    }
    }).send()
   },
   setData: function(a) {
    a.push({
	    "class": "time",
	    data: window.server_time
    });
    this.elmData = a
   },
   update: function() {
    var b = this;
    var a = this.elmData;
    this.elmData.each(function(i, e) {
	    var k = $$(".menuad." + i["class"]);
	    var j = i.data;
	    if (i["class"] == "time") {
		    window.server_time++;
		    a[e]["data"] = window.server_time;
		    var d = new Date(j * 1000);
		    var g = d.getHours();
		    var c = d.getMinutes();
		    var f = d.getSeconds();
		    k.set("html", (g < 10 ? "0" + g : g) + ":" + (c < 10 ? "0" + c : c) + ":" + (f < 10 ? "0" + f : f))
	    } else {
		    if (["brekk_timeleft", "blackmail_timeleft", "car_theft_timeleft", "training_timeleft"].contains(i["class"])) {
			    j--;
			    a[e]["data"] = j;
			    k.set("html", (j <= 0 ? '<span style="color: #ff6600; font-weight: bold;">Klar</span>' : j + " sek"))
		    } else {
			    if (["killtime_timeleft", "bullet_timeleft", "pr_timeleft"].contains(i["class"])) {
				    j--;
				    a[e]["data"] = j;
				    if (j > 3600) {
					    k.set("html", '<span class="dark">Stengt</span>')
				    } else {
					    k.set("html", (j <= 0 ? '<span style="color: #ff6600; font-weight: bold;">Klar</span>' : j + " sek"))
				    }
			    } else {
				    k.set("html", (j > 0 ? '<span style="color: #ff6600;">' + j + "</span>" : j) + " " + (["online", "in_jail", "blackjack_num", "auction_num"].contains(i["class"]) ? "stk" : "ny" + (j != 1 ? "e" : "")))
			    }
		    }
	    }
    });
    this.elmData = a;
    this.start()
   },
   start: function() {
    this.stop();
    var a = this;
    this.timer = setTimeout(function() {
	    a.update()
    }, 1000)
   },
   stop: function() {
    if (this.timer) {
	    $clear(this.timer);
	    this.timer = false
    }
   }
});
var Countdown = new Class({
   initialize: function(a) {
    this.elem = a;
    this.num = this.elem.get("html");
    this.timer = false;
    this.down()
   },
   down: function() {
    this.num--;
    this.elem.set("html", this.num);
    if (this.num <= 0) {
	    this.stop();
	    if (this.elem.hasClass("reload") || this.elem.hasClass("reload_url")) {
		    NavigateTo(this.elem.hasClass("reload_url") ? this.elem.get("title") : document.location.href, 500)
	    } else {
		    if ($chk(this.elem.get("title"))) {
			    eval(this.elem.get("title"))
		    }
	    }
    }
    var self = this;
    this.timer = setTimeout(function() {
	    self.down()
    }, 1000)
   },
   stop: function() {
    if (this.timer) {
	    $clear(this.timer);
	    this.timer = false;
	    this.down = $empty
    }
   }
});
function detect_counters(a) {
   a.getElements(".countdown").each(function(b) {
    if ($(b).retrieve("Countdown")) {
	    return
    }
    b.store("Countdown", new Countdown(b))
   })
}
var ImageHandler = new Class({
   initialize: function(b) {
    this.elem = b;
    this.src = this.elem.get("src");
    this.noZoom = b.hasClass("noZoom");
    this.loadText = new Element("span", {
	    html: "Laster bilde...",
    }).setStyles({
	    "font-size": "10px",
	    opacity: 0.6
    }).inject(this.elem, "after");
    this.elem.destroy();
    var a = this;
    this.elem = new Asset.image(this.src, {
	    onload: function() {
		    a.handleImage()
	    }
    })
   },
   handleImage: function() {
    this.elem.inject(this.loadText, "before");
    this.loadText.destroy();
    var b = this.elem.getParent().getSize();
    this.max_width = b.x;
    this.max_height = b.y;
    this.width = this.elem.getSize().x;
    this.height = this.elem.getSize().y;
    this.width_orign = this.elem.getSize().x;
    this.height_orign = this.elem.getSize().y;
    var c = 0;
    var a = false;
    if (this.width > this.max_width) {
	    c = this.max_width / this.width;
	    this.elem.setStyles({
		    width: this.max_width,
		    height: this.height * c
	    });
	    this.height = this.height * c;
	    this.width = this.width * c;
	    a = true
    }
    if (this.height > this.max_height) {
	    c = this.max_height / this.height;
	    this.elem.setStyles({
		    height: this.max_height,
		    width: this.width * c
	    });
	    a = true
    }
    if (a == true && !this.noZoom) {
	    this.zoomable()
    }
   },
   zoomable: function() {
    this.elem.setStyle("cursor", "pointer");
    var a = new Element("img", {
	    src: this.elem.get("src")
    }).setStyles({
	    position: "absolute",
	    top: this.elem.getPosition().y - ((this.height_orign - this.elem.getSize().y) / 2) + "px",
	    left: this.elem.getPosition().x - ((this.width_orign - this.elem.getSize().x) / 2) + "px",
	    "z-index": "9999999",
	    cursor: "pointer"
    }).addEvents({
	    click: function(b) {
		    b.stop();
		    this.fade(0)
	    },
	    mouseenter: function(b) {
		    if (this.getStyle("opacity") < 0.6) {
			    return
		    }
		    b.stop();
		    this.fade(1)
	    },
	    mouseleave: function(b) {
		    if (this.getStyle("opacity") < 0.6) {
			    return
		    }
		    b.stop();
		    this.fade(0.6)
	    }
    }).set("tween", {
	    duration: "short"
    }).fade("hide").inject(document.body);
    this.elem.addEvent("click", function(b) {
	    b.stop();
	    a.fade(1)
    })
   }
});
function detect_images(a) {
   a.getElements(".handle_image").each(function(b) {
    if ($(b).retrieve("ImageHandler")) {
	    return
    }
    b.store("ImageHandler", new ImageHandler(b))
   })
}
var BoxHandleElms = {};
var BoxHandle = new Class({
   initialize: function(b, c) {
    this.wrap = b;
    this.box = c;
    this.type = this.box.get("type");
    this.elements = this.wrap.getChildren("td");
    this.box.setStyle("display", "none");
    this.elements[0].setStyles({
	    "background-position": "left",
	    "background-repeat": "no-repeat",
	    "padding-left": "23px"
    });
    this.disabled = false;
    if (this.box.get("disabled")) {
	    this.disabled = true
    }
    BoxHandleElms[this.box.get("name")] = BoxHandleElms[this.box.get("name")] || [];
    BoxHandleElms[this.box.get("name")].push(this);
    this.checked = this.box.get("checked");
    b.addEvents({
	    mouseenter: function() {
		    if (!b.hasClass("hover")) {
			    b.addClass("hover")
		    }
	    },
	    mouseleave: function() {
		    b.removeClass("hover")
	    }
    });
    if (!this.disabled) {
	    var a = this;
	    b.addEvent("click", function(d) {
		    a.click(d)
	    })
    }
    this.setBackground()
   },
   click: function(b) {
    if (["a", "input", "textarea", "select"].contains($(b.target).get("tag"))) {
	    return
    }
    this.checked = !this.checked;
    if (this.type == "radio" && this.checked && BoxHandleElms[this.box.get("name")].length > 1) {
	    var a = this;
	    BoxHandleElms[this.box.get("name")].each(function(c) {
		    if (!c.checked || c == a) {
			    return
		    }
		    c.checked = false;
		    c.check()
	    })
    }
    this.check()
   },
   check: function() {
    this.box.set("checked", this.checked);
    this.setBackground()
   },
   setBackground: function() {
    this.elements[0].setStyle("background-image", "url(/game/images/icons/" + this.type + "_" + (this.disabled ? "disabled_" : "") + "" + (this.checked ? "yes" : "no") + ".png)");
    if (this.disabled) {
	    this.wrap.addClass("disabled")
    } else {
	    if (this.checked) {
		    this.wrap.addClass("checked")
	    } else {
		    this.wrap.removeClass("checked")
	    }
    }
   }
});
function detect_boxhandle(a) {
   a.getElements(".table.boxHandle tr.boxHandle").each(function(b) {
    var c = b.getElement("input");
    if (c.retrieve("BoxHandle")) {
	    return
    }
    c.store("BoxHandle", new BoxHandle(b, c))
   })
}
function check_boxhandle(a) {
   BoxHandleElms[a].each(function(b) {
    b.checked = !b.checked;
    b.check()
   })
}
var toggleHTML = new Class({
   options: {
    fade_time: 200,
    fadeOut_delay: 1000
   },
   initialize: function(b) {
    this.elem = b;
    this.timer = false;
    this.original_html = this.elem.get("html");
    this.html = this.elem.get("rel") || this.elem.get("title");
    if ($chk(this.elem.get("title"))) {
	    this.elem.set("title", "")
    }
    if ($chk(this.html)) {
	    this.hasNewHTML = false;
	    this.elem.set("tween", {
		    duration: this.options.fade_time
	    });
	    var a = this;
	    this.elem.addEvents({
		    mouseenter: function() {
			    a.mouseEnter()
		    },
		    mouseleave: function() {
			    a.mouseLeave()
		    }
	    })
    }
   },
   mouseEnter: function() {
    $clear(this.timer);
    this.timer = false;
    if (this.hasNewHTML == true) {
	    return
    }
    this.elem.fade(0);
    var a = this;
    (function() {
	    a.elem.set("html", a.html).fade(1);
	    a.hasNewHTML = true
    }).delay(this.options.fade_time)
   },
   mouseLeave: function() {
    $clear(this.timer);
    this.timer = false;
    var a = this;
    this.timer = setTimeout(function() {
	    a.elem.fade(0);
	    (function() {
		    a.elem.set("html", a.original_html).fade(1);
		    a.hasNewHTML = false
	    }).delay(a.options.fade_time)
    }, this.options.fadeOut_delay)
   }
});
function detect_toggleHTML(a) {
   a.getElements(".toggleHTML").each(function(b) {
    if ($(b).retrieve("toggleHTML")) {
	    return
    }
    b.store("toggleHTML", new toggleHTML(b))
   })
}
var Button = new Class({
   initialize: function(c) {
    this.elem = c;
    this.over = false;
    this.html = this.elem.get("html");
    this.elem.empty();
    this.text = new Element("span", {
	    html: this.html
    }).inject(this.elem);
    var a = this;
    this.elem.addEvents({
	    mouseenter: function() {
		    a.hover()
	    },
	    mouseleave: function() {
		    a.hover()
	    }
    });
    if (this.elem.hasClass("form_submit")) {
	    var b = this.elem.getParent("form");
	    this.elem.addEvent("click", function() {
		    b.submit();
		    return false
	    })
    }
   },
   hover: function() {
    this.over = !this.over;
    if (this.over) {
	    this.elem.addClass("b_hover")
    } else {
	    this.elem.removeClass("b_hover")
    }
   },
   setText: function(a) {
    this.text.set("html", a)
   }
});
function detect_buttons(a) {
   a.getElements("a.button").each(function(b) {
    if ($(b).retrieve("Button")) {
	    return
    }
    b.store("Button", new Button(b))
   })
}
var Playerlinks_data = [];
var PlayerlinkHandler = new Class({
   options: {
    fade_time: 200,
    close_time: 500,
    offset_x: 10,
    offset_y: 10
   },
   initialize: function(b) {
    this.hasData = false;
    this.name = b.get("rel");
    var a = this;
    this.box = new Element("div", {
	    html: "Henter data...",
	    "class": "tooltip_box",
	    tween: {
		    duration: this.options.fade_time
	    },
	    style: "width: 300px; opacity: 0.9"
    }).fade("hide").addEvents({
	    mouseenter: function() {
		    $clear(a.timer)
	    },
	    mouseleave: function() {
		    a.hideBox()
	    }
    }).inject(document.body);
    this.box_visible = false;
    $(b).addEvents({
	    click: function(d) {
		    if (a.box_visible) {
			    return
		    }
		    d.stop();
		    a.page = d.page;
		    a.showBox();
		    if (!a.hasData) {
			    if (Playerlinks_data[a.name]) {
				    a.setBoxContent(Playerlinks_data[a.name])
			    } else {
				    try {
					    a.xhr.cancel()
				    } catch (c) {}
				    a.xhr = new Request({
					    url: "/game/js/ajax/playerdata.php",
					    method: "get",
					    data: "name=" + a.name
				    }).addEvents({
					    success: function(e) {
						    Playerlinks_data[a.name] = e;
						    a.setBoxContent(e)
					    },
					    failure: function() {
						    a.setBoxContent("Kunne ikke hente spillerdata.")
					    }
				    }).send()
			    }
		    }
	    },
	    mouseenter: function() {
		    $clear(a.timer)
	    },
	    mouseleave: function() {
		    a.hideBox()
	    }
    })
   },
   showBox: function() {
    this.box.setPosition({
	    x: this.page.x + this.options.offset_x,
	    y: this.page.y + this.options.offset_y
    });
    this.box_visible = true;
    this.box.fade(0.95)
   },
   hideBox: function() {
    $clear(this.timer);
    var a = this;
    this.timer = setTimeout(function() {
	    a.box_visible = false;
	    a.box.fade(0)
    }, this.options.close_time)
   },
   setBoxContent: function(a) {
    this.box.empty().set("html", a);
    check_html(this.box)
   }
});
function detect_playerlinks(a) {
   a.getElements(".playerlink").each(function(b) {
    if ($(b).retrieve("PlayerlinkHandler") || b.hasClass("noToolTip")) {
	    return
    }
    b.store("PlayerlinkHandler", new PlayerlinkHandler(b))
   })
}
var ChatBox = new Class({
   options: {
    get_interval: 5000
   },
   initialize: function(c, b) {
    this.bar_wrap = c;
    this.posts_wrap = this.bar_wrap.getElement(".posts");
    this.new_posts = new Element("div").inject(this.posts_wrap, "top");
    this.post_result = this.bar_wrap.getElement("p.post_result").set("tween", {
	    duration: 300
    }).fade("hide");
    this.chatIsOpen = b;
    this.last_get = 0;
    this.hasData = false;
    if (this.chatIsOpen) {
	    this.last_get = window.server_time;
	    this.hasData = true
    }
    this.paused = false;
    this.timer = false;
    var a = this;
    this.bar_wrap.getElement("ul.nav a.toggleChat").addEvent("click", function() {
	    a.bar_wrap.getElement(".chat_wrap").toggleClass("hidden");
	    a.chatIsOpen = !a.chatIsOpen;
	    a.req = $empty;
	    a.req = new Request({
		    url: "/game/js/ajax/chat_toggle.php"
	    }).send();
	    this.appendTo = "top";
	    if (a.chatIsOpen && !a.hasData) {
		    this.appendTo = "bottom";
		    a.getMessages()
	    } else {
		    if (a.chatIsOpen) {
			    a.getMessages(true)
		    } else {
			    a.pause()
		    }
	    }
	    return false
    });
    this.bar_wrap.getElement("form").addEvent("submit", function(d) {
	    new Event(d).stop();
	    a.post_result.fade("hide").set("html", "Vennligst vent...").fade(1);
	    a.postMessage(this.getElement("textarea").value)
    });
    document.addEvents({
	    active: function() {
		    a.start()
	    },
	    idle: function() {
		    a.pause()
	    }
    });
    if (this.chatIsOpen) {
	    this.timer = setTimeout(function() {
		    a.getMessages(true)
	    }, this.options.get_interval)
    }
   },
   getMessages: function(a) {
    if (a > 0) {
	    this.appendTo = "top"
    }
    this.hasData = true;
    $clear(this.timer);
    this.timer = false;
    var b = this;
    this.xhr = new Request.JSON({
	    url: "/game/js/ajax/chat_get.php",
	    method: "get",
	    data: "time=" + (a == true ? this.last_get : 0)
    });
    this.xhr.addEvents({
	    success: function(c) {
		    if ($chk(c.error)) {
			    b.stop()
		    } else {
			    b.last_get = window.server_time;
			    c.each(function(d) {
				    b.appendMessage(d)
			    });
			    b.timer = setTimeout(function() {
				    b.getMessages(true)
			    }, b.options.get_interval)
		    }
	    },
	    failure: function() {
		    b.stop()
	    }
    });
    this.xhr.send()
   },
   appendMessage: function(a) {
    new Element("div", {
	    html: a,
	    "class": "post"
    }).set("tween", {
	    duration: 600
    }).fade("hide").inject(this.new_posts, this.appendTo).fade(1)
   },
   postMessage: function(b) {
    b = b.trim();
    if (this.last_write + 4000 > (new Date).getTime()) {
	    this.post_result.fade("hide").set("html", "Må vente litt...").fade(1)
    } else {
	    if (b.length < 2) {
		    this.post_result.fade("hide").set("html", "Minst 2 tegn").fade(1)
	    } else {
		    if (b.length > 500) {
			    this.post_result.fade("hide").set("html", "Maks 500 tegn").fade(1)
		    } else {
			    this.last_write = (new Date).getTime();
			    var a = this;
			    this.xhr = $empty;
			    this.xhr = new Request.JSON({
				    url: "/game/js/ajax/chat_post.php",
				    method: "get",
				    data: "text=" + b
			    });
			    this.xhr.addEvents({
				    success: function(c) {
					    if ($chk(c.error)) {
						    a.stop()
					    } else {
						    a.bar_wrap.getElement("form textarea").value = "";
						    a.post_result.fade("hide").set("html", "Du har skrevet i chatten").fade(1)
					    }
				    },
				    failure: function() {
					    a.stop()
				    }
			    });
			    this.xhr.send()
		    }
	    }
    }
   },
   start: function() {
    if (!this.paused) {
	    return
    }
    this.getMessages(true)
   },
   pause: function() {
    if (this.paused) {
	    return
    }
    $clear(this.timer);
    this.timer = false;
    this.xhr.cancel()
   },
   stop: function() {
    this.getMessages = $empty;
    $clear(this.timer);
    this.timer = false;
    this.request.cancel()
   }
});
function target_blank_links(a) {
   a.getElements('a[rel="target:blank"]').each(function(b) {
    if ($(b).retrieve("Target_blank")) {
	    return
    }
    b.store("Target_blank", true);
    b.set("target", "_blank")
   })
}
function number_format(f, c, h, e) {
   var b = !isFinite(+f) ? 0 : +f,
    a = !isFinite(+c) ? 0 : Math.abs(c),
    j = (typeof e === "undefined") ? "," : e,
    d = (typeof h === "undefined") ? "." : h,
    i = "",
    g = function(o, m) {
	    var l = Math.pow(10, m);
	    return "" + Math.round(o * l) / l
    };
   i = (a ? g(b, a) : "" + Math.round(b)).split(".");
   if (i[0].length > 3) {
    i[0] = i[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, j)
   }
   if ((i[1] || "").length < a) {
    i[1] = i[1] || "";
    i[1] += new Array(a - i[1].length + 1).join("0")
   }
   return i.join(d)
}
function hasLocalStorage() {
   try {
    return "localStorage" in window && window.localStorage !== null
   } catch (a) {
    return false
   }
}
var js_default_loaded = (new Date).getTime();

 

Har prøvd å feilsøke via Inspiser Element i Chrome, og da får jeg opp at det er noe feil med GetElements.. skjønner ikke helt hvorfor men. Takk for svar på forhånd :)

 

- Kristoffer

Lenke til kommentar
Videoannonse
Annonse

Hvorfor poster du et javascript-spørsmål i java-forumet? (java har ingenting med javascript å gjøre).

 

Du har mye kode her, veldig vanskelig å feilsøke bare ved å titte over koden. Kan du ikke poste en link til sida di eller lag en jsfiddle ( http://jsfiddle.net/ ).

 

Er dette kode du har funnet en annen plass? Har du lasta inn prototype.js?

Endret av dabear
Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
×
×
  • Opprett ny...