Subversion Repositories wimsdev

Rev

Rev 17748 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 17748 Rev 17770
Line 4... Line 4...
4
function add_interaction(){
4
function add_interaction(){
5
    var elements = $("div.element");
5
    var elements = jQuery("div.element");
6
    elements.each(function(i, elt){
6
    elements.each(function(i, elt){
7
        elt = $(elt);
7
        elt = jQuery(elt);
8
        elt.css("cursor", "help");
8
        elt.css("cursor", "help");
9
        var symbol = elt.find(".symbol").text();
9
        var symbol = elt.find(".symbol").text();
10
        var Z = elt.find(".Z").text();
10
        var Z = elt.find(".Z").text();
11
        var mass = elt.find(".mass").text();
11
        var mass = elt.find(".mass").text();
12
        var struct = elt.find(".struct").html();
12
        var struct = elt.find(".str0").html();
13
        elt.click(
13
        elt.click(
14
            function make_callback(o){
14
            function make_callback(o){
15
                return function (evt){
15
                return function (evt){
16
                    var x = elt.css("top"), y = elt.css("top");
16
                    var x = elt.css("top"), y = elt.css("top");
17
                    o.html(""); /* erase all previous contents */
17
                    o.html(""); /* erase all previous contents */
18
                    var p;
18
                    var p;
19
                    p = $("<p>").text("Element: " + symbol);
19
                    p = jQuery("<p>").text("Element: " + symbol);
20
                    o.append(p);
20
                    o.append(p);
21
                    p = $("<p>").text("Atomic number: " + Z);
21
                    p = jQuery("<p>").text("Atomic number: " + Z);
22
                    o.append(p);
22
                    o.append(p);
23
                    p = $("<p>").text("Molar mass: " + mass);
23
                    p = jQuery("<p>").text("Molar mass: " + mass);
24
                    o.append(p);
24
                    o.append(p);
25
                    p = $("<p>").html("Electronic structure: " + struct);
25
                    p = jQuery("<p>").html("Electronic structure: " + struct);
26
                    o.append(p);
26
                    o.append(p);
27
                    o.dialog();
27
                    o.dialog();
28
                    var top = parseInt(elt.css("top"));
28
                    var top = evt.clientY;
29
                    if (top > 250){
29
                    if (top > 250){
30
                        /* the element is low enough, let us animate above */
30
                        /* the element is low enough, let us animate above */
31
                        top -= 250;
31
                        top -= 250;
32
                    } else {
32
                    } else {
33
                        top += 60;
33
                        top += 60;
34
                    }
34
                    }
35
                    var left = parseInt(elt.css("left"));
35
                    var left = evt.clientX;
36
                    if (left > 320){
36
                    if (left > 340){
37
                        /* the element is right enough, let us go to the left */
37
                        /* the element is right enough, let us go to the left */
38
                        left -= 320;
38
                        left -= 340;
39
                    } else{
39
                    } else{
40
                        left +=50;
40
                        left +=50;
41
                    }          
41
                    }          
42
                    o.parents(".ui-dialog").animate(
42
                    o.parents(".ui-dialog").animate(
43
                        {top: top+"px", left: left+"px"});
43
                        {top: top+"px", left: left+"px"});
44
                }
44
                }
45
            }($("#one_element")));
45
            }(jQuery("#one_element")));
46
    });
46
    });
47
    $("#wait").fadeOut();
47
    jQuery("#wait").fadeOut();
48
}
48
}
49
 
49
 
50
/**
50
/**
51
 * imports jQuery (JS), jQuery-UI (JS and CSS)
51
 * imports jQuery (JS), jQuery-UI (JS and CSS)
52
 * parametes url1 .. url3 are for jquery.js, jquery-ui.js, jquery-ui.css
52
 * parametes url1 .. url3 are for jquery.js, jquery-ui.js, jquery-ui.css