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

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

Some major improvements including the functionality to select arbitrary files to modify

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