- Timestamp:
- 2013-03-27T12:04:48+13:00 (11 years ago)
- Location:
- main/trunk/greenstone3/web/interfaces/default/js
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/web/interfaces/default/js/debug_scripts.js
r27129 r27130 4 4 //Private member variables 5 5 //************************ 6 6 7 7 //The this variable 8 8 var _greenbug = this; 9 9 10 10 //Debugger state-keeping variables 11 11 var _debugOn = false; … … 15 15 var _editModeText = false; 16 16 var _selectedTemplate; 17 17 18 18 //Page elements 19 19 var _mainDiv; 20 20 21 21 var _textEditor; 22 22 var _vEditor; 23 23 24 24 var _navArea; 25 25 var _fileSelector; … … 27 27 var _editor; 28 28 var _editingDiv; 29 var _ unpauseButton;29 var _selectNewElementButton; 30 30 var _closeEditorButton; 31 31 var _xmlStatusBar; 32 32 var _saveButton; 33 33 var _swapEditorButton; 34 34 35 35 //Editor state-keeping variables 36 36 var _currentFileName; … … 41 41 var _currentNamespace; 42 42 var _isVisualEditor = true; 43 43 44 44 var _styleFunctions = new Array(); 45 45 46 //Used to reload the page while keeping the state of the editor 46 47 var partialPageReload = function(callback) 47 48 { … … 53 54 var bodyEndIndex = response.indexOf("</body>"); 54 55 var bodyText = response.substring(bodyStartIndex, bodyEndIndex + 7); 55 56 56 57 //Get the current top area and container 57 58 var topLevelTopArea = $("#topArea"); 58 59 var topLevelContainer = $("#container"); 59 60 60 61 //Create a temporary div and put the html into it 61 62 var tempDiv = $("<div>"); 62 63 tempDiv.html(bodyText); 63 64 64 65 //Replace the contents of the old elements with the new elements 65 66 var topArea = tempDiv.find("#topArea"); … … 67 68 topLevelTopArea.html(topArea.html()); 68 69 topLevelContainer.html(container.html()); 69 70 70 71 //Update the events for the debug elements that currently don't have events associated with them 71 72 var debugElems = $('debug, [debug="true"]').filter(function(){return (!($.data(this, "events"))) ? true : false}); … … 76 77 alert("There was an error reloading the page, please reload manually."); 77 78 }); 78 79 79 80 if(callback) 80 81 { … … 82 83 } 83 84 } 84 85 86 //Some functions need to be called after an element is added to the page. So we store them and call them later. 85 87 var callStyleFunctions = function() 86 88 { … … 91 93 } 92 94 } 93 95 96 //Create the area where the buttons are stored 94 97 var createButtonDiv = function(buttonDiv) 95 98 { 96 var pickElementButton = $("<button>Enable selector</button>"); 97 pickElementButton.click(function() 99 //Used to enable the selector to get the templates of a particular area of the page 100 var enableSelectorButton = $("<button>Enable selector</button>"); 101 enableSelectorButton.click(function() 98 102 { 99 103 if(!_debugOn) 100 104 { 101 pickElementButton.button("option", "label", "Disable selector");105 enableSelectorButton.button("option", "label", "Disable selector"); 102 106 $("a").click(function(e) 103 107 { … … 108 112 else 109 113 { 110 pickElementButton.button("option", "label", "Enable selector");114 enableSelectorButton.button("option", "label", "Enable selector"); 111 115 $("a").off("click"); 112 116 clearAll(); 113 _ unpauseButton.button("option", "disabled", true);117 _selectNewElementButton.button("option", "disabled", true); 114 118 _pauseSelector = false; 115 119 _debugOn = false; 116 120 } 117 121 }); 118 _styleFunctions.push(function(){pickElementButton.button({icons:{primary:"ui-icon-power"}})}); 119 120 _unpauseButton = $("<button>Select new element</button>"); 121 _unpauseButton.click(function() 122 _styleFunctions.push(function(){enableSelectorButton.button({icons:{primary:"ui-icon-power"}})}); 123 124 //Used to change what is currently selected 125 _selectNewElementButton = $("<button>Select new element</button>"); 126 _selectNewElementButton.click(function() 122 127 { 123 128 if(_pauseSelector) 124 129 { 125 130 _pauseSelector = false; 126 _unpauseButton.button("option", "disabled", true); 127 } 128 }); 129 _styleFunctions.push(function(){_unpauseButton.button({icons:{primary:"ui-icon-pencil"}, disabled:true})}); 130 131 _selectNewElementButton.button("option", "disabled", true); 132 } 133 }); 134 _styleFunctions.push(function(){_selectNewElementButton.button({icons:{primary:"ui-icon-pencil"}, disabled:true})}); 135 136 //Used to minimise/restore the editor 131 137 _closeEditorButton = $("<button>Close editor</button>"); 132 138 _closeEditorButton.click(function() … … 145 151 _closeEditorButton.css("float", "right"); 146 152 _styleFunctions.push(function(){_closeEditorButton.button({icons:{secondary:"ui-icon-newwin"}, disabled:true})}); 147 153 154 //Used to save any changes that have been made to this template 148 155 _saveButton = $("<button>Save changes</button>"); 149 156 _saveButton.click(function() … … 162 169 } 163 170 xmlString = xmlString.replace(/&/g, "&"); 164 171 165 172 try 166 173 { … … 172 179 return; 173 180 } 174 181 175 182 var url = gs.xsltParams.library_name; 176 183 var parameters = {"a":"g", "rt":"r", "s":"SaveXMLTemplateToFile", "s1.locationName":_currentLocation, "s1.fileName":_currentFileName, "s1.interfaceName":gs.xsltParams.interface_name, "s1.siteName":gs.xsltParams.site_name, "s1.collectionName":gs.cgiParams.c, "s1.namespace":_currentNamespace, "s1.nodename":_currentNodename, "s1.xml":xmlString}; … … 207 214 }); 208 215 _styleFunctions.push(function(){_saveButton.button({icons:{primary:"ui-icon-disk"}, disabled:true})}); 209 216 217 //Used to switch between the XML and Visual editors 210 218 _swapEditorButton = $("<button>Switch to XML editor</button>"); 211 219 _swapEditorButton.button().click(function() … … 253 261 }); 254 262 _styleFunctions.push(function(){_swapEditorButton.button({icons:{primary:"ui-icon-refresh"}})}); 255 263 256 264 undoButton = $("<button>Undo</button>"); 257 265 undoButton.click(function() … … 267 275 }); 268 276 _styleFunctions.push(function(){undoButton.button({icons:{primary:"ui-icon-arrowreturnthick-1-w"}})}); 269 270 buttonDiv.append( pickElementButton);271 buttonDiv.append(_ unpauseButton);277 278 buttonDiv.append(enableSelectorButton); 279 buttonDiv.append(_selectNewElementButton); 272 280 buttonDiv.append(_closeEditorButton); 273 281 buttonDiv.append(_saveButton); … … 275 283 buttonDiv.append(undoButton); 276 284 } 277 285 286 //Used to monitor the state of the XML in the XML editor and will notify the user if there is an error 278 287 var createXMLStatusBar = function(buttonDiv) 279 288 { … … 282 291 _xmlStatusBar.addClass("ui-corner-all"); 283 292 _styleFunctions.push(function(){_xmlStatusBar.hide();}); 284 293 285 294 //Check the XML for errors every 2 seconds 286 295 setInterval(function() … … 304 313 return; 305 314 } 306 315 307 316 _xmlStatusBar.text("XML OK!"); 308 317 _xmlStatusBar.addClass("ui-state-active"); … … 318 327 } 319 328 } 320 321 329 }, 2000); 322 330 buttonDiv.append(_xmlStatusBar); 323 331 } 324 332 333 //Create the elements that allow 325 334 var createFileAndTemplateSelectors = function(buttonDiv) 326 335 { … … 338 347 }); 339 348 _templateSelector.append(templateSelectBox); 340 _fileSelector = $("<div>", {"id":"veFileSelector" , "class":"ui-state-default ui-corner-all"});349 _fileSelector = $("<div>", {"id":"veFileSelector"}); 341 350 buttonDiv.append(_fileSelector); 342 351 buttonDiv.append(_templateSelector); 343 } 344 352 353 //Populate the file selector 354 var url = gs.xsltParams.library_name + "?a=g&rt=r&s=GetXSLTFilesForCollection&s1.interfaceName=" + gs.xsltParams.interface_name + "&s1.siteName=" + gs.xsltParams.site_name + "&s1.collectionName=" + gs.cgiParams.c; 355 $.ajax(url) 356 .success(function(response) 357 { 358 var listStartIndex = response.indexOf("<fileListJSON>") + "<fileListJSON>".length; 359 var listEndIndex = response.indexOf("</fileListJSON>"); 360 361 var listString = response.substring(listStartIndex, listEndIndex).replace(/"/g, "\"").replace(/\\/g, "/"); 362 var list = eval(listString); 363 364 var selectBox = $("<select>"); 365 selectBox.append($("<option>-- Select a file --</option>", {value:"none"})); 366 _fileSelector.addClass("ui-state-default"); 367 _fileSelector.addClass("ui-corner-all"); 368 _fileSelector.append("<span>Files: </span>"); 369 _fileSelector.append(selectBox); 370 for(var i = 0; i < list.length; i++) 371 { 372 var item = list[i]; 373 var option = $("<option>" + item.path + " (" + item.location + ")</option>", {value:item.path}); 374 option.data("fileItem", item); 375 selectBox.append(option); 376 } 377 378 selectBox.change(function() 379 { 380 var selectedItem = selectBox.find(":selected"); 381 382 if(!selectedItem.data("fileItem")) 383 { 384 return; 385 } 386 387 var getURL = gs.xsltParams.library_name + "?a=g&rt=r&s=GetTemplateListFromFile&s1.fileName=" + selectedItem.data("fileItem").path + "&s1.locationName=" + selectedItem.data("fileItem").location + "&s1.interfaceName=" + gs.xsltParams.interface_name + "&s1.siteName=" + gs.xsltParams.site_name + "&s1.collectionName=" + gs.cgiParams.c; 388 $.ajax(getURL) 389 .success(function(templateResponse) 390 { 391 var templateListStart = templateResponse.indexOf("<templateList>") + "<templateList>".length; 392 var templateListEnd = templateResponse.indexOf("</templateList>"); 393 var templateListString = templateResponse.substring(templateListStart, templateListEnd).replace(/"/g, "\""); 394 var templateList = eval(templateListString); 395 396 clearAll(); 397 398 _templateSelector.children("select").empty(); 399 if(templateList.length == 0) 400 { 401 _templateSelector.children("select").append("<option>-- No templates --</option>"); 402 } 403 else 404 { 405 _templateSelector.children("select").append("<option>-- Select a template --</option>"); 406 } 407 408 for(var i = 0; i < templateList.length; i++) 409 { 410 var fileName = selectedItem.data("fileItem").path; 411 var location = selectedItem.data("fileItem").location; 412 var namespace = templateList[i].namespace; 413 var nodename = "template"; 414 var name = templateList[i].name; 415 var match = templateList[i].match; 416 417 if(name) 418 { 419 name = templateList[i].name.replace(/'/g, "'").replace(/"/g, "\"").replace(/&/g, "&"); 420 } 421 if(match) 422 { 423 match = templateList[i].match.replace(/'/g, "'").replace(/"/g, "\"").replace(/&/g, "&"); 424 } 425 426 var infoContainer = $("<option>"); 427 428 _elements.push(infoContainer); 429 430 addChangeEventToInfoContainer(infoContainer, fileName, location, nodename, namespace, name, match); 431 432 if(name && name.length > 0) 433 { 434 infoContainer.text(name); 435 } 436 if(match && match.length > 0) 437 { 438 infoContainer.text(match); 439 } 440 441 _templateSelector.children("select").append(infoContainer); 442 } 443 }); 444 }); 445 }) 446 .error(function() 447 { 448 console.log("Error retrieving XSLT files"); 449 }); 450 } 451 452 //The function that creates all the necessary elements for Greenbug 345 453 var createDebugDiv = function() 346 454 { … … 368 476 createFileAndTemplateSelectors(buttonDiv); 369 477 createXMLStatusBar(buttonDiv); 370 371 //Populate the file selector 372 var url = gs.xsltParams.library_name + "?a=g&rt=r&s=GetXSLTFilesForCollection&s1.interfaceName=" + gs.xsltParams.interface_name + "&s1.siteName=" + gs.xsltParams.site_name + "&s1.collectionName=" + gs.cgiParams.c; 373 $.ajax(url) 374 .success(function(response) 375 { 376 var listStartIndex = response.indexOf("<fileListJSON>") + "<fileListJSON>".length; 377 var listEndIndex = response.indexOf("</fileListJSON>"); 378 379 var listString = response.substring(listStartIndex, listEndIndex).replace(/"/g, "\"").replace(/\\/g, "/"); 380 var list = eval(listString); 381 382 var selectBox = $("<select>"); 383 selectBox.append($("<option>-- Select a file --</option>", {value:"none"})); 384 _fileSelector.append("<span>Files: </span>"); 385 _fileSelector.append(selectBox); 386 for(var i = 0; i < list.length; i++) 387 { 388 var item = list[i]; 389 var option = $("<option>" + item.path + " (" + item.location + ")</option>", {value:item.path}); 390 option.data("fileItem", item); 391 selectBox.append(option); 392 } 393 394 selectBox.change(function() 395 { 396 var selectedItem = selectBox.find(":selected"); 397 398 if(!selectedItem.data("fileItem")) 399 { 400 return; 401 } 402 403 var getURL = gs.xsltParams.library_name + "?a=g&rt=r&s=GetTemplateListFromFile&s1.fileName=" + selectedItem.data("fileItem").path + "&s1.locationName=" + selectedItem.data("fileItem").location + "&s1.interfaceName=" + gs.xsltParams.interface_name + "&s1.siteName=" + gs.xsltParams.site_name + "&s1.collectionName=" + gs.cgiParams.c; 404 $.ajax(getURL) 405 .success(function(templateResponse) 406 { 407 var templateListStart = templateResponse.indexOf("<templateList>") + "<templateList>".length; 408 var templateListEnd = templateResponse.indexOf("</templateList>"); 409 var templateListString = templateResponse.substring(templateListStart, templateListEnd).replace(/"/g, "\""); 410 var templateList = eval(templateListString); 411 412 clearAll(); 413 414 _templateSelector.children("select").empty(); 415 if(templateList.length == 0) 416 { 417 _templateSelector.children("select").append("<option>-- No templates --</option>"); 418 } 419 else 420 { 421 _templateSelector.children("select").append("<option>-- Select a template --</option>"); 422 } 423 424 for(var i = 0; i < templateList.length; i++) 425 { 426 var fileName = selectedItem.data("fileItem").path; 427 var location = selectedItem.data("fileItem").location; 428 var namespace = templateList[i].namespace; 429 var nodename = "template"; 430 var name = templateList[i].name; 431 var match = templateList[i].match; 432 433 if(name) 434 { 435 name = templateList[i].name.replace(/'/g, "'").replace(/"/g, "\"").replace(/&/g, "&"); 436 } 437 if(match) 438 { 439 match = templateList[i].match.replace(/'/g, "'").replace(/"/g, "\"").replace(/&/g, "&"); 440 } 441 442 var infoContainer = $("<option>"); 443 444 _elements.push(infoContainer); 445 446 addMouseEventsToInfoContainer(infoContainer, fileName, location, nodename, namespace, name, match); 447 448 if(name && name.length > 0) 449 { 450 infoContainer.text(name); 451 } 452 if(match && match.length > 0) 453 { 454 infoContainer.text(match); 455 } 456 457 if(_templateSelector.children("div").length > 0) 458 {/* 459 var spacer = $("<div>>></div>"); 460 spacer.addClass("gbSpacer"); 461 462 _templateSelector.prepend(spacer); 463 _elements.push(spacer); 464 */ 465 } 466 467 _templateSelector.children("select").append(infoContainer); 468 469 //resizeContainers(); 470 } 471 }); 472 }); 473 }) 474 .error(function() 475 { 476 console.log("Error retrieving XSLT files"); 477 }); 478 478 479 479 _styleFunctions.push(function(){$(".ui-button").css({"margin-right":"0.5em"});}); 480 480 481 481 _mainDiv.append(toolBarDiv); 482 482 _mainDiv.append(_editingDiv); 483 483 _mainDiv.append(_navArea); 484 484 } 485 485 486 //Clear all selected elements on the page 486 487 var clearAll = function() 487 488 { … … 492 493 }); 493 494 } 494 495 496 //Put a border around the given element 495 497 var highlightElement = function(e) 496 498 { … … 512 514 _elements.push(rightBorderDiv); 513 515 } 514 516 517 //Change the current template in the XML and Visual editor 515 518 this.changeCurrentTemplate = function(location, fileName, nodename, namespace, name, match) 516 519 { 517 520 var responseName = "requestedNameTemplate"; 518 521 519 522 var url = gs.xsltParams.library_name + "?a=g&rt=r&s=GetXMLTemplateFromFile&s1.fileName=" + fileName + "&s1.interfaceName=" + gs.xsltParams.interface_name + "&s1.siteName=" + gs.xsltParams.site_name + "&s1.collectionName=" + gs.cgiParams.c + "&s1.locationName=" + location + "&s1.namespace=" + namespace + "&s1.nodename=" + nodename; 520 523 if(match && match.length > 0){url += "&s1.match=" + match; responseName = "requestedMatchTemplate";} … … 535 538 return; 536 539 } 537 540 538 541 _textEditor = $("<div>", {"id":"textEditor"}); 539 542 _textEditor.css({"width":"100%", "height":"300px"}); 540 543 _textEditor.val(template); 541 544 542 545 if(_isVisualEditor) 543 546 { 544 547 _textEditor.hide(); 545 548 } 546 549 547 550 _editingDiv.empty(); 548 551 _editingDiv.append($("<p>Location: " + location + " <br/>Filename: " + fileName + "</p>")); 549 552 _editingDiv.append(_textEditor); 550 553 551 554 _vEditor = new visualXMLEditor(template); 552 555 _editingDiv.append(_vEditor.getMainDiv()); 553 556 _vEditor.setGreenbug(_greenbug); 554 557 _vEditor.selectRootElement(); 555 558 556 559 if(!_isVisualEditor) 557 560 { 558 561 _vEditor.getMainDiv().hide(); 559 562 } 560 563 561 564 _editor = ace.edit("textEditor"); 562 565 _editor.getSession().setMode("ace/mode/xml"); … … 566 569 var UndoManager = require("ace/undomanager").UndoManager; 567 570 _editor.getSession().setUndoManager(new UndoManager()); 568 571 569 572 _textEditor.css({"min-height":"200px", "border-top":"5px solid #444"}); 570 573 _textEditor.resizable({handles: 'n', resize:function() … … 583 586 .error(function() 584 587 { 585 console.log("ERROR"); 586 }); 587 } 588 589 var addMouseEventsToInfoContainer = function(infoContainer, fileName, location, nodename, namespace, name, match) 588 console.log("Error getting the XML template from the file"); 589 }); 590 } 591 592 //Store the function that is called when this template is selected from the list 593 var addChangeEventToInfoContainer = function(infoContainer, fileName, location, nodename, namespace, name, match) 590 594 { 591 595 infoContainer.data("changeFunction", function() … … 598 602 _selectedTemplate.prevBorder = _selectedTemplate.css("border"); 599 603 _selectedTemplate.css("border", "red 1px solid"); 600 604 601 605 _currentFileName = fileName; 602 606 _currentLocation = location; … … 605 609 _currentName = name; 606 610 _currentMatch = match; 607 611 608 612 _greenbug.changeCurrentTemplate(location, fileName, nodename, namespace, name, match); 609 613 }); 610 /* 611 infoContainer.mouseover(function() 612 { 613 $(this).removeClass("ui-state-default"); 614 $(this).addClass("ui-state-active"); 615 }); 616 infoContainer.mouseout(function() 617 { 618 $(this).addClass("ui-state-default"); 619 $(this).removeClass("ui-state-active"); 620 }); 621 */ 622 } 623 614 } 615 616 //Add the mouse events to the <debug> elemetns that are called when the selector is anabled 624 617 var addMouseEventsToDebugElements = function(debugElems) 625 618 { … … 629 622 { 630 623 _pauseSelector = true; 631 _ unpauseButton.button("option", "disabled", false);624 _selectNewElementButton.button("option", "disabled", false); 632 625 } 633 626 }); … … 680 673 var location; 681 674 var fileName; 675 //Use the filepath to work out where this file is from 682 676 if(filepath.search(/[\/\\]interfaces[\/\\]/) != -1) 683 677 { … … 705 699 _elements.push(infoContainer); 706 700 707 add MouseEventsToInfoContainer(infoContainer, fileName, location, nodename, namespace, name, match);701 addChangeEventToInfoContainer(infoContainer, fileName, location, nodename, namespace, name, match); 708 702 709 703 if(name && name.length > 0) … … 716 710 } 717 711 718 if(_templateSelector.children("div").length > 0)719 {720 /*721 var spacer = $("<div>>></div>");722 spacer.addClass("gbSpacer");723 724 _templateSelector.prepend(spacer);725 _elements.push(spacer);726 */727 }728 729 712 _templateSelector.children("select").append(infoContainer); 730 731 //resizeContainers();732 713 }); 733 714 … … 750 731 }); 751 732 } 752 733 734 //Remove <debug> elements from the title 753 735 var fixTitle = function() 754 736 { 755 737 $("title").text($("title").text().replace(/<[^>]*>/g, "")); 756 738 } 757 758 /* 759 var resizeContainers = function() 760 { 761 var templates = _templateSelector.children(".gbTemplateContainer"); 762 var spacers = _templateSelector.children(".gbSpacer"); 763 764 var templateWidth = (79/templates.length) + "%"; 765 templates.css("width", templateWidth); 766 767 if(spacers.length > 0) 768 { 769 var spacersWidth = (19/spacers.length) + "%"; 770 spacers.css("width", spacersWidth); 771 } 772 } 773 */ 774 739 740 //Initialise Greenbug 775 741 this.init = function() 776 742 { … … 805 771 createDebugDiv(); 806 772 $("body").append(_mainDiv); 807 773 808 774 callStyleFunctions(); 809 775 … … 811 777 fixTitle(); 812 778 } 813 814 779 } 815 780 781 //The code entry point 816 782 $(window).load(function() 817 783 { -
main/trunk/greenstone3/web/interfaces/default/js/visual-xml-editor.js
r27110 r27130 3 3 // This class represents an editor that allows you to modify XML visually // 4 4 // ********************************************************************** // 5 6 5 function visualXMLEditor(xmlString) 7 6 { 7 //Variables that store the visual editor and a link to the DebugWidget 8 8 var _thisEditor = this; 9 9 var _greenbug; 10 10 11 //Stores what id we are up to (used to compare VEElements) 11 12 var _globalID = 0; 12 13 14 //Stores the current state of the XML 13 15 var _xml; 14 16 17 //Elements of the editor 15 18 var _mainDiv = $("<div>", {"id":"veMainDiv"}); 16 19 var _toolboxDiv = $("<div>", {"id":"veToolboxDiv"}); … … 18 21 var _editorDiv = $("<div>", {"id":"veEditorDiv"}); 19 22 var _infoDiv = $("<div>", {"id":"veInfoDiv"}); 23 24 //State-keeping variables 20 25 var _rootElement; 21 26 var _selectedElement; 22 23 27 var _overTrash = false; 24 25 28 var _validDropSpot = false; 26 29 var _validDropType; 27 30 var _validDropElem; 28 29 31 var _origDDParent; 30 32 var _origDDPosition; 31 33 34 //Keep track of what is currently being edited 32 35 var _editingNodes = new Array(); 33 36 37 //Stores what elements we are currently over while dragging (necessary to find the deepest element) 34 38 var _overList = new Array(); 35 39 _overList.freeSpaces = new Array(); 36 40 41 //Keep a list of what has been changed so that it can be undone 37 42 var _transactions = new Array(); 38 43 44 //A list of "ready-made" attributes for certain elements 39 45 var _validAttrList = 40 46 { … … 58 64 } 59 65 } 60 66 67 //The list of elements that show up in the toolbox (gslib is added dynamically later) 61 68 var _elemList = 62 69 { … … 80 87 ] 81 88 }; 82 89 90 //Restricts what elements can be added to a given element 83 91 var _childRestrictions = 84 92 { … … 89 97 } 90 98 }; 91 99 100 //Get a connection to the DebugWidget 92 101 this.setGreenbug = function(gb) 93 102 { 94 103 _greenbug = gb; 95 104 } 96 105 106 //Get the XML in its current state 97 107 this.getXML = function() 98 108 { 99 109 return _xml; 100 110 } 101 111 112 //Undo a transation 102 113 this.undo = function() 103 114 { … … 118 129 var pos = t.vElemPos; 119 130 var elem = t.vElem; 120 131 121 132 elem.detach(); 122 133 if(pos == 0) … … 188 199 } 189 200 } 190 201 202 //Check if an element is allowed as a child to another element 191 203 var checkRestricted = function(child, parent) 192 204 { … … 205 217 pNodeName = pFullNodename.substring(pFullNodename.indexOf(":") + 1); 206 218 } 207 219 208 220 var namespaceList = _childRestrictions[pNamespace]; 209 221 if(namespaceList) … … 222 234 } 223 235 } 224 236 225 237 return true; 226 238 } 227 239 240 //Add the trash bin to the editor 228 241 var placeTrashBin = function() 229 242 { … … 246 259 _editorContainer.append(bin); 247 260 } 248 261 262 //Dynamically retrieve the gslib elements from the gslib.xsl file to put into the toolbox 249 263 var retrieveGSLIBTemplates = function(callback) 250 264 { … … 256 270 startIndex = response.search("<templateList>") + "<templateList>".length; 257 271 endIndex = response.search("</templateList>"); 258 272 259 273 var listString = response.substring(startIndex, endIndex); 260 274 var list = eval(listString.replace(/"/g, "\"")); 261 275 var modifiedList = new Array(); 262 276 263 277 for(var i = 0; i < list.length; i++) 264 278 { … … 269 283 } 270 284 } 271 285 272 286 _elemList["gslib"] = modifiedList; 273 287 274 288 if(callback) 275 289 { … … 282 296 }); 283 297 } 284 298 299 //Create the toolbar 285 300 var populateToolbar = function() 286 301 { … … 316 331 _toolboxDiv.append(tabDiv); 317 332 } 318 333 319 334 var otherTab = $("<li>"); 320 335 var otherTabLink = $("<a>", {"href":"#veother"}); … … 323 338 otherTab.append(otherTabLink); 324 339 tabHolder.append(otherTab); 325 340 326 341 var otherTabDiv = $("<div>", {"id":"veother"}); 327 342 var textNode = _xml.createTextNode("text"); … … 331 346 textDiv.data("toolbar", true); 332 347 otherTabDiv.append(textDiv); 333 348 334 349 var customInput = $("<input type=\"text\">"); 335 350 var customElemHolder = $("<div>"); … … 352 367 otherTabDiv.append(customCreateButton); 353 368 otherTabDiv.append(customElemHolder); 354 369 355 370 _toolboxDiv.append(otherTabDiv); 356 371 357 372 _toolboxDiv.tabs(); 358 373 359 374 customCreateButton.button(); 360 375 } 361 376 377 //Turns the given XML into the nice visual structure recursively 362 378 var constructDivsRecursive = function(currentDiv, currentParent, level) 363 379 { … … 370 386 container.addClass("veContainerElement"); 371 387 currentDiv.append(container); 372 388 373 389 var allowedList = new Array(); 374 390 var counter = currentParent.firstChild; … … 394 410 var elementDiv = veElement.getDiv(); 395 411 veElement.setWidth(width); 396 412 397 413 if(!_rootElement) 398 414 { … … 411 427 container.append($("<div>", {"style":"clear:both;"})); 412 428 } 413 429 430 //Fake a click on the root element 414 431 this.selectRootElement = function() 415 432 { 416 433 var height = _editorDiv.height() + 10; 417 434 if(height < 300){height = 300;} 418 435 419 436 _editorContainer.css("height", height + "px"); 420 437 _infoDiv.css("height", height + "px"); 421 438 _rootElement.trigger("click"); 422 439 } 423 440 441 //Return the main visual editor div 424 442 this.getMainDiv = function() 425 443 { 426 444 return _mainDiv; 427 445 } 428 446 447 //Save any unfinished edits 429 448 this.savePendingEdits = function() 430 449 { … … 435 454 } 436 455 } 437 456 457 //Add the given VEElement to the list of VEElements we are currently dragging over 438 458 var addToOverList = function(veElement) 439 459 { … … 442 462 return; 443 463 } 444 464 445 465 for(var i = 0; i < _overList.length; i++) 446 466 { … … 449 469 continue; 450 470 } 451 471 452 472 if(_overList[i].getID() == veElement.getID()) 453 473 { … … 455 475 } 456 476 } 457 477 458 478 if(_overList.freeSpaces.length > 0) 459 479 { … … 465 485 } 466 486 } 467 487 488 //Remove the given VEElement from the list of VElements we are currently dragging over 468 489 var removeFromOverList = function(veElement) 469 490 { … … 474 495 continue; 475 496 } 476 497 477 498 if(_overList[i].getID() == veElement.getID()) 478 499 { … … 482 503 } 483 504 } 484 505 506 //Get the deepest VEElement we are currently dragging over 485 507 var getDeepestOverElement = function() 486 508 { … … 512 534 return deepestElem; 513 535 } 514 536 537 //Resize all the VEElements 515 538 var resizeAll = function() 516 539 { … … 519 542 var toolbarStatus = $(this).data("toolbar"); 520 543 var beingDraggedStatus = $(this).data("dragging"); 521 544 522 545 if(beingDraggedStatus || !toolbarStatus) 523 546 { 524 547 return true; 525 548 } 526 549 527 550 return false; 528 551 } 529 552 530 553 var allElems = $(".veElement").filter(filterFunction).each(function() 531 554 { … … 550 573 } 551 574 575 //Initialise the visual editor 552 576 var initVXE = function() 553 577 { … … 573 597 _mainDiv.append($("<div>", {"style":"clear:both;"})); 574 598 } 575 599 576 600 // *********************************************************************** // 577 601 // Visual Editor Text // 578 602 // This inner class represents a single xml text node in the visual editor // 579 603 // *********************************************************************** // 580 581 604 var VEText = function(node) 582 605 { 606 //Constructor code 583 607 var _thisNode = this; 584 608 var _xmlNode = node; 585 609 586 610 var _textEditor = $("<div>"); 587 611 var _nodeText = $("<div>"); … … 589 613 590 614 _textEditor.append(_nodeText); 591 615 592 616 var _editButton = $("<button>Edit text</button>"); 593 617 _editButton.click(function() … … 603 627 }); 604 628 _textEditor.append(_editButton); 605 629 630 //Enable editing of this text node 606 631 this.editMode = function() 607 632 { … … 615 640 } 616 641 642 //Save edits to this text node 617 643 this.saveEdits = function() 618 644 { … … 625 651 } 626 652 } 627 653 628 654 _transactions.push({type:"editText", elem:_xmlNode, vElem: _nodeText, value:_nodeText.data("prevTextValue")}); 629 655 var textArea = _nodeText.find("textarea"); … … 635 661 } 636 662 663 //Create a text node editor 637 664 this.getDiv = function() 638 665 { … … 642 669 } 643 670 } 644 671 645 672 // *********************************************************************** // 646 673 // Visual Editor Attribute // 647 674 // This inner class represents a single xml attribute in the visual editor // 648 675 // *********************************************************************** // 649 650 676 var VEAttribute = function(attrElem, xmlElem, name, value) 651 677 { 678 //Constructor code 652 679 var _name; 653 680 if(name) … … 659 686 _name = attrElem.name; 660 687 } 661 688 662 689 var _value; 663 690 if(value) … … 673 700 674 701 var _thisAttr = this; 675 702 703 //Get the attribute name 676 704 this.getName = function() 677 705 { … … 679 707 } 680 708 709 //Get the attribute value 681 710 this.getValue = function() 682 711 { … … 684 713 } 685 714 715 //Get the name cell of the attribute table 686 716 var createNameCell = function() 687 717 { … … 691 721 } 692 722 723 //Get the value cell of the attribute table 693 724 var createValueCell = function() 694 725 { … … 698 729 } 699 730 731 //Get the edit cell of the attribute table 700 732 var createEditCell = function() 701 733 { 702 734 var cell = $("<td>", {"class":"veEditCell"}); 703 735 var link = $("<a href=\"javascript:;\">edit</a>"); 704 736 705 737 link.click(function() 706 738 { … … 711 743 } 712 744 745 //Get the delete cell of the attribute table 713 746 var createDeleteCell = function() 714 747 { … … 725 758 } 726 759 760 //Create a table row from this attribute 727 761 this.getAsTableRow = function() 728 762 { … … 745 779 return tableRow; 746 780 } 747 781 782 //Enable editing of this attribute 748 783 this.editMode = function(editValue) 749 784 { 750 785 _editingNodes.push(_thisAttr); 751 786 752 787 var nameCell = _row.children("td").eq(0); 753 788 var valueCell = _row.children("td").eq(1); … … 784 819 } 785 820 } 786 821 822 //Save edits to this attribute 787 823 this.saveEdits = function() 788 824 { … … 799 835 var valueCell = _row.children("td").eq(1); 800 836 var editLink = _row.children("td").eq(2).find("a"); 801 837 802 838 editLink.text("edit"); 803 839 editLink.off("click"); … … 809 845 var nameInput = nameCell.children("input"); 810 846 var valueInput = valueCell.children("input"); 811 847 812 848 nameInput.blur(); 813 849 valueInput.blur(); … … 815 851 var name = nameInput.val(); 816 852 var value = valueInput.val(); 817 853 818 854 if(name.length == 0 || name.search(/\w/g) == -1) 819 855 { … … 821 857 return; 822 858 } 823 859 824 860 nameCell.empty(); 825 861 nameCell.text(name); … … 827 863 valueCell.empty(); 828 864 valueCell.text(value); 829 865 830 866 if(nameCell.data("prevName") != "") 831 867 { … … 833 869 } 834 870 _xmlElem.setAttribute(name, value); 835 871 836 872 _transactions.push({type:"editAttr", elem:_xmlElem, row:_row, newName:name, name:_name, value:_value}); 837 873 838 874 _name = name; 839 875 _value = value; … … 853 889 _div.data("parentVEElement", this); 854 890 _div.data("expanded", "normal"); 855 891 892 //Add the necessary functions to make this VEElement draggable 856 893 var makeDraggable = function() 857 894 { 858 895 _div.draggable( 859 896 { 897 "distance":"20", 860 898 "revert":"true", 861 899 "helper":function() … … 864 902 var height = _div.children(".veTitleElement").height(); 865 903 _div.draggable("option", "cursorAt", {top:(height / 2), left:(_div.width() / 2)}); 866 904 867 905 var tempVEE = new VEElement(_xmlNode); 868 906 var tempDiv = tempVEE.getDiv(); … … 952 990 } 953 991 var pos = Math.floor(overChildrenLength * posPercent); 954 992 955 993 if(pos < overChildrenLength - 1) 956 994 { … … 982 1020 { 983 1021 var transactionType = (_div.data("toolbar")) ? "addElem" : "remMvElem"; 984 1022 985 1023 if(_div.data("toolbar")) 986 1024 { … … 990 1028 _div.css("border", "1px solid black"); 991 1029 _div.css("background", _div.data("prevBackground")); 992 1030 993 1031 //If the element was not dropped in a valid place then put it back 994 1032 if(!_validDropSpot && !_div.data("toolbar")) … … 1007 1045 _origDDParent.children(".veElement").eq(_origDDPosition).before(_div); 1008 1046 } 1009 1047 1010 1048 if(_overTrash) 1011 1049 { … … 1034 1072 _transactions.push({type:transactionType, vElemParent:_origDDParent, vElemPos:_origDDPosition, vElem:_div}); 1035 1073 } 1036 1074 1037 1075 _div.data("dragging", false); 1038 1076 _div.data("toolbar", false); 1039 1077 1040 1078 _overList = new Array(); 1041 1079 _overList.freeSpaces = new Array(); … … 1043 1081 }); 1044 1082 1083 //Also make this element a drop-zone for other elements 1045 1084 _div.droppable( 1046 1085 { … … 1057 1096 }); 1058 1097 } 1059 1098 1099 //Get the underlying div 1060 1100 this.getDiv = function() 1061 1101 { 1062 1102 return _div; 1063 1103 } 1064 1104 1105 //Get the XML for this element 1065 1106 this.getXMLNode = function() 1066 1107 { 1067 1108 return _xmlNode; 1068 1109 } 1069 1110 1111 //Get the unique ID of this VEElement 1070 1112 this.getID = function() 1071 1113 { … … 1073 1115 } 1074 1116 1075 var createTableHeader = function() 1076 { 1077 var tableHeader = $("<tr>"); 1078 tableHeader.html("<td class=\"veNameCell\">Name</td><td class=\"veValueCell\">Value</td>"); 1079 return tableHeader; 1080 } 1081 1117 //Fill the information area with details about this element 1082 1118 this.populateInformationDiv = function() 1083 1119 { … … 1104 1140 attributeTable.addClass("veAttributeTableContainer"); 1105 1141 1106 attributeTable.append( createTableHeader());1142 attributeTable.append($("<tr>").html("<td class=\"veNameCell\">Name</td><td class=\"veValueCell\">Value</td>")); 1107 1143 1108 1144 $(_xmlNode.attributes).each(function() … … 1114 1150 _infoDiv.append(attributeTableTitle); 1115 1151 _infoDiv.append(attributeTable); 1116 1152 1117 1153 var addDiv = $("<div>", {"class":"veInfoDivTitle"}); 1118 1154 var addSelect = $("<select>"); … … 1144 1180 } 1145 1181 } 1146 1182 1147 1183 var addButton = $("<button>Add attribute</button>"); 1148 1184 addButton.click(function() … … 1170 1206 _infoDiv.append(addDiv); 1171 1207 addButton.button(); 1172 1208 1173 1209 /* 1174 1210 if(_xmlNode.tagName == "xsl:call-template" && _xmlNode.getAttribute("name").length > 0) … … 1246 1282 } 1247 1283 1284 //Add mouseover/out and click events to this element 1248 1285 var addMouseEvents = function() 1249 1286 { … … 1291 1328 }); 1292 1329 } 1293 1330 1331 //Check if we need to expand an element before we do 1294 1332 var checkResizeNecessary = function() 1295 1333 { … … 1315 1353 return false; 1316 1354 } 1317 1355 1356 //Remove this from the editor 1318 1357 this.remove = function() 1319 1358 { … … 1324 1363 _div.detach(); 1325 1364 _infoDiv.empty(); 1326 1365 1327 1366 if(divParent.length) 1328 1367 { 1329 1368 divParent.first().trigger("click"); 1330 1369 } 1331 1370 1332 1371 $("#veTrash").children("img").attr("src", gs.imageURLs.trashFull); 1333 1372 } 1334 1373 1374 //Expend this element horizontally 1335 1375 this.expand = function() 1336 1376 { … … 1344 1384 $(this).data("expanded", "small"); 1345 1385 }); 1346 1386 1347 1387 _div.animate({width:"80%"}, 1000); 1348 1388 _div.data("expanded", "expanded"); … … 1350 1390 } 1351 1391 1392 //Evenly distribute the children of this node evenly 1352 1393 this.evenlyDistributeChildren = function() 1353 1394 { … … 1361 1402 } 1362 1403 1404 //Expand this node and any parents and evenly distribute its children 1363 1405 this.focus = function() 1364 1406 { … … 1366 1408 { 1367 1409 _div.data("parentVEElement").expand(); 1368 1410 1369 1411 var parents = _div.parents(".veElement"); 1370 1412 parents.each(function() … … 1376 1418 _div.data("parentVEElement").evenlyDistributeChildren(); 1377 1419 } 1378 1420 1421 //Set whether to use the short name for this element (i.e. without the namespace) 1379 1422 this.setShortName = function(short) 1380 1423 { … … 1389 1432 } 1390 1433 1434 //Set the width of this element 1391 1435 this.setWidth = function(width) 1392 1436 { 1393 1437 _div.css("width", width + "%"); 1394 1438 } 1395 1439 1396 1440 //Visual Editor Element constructor 1397 1441 var initVEE = function() … … 1400 1444 _div.addClass("ui-corner-all"); 1401 1445 makeDraggable(); 1402 1446 1403 1447 var titleText; 1404 1448 if(_xmlNode.nodeType == 3 && _xmlNode.nodeValue.search(/\S/) != -1) … … 1427 1471 titleText = _xmlNode.tagName; 1428 1472 } 1429 1473 1430 1474 addMouseEvents(); 1431 1475 1432 1476 _div.append("<div class=\"veTitleElement\">" + titleText + "</div>"); 1433 1477 } … … 1435 1479 initVEE(); 1436 1480 } 1437 1481 1438 1482 //Call the constructor 1439 1483 initVXE();
Note:
See TracChangeset
for help on using the changeset viewer.