AnnoCPAN

 view release on metacpan or  search on metacpan

html/show.js  view on Meta::CPAN

window.onload = init;

var Req;
var Form;
var Please_Wait;
var Hidden_Note;
var Edit_Buttons;
var Note_Links = [];
var Move_Msg;

function init() {
    Form = document.getElementById('noteform');
    Edit_Buttons = document.getElementById('edit_buttons');
    Form.save_button.onclick = save_note;
    Form.del_button.onclick  = delete_note;
    Form.hide_button.onclick = hide_note;

    Move_Msg = document.createElement('div');
    Move_Msg.innerHTML = "Moving note... please select destination";

    Please_Wait = document.getElementById('plswait');
    init_buttons(document);
}

function init_buttons(node) {
    var links = node.getElementsByTagName('a'); 
    for (var i = 0; i < links.length; i++) {
        var link    = links[i];
        var mode    = '';
        var note    = '';
        var notepos = '';
        var section = '';
        if (link.className == "cb") { // create
            mode = 'create';
            note = link;
            Note_Links.push(link);
            section = link.href.match(/section=(\d+)/)[1];
        } else if (link.className.match(/button/) 
            && (link.href.match(/mode=edit/))) 
        { // edit
            mode = 'edit';
            note = link.parentNode.parentNode.parentNode;
            notepos = link.href.match(/notepos=(\d+)/)[1];
        } else if (link.className.match(/button/) 
            && (link.href.match(/mode=move/))) 
        { // move
            note    = link.parentNode.parentNode.parentNode;
            notepos = link.href.match(/notepos=(\d+)/)[1];
            link.onclick = move_link_onclick('move', note, notepos);
        }

        if (mode) {
            link.onclick = edit_link_onclick(mode, note, notepos, section);
        } 
    }
    var help_link = document.getElementById('note_help_link');
    help_link.onclick = function () {
        window.open('/note_help', 'ac_help', 'width=500,height=450,resizable=yes,scrollbars=yes').focus();
        return false;
    }
}

// Shows the form when user clicks on edit or create note button
function edit_link_onclick (mode, note, notepos, section) {
    return function () {
        // move form here and show it
        if (Hidden_Note) {
            Hidden_Note.style.display = mode == 'create' ? 'inline' : 'block';
        }
        // alert('note='+note); return false;
        Hidden_Note = note;
        note.parentNode.insertBefore(Form, note);
        note.parentNode.insertBefore(Please_Wait, note);
        Form.notepos.value = notepos; 
        Form.section.value = section;
        if (mode == 'create') {
            Hidden_Note.style.display = "none";
            Form.style.display = "block";
            Form.note_text.value = ''; // XXX - may cause lost text
            Edit_Buttons.style.display = 'none';
            Form.note_text.focus();
        } else if (mode == 'edit') {
            set_note_plaintext(notepos);
            Edit_Buttons.style.display = 'inline';
        } else {
            alert('there is a mysterious bug');
        }
        return false;
    }
}

function move_link_onclick(mode, note, notepos) {
    return function() {
        if (Hidden_Note) {
            Hidden_Note.style.display = mode == 'create' ? 'inline' : 'block';
        }
        Hidden_Note = note;
        Hidden_Note.style.display = "none";
        // XXX
        note.parentNode.insertBefore(Move_Msg, note);

        for (var i = 0; i < Note_Links.length; i++) {
            var link = Note_Links[i];
            if (link.parentNode == note.parentNode) {  
                // hide
            }
            link.firstChild.src="/img/move_to.gif";
            link.firstChild.title="Move note here";
            link.onclick_create = link.onclick; // XXX
            link.onclick = move_note(notepos);
        }
        return false;
    }
}

function post_xml(url, data, on_success) {
    Req = getXMLHTTP();
    if (!Req) {
        Form.mode.value = 'save';
        return true;
    }
    Req.onreadystatechange = processReqChange(on_success);
    Req.open("POST", url, true);
    Req.send(data);
    Form.style.display = 'none';
    Please_Wait.style.display = 'block';
    return false;
}

function getXMLHTTP(){
  var A=null;
  try{
    A=new ActiveXObject("Msxml2.XMLHTTP")
  }catch(e){
    try{
      A=new ActiveXObject("Microsoft.XMLHTTP")
    } catch(oc){
      A=null
    }
  }
  if(!A && typeof XMLHttpRequest != "undefined") {
    A=new XMLHttpRequest()



( run in 0.783 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )