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