1 var clickmap = function( args ) {
6 var fn_buildMarker = function( x, y, pos, annotation ) {
7 var legendItem = $("<li class='legend-item'><b>" + pos + "</b> " + decodeURIComponent(annotation) + "</li>");
8 $(".legend .body ul").append( legendItem );
10 var marker = $(".marker-template").clone();
11 marker.attr("data-x", x).attr("data-y", y).attr("data-pos", pos).attr("id", new Date().getTime() ).attr("class", "marker")
12 .attr("style", "left:" + x + "px; top:" + y + "px;" )
13 .find("span.count").text( pos );
14 marker.mouseenter( function() { f = true; } )
15 .mouseleave( function() { f = false; } )
16 .attr("title", annotation ? decodeURIComponent(annotation) : "" )
18 .click( function() { $(this).remove(); legendItem.remove(); f = false; } );
22 var fn_isnumber = function(num) { return !isNaN( parseInt( num ) ); }
24 var fn_clear = function() {
25 $(".marker").remove();
26 $(".legend-item").remove();
30 var fn_load = function( container, val ) {
33 var coordinates = val.split("}");
34 for ( var i = 0; i < coordinates.length; i++ ) {
35 var coordinate = coordinates[i];
37 var info = coordinate.split("^");
38 var x = info[0]; var y = info[1]; var label = info[2]; var detail = info[3];
39 var marker = fn_buildMarker( x, y, label, detail );
40 container.append(marker);
41 if ( fn_isnumber(label) ) {
42 counter = parseInt(label);
48 var fn_save = function() {
50 $(".marker").each( function() {
52 val += marker.attr("data-x") + "^" + marker.attr("data-y") + "^" + marker.attr("data-pos") + "^" + encodeURIComponent(marker.attr("title")) + "}";
54 $("#data").attr("value", val);
55 $("#submitForm").submit();
60 var dropdownOptions = args.dropdownOptions;
61 var options = dropdownOptions.options;
62 var optionsLabel = dropdownOptions.label;
63 var container = args.container;
65 var hideNav = args.hideNav;
67 container.mousemove( function() { f = true; });
70 container.click ( function(e) {
72 var x = e.pageX - this.offsetLeft - 5;
73 var y = e.pageY - this.offsetTop - 5;
74 var dialog = $( ".dialog-form" ).clone();
75 dialog.find(".label").val( counter + 1 );
76 var hasOptions = typeof(options) != "undefined";
78 dialog.find("label[for='options']").text( typeof(optionsLabel) != "undefined" ? optionsLabel : "Select one" );
79 var select = dialog.find("select[name='options']");
80 for ( var attr in options ) {
81 if ( options.hasOwnProperty(attr) ) {
82 select.append("<option value='" + attr + "'>" + options[attr] + "</option>");
86 dialog.find("label[for='options']").remove();
87 dialog.find("select[name='options']").remove();
90 var do_marker = function() {
92 var newcounter = dialog.find(".label").val();
93 var notes = encodeURIComponent(dialog.find(".detail").val());
94 var selectedOption = encodeURIComponent(dialog.find("select[name='options']").val());
95 var combinedNotes = "";
96 if ( selectedOption) {
97 combinedNotes = options[selectedOption];
99 if ( selectedOption && notes ) {
100 combinedNotes += "%3A%20";
103 combinedNotes += notes;
106 var marker = fn_buildMarker( x, y, newcounter, combinedNotes );
107 container.append(marker);
108 if ( fn_isnumber(newcounter) ) { counter++; }
114 title: "Information",
115 autoOpen: false, height: hasOptions? 345 : 300, width: 350, modal:true,
116 open: function() { dialog.find(".detail").focus(); },
118 "Save": function() { dialog.saved = true; $(this).dialog("close"); },
119 "Cancel": function() { $(this).dialog("close"); }
123 dialog.dialog("open");
127 var btn_clear = $("#btn_clear");
128 btn_clear.click( fn_clear );
130 var btn_save = $("#btn_save");
131 btn_save.click( fn_save );
133 fn_load( container, data );