MediaWiki:Skin/Projekt:Adventure2/lib.js
Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
// A2lib
a2 = {};
a2.events = {};
a2.clearScope = function clearScope(sc) {
delete a2.events[sc];
};
a2.registerEventHandler = function registerEventHandler(e) {
var sc = (e.scope[0] == "page") ? ":page:" : e.scope[1];
if (!a2.events[sc])
a2.events[sc]={};
for(var i=0; i<e.trigger.length; i++){
var tr = e.trigger[i];
if (!a2.events[sc][tr])
a2.events[sc][tr] = [];
a2.events[sc][tr].push(function(){
a2.log("run", e.name);
if (e.condition())
e.action();
});
}
};
if (window.console && window.console.log)
a2.log = window.console.log;
else
a2.log = function () {return;};
a2.fireEvent = function fireEvent (event) {
a2.log("Fire", event);
var e = a2.events;
for(i in e)
try {
for(j=0; j<e[i][event].length; j++){
a2.log("Event", i, event, j, e[i][event][j]);
e[i][event][j]();
}
} catch (e) {
a2.log("Event Exception", e);
}
};
a2.loadPage = function loadPage(n){
a2.clearScope(":page:");
a2.fireEvent("leave."+a2.cpage);
response = $.ajax({
url: "/index.php/Kamel:J*/Test2/"+parseInt(n)+"?action=render",
async: false
});
a2.cpage = n;
$content = $(response.responseText)
$content.append('<scr'+'ipt type="text/javascript">setTimeout(function(){a2.fireEvent("enter."+a2.cpage);}, 100);</scr'+'ipt>');
$("#a2image").empty().append($content);
console.log($("#a2image a"));
$("#a2image area").click(function (ev) {
a2.fireEvent("click."+ev.target.hash.substr(1));
return false;
});
$("#a2image area[href='#_L']").css('cursor','url("/images/4/41/Leftarrow.png") 0 15, w-resize');
$("#a2image area[href='#_R']").css('cursor','url("/images/b/b9/Rightarrow.png") 30 15, e-resize');
$("#a2image area[href='#_U']").css('cursor','url("/images/3/37/Uparrow.png") 15 0, n-resize');
$("#a2image area[href='#_D']").css('cursor','url("/images/6/62/Downarrow.png") 15 30, s-resize');
$("#a2image area").droppable({
drop: function (event, ui) {
a2.fireEvent("apply."+ui.draggable.attr("data.item")+"."+this.hash.substr(1));
}
});
};
a2.util = {
print: function (s) {
$("#a2text").text(s);
},
goto: function (p) {
a2.loadPage(p);
}
};
a2.items = {};
a2.loadItem = function loadItem(n){
a2.log("load", n);
a2.clearScope(n);
response = $.ajax({
url: "/index.php/Kamel:J*/Test2/item/"+n+"?action=render",
async: false
});
a2.items[n] = response.responseText;
a2.log(a2.items);
a2.renderItems();
};
a2.renderItems = function renderItems(){
$("#a2items").empty()
for (item in a2.items){
$fl=$('<div style="float:left;" class="a2item" />');
$fl.append(a2.items[item]);
$("#a2items").append($fl);
$fl.draggable({
revert: true,
zIndex: 10000,
start: function(event, ui) {
ui.helper.bind("click.prevent", function(event) { event.preventDefault(); });
},
stop: function(event, ui) {
setTimeout(function(){ui.helper.unbind("click.prevent");}, 300);
}
});
$fl.click(function () {a2.fireEvent("activate."+item);});
$fl.attr("data.item",item);
$fl.droppable({
drop: function (event, ui) {
a2.fireEvent("combine."+ui.draggable.attr("data.item")+"."+$(this).attr("data.item"));
return false;
}
});
a2.log($("#a2items"))
}
}
a2.util.add = function add (i) {
a2.loadItem(i);
};
a2.util.remove = function remove(i) {
delete a2.items[i];
delete a2.events[i];
a2.renderItems();
};