source: main/trunk/greenstone3/web/interfaces/default/js/formateditor/format_jquery_prototypes.js@ 27713

Last change on this file since 27713 was 27713, checked in by sjm84, 11 years ago

Fixing collectionConfig templates being incorrect

File size: 16.2 KB
Line 
1
2console.log("Loading format_jquery_prototypes.js\n");
3
4$(document).ready(function()
5{
6 /*
7 var collection = "";
8
9 var regex = new RegExp("[?&]c=");
10 var matches = regex.exec(document.URL);
11 if(matches != null)
12 {
13 var startIndex = matches.index;
14 var endIndex = document.URL.indexOf("&", startIndex + 1);
15
16 if(endIndex == -1)
17 {
18 endIndex = document.URL.length;
19 }
20
21 collection = document.URL.substring(startIndex, endIndex);
22 }
23 */
24
25 //Retrieve the collection metadataset using ajax
26 $.ajax
27 ({
28 type: "GET",
29 url: "?a=g&s=CoverageMetadataRetrieve&o=xml&rt=r&c=" + host_info.collection_name,
30 success: function(data)
31 {
32 var str = "<select name=\"meta_select\" onChange=\"onSelectChange(this)\">";
33
34 var selectorArea = document.getElementById("metadataSelector");
35 var metadataSets = data.getElementsByTagName("metadataSet");
36 for(var i = 0; i < metadataSets.length; i++)
37 {
38 var metadata = metadataSets[i].getElementsByTagName("metadata");
39 for(var j = 0; j < metadata.length; j++)
40 {
41 var metaValue = metadataSets[i].getAttribute("name") + "." + metadata[j].getAttribute("name");
42 str += "<option value=\"" + metaValue + "\">" + metaValue + "</option>";
43 }
44 }
45
46 str += "</select>";
47
48 selectorArea.innerHTML = str;
49 gsf_metadata_element = "<div class=\"gsf_metadata css_gsf_metadata block leaf\" title=\"gsf:metadata\"><table class=\"header\"><tbody><tr><td class=\"header\">" + str + "</td><td class=\"header\"><a href=\"#\" class=\"remove ui-icon ui-icon-closethick\" title=\"Click me to remove\"/></td></tr></tbody></table></div>";
50 //console.log("Metadata element from ajax: " + gsf_metadata_element);
51 }
52 });
53
54 $.ui.draggable.prototype._createHelper = function(event) {
55 var o = this.options;
56 var helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event])) : (o.helper == 'clone' ? this.element.clone().removeAttr('id') : this.element);
57
58 var select = $(this.element).find('select');
59 var value = select.attr('value');
60 console.log("Found "+value+" in helper");
61 CURRENT_SELECT_VALUE = value;
62 helper.find('select').attr('value', value);
63
64 if(!helper.parents('body').length)
65 helper.appendTo((o.appendTo == 'parent' ? this.element[0].parentNode : o.appendTo));
66
67 if(helper[0] != this.element[0] && !(/(fixed|absolute)/).test(helper.css("position")))
68 helper.css("position", "absolute");
69
70 return helper;
71
72 };
73
74 $.ui.sortable.prototype._removeCurrentsFromItems = function() {
75 //console.log("IN _removeCurrentsFromItems FUNCTION");
76 //console.log("this = " + this.currentItem[0].getAttribute('class'));
77 var list = this.currentItem.find(":data(sortable-item)");
78
79 var i = 0;
80 while (i<this.items.length) {
81 var found_match = false;
82 for (var j=0; j<list.length; j++) {
83 if(this.items[i])
84 {
85 if(list[j] == this.items[i].item[0]) {
86 //console.log("Item to splice = " + this.items[i].item[0].getAttribute('class'));
87 this.items.splice(i,1);
88 found_match = true;
89 break;
90 }
91 }
92 };
93 if (!found_match)
94 i++;
95 else
96 break;
97 }
98 };
99
100 $.ui.plugin.add("draggable", "connectToSortable", {
101 start: function(event, ui) {
102 //console.log("FUNCTION start draggable connectToSortable");
103 var inst = $(this).data("draggable"), o = inst.options, uiSortable = $.extend({}, ui, { item: inst.element });
104 inst.sortables = [];
105 $(o.connectToSortable).each(function() {
106 var sortable = $.data(this, 'sortable');
107 if (sortable && !sortable.options.disabled) {
108 inst.sortables.push({instance: sortable, shouldRevert: sortable.options.revert});
109 sortable._refreshItems(); //Do a one-time refresh at start to refresh the containerCache
110 sortable._trigger("activate", event, uiSortable);
111 }
112 });
113
114 },
115 stop: function(event, ui) {
116
117 //console.log("FUNCTION stop draggable connectToSortable");
118 //If we are still over the sortable, we fake the stop event of the sortable, but also remove helper
119 var inst = $(this).data("draggable"),
120 uiSortable = $.extend({}, ui, { item: inst.element });
121
122 $.each(inst.sortables, function() {
123 if(this.instance.isOver) {
124
125 this.instance.isOver = 0;
126
127 inst.cancelHelperRemoval = true; //Don't remove the helper in the draggable instance
128 this.instance.cancelHelperRemoval = false; //Remove it in the sortable instance (so sortable plugins like revert still work)
129
130 //The sortable revert is supported, and we have to set a temporary dropped variable on the draggable to support revert: 'valid/invalid'
131 if(this.shouldRevert) this.instance.options.revert = true;
132
133 //Trigger the stop of the sortable
134 //console.log("Draggable tells sortable to stop");
135 this.instance._mouseStop(event);
136
137 this.instance.options.helper = this.instance.options._helper;
138
139 //If the helper has been the original item, restore properties in the sortable
140 if(inst.options.helper == 'original')
141 this.instance.currentItem.css({ top: 'auto', left: 'auto' });
142
143 } else {
144 this.instance.cancelHelperRemoval = false; //Remove the helper in the sortable instance
145 this.instance._trigger("deactivate", event, uiSortable);
146 }
147 });
148
149 },
150 drag: function(event, ui) {
151 //console.log("FUNCTION drag draggable connectToSortable");
152
153 var inst = $(this).data("draggable"), self = this;
154
155 var checkPos = function(o) {
156 var dyClick = this.offset.click.top, dxClick = this.offset.click.left;
157 var helperTop = this.positionAbs.top, helperLeft = this.positionAbs.left;
158 var itemHeight = o.height, itemWidth = o.width;
159 var itemTop = o.top, itemLeft = o.left;
160
161 return $.ui.isOver(helperTop + dyClick, helperLeft + dxClick, itemTop, itemLeft, itemHeight, itemWidth);
162 };
163
164 var intersecting_items = new Array();
165
166 $.each(inst.sortables, function(i) {
167
168 //Copy over some variables to allow calling the sortable's native _intersectsWith
169 this.instance.positionAbs = inst.positionAbs;
170 this.instance.helperProportions = inst.helperProportions;
171 this.instance.offset.click = inst.offset.click;
172
173 if(this.instance._intersectsWith(this.instance.containerCache)) {
174
175 //If it intersects, we use a little isOver variable and set it once, so our move-in stuff gets fired only once
176 //if(!this.instance.isOver) {
177
178 //console.log('Line 1113');
179
180 // this.instance.isOver = 1;
181
182 intersecting_items.push(this.instance); // sam
183 //} //sam
184
185 //Now we fake the start of dragging for the sortable instance,
186 //by cloning the list group item, appending it to the sortable and using it as inst.currentItem
187 //We can then fire the start event of the sortable with our passed browser event, and our own helper (so it doesn't create a new one)
188 //sam this.instance.currentItem = $(self).clone().appendTo(this.instance.element).data("sortable-item", true);
189 //sam this.instance.options._helper = this.instance.options.helper; //Store helper option to later restore it
190 //sam this.instance.options.helper = function() { return ui.helper[0]; };
191
192 //sam event.target = this.instance.currentItem[0];
193 //sam this.instance._mouseCapture(event, true);
194 //sam this.instance._mouseStart(event, true, true);
195
196 //Because the browser event is way off the new appended portlet, we modify a couple of variables to reflect the changes
197 //sam this.instance.offset.click.top = inst.offset.click.top;
198 //sam this.instance.offset.click.left = inst.offset.click.left;
199 //sam this.instance.offset.parent.left -= inst.offset.parent.left - this.instance.offset.parent.left;
200 //sam this.instance.offset.parent.top -= inst.offset.parent.top - this.instance.offset.parent.top;
201
202 //sam inst._trigger("toSortable", event);
203 //sam inst.dropped = this.instance.element; //draggable revert needs that
204 //hack so receive/update callbacks work (mostly)
205 //sam inst.currentItem = inst.element;
206 //sam this.instance.fromOutside = inst;
207
208 //sam brace
209
210 //Provided we did all the previous steps, we can fire the drag event of the sortable on every draggable drag, when it intersects with the sortable
211 //sam if(this.instance.currentItem) this.instance._mouseDrag(event);
212
213 } else {
214
215 //If it doesn't intersect with the sortable, and it intersected before,
216 //we fake the drag stop of the sortable, but make sure it doesn't remove the helper by using cancelHelperRemoval
217 if(this.instance.isOver) {
218
219 console.log("UNSETTING ISOVER");
220 console.log("ON ITEM="+this.instance.currentItem[0].getAttribute('class'))
221 this.instance.isOver = 0;
222 this.instance.cancelHelperRemoval = true;
223
224 //Prevent reverting on this forced stop
225 this.instance.options.revert = false;
226
227 // The out event needs to be triggered independently
228 this.instance._trigger('out', event, this.instance._uiHash(this.instance));
229
230 this.instance._mouseStop(event, true);
231 this.instance.options.helper = this.instance.options._helper;
232
233 //Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size
234 //console.log("DO WE GET HERE?");
235 this.instance.currentItem.remove();
236 if(this.instance.placeholder) this.instance.placeholder.remove();
237
238 inst._trigger("fromSortable", event);
239 inst.dropped = false; //draggable revert needs that
240
241 }
242 }
243 });
244
245 //sam
246 //console.log("Contents of intersecting_items");
247 var innermostContainer = null, innermostIndex = null;
248 for (i=0;i<intersecting_items.length;i++)
249 {
250 //console.log('ITEM: '+intersecting_items[i].element[0].getAttribute('class'));
251
252 if(innermostContainer && $.ui.contains(intersecting_items[i].element[0], innermostContainer.element[0]))
253 continue;
254
255 innermostContainer = intersecting_items[i];
256 innermostIndex = i;
257 }
258
259 for (i=0;i<intersecting_items.length;i++)
260 {
261 if(intersecting_items[i] != innermostContainer)
262 if(intersecting_items[i].isOver) {
263
264 console.log("UNSETTING ISOVER");
265 console.log("ON ITEM="+intersecting_items[i].currentItem[0].getAttribute('class'))
266 intersecting_items[i].isOver = 0;
267 intersecting_items[i].cancelHelperRemoval = true;
268
269 //Prevent reverting on this forced stop
270 intersecting_items[i].options.revert = false;
271
272 // The out event needs to be triggered independently
273 intersecting_items[i]._trigger('out', event, intersecting_items[i]._uiHash(intersecting_items[i]));
274
275 intersecting_items[i]._mouseStop(event, true);
276 intersecting_items[i].options.helper = intersecting_items[i].options._helper;
277
278 //Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size
279 //console.log("DO WE GET HERE?");
280 if(intersecting_items[i].currentItem) intersecting_items[i].currentItem.remove();
281 if(intersecting_items[i].placeholder) intersecting_items[i].placeholder.remove();
282
283 inst._trigger("fromSortable", event);
284 inst.dropped = false; //draggable revert needs that
285 }
286
287 intersecting_items[i].isOver = 0;
288 }
289
290 if(innermostContainer && !innermostContainer.isOver)
291 {
292 console.log("INNER="+innermostContainer.element[0].getAttribute('class'));
293 console.log("SETTING ISOVER");
294 innermostContainer.isOver = 1;
295
296 //Now we fake the start of dragging for the sortable instance,
297 //by cloning the list group item, appending it to the sortable and using it as inst.currentItem
298 //We can then fire the start event of the sortable with our passed browser event, and our own helper (so it doesn't create a new one)
299
300 if(innermostContainer.currentItem) innermostContainer.currentItem.remove();
301 if(innermostContainer.placeholder) innermostContainer.placeholder.remove();
302
303 innermostContainer.currentItem = $(self).clone().appendTo(innermostContainer.element).data("sortable-item", true);
304
305 innermostContainer.options._helper = innermostContainer.options.helper; //Store helper option to later restore it
306 innermostContainer.options.helper = function() { return ui.helper[0]; };
307
308 console.log("EVENT TARGET="+innermostContainer.currentItem[0].getAttribute('class'));
309 event.target = innermostContainer.currentItem[0];
310 innermostContainer._mouseCapture(event, true);
311 innermostContainer._mouseStart(event, true, true);
312
313 //Because the browser event is way off the new appended portlet, we modify a couple of variables to reflect the changes
314 innermostContainer.offset.click.top = inst.offset.click.top;
315 innermostContainer.offset.click.left = inst.offset.click.left;
316 innermostContainer.offset.parent.left -= inst.offset.parent.left - innermostContainer.offset.parent.left;
317 innermostContainer.offset.parent.top -= inst.offset.parent.top - innermostContainer.offset.parent.top;
318
319 inst._trigger("toSortable", event);
320 inst.dropped = innermostContainer.element; //draggable revert needs that
321 //hack so receive/update callbacks work (mostly)
322 inst.currentItem = inst.element;
323 innermostContainer.fromOutside = inst;
324
325 //sam brace
326 }
327
328 if(innermostContainer)
329 {
330 //Provided we did all the previous steps, we can fire the drag event of the sortable on every draggable drag, when it intersects with the sortable
331 if(innermostContainer.currentItem) innermostContainer._mouseDrag(event);
332 }
333
334 }
335 });
336
337});
Note: See TracBrowser for help on using the repository browser.