source: main/trunk/greenstone3/web/interfaces/oran/js/gui_div.js@ 23336

Last change on this file since 23336 was 23336, checked in by sjb48, 13 years ago

Continued work on XHTML parsing for format statement saving. Found js code for ensuring XHTML (innerXHTML). Removed a few unneccessary bits of code from default servlet that were lingering around from when we first started playing with format statements.

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