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