source: main/trunk/greenstone3/web/interfaces/default/js/debug_scripts.js@ 27153

Last change on this file since 27153 was 27153, checked in by sjm84, 11 years ago

Some usability changes as well as a few bug fixes

  • Property svn:executable set to *
File size: 24.9 KB
Line 
1function DebugWidget()
2{
3 //************************
4 //Private member variables
5 //************************
6
7 //The this variable
8 var _greenbug = this;
9
10 //Debugger state-keeping variables
11 var _debugOn = false;
12 var _pauseSelector = false;
13 var _elements = new Array();
14 var _itemSelected = false; //Used to prevent multiple elements from being highlighted
15 var _editModeText = false;
16 var _fromSelection = false;
17 var _selectedTemplate;
18 var _selectedInfoContainers = new Array();
19
20 //Page elements
21 var _mainDiv;
22
23 var _textEditor;
24 var _vEditor;
25
26 var _navArea;
27 var _fileSelector;
28 var _templateSelector;
29 var _editor;
30 var _editingDiv;
31 var _enableSelectorButton;
32 var _closeEditorButton;
33 var _xmlStatusBar;
34 var _saveButton;
35 var _swapEditorButton;
36
37 //Editor state-keeping variables
38 var _currentFileName;
39 var _currentLocation;
40 var _currentNodename;
41 var _currentName;
42 var _currentMatch;
43 var _currentNamespace;
44 var _isVisualEditor = true;
45
46 var _styleFunctions = new Array();
47
48 //Used to reload the page while keeping the state of the editor
49 var partialPageReload = function(callback)
50 {
51 $.ajax(document.URL)
52 .success(function(response)
53 {
54 //Get the body text from the response
55 var bodyStartIndex = response.indexOf("<body");
56 var bodyEndIndex = response.indexOf("</body>");
57 var bodyText = response.substring(bodyStartIndex, bodyEndIndex + 7);
58
59 //Get the current top area and container
60 var topLevelTopArea = $("#topArea");
61 var topLevelContainer = $("#container");
62
63 //Create a temporary div and put the html into it
64 var tempDiv = $("<div>");
65 tempDiv.html(bodyText);
66
67 //Replace the contents of the old elements with the new elements
68 var topArea = tempDiv.find("#topArea");
69 var container = tempDiv.find("#container");
70 topLevelTopArea.html(topArea.html());
71 topLevelContainer.html(container.html());
72
73 //Update the events for the debug elements that currently don't have events associated with them
74 var debugElems = $('debug, [debug="true"]').filter(function(){return (!($.data(this, "events"))) ? true : false});
75 addMouseEventsToDebugElements(debugElems);
76 })
77 .error(function()
78 {
79 alert("There was an error reloading the page, please reload manually.");
80 });
81
82 if(callback)
83 {
84 callback();
85 }
86 }
87
88 //Some functions need to be called after an element is added to the page. So we store them and call them later.
89 var callStyleFunctions = function()
90 {
91 for(var i = 0; i < _styleFunctions.length; i++)
92 {
93 var sFunction = _styleFunctions[i];
94 sFunction();
95 }
96 }
97
98 //Create the area where the buttons are stored
99 var createButtonDiv = function(buttonDiv)
100 {
101 //Used to enable the selector to get the templates of a particular area of the page
102 _enableSelectorButton = $("<button>Select an element</button>");
103 _enableSelectorButton.click(function()
104 {
105 _enableSelectorButton.button("option", "label", "Select new element");
106 $("a").click(function(e)
107 {
108 e.preventDefault();
109 });
110 _debugOn = true;
111 _pauseSelector = false;
112 _enableSelectorButton.button("option", "disabled", true);
113 });
114 _styleFunctions.push(function(){_enableSelectorButton.button({icons:{primary:"ui-icon-power"}})});
115
116 //Used to minimise/restore the editor
117 _closeEditorButton = $("<button>Close editor</button>");
118 _closeEditorButton.click(function()
119 {
120 if(_closeEditorButton.button("option", "label") == "Close editor")
121 {
122 _closeEditorButton.button("option", "label", "Open editor");
123 _editingDiv.hide();
124 }
125 else
126 {
127 _closeEditorButton.button("option", "label", "Close editor");
128 _editingDiv.show();
129 }
130 });
131 _closeEditorButton.css("float", "right");
132 _styleFunctions.push(function(){_closeEditorButton.button({icons:{secondary:"ui-icon-newwin"}, disabled:true})});
133
134 //Used to save any changes that have been made to this template
135 _saveButton = $("<button>Save changes</button>");
136 _saveButton.click(function()
137 {
138 if(_editor)
139 {
140 var xmlString;
141 if(_isVisualEditor)
142 {
143 _vEditor.savePendingEdits();
144 xmlString = new XMLSerializer().serializeToString(_vEditor.getXML());
145 }
146 else
147 {
148 xmlString = _editor.getValue();
149 }
150 xmlString = xmlString.replace(/&/g, "&amp;");
151
152 try
153 {
154 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>");
155 }
156 catch(error)
157 {
158 alert("Could not save as there is a problem with the XML.");
159 return;
160 }
161
162 var url = gs.xsltParams.library_name;
163 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};
164
165 if(_currentName && _currentName.length > 0){parameters["s1.name"] = _currentName;}
166 if(_currentMatch && _currentMatch.length > 0){parameters["s1.match"] = _currentMatch;}
167
168 _saveButton.button("option", "disabled", true);
169 $.blockUI({message:'<div class="ui-state-active">Saving, please wait...</div>'});
170
171 $.post(url, parameters)
172 .success(function()
173 {
174 $.ajax(gs.xsltParams.library_name + "?a=s&sa=c")
175 .success(function()
176 {
177 partialPageReload(function(){$.unblockUI();});
178 })
179 .error(function()
180 {
181 $.unblockUI();
182 alert("Error reloading collection.");
183 })
184 .complete(function()
185 {
186 _saveButton.button("option", "disabled", false);
187 });
188 })
189 .error(function()
190 {
191 alert("There was an error sending the request to the server, please try again.");
192 });
193 }
194 });
195 _styleFunctions.push(function(){_saveButton.button({icons:{primary:"ui-icon-disk"}, disabled:true})});
196
197 //Used to switch between the XML and Visual editors
198 _swapEditorButton = $("<button>Switch to XML editor</button>");
199 _swapEditorButton.button().click(function()
200 {
201 if(_vEditor && _textEditor)
202 {
203 if(_isVisualEditor)
204 {
205 _vEditor.savePendingEdits();
206 _vEditor.getMainDiv().hide();
207 var containerNode = _vEditor.getXML().firstChild;
208 var templateNode = containerNode.firstChild;
209 while(templateNode)
210 {
211 if(templateNode.nodeType == 1)
212 {
213 break;
214 }
215 templateNode = templateNode.nextSibling;
216 }
217 var xmlText = new XMLSerializer().serializeToString(templateNode);
218 _editor.setValue(xmlText);
219 _editor.clearSelection();
220 var UndoManager = require("ace/undomanager").UndoManager;
221 _editor.getSession().setUndoManager(new UndoManager());
222 _textEditor.show();
223 _swapEditorButton.button("option", "label", "Switch to visual editor");
224 _isVisualEditor = false;
225 _xmlStatusBar.show();
226 }
227 else
228 {
229 _textEditor.hide();
230 var xmlText = _editor.getValue();
231 _vEditor.getMainDiv().remove();
232 _vEditor = new visualXMLEditor(xmlText);
233 _editingDiv.append(_vEditor.getMainDiv());
234 _vEditor.selectRootElement();
235 _vEditor.getMainDiv().show();
236 _swapEditorButton.button("option", "label", "Switch to XML editor");
237 _isVisualEditor = true;
238 _xmlStatusBar.hide();
239 }
240 }
241 });
242 _styleFunctions.push(function(){_swapEditorButton.button({icons:{primary:"ui-icon-refresh"}})});
243
244 undoButton = $("<button>Undo</button>");
245 undoButton.click(function()
246 {
247 if(_isVisualEditor)
248 {
249 _vEditor.undo();
250 }
251 else
252 {
253 _editor.undo();
254 }
255 });
256 _styleFunctions.push(function(){undoButton.button({icons:{primary:"ui-icon-arrowreturnthick-1-w"}})});
257
258 buttonDiv.append(_enableSelectorButton);
259 buttonDiv.append(_closeEditorButton);
260 buttonDiv.append(_saveButton);
261 buttonDiv.append(_swapEditorButton);
262 buttonDiv.append(undoButton);
263 }
264
265 //Used to monitor the state of the XML in the XML editor and will notify the user if there is an error
266 var createXMLStatusBar = function(buttonDiv)
267 {
268 _xmlStatusBar = $("<span>");
269 _xmlStatusBar.css("padding", "5px");
270 _xmlStatusBar.addClass("ui-corner-all");
271 _styleFunctions.push(function(){_xmlStatusBar.hide();});
272
273 //Check the XML for errors every 2 seconds
274 setInterval(function()
275 {
276 if(_editor)
277 {
278 var xmlString = _editor.getValue();
279 try
280 {
281 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>");
282 }
283 catch(error)
284 {
285 console.log(error);
286 _xmlStatusBar.text("XML ERROR! (Mouse over for details)");
287 _xmlStatusBar.addClass("ui-state-error");
288 _xmlStatusBar.removeClass("ui-state-active");
289 _xmlStatusBar.attr("title", error);
290 _saveButton.button("option", "disabled", true);
291 _swapEditorButton.button("option", "disabled", true);
292 return;
293 }
294
295 _xmlStatusBar.text("XML OK!");
296 _xmlStatusBar.addClass("ui-state-active");
297 _xmlStatusBar.removeClass("ui-state-error");
298 _xmlStatusBar.removeAttr("title");
299 if(_saveButton.button("option", "label") == "Save changes")
300 {
301 _saveButton.button("option", "disabled", false);
302 }
303 if(_swapEditorButton.button("option", "label") == "Switch to visual editor")
304 {
305 _swapEditorButton.button("option", "disabled", false);
306 }
307 }
308 }, 2000);
309 buttonDiv.append(_xmlStatusBar);
310 }
311
312 //Create the elements that allow
313 var createFileAndTemplateSelectors = function(buttonDiv)
314 {
315 _templateSelector = $("<div>", {"id":"veTemplateSelector", "class":"ui-state-default ui-corner-all"});
316 _templateSelector.append($("<span>Templates: <span>"));
317 var templateSelectBox = $("<select>").append("<option>-- No templates --</option>");
318 templateSelectBox.change(function()
319 {
320 var selected = templateSelectBox.find(":selected");
321 var changeFunction = selected.data("changeFunction");
322 if(changeFunction)
323 {
324 changeFunction();
325 }
326 });
327 _templateSelector.append(templateSelectBox);
328 _fileSelector = $("<div>", {"id":"veFileSelector"});
329 buttonDiv.append(_fileSelector);
330 buttonDiv.append(_templateSelector);
331
332 //Populate the file selector
333 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;
334 $.ajax(url)
335 .success(function(response)
336 {
337 var listStartIndex = response.indexOf("<fileListJSON>") + "<fileListJSON>".length;
338 var listEndIndex = response.indexOf("</fileListJSON>");
339
340 var listString = response.substring(listStartIndex, listEndIndex).replace(/&quot;/g, "\"").replace(/\\/g, "/");
341 var list = eval(listString);
342
343 var selectBox = $("<select>");
344 selectBox.append($("<option>-- Select a file --</option>", {value:"none"}));
345 _fileSelector.addClass("ui-state-default");
346 _fileSelector.addClass("ui-corner-all");
347 _fileSelector.append("<span>Files: </span>");
348 _fileSelector.append(selectBox);
349
350 var currentSelectionOption = $("<option>[Current selection]</option>");
351 currentSelectionOption.val("currentSelection");
352 selectBox.append(currentSelectionOption);
353
354 for(var i = 0; i < list.length; i++)
355 {
356 var item = list[i];
357 var option = $("<option>" + item.path + " (" + item.location + ")</option>", {value:item.path});
358 option.data("fileItem", item);
359 selectBox.append(option);
360 }
361
362 selectBox.change(function()
363 {
364 var selectedItem = selectBox.find(":selected");
365
366 if(selectedItem.val() == "currentSelection")
367 {
368 _templateSelector.children("select").empty();
369 for(var i = 0; i < _selectedInfoContainers.length; i++)
370 {
371 var currentContainer = _selectedInfoContainers[i];
372 _templateSelector.children("select").append(currentContainer);
373 }
374 _templateSelector.children("select").children().first().trigger("change");
375 return;
376 }
377
378 if(!selectedItem.data("fileItem"))
379 {
380 return;
381 }
382
383 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;
384 $.ajax(getURL)
385 .success(function(templateResponse)
386 {
387 var templateListStart = templateResponse.indexOf("<templateList>") + "<templateList>".length;
388 var templateListEnd = templateResponse.indexOf("</templateList>");
389 var templateListString = templateResponse.substring(templateListStart, templateListEnd).replace(/&quot;/g, "\"");
390 var templateList = eval(templateListString);
391
392 _templateSelector.children("select").empty();
393 if(templateList.length == 0)
394 {
395 _templateSelector.children("select").append("<option>-- No templates --</option>");
396 }
397
398 for(var i = 0; i < templateList.length; i++)
399 {
400 var fileName = selectedItem.data("fileItem").path;
401 var location = selectedItem.data("fileItem").location;
402 var namespace = templateList[i].namespace;
403 var nodename = "template";
404 var name = templateList[i].name;
405 var match = templateList[i].match;
406
407 if(name)
408 {
409 name = templateList[i].name.replace(/&apos;/g, "'").replace(/&quot;/g, "\"").replace(/&amp;/g, "&");
410 }
411 if(match)
412 {
413 match = templateList[i].match.replace(/&apos;/g, "'").replace(/&quot;/g, "\"").replace(/&amp;/g, "&");
414 }
415
416 var infoContainer = $("<option>");
417
418 _elements.push(infoContainer);
419
420 addChangeEventToInfoContainer(infoContainer, fileName, location, nodename, namespace, name, match);
421
422 if(name && name.length > 0)
423 {
424 infoContainer.text(name);
425 }
426 if(match && match.length > 0)
427 {
428 infoContainer.text(match);
429 }
430
431 _templateSelector.children("select").append(infoContainer);
432 }
433
434 _templateSelector.children("select").trigger("change");
435 });
436 });
437 })
438 .error(function()
439 {
440 console.log("Error retrieving XSLT files");
441 });
442 }
443
444 //The function that creates all the necessary elements for Greenbug
445 var createDebugDiv = function()
446 {
447 _mainDiv = $("<div>", {"id":"debugDiv"});
448 _mainDiv.css(
449 {
450 "position":"fixed",
451 "font-size":"0.8em",
452 "bottom":"0px",
453 "width":"100%",
454 "background":"white",
455 "border":"1px black solid",
456 "padding":"5px",
457 "z-index":100
458 });
459
460 _editingDiv = $("<div>");
461 var toolBarDiv = $("<div>");
462 toolBarDiv.css({"height":"40px"});
463 toolBarDiv.append("<div>", {style:"clear:both;"});
464
465 var buttonDiv = $("<div>");
466 toolBarDiv.append(buttonDiv);
467 createButtonDiv(buttonDiv);
468 createFileAndTemplateSelectors(buttonDiv);
469 createXMLStatusBar(buttonDiv);
470
471 _styleFunctions.push(function(){$(".ui-button").css({"margin-right":"0.5em"});});
472
473 _mainDiv.append(toolBarDiv);
474 _mainDiv.append(_editingDiv);
475 _mainDiv.append(_navArea);
476 }
477
478 //Clear all selected elements on the page
479 var clearAll = function()
480 {
481 _itemSelected = false;
482 $(_elements).each(function()
483 {
484 $(this).remove();
485 });
486 }
487
488 //Put a border around the given element
489 var highlightElement = function(e)
490 {
491 var topBorderDiv = $("<div>");
492 var bottomBorderDiv = $("<div>");
493 var leftBorderDiv = $("<div>");
494 var rightBorderDiv = $("<div>");
495
496 topBorderDiv.css({"position":"absolute", "top":e.offset().top + "px", "left":e.offset().left + "px", "height":"0px", "width":e.width() + "px", "border":"1px solid red"});
497 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"});
498 leftBorderDiv.css({"position":"absolute", "top":e.offset().top + "px", "left":e.offset().left + "px", "height":e.height() + "px", "width":"0px", "border":"1px solid red"});
499 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"});
500
501 $("body").append(topBorderDiv, bottomBorderDiv, leftBorderDiv, rightBorderDiv);
502
503 _elements.push(topBorderDiv);
504 _elements.push(bottomBorderDiv);
505 _elements.push(leftBorderDiv);
506 _elements.push(rightBorderDiv);
507 }
508
509 //Change the current template in the XML and Visual editor
510 this.changeCurrentTemplate = function(location, fileName, nodename, namespace, name, match)
511 {
512 var responseName = "requestedNameTemplate";
513
514 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;
515 if(match && match.length > 0){url += "&s1.match=" + match; responseName = "requestedMatchTemplate";}
516 if(name && name.length > 0){url += "&s1.name=" + name;}
517
518 $.ajax(url)
519 .success(function(response)
520 {
521 var template;
522 if(response.search(responseName) != -1)
523 {
524 var startIndex = response.indexOf("<" + responseName + ">") + responseName.length + 2;
525 var endIndex = response.indexOf("</" + responseName + ">");
526 template = response.substring(startIndex, endIndex);
527 }
528 else
529 {
530 return;
531 }
532
533 _textEditor = $("<div>", {"id":"textEditor"});
534 _textEditor.css({"width":"100%", "height":"300px"});
535 _textEditor.val(template);
536
537 if(_isVisualEditor)
538 {
539 _textEditor.hide();
540 }
541
542 _editingDiv.empty();
543 _editingDiv.append($("<p>Location: " + location + " <br/>Filename: " + fileName + "</p>"));
544 _editingDiv.append(_textEditor);
545
546 _vEditor = new visualXMLEditor(template);
547 _editingDiv.append(_vEditor.getMainDiv());
548 _vEditor.setGreenbug(_greenbug);
549 _vEditor.selectRootElement();
550
551 if(!_isVisualEditor)
552 {
553 _vEditor.getMainDiv().hide();
554 }
555
556 _editor = ace.edit("textEditor");
557 _editor.getSession().setMode("ace/mode/xml");
558 _editor.getSession().setUseSoftTabs(false);
559 _editor.setValue(template);
560 _editor.clearSelection();
561 var UndoManager = require("ace/undomanager").UndoManager;
562 _editor.getSession().setUndoManager(new UndoManager());
563
564 _textEditor.css({"min-height":"200px", "border-top":"5px solid #444"});
565 _textEditor.resizable({handles: 'n', resize:function()
566 {
567 _textEditor.css({top:"0px"});
568 _editor.resize();
569 }});
570
571 _closeEditorButton.button("option", "disabled", false);
572 if(_closeEditorButton.button("option", "label") == "Open editor")
573 {
574 _closeEditorButton.button("option", "label", "Close editor");
575 _editingDiv.show();
576 }
577 })
578 .error(function()
579 {
580 console.log("Error getting the XML template from the file");
581 });
582 }
583
584 //Store the function that is called when this template is selected from the list
585 var addChangeEventToInfoContainer = function(infoContainer, fileName, location, nodename, namespace, name, match)
586 {
587 infoContainer.data("changeFunction", function()
588 {
589 if(_selectedTemplate)
590 {
591 _selectedTemplate.css("border", _selectedTemplate.prevBorder);
592 }
593 _selectedTemplate = infoContainer;
594 _selectedTemplate.prevBorder = _selectedTemplate.css("border");
595 _selectedTemplate.css("border", "red 1px solid");
596
597 _currentFileName = fileName;
598 _currentLocation = location;
599 _currentNodename = nodename;
600 _currentNamespace = namespace;
601 _currentName = name;
602 _currentMatch = match;
603
604 _greenbug.changeCurrentTemplate(location, fileName, nodename, namespace, name, match);
605 });
606 }
607
608 //Add the mouse events to the <debug> elemetns that are called when the selector is anabled
609 var addMouseEventsToDebugElements = function(debugElems)
610 {
611 debugElems.click(function(e)
612 {
613 if(_debugOn)
614 {
615 $("a").off("click");
616 _debugOn = false;
617 _pauseSelector = true;
618 _enableSelectorButton.button("option", "disabled", false);
619 _templateSelector.children("select").trigger("change");
620 _fileSelector.children("select").val("currentSelection");
621 e.stopPropagation();
622 }
623 });
624
625 debugElems.mouseover(function()
626 {
627 if(_debugOn && !_pauseSelector)
628 {
629 _fileSelector.find("select").val("none");
630
631 var nodes = new Array();
632 if($(this).is("table, tr"))
633 {
634 var size = parseInt($(this).attr("debugSize"));
635 for(var i = 0; i < size; i++)
636 {
637 var tempNode = $("<div>");
638 tempNode.tempAttrs = new Array();
639 $(this.attributes).each(function()
640 {
641 if(this.value.charAt(0) == '[')
642 {
643 var values = eval(this.value);
644 if(values[i] == "")
645 {
646 return;
647 }
648 tempNode.attr(this.name, values[i]);
649 tempNode.tempAttrs.push({name:this.name, value:values[i]});
650 }
651 });
652 nodes.push(tempNode);
653 }
654 }
655 else
656 {
657 nodes.push(this);
658 }
659
660 $(nodes).each(function()
661 {
662 var filepath = $(this).attr("filename");
663 var fullNodename = $(this).attr("nodename");
664 var colonIndex = fullNodename.indexOf(":");
665 var namespace = fullNodename.substring(0, colonIndex);
666 var nodename = fullNodename.substring(colonIndex + 1);
667 var name = $(this).attr("name");
668 var match = $(this).attr("match");
669
670 var location;
671 var fileName;
672 //Use the filepath to work out where this file is from
673 if(filepath.search(/[\/\\]interfaces[\/\\]/) != -1)
674 {
675 location = "interface";
676 fileName = filepath.replace(/.*[\/\\]transform[\/\\]/, "");
677 }
678 else if(filepath.search(/[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]etc[\/\\]/) != -1)
679 {
680 location = "collectionConfig";
681 fileName = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]etc[\/\\]/, "");
682 }
683 else if(filepath.search(/[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]transform[\/\\]/) != -1)
684 {
685 location = "collection";
686 fileName = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]transform[\/\\]/, "");
687 }
688 else if(filepath.search(/[\/\\]sites[\/\\].*[\/\\]transform[\/\\]/) != -1)
689 {
690 location = "site";
691 fileName = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]transform[\/\\]/, "");
692 }
693
694 var infoContainer = $("<option>");
695
696 _elements.push(infoContainer);
697
698 addChangeEventToInfoContainer(infoContainer, fileName, location, nodename, namespace, name, match);
699
700 if(name && name.length > 0)
701 {
702 infoContainer.text(name);
703 }
704 if(match && match.length > 0)
705 {
706 infoContainer.text(match);
707 }
708
709 _selectedInfoContainers.push(infoContainer.clone(true));
710
711 _templateSelector.children("select").append(infoContainer);
712 });
713
714 if(!_itemSelected)
715 {
716 _itemSelected = true;
717 highlightElement($(this));
718 }
719 }
720 });
721
722 debugElems.mouseout(function()
723 {
724 if(_debugOn && !_pauseSelector)
725 {
726 clearAll();
727 _templateSelector.children("select").empty();
728 _selectedInfoContainers = new Array();
729 }
730 });
731 }
732
733 //Remove <debug> elements from the title
734 var fixTitle = function()
735 {
736 $("title").text($("title").text().replace(/<[^>]*>/g, ""));
737 }
738
739 //Initialise Greenbug
740 this.init = function()
741 {
742 //We only want this on if we have debug elements in the page
743 var debugElems = $('debug, [debug="true"]');
744 if(!debugElems.length)
745 {
746 var enableGBButtonHolder = $("<div>", {"title":"Enable Greenbug", "id":"gbEnableButton", "class":"ui-state-default ui-corner-all"});
747 enableGBButtonHolder.append($("<img>", {"src":gs.imageURLs.greenBug}));
748 enableGBButtonHolder.click(function()
749 {
750 var url = document.URL;
751 url = url.replace(/[\?&]debug=0/g, "").replace(/[\?&]debug=1/g, "");
752
753 if(url.indexOf("?") == url.length - 1)
754 {
755 document.location.href = url += "debug=1";
756 }
757 else if(url.indexOf("?") != -1)
758 {
759 document.location.href = url += "&debug=1";
760 }
761 else
762 {
763 document.location.href = url += "?debug=1";
764 }
765 });
766 $("body").append(enableGBButtonHolder);
767 return;
768 }
769
770 createDebugDiv();
771 $("body").append(_mainDiv);
772
773 callStyleFunctions();
774
775 addMouseEventsToDebugElements(debugElems);
776 fixTitle();
777 }
778}
779
780//The code entry point
781$(window).load(function()
782{
783 var debugWidget = new DebugWidget();
784 debugWidget.init();
785});
Note: See TracBrowser for help on using the repository browser.