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