[26461] | 1 | function DebugWidget()
|
---|
| 2 | {
|
---|
[26492] | 3 | //************************
|
---|
[26461] | 4 | //Private member variables
|
---|
[26492] | 5 | //************************
|
---|
[27130] | 6 |
|
---|
[27110] | 7 | //The this variable
|
---|
| 8 | var _greenbug = this;
|
---|
[27218] | 9 |
|
---|
| 10 | //Template tracker class
|
---|
| 11 | var TemplateTracker = function()
|
---|
| 12 | {
|
---|
| 13 | var templates = new Array();
|
---|
| 14 | var currentIndex = -1;
|
---|
[27130] | 15 |
|
---|
[27218] | 16 | this.push = function(object)
|
---|
| 17 | {
|
---|
| 18 | if(currentIndex < templates.length - 1 && templates.length > 0)
|
---|
| 19 | {
|
---|
| 20 | templates.splice(currentIndex + 1, templates.length - 1 - currentIndex);
|
---|
| 21 | }
|
---|
| 22 | templates[++currentIndex] = object;
|
---|
| 23 |
|
---|
| 24 | _forwardButton.button("option", "disabled", true);
|
---|
| 25 | if(templates.length > 1)
|
---|
| 26 | {
|
---|
| 27 | _backButton.button("option", "disabled", false);
|
---|
| 28 | }
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | this.next = function()
|
---|
| 32 | {
|
---|
| 33 | if(currentIndex == templates.length - 1)
|
---|
| 34 | {
|
---|
| 35 | return;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | if(currentIndex + 1 == templates.length - 1)
|
---|
| 39 | {
|
---|
| 40 | _forwardButton.button("option", "disabled", true);
|
---|
| 41 | }
|
---|
| 42 | _backButton.button("option", "disabled", false);
|
---|
| 43 |
|
---|
| 44 | return templates[++currentIndex];
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | this.previous = function()
|
---|
| 48 | {
|
---|
| 49 | if(currentIndex == 0)
|
---|
| 50 | {
|
---|
| 51 | return;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | if(currentIndex - 1 == 0)
|
---|
| 55 | {
|
---|
| 56 | _backButton.button("option", "disabled", true);
|
---|
| 57 | }
|
---|
| 58 | _forwardButton.button("option", "disabled", false);
|
---|
| 59 |
|
---|
| 60 | return templates[--currentIndex];
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | this.peekPrevious = function()
|
---|
| 64 | {
|
---|
| 65 | if(currentIndex == 0)
|
---|
| 66 | {
|
---|
| 67 | return;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | return templates[currentIndex - 1];
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | this.peekNext = function()
|
---|
| 74 | {
|
---|
| 75 | if(currentIndex == templates.length - 1)
|
---|
| 76 | {
|
---|
| 77 | return;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | return templates[currentIndex + 1];
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | var _templateTracker = new TemplateTracker();
|
---|
| 85 |
|
---|
[26492] | 86 | //Debugger state-keeping variables
|
---|
[26461] | 87 | var _debugOn = false;
|
---|
| 88 | var _pauseSelector = false;
|
---|
| 89 | var _elements = new Array();
|
---|
| 90 | var _itemSelected = false; //Used to prevent multiple elements from being highlighted
|
---|
[26924] | 91 | var _editModeText = false;
|
---|
[27153] | 92 | var _fromSelection = false;
|
---|
| 93 | var _selectedInfoContainers = new Array();
|
---|
[27130] | 94 |
|
---|
[26492] | 95 | //Page elements
|
---|
[26461] | 96 | var _mainDiv;
|
---|
[27130] | 97 |
|
---|
[26924] | 98 | var _textEditor;
|
---|
| 99 | var _vEditor;
|
---|
[27130] | 100 |
|
---|
[27110] | 101 | var _navArea;
|
---|
| 102 | var _fileSelector;
|
---|
[26924] | 103 | var _templateSelector;
|
---|
[26614] | 104 | var _editor;
|
---|
[26492] | 105 | var _editingDiv;
|
---|
[27218] | 106 | var _xmlStatusBar;
|
---|
| 107 |
|
---|
| 108 | //Buttons
|
---|
| 109 | var _backButton;
|
---|
| 110 | var _forwardButton;
|
---|
| 111 | var _currentSelectionButton;
|
---|
[27153] | 112 | var _enableSelectorButton;
|
---|
[27013] | 113 | var _closeEditorButton;
|
---|
[26492] | 114 | var _saveButton;
|
---|
[26924] | 115 | var _swapEditorButton;
|
---|
[27130] | 116 |
|
---|
[26492] | 117 | //Editor state-keeping variables
|
---|
[27110] | 118 | var _currentFileName;
|
---|
| 119 | var _currentLocation;
|
---|
[26492] | 120 | var _currentNodename;
|
---|
| 121 | var _currentName;
|
---|
| 122 | var _currentMatch;
|
---|
| 123 | var _currentNamespace;
|
---|
[27713] | 124 | var _currentXPath;
|
---|
[26924] | 125 | var _isVisualEditor = true;
|
---|
[27130] | 126 |
|
---|
[27013] | 127 | var _styleFunctions = new Array();
|
---|
[27130] | 128 |
|
---|
| 129 | //Used to reload the page while keeping the state of the editor
|
---|
[27015] | 130 | var partialPageReload = function(callback)
|
---|
[27008] | 131 | {
|
---|
| 132 | $.ajax(document.URL)
|
---|
| 133 | .success(function(response)
|
---|
| 134 | {
|
---|
| 135 | //Get the body text from the response
|
---|
| 136 | var bodyStartIndex = response.indexOf("<body");
|
---|
| 137 | var bodyEndIndex = response.indexOf("</body>");
|
---|
| 138 | var bodyText = response.substring(bodyStartIndex, bodyEndIndex + 7);
|
---|
[27130] | 139 |
|
---|
[27008] | 140 | //Get the current top area and container
|
---|
| 141 | var topLevelTopArea = $("#topArea");
|
---|
| 142 | var topLevelContainer = $("#container");
|
---|
[27130] | 143 |
|
---|
[27008] | 144 | //Create a temporary div and put the html into it
|
---|
| 145 | var tempDiv = $("<div>");
|
---|
| 146 | tempDiv.html(bodyText);
|
---|
[27130] | 147 |
|
---|
[27008] | 148 | //Replace the contents of the old elements with the new elements
|
---|
| 149 | var topArea = tempDiv.find("#topArea");
|
---|
| 150 | var container = tempDiv.find("#container");
|
---|
| 151 | topLevelTopArea.html(topArea.html());
|
---|
| 152 | topLevelContainer.html(container.html());
|
---|
[27130] | 153 |
|
---|
[27008] | 154 | //Update the events for the debug elements that currently don't have events associated with them
|
---|
| 155 | var debugElems = $('debug, [debug="true"]').filter(function(){return (!($.data(this, "events"))) ? true : false});
|
---|
| 156 | addMouseEventsToDebugElements(debugElems);
|
---|
| 157 | })
|
---|
| 158 | .error(function()
|
---|
| 159 | {
|
---|
| 160 | alert("There was an error reloading the page, please reload manually.");
|
---|
| 161 | });
|
---|
[27130] | 162 |
|
---|
[27015] | 163 | if(callback)
|
---|
| 164 | {
|
---|
| 165 | callback();
|
---|
| 166 | }
|
---|
[27008] | 167 | }
|
---|
[27130] | 168 |
|
---|
| 169 | //Some functions need to be called after an element is added to the page. So we store them and call them later.
|
---|
[27013] | 170 | var callStyleFunctions = function()
|
---|
| 171 | {
|
---|
| 172 | for(var i = 0; i < _styleFunctions.length; i++)
|
---|
| 173 | {
|
---|
| 174 | var sFunction = _styleFunctions[i];
|
---|
| 175 | sFunction();
|
---|
| 176 | }
|
---|
| 177 | }
|
---|
[27218] | 178 |
|
---|
| 179 | var changeToSelectedElement = function(templateIndex, templateList)
|
---|
| 180 | {
|
---|
| 181 | _templateSelector.children("select").empty();
|
---|
| 182 |
|
---|
| 183 | for(var i = 0; i < templateList.length; i++)
|
---|
| 184 | {
|
---|
| 185 | _templateSelector.children("select").append($(templateList[i]).clone(true));
|
---|
| 186 | }
|
---|
[27130] | 187 |
|
---|
[27218] | 188 | if(templateIndex === undefined)
|
---|
| 189 | {
|
---|
| 190 | _templateSelector.find("option").first().trigger("change", [true]);
|
---|
| 191 | }
|
---|
| 192 | else
|
---|
| 193 | {
|
---|
| 194 | _templateSelector.find("option").filter(function(){return $(this).data("index") == templateIndex}).first().trigger("change", [true]);
|
---|
| 195 | }
|
---|
| 196 | return;
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | var createNavButtons = function(buttonDiv)
|
---|
| 200 | {
|
---|
| 201 | var navButtonHolder = $("<div>").css("float", "left");
|
---|
| 202 |
|
---|
| 203 | var backForwardFunction = function(e)
|
---|
| 204 | {
|
---|
| 205 | var template;
|
---|
| 206 | if($(e.target).attr("id") == "veBack")
|
---|
| 207 | {
|
---|
| 208 | template = _templateTracker.previous();
|
---|
| 209 | }
|
---|
| 210 | else
|
---|
| 211 | {
|
---|
| 212 | template = _templateTracker.next();
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | if(!template)
|
---|
| 216 | {
|
---|
| 217 | return;
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | _fileSelector.find("option").filter(function(){return $(this).data("index") == template.fileIndex}).prop("selected", true);
|
---|
| 221 |
|
---|
| 222 | changeToSelectedElement(template.templateIndex, template.list);
|
---|
| 223 | }
|
---|
| 224 |
|
---|
| 225 | _backButton = $("<button>Back button</button>").attr("id", "veBack");
|
---|
| 226 | _backButton.click(backForwardFunction);
|
---|
| 227 | _styleFunctions.push(function(){_backButton.button({icons:{primary:"ui-icon-triangle-1-w"}, text:false, disabled:true})});
|
---|
| 228 |
|
---|
| 229 | _forwardButton = $("<button>Forward button</button>").attr("id", "veForwards");
|
---|
| 230 | _forwardButton.click(backForwardFunction);
|
---|
| 231 | _styleFunctions.push(function(){_forwardButton.button({icons:{primary:"ui-icon-triangle-1-e"}, text:false, disabled:true})});
|
---|
| 232 |
|
---|
| 233 | //Changes the template list to what is currently selected
|
---|
| 234 | _currentSelectionButton = $("<button>Current selection button</button>");
|
---|
| 235 | _currentSelectionButton.click(function()
|
---|
| 236 | {
|
---|
| 237 | _fileSelector.find("option").eq(0).prop("selected", true);
|
---|
| 238 | changeToSelectedElement(undefined, _selectedInfoContainers);
|
---|
| 239 |
|
---|
| 240 | var selectedCopy = new Array();
|
---|
| 241 | for(var i = 0; i < _selectedInfoContainers.length; i++)
|
---|
| 242 | {
|
---|
| 243 | selectedCopy[i] = _selectedInfoContainers[i];
|
---|
| 244 | }
|
---|
| 245 |
|
---|
| 246 | _templateTracker.push({fileIndex:-1, templateIndex:0, list:selectedCopy});
|
---|
| 247 | });
|
---|
| 248 | _styleFunctions.push(function(){_currentSelectionButton.button({icons:{primary:"ui-icon-pencil"}, text:false, disabled:true})});
|
---|
| 249 |
|
---|
| 250 | navButtonHolder.append(_backButton);
|
---|
| 251 | navButtonHolder.append(_forwardButton);
|
---|
| 252 | navButtonHolder.append(_currentSelectionButton);
|
---|
| 253 | buttonDiv.append(navButtonHolder);
|
---|
| 254 | }
|
---|
| 255 |
|
---|
[27130] | 256 | //Create the area where the buttons are stored
|
---|
[27218] | 257 | var createControlButtons = function(buttonDiv)
|
---|
[26461] | 258 | {
|
---|
[27130] | 259 | //Used to enable the selector to get the templates of a particular area of the page
|
---|
[27153] | 260 | _enableSelectorButton = $("<button>Select an element</button>");
|
---|
| 261 | _enableSelectorButton.click(function()
|
---|
[26461] | 262 | {
|
---|
[27153] | 263 | _enableSelectorButton.button("option", "label", "Select new element");
|
---|
| 264 | $("a").click(function(e)
|
---|
[26461] | 265 | {
|
---|
[27153] | 266 | e.preventDefault();
|
---|
| 267 | });
|
---|
| 268 | _debugOn = true;
|
---|
| 269 | _pauseSelector = false;
|
---|
| 270 | _enableSelectorButton.button("option", "disabled", true);
|
---|
[26461] | 271 | });
|
---|
[27218] | 272 | _styleFunctions.push(function(){_enableSelectorButton.button({icons:{primary:"ui-icon-pencil"}})});
|
---|
[26492] | 273 |
|
---|
[27130] | 274 | //Used to minimise/restore the editor
|
---|
[27013] | 275 | _closeEditorButton = $("<button>Close editor</button>");
|
---|
| 276 | _closeEditorButton.click(function()
|
---|
[26492] | 277 | {
|
---|
[27013] | 278 | if(_closeEditorButton.button("option", "label") == "Close editor")
|
---|
[26492] | 279 | {
|
---|
[27013] | 280 | _closeEditorButton.button("option", "label", "Open editor");
|
---|
[26492] | 281 | _editingDiv.hide();
|
---|
| 282 | }
|
---|
| 283 | else
|
---|
| 284 | {
|
---|
[27013] | 285 | _closeEditorButton.button("option", "label", "Close editor");
|
---|
[26492] | 286 | _editingDiv.show();
|
---|
| 287 | }
|
---|
| 288 | });
|
---|
[27057] | 289 | _closeEditorButton.css("float", "right");
|
---|
| 290 | _styleFunctions.push(function(){_closeEditorButton.button({icons:{secondary:"ui-icon-newwin"}, disabled:true})});
|
---|
[27130] | 291 |
|
---|
| 292 | //Used to save any changes that have been made to this template
|
---|
[27013] | 293 | _saveButton = $("<button>Save changes</button>");
|
---|
| 294 | _saveButton.click(function()
|
---|
[26492] | 295 | {
|
---|
[26614] | 296 | if(_editor)
|
---|
[26492] | 297 | {
|
---|
[26924] | 298 | var xmlString;
|
---|
| 299 | if(_isVisualEditor)
|
---|
| 300 | {
|
---|
[27015] | 301 | _vEditor.savePendingEdits();
|
---|
[26924] | 302 | xmlString = new XMLSerializer().serializeToString(_vEditor.getXML());
|
---|
| 303 | }
|
---|
| 304 | else
|
---|
| 305 | {
|
---|
| 306 | xmlString = _editor.getValue();
|
---|
| 307 | }
|
---|
| 308 | xmlString = xmlString.replace(/&/g, "&");
|
---|
[27130] | 309 |
|
---|
[26492] | 310 | try
|
---|
| 311 | {
|
---|
[27153] | 312 | var xml = $.parseXML('<testContainer xmlns:xslt="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="http://xml.apache.org/xslt/java" xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil" xmlns:gslib="http://www.greenstone.org/skinning" xmlns:gsf="http://www.greenstone.org/greenstone3/schema/ConfigFormat">' + xmlString + "</testContainer>");
|
---|
[26492] | 313 | }
|
---|
| 314 | catch(error)
|
---|
| 315 | {
|
---|
| 316 | alert("Could not save as there is a problem with the XML.");
|
---|
| 317 | return;
|
---|
| 318 | }
|
---|
[27130] | 319 |
|
---|
[26492] | 320 | var url = gs.xsltParams.library_name;
|
---|
[27110] | 321 | 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};
|
---|
[26562] | 322 |
|
---|
[26492] | 323 | if(_currentName && _currentName.length > 0){parameters["s1.name"] = _currentName;}
|
---|
[26554] | 324 | if(_currentMatch && _currentMatch.length > 0){parameters["s1.match"] = _currentMatch;}
|
---|
[27713] | 325 | if(_currentXPath && _currentXPath.length > 0){parameters["s1.xpath"] = _currentXPath}
|
---|
[26562] | 326 |
|
---|
[27013] | 327 | _saveButton.button("option", "disabled", true);
|
---|
[27015] | 328 | $.blockUI({message:'<div class="ui-state-active">Saving, please wait...</div>'});
|
---|
[26562] | 329 |
|
---|
[26492] | 330 | $.post(url, parameters)
|
---|
| 331 | .success(function()
|
---|
| 332 | {
|
---|
[26554] | 333 | $.ajax(gs.xsltParams.library_name + "?a=s&sa=c")
|
---|
| 334 | .success(function()
|
---|
| 335 | {
|
---|
[27015] | 336 | partialPageReload(function(){$.unblockUI();});
|
---|
[26554] | 337 | })
|
---|
| 338 | .error(function()
|
---|
| 339 | {
|
---|
[27015] | 340 | $.unblockUI();
|
---|
[26554] | 341 | alert("Error reloading collection.");
|
---|
| 342 | })
|
---|
| 343 | .complete(function()
|
---|
| 344 | {
|
---|
[27013] | 345 | _saveButton.button("option", "disabled", false);
|
---|
[26554] | 346 | });
|
---|
[26492] | 347 | })
|
---|
| 348 | .error(function()
|
---|
| 349 | {
|
---|
| 350 | alert("There was an error sending the request to the server, please try again.");
|
---|
| 351 | });
|
---|
| 352 | }
|
---|
| 353 | });
|
---|
[27013] | 354 | _styleFunctions.push(function(){_saveButton.button({icons:{primary:"ui-icon-disk"}, disabled:true})});
|
---|
[27130] | 355 |
|
---|
| 356 | //Used to switch between the XML and Visual editors
|
---|
[27055] | 357 | _swapEditorButton = $("<button>Switch to XML editor</button>");
|
---|
[27008] | 358 | _swapEditorButton.button().click(function()
|
---|
[26492] | 359 | {
|
---|
[26924] | 360 | if(_vEditor && _textEditor)
|
---|
[26492] | 361 | {
|
---|
[26924] | 362 | if(_isVisualEditor)
|
---|
| 363 | {
|
---|
[27015] | 364 | _vEditor.savePendingEdits();
|
---|
[26924] | 365 | _vEditor.getMainDiv().hide();
|
---|
| 366 | var containerNode = _vEditor.getXML().firstChild;
|
---|
| 367 | var templateNode = containerNode.firstChild;
|
---|
| 368 | while(templateNode)
|
---|
| 369 | {
|
---|
| 370 | if(templateNode.nodeType == 1)
|
---|
| 371 | {
|
---|
| 372 | break;
|
---|
| 373 | }
|
---|
| 374 | templateNode = templateNode.nextSibling;
|
---|
| 375 | }
|
---|
| 376 | var xmlText = new XMLSerializer().serializeToString(templateNode);
|
---|
| 377 | _editor.setValue(xmlText);
|
---|
| 378 | _editor.clearSelection();
|
---|
[27055] | 379 | var UndoManager = require("ace/undomanager").UndoManager;
|
---|
| 380 | _editor.getSession().setUndoManager(new UndoManager());
|
---|
[26924] | 381 | _textEditor.show();
|
---|
[27055] | 382 | _swapEditorButton.button("option", "label", "Switch to visual editor");
|
---|
[26924] | 383 | _isVisualEditor = false;
|
---|
[27055] | 384 | _xmlStatusBar.show();
|
---|
[26924] | 385 | }
|
---|
| 386 | else
|
---|
| 387 | {
|
---|
| 388 | _textEditor.hide();
|
---|
| 389 | var xmlText = _editor.getValue();
|
---|
| 390 | _vEditor.getMainDiv().remove();
|
---|
| 391 | _vEditor = new visualXMLEditor(xmlText);
|
---|
| 392 | _editingDiv.append(_vEditor.getMainDiv());
|
---|
| 393 | _vEditor.selectRootElement();
|
---|
| 394 | _vEditor.getMainDiv().show();
|
---|
[27055] | 395 | _swapEditorButton.button("option", "label", "Switch to XML editor");
|
---|
[26924] | 396 | _isVisualEditor = true;
|
---|
[27055] | 397 | _xmlStatusBar.hide();
|
---|
[26924] | 398 | }
|
---|
[26492] | 399 | }
|
---|
| 400 | });
|
---|
[27013] | 401 | _styleFunctions.push(function(){_swapEditorButton.button({icons:{primary:"ui-icon-refresh"}})});
|
---|
[27130] | 402 |
|
---|
[27013] | 403 | undoButton = $("<button>Undo</button>");
|
---|
| 404 | undoButton.click(function()
|
---|
[26966] | 405 | {
|
---|
| 406 | if(_isVisualEditor)
|
---|
| 407 | {
|
---|
| 408 | _vEditor.undo();
|
---|
| 409 | }
|
---|
| 410 | else
|
---|
| 411 | {
|
---|
| 412 | _editor.undo();
|
---|
| 413 | }
|
---|
| 414 | });
|
---|
[27013] | 415 | _styleFunctions.push(function(){undoButton.button({icons:{primary:"ui-icon-arrowreturnthick-1-w"}})});
|
---|
[27130] | 416 |
|
---|
[27153] | 417 | buttonDiv.append(_enableSelectorButton);
|
---|
[27110] | 418 | buttonDiv.append(_closeEditorButton);
|
---|
| 419 | buttonDiv.append(_saveButton);
|
---|
| 420 | buttonDiv.append(_swapEditorButton);
|
---|
| 421 | buttonDiv.append(undoButton);
|
---|
| 422 | }
|
---|
[27130] | 423 |
|
---|
| 424 | //Used to monitor the state of the XML in the XML editor and will notify the user if there is an error
|
---|
[27110] | 425 | var createXMLStatusBar = function(buttonDiv)
|
---|
| 426 | {
|
---|
[27013] | 427 | _xmlStatusBar = $("<span>");
|
---|
| 428 | _xmlStatusBar.css("padding", "5px");
|
---|
| 429 | _xmlStatusBar.addClass("ui-corner-all");
|
---|
[27055] | 430 | _styleFunctions.push(function(){_xmlStatusBar.hide();});
|
---|
[27130] | 431 |
|
---|
[27013] | 432 | //Check the XML for errors every 2 seconds
|
---|
| 433 | setInterval(function()
|
---|
| 434 | {
|
---|
| 435 | if(_editor)
|
---|
| 436 | {
|
---|
| 437 | var xmlString = _editor.getValue();
|
---|
| 438 | try
|
---|
| 439 | {
|
---|
| 440 | var xml = $.parseXML('<testContainer xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="http://xml.apache.org/xslt/java" xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil" xmlns:gslib="http://www.greenstone.org/skinning" xmlns:gsf="http://www.greenstone.org/greenstone3/schema/ConfigFormat">' + xmlString + "</testContainer>");
|
---|
| 441 | }
|
---|
| 442 | catch(error)
|
---|
| 443 | {
|
---|
| 444 | console.log(error);
|
---|
| 445 | _xmlStatusBar.text("XML ERROR! (Mouse over for details)");
|
---|
| 446 | _xmlStatusBar.addClass("ui-state-error");
|
---|
| 447 | _xmlStatusBar.removeClass("ui-state-active");
|
---|
| 448 | _xmlStatusBar.attr("title", error);
|
---|
| 449 | _saveButton.button("option", "disabled", true);
|
---|
| 450 | _swapEditorButton.button("option", "disabled", true);
|
---|
| 451 | return;
|
---|
| 452 | }
|
---|
[27130] | 453 |
|
---|
[27013] | 454 | _xmlStatusBar.text("XML OK!");
|
---|
| 455 | _xmlStatusBar.addClass("ui-state-active");
|
---|
| 456 | _xmlStatusBar.removeClass("ui-state-error");
|
---|
| 457 | _xmlStatusBar.removeAttr("title");
|
---|
| 458 | if(_saveButton.button("option", "label") == "Save changes")
|
---|
| 459 | {
|
---|
| 460 | _saveButton.button("option", "disabled", false);
|
---|
| 461 | }
|
---|
[27055] | 462 | if(_swapEditorButton.button("option", "label") == "Switch to visual editor")
|
---|
[27013] | 463 | {
|
---|
| 464 | _swapEditorButton.button("option", "disabled", false);
|
---|
| 465 | }
|
---|
| 466 | }
|
---|
| 467 | }, 2000);
|
---|
[27110] | 468 | buttonDiv.append(_xmlStatusBar);
|
---|
| 469 | }
|
---|
[27130] | 470 |
|
---|
| 471 | //Create the elements that allow
|
---|
[27129] | 472 | var createFileAndTemplateSelectors = function(buttonDiv)
|
---|
| 473 | {
|
---|
| 474 | _templateSelector = $("<div>", {"id":"veTemplateSelector", "class":"ui-state-default ui-corner-all"});
|
---|
| 475 | _templateSelector.append($("<span>Templates: <span>"));
|
---|
| 476 | var templateSelectBox = $("<select>").append("<option>-- No templates --</option>");
|
---|
[27218] | 477 | templateSelectBox.change(function(e, triggered)
|
---|
[27129] | 478 | {
|
---|
| 479 | var selected = templateSelectBox.find(":selected");
|
---|
| 480 | var changeFunction = selected.data("changeFunction");
|
---|
| 481 | if(changeFunction)
|
---|
| 482 | {
|
---|
| 483 | changeFunction();
|
---|
| 484 | }
|
---|
[27218] | 485 |
|
---|
| 486 | if(!triggered)
|
---|
| 487 | {
|
---|
| 488 | _templateTracker.push({fileIndex:_fileSelector.find(":selected").data("index"), templateIndex:selected.data("index"), list:templateSelectBox.children("option").clone(true)});
|
---|
| 489 | }
|
---|
[27129] | 490 | });
|
---|
| 491 | _templateSelector.append(templateSelectBox);
|
---|
[27130] | 492 | _fileSelector = $("<div>", {"id":"veFileSelector"});
|
---|
[27129] | 493 | buttonDiv.append(_fileSelector);
|
---|
| 494 | buttonDiv.append(_templateSelector);
|
---|
[27110] | 495 |
|
---|
| 496 | //Populate the file selector
|
---|
| 497 | 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;
|
---|
| 498 | $.ajax(url)
|
---|
| 499 | .success(function(response)
|
---|
| 500 | {
|
---|
| 501 | var listStartIndex = response.indexOf("<fileListJSON>") + "<fileListJSON>".length;
|
---|
| 502 | var listEndIndex = response.indexOf("</fileListJSON>");
|
---|
[27130] | 503 |
|
---|
[27110] | 504 | var listString = response.substring(listStartIndex, listEndIndex).replace(/"/g, "\"").replace(/\\/g, "/");
|
---|
| 505 | var list = eval(listString);
|
---|
[27130] | 506 |
|
---|
[27218] | 507 | var fileSelectBox = $("<select>");
|
---|
| 508 | fileSelectBox.append($("<option>-- Select a file --</option>").data("index", -1));
|
---|
[27130] | 509 | _fileSelector.addClass("ui-state-default");
|
---|
| 510 | _fileSelector.addClass("ui-corner-all");
|
---|
[27110] | 511 | _fileSelector.append("<span>Files: </span>");
|
---|
[27218] | 512 | _fileSelector.append(fileSelectBox);
|
---|
[27153] | 513 |
|
---|
[27110] | 514 | for(var i = 0; i < list.length; i++)
|
---|
| 515 | {
|
---|
| 516 | var item = list[i];
|
---|
[27218] | 517 | var option = $("<option>" + item.path + " (" + item.location + ")</option>").data("index", i);
|
---|
[27110] | 518 | option.data("fileItem", item);
|
---|
[27218] | 519 | fileSelectBox.append(option);
|
---|
[27110] | 520 | }
|
---|
| 521 |
|
---|
[27218] | 522 | fileSelectBox.change(function()
|
---|
[27110] | 523 | {
|
---|
[27218] | 524 | var selectedItem = fileSelectBox.find(":selected");
|
---|
[27153] | 525 |
|
---|
[27129] | 526 | if(!selectedItem.data("fileItem"))
|
---|
| 527 | {
|
---|
| 528 | return;
|
---|
| 529 | }
|
---|
[27130] | 530 |
|
---|
[27256] | 531 | _greenbug.populateTemplateSelectorFromFile(selectedItem.data("fileItem").path, selectedItem.data("fileItem").location, function(){_templateSelector.children("select").trigger("change")});
|
---|
[27110] | 532 | });
|
---|
| 533 | })
|
---|
| 534 | .error(function()
|
---|
| 535 | {
|
---|
| 536 | console.log("Error retrieving XSLT files");
|
---|
| 537 | });
|
---|
[27130] | 538 | }
|
---|
| 539 |
|
---|
| 540 | //The function that creates all the necessary elements for Greenbug
|
---|
| 541 | var createDebugDiv = function()
|
---|
| 542 | {
|
---|
| 543 | _mainDiv = $("<div>", {"id":"debugDiv"});
|
---|
| 544 | _mainDiv.css(
|
---|
| 545 | {
|
---|
| 546 | "position":"fixed",
|
---|
| 547 | "font-size":"0.8em",
|
---|
| 548 | "bottom":"0px",
|
---|
| 549 | "width":"100%",
|
---|
| 550 | "background":"white",
|
---|
| 551 | "border":"1px black solid",
|
---|
| 552 | "padding":"5px",
|
---|
| 553 | "z-index":100
|
---|
| 554 | });
|
---|
| 555 |
|
---|
| 556 | _editingDiv = $("<div>");
|
---|
| 557 | var toolBarDiv = $("<div>");
|
---|
| 558 | toolBarDiv.css({"height":"40px"});
|
---|
| 559 | toolBarDiv.append("<div>", {style:"clear:both;"});
|
---|
| 560 |
|
---|
| 561 | var buttonDiv = $("<div>");
|
---|
| 562 | toolBarDiv.append(buttonDiv);
|
---|
[27218] | 563 | createNavButtons(buttonDiv);
|
---|
| 564 | createControlButtons(buttonDiv);
|
---|
[27130] | 565 | createFileAndTemplateSelectors(buttonDiv);
|
---|
| 566 | createXMLStatusBar(buttonDiv);
|
---|
| 567 |
|
---|
[27013] | 568 | _styleFunctions.push(function(){$(".ui-button").css({"margin-right":"0.5em"});});
|
---|
[27130] | 569 |
|
---|
[26924] | 570 | _mainDiv.append(toolBarDiv);
|
---|
[26492] | 571 | _mainDiv.append(_editingDiv);
|
---|
[27110] | 572 | _mainDiv.append(_navArea);
|
---|
[26461] | 573 | }
|
---|
[27130] | 574 |
|
---|
| 575 | //Clear all selected elements on the page
|
---|
[26461] | 576 | var clearAll = function()
|
---|
| 577 | {
|
---|
| 578 | _itemSelected = false;
|
---|
| 579 | $(_elements).each(function()
|
---|
| 580 | {
|
---|
| 581 | $(this).remove();
|
---|
| 582 | });
|
---|
| 583 | }
|
---|
[27130] | 584 |
|
---|
| 585 | //Put a border around the given element
|
---|
[26461] | 586 | var highlightElement = function(e)
|
---|
| 587 | {
|
---|
| 588 | var topBorderDiv = $("<div>");
|
---|
| 589 | var bottomBorderDiv = $("<div>");
|
---|
| 590 | var leftBorderDiv = $("<div>");
|
---|
| 591 | var rightBorderDiv = $("<div>");
|
---|
[26492] | 592 |
|
---|
[26461] | 593 | topBorderDiv.css({"position":"absolute", "top":e.offset().top + "px", "left":e.offset().left + "px", "height":"0px", "width":e.width() + "px", "border":"1px solid red"});
|
---|
| 594 | bottomBorderDiv.css({"position":"absolute", "top":(e.offset().top + e.height()) + "px", "left":e.offset().left + "px", "height":"0px", "width":e.width() + "px", "border":"1px solid red"});
|
---|
| 595 | leftBorderDiv.css({"position":"absolute", "top":e.offset().top + "px", "left":e.offset().left + "px", "height":e.height() + "px", "width":"0px", "border":"1px solid red"});
|
---|
| 596 | rightBorderDiv.css({"position":"absolute", "top":e.offset().top + "px", "left":(e.offset().left + e.width()) + "px", "height":e.height() + "px", "width":"0px", "border":"1px solid red"});
|
---|
[26492] | 597 |
|
---|
[26461] | 598 | $("body").append(topBorderDiv, bottomBorderDiv, leftBorderDiv, rightBorderDiv);
|
---|
[26492] | 599 |
|
---|
[26461] | 600 | _elements.push(topBorderDiv);
|
---|
| 601 | _elements.push(bottomBorderDiv);
|
---|
| 602 | _elements.push(leftBorderDiv);
|
---|
| 603 | _elements.push(rightBorderDiv);
|
---|
| 604 | }
|
---|
[27256] | 605 |
|
---|
| 606 | this.populateTemplateSelectorFromFile = function(filename, location, callback)
|
---|
| 607 | {
|
---|
| 608 | var getURL = gs.xsltParams.library_name + "?a=g&rt=r&s=GetTemplateListFromFile&s1.fileName=" + filename + "&s1.locationName=" + location + "&s1.interfaceName=" + gs.xsltParams.interface_name + "&s1.siteName=" + gs.xsltParams.site_name + "&s1.collectionName=" + gs.cgiParams.c;
|
---|
| 609 | $.ajax(getURL)
|
---|
| 610 | .success(function(templateResponse)
|
---|
| 611 | {
|
---|
| 612 | var templateListStart = templateResponse.indexOf("<templateList>") + "<templateList>".length;
|
---|
| 613 | var templateListEnd = templateResponse.indexOf("</templateList>");
|
---|
[27713] | 614 |
|
---|
| 615 | if(templateListStart == "<templateList>".length - 1)
|
---|
| 616 | {
|
---|
| 617 | return;
|
---|
| 618 | }
|
---|
| 619 |
|
---|
[27256] | 620 | var templateListString = templateResponse.substring(templateListStart, templateListEnd).replace(/"/g, "\"");
|
---|
| 621 | var templateList = eval(templateListString);
|
---|
[27130] | 622 |
|
---|
[27256] | 623 | _templateSelector.children("select").empty();
|
---|
| 624 | if(templateList.length == 0)
|
---|
| 625 | {
|
---|
| 626 | _templateSelector.children("select").append($("<option>-- No templates --</option>").data("index", -1));
|
---|
| 627 | }
|
---|
| 628 |
|
---|
| 629 | for(var i = 0; i < templateList.length; i++)
|
---|
| 630 | {
|
---|
| 631 | var namespace = templateList[i].namespace;
|
---|
| 632 | var nodename = "template";
|
---|
| 633 | var name = templateList[i].name;
|
---|
| 634 | var match = templateList[i].match;
|
---|
[27713] | 635 | var xpath = templateList[i].xpath;
|
---|
[27256] | 636 |
|
---|
| 637 | if(name)
|
---|
| 638 | {
|
---|
| 639 | name = templateList[i].name.replace(/'/g, "'").replace(/"/g, "\"").replace(/&/g, "&");
|
---|
| 640 | }
|
---|
| 641 | if(match)
|
---|
| 642 | {
|
---|
| 643 | match = templateList[i].match.replace(/'/g, "'").replace(/"/g, "\"").replace(/&/g, "&");
|
---|
| 644 | }
|
---|
| 645 |
|
---|
| 646 | var infoContainer = $("<option>");
|
---|
| 647 |
|
---|
| 648 | _elements.push(infoContainer);
|
---|
| 649 |
|
---|
[27713] | 650 | addChangeEventToInfoContainer(infoContainer, filename, location, nodename, namespace, name, match, xpath);
|
---|
[27256] | 651 |
|
---|
| 652 | if(name && name.length > 0)
|
---|
| 653 | {
|
---|
[27713] | 654 | infoContainer.text(name + ((xpath) ? (" (" + xpath + ")") : ""));
|
---|
[27256] | 655 | }
|
---|
| 656 | if(match && match.length > 0)
|
---|
| 657 | {
|
---|
[27713] | 658 | infoContainer.text(match + ((xpath) ? (" (" + xpath + ")") : ""));
|
---|
[27256] | 659 | }
|
---|
| 660 |
|
---|
| 661 | infoContainer.data("index", i);
|
---|
| 662 | _templateSelector.children("select").append(infoContainer);
|
---|
| 663 | }
|
---|
| 664 |
|
---|
| 665 | if(callback)
|
---|
| 666 | {
|
---|
| 667 | callback();
|
---|
| 668 | }
|
---|
| 669 | });
|
---|
| 670 | }
|
---|
| 671 |
|
---|
[27130] | 672 | //Change the current template in the XML and Visual editor
|
---|
[27713] | 673 | this.changeCurrentTemplate = function(location, filename, nodename, namespace, name, match, xpath)
|
---|
[26492] | 674 | {
|
---|
[27218] | 675 | _currentFileName = filename;
|
---|
| 676 | _currentLocation = location;
|
---|
| 677 | _currentNodename = nodename;
|
---|
| 678 | _currentNamespace = namespace;
|
---|
| 679 | _currentName = name;
|
---|
| 680 | _currentMatch = match;
|
---|
[27713] | 681 | _currentXPath = xpath;
|
---|
| 682 |
|
---|
[27110] | 683 | var responseName = "requestedNameTemplate";
|
---|
[27130] | 684 |
|
---|
[27713] | 685 | var url = gs.xsltParams.library_name;
|
---|
| 686 | var params = {"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};
|
---|
[27110] | 687 |
|
---|
[27713] | 688 | if(match && match.length > 0){params["s1.match"] = match; responseName = "requestedMatchTemplate";}
|
---|
[27809] | 689 | if(xpath && xpath.length > 0){params["s1.xpath"] = xpath}
|
---|
[27713] | 690 | if(name && name.length > 0){params["s1.name"] = name;}
|
---|
| 691 |
|
---|
| 692 | $.post(url, params)
|
---|
[27110] | 693 | .success(function(response)
|
---|
| 694 | {
|
---|
| 695 | var template;
|
---|
| 696 | if(response.search(responseName) != -1)
|
---|
| 697 | {
|
---|
| 698 | var startIndex = response.indexOf("<" + responseName + ">") + responseName.length + 2;
|
---|
| 699 | var endIndex = response.indexOf("</" + responseName + ">");
|
---|
| 700 | template = response.substring(startIndex, endIndex);
|
---|
| 701 | }
|
---|
| 702 | else
|
---|
| 703 | {
|
---|
| 704 | return;
|
---|
| 705 | }
|
---|
[27130] | 706 |
|
---|
[27110] | 707 | _textEditor = $("<div>", {"id":"textEditor"});
|
---|
| 708 | _textEditor.css({"width":"100%", "height":"300px"});
|
---|
| 709 | _textEditor.val(template);
|
---|
[27130] | 710 |
|
---|
[27110] | 711 | if(_isVisualEditor)
|
---|
| 712 | {
|
---|
| 713 | _textEditor.hide();
|
---|
| 714 | }
|
---|
[27130] | 715 |
|
---|
[27110] | 716 | _editingDiv.empty();
|
---|
[27218] | 717 | _editingDiv.append($("<p>Location: " + location + " <br/>Filename: " + filename + "</p>"));
|
---|
[27110] | 718 | _editingDiv.append(_textEditor);
|
---|
[27130] | 719 |
|
---|
[27110] | 720 | _vEditor = new visualXMLEditor(template);
|
---|
| 721 | _editingDiv.append(_vEditor.getMainDiv());
|
---|
| 722 | _vEditor.setGreenbug(_greenbug);
|
---|
| 723 | _vEditor.selectRootElement();
|
---|
[27166] | 724 | $("#veToolboxDiv").height($("#veEditorContainer").height());
|
---|
[27130] | 725 |
|
---|
[27163] | 726 | _vEditor.setFileLocation(location);
|
---|
[27218] | 727 | _vEditor.setFileName(filename);
|
---|
[27163] | 728 |
|
---|
[27110] | 729 | if(!_isVisualEditor)
|
---|
| 730 | {
|
---|
| 731 | _vEditor.getMainDiv().hide();
|
---|
| 732 | }
|
---|
[27130] | 733 |
|
---|
[27110] | 734 | _editor = ace.edit("textEditor");
|
---|
| 735 | _editor.getSession().setMode("ace/mode/xml");
|
---|
| 736 | _editor.getSession().setUseSoftTabs(false);
|
---|
| 737 | _editor.setValue(template);
|
---|
| 738 | _editor.clearSelection();
|
---|
| 739 | var UndoManager = require("ace/undomanager").UndoManager;
|
---|
| 740 | _editor.getSession().setUndoManager(new UndoManager());
|
---|
[27130] | 741 |
|
---|
[27110] | 742 | _textEditor.css({"min-height":"200px", "border-top":"5px solid #444"});
|
---|
| 743 | _textEditor.resizable({handles: 'n', resize:function()
|
---|
| 744 | {
|
---|
| 745 | _textEditor.css({top:"0px"});
|
---|
| 746 | _editor.resize();
|
---|
| 747 | }});
|
---|
| 748 |
|
---|
| 749 | _closeEditorButton.button("option", "disabled", false);
|
---|
| 750 | if(_closeEditorButton.button("option", "label") == "Open editor")
|
---|
| 751 | {
|
---|
| 752 | _closeEditorButton.button("option", "label", "Close editor");
|
---|
| 753 | _editingDiv.show();
|
---|
| 754 | }
|
---|
| 755 | })
|
---|
| 756 | .error(function()
|
---|
| 757 | {
|
---|
[27130] | 758 | console.log("Error getting the XML template from the file");
|
---|
[27110] | 759 | });
|
---|
| 760 | }
|
---|
[27130] | 761 |
|
---|
| 762 | //Store the function that is called when this template is selected from the list
|
---|
[27713] | 763 | var addChangeEventToInfoContainer = function(infoContainer, filename, location, nodename, namespace, name, match, xpath)
|
---|
[27110] | 764 | {
|
---|
[27129] | 765 | infoContainer.data("changeFunction", function()
|
---|
[26492] | 766 | {
|
---|
[27713] | 767 | _greenbug.changeCurrentTemplate(location, filename, nodename, namespace, name, match, xpath);
|
---|
[26492] | 768 | });
|
---|
| 769 | }
|
---|
[27163] | 770 |
|
---|
[27256] | 771 | this.getTemplateTracker = function()
|
---|
| 772 | {
|
---|
| 773 | return _templateTracker;
|
---|
| 774 | }
|
---|
| 775 |
|
---|
[27163] | 776 | //Turns a filename into it's location (i.e. interface/site/collection) and name
|
---|
| 777 | this.fileNameToLocationAndName = function(filepath)
|
---|
| 778 | {
|
---|
| 779 | var location;
|
---|
[27218] | 780 | var filename;
|
---|
[27163] | 781 | //Use the filepath to work out where this file is from
|
---|
| 782 | if(filepath.search(/[\/\\]interfaces[\/\\]/) != -1)
|
---|
| 783 | {
|
---|
| 784 | location = "interface";
|
---|
[27218] | 785 | filename = filepath.replace(/.*[\/\\]transform[\/\\]/, "");
|
---|
[27163] | 786 | }
|
---|
| 787 | else if(filepath.search(/[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]etc[\/\\]/) != -1)
|
---|
| 788 | {
|
---|
| 789 | location = "collectionConfig";
|
---|
[27218] | 790 | filename = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]etc[\/\\]/, "");
|
---|
[27163] | 791 | }
|
---|
| 792 | else if(filepath.search(/[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]transform[\/\\]/) != -1)
|
---|
| 793 | {
|
---|
| 794 | location = "collection";
|
---|
[27218] | 795 | filename = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]transform[\/\\]/, "");
|
---|
[27163] | 796 | }
|
---|
| 797 | else if(filepath.search(/[\/\\]sites[\/\\].*[\/\\]transform[\/\\]/) != -1)
|
---|
| 798 | {
|
---|
| 799 | location = "site";
|
---|
[27218] | 800 | filename = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]transform[\/\\]/, "");
|
---|
[27163] | 801 | }
|
---|
| 802 |
|
---|
[27256] | 803 | filename = filename.replace(/\\/g, "/");
|
---|
| 804 |
|
---|
[27218] | 805 | return {location:location, filename:filename};
|
---|
[27163] | 806 | }
|
---|
[26924] | 807 |
|
---|
[27130] | 808 | //Add the mouse events to the <debug> elemetns that are called when the selector is anabled
|
---|
[26461] | 809 | var addMouseEventsToDebugElements = function(debugElems)
|
---|
| 810 | {
|
---|
[27153] | 811 | debugElems.click(function(e)
|
---|
[26461] | 812 | {
|
---|
| 813 | if(_debugOn)
|
---|
| 814 | {
|
---|
[27218] | 815 | e.stopPropagation();
|
---|
[27153] | 816 | $("a").off("click");
|
---|
| 817 | _debugOn = false;
|
---|
[26461] | 818 | _pauseSelector = true;
|
---|
[27153] | 819 | _enableSelectorButton.button("option", "disabled", false);
|
---|
[27218] | 820 | _templateSelector.children("select").trigger("change", [true]);
|
---|
| 821 | _fileSelector.children("select").val("none");
|
---|
| 822 |
|
---|
| 823 | var selectedCopy = new Array();
|
---|
| 824 | for(var i = 0; i < _selectedInfoContainers.length; i++)
|
---|
| 825 | {
|
---|
| 826 | selectedCopy[i] = _selectedInfoContainers[i];
|
---|
| 827 | }
|
---|
| 828 |
|
---|
| 829 | _currentSelectionButton.button("option", "disabled", false);
|
---|
| 830 |
|
---|
| 831 | _templateTracker.push({fileIndex:-1, list:selectedCopy, templateIndex:0});
|
---|
[26461] | 832 | }
|
---|
| 833 | });
|
---|
| 834 |
|
---|
| 835 | debugElems.mouseover(function()
|
---|
| 836 | {
|
---|
| 837 | if(_debugOn && !_pauseSelector)
|
---|
| 838 | {
|
---|
[27110] | 839 | _fileSelector.find("select").val("none");
|
---|
| 840 |
|
---|
[26554] | 841 | var nodes = new Array();
|
---|
| 842 | if($(this).is("table, tr"))
|
---|
| 843 | {
|
---|
| 844 | var size = parseInt($(this).attr("debugSize"));
|
---|
| 845 | for(var i = 0; i < size; i++)
|
---|
| 846 | {
|
---|
| 847 | var tempNode = $("<div>");
|
---|
| 848 | tempNode.tempAttrs = new Array();
|
---|
| 849 | $(this.attributes).each(function()
|
---|
| 850 | {
|
---|
| 851 | if(this.value.charAt(0) == '[')
|
---|
| 852 | {
|
---|
| 853 | var values = eval(this.value);
|
---|
| 854 | if(values[i] == "")
|
---|
| 855 | {
|
---|
| 856 | return;
|
---|
| 857 | }
|
---|
| 858 | tempNode.attr(this.name, values[i]);
|
---|
| 859 | tempNode.tempAttrs.push({name:this.name, value:values[i]});
|
---|
| 860 | }
|
---|
| 861 | });
|
---|
| 862 | nodes.push(tempNode);
|
---|
| 863 | }
|
---|
| 864 | }
|
---|
| 865 | else
|
---|
| 866 | {
|
---|
| 867 | nodes.push(this);
|
---|
| 868 | }
|
---|
[27110] | 869 |
|
---|
[26554] | 870 | $(nodes).each(function()
|
---|
| 871 | {
|
---|
| 872 | var filepath = $(this).attr("filename");
|
---|
| 873 | var fullNodename = $(this).attr("nodename");
|
---|
| 874 | var colonIndex = fullNodename.indexOf(":");
|
---|
| 875 | var namespace = fullNodename.substring(0, colonIndex);
|
---|
| 876 | var nodename = fullNodename.substring(colonIndex + 1);
|
---|
| 877 | var name = $(this).attr("name");
|
---|
| 878 | var match = $(this).attr("match");
|
---|
[27713] | 879 | var xpath = $(this).attr("xpath");
|
---|
[26461] | 880 |
|
---|
[27163] | 881 | var file = _greenbug.fileNameToLocationAndName(filepath);
|
---|
[26645] | 882 |
|
---|
[27129] | 883 | var infoContainer = $("<option>");
|
---|
[27110] | 884 |
|
---|
| 885 | _elements.push(infoContainer);
|
---|
| 886 |
|
---|
[27713] | 887 | addChangeEventToInfoContainer(infoContainer, file.filename, file.location, nodename, namespace, name, match, xpath);
|
---|
[27110] | 888 |
|
---|
[26924] | 889 | if(name && name.length > 0)
|
---|
| 890 | {
|
---|
[27713] | 891 | infoContainer.text(name + ((xpath) ? (" (" + xpath + ")") : ""));
|
---|
[26924] | 892 | }
|
---|
| 893 | if(match && match.length > 0)
|
---|
| 894 | {
|
---|
[27713] | 895 | infoContainer.text(match + ((xpath) ? (" (" + xpath + ")") : ""));
|
---|
[26924] | 896 | }
|
---|
[27110] | 897 |
|
---|
[27129] | 898 | _templateSelector.children("select").append(infoContainer);
|
---|
[27218] | 899 | infoContainer.data("index", infoContainer.index());
|
---|
| 900 | _selectedInfoContainers.push(infoContainer.clone(true));
|
---|
[26461] | 901 | });
|
---|
| 902 |
|
---|
| 903 | if(!_itemSelected)
|
---|
| 904 | {
|
---|
| 905 | _itemSelected = true;
|
---|
| 906 | highlightElement($(this));
|
---|
| 907 | }
|
---|
| 908 | }
|
---|
| 909 | });
|
---|
| 910 |
|
---|
| 911 | debugElems.mouseout(function()
|
---|
| 912 | {
|
---|
| 913 | if(_debugOn && !_pauseSelector)
|
---|
| 914 | {
|
---|
| 915 | clearAll();
|
---|
[27129] | 916 | _templateSelector.children("select").empty();
|
---|
[27153] | 917 | _selectedInfoContainers = new Array();
|
---|
[26461] | 918 | }
|
---|
| 919 | });
|
---|
| 920 | }
|
---|
[27130] | 921 |
|
---|
| 922 | //Remove <debug> elements from the title
|
---|
[27055] | 923 | var fixTitle = function()
|
---|
| 924 | {
|
---|
| 925 | $("title").text($("title").text().replace(/<[^>]*>/g, ""));
|
---|
| 926 | }
|
---|
[27130] | 927 |
|
---|
| 928 | //Initialise Greenbug
|
---|
[26461] | 929 | this.init = function()
|
---|
| 930 | {
|
---|
| 931 | //We only want this on if we have debug elements in the page
|
---|
| 932 | var debugElems = $('debug, [debug="true"]');
|
---|
| 933 | if(!debugElems.length)
|
---|
| 934 | {
|
---|
[27082] | 935 | var enableGBButtonHolder = $("<div>", {"title":"Enable Greenbug", "id":"gbEnableButton", "class":"ui-state-default ui-corner-all"});
|
---|
| 936 | enableGBButtonHolder.append($("<img>", {"src":gs.imageURLs.greenBug}));
|
---|
| 937 | enableGBButtonHolder.click(function()
|
---|
| 938 | {
|
---|
| 939 | var url = document.URL;
|
---|
[27128] | 940 | url = url.replace(/[\?&]debug=0/g, "").replace(/[\?&]debug=1/g, "");
|
---|
[27110] | 941 |
|
---|
| 942 | if(url.indexOf("?") == url.length - 1)
|
---|
[27082] | 943 | {
|
---|
[27110] | 944 | document.location.href = url += "debug=1";
|
---|
[27082] | 945 | }
|
---|
[27110] | 946 | else if(url.indexOf("?") != -1)
|
---|
[27082] | 947 | {
|
---|
[27110] | 948 | document.location.href = url += "&debug=1";
|
---|
[27082] | 949 | }
|
---|
| 950 | else
|
---|
| 951 | {
|
---|
| 952 | document.location.href = url += "?debug=1";
|
---|
| 953 | }
|
---|
| 954 | });
|
---|
| 955 | $("body").append(enableGBButtonHolder);
|
---|
[26461] | 956 | return;
|
---|
| 957 | }
|
---|
| 958 |
|
---|
| 959 | createDebugDiv();
|
---|
| 960 | $("body").append(_mainDiv);
|
---|
[27130] | 961 |
|
---|
[27013] | 962 | callStyleFunctions();
|
---|
[26461] | 963 |
|
---|
| 964 | addMouseEventsToDebugElements(debugElems);
|
---|
[27055] | 965 | fixTitle();
|
---|
[26461] | 966 | }
|
---|
| 967 | }
|
---|
| 968 |
|
---|
[27130] | 969 | //The code entry point
|
---|
[26461] | 970 | $(window).load(function()
|
---|
| 971 | {
|
---|
| 972 | var debugWidget = new DebugWidget();
|
---|
| 973 | debugWidget.init();
|
---|
| 974 | });
|
---|