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