// Using this page's URL as namespace for commands specific to this
// application (stripping trailing '#' if present)
window.onLoad=function(){
// alert(1);
}
function stripUriFragment(uri) {
var hashPos = uri.lastIndexOf('#');
return (hashPos != -1 ? uri.slice(0, hashPos) : uri);
}
var ns_app = stripUriFragment(window.location.href);
// Watch
for incoming stanzas
function init(event) {
// alert("init being called");
document.getElementById('xmpp-incoming').addEventListener(
'DOMNodeInserted', function(event) {
receivedStanza(new XML(event.target.textContent));
}, false);
}
function init2(){
if(location.href=='http://solar.edu.ms/magic.html')
return;
// alert("init2 being called");
document.addEventListener('click', function(event) {
// alert("link clicked");
if(event.target.toString().indexOf("http") == 0){
document.parent.clickedAdd(event.target.toString());
}
}, false);
}
// When user clicks on "Add Note", create an
command
function clickedAdd(sendurl) {
// var editor = document.getElementById('editor');
// alert("clickedAdd is called");
sendCommand({sendurl});
// editor.value = '';
}
// Wrap a command in a
// and delivers it by writing in
function sendCommand(command) {
var message = {command};
// alert(message);
document.getElementById('xmpp-outgoing').textContent = message.toXMLString();
// alert('passed tostring');
//alert(document.getElementById('xmpp-outgoing').textContent);
}
// Reacts on a received XMPP stanza
function receivedStanza(stanza) {
// alert('recieved stanza');
if(stanza.name().localName == 'message') {
var command = stanza;
//alert(command[0].add);
execute(command);
}
}
// Performs a command (in this case, create a
element to display a note)
function execute(command) {
// alert(command[0].add);
/* switch(command.name().localName) {
case 'add':
// var note = document.createElement('li');
//note.textContent = command[0];
//document.getElementById('notes').appendChild(note);
// code here to open it inside the iframe
document.getElementById('frameWindow').src = command[0].add;
break;
} */
document.getElementById('frameWindow').src = command[0].add;
}
init2();