source: main/trunk/greenstone2/macros/seaweed.dm@ 23500

Last change on this file since 23500 was 23500, checked in by davidb, 11 years ago

needed to change window.addEventListener to document.addEventListener

File size: 4.8 KB
Line 
1package Global
2
3_seaweed_ {
4
5
6<!--
7.editable-metadata \{ background-color: \#ffffd0 \}
8.editable-text \{ background-color: \#e0ffe0 \}
9-->
10
11<style type="text/css">
12
13span.editable-metadata \{
14 position:relative; /*this is the key*/
15 z-index:24;
16\}
17
18div.editable-text \{
19 position:relative; /*this is the key*/
20 z-index:24;
21\}
22
23span.tooltip \{ display: none \}
24
25</style>
26
27
28<script type="text/javascript" src="_httpscript_/seaweed.js"></script>
29<script type="text/javascript" src="_httpscript_/gsajaxapi.js"></script>
30
31
32<script type="text/javascript">
33
34 function gsdefined(val)
35 \{
36 return (typeof(val) != "undefined");
37 \}
38
39 var tooltipParentElem = null;
40
41 function showTooltip(elem)
42 \{
43
44 if (de.getEditedElements) \{
45
46 // guard against getEditedElements() not being defined
47 // this can happen if we get a onmouseover event
48 // before the document is fully loaded
49
50 var editedHashSet = de.getEditedElements();
51
52 if (editedHashSet.contains(elem)) \{
53 return;
54 \}
55 \}
56
57 elem.style.zIndex="25";
58
59 var metaname = elem.getAttribute("metaname");
60 var tooltip = document.createElement("span");
61 tooltip.setAttribute("class","tooltip");
62 tooltip.setAttribute("id","tooltip");
63
64 tooltip.style.position = "absolute";
65 tooltip.style.zIndex = "26";
66 tooltip.style.top = "0.9em";
67 tooltip.style.left = "1em";
68 tooltip.style.height = "1.1em";
69 tooltip.style.border = "1px solid #660";
70 tooltip.style.backgroundColor = "#ffffe0";
71 tooltip.style.color = "\#000";
72 //tooltip.style.textAlign = "center";
73 tooltip.style.padding = "0.2em";
74
75 tooltip.innerHTML = "<nobr>Click (and then type) to edit <i>" + metaname + "</i> metadata</nobr>";
76
77 tooltipParentElem = elem;
78 setTimeout("delayedShowTooltip()", 2000);
79 elem.appendChild(tooltip);
80
81 \}
82
83 function delayedShowTooltip()
84 \{
85 if (tooltipParentElem!=null) \{
86
87 if (de.getEditedElements) \{
88 var editedHashSet = de.getEditedElements();
89
90 if (editedHashSet.contains(tooltipParentElem)) \{
91 tooltipParentElem = null;
92 return;
93 \}
94 \}
95
96 var tooltip = document.getElementById("tooltip");
97 tooltip.style.display = "block";
98 setTimeout("delayedHideTooltip()", 5000);
99 \}
100 \}
101
102
103 function hideTooltip(elem)
104 \{
105 var tooltip = document.getElementById("tooltip");
106 if (tooltip != null) \{
107 elem.removeChild(tooltip)
108 tooltip.style.display = "none";
109 \}
110
111 tooltipParentElem = null;
112
113 elem.style.zIndex="24";
114 \}
115
116 function delayedHideTooltip(elem)
117 \{
118 if (tooltipParentElem!=null) \{
119 hideTooltip(tooltipParentElem);
120 \}
121 \}
122
123
124
125 var gsapi = new GSAjaxAPI("_gwcgi_","_cgiargc_");
126
127 window.onload=function()\{
128 try \{
129 de.init();
130 document.addEventListener('beforeunload',saveMetadata,true);
131
132 de.doc.declarePropertySets(\{
133 metadata: \{
134 phMarkup: '<span style="background-color:#DDDDDD;color:black"><em>[Enter a value]</em></span>',
135 name: "metadata"
136 \}
137 \});
138
139 \}
140 catch(err) \{
141 alert("SeaWeed failed to initialise: " + err.message);
142 \}
143 \}
144
145
146
147 function saveMetadataElement(editedElem)
148 \{
149 var docoid = editedElem.getAttribute("docoid");
150
151 if (gsdefined(docoid)) \{
152 var metaname = editedElem.getAttribute("metaname");
153 var metapos = editedElem.getAttribute("metapos");
154 var metavalue= editedElem.innerHTML;
155
156 var metavalue = metavalue.replace(/&nbsp;/g, " ");
157 metavalue = escape(metavalue);
158
159 // alert("docoid = " + docoid + " metaname = " + metaname + " metapos = " + metapos + " metavalue = " + metavalue);
160
161 // console.log("docoid = " + docoid + " metaname = " + metaname + " metapos = " + metapos + " metavalue = " + metavalue);
162
163 gsapi.setDocumentMetadata(docoid,metaname,metapos,metavalue);
164 gsapi.explodeDocument(docoid);
165
166 \}
167
168 return true;
169 \}
170
171 function saveMetadata()
172 \{
173 var editedArray = de.Changes.getChangedEditableSections();
174 // editedHashSet.iterate(function(item) \{ console.log(item.innerHTML); return true \} );
175
176 if (editedArray.length>0) \{
177 var commitChanges = confirm("Commit edited metadata?");
178 if (commitChanges) \{
179 for (i=0; i<editedArray.length; i++)
180 \{
181 saveMetadataElement(editedArray[i]);
182 \}
183
184 \}
185
186 // whether commited or not, now clear list of edited values
187 //clearEditedElements();
188 \}
189
190
191 \}
192
193
194</script>
195
196
197}
Note: See TracBrowser for help on using the repository browser.