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

Last change on this file since 23396 was 23396, checked in by max, 11 years ago

Initial cut at support for Brook's seamless web editing (nick-named seaweed)

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