1 |
|
---|
2 | console.log("Loading gui_div.js\n");
|
---|
3 |
|
---|
4 | var initialised_iframe = "false";
|
---|
5 |
|
---|
6 | function createFormatStatement()
|
---|
7 | {
|
---|
8 |
|
---|
9 | var formatStatement = document.getElementById('formatStatement');
|
---|
10 | console.log(formatStatement);
|
---|
11 | if(formatStatement.hasChildNodes())
|
---|
12 | {
|
---|
13 | var formatstring = traverse(formatStatement, "");
|
---|
14 | console.log(formatstring);
|
---|
15 |
|
---|
16 | // var children = $(formatStatement).children('div');
|
---|
17 | // for(var i=0; i < children.length; i++)
|
---|
18 | // traverse(children[i], formatstring)
|
---|
19 |
|
---|
20 | /*
|
---|
21 | var children = formatStatement.childNodes; //[]getChildNodes();
|
---|
22 | var current;
|
---|
23 | for(var i = 0; i < formatStatement.childNodes.length; i++)
|
---|
24 | {
|
---|
25 | current = formatStatement.childNodes[i];
|
---|
26 | //console.log(current.nodeName);
|
---|
27 | //console.log(current.nodeType);
|
---|
28 | if(current.nodeName=='DIV')
|
---|
29 | {
|
---|
30 | //console.log(current);
|
---|
31 | //console.log(current.className);
|
---|
32 | var gsf = find_class(current);
|
---|
33 | console.log(gsf);
|
---|
34 | }
|
---|
35 | }
|
---|
36 | */
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | function traverse(node, formatstring)
|
---|
41 | {
|
---|
42 | //console.log("node=("+node.nodeName+","+node.nodeType+")");
|
---|
43 |
|
---|
44 | if(node.nodeName=='DIV')
|
---|
45 | {
|
---|
46 | console.log("Found a div" +node.nodeName+","+node.nodeType);
|
---|
47 | formatstring = formatstring + find_class(node);
|
---|
48 | console.log(formatstring);
|
---|
49 | }
|
---|
50 |
|
---|
51 | var children = $(node).children();
|
---|
52 | for(var i=0; i < children.length; i++)
|
---|
53 | formatstring = formatstring + traverse(children[i], formatstring);
|
---|
54 |
|
---|
55 | return formatstring;
|
---|
56 | }
|
---|
57 |
|
---|
58 |
|
---|
59 | /*
|
---|
60 | console.log("node=("+node.nodeName+","+node.nodeType+")");
|
---|
61 |
|
---|
62 | if(node.children.length == 0) //hasChildNodes())
|
---|
63 | {
|
---|
64 | console.log("No children so return");
|
---|
65 | return "";
|
---|
66 | }
|
---|
67 |
|
---|
68 | if(node.nodeName=='DIV')
|
---|
69 | {
|
---|
70 | console.log("Found a div");
|
---|
71 | formatstring = formatstring + find_class(node);
|
---|
72 | }
|
---|
73 |
|
---|
74 | for(var i = 0; i < node.children.length; i++)
|
---|
75 | return recursiveTraverse(node.children[i], formatstring);
|
---|
76 |
|
---|
77 |
|
---|
78 | return formatstring;
|
---|
79 | }
|
---|
80 | */
|
---|
81 |
|
---|
82 | function find_class(current)
|
---|
83 | {
|
---|
84 | var classes = current.className.split(' ');
|
---|
85 | var none = "";
|
---|
86 | for(var i = 0; i < classes.length; i++)
|
---|
87 | {
|
---|
88 | switch(classes[i])
|
---|
89 | {
|
---|
90 | case 'gsf_template':
|
---|
91 | return create_gsf_template(current);
|
---|
92 | default:
|
---|
93 | {
|
---|
94 | console.log("Class not found");
|
---|
95 | return none;
|
---|
96 | }
|
---|
97 | }
|
---|
98 | }
|
---|
99 | }
|
---|
100 |
|
---|
101 | function create_gsf_template(current)
|
---|
102 | {
|
---|
103 | // find match text which is an input with class match
|
---|
104 | var match = $(current).find('.match')[0].value;
|
---|
105 | console.log(match);
|
---|
106 |
|
---|
107 | // find mode text which is an input with class mode
|
---|
108 | var mode = $(current).find('.mode')[0].value;
|
---|
109 | console.log(mode);
|
---|
110 |
|
---|
111 | // "<gsf:template match=\"classifierNode\" mode=\"horizontal\">"
|
---|
112 | var gsf = "<gsf:template match=\"" + match + "\"";
|
---|
113 | if(mode != "vertical")
|
---|
114 | gsf = gsf + " mode=\"" + mode + "\"";
|
---|
115 | gsf = gsf + ">";
|
---|
116 |
|
---|
117 | return gsf;
|
---|
118 |
|
---|
119 | }
|
---|
120 |
|
---|
121 | /*
|
---|
122 | $("#iframe").ready(function(){
|
---|
123 | console.log("iframe is ready ...");
|
---|
124 | var iframe = document.getElementById('iframe');
|
---|
125 | var iframe_document = iframe.document;
|
---|
126 |
|
---|
127 | if(iframe.contentDocument)
|
---|
128 | {
|
---|
129 | iframe_document = iframe.contentDocument; // For NS6
|
---|
130 | console.log("Chose content document");
|
---|
131 | }
|
---|
132 | else if(iframe.contentWindow)
|
---|
133 | {
|
---|
134 | iframe_document = iframe.contentWindow.document; // For IE5.5 and IE6
|
---|
135 | console.log("Chose content window");
|
---|
136 | }
|
---|
137 |
|
---|
138 | console.log(iframe_document.documentElement.innerHTML); //document.documentElement.outerHTML
|
---|
139 |
|
---|
140 | $(iframe_document.documentElement.innerHTML).find('a').each(function() {
|
---|
141 | console.log("data "+$(this).data('href'));
|
---|
142 | console.log("getAttribute "+$(this).getAttribute('href'));
|
---|
143 | console.log("attr "+$(this).attr('href'));
|
---|
144 | console.log("this.href "+this.href);
|
---|
145 | var original = this.href; //$(this).attr('href');
|
---|
146 | // check if greenstone link ie. starts with format
|
---|
147 | //var original = $(this).data('href');
|
---|
148 | var modified = original.toString().concat("&excerptid=gs_content");
|
---|
149 | console.log(modified);
|
---|
150 | this.href = modified;
|
---|
151 | //$(this).attr('href',modified);
|
---|
152 | //$(this).data('href', modified);
|
---|
153 | //console.log($(this).attr('href'));
|
---|
154 | console.log("data "+$(this).data('href'));
|
---|
155 | console.log("getAttribute "+$(this).getAttribute('href'));
|
---|
156 | console.log("attr "+$(this).attr('href'));
|
---|
157 | console.log("this.href "+this.href);
|
---|
158 | console.log("**********");
|
---|
159 |
|
---|
160 | });
|
---|
161 | }); */
|
---|
162 | /*
|
---|
163 | function loadXMLDoc()
|
---|
164 | {
|
---|
165 | if (window.XMLHttpRequest)
|
---|
166 | {// code for IE7+, Firefox, Chrome, Opera, Safari
|
---|
167 | xmlhttp=new XMLHttpRequest();
|
---|
168 | }
|
---|
169 | else
|
---|
170 | {// code for IE6, IE5
|
---|
171 | xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
|
---|
172 | }
|
---|
173 |
|
---|
174 | xmlhttp.onreadystatechange=function()
|
---|
175 | {
|
---|
176 | console.log("state changed to " + xmlhttp.readyState);
|
---|
177 | console.log("status is " + xmlhttp.status);
|
---|
178 | if (xmlhttp.readyState==4 && xmlhttp.status==200)
|
---|
179 | {
|
---|
180 | console.log("get code");
|
---|
181 | console.log(xmlhttp.responseText);
|
---|
182 | document.getElementById("gs_content").innerHTML=xmlhttp.responseText;
|
---|
183 | }
|
---|
184 | }
|
---|
185 |
|
---|
186 | xmlhttp.open("GET","http://localhost:8080/greenstone3/format?a=b&rt=s&s=ClassifierBrowse&c=simpleht&cl=CL1&excerptid=gs_content",true);
|
---|
187 | //xmlhttp.open("GET","http://www.cs.waikato.ac.nz",true);
|
---|
188 | //xmlhttp.open("GET","http://wand.net.nz/~sjb48/index.html",true);
|
---|
189 | xmlhttp.send();
|
---|
190 | }
|
---|
191 | */
|
---|
192 | $(document).ready(function(){
|
---|
193 |
|
---|
194 | console.log("Document ready function\n");
|
---|
195 |
|
---|
196 | var CURRENT_SELECT_VALUE = "";
|
---|
197 |
|
---|
198 | var iframe = document.getElementById('iframe');
|
---|
199 | var iframe_document = iframe.document;
|
---|
200 |
|
---|
201 | if(iframe.contentDocument)
|
---|
202 | {
|
---|
203 | iframe_document = iframe.contentDocument; // For NS6
|
---|
204 | console.log("Chose content document");
|
---|
205 | }
|
---|
206 | else if(iframe.contentWindow)
|
---|
207 | {
|
---|
208 | iframe_document = iframe.contentWindow.document; // For IE5.5 and IE6
|
---|
209 | console.log("Chose content window");
|
---|
210 | }
|
---|
211 |
|
---|
212 | // Edit the hrefs in preview_html - search for <a href="format?a=b&rt=r&s=ClassifierBrowse&c=simpleht&cl=CL1.2">
|
---|
213 | var start_index = 0;
|
---|
214 | var end_index = 0;
|
---|
215 | while(start_index != -1)
|
---|
216 | {
|
---|
217 | start_index = preview_html.indexOf("href=\"format", start_index);
|
---|
218 | console.log("start index = " + start_index);
|
---|
219 | if(start_index != -1)
|
---|
220 | {
|
---|
221 | end_index = preview_html.indexOf("\">", start_index);
|
---|
222 | console.log("end_index = " + end_index);
|
---|
223 | a = preview_html.substring(0,end_index);
|
---|
224 | b = preview_html.substring(end_index);
|
---|
225 | preview_html = a.concat("&excerptid=results", b);
|
---|
226 | console.log(preview_html);
|
---|
227 | start_index = end_index + "&excerptid=results\">".length;
|
---|
228 | }
|
---|
229 | }
|
---|
230 |
|
---|
231 | // Split the html code in to three parts
|
---|
232 | var first_index = preview_html.indexOf("<ul id=\"results\"");
|
---|
233 | console.log("First index is "+first_index);
|
---|
234 | var second_index = preview_html.indexOf("</ul>", first_index) + "</ul>".length;
|
---|
235 | console.log("Second index is "+second_index);
|
---|
236 |
|
---|
237 | var first_half = preview_html.substring(0, first_index);
|
---|
238 | var iframe_code = preview_html.substring(first_index, second_index);
|
---|
239 | var second_half = preview_html.substring(second_index);
|
---|
240 |
|
---|
241 | //$('#my_categories').innerHTML = first_half.concat(second_half);
|
---|
242 | document.getElementById("my_categories").innerHTML = first_half.concat(second_half);
|
---|
243 |
|
---|
244 | // Put the content in the iframe
|
---|
245 | if(initialised_iframe == "false")
|
---|
246 | {
|
---|
247 | console.log("Initialised iframe with preview html");
|
---|
248 | console.log(preview_html);
|
---|
249 | iframe_document.open();
|
---|
250 | iframe_document.writeln(iframe_code); //.concat("&excerptid=gs_content"));
|
---|
251 | iframe_document.close();
|
---|
252 | initialised_iframe = "true";
|
---|
253 | }
|
---|
254 |
|
---|
255 | /*
|
---|
256 | $(iframe_document.documentElement.innerHTML).find('a').each(function() {
|
---|
257 | console.log("data "+$(this).data('href'));
|
---|
258 | console.log("getAttribute "+this.getAttribute('href'));
|
---|
259 | console.log("attr "+$(this).attr('href'));
|
---|
260 | console.log("this.href "+this.href);
|
---|
261 | var original = this.href; //$(this).attr('href');
|
---|
262 | // check if greenstone link ie. starts with format
|
---|
263 | //var original = $(this).data('href');
|
---|
264 | var modified = original.toString().concat("&excerptid=gs_content");
|
---|
265 | console.log("* *");
|
---|
266 | console.log(modified);
|
---|
267 | console.log("* *");
|
---|
268 | //this.href = modified;
|
---|
269 | //$(this).attr('href',modified);
|
---|
270 | //$(this).data('href', modified);
|
---|
271 | $(this).attr({ 'href': modified });
|
---|
272 | //console.log($(this).attr('href'));
|
---|
273 | console.log("data "+$(this).data('href'));
|
---|
274 | console.log("getAttribute "+this.getAttribute('href'));
|
---|
275 | console.log("attr "+$(this).attr('href'));
|
---|
276 | console.log("this.href "+this.href);
|
---|
277 | console.log("***********************");
|
---|
278 | });
|
---|
279 | */
|
---|
280 |
|
---|
281 | /******************************************/
|
---|
282 | /* DRAGGABLES */
|
---|
283 | /******************************************/
|
---|
284 |
|
---|
285 | $(".draggable_gsf_template").draggable({
|
---|
286 | cursor: 'crosshair',
|
---|
287 | connectToSortable: '#formatStatement',
|
---|
288 | helper: 'clone',
|
---|
289 | revert: 'invalid'
|
---|
290 | });
|
---|
291 |
|
---|
292 | $(".draggable_table").draggable({
|
---|
293 | cursor: 'crosshair',
|
---|
294 | connectToSortable: '.gsf_template',
|
---|
295 | helper: 'clone',
|
---|
296 | revert: 'invalid'
|
---|
297 | });
|
---|
298 |
|
---|
299 | $(".draggable_tr").draggable({
|
---|
300 | cursor: 'crosshair',
|
---|
301 | connectToSortable: '.gsf_table',
|
---|
302 | helper: 'clone',
|
---|
303 | revert: 'invalid'
|
---|
304 | })
|
---|
305 |
|
---|
306 | $(".draggable_td").draggable({
|
---|
307 | cursor: 'crosshair',
|
---|
308 | //connectToSortable: '.td',
|
---|
309 | helper: 'clone',
|
---|
310 | revert: 'invalid'
|
---|
311 | })
|
---|
312 |
|
---|
313 | $(".draggable_gsf_text").draggable({
|
---|
314 | cursor: 'crosshair',
|
---|
315 | connectToSortable: '.td-div, .gsf_when, .gsf_otherwise, .gsf_link, .gsf_choose_metadata, .gsf_default',
|
---|
316 | helper: 'clone',
|
---|
317 | revert: 'invalid'
|
---|
318 | });
|
---|
319 |
|
---|
320 | $(".draggable_gsf_choose_metadata").draggable({
|
---|
321 | cursor: 'crosshair',
|
---|
322 | connectToSortable: '.td-div, .gsf_link, .gsf_when, .gsf_otherwise',
|
---|
323 | helper: 'clone',
|
---|
324 | revert: 'invalid'
|
---|
325 | });
|
---|
326 |
|
---|
327 | //$(".element_type_gsf_metadata").draggable({
|
---|
328 | $(".draggable_gsf_metadata").draggable({
|
---|
329 | cursor: 'crosshair',
|
---|
330 | connectToSortable: '.gsf_choose_metadata, .gsf_when, .gsf_otherwise, .gsf_link, .td-div',
|
---|
331 | helper: 'clone',
|
---|
332 | revert: 'invalid'
|
---|
333 | });
|
---|
334 |
|
---|
335 | $(".draggable_gsf_link").draggable({
|
---|
336 | cursor: 'crosshair',
|
---|
337 | connectToSortable: '.td-div, .gsf_when, .gsf_otherwise, .gsf_link',
|
---|
338 | helper: 'clone',
|
---|
339 | revert: 'invalid'
|
---|
340 | });
|
---|
341 |
|
---|
342 | // switch, when, otherwise, icon
|
---|
343 | $(".draggable_gsf_switch").draggable({
|
---|
344 | cursor: 'crosshair',
|
---|
345 | connectToSortable: '.td-div, .gsf_link',
|
---|
346 | helper: 'clone',
|
---|
347 | revert: 'invalid'
|
---|
348 | });
|
---|
349 |
|
---|
350 | $(".draggable_gsf_when").draggable({
|
---|
351 | cursor: 'crosshair',
|
---|
352 | connectToSortable: '.gsf_switch',
|
---|
353 | helper: 'clone',
|
---|
354 | revert: 'invalid'
|
---|
355 | });
|
---|
356 |
|
---|
357 | $(".draggable_gsf_otherwise").draggable({
|
---|
358 | cursor: 'crosshair',
|
---|
359 | connectToSortable: '.gsf_switch',
|
---|
360 | helper: 'clone',
|
---|
361 | revert: 'invalid'
|
---|
362 | });
|
---|
363 |
|
---|
364 | $(".draggable_gsf_icon").draggable({
|
---|
365 | cursor: 'crosshair',
|
---|
366 | connectToSortable: '.td-div, .gsf_link, .gsf_choose, .gsf_when, .gsf_otherwise',
|
---|
367 | helper: 'clone',
|
---|
368 | revert: 'invalid'
|
---|
369 | });
|
---|
370 |
|
---|
371 |
|
---|
372 | /******************************************/
|
---|
373 | /* SORTABLES */
|
---|
374 | /******************************************/
|
---|
375 |
|
---|
376 | bind_td_sortable();
|
---|
377 | bind_all_sortables();
|
---|
378 |
|
---|
379 | $('#formatStatement').sortable({
|
---|
380 | cursor: 'pointer',
|
---|
381 | tolerance: 'pointer',
|
---|
382 | items: '.gsf_template',
|
---|
383 | placeholder:'placeholder',
|
---|
384 | //'nested':'div'
|
---|
385 | stop: function(event, ui) {
|
---|
386 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('css_gsf_template')) { replace_with(ui.item,gsf_template_element); }
|
---|
387 | }
|
---|
388 | });
|
---|
389 |
|
---|
390 | $('div.gsf_template').children(".block,.table").slideUp(300);
|
---|
391 | });
|
---|
392 |
|
---|
393 | /*******************************************************************************/
|
---|
394 |
|
---|
395 | function bind_all_sortables()
|
---|
396 | {
|
---|
397 | console.log('function bind_all_sortables()');
|
---|
398 | bind_template_sortable();
|
---|
399 | //bind_table_sortable();
|
---|
400 | //bind_tr_sortable();
|
---|
401 | //bind_td_sortable();
|
---|
402 | bind_choose_metadata_sortable();
|
---|
403 | bind_link_sortable();
|
---|
404 | bind_switch_sortable();
|
---|
405 | bind_when_sortable();
|
---|
406 | bind_otherwise_sortable();
|
---|
407 |
|
---|
408 | bind_tables();
|
---|
409 |
|
---|
410 | bind_block_mouseover();
|
---|
411 | bind_minmax_remove();
|
---|
412 | }
|
---|
413 |
|
---|
414 | function bind_tables()
|
---|
415 | {
|
---|
416 | console.log('function bind_tables()');
|
---|
417 | //$('.tr').resize_tables($(this)); //equalHeights();
|
---|
418 |
|
---|
419 |
|
---|
420 | $('td').click(function () {
|
---|
421 | console.log('td click *');
|
---|
422 | return false;
|
---|
423 | });
|
---|
424 |
|
---|
425 | $(".td-div").resizable({
|
---|
426 | alsoResize: 'parent',
|
---|
427 | //containment: 'parent',
|
---|
428 | handles: 'w,e',
|
---|
429 | stop: function(event, ui) {
|
---|
430 | console.log('Resize table on stop');
|
---|
431 | resize_tables($(this));
|
---|
432 | //$(this).parent().parent().equalHeights();
|
---|
433 | }, });
|
---|
434 |
|
---|
435 | //$(".droppable").sortable({
|
---|
436 | // 'cursor':'pointer',
|
---|
437 | // 'tolerance': 'pointer',
|
---|
438 | // 'items':'.column, .td-div',
|
---|
439 | // 'placeholder':'placeholder'
|
---|
440 | //});
|
---|
441 |
|
---|
442 | $(".droppable").droppable({
|
---|
443 | accept: '.element_type_td',
|
---|
444 | tolerance: 'pointer',
|
---|
445 | activate: function(event, ui) { $(this).addClass("droppable_hl");}, // console.log("droppable activated")},
|
---|
446 | deactivate: function(event, ui) { $(this).removeClass("droppable_hl"); }, // console.log("droppable deactivated")},
|
---|
447 | drop: function(event, ui) {
|
---|
448 | //if ($(this).hasClass("ui-draggable"))
|
---|
449 | //if (ui.helper.hasClass("ui-draggable"))
|
---|
450 | //{
|
---|
451 | var neverempty = document.createElement("div");
|
---|
452 | neverempty.setAttribute("class","neverempty block");
|
---|
453 | neverempty.setAttribute("style","height:50px");
|
---|
454 | neverempty.setAttribute("style","display:block");
|
---|
455 | var text = document.createTextNode('NEVER EMPTY');
|
---|
456 | neverempty.appendChild(text);
|
---|
457 | var td = document.createElement("td");
|
---|
458 | var div = document.createElement("div"); // class=\"td block\" title=\"td-div\"");
|
---|
459 | div.setAttribute("title","td-div");
|
---|
460 | div.setAttribute("class","td-div block");
|
---|
461 | div.setAttribute("style","margin-left:0px");
|
---|
462 | div.setAttribute("width","25px");
|
---|
463 | td.appendChild(div);
|
---|
464 | div.appendChild(neverempty);
|
---|
465 | var sep = document.createElement("td");
|
---|
466 | sep.setAttribute("class","droppable");
|
---|
467 | sep.setAttribute("width","10px");
|
---|
468 | $(this).after(sep);
|
---|
469 | $(this).after(td);
|
---|
470 | bind_tables();
|
---|
471 | resize_tables($(this));
|
---|
472 | bind_td_sortable();
|
---|
473 | bind_block_mouseover();
|
---|
474 | //bind_all_sortables();
|
---|
475 | //}
|
---|
476 | //else
|
---|
477 | //{
|
---|
478 | // console.log("Attempting to add");
|
---|
479 | //$(this).appendTo(ui.draggable[0]);
|
---|
480 | // $(this).prepend(ui.draggable[0]);
|
---|
481 | //$(ui.draggable[0]).appendTo($(this));
|
---|
482 | //}
|
---|
483 | }
|
---|
484 | });
|
---|
485 |
|
---|
486 | }
|
---|
487 |
|
---|
488 | function replace_with(item, me)
|
---|
489 | {
|
---|
490 | // Search me for select
|
---|
491 | if(me.search("select") != -1)
|
---|
492 | {
|
---|
493 | // If select exists, then find CURRENT_SELECT_VALUE
|
---|
494 | var index = me.search(CURRENT_SELECT_VALUE);
|
---|
495 | if(index == -1)
|
---|
496 | console.log("Did not find " + CURRENT_SELECT_VALUE);
|
---|
497 | else
|
---|
498 | console.log("Found " + CURRENT_SELECT_VALUE + " at index " + index);
|
---|
499 | index = index + CURRENT_SELECT_VALUE.length + 1;
|
---|
500 | console.log("Attempt inserting select at new index "+index);
|
---|
501 | a = me.substring(0,index);
|
---|
502 | b = me.substring(index);
|
---|
503 | me = a.concat("selected",b);
|
---|
504 | }
|
---|
505 |
|
---|
506 | //console.log('function replace_with(item, me)');
|
---|
507 | item.replaceWith(me); //'<div class="element element-txt">This text box has been added!</div>');
|
---|
508 | //item.find('select').attr("value", CURRENT_SELECT_VALUE);
|
---|
509 |
|
---|
510 |
|
---|
511 | //if(select != null){
|
---|
512 | // console.log("Attempting to select " + CURRENT_SELECT_VALUE);
|
---|
513 | // console.log("length = "+select.length);
|
---|
514 | // for(index = 0; index < select.length; index++) {
|
---|
515 | // console.log(select[index].value);
|
---|
516 | // if(select[index].value == CURRENT_SELECT_VALUE)
|
---|
517 | // console.log("Found "+CURRENT_SELECT_VALUE+" at index " + index);
|
---|
518 | // select.selectedIndex = index;
|
---|
519 | // }
|
---|
520 | // }
|
---|
521 |
|
---|
522 | resize_tables(item);
|
---|
523 |
|
---|
524 | bind_all_sortables();
|
---|
525 | }
|
---|
526 |
|
---|
527 | function resize_tables(item)
|
---|
528 | {
|
---|
529 | //console.log('function resize_tables(item)');
|
---|
530 | var max_height = 0;
|
---|
531 | (item.parents('.table')).each(function(index) {
|
---|
532 | $(this).children().children().children().each(function() {
|
---|
533 | var sum_one = 0;
|
---|
534 | var sum_two = 0;
|
---|
535 | $(this).children('.block').each(function() { sum_one = sum_one + $(this).height();
|
---|
536 | $(this).children('.block').each(function() { sum_two = sum_two + $(this).height(); } );
|
---|
537 | console.log("My height is " + $(this).height() + ", sum height 2 is " + sum_two);
|
---|
538 | });
|
---|
539 | console.log("My height is " + $(this).height() + ", sum height 1 is " + sum_one);
|
---|
540 | if (sum_two > max_height)
|
---|
541 | max_height = sum_two;
|
---|
542 | });
|
---|
543 | });
|
---|
544 | equalHeights(item,max_height);
|
---|
545 | }
|
---|
546 |
|
---|
547 | function bind_template_sortable()
|
---|
548 | {
|
---|
549 | //console.log('function bind_template_sortable()');
|
---|
550 | $('.gsf_template').sortable({
|
---|
551 | 'cursor':'pointer',
|
---|
552 | 'tolerance': 'pointer',
|
---|
553 | 'items':'.table', //.gsf_choose_metadata, .gsf_metadata',
|
---|
554 | 'placeholder':'placeholder',
|
---|
555 | //'nested':'.gsf:metadata'
|
---|
556 | stop: function(event, ui) {
|
---|
557 | //if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('css_table')) { replace_with(ui.item, "<table border=\"1\" width=\"100%\" height=\"50px\"><tr><td><div class=\"td block\" title=\"td-div\">XXXXXXXXXXXXXXXXXXXXXXXX</div></td></tr></table>"); }
|
---|
558 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_table')) { replace_with(ui.item, "<table class=\"table\" border=\"2\"></table>"); }
|
---|
559 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_choose_metadata')) { replace_with(ui.item, gsf_choose_metadata_element); }
|
---|
560 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_metadata')) { replace_with(ui.item, gsf_metadata_element); }
|
---|
561 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_link')) { replace_with(ui.item, gsf_link_element); }
|
---|
562 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_switch')) { replace_with(ui.item, gsf_switch_element); }
|
---|
563 | }
|
---|
564 | });
|
---|
565 |
|
---|
566 | $('.gsf_template').click(function () {
|
---|
567 | console.log('gsf_template class click');
|
---|
568 | return false;
|
---|
569 | });
|
---|
570 |
|
---|
571 | }
|
---|
572 |
|
---|
573 | function bind_td_sortable()
|
---|
574 | {
|
---|
575 |
|
---|
576 | $('tr').sortable({
|
---|
577 | 'cursor':'pointer',
|
---|
578 | 'tolerance': 'intersect',
|
---|
579 | 'items':'.column',
|
---|
580 | 'placeholder':'placeholder_td',
|
---|
581 | 'connectWith':'column'});
|
---|
582 |
|
---|
583 | //$('.column').sortable({
|
---|
584 | // connectWith:['.column'],
|
---|
585 | // placeholder: 'placeholder',
|
---|
586 | // items:'td-div'
|
---|
587 | //});
|
---|
588 |
|
---|
589 |
|
---|
590 | //$('.column').sortable({
|
---|
591 | // 'cursor':'pointer',
|
---|
592 | // 'tolerance': 'pointer',
|
---|
593 | // 'items':'.td-div',
|
---|
594 | // 'placeholder':'placeholder',
|
---|
595 | // 'connectWith':'.column'
|
---|
596 | //'nested':'.gsf:metadata'
|
---|
597 | //receive: function(event, ui) { alert("Attempted to receive"); },
|
---|
598 | //stop: function(event, ui) {
|
---|
599 | // if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('element_type_gsf_metadata')) { replace_with(ui.item, gsf_metadata_element); }
|
---|
600 |
|
---|
601 | //});
|
---|
602 |
|
---|
603 | //console.log('function bind_td_sortable()');
|
---|
604 | $('.td-div').sortable({
|
---|
605 | 'cursor':'pointer',
|
---|
606 | 'tolerance': 'pointer',
|
---|
607 | 'items':'.gsf_metadata, .gsf_choose_metadata, .gsf_link, .gsf_switch',
|
---|
608 | 'placeholder':'placeholder',
|
---|
609 | //'connectWith':'.td-div',
|
---|
610 | //'nested':'.gsf:metadata'
|
---|
611 | receive: function(event, ui) { alert("Attempted to receive"); },
|
---|
612 | stop: function(event, ui) {
|
---|
613 | // gsf metadata
|
---|
614 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_metadata')) { replace_with(ui.item, gsf_metadata_element); }
|
---|
615 | // gsf choose metadata
|
---|
616 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_choose_metadata')) { replace_with(ui.item, gsf_choose_metadata_element); }
|
---|
617 | // gsf link
|
---|
618 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_link')) { replace_with(ui.item, gsf_link_element); }
|
---|
619 | // gsf switch
|
---|
620 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_switch')) { replace_with(ui.item, gsf_switch_element); }
|
---|
621 |
|
---|
622 | }
|
---|
623 |
|
---|
624 | });
|
---|
625 |
|
---|
626 | $('.td-div').click(function () {
|
---|
627 | //console.log('td class click');
|
---|
628 | return true;
|
---|
629 | });
|
---|
630 |
|
---|
631 |
|
---|
632 |
|
---|
633 | }
|
---|
634 |
|
---|
635 |
|
---|
636 | function bind_choose_metadata_sortable()
|
---|
637 | {
|
---|
638 | //console.log('function bind_choose_metadata_sortable()');
|
---|
639 | $('.gsf_choose_metadata').sortable({
|
---|
640 | 'cursor':'pointer',
|
---|
641 | 'tolerance': 'pointer',
|
---|
642 | 'items':'.gsf_metadata, .gsf_text, .gsf_default',
|
---|
643 | 'placeholder':'placeholder',
|
---|
644 | 'connectWith':'.gsf_choose_metadata',
|
---|
645 | //'nested':'.gsf:metadata'
|
---|
646 | stop: function(event, ui) {
|
---|
647 | // gsf metadata
|
---|
648 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_metadata')) { replace_with(ui.item, gsf_metadata_element); }
|
---|
649 | // gsf text
|
---|
650 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_text')) { replace_with(ui.item, gsf_text_element); }
|
---|
651 | // gsf default
|
---|
652 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_default')) { replace_with(ui.item, gsf_default_element); }
|
---|
653 |
|
---|
654 | bind_all_sortables();
|
---|
655 | }
|
---|
656 | });
|
---|
657 | }
|
---|
658 |
|
---|
659 | function bind_link_sortable()
|
---|
660 | {
|
---|
661 | //console.log('function bind_link_sortable()');
|
---|
662 | $('.gsf_link').sortable({
|
---|
663 | 'cursor':'pointer',
|
---|
664 | 'tolerance': 'pointer',
|
---|
665 | 'items':'.leaf, .gsf_link, .gsf_switch, .gsf_choose',
|
---|
666 | 'placeholder':'placeholder',
|
---|
667 | 'connectWith':'.gsf_link',
|
---|
668 | //'nested':'.gsf:metadata'
|
---|
669 | stop: function(event, ui) {
|
---|
670 | // gsf icon
|
---|
671 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_icon')) { replace_with(ui.item, gsf_icon_element); }
|
---|
672 | // gsf text
|
---|
673 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_text')) { replace_with(ui.item, "<input type=\"text\" name=\"rawtextinput\" size=\"10\"/>"); }
|
---|
674 | // gsf metadata
|
---|
675 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_metadata')) { replace_with(ui.item, gsf_metadata_element); }
|
---|
676 | // gsf link
|
---|
677 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_link')) { replace_with(ui.item, gsf_link_element); }
|
---|
678 | // gsf switch
|
---|
679 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_switch')) { replace_with(ui.item, gsf_switch_element); }
|
---|
680 | // gsf choose
|
---|
681 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_choose_metadata')) { replace_with(ui.item, gsf_choose_metadata_element); }
|
---|
682 | }
|
---|
683 | });
|
---|
684 | }
|
---|
685 |
|
---|
686 | function bind_switch_sortable()
|
---|
687 | {
|
---|
688 | //console.log('function bind_switch_sortable()');
|
---|
689 | $('.gsf_switch').sortable({
|
---|
690 | 'cursor':'pointer',
|
---|
691 | 'tolerance': 'pointer',
|
---|
692 | 'items':'.gsf_metadata, .gsf_when, .gsf_otherwise, .gsf_text',
|
---|
693 | 'placeholder':'placeholder',
|
---|
694 | 'connectWith':'.gsf_switch',
|
---|
695 | //'nested':'.gsf:metadata'
|
---|
696 | stop: function(event, ui) {
|
---|
697 | // gsf when
|
---|
698 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_when')) { replace_with(ui.item, gsf_when_element); }
|
---|
699 | // gsf otherwise
|
---|
700 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_otherwise')) { replace_with(ui.item, gsf_otherwise_element); }
|
---|
701 | // gsf metadata
|
---|
702 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_metadata')) { replace_with(ui.item, gsf_metadata_element); }
|
---|
703 | // gsf text
|
---|
704 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_text')) { replace_with(ui.item, gsf_text_element); }
|
---|
705 | }
|
---|
706 | });
|
---|
707 | }
|
---|
708 |
|
---|
709 | function bind_when_sortable()
|
---|
710 | {
|
---|
711 | //console.log('function bind_when_sortable()');
|
---|
712 | $('.gsf_when').sortable({
|
---|
713 | 'cursor':'pointer',
|
---|
714 | 'tolerance': 'pointer',
|
---|
715 | 'items':'.leaf, .gsf_link, .gsf_choose',
|
---|
716 | 'placeholder':'placeholder',
|
---|
717 | //'nested':'.gsf:metadata'
|
---|
718 | stop: function(event, ui) {
|
---|
719 | // gsf metadata
|
---|
720 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_metadata')) { replace_with(ui.item, gsf_metadata_element); }
|
---|
721 | // gsf icon
|
---|
722 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_icon')) { replace_with(ui.item, gsf_icon_element); }
|
---|
723 | // gsf text
|
---|
724 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_text')) { replace_with(ui.item, gsf_text_element); }
|
---|
725 | // gsf link
|
---|
726 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_link')) { replace_with(ui.item, gsf_link_element); }
|
---|
727 | // gsf choose
|
---|
728 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_choose')) { replace_with(ui.item, gsf_choose_element); }
|
---|
729 | }
|
---|
730 | });
|
---|
731 | }
|
---|
732 |
|
---|
733 | function bind_otherwise_sortable()
|
---|
734 | {
|
---|
735 | //console.log('function bind_otherwise_sortable()');
|
---|
736 | $('.gsf_otherwise').sortable({
|
---|
737 | 'cursor':'pointer',
|
---|
738 | 'tolerance': 'pointer',
|
---|
739 | 'items':'.leaf, .gsf_link, .gsf_choose',
|
---|
740 | 'placeholder':'placeholder',
|
---|
741 | //'nested':'.gsf:metadata'
|
---|
742 | stop: function(event, ui) {
|
---|
743 | // gsf metadata
|
---|
744 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_metadata')) { replace_with(ui.item, gsf_metadata_element); }
|
---|
745 | // gsf text
|
---|
746 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_text')) { replace_with(ui.item, "<input type=\"text\" name=\"rawtextinput\" size=\"10\"/>"); }
|
---|
747 | // gsf icon
|
---|
748 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_icon')) { replace_with(ui.item, gsf_icon_element); }
|
---|
749 | // gsf link
|
---|
750 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_link')) { replace_with(ui.item, gsf_link_element); }
|
---|
751 | // gsf choose
|
---|
752 | if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_choose')) { replace_with(ui.item, gsf_choose_element); }
|
---|
753 | }
|
---|
754 | });
|
---|
755 | }
|
---|
756 |
|
---|
757 | function bind_block_mouseover()
|
---|
758 | {
|
---|
759 | //console.log('function bind_block_mouseover()');
|
---|
760 | $(".block").mouseover(function()
|
---|
761 | {
|
---|
762 | $(this).parents().css("border", "");
|
---|
763 | $(this).css("border", "2px solid blue");
|
---|
764 | return false;
|
---|
765 | }).mouseout(function(){
|
---|
766 | $(this).css("border", "");
|
---|
767 | return false;
|
---|
768 | });
|
---|
769 | }
|
---|
770 |
|
---|
771 | function bind_minmax_remove()
|
---|
772 | {
|
---|
773 | console.log('function bind_minmax_remove()');
|
---|
774 | $('a.minmax').bind('click', toggleContent);
|
---|
775 | $('a.remove').bind('click', removeContent);
|
---|
776 | };
|
---|
777 |
|
---|
778 | var removeContent = (function () {
|
---|
779 | //console.log('var removeContent = (function ()');
|
---|
780 | // this -> a -> td -> tr -> tbody -> table -> div
|
---|
781 | //$(this).parent().parent().parent().parent().parent().remove();
|
---|
782 | $(this).closest(".block").remove();
|
---|
783 | });
|
---|
784 |
|
---|
785 |
|
---|
786 | var toggleContent = function(e)
|
---|
787 | {
|
---|
788 | //console.log('var toggleContent = function(e)');
|
---|
789 | console.log('parent: ' + $(this).html());
|
---|
790 | if ($(this).html() == '[+]'){ //targetContent.css('display') == 'none') {
|
---|
791 | //$(this).parent().parent().parent().parent().parent().children(".block,.table").slideDown(300);
|
---|
792 | //$(this).parents().children(".block,.table").stopPropagation().slideDown(300);
|
---|
793 | //var x = $(this).parent().parent().parent().parent().parent();
|
---|
794 | //var y = $(this).parent().parent().parent().parent().parent().children(".block,.table");
|
---|
795 | //var z = $(this).closest(".block").children(".table, .block");
|
---|
796 | $(this).closest(".block").children(".table, .block").slideDown(300);
|
---|
797 | $(this).html('[-]');
|
---|
798 | $(this).removeClass("ui-icon-plusthick");
|
---|
799 | $(this).addClass("ui-icon-minusthick");
|
---|
800 | } else {
|
---|
801 | //$(this).parent().parent().parent().parent().parent().children(".block,.table").slideUp(300);
|
---|
802 | //$(this).parents().children(".block,.table").slideUp(300);
|
---|
803 | $(this).closest(".block").children(".table, .block").slideUp(300);
|
---|
804 | $(this).html('[+]');
|
---|
805 | $(this).removeClass("ui-icon-minusthick");
|
---|
806 | $(this).addClass("ui-icon-plusthick");
|
---|
807 | }
|
---|
808 | return false;
|
---|
809 | };
|
---|
810 |
|
---|
811 | function serialize(s)
|
---|
812 | {
|
---|
813 | serial = $.SortSerialize(s);
|
---|
814 | alert(serial.hash);
|
---|
815 | };
|
---|
816 |
|
---|
817 | function equalHeights(item, height) {
|
---|
818 | //console.log('function equalHeights(item, height)');
|
---|
819 | (item.parents('.table')).each(function(index) {
|
---|
820 | $(this).children().children().children().each(function() {
|
---|
821 | $(this).height(height);
|
---|
822 | $(this).children().height(height);
|
---|
823 | });
|
---|
824 | });
|
---|
825 | };
|
---|
826 |
|
---|